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