Chris@0: /* Chris@0: ** Copyright (C) 2001-2011 Erik de Castro Lopo Chris@0: ** Chris@0: ** This program is free software; you can redistribute it and/or modify Chris@0: ** it under the terms of the GNU General Public License as published by Chris@0: ** the Free Software Foundation; either version 2 of the License, or Chris@0: ** (at your option) any later version. Chris@0: ** Chris@0: ** This program is distributed in the hope that it will be useful, Chris@0: ** but WITHOUT ANY WARRANTY; without even the implied warranty of Chris@0: ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the Chris@0: ** GNU General Public License for more details. Chris@0: ** Chris@0: ** You should have received a copy of the GNU General Public License Chris@0: ** along with this program; if not, write to the Free Software Chris@0: ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. Chris@0: */ Chris@0: Chris@0: #include "sfconfig.h" Chris@0: Chris@0: #include Chris@0: #include Chris@0: #include Chris@0: #include Chris@0: Chris@0: #if HAVE_UNISTD_H Chris@0: #include Chris@0: #endif Chris@0: Chris@0: #include Chris@0: Chris@0: #include "utils.h" Chris@0: Chris@0: #define BUFFER_LEN (1<<16) Chris@0: Chris@0: static void stdin_test (int typemajor, int count) ; Chris@0: Chris@0: int Chris@0: main (int argc, char *argv []) Chris@0: { int do_all = 0, test_count = 0 ; Chris@0: Chris@0: if (BUFFER_LEN < PIPE_TEST_LEN) Chris@0: { fprintf (stderr, "Error : BUFFER_LEN < PIPE_TEST_LEN.\n\n") ; Chris@0: exit (1) ; Chris@0: } ; Chris@0: Chris@0: if (argc != 2) Chris@0: { fprintf (stderr, "This program cannot be run by itself. It needs\n") ; Chris@0: fprintf (stderr, "to be run from the stdio_test program.\n") ; Chris@0: exit (1) ; Chris@0: } ; Chris@0: Chris@0: do_all = ! strcmp (argv [1], "all") ; Chris@0: Chris@0: if (do_all || ! strcmp (argv [1], "raw")) Chris@0: { stdin_test (SF_FORMAT_RAW, PIPE_TEST_LEN) ; Chris@0: test_count++ ; Chris@0: } ; Chris@0: Chris@0: if (do_all || ! strcmp (argv [1], "wav")) Chris@0: { stdin_test (SF_FORMAT_WAV, PIPE_TEST_LEN) ; Chris@0: test_count++ ; Chris@0: } ; Chris@0: Chris@0: if (do_all || ! strcmp (argv [1], "aiff")) Chris@0: { stdin_test (SF_FORMAT_AIFF, PIPE_TEST_LEN) ; Chris@0: test_count++ ; Chris@0: } ; Chris@0: Chris@0: if (do_all || ! strcmp (argv [1], "au")) Chris@0: { stdin_test (SF_FORMAT_AU, PIPE_TEST_LEN) ; Chris@0: test_count++ ; Chris@0: } ; Chris@0: Chris@0: if (do_all || ! strcmp (argv [1], "paf")) Chris@0: { stdin_test (SF_FORMAT_PAF, PIPE_TEST_LEN) ; Chris@0: test_count++ ; Chris@0: } ; Chris@0: Chris@0: if (do_all || ! strcmp (argv [1], "svx")) Chris@0: { stdin_test (SF_FORMAT_SVX, PIPE_TEST_LEN) ; Chris@0: test_count++ ; Chris@0: } ; Chris@0: Chris@0: if (do_all || ! strcmp (argv [1], "nist")) Chris@0: { stdin_test (SF_FORMAT_NIST, PIPE_TEST_LEN) ; Chris@0: test_count++ ; Chris@0: } ; Chris@0: Chris@0: if (do_all || ! strcmp (argv [1], "ircam")) Chris@0: { stdin_test (SF_FORMAT_IRCAM, PIPE_TEST_LEN) ; Chris@0: test_count++ ; Chris@0: } ; Chris@0: Chris@0: if (do_all || ! strcmp (argv [1], "voc")) Chris@0: { stdin_test (SF_FORMAT_VOC, PIPE_TEST_LEN) ; Chris@0: test_count++ ; Chris@0: } ; Chris@0: Chris@0: if (do_all || ! strcmp (argv [1], "w64")) Chris@0: { stdin_test (SF_FORMAT_W64, PIPE_TEST_LEN) ; Chris@0: test_count++ ; Chris@0: } ; Chris@0: Chris@0: if (do_all || ! strcmp (argv [1], "mat4")) Chris@0: { stdin_test (SF_FORMAT_MAT4, PIPE_TEST_LEN) ; Chris@0: test_count++ ; Chris@0: } ; Chris@0: Chris@0: if (do_all || ! strcmp (argv [1], "mat5")) Chris@0: { stdin_test (SF_FORMAT_MAT5, PIPE_TEST_LEN) ; Chris@0: test_count++ ; Chris@0: } ; Chris@0: Chris@0: if (do_all || ! strcmp (argv [1], "pvf")) Chris@0: { stdin_test (SF_FORMAT_PVF, PIPE_TEST_LEN) ; Chris@0: test_count++ ; Chris@0: } ; Chris@0: Chris@0: if (do_all || ! strcmp (argv [1], "htk")) Chris@0: { stdin_test (SF_FORMAT_HTK, PIPE_TEST_LEN) ; Chris@0: test_count++ ; Chris@0: } ; Chris@0: Chris@0: if (test_count == 0) Chris@0: { fprintf (stderr, "************************************\n") ; Chris@0: fprintf (stderr, "* No '%s' test defined.\n", argv [1]) ; Chris@0: fprintf (stderr, "************************************\n") ; Chris@0: return 1 ; Chris@0: } ; Chris@0: Chris@0: return 0 ; Chris@0: } /* main */ Chris@0: Chris@0: static void Chris@0: stdin_test (int typemajor, int count) Chris@0: { static short data [BUFFER_LEN] ; Chris@0: Chris@0: SNDFILE *file ; Chris@0: SF_INFO sfinfo ; Chris@0: int k, total, err ; Chris@0: Chris@0: if (typemajor == SF_FORMAT_RAW) Chris@0: { sfinfo.samplerate = 44100 ; Chris@0: sfinfo.format = SF_FORMAT_RAW | SF_FORMAT_PCM_16 ; Chris@0: sfinfo.channels = 1 ; Chris@0: sfinfo.frames = 0 ; Chris@0: } Chris@0: else Chris@0: memset (&sfinfo, 0, sizeof (sfinfo)) ; Chris@0: Chris@0: if ((file = sf_open_fd (STDIN_FILENO, SFM_READ, &sfinfo, SF_TRUE)) == NULL) Chris@0: { fprintf (stderr, "sf_open_fd failed with error : ") ; Chris@0: puts (sf_strerror (NULL)) ; Chris@0: dump_log_buffer (NULL) ; Chris@0: exit (1) ; Chris@0: } ; Chris@0: Chris@0: err = sf_error (file) ; Chris@0: if (err != SF_ERR_NO_ERROR) Chris@0: { printf ("Line %d : unexpected error : %s\n", __LINE__, sf_error_number (err)) ; Chris@0: exit (1) ; Chris@0: } ; Chris@0: Chris@0: if ((sfinfo.format & SF_FORMAT_TYPEMASK) != typemajor) Chris@0: { fprintf (stderr, "\n\nError : File type doesn't match.\n") ; Chris@0: exit (1) ; Chris@0: } ; Chris@0: Chris@0: if (sfinfo.samplerate != 44100) Chris@0: { fprintf (stderr, "\n\nError : Sample rate (%d) should be 44100\n", sfinfo.samplerate) ; Chris@0: exit (1) ; Chris@0: } ; Chris@0: Chris@0: if (sfinfo.channels != 1) Chris@0: { fprintf (stderr, "\n\nError : Channels (%d) should be 1\n", sfinfo.channels) ; Chris@0: exit (1) ; Chris@0: } ; Chris@0: Chris@0: if (sfinfo.frames < count) Chris@0: { fprintf (stderr, "\n\nError : Sample count (%ld) should be %d\n", (long) sfinfo.frames, count) ; Chris@0: exit (1) ; Chris@0: } ; Chris@0: Chris@0: total = 0 ; Chris@0: while ((k = sf_read_short (file, data + total, BUFFER_LEN - total)) > 0) Chris@0: total += k ; Chris@0: Chris@0: if (total != count) Chris@0: { fprintf (stderr, "\n\nError : Expected %d frames, read %d.\n", count, total) ; Chris@0: exit (1) ; Chris@0: } ; Chris@0: Chris@0: for (k = 0 ; k < total ; k++) Chris@0: if (data [k] != PIPE_INDEX (k)) Chris@0: { printf ("\n\nError : data [%d] == %d, should have been %d.\n\n", k, data [k], k) ; Chris@0: exit (1) ; Chris@0: } ; Chris@0: Chris@0: sf_close (file) ; Chris@0: Chris@0: return ; Chris@0: } /* stdin_test */ Chris@0: