2 ** Copyright (C) 2001-2009 Erik de Castro Lopo <erikd@mega-nerd.com>
4 ** This program is free software; you can redistribute it and/or modify
5 ** it under the terms of the GNU General Public License as published by
6 ** the Free Software Foundation; either version 2 of the License, or
7 ** (at your option) any later version.
9 ** This program is distributed in the hope that it will be useful,
10 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
11 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 ** GNU General Public License for more details.
14 ** You should have received a copy of the GNU General Public License
15 ** along with this program; if not, write to the Free Software
16 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
34 static void stdout_test (int typemajor, int count) ;
37 main (int argc, char *argv [])
38 { int do_all, test_count = 0 ;
41 { fprintf (stderr, "This program cannot be run by itself. It needs\n") ;
42 fprintf (stderr, "to be run from the stdio_test program.\n") ;
46 do_all =! strcmp (argv [1], "all") ;
48 if (do_all || ! strcmp (argv [1], "raw"))
49 { stdout_test (SF_FORMAT_RAW, PIPE_TEST_LEN) ;
53 if (do_all || ! strcmp (argv [1], "wav"))
54 { stdout_test (SF_FORMAT_WAV, PIPE_TEST_LEN) ;
58 if (do_all || ! strcmp (argv [1], "aiff"))
59 { stdout_test (SF_FORMAT_AIFF, PIPE_TEST_LEN) ;
63 if (do_all || ! strcmp (argv [1], "au"))
64 { stdout_test (SF_FORMAT_AU, PIPE_TEST_LEN) ;
68 if (do_all || ! strcmp (argv [1], "paf"))
69 { stdout_test (SF_FORMAT_PAF, PIPE_TEST_LEN) ;
73 if (do_all || ! strcmp (argv [1], "svx"))
74 { stdout_test (SF_FORMAT_SVX, PIPE_TEST_LEN) ;
78 if (do_all || ! strcmp (argv [1], "nist"))
79 { stdout_test (SF_FORMAT_NIST, PIPE_TEST_LEN) ;
83 if (do_all || ! strcmp (argv [1], "ircam"))
84 { stdout_test (SF_FORMAT_IRCAM, PIPE_TEST_LEN) ;
88 if (do_all || ! strcmp (argv [1], "voc"))
89 { stdout_test (SF_FORMAT_VOC, PIPE_TEST_LEN) ;
93 if (do_all || ! strcmp (argv [1], "w64"))
94 { stdout_test (SF_FORMAT_W64, PIPE_TEST_LEN) ;
98 if (do_all || ! strcmp (argv [1], "mat4"))
99 { stdout_test (SF_FORMAT_MAT4, PIPE_TEST_LEN) ;
103 if (do_all || ! strcmp (argv [1], "mat5"))
104 { stdout_test (SF_FORMAT_MAT5, PIPE_TEST_LEN) ;
108 if (do_all || ! strcmp (argv [1], "pvf"))
109 { stdout_test (SF_FORMAT_PVF, PIPE_TEST_LEN) ;
114 { fprintf (stderr, "************************************\n") ;
115 fprintf (stderr, "* No '%s' test defined.\n", argv [1]) ;
116 fprintf (stderr, "************************************\n") ;
124 stdout_test (int typemajor, int count)
125 { static short data [PIPE_TEST_LEN] ;
129 int k, total, this_write ;
131 sfinfo.samplerate = 44100 ;
132 sfinfo.format = (typemajor | SF_FORMAT_PCM_16) ;
133 sfinfo.channels = 1 ;
136 /* Create some random data. */
137 for (k = 0 ; k < PIPE_TEST_LEN ; k++)
138 data [k] = PIPE_INDEX (k) ;
140 if ((file = sf_open ("-", SFM_WRITE, &sfinfo)) == NULL)
141 { fprintf (stderr, "sf_open_write failed with error : ") ;
142 fprintf (stderr, "%s\n", sf_strerror (NULL)) ;
148 while (total < count)
149 { this_write = (count - total > 1024) ? 1024 : count - total ;
150 if ((k = sf_write_short (file, data + total, this_write)) != this_write)
151 { fprintf (stderr, "sf_write_short # %d failed with short write (%d -> %d)\n", count, this_write, k) ;