1 [+ AutoGen5 template c +]
3 ** Copyright (C) 1999-2009 Erik de Castro Lopo <erikd@mega-nerd.com>
5 ** This program is free software; you can redistribute it and/or modify
6 ** it under the terms of the GNU General Public License as published by
7 ** the Free Software Foundation; either version 2 of the License, or
8 ** (at your option) any later version.
10 ** This program is distributed in the hope that it will be useful,
11 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
12 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 ** GNU General Public License for more details.
15 ** You should have received a copy of the GNU General Public License
16 ** along with this program; if not, write to the Free Software
17 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
32 #if (defined (WIN32) || defined (_WIN32))
34 static int truncate (const char *filename, int ignored) ;
42 #define SAMPLE_RATE 11025
43 #define DATA_LENGTH (1<<12)
45 #define SILLY_WRITE_COUNT (234)
48 +]static void pcm_test_[+ (get "type_name") +] (const char *str, int format, int long_file_okz) ;
51 static void empty_file_test (const char *filename, int format) ;
54 { double d [DATA_LENGTH] ;
55 float f [DATA_LENGTH] ;
57 short s [DATA_LENGTH] ;
58 char c [DATA_LENGTH] ;
61 static BUFFER orig_data ;
62 static BUFFER test_data ;
65 main (int argc, char **argv)
72 { printf ("Usage : %s <test>\n", argv [0]) ;
73 printf (" Where <test> is one of the following:\n") ;
74 printf (" wav - test WAV file functions (little endian)\n") ;
75 printf (" aiff - test AIFF file functions (big endian)\n") ;
76 printf (" au - test AU file functions\n") ;
77 printf (" avr - test AVR file functions\n") ;
78 printf (" caf - test CAF file functions\n") ;
79 printf (" raw - test RAW header-less PCM file functions\n") ;
80 printf (" paf - test PAF file functions\n") ;
81 printf (" svx - test 8SVX/16SV file functions\n") ;
82 printf (" nist - test NIST Sphere file functions\n") ;
83 printf (" ircam - test IRCAM file functions\n") ;
84 printf (" voc - Create Voice file functions\n") ;
85 printf (" w64 - Sonic Foundry's W64 file functions\n") ;
86 printf (" flac - test FLAC file functions\n") ;
87 printf (" mpc2k - test MPC 2000 file functions\n") ;
88 printf (" rf64 - test RF64 file functions\n") ;
89 printf (" all - perform all tests\n") ;
93 do_all = !strcmp (argv [1], "all") ;
95 if (do_all || ! strcmp (argv [1], "wav"))
96 { pcm_test_char ("char.wav" , SF_FORMAT_WAV | SF_FORMAT_PCM_U8, SF_FALSE) ;
97 pcm_test_short ("short.wav" , SF_FORMAT_WAV | SF_FORMAT_PCM_16, SF_FALSE) ;
98 pcm_test_24bit ("24bit.wav" , SF_FORMAT_WAV | SF_FORMAT_PCM_24, SF_FALSE) ;
99 pcm_test_int ("int.wav" , SF_FORMAT_WAV | SF_FORMAT_PCM_32, SF_FALSE) ;
101 pcm_test_char ("char.rifx" , SF_ENDIAN_BIG | SF_FORMAT_WAV | SF_FORMAT_PCM_U8, SF_FALSE) ;
102 pcm_test_short ("short.rifx" , SF_ENDIAN_BIG | SF_FORMAT_WAV | SF_FORMAT_PCM_16, SF_FALSE) ;
103 pcm_test_24bit ("24bit.rifx" , SF_ENDIAN_BIG | SF_FORMAT_WAV | SF_FORMAT_PCM_24, SF_FALSE) ;
104 pcm_test_int ("int.rifx" , SF_ENDIAN_BIG | SF_FORMAT_WAV | SF_FORMAT_PCM_32, SF_FALSE) ;
106 pcm_test_24bit ("24bit.wavex" , SF_FORMAT_WAVEX | SF_FORMAT_PCM_24, SF_FALSE) ;
107 pcm_test_int ("int.wavex" , SF_FORMAT_WAVEX | SF_FORMAT_PCM_32, SF_FALSE) ;
109 /* Lite remove start */
110 pcm_test_float ("float.wav" , SF_FORMAT_WAV | SF_FORMAT_FLOAT , SF_FALSE) ;
111 pcm_test_double ("double.wav" , SF_FORMAT_WAV | SF_FORMAT_DOUBLE, SF_FALSE) ;
113 pcm_test_float ("float.rifx" , SF_ENDIAN_BIG | SF_FORMAT_WAV | SF_FORMAT_FLOAT , SF_FALSE) ;
114 pcm_test_double ("double.rifx" , SF_ENDIAN_BIG | SF_FORMAT_WAV | SF_FORMAT_DOUBLE, SF_FALSE) ;
116 pcm_test_float ("float.wavex" , SF_FORMAT_WAVEX | SF_FORMAT_FLOAT , SF_FALSE) ;
117 pcm_test_double ("double.wavex" , SF_FORMAT_WAVEX | SF_FORMAT_DOUBLE, SF_FALSE) ;
118 /* Lite remove end */
120 empty_file_test ("empty_char.wav", SF_FORMAT_WAV | SF_FORMAT_PCM_U8) ;
121 empty_file_test ("empty_short.wav", SF_FORMAT_WAV | SF_FORMAT_PCM_16) ;
122 empty_file_test ("empty_float.wav", SF_FORMAT_WAV | SF_FORMAT_FLOAT) ;
127 if (do_all || ! strcmp (argv [1], "aiff"))
128 { pcm_test_char ("char_u8.aiff" , SF_FORMAT_AIFF | SF_FORMAT_PCM_U8, SF_FALSE) ;
129 pcm_test_char ("char_s8.aiff" , SF_FORMAT_AIFF | SF_FORMAT_PCM_S8, SF_FALSE) ;
130 pcm_test_short ("short.aiff" , SF_FORMAT_AIFF | SF_FORMAT_PCM_16, SF_FALSE) ;
131 pcm_test_24bit ("24bit.aiff" , SF_FORMAT_AIFF | SF_FORMAT_PCM_24, SF_FALSE) ;
132 pcm_test_int ("int.aiff" , SF_FORMAT_AIFF | SF_FORMAT_PCM_32, SF_FALSE) ;
134 pcm_test_short ("short_sowt.aifc" , SF_ENDIAN_LITTLE | SF_FORMAT_AIFF | SF_FORMAT_PCM_16, SF_FALSE) ;
135 pcm_test_24bit ("24bit_sowt.aifc" , SF_ENDIAN_LITTLE | SF_FORMAT_AIFF | SF_FORMAT_PCM_24, SF_FALSE) ;
136 pcm_test_int ("int_sowt.aifc" , SF_ENDIAN_LITTLE | SF_FORMAT_AIFF | SF_FORMAT_PCM_32, SF_FALSE) ;
138 pcm_test_short ("short_twos.aifc" , SF_ENDIAN_BIG | SF_FORMAT_AIFF | SF_FORMAT_PCM_16, SF_FALSE) ;
139 pcm_test_24bit ("24bit_twos.aifc" , SF_ENDIAN_BIG | SF_FORMAT_AIFF | SF_FORMAT_PCM_24, SF_FALSE) ;
140 pcm_test_int ("int_twos.aifc" , SF_ENDIAN_BIG | SF_FORMAT_AIFF | SF_FORMAT_PCM_32, SF_FALSE) ;
142 /* Lite remove start */
143 pcm_test_short ("dwvw16.aifc", SF_FORMAT_AIFF | SF_FORMAT_DWVW_16, SF_TRUE) ;
144 pcm_test_24bit ("dwvw24.aifc", SF_FORMAT_AIFF | SF_FORMAT_DWVW_24, SF_TRUE) ;
146 pcm_test_float ("float.aifc" , SF_FORMAT_AIFF | SF_FORMAT_FLOAT , SF_FALSE) ;
147 pcm_test_double ("double.aifc" , SF_FORMAT_AIFF | SF_FORMAT_DOUBLE, SF_FALSE) ;
148 /* Lite remove end */
150 empty_file_test ("empty_char.aiff", SF_FORMAT_AIFF | SF_FORMAT_PCM_U8) ;
151 empty_file_test ("empty_short.aiff", SF_FORMAT_AIFF | SF_FORMAT_PCM_16) ;
152 empty_file_test ("empty_float.aiff", SF_FORMAT_AIFF | SF_FORMAT_FLOAT) ;
157 if (do_all || ! strcmp (argv [1], "au"))
158 { pcm_test_char ("char.au" , SF_FORMAT_AU | SF_FORMAT_PCM_S8, SF_FALSE) ;
159 pcm_test_short ("short.au" , SF_FORMAT_AU | SF_FORMAT_PCM_16, SF_FALSE) ;
160 pcm_test_24bit ("24bit.au" , SF_FORMAT_AU | SF_FORMAT_PCM_24, SF_FALSE) ;
161 pcm_test_int ("int.au" , SF_FORMAT_AU | SF_FORMAT_PCM_32, SF_FALSE) ;
162 /* Lite remove start */
163 pcm_test_float ("float.au" , SF_FORMAT_AU | SF_FORMAT_FLOAT , SF_FALSE) ;
164 pcm_test_double ("double.au", SF_FORMAT_AU | SF_FORMAT_DOUBLE, SF_FALSE) ;
165 /* Lite remove end */
167 pcm_test_char ("char_le.au" , SF_ENDIAN_LITTLE | SF_FORMAT_AU | SF_FORMAT_PCM_S8, SF_FALSE) ;
168 pcm_test_short ("short_le.au" , SF_ENDIAN_LITTLE | SF_FORMAT_AU | SF_FORMAT_PCM_16, SF_FALSE) ;
169 pcm_test_24bit ("24bit_le.au" , SF_ENDIAN_LITTLE | SF_FORMAT_AU | SF_FORMAT_PCM_24, SF_FALSE) ;
170 pcm_test_int ("int_le.au" , SF_ENDIAN_LITTLE | SF_FORMAT_AU | SF_FORMAT_PCM_32, SF_FALSE) ;
171 /* Lite remove start */
172 pcm_test_float ("float_le.au" , SF_ENDIAN_LITTLE | SF_FORMAT_AU | SF_FORMAT_FLOAT , SF_FALSE) ;
173 pcm_test_double ("double_le.au" , SF_ENDIAN_LITTLE | SF_FORMAT_AU | SF_FORMAT_DOUBLE, SF_FALSE) ;
174 /* Lite remove end */
178 if (do_all || ! strcmp (argv [1], "caf"))
179 { pcm_test_char ("char.caf" , SF_FORMAT_CAF | SF_FORMAT_PCM_S8, SF_FALSE) ;
180 pcm_test_short ("short.caf" , SF_FORMAT_CAF | SF_FORMAT_PCM_16, SF_FALSE) ;
181 pcm_test_24bit ("24bit.caf" , SF_FORMAT_CAF | SF_FORMAT_PCM_24, SF_FALSE) ;
182 pcm_test_int ("int.caf" , SF_FORMAT_CAF | SF_FORMAT_PCM_32, SF_FALSE) ;
183 /* Lite remove start */
184 pcm_test_float ("float.caf" , SF_FORMAT_CAF | SF_FORMAT_FLOAT , SF_FALSE) ;
185 pcm_test_double ("double.caf" , SF_FORMAT_CAF | SF_FORMAT_DOUBLE, SF_FALSE) ;
186 /* Lite remove end */
188 pcm_test_short ("short_le.caf" , SF_ENDIAN_LITTLE | SF_FORMAT_CAF | SF_FORMAT_PCM_16, SF_FALSE) ;
189 pcm_test_24bit ("24bit_le.caf" , SF_ENDIAN_LITTLE | SF_FORMAT_CAF | SF_FORMAT_PCM_24, SF_FALSE) ;
190 pcm_test_int ("int_le.caf" , SF_ENDIAN_LITTLE | SF_FORMAT_CAF | SF_FORMAT_PCM_32, SF_FALSE) ;
191 /* Lite remove start */
192 pcm_test_float ("float_le.caf" , SF_ENDIAN_LITTLE | SF_FORMAT_CAF | SF_FORMAT_FLOAT , SF_FALSE) ;
193 pcm_test_double ("double_le.caf", SF_ENDIAN_LITTLE | SF_FORMAT_CAF | SF_FORMAT_DOUBLE, SF_FALSE) ;
194 /* Lite remove end */
198 if (do_all || ! strcmp (argv [1], "raw"))
199 { pcm_test_char ("char_s8.raw" , SF_FORMAT_RAW | SF_FORMAT_PCM_S8, SF_FALSE) ;
200 pcm_test_char ("char_u8.raw" , SF_FORMAT_RAW | SF_FORMAT_PCM_U8, SF_FALSE) ;
202 pcm_test_short ("short_le.raw" , SF_ENDIAN_LITTLE | SF_FORMAT_RAW | SF_FORMAT_PCM_16, SF_FALSE) ;
203 pcm_test_short ("short_be.raw" , SF_ENDIAN_BIG | SF_FORMAT_RAW | SF_FORMAT_PCM_16, SF_FALSE) ;
204 pcm_test_24bit ("24bit_le.raw" , SF_ENDIAN_LITTLE | SF_FORMAT_RAW | SF_FORMAT_PCM_24, SF_FALSE) ;
205 pcm_test_24bit ("24bit_be.raw" , SF_ENDIAN_BIG | SF_FORMAT_RAW | SF_FORMAT_PCM_24, SF_FALSE) ;
206 pcm_test_int ("int_le.raw" , SF_ENDIAN_LITTLE | SF_FORMAT_RAW | SF_FORMAT_PCM_32, SF_FALSE) ;
207 pcm_test_int ("int_be.raw" , SF_ENDIAN_BIG | SF_FORMAT_RAW | SF_FORMAT_PCM_32, SF_FALSE) ;
209 /* Lite remove start */
210 pcm_test_float ("float_le.raw" , SF_ENDIAN_LITTLE | SF_FORMAT_RAW | SF_FORMAT_FLOAT , SF_FALSE) ;
211 pcm_test_float ("float_be.raw" , SF_ENDIAN_BIG | SF_FORMAT_RAW | SF_FORMAT_FLOAT , SF_FALSE) ;
213 pcm_test_double ("double_le.raw", SF_ENDIAN_LITTLE | SF_FORMAT_RAW | SF_FORMAT_DOUBLE, SF_FALSE) ;
214 pcm_test_double ("double_be.raw", SF_ENDIAN_BIG | SF_FORMAT_RAW | SF_FORMAT_DOUBLE, SF_FALSE) ;
215 /* Lite remove end */
219 /* Lite remove start */
220 if (do_all || ! strcmp (argv [1], "paf"))
221 { pcm_test_char ("char_le.paf", SF_ENDIAN_LITTLE | SF_FORMAT_PAF | SF_FORMAT_PCM_S8, SF_FALSE) ;
222 pcm_test_char ("char_be.paf", SF_ENDIAN_BIG | SF_FORMAT_PAF | SF_FORMAT_PCM_S8, SF_FALSE) ;
223 pcm_test_short ("short_le.paf", SF_ENDIAN_LITTLE | SF_FORMAT_PAF | SF_FORMAT_PCM_16, SF_FALSE) ;
224 pcm_test_short ("short_be.paf", SF_ENDIAN_BIG | SF_FORMAT_PAF | SF_FORMAT_PCM_16, SF_FALSE) ;
225 pcm_test_24bit ("24bit_le.paf", SF_ENDIAN_LITTLE | SF_FORMAT_PAF | SF_FORMAT_PCM_24, SF_TRUE) ;
226 pcm_test_24bit ("24bit_be.paf", SF_ENDIAN_BIG | SF_FORMAT_PAF | SF_FORMAT_PCM_24, SF_TRUE) ;
230 if (do_all || ! strcmp (argv [1], "svx"))
231 { pcm_test_char ("char.svx" , SF_FORMAT_SVX | SF_FORMAT_PCM_S8, SF_FALSE) ;
232 pcm_test_short ("short.svx", SF_FORMAT_SVX | SF_FORMAT_PCM_16, SF_FALSE) ;
234 empty_file_test ("empty_char.svx", SF_FORMAT_SVX | SF_FORMAT_PCM_S8) ;
235 empty_file_test ("empty_short.svx", SF_FORMAT_SVX | SF_FORMAT_PCM_16) ;
240 if (do_all || ! strcmp (argv [1], "nist"))
241 { pcm_test_short ("short_le.nist", SF_ENDIAN_LITTLE | SF_FORMAT_NIST | SF_FORMAT_PCM_16, SF_FALSE) ;
242 pcm_test_short ("short_be.nist", SF_ENDIAN_BIG | SF_FORMAT_NIST | SF_FORMAT_PCM_16, SF_FALSE) ;
243 pcm_test_24bit ("24bit_le.nist", SF_ENDIAN_LITTLE | SF_FORMAT_NIST | SF_FORMAT_PCM_24, SF_FALSE) ;
244 pcm_test_24bit ("24bit_be.nist", SF_ENDIAN_BIG | SF_FORMAT_NIST | SF_FORMAT_PCM_24, SF_FALSE) ;
245 pcm_test_int ("int_le.nist" , SF_ENDIAN_LITTLE | SF_FORMAT_NIST | SF_FORMAT_PCM_32, SF_FALSE) ;
246 pcm_test_int ("int_be.nist" , SF_ENDIAN_BIG | SF_FORMAT_NIST | SF_FORMAT_PCM_32, SF_FALSE) ;
251 if (do_all || ! strcmp (argv [1], "ircam"))
252 { pcm_test_short ("short_be.ircam" , SF_ENDIAN_BIG | SF_FORMAT_IRCAM | SF_FORMAT_PCM_16, SF_FALSE) ;
253 pcm_test_short ("short_le.ircam" , SF_ENDIAN_LITTLE | SF_FORMAT_IRCAM | SF_FORMAT_PCM_16, SF_FALSE) ;
254 pcm_test_int ("int_be.ircam" , SF_ENDIAN_BIG | SF_FORMAT_IRCAM | SF_FORMAT_PCM_32, SF_FALSE) ;
255 pcm_test_int ("int_le.ircam" , SF_ENDIAN_LITTLE | SF_FORMAT_IRCAM | SF_FORMAT_PCM_32, SF_FALSE) ;
256 pcm_test_float ("float_be.ircam" , SF_ENDIAN_BIG | SF_FORMAT_IRCAM | SF_FORMAT_FLOAT , SF_FALSE) ;
257 pcm_test_float ("float_le.ircam" , SF_ENDIAN_LITTLE | SF_FORMAT_IRCAM | SF_FORMAT_FLOAT , SF_FALSE) ;
262 if (do_all || ! strcmp (argv [1], "voc"))
263 { pcm_test_char ("char.voc" , SF_FORMAT_VOC | SF_FORMAT_PCM_U8, SF_FALSE) ;
264 pcm_test_short ("short.voc", SF_FORMAT_VOC | SF_FORMAT_PCM_16, SF_FALSE) ;
269 if (do_all || ! strcmp (argv [1], "mat4"))
270 { pcm_test_short ("short_be.mat4" , SF_ENDIAN_BIG | SF_FORMAT_MAT4 | SF_FORMAT_PCM_16, SF_FALSE) ;
271 pcm_test_short ("short_le.mat4" , SF_ENDIAN_LITTLE | SF_FORMAT_MAT4 | SF_FORMAT_PCM_16, SF_FALSE) ;
272 pcm_test_int ("int_be.mat4" , SF_ENDIAN_BIG | SF_FORMAT_MAT4 | SF_FORMAT_PCM_32, SF_FALSE) ;
273 pcm_test_int ("int_le.mat4" , SF_ENDIAN_LITTLE | SF_FORMAT_MAT4 | SF_FORMAT_PCM_32, SF_FALSE) ;
274 pcm_test_float ("float_be.mat4" , SF_ENDIAN_BIG | SF_FORMAT_MAT4 | SF_FORMAT_FLOAT , SF_FALSE) ;
275 pcm_test_float ("float_le.mat4" , SF_ENDIAN_LITTLE | SF_FORMAT_MAT4 | SF_FORMAT_FLOAT , SF_FALSE) ;
276 pcm_test_double ("double_be.mat4" , SF_ENDIAN_BIG | SF_FORMAT_MAT4 | SF_FORMAT_DOUBLE, SF_FALSE) ;
277 pcm_test_double ("double_le.mat4" , SF_ENDIAN_LITTLE | SF_FORMAT_MAT4 | SF_FORMAT_DOUBLE, SF_FALSE) ;
279 empty_file_test ("empty_short.mat4", SF_FORMAT_MAT4 | SF_FORMAT_PCM_16) ;
280 empty_file_test ("empty_float.mat4", SF_FORMAT_MAT4 | SF_FORMAT_FLOAT) ;
284 if (do_all || ! strcmp (argv [1], "mat5"))
285 { pcm_test_char ("char_be.mat5" , SF_ENDIAN_BIG | SF_FORMAT_MAT5 | SF_FORMAT_PCM_U8, SF_FALSE) ;
286 pcm_test_char ("char_le.mat5" , SF_ENDIAN_LITTLE | SF_FORMAT_MAT5 | SF_FORMAT_PCM_U8, SF_FALSE) ;
287 pcm_test_short ("short_be.mat5" , SF_ENDIAN_BIG | SF_FORMAT_MAT5 | SF_FORMAT_PCM_16, SF_FALSE) ;
288 pcm_test_short ("short_le.mat5" , SF_ENDIAN_LITTLE | SF_FORMAT_MAT5 | SF_FORMAT_PCM_16, SF_FALSE) ;
289 pcm_test_int ("int_be.mat5" , SF_ENDIAN_BIG | SF_FORMAT_MAT5 | SF_FORMAT_PCM_32, SF_FALSE) ;
290 pcm_test_int ("int_le.mat5" , SF_ENDIAN_LITTLE | SF_FORMAT_MAT5 | SF_FORMAT_PCM_32, SF_FALSE) ;
291 pcm_test_float ("float_be.mat5" , SF_ENDIAN_BIG | SF_FORMAT_MAT5 | SF_FORMAT_FLOAT , SF_FALSE) ;
292 pcm_test_float ("float_le.mat5" , SF_ENDIAN_LITTLE | SF_FORMAT_MAT5 | SF_FORMAT_FLOAT , SF_FALSE) ;
293 pcm_test_double ("double_be.mat5" , SF_ENDIAN_BIG | SF_FORMAT_MAT5 | SF_FORMAT_DOUBLE, SF_FALSE) ;
294 pcm_test_double ("double_le.mat5" , SF_ENDIAN_LITTLE | SF_FORMAT_MAT5 | SF_FORMAT_DOUBLE, SF_FALSE) ;
296 increment_open_file_count () ;
298 empty_file_test ("empty_char.mat5", SF_FORMAT_MAT5 | SF_FORMAT_PCM_U8) ;
299 empty_file_test ("empty_short.mat5", SF_FORMAT_MAT5 | SF_FORMAT_PCM_16) ;
300 empty_file_test ("empty_float.mat5", SF_FORMAT_MAT5 | SF_FORMAT_FLOAT) ;
305 if (do_all || ! strcmp (argv [1], "pvf"))
306 { pcm_test_char ("char.pvf" , SF_FORMAT_PVF | SF_FORMAT_PCM_S8, SF_FALSE) ;
307 pcm_test_short ("short.pvf", SF_FORMAT_PVF | SF_FORMAT_PCM_16, SF_FALSE) ;
308 pcm_test_int ("int.pvf" , SF_FORMAT_PVF | SF_FORMAT_PCM_32, SF_FALSE) ;
312 if (do_all || ! strcmp (argv [1], "htk"))
313 { pcm_test_short ("short.htk", SF_FORMAT_HTK | SF_FORMAT_PCM_16, SF_FALSE) ;
317 if (do_all || ! strcmp (argv [1], "mpc2k"))
318 { pcm_test_short ("short.mpc", SF_FORMAT_MPC2K | SF_FORMAT_PCM_16, SF_FALSE) ;
322 if (do_all || ! strcmp (argv [1], "avr"))
323 { pcm_test_char ("char_u8.avr" , SF_FORMAT_AVR | SF_FORMAT_PCM_U8, SF_FALSE) ;
324 pcm_test_char ("char_s8.avr" , SF_FORMAT_AVR | SF_FORMAT_PCM_S8, SF_FALSE) ;
325 pcm_test_short ("short.avr" , SF_FORMAT_AVR | SF_FORMAT_PCM_16, SF_FALSE) ;
328 /* Lite remove end */
330 if (do_all || ! strcmp (argv [1], "w64"))
331 { pcm_test_char ("char.w64" , SF_FORMAT_W64 | SF_FORMAT_PCM_U8, SF_FALSE) ;
332 pcm_test_short ("short.w64" , SF_FORMAT_W64 | SF_FORMAT_PCM_16, SF_FALSE) ;
333 pcm_test_24bit ("24bit.w64" , SF_FORMAT_W64 | SF_FORMAT_PCM_24, SF_FALSE) ;
334 pcm_test_int ("int.w64" , SF_FORMAT_W64 | SF_FORMAT_PCM_32, SF_FALSE) ;
335 /* Lite remove start */
336 pcm_test_float ("float.w64" , SF_FORMAT_W64 | SF_FORMAT_FLOAT , SF_FALSE) ;
337 pcm_test_double ("double.w64" , SF_FORMAT_W64 | SF_FORMAT_DOUBLE, SF_FALSE) ;
338 /* Lite remove end */
340 empty_file_test ("empty_char.w64", SF_FORMAT_W64 | SF_FORMAT_PCM_U8) ;
341 empty_file_test ("empty_short.w64", SF_FORMAT_W64 | SF_FORMAT_PCM_16) ;
342 empty_file_test ("empty_float.w64", SF_FORMAT_W64 | SF_FORMAT_FLOAT) ;
347 if (do_all || ! strcmp (argv [1], "sds"))
348 { pcm_test_char ("char.sds" , SF_FORMAT_SDS | SF_FORMAT_PCM_S8, SF_TRUE) ;
349 pcm_test_short ("short.sds" , SF_FORMAT_SDS | SF_FORMAT_PCM_16, SF_TRUE) ;
350 pcm_test_24bit ("24bit.sds" , SF_FORMAT_SDS | SF_FORMAT_PCM_24, SF_TRUE) ;
352 empty_file_test ("empty_char.sds", SF_FORMAT_SDS | SF_FORMAT_PCM_S8) ;
353 empty_file_test ("empty_short.sds", SF_FORMAT_SDS | SF_FORMAT_PCM_16) ;
358 if (do_all || ! strcmp (argv [1], "sd2"))
359 { pcm_test_char ("char.sd2" , SF_FORMAT_SD2 | SF_FORMAT_PCM_S8, SF_TRUE) ;
360 pcm_test_short ("short.sd2" , SF_FORMAT_SD2 | SF_FORMAT_PCM_16, SF_TRUE) ;
361 pcm_test_24bit ("24bit.sd2" , SF_FORMAT_SD2 | SF_FORMAT_PCM_24, SF_TRUE) ;
365 if (do_all || ! strcmp (argv [1], "flac"))
366 { if (HAVE_EXTERNAL_LIBS)
367 { pcm_test_char ("char.flac" , SF_FORMAT_FLAC | SF_FORMAT_PCM_S8, SF_TRUE) ;
368 pcm_test_short ("short.flac" , SF_FORMAT_FLAC | SF_FORMAT_PCM_16, SF_TRUE) ;
369 pcm_test_24bit ("24bit.flac" , SF_FORMAT_FLAC | SF_FORMAT_PCM_24, SF_TRUE) ;
372 puts (" No FLAC tests because FLAC support was not compiled in.") ;
376 if (do_all || ! strcmp (argv [1], "rf64"))
377 { pcm_test_char ("char.rf64" , SF_FORMAT_RF64 | SF_FORMAT_PCM_U8, SF_FALSE) ;
378 pcm_test_short ("short.rf64" , SF_FORMAT_RF64 | SF_FORMAT_PCM_16, SF_FALSE) ;
379 pcm_test_24bit ("24bit.rf64" , SF_FORMAT_RF64 | SF_FORMAT_PCM_24, SF_FALSE) ;
380 pcm_test_int ("int.rf64" , SF_FORMAT_RF64 | SF_FORMAT_PCM_32, SF_FALSE) ;
382 /* Lite remove start */
383 pcm_test_float ("float.rf64" , SF_FORMAT_RF64 | SF_FORMAT_FLOAT , SF_FALSE) ;
384 pcm_test_double ("double.rf64" , SF_FORMAT_RF64 | SF_FORMAT_DOUBLE, SF_FALSE) ;
385 empty_file_test ("empty_char.rf64", SF_FORMAT_RF64 | SF_FORMAT_PCM_U8) ;
386 empty_file_test ("empty_short.rf64", SF_FORMAT_RF64 | SF_FORMAT_PCM_16) ;
387 empty_file_test ("empty_float.rf64", SF_FORMAT_RF64 | SF_FORMAT_FLOAT) ;
388 /* Lite remove end */
394 { printf ("Mono : ************************************\n") ;
395 printf ("Mono : * No '%s' test defined.\n", argv [1]) ;
396 printf ("Mono : ************************************\n") ;
400 /* Only open file descriptors should be stdin, stdout and stderr. */
401 check_open_file_count_or_die (__LINE__) ;
406 /*============================================================================================
407 ** Helper functions and macros.
410 static void create_short_file (const char *filename) ;
412 #define CHAR_ERROR(x,y) (abs ((x) - (y)) > 255)
413 #define INT_ERROR(x,y) (((x) - (y)) != 0)
414 #define TRIBYTE_ERROR(x,y) (abs ((x) - (y)) > 255)
415 #define FLOAT_ERROR(x,y) (fabs ((x) - (y)) > 1e-5)
417 #define CONVERT_DATA(k,len,new,orig) \
418 { for ((k) = 0 ; (k) < (len) ; (k) ++) \
419 (new) [k] = (orig) [k] ; \
424 /*======================================================================================
427 static void mono_[+ (get "type_name") +]_test (const char *filename, int format, int long_file_ok, int allow_fd) ;
428 static void stereo_[+ (get "type_name") +]_test (const char *filename, int format, int long_file_ok, int allow_fd) ;
429 static void mono_rdwr_[+ (get "type_name") +]_test (const char *filename, int format, int long_file_ok, int allow_fd) ;
430 static void new_rdwr_[+ (get "type_name") +]_test (const char *filename, int format, int allow_fd) ;
431 static void multi_seek_test (const char * filename, int format) ;
432 static void write_seek_extend_test (const char * filename, int format) ;
435 pcm_test_[+ (get "type_name") +] (const char *filename, int format, int long_file_ok)
437 [+ (get "data_type") +] *orig, *test ;
438 int k, items, allow_fd ;
440 /* Sd2 files cannot be opened from an existing file descriptor. */
441 allow_fd = ((format & SF_FORMAT_TYPEMASK) == SF_FORMAT_SD2) ? SF_FALSE : SF_TRUE ;
443 print_test_name ("pcm_test_[+ (get "type_name") +]", filename) ;
445 sfinfo.samplerate = 44100 ;
446 sfinfo.frames = SILLY_WRITE_COUNT ; /* Wrong length. Library should correct this on sf_close. */
447 sfinfo.channels = 1 ;
448 sfinfo.format = format ;
450 gen_windowed_sine_double (orig_data.d, DATA_LENGTH, [+ (get "max_val") +]) ;
452 orig = orig_data.[+ (get "data_field") +] ;
453 test = test_data.[+ (get "data_field") +] ;
455 /* Make this a macro so gdb steps over it in one go. */
456 CONVERT_DATA (k, DATA_LENGTH, orig, orig_data.d) ;
458 items = DATA_LENGTH ;
460 /* Some test broken out here. */
462 mono_[+ (get "type_name") +]_test (filename, format, long_file_ok, allow_fd) ;
464 /* Sub format DWVW does not allow seeking. */
465 if ((format & SF_FORMAT_SUBMASK) == SF_FORMAT_DWVW_16 ||
466 (format & SF_FORMAT_SUBMASK) == SF_FORMAT_DWVW_24)
467 { unlink (filename) ;
468 printf ("no seek : ok\n") ;
472 if ((format & SF_FORMAT_TYPEMASK) != SF_FORMAT_FLAC)
473 mono_rdwr_[+ (get "type_name") +]_test (filename, format, long_file_ok, allow_fd) ;
475 /* If the format doesn't support stereo we're done. */
476 sfinfo.channels = 2 ;
477 if (sf_format_check (&sfinfo) == 0)
478 { unlink (filename) ;
479 puts ("no stereo : ok") ;
483 stereo_[+ (get "type_name") +]_test (filename, format, long_file_ok, allow_fd) ;
485 /* New read/write test. Not sure if this is needed yet. */
487 if ((format & SF_FORMAT_TYPEMASK) != SF_FORMAT_PAF &&
488 (format & SF_FORMAT_TYPEMASK) != SF_FORMAT_VOC &&
489 (format & SF_FORMAT_TYPEMASK) != SF_FORMAT_FLAC)
490 new_rdwr_[+ (get "type_name") +]_test (filename, format, allow_fd) ;
492 delete_file (format, filename) ;
496 } /* pcm_test_[+ (get "type_name") +] */
499 mono_[+ (get "type_name") +]_test (const char *filename, int format, int long_file_ok, int allow_fd)
502 [+ (get "data_type") +] *orig, *test ;
506 sfinfo.samplerate = 44100 ;
507 sfinfo.frames = SILLY_WRITE_COUNT ; /* Wrong length. Library should correct this on sf_close. */
508 sfinfo.channels = 1 ;
509 sfinfo.format = format ;
511 orig = orig_data.[+ (get "data_field") +] ;
512 test = test_data.[+ (get "data_field") +] ;
514 items = DATA_LENGTH ;
516 file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, allow_fd, __LINE__) ;
518 sf_set_string (file, SF_STR_ARTIST, "Your name here") ;
520 test_write_[+ (get "data_type") +]_or_die (file, 0, orig, items, __LINE__) ;
521 sf_write_sync (file) ;
522 test_write_[+ (get "data_type") +]_or_die (file, 0, orig, items, __LINE__) ;
523 sf_write_sync (file) ;
525 /* Add non-audio data after the audio. */
526 sf_set_string (file, SF_STR_COPYRIGHT, "Copyright (c) 2003") ;
530 memset (test, 0, items * sizeof ([+ (get "data_type") +])) ;
532 if ((format & SF_FORMAT_TYPEMASK) != SF_FORMAT_RAW)
533 memset (&sfinfo, 0, sizeof (sfinfo)) ;
535 file = test_open_file_or_die (filename, SFM_READ, &sfinfo, allow_fd, __LINE__) ;
537 if (sfinfo.format != format)
538 { printf ("\n\nLine %d : Mono : Returned format incorrect (0x%08X => 0x%08X).\n", __LINE__, format, sfinfo.format) ;
542 if (sfinfo.frames < 2 * items)
543 { printf ("\n\nLine %d : Mono : Incorrect number of frames in file (too short). (%ld should be %d)\n", __LINE__, SF_COUNT_TO_LONG (sfinfo.frames), items) ;
547 if (! long_file_ok && sfinfo.frames > 2 * items)
548 { printf ("\n\nLine %d : Mono : Incorrect number of frames in file (too long). (%ld should be %d)\n", __LINE__, SF_COUNT_TO_LONG (sfinfo.frames), items) ;
552 if (sfinfo.channels != 1)
553 { printf ("\n\nLine %d : Mono : Incorrect number of channels in file.\n", __LINE__) ;
557 check_log_buffer_or_die (file, __LINE__) ;
559 test_read_[+ (get "data_type") +]_or_die (file, 0, test, items, __LINE__) ;
560 for (k = 0 ; k < items ; k++)
561 if ([+ (get "error_func") +] (orig [k], test [k]))
562 { printf ("\n\nLine %d: Mono : Incorrect sample A (#%d : [+ (get "format_char") +] => [+ (get "format_char") +]).\n", __LINE__, k, orig [k], test [k]) ;
563 oct_save_[+ (get "data_type") +] (orig, test, items) ;
567 /* Seek to start of file. */
568 test_seek_or_die (file, 0, SEEK_SET, 0, sfinfo.channels, __LINE__) ;
570 test_read_[+ (get "data_type") +]_or_die (file, 0, test, 4, __LINE__) ;
571 for (k = 0 ; k < 4 ; k++)
572 if ([+ (get "error_func") +] (orig [k], test [k]))
573 { printf ("\n\nLine %d : Mono : Incorrect sample A (#%d : [+ (get "format_char") +] => [+ (get "format_char") +]).\n", __LINE__, k, orig [k], test [k]) ;
577 if ((format & SF_FORMAT_SUBMASK) == SF_FORMAT_DWVW_16 ||
578 (format & SF_FORMAT_SUBMASK) == SF_FORMAT_DWVW_24)
581 printf ("no seek : ") ;
585 /* Seek to offset from start of file. */
586 test_seek_or_die (file, items + 10, SEEK_SET, items + 10, sfinfo.channels, __LINE__) ;
588 test_read_[+ (get "data_type") +]_or_die (file, 0, test + 10, 4, __LINE__) ;
589 for (k = 10 ; k < 14 ; k++)
590 if ([+ (get "error_func") +] (orig [k], test [k]))
591 { printf ("\n\nLine %d : Mono : Incorrect sample A (#%d : [+ (get "format_char") +] => [+ (get "format_char") +]).\n", __LINE__, k, test [k], orig [k]) ;
595 /* Seek to offset from current position. */
596 test_seek_or_die (file, 6, SEEK_CUR, items + 20, sfinfo.channels, __LINE__) ;
598 test_read_[+ (get "data_type") +]_or_die (file, 0, test + 20, 4, __LINE__) ;
599 for (k = 20 ; k < 24 ; k++)
600 if ([+ (get "error_func") +] (orig [k], test [k]))
601 { printf ("\n\nLine %d : Mono : Incorrect sample A (#%d : [+ (get "format_char") +] => [+ (get "format_char") +]).\n", __LINE__, k, test [k], orig [k]) ;
605 /* Seek to offset from end of file. */
606 test_seek_or_die (file, -1 * (sfinfo.frames - 10), SEEK_END, 10, sfinfo.channels, __LINE__) ;
608 test_read_[+ (get "data_type") +]_or_die (file, 0, test + 10, 4, __LINE__) ;
609 for (k = 10 ; k < 14 ; k++)
610 if ([+ (get "error_func") +] (orig [k], test [k]))
611 { printf ("\n\nLine %d : Mono : Incorrect sample D (#%d : [+ (get "format_char") +] => [+ (get "format_char") +]).\n", __LINE__, k, test [k], orig [k]) ;
615 /* Check read past end of file followed by sf_seek (sndfile, 0, SEEK_CUR). */
616 test_seek_or_die (file, 0, SEEK_SET, 0, sfinfo.channels, __LINE__) ;
619 while (count < sfinfo.frames)
620 count += sf_read_[+ (get "data_type") +] (file, test, 311) ;
622 /* Check that no error has occurred. */
624 { printf ("\n\nLine %d : Mono : error where there shouldn't have been one.\n", __LINE__) ;
625 puts (sf_strerror (file)) ;
629 /* Check that we haven't read beyond EOF. */
630 if (count > sfinfo.frames)
631 { printf ("\n\nLines %d : read past end of file (%ld should be %ld)\n", __LINE__, (long) count, (long) sfinfo.frames) ;
635 test_seek_or_die (file, 0, SEEK_CUR, sfinfo.frames, sfinfo.channels, __LINE__) ;
639 multi_seek_test (filename, format) ;
640 write_seek_extend_test (filename, format) ;
642 } /* mono_[+ (get "type_name") +]_test */
645 stereo_[+ (get "type_name") +]_test (const char *filename, int format, int long_file_ok, int allow_fd)
648 [+ (get "data_type") +] *orig, *test ;
649 int k, items, frames ;
651 sfinfo.samplerate = 44100 ;
652 sfinfo.frames = SILLY_WRITE_COUNT ; /* Wrong length. Library should correct this on sf_close. */
653 sfinfo.channels = 2 ;
654 sfinfo.format = format ;
656 gen_windowed_sine_double (orig_data.d, DATA_LENGTH, [+ (get "max_val") +]) ;
658 orig = orig_data.[+ (get "data_field") +] ;
659 test = test_data.[+ (get "data_field") +] ;
661 /* Make this a macro so gdb steps over it in one go. */
662 CONVERT_DATA (k, DATA_LENGTH, orig, orig_data.d) ;
664 items = DATA_LENGTH ;
665 frames = items / sfinfo.channels ;
667 file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, allow_fd, __LINE__) ;
669 sf_set_string (file, SF_STR_ARTIST, "Your name here") ;
671 test_writef_[+ (get "data_type") +]_or_die (file, 0, orig, frames, __LINE__) ;
673 sf_set_string (file, SF_STR_COPYRIGHT, "Copyright (c) 2003") ;
677 memset (test, 0, items * sizeof ([+ (get "data_type") +])) ;
679 if ((format & SF_FORMAT_TYPEMASK) != SF_FORMAT_RAW)
680 memset (&sfinfo, 0, sizeof (sfinfo)) ;
682 file = test_open_file_or_die (filename, SFM_READ, &sfinfo, allow_fd, __LINE__) ;
684 if (sfinfo.format != format)
685 { printf ("\n\nLine %d : Stereo : Returned format incorrect (0x%08X => 0x%08X).\n",
686 __LINE__, format, sfinfo.format) ;
690 if (sfinfo.frames < frames)
691 { printf ("\n\nLine %d : Stereo : Incorrect number of frames in file (too short). (%ld should be %d)\n",
692 __LINE__, SF_COUNT_TO_LONG (sfinfo.frames), frames) ;
696 if (! long_file_ok && sfinfo.frames > frames)
697 { printf ("\n\nLine %d : Stereo : Incorrect number of frames in file (too long). (%ld should be %d)\n",
698 __LINE__, SF_COUNT_TO_LONG (sfinfo.frames), frames) ;
702 if (sfinfo.channels != 2)
703 { printf ("\n\nLine %d : Stereo : Incorrect number of channels in file.\n", __LINE__) ;
707 check_log_buffer_or_die (file, __LINE__) ;
709 test_readf_[+ (get "data_type") +]_or_die (file, 0, test, frames, __LINE__) ;
710 for (k = 0 ; k < items ; k++)
711 if ([+ (get "error_func") +] (test [k], orig [k]))
712 { printf ("\n\nLine %d : Stereo : Incorrect sample (#%d : [+ (get "format_char") +] => [+ (get "format_char") +]).\n", __LINE__, k, orig [k], test [k]) ;
716 /* Seek to start of file. */
717 test_seek_or_die (file, 0, SEEK_SET, 0, sfinfo.channels, __LINE__) ;
719 test_readf_[+ (get "data_type") +]_or_die (file, 0, test, 2, __LINE__) ;
720 for (k = 0 ; k < 4 ; k++)
721 if ([+ (get "error_func") +] (test [k], orig [k]))
722 { printf ("\n\nLine %d : Stereo : Incorrect sample (#%d : [+ (get "format_char") +] => [+ (get "format_char") +]).\n", __LINE__, k, orig [k], test [k]) ;
726 /* Seek to offset from start of file. */
727 test_seek_or_die (file, 10, SEEK_SET, 10, sfinfo.channels, __LINE__) ;
729 /* Check for errors here. */
731 { printf ("Line %d: Should NOT return an error.\n", __LINE__) ;
732 puts (sf_strerror (file)) ;
736 if (sf_read_[+ (get "data_type") +] (file, test, 1) > 0)
737 { printf ("Line %d: Should return 0.\n", __LINE__) ;
741 if (! sf_error (file))
742 { printf ("Line %d: Should return an error.\n", __LINE__) ;
745 /*-----------------------*/
747 test_readf_[+ (get "data_type") +]_or_die (file, 0, test + 10, 2, __LINE__) ;
748 for (k = 20 ; k < 24 ; k++)
749 if ([+ (get "error_func") +] (test [k], orig [k]))
750 { printf ("\n\nLine %d : Stereo : Incorrect sample (#%d : [+ (get "format_char") +] => [+ (get "format_char") +]).\n", __LINE__, k, orig [k], test [k]) ;
754 /* Seek to offset from current position. */
755 test_seek_or_die (file, 8, SEEK_CUR, 20, sfinfo.channels, __LINE__) ;
757 test_readf_[+ (get "data_type") +]_or_die (file, 0, test + 20, 2, __LINE__) ;
758 for (k = 40 ; k < 44 ; k++)
759 if ([+ (get "error_func") +] (test [k], orig [k]))
760 { printf ("\n\nLine %d : Stereo : Incorrect sample (#%d : [+ (get "format_char") +] => [+ (get "format_char") +]).\n", __LINE__, k, orig [k], test [k]) ;
764 /* Seek to offset from end of file. */
765 test_seek_or_die (file, -1 * (sfinfo.frames - 10), SEEK_END, 10, sfinfo.channels, __LINE__) ;
767 test_readf_[+ (get "data_type") +]_or_die (file, 0, test + 20, 2, __LINE__) ;
768 for (k = 20 ; k < 24 ; k++)
769 if ([+ (get "error_func") +] (test [k], orig [k]))
770 { printf ("\n\nLine %d : Stereo : Incorrect sample (#%d : [+ (get "format_char") +] => [+ (get "format_char") +]).\n", __LINE__, k, orig [k], test [k]) ;
775 } /* stereo_[+ (get "type_name") +]_test */
778 mono_rdwr_[+ (get "type_name") +]_test (const char *filename, int format, int long_file_ok, int allow_fd)
781 [+ (get "data_type") +] *orig, *test ;
784 orig = orig_data.[+ (get "data_field") +] ;
785 test = test_data.[+ (get "data_field") +] ;
787 sfinfo.samplerate = SAMPLE_RATE ;
788 sfinfo.frames = DATA_LENGTH ;
789 sfinfo.channels = 1 ;
790 sfinfo.format = format ;
792 if ((format & SF_FORMAT_TYPEMASK) == SF_FORMAT_RAW
793 || (format & SF_FORMAT_TYPEMASK) == SF_FORMAT_AU
794 || (format & SF_FORMAT_TYPEMASK) == SF_FORMAT_SD2)
797 { /* Create a short file. */
798 create_short_file (filename) ;
800 /* Opening a already existing short file (ie invalid header) RDWR is disallowed.
801 ** If this returns a valif pointer sf_open() screwed up.
803 if ((file = sf_open (filename, SFM_RDWR, &sfinfo)))
804 { printf ("\n\nLine %d: sf_open should (SFM_RDWR) have failed but didn't.\n", __LINE__) ;
808 /* Truncate the file to zero bytes. */
809 if (truncate (filename, 0) < 0)
810 { printf ("\n\nLine %d: truncate (%s) failed", __LINE__, filename) ;
816 /* Opening a zero length file RDWR is allowed, but the SF_INFO struct must contain
817 ** all the usual data required when opening the file in WRITE mode.
819 sfinfo.samplerate = SAMPLE_RATE ;
820 sfinfo.frames = DATA_LENGTH ;
821 sfinfo.channels = 1 ;
822 sfinfo.format = format ;
824 file = test_open_file_or_die (filename, SFM_RDWR, &sfinfo, allow_fd, __LINE__) ;
826 /* Do 3 writes followed by reads. After each, check the data and the current
827 ** read and write offsets.
829 for (pass = 1 ; pass <= 3 ; pass ++)
830 { orig [20] = pass * 2 ;
832 /* Write some data. */
833 test_write_[+ (get "data_type") +]_or_die (file, pass, orig, DATA_LENGTH, __LINE__) ;
835 test_read_write_position_or_die (file, __LINE__, pass, (pass - 1) * DATA_LENGTH, pass * DATA_LENGTH) ;
837 /* Read what we just wrote. */
838 test_read_[+ (get "data_type") +]_or_die (file, 0, test, DATA_LENGTH, __LINE__) ;
840 /* Check the data. */
841 for (k = 0 ; k < DATA_LENGTH ; k++)
842 if ([+ (get "error_func") +] (orig [k], test [k]))
843 { printf ("\n\nLine %d (pass %d) A : Error at sample %d ([+ (get "format_char") +] => [+ (get "format_char") +]).\n", __LINE__, pass, k, orig [k], test [k]) ;
844 oct_save_[+ (get "data_type") +] (orig, test, DATA_LENGTH) ;
848 test_read_write_position_or_die (file, __LINE__, pass, pass * DATA_LENGTH, pass * DATA_LENGTH) ;
849 } ; /* for (pass ...) */
853 /* Open the file again to check the data. */
854 file = test_open_file_or_die (filename, SFM_RDWR, &sfinfo, allow_fd, __LINE__) ;
856 if (sfinfo.format != format)
857 { printf ("\n\nLine %d : Returned format incorrect (0x%08X => 0x%08X).\n", __LINE__, format, sfinfo.format) ;
861 if (sfinfo.frames < 3 * DATA_LENGTH)
862 { printf ("\n\nLine %d : Not enough frames in file. (%ld < %d)\n", __LINE__, SF_COUNT_TO_LONG (sfinfo.frames), 3 * DATA_LENGTH ) ;
866 if (! long_file_ok && sfinfo.frames != 3 * DATA_LENGTH)
867 { printf ("\n\nLine %d : Incorrect number of frames in file. (%ld should be %d)\n", __LINE__, SF_COUNT_TO_LONG (sfinfo.frames), 3 * DATA_LENGTH ) ;
871 if (sfinfo.channels != 1)
872 { printf ("\n\nLine %d : Incorrect number of channels in file.\n", __LINE__) ;
877 test_read_write_position_or_die (file, __LINE__, 0, 0, 3 * DATA_LENGTH) ;
879 test_seek_or_die (file, 3 * DATA_LENGTH, SFM_WRITE | SEEK_SET, 3 * DATA_LENGTH, sfinfo.channels, __LINE__) ;
881 for (pass = 1 ; pass <= 3 ; pass ++)
882 { orig [20] = pass * 2 ;
884 test_read_write_position_or_die (file, __LINE__, pass, (pass - 1) * DATA_LENGTH, 3 * DATA_LENGTH) ;
886 /* Read what we just wrote. */
887 test_read_[+ (get "data_type") +]_or_die (file, pass, test, DATA_LENGTH, __LINE__) ;
889 /* Check the data. */
890 for (k = 0 ; k < DATA_LENGTH ; k++)
891 if ([+ (get "error_func") +] (orig [k], test [k]))
892 { printf ("\n\nLine %d (pass %d) B : Error at sample %d ([+ (get "format_char") +] => [+ (get "format_char") +]).\n", __LINE__, pass, k, orig [k], test [k]) ;
893 oct_save_[+ (get "data_type") +] (orig, test, DATA_LENGTH) ;
897 } ; /* for (pass ...) */
900 } /* mono_rdwr_[+ (get "data_type") +]_test */
903 new_rdwr_[+ (get "type_name") +]_test (const char *filename, int format, int allow_fd)
904 { SNDFILE *wfile, *rwfile ;
906 [+ (get "data_type") +] *orig, *test ;
909 orig = orig_data.[+ (get "data_field") +] ;
910 test = test_data.[+ (get "data_field") +] ;
912 sfinfo.samplerate = 44100 ;
913 sfinfo.frames = SILLY_WRITE_COUNT ; /* Wrong length. Library should correct this on sf_close. */
914 sfinfo.channels = 2 ;
915 sfinfo.format = format ;
917 items = DATA_LENGTH ;
918 frames = items / sfinfo.channels ;
920 wfile = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, allow_fd, __LINE__) ;
921 sf_command (wfile, SFC_SET_UPDATE_HEADER_AUTO, NULL, SF_TRUE) ;
922 test_writef_[+ (get "data_type") +]_or_die (wfile, 1, orig, frames, __LINE__) ;
923 sf_write_sync (wfile) ;
924 test_writef_[+ (get "data_type") +]_or_die (wfile, 2, orig, frames, __LINE__) ;
925 sf_write_sync (wfile) ;
927 rwfile = test_open_file_or_die (filename, SFM_RDWR, &sfinfo, allow_fd, __LINE__) ;
928 if (sfinfo.frames != 2 * frames)
929 { printf ("\n\nLine %d : incorrect number of frames in file (%ld should be %d)\n\n", __LINE__, SF_COUNT_TO_LONG (sfinfo.frames), 2 * frames) ;
933 test_writef_[+ (get "data_type") +]_or_die (wfile, 3, orig, frames, __LINE__) ;
935 test_readf_[+ (get "data_type") +]_or_die (rwfile, 1, test, frames, __LINE__) ;
936 test_readf_[+ (get "data_type") +]_or_die (rwfile, 2, test, frames, __LINE__) ;
940 } /* new_rdwr_[+ (get "type_name") +]_test */
942 [+ ENDFOR data_type +]
944 /*----------------------------------------------------------------------------------------
948 empty_file_test (const char *filename, int format)
953 /* Sd2 files cannot be opened from an existing file descriptor. */
954 allow_fd = ((format & SF_FORMAT_TYPEMASK) == SF_FORMAT_SD2) ? SF_FALSE : SF_TRUE ;
956 print_test_name ("empty_file_test", filename) ;
960 info.samplerate = 48000 ;
962 info.format = format ;
964 if (sf_format_check (&info) == SF_FALSE)
965 { info.channels = 1 ;
966 if (sf_format_check (&info) == SF_FALSE)
967 { puts ("invalid file format") ;
972 /* Create an empty file. */
973 file = test_open_file_or_die (filename, SFM_WRITE, &info, allow_fd, __LINE__) ;
976 /* Open for read and check the length. */
977 file = test_open_file_or_die (filename, SFM_READ, &info, allow_fd, __LINE__) ;
979 if (SF_COUNT_TO_LONG (info.frames) != 0)
980 { printf ("\n\nError : frame count (%ld) should be zero.\n", SF_COUNT_TO_LONG (info.frames)) ;
986 /* Open for read/write and check the length. */
987 file = test_open_file_or_die (filename, SFM_RDWR, &info, allow_fd, __LINE__) ;
989 if (SF_COUNT_TO_LONG (info.frames) != 0)
990 { printf ("\n\nError : frame count (%ld) should be zero.\n", SF_COUNT_TO_LONG (info.frames)) ;
996 /* Open for read and check the length. */
997 file = test_open_file_or_die (filename, SFM_READ, &info, allow_fd, __LINE__) ;
999 if (SF_COUNT_TO_LONG (info.frames) != 0)
1000 { printf ("\n\nError : frame count (%ld) should be zero.\n", SF_COUNT_TO_LONG (info.frames)) ;
1006 check_open_file_count_or_die (__LINE__) ;
1012 } /* empty_file_test */
1015 /*----------------------------------------------------------------------------------------
1019 create_short_file (const char *filename)
1022 if (! (file = fopen (filename, "w")))
1023 { printf ("create_short_file : fopen (%s, \"w\") failed.", filename) ;
1029 fprintf (file, "This is the file data.\n") ;
1032 } /* create_short_file */
1034 #if (defined (WIN32) || defined (__WIN32))
1036 /* Win32 does not have truncate (nor does it have the POSIX function ftruncate).
1037 ** Hack somethng up here to over come this. This function can only truncate to a
1042 truncate (const char *filename, int ignored)
1047 if ((fd = open (filename, O_RDWR | O_TRUNC | O_BINARY)) < 0)
1058 multi_seek_test (const char * filename, int format)
1064 /* This test doesn't work on the following. */
1065 switch (format & SF_FORMAT_TYPEMASK)
1066 { case SF_FORMAT_RAW :
1073 memset (&info, 0, sizeof (info)) ;
1075 generate_file (filename, format, 88200) ;
1077 file = test_open_file_or_die (filename, SFM_READ, &info, SF_FALSE, __LINE__) ;
1079 for (k = 0 ; k < 10 ; k++)
1080 { pos = info.frames / (k + 2) ;
1081 test_seek_or_die (file, pos, SEEK_SET, pos, info.channels, __LINE__) ;
1085 } /* multi_seek_test */
1088 write_seek_extend_test (const char * filename, int format)
1091 short *orig, *test ;
1094 /* This test doesn't work on the following. */
1095 switch (format & SF_FORMAT_TYPEMASK)
1096 { case SF_FORMAT_FLAC :
1097 case SF_FORMAT_HTK :
1098 case SF_FORMAT_PAF :
1099 case SF_FORMAT_SDS :
1100 case SF_FORMAT_SVX :
1107 memset (&info, 0, sizeof (info)) ;
1109 info.samplerate = 48000 ;
1111 info.format = format ;
1114 exit_if_true (items > ARRAY_LEN (orig_data.s), "Line %d : Bad assumption.\n", __LINE__) ;
1116 orig = orig_data.s ;
1117 test = test_data.s ;
1119 for (k = 0 ; k < ARRAY_LEN (orig_data.s) ; k++)
1122 file = test_open_file_or_die (filename, SFM_WRITE, &info, SF_FALSE, __LINE__) ;
1123 test_write_short_or_die (file, 0, orig, items, __LINE__) ;
1125 /* Extend the file using a seek. */
1126 test_seek_or_die (file, 2 * items, SEEK_SET, 2 * items, info.channels, __LINE__) ;
1128 test_writef_short_or_die (file, 0, orig, items, __LINE__) ;
1131 file = test_open_file_or_die (filename, SFM_READ, &info, SF_FALSE, __LINE__) ;
1132 test_read_short_or_die (file, 0, test, 3 * items, __LINE__) ;
1135 /* Can't do these formats due to scaling. */
1136 switch (format & SF_FORMAT_SUBMASK)
1137 { case SF_FORMAT_PCM_S8 :
1138 case SF_FORMAT_PCM_U8 :
1144 for (k = 0 ; k < items ; k++)
1145 { exit_if_true (test [k] != 0x3fff, "Line %d : test [%d] == %d, should be 0x3fff.\n", __LINE__, k, test [k]) ;
1146 exit_if_true (test [items + k] != 0, "Line %d : test [%d] == %d, should be 0.\n", __LINE__, items + k, test [items + k]) ;
1147 exit_if_true (test [2 * items + k] != 0x3fff, "Line %d : test [%d] == %d, should be 0x3fff.\n", __LINE__, 2 * items + k, test [2 * items + k]) ;
1151 } /* write_seek_extend_test */