cannam@85: /* cannam@85: ** Copyright (C) 2001-2011 Erik de Castro Lopo cannam@85: ** cannam@85: ** This program is free software; you can redistribute it and/or modify cannam@85: ** it under the terms of the GNU General Public License as published by cannam@85: ** the Free Software Foundation; either version 2 of the License, or cannam@85: ** (at your option) any later version. cannam@85: ** cannam@85: ** This program is distributed in the hope that it will be useful, cannam@85: ** but WITHOUT ANY WARRANTY; without even the implied warranty of cannam@85: ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the cannam@85: ** GNU General Public License for more details. cannam@85: ** cannam@85: ** You should have received a copy of the GNU General Public License cannam@85: ** along with this program; if not, write to the Free Software cannam@85: ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. cannam@85: */ cannam@85: cannam@85: #include "sfconfig.h" cannam@85: cannam@85: #include cannam@85: #include cannam@85: #include cannam@85: #include cannam@85: cannam@85: #if HAVE_UNISTD_H cannam@85: #include cannam@85: #endif cannam@85: cannam@85: #include cannam@85: cannam@85: #include "utils.h" cannam@85: cannam@85: static void stdout_test (int typemajor, int count) ; cannam@85: cannam@85: int cannam@85: main (int argc, char *argv []) cannam@85: { int do_all, test_count = 0 ; cannam@85: cannam@85: if (argc != 2) cannam@85: { fprintf (stderr, "This program cannot be run by itself. It needs\n") ; cannam@85: fprintf (stderr, "to be run from the stdio_test program.\n") ; cannam@85: exit (1) ; cannam@85: } ; cannam@85: cannam@85: do_all =! strcmp (argv [1], "all") ; cannam@85: cannam@85: if (do_all || ! strcmp (argv [1], "raw")) cannam@85: { stdout_test (SF_FORMAT_RAW, PIPE_TEST_LEN) ; cannam@85: test_count ++ ; cannam@85: } ; cannam@85: cannam@85: if (do_all || ! strcmp (argv [1], "wav")) cannam@85: { stdout_test (SF_FORMAT_WAV, PIPE_TEST_LEN) ; cannam@85: test_count ++ ; cannam@85: } ; cannam@85: cannam@85: if (do_all || ! strcmp (argv [1], "aiff")) cannam@85: { stdout_test (SF_FORMAT_AIFF, PIPE_TEST_LEN) ; cannam@85: test_count ++ ; cannam@85: } ; cannam@85: cannam@85: if (do_all || ! strcmp (argv [1], "au")) cannam@85: { stdout_test (SF_FORMAT_AU, PIPE_TEST_LEN) ; cannam@85: test_count ++ ; cannam@85: } ; cannam@85: cannam@85: if (do_all || ! strcmp (argv [1], "paf")) cannam@85: { stdout_test (SF_FORMAT_PAF, PIPE_TEST_LEN) ; cannam@85: test_count ++ ; cannam@85: } ; cannam@85: cannam@85: if (do_all || ! strcmp (argv [1], "svx")) cannam@85: { stdout_test (SF_FORMAT_SVX, PIPE_TEST_LEN) ; cannam@85: test_count ++ ; cannam@85: } ; cannam@85: cannam@85: if (do_all || ! strcmp (argv [1], "nist")) cannam@85: { stdout_test (SF_FORMAT_NIST, PIPE_TEST_LEN) ; cannam@85: test_count ++ ; cannam@85: } ; cannam@85: cannam@85: if (do_all || ! strcmp (argv [1], "ircam")) cannam@85: { stdout_test (SF_FORMAT_IRCAM, PIPE_TEST_LEN) ; cannam@85: test_count ++ ; cannam@85: } ; cannam@85: cannam@85: if (do_all || ! strcmp (argv [1], "voc")) cannam@85: { stdout_test (SF_FORMAT_VOC, PIPE_TEST_LEN) ; cannam@85: test_count ++ ; cannam@85: } ; cannam@85: cannam@85: if (do_all || ! strcmp (argv [1], "w64")) cannam@85: { stdout_test (SF_FORMAT_W64, PIPE_TEST_LEN) ; cannam@85: test_count ++ ; cannam@85: } ; cannam@85: cannam@85: if (do_all || ! strcmp (argv [1], "mat4")) cannam@85: { stdout_test (SF_FORMAT_MAT4, PIPE_TEST_LEN) ; cannam@85: test_count ++ ; cannam@85: } ; cannam@85: cannam@85: if (do_all || ! strcmp (argv [1], "mat5")) cannam@85: { stdout_test (SF_FORMAT_MAT5, PIPE_TEST_LEN) ; cannam@85: test_count ++ ; cannam@85: } ; cannam@85: cannam@85: if (do_all || ! strcmp (argv [1], "pvf")) cannam@85: { stdout_test (SF_FORMAT_PVF, PIPE_TEST_LEN) ; cannam@85: test_count ++ ; cannam@85: } ; cannam@85: cannam@85: if (test_count == 0) cannam@85: { fprintf (stderr, "************************************\n") ; cannam@85: fprintf (stderr, "* No '%s' test defined.\n", argv [1]) ; cannam@85: fprintf (stderr, "************************************\n") ; cannam@85: return 1 ; cannam@85: } ; cannam@85: cannam@85: return 0 ; cannam@85: } /* main */ cannam@85: cannam@85: static void cannam@85: stdout_test (int typemajor, int count) cannam@85: { static short data [PIPE_TEST_LEN] ; cannam@85: cannam@85: SNDFILE *file ; cannam@85: SF_INFO sfinfo ; cannam@85: int k, total, this_write ; cannam@85: cannam@85: sfinfo.samplerate = 44100 ; cannam@85: sfinfo.format = (typemajor | SF_FORMAT_PCM_16) ; cannam@85: sfinfo.channels = 1 ; cannam@85: sfinfo.frames = 0 ; cannam@85: cannam@85: /* Create some random data. */ cannam@85: for (k = 0 ; k < PIPE_TEST_LEN ; k++) cannam@85: data [k] = PIPE_INDEX (k) ; cannam@85: cannam@85: if ((file = sf_open ("-", SFM_WRITE, &sfinfo)) == NULL) cannam@85: { fprintf (stderr, "sf_open_write failed with error : ") ; cannam@85: fprintf (stderr, "%s\n", sf_strerror (NULL)) ; cannam@85: exit (1) ; cannam@85: } ; cannam@85: cannam@85: total = 0 ; cannam@85: cannam@85: while (total < count) cannam@85: { this_write = (count - total > 1024) ? 1024 : count - total ; cannam@85: if ((k = sf_write_short (file, data + total, this_write)) != this_write) cannam@85: { fprintf (stderr, "sf_write_short # %d failed with short write (%d -> %d)\n", count, this_write, k) ; cannam@85: exit (1) ; cannam@85: } ; cannam@85: total += k ; cannam@85: } ; cannam@85: cannam@85: sf_close (file) ; cannam@85: cannam@85: return ; cannam@85: } /* stdout_test */ cannam@85: