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: static void stdout_test (int typemajor, int count) ; Chris@0: Chris@0: int Chris@0: main (int argc, char *argv []) Chris@0: { int do_all, test_count = 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: { stdout_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: { stdout_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: { stdout_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: { stdout_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: { stdout_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: { stdout_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: { stdout_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: { stdout_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: { stdout_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: { stdout_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: { stdout_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: { stdout_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: { stdout_test (SF_FORMAT_PVF, 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: stdout_test (int typemajor, int count) Chris@0: { static short data [PIPE_TEST_LEN] ; Chris@0: Chris@0: SNDFILE *file ; Chris@0: SF_INFO sfinfo ; Chris@0: int k, total, this_write ; Chris@0: Chris@0: sfinfo.samplerate = 44100 ; Chris@0: sfinfo.format = (typemajor | SF_FORMAT_PCM_16) ; Chris@0: sfinfo.channels = 1 ; Chris@0: sfinfo.frames = 0 ; Chris@0: Chris@0: /* Create some random data. */ Chris@0: for (k = 0 ; k < PIPE_TEST_LEN ; k++) Chris@0: data [k] = PIPE_INDEX (k) ; Chris@0: Chris@0: if ((file = sf_open ("-", SFM_WRITE, &sfinfo)) == NULL) Chris@0: { fprintf (stderr, "sf_open_write failed with error : ") ; Chris@0: fprintf (stderr, "%s\n", sf_strerror (NULL)) ; Chris@0: exit (1) ; Chris@0: } ; Chris@0: Chris@0: total = 0 ; Chris@0: Chris@0: while (total < count) Chris@0: { this_write = (count - total > 1024) ? 1024 : count - total ; Chris@0: if ((k = sf_write_short (file, data + total, this_write)) != this_write) Chris@0: { fprintf (stderr, "sf_write_short # %d failed with short write (%d -> %d)\n", count, this_write, k) ; Chris@0: exit (1) ; Chris@0: } ; Chris@0: total += k ; Chris@0: } ; Chris@0: Chris@0: sf_close (file) ; Chris@0: Chris@0: return ; Chris@0: } /* stdout_test */ Chris@0: