1d941bd3ac375cb3174d8e6137801483d25c89ea
2 ** Copyright (C) 2001-2011 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 #define BUFFER_LEN (1<<16)
36 static void stdin_test (int typemajor
, int count
) ;
39 main (int argc
, char *argv
[])
40 { int do_all
= 0, test_count
= 0 ;
42 if (BUFFER_LEN
< PIPE_TEST_LEN
)
43 { fprintf (stderr
, "Error : BUFFER_LEN < PIPE_TEST_LEN.\n\n") ;
48 { fprintf (stderr
, "This program cannot be run by itself. It needs\n") ;
49 fprintf (stderr
, "to be run from the stdio_test program.\n") ;
53 do_all
= ! strcmp (argv
[1], "all") ;
55 if (do_all
|| ! strcmp (argv
[1], "raw"))
56 { stdin_test (SF_FORMAT_RAW
, PIPE_TEST_LEN
) ;
60 if (do_all
|| ! strcmp (argv
[1], "wav"))
61 { stdin_test (SF_FORMAT_WAV
, PIPE_TEST_LEN
) ;
65 if (do_all
|| ! strcmp (argv
[1], "aiff"))
66 { stdin_test (SF_FORMAT_AIFF
, PIPE_TEST_LEN
) ;
70 if (do_all
|| ! strcmp (argv
[1], "au"))
71 { stdin_test (SF_FORMAT_AU
, PIPE_TEST_LEN
) ;
75 if (do_all
|| ! strcmp (argv
[1], "paf"))
76 { stdin_test (SF_FORMAT_PAF
, PIPE_TEST_LEN
) ;
80 if (do_all
|| ! strcmp (argv
[1], "svx"))
81 { stdin_test (SF_FORMAT_SVX
, PIPE_TEST_LEN
) ;
85 if (do_all
|| ! strcmp (argv
[1], "nist"))
86 { stdin_test (SF_FORMAT_NIST
, PIPE_TEST_LEN
) ;
90 if (do_all
|| ! strcmp (argv
[1], "ircam"))
91 { stdin_test (SF_FORMAT_IRCAM
, PIPE_TEST_LEN
) ;
95 if (do_all
|| ! strcmp (argv
[1], "voc"))
96 { stdin_test (SF_FORMAT_VOC
, PIPE_TEST_LEN
) ;
100 if (do_all
|| ! strcmp (argv
[1], "w64"))
101 { stdin_test (SF_FORMAT_W64
, PIPE_TEST_LEN
) ;
105 if (do_all
|| ! strcmp (argv
[1], "mat4"))
106 { stdin_test (SF_FORMAT_MAT4
, PIPE_TEST_LEN
) ;
110 if (do_all
|| ! strcmp (argv
[1], "mat5"))
111 { stdin_test (SF_FORMAT_MAT5
, PIPE_TEST_LEN
) ;
115 if (do_all
|| ! strcmp (argv
[1], "pvf"))
116 { stdin_test (SF_FORMAT_PVF
, PIPE_TEST_LEN
) ;
120 if (do_all
|| ! strcmp (argv
[1], "htk"))
121 { stdin_test (SF_FORMAT_HTK
, PIPE_TEST_LEN
) ;
126 { fprintf (stderr
, "************************************\n") ;
127 fprintf (stderr
, "* No '%s' test defined.\n", argv
[1]) ;
128 fprintf (stderr
, "************************************\n") ;
136 stdin_test (int typemajor
, int count
)
137 { static short data
[BUFFER_LEN
] ;
143 if (typemajor
== SF_FORMAT_RAW
)
144 { sfinfo
.samplerate
= 44100 ;
145 sfinfo
.format
= SF_FORMAT_RAW
| SF_FORMAT_PCM_16
;
146 sfinfo
.channels
= 1 ;
150 memset (&sfinfo
, 0, sizeof (sfinfo
)) ;
152 if ((file
= sf_open_fd (STDIN_FILENO
, SFM_READ
, &sfinfo
, SF_TRUE
)) == NULL
)
153 { fprintf (stderr
, "sf_open_fd failed with error : ") ;
154 puts (sf_strerror (NULL
)) ;
155 dump_log_buffer (NULL
) ;
159 err
= sf_error (file
) ;
160 if (err
!= SF_ERR_NO_ERROR
)
161 { printf ("Line %d : unexpected error : %s\n", __LINE__
, sf_error_number (err
)) ;
165 if ((sfinfo
.format
& SF_FORMAT_TYPEMASK
) != typemajor
)
166 { fprintf (stderr
, "\n\nError : File type doesn't match.\n") ;
170 if (sfinfo
.samplerate
!= 44100)
171 { fprintf (stderr
, "\n\nError : Sample rate (%d) should be 44100\n", sfinfo
.samplerate
) ;
175 if (sfinfo
.channels
!= 1)
176 { fprintf (stderr
, "\n\nError : Channels (%d) should be 1\n", sfinfo
.channels
) ;
180 if (sfinfo
.frames
< count
)
181 { fprintf (stderr
, "\n\nError : Sample count (%ld) should be %d\n", (long) sfinfo
.frames
, count
) ;
186 while ((k
= sf_read_short (file
, data
+ total
, BUFFER_LEN
- total
)) > 0)
190 { fprintf (stderr
, "\n\nError : Expected %d frames, read %d.\n", count
, total
) ;
194 for (k
= 0 ; k
< total
; k
++)
195 if (data
[k
] != PIPE_INDEX (k
))
196 { printf ("\n\nError : data [%d] == %d, should have been %d.\n\n", k
, data
[k
], k
) ;