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