1 [+ AutoGen5 template c +]
3 ** Copyright (C) 1999-2011 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_FALSE) ;
349 pcm_test_short ("short.sds" , SF_FORMAT_SDS | SF_FORMAT_PCM_16, SF_FALSE) ;
350 pcm_test_24bit ("24bit.sds" , SF_FORMAT_SDS | SF_FORMAT_PCM_24, SF_FALSE) ;
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 ;
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") +] ;
454 /* Make this a macro so gdb steps over it in one go. */
455 CONVERT_DATA (k, DATA_LENGTH, orig, orig_data.d) ;
457 /* Some test broken out here. */
459 mono_[+ (get "type_name") +]_test (filename, format, long_file_ok, allow_fd) ;
461 /* Sub format DWVW does not allow seeking. */
462 if ((format & SF_FORMAT_SUBMASK) == SF_FORMAT_DWVW_16 ||
463 (format & SF_FORMAT_SUBMASK) == SF_FORMAT_DWVW_24)
464 { unlink (filename) ;
465 printf ("no seek : ok\n") ;
469 if ((format & SF_FORMAT_TYPEMASK) != SF_FORMAT_FLAC)
470 mono_rdwr_[+ (get "type_name") +]_test (filename, format, long_file_ok, allow_fd) ;
472 /* If the format doesn't support stereo we're done. */
473 sfinfo.channels = 2 ;
474 if (sf_format_check (&sfinfo) == 0)
475 { unlink (filename) ;
476 puts ("no stereo : ok") ;
480 stereo_[+ (get "type_name") +]_test (filename, format, long_file_ok, allow_fd) ;
482 /* New read/write test. Not sure if this is needed yet. */
484 if ((format & SF_FORMAT_TYPEMASK) != SF_FORMAT_PAF &&
485 (format & SF_FORMAT_TYPEMASK) != SF_FORMAT_VOC &&
486 (format & SF_FORMAT_TYPEMASK) != SF_FORMAT_FLAC)
487 new_rdwr_[+ (get "type_name") +]_test (filename, format, allow_fd) ;
489 delete_file (format, filename) ;
493 } /* pcm_test_[+ (get "type_name") +] */
496 mono_[+ (get "type_name") +]_test (const char *filename, int format, int long_file_ok, int allow_fd)
499 [+ (get "data_type") +] *orig, *test ;
503 sfinfo.samplerate = 44100 ;
504 sfinfo.frames = SILLY_WRITE_COUNT ; /* Wrong length. Library should correct this on sf_close. */
505 sfinfo.channels = 1 ;
506 sfinfo.format = format ;
508 orig = orig_data.[+ (get "data_field") +] ;
509 test = test_data.[+ (get "data_field") +] ;
511 items = DATA_LENGTH ;
513 file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, allow_fd, __LINE__) ;
515 sf_set_string (file, SF_STR_ARTIST, "Your name here") ;
517 test_write_[+ (get "data_type") +]_or_die (file, 0, orig, items, __LINE__) ;
518 sf_write_sync (file) ;
519 test_write_[+ (get "data_type") +]_or_die (file, 0, orig, items, __LINE__) ;
520 sf_write_sync (file) ;
522 /* Add non-audio data after the audio. */
523 sf_set_string (file, SF_STR_COPYRIGHT, "Copyright (c) 2003") ;
527 memset (test, 0, items * sizeof ([+ (get "data_type") +])) ;
529 if ((format & SF_FORMAT_TYPEMASK) != SF_FORMAT_RAW)
530 memset (&sfinfo, 0, sizeof (sfinfo)) ;
532 file = test_open_file_or_die (filename, SFM_READ, &sfinfo, allow_fd, __LINE__) ;
534 if (sfinfo.format != format)
535 { printf ("\n\nLine %d : Mono : Returned format incorrect (0x%08X => 0x%08X).\n", __LINE__, format, sfinfo.format) ;
539 if (sfinfo.frames < 2 * items)
540 { 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) ;
544 if (! long_file_ok && sfinfo.frames > 2 * items)
545 { 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) ;
549 if (sfinfo.channels != 1)
550 { printf ("\n\nLine %d : Mono : Incorrect number of channels in file.\n", __LINE__) ;
554 check_log_buffer_or_die (file, __LINE__) ;
556 test_read_[+ (get "data_type") +]_or_die (file, 0, test, items, __LINE__) ;
557 for (k = 0 ; k < items ; k++)
558 if ([+ (get "error_func") +] (orig [k], test [k]))
559 { printf ("\n\nLine %d: Mono : Incorrect sample A (#%d : [+ (get "format_char") +] => [+ (get "format_char") +]).\n", __LINE__, k, orig [k], test [k]) ;
560 oct_save_[+ (get "data_type") +] (orig, test, items) ;
564 /* Seek to start of file. */
565 test_seek_or_die (file, 0, SEEK_SET, 0, sfinfo.channels, __LINE__) ;
567 test_read_[+ (get "data_type") +]_or_die (file, 0, test, 4, __LINE__) ;
568 for (k = 0 ; k < 4 ; k++)
569 if ([+ (get "error_func") +] (orig [k], test [k]))
570 { printf ("\n\nLine %d : Mono : Incorrect sample A (#%d : [+ (get "format_char") +] => [+ (get "format_char") +]).\n", __LINE__, k, orig [k], test [k]) ;
574 if ((format & SF_FORMAT_SUBMASK) == SF_FORMAT_DWVW_16 ||
575 (format & SF_FORMAT_SUBMASK) == SF_FORMAT_DWVW_24)
578 printf ("no seek : ") ;
582 /* Seek to offset from start of file. */
583 test_seek_or_die (file, items + 10, SEEK_SET, items + 10, sfinfo.channels, __LINE__) ;
585 test_read_[+ (get "data_type") +]_or_die (file, 0, test + 10, 4, __LINE__) ;
586 for (k = 10 ; k < 14 ; k++)
587 if ([+ (get "error_func") +] (orig [k], test [k]))
588 { printf ("\n\nLine %d : Mono : Incorrect sample A (#%d : [+ (get "format_char") +] => [+ (get "format_char") +]).\n", __LINE__, k, test [k], orig [k]) ;
592 /* Seek to offset from current position. */
593 test_seek_or_die (file, 6, SEEK_CUR, items + 20, sfinfo.channels, __LINE__) ;
595 test_read_[+ (get "data_type") +]_or_die (file, 0, test + 20, 4, __LINE__) ;
596 for (k = 20 ; k < 24 ; k++)
597 if ([+ (get "error_func") +] (orig [k], test [k]))
598 { printf ("\n\nLine %d : Mono : Incorrect sample A (#%d : [+ (get "format_char") +] => [+ (get "format_char") +]).\n", __LINE__, k, test [k], orig [k]) ;
602 /* Seek to offset from end of file. */
603 test_seek_or_die (file, -1 * (sfinfo.frames - 10), SEEK_END, 10, sfinfo.channels, __LINE__) ;
605 test_read_[+ (get "data_type") +]_or_die (file, 0, test + 10, 4, __LINE__) ;
606 for (k = 10 ; k < 14 ; k++)
607 if ([+ (get "error_func") +] (orig [k], test [k]))
608 { printf ("\n\nLine %d : Mono : Incorrect sample D (#%d : [+ (get "format_char") +] => [+ (get "format_char") +]).\n", __LINE__, k, test [k], orig [k]) ;
612 /* Check read past end of file followed by sf_seek (sndfile, 0, SEEK_CUR). */
613 test_seek_or_die (file, 0, SEEK_SET, 0, sfinfo.channels, __LINE__) ;
616 while (count < sfinfo.frames)
617 count += sf_read_[+ (get "data_type") +] (file, test, 311) ;
619 /* Check that no error has occurred. */
621 { printf ("\n\nLine %d : Mono : error where there shouldn't have been one.\n", __LINE__) ;
622 puts (sf_strerror (file)) ;
626 /* Check that we haven't read beyond EOF. */
627 if (count > sfinfo.frames)
628 { printf ("\n\nLines %d : read past end of file (%ld should be %ld)\n", __LINE__, (long) count, (long) sfinfo.frames) ;
632 test_seek_or_die (file, 0, SEEK_CUR, sfinfo.frames, sfinfo.channels, __LINE__) ;
636 multi_seek_test (filename, format) ;
637 write_seek_extend_test (filename, format) ;
639 } /* mono_[+ (get "type_name") +]_test */
642 stereo_[+ (get "type_name") +]_test (const char *filename, int format, int long_file_ok, int allow_fd)
645 [+ (get "data_type") +] *orig, *test ;
646 int k, items, frames ;
648 sfinfo.samplerate = 44100 ;
649 sfinfo.frames = SILLY_WRITE_COUNT ; /* Wrong length. Library should correct this on sf_close. */
650 sfinfo.channels = 2 ;
651 sfinfo.format = format ;
653 gen_windowed_sine_double (orig_data.d, DATA_LENGTH, [+ (get "max_val") +]) ;
655 orig = orig_data.[+ (get "data_field") +] ;
656 test = test_data.[+ (get "data_field") +] ;
658 /* Make this a macro so gdb steps over it in one go. */
659 CONVERT_DATA (k, DATA_LENGTH, orig, orig_data.d) ;
661 items = DATA_LENGTH ;
662 frames = items / sfinfo.channels ;
664 file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, allow_fd, __LINE__) ;
666 sf_set_string (file, SF_STR_ARTIST, "Your name here") ;
668 test_writef_[+ (get "data_type") +]_or_die (file, 0, orig, frames, __LINE__) ;
670 sf_set_string (file, SF_STR_COPYRIGHT, "Copyright (c) 2003") ;
674 memset (test, 0, items * sizeof ([+ (get "data_type") +])) ;
676 if ((format & SF_FORMAT_TYPEMASK) != SF_FORMAT_RAW)
677 memset (&sfinfo, 0, sizeof (sfinfo)) ;
679 file = test_open_file_or_die (filename, SFM_READ, &sfinfo, allow_fd, __LINE__) ;
681 if (sfinfo.format != format)
682 { printf ("\n\nLine %d : Stereo : Returned format incorrect (0x%08X => 0x%08X).\n",
683 __LINE__, format, sfinfo.format) ;
687 if (sfinfo.frames < frames)
688 { printf ("\n\nLine %d : Stereo : Incorrect number of frames in file (too short). (%ld should be %d)\n",
689 __LINE__, SF_COUNT_TO_LONG (sfinfo.frames), frames) ;
693 if (! long_file_ok && sfinfo.frames > frames)
694 { printf ("\n\nLine %d : Stereo : Incorrect number of frames in file (too long). (%ld should be %d)\n",
695 __LINE__, SF_COUNT_TO_LONG (sfinfo.frames), frames) ;
699 if (sfinfo.channels != 2)
700 { printf ("\n\nLine %d : Stereo : Incorrect number of channels in file.\n", __LINE__) ;
704 check_log_buffer_or_die (file, __LINE__) ;
706 test_readf_[+ (get "data_type") +]_or_die (file, 0, test, frames, __LINE__) ;
707 for (k = 0 ; k < items ; k++)
708 if ([+ (get "error_func") +] (test [k], orig [k]))
709 { printf ("\n\nLine %d : Stereo : Incorrect sample (#%d : [+ (get "format_char") +] => [+ (get "format_char") +]).\n", __LINE__, k, orig [k], test [k]) ;
713 /* Seek to start of file. */
714 test_seek_or_die (file, 0, SEEK_SET, 0, sfinfo.channels, __LINE__) ;
716 test_readf_[+ (get "data_type") +]_or_die (file, 0, test, 2, __LINE__) ;
717 for (k = 0 ; k < 4 ; k++)
718 if ([+ (get "error_func") +] (test [k], orig [k]))
719 { printf ("\n\nLine %d : Stereo : Incorrect sample (#%d : [+ (get "format_char") +] => [+ (get "format_char") +]).\n", __LINE__, k, orig [k], test [k]) ;
723 /* Seek to offset from start of file. */
724 test_seek_or_die (file, 10, SEEK_SET, 10, sfinfo.channels, __LINE__) ;
726 /* Check for errors here. */
728 { printf ("Line %d: Should NOT return an error.\n", __LINE__) ;
729 puts (sf_strerror (file)) ;
733 if (sf_read_[+ (get "data_type") +] (file, test, 1) > 0)
734 { printf ("Line %d: Should return 0.\n", __LINE__) ;
738 if (! sf_error (file))
739 { printf ("Line %d: Should return an error.\n", __LINE__) ;
742 /*-----------------------*/
744 test_readf_[+ (get "data_type") +]_or_die (file, 0, test + 10, 2, __LINE__) ;
745 for (k = 20 ; k < 24 ; k++)
746 if ([+ (get "error_func") +] (test [k], orig [k]))
747 { printf ("\n\nLine %d : Stereo : Incorrect sample (#%d : [+ (get "format_char") +] => [+ (get "format_char") +]).\n", __LINE__, k, orig [k], test [k]) ;
751 /* Seek to offset from current position. */
752 test_seek_or_die (file, 8, SEEK_CUR, 20, sfinfo.channels, __LINE__) ;
754 test_readf_[+ (get "data_type") +]_or_die (file, 0, test + 20, 2, __LINE__) ;
755 for (k = 40 ; k < 44 ; k++)
756 if ([+ (get "error_func") +] (test [k], orig [k]))
757 { printf ("\n\nLine %d : Stereo : Incorrect sample (#%d : [+ (get "format_char") +] => [+ (get "format_char") +]).\n", __LINE__, k, orig [k], test [k]) ;
761 /* Seek to offset from end of file. */
762 test_seek_or_die (file, -1 * (sfinfo.frames - 10), SEEK_END, 10, sfinfo.channels, __LINE__) ;
764 test_readf_[+ (get "data_type") +]_or_die (file, 0, test + 20, 2, __LINE__) ;
765 for (k = 20 ; k < 24 ; k++)
766 if ([+ (get "error_func") +] (test [k], orig [k]))
767 { printf ("\n\nLine %d : Stereo : Incorrect sample (#%d : [+ (get "format_char") +] => [+ (get "format_char") +]).\n", __LINE__, k, orig [k], test [k]) ;
772 } /* stereo_[+ (get "type_name") +]_test */
775 mono_rdwr_[+ (get "type_name") +]_test (const char *filename, int format, int long_file_ok, int allow_fd)
778 [+ (get "data_type") +] *orig, *test ;
781 orig = orig_data.[+ (get "data_field") +] ;
782 test = test_data.[+ (get "data_field") +] ;
784 sfinfo.samplerate = SAMPLE_RATE ;
785 sfinfo.frames = DATA_LENGTH ;
786 sfinfo.channels = 1 ;
787 sfinfo.format = format ;
789 if ((format & SF_FORMAT_TYPEMASK) == SF_FORMAT_RAW
790 || (format & SF_FORMAT_TYPEMASK) == SF_FORMAT_AU
791 || (format & SF_FORMAT_TYPEMASK) == SF_FORMAT_SD2)
794 { /* Create a short file. */
795 create_short_file (filename) ;
797 /* Opening a already existing short file (ie invalid header) RDWR is disallowed.
798 ** If this returns a valif pointer sf_open() screwed up.
800 if ((file = sf_open (filename, SFM_RDWR, &sfinfo)))
801 { printf ("\n\nLine %d: sf_open should (SFM_RDWR) have failed but didn't.\n", __LINE__) ;
805 /* Truncate the file to zero bytes. */
806 if (truncate (filename, 0) < 0)
807 { printf ("\n\nLine %d: truncate (%s) failed", __LINE__, filename) ;
813 /* Opening a zero length file RDWR is allowed, but the SF_INFO struct must contain
814 ** all the usual data required when opening the file in WRITE mode.
816 sfinfo.samplerate = SAMPLE_RATE ;
817 sfinfo.frames = DATA_LENGTH ;
818 sfinfo.channels = 1 ;
819 sfinfo.format = format ;
821 file = test_open_file_or_die (filename, SFM_RDWR, &sfinfo, allow_fd, __LINE__) ;
823 /* Do 3 writes followed by reads. After each, check the data and the current
824 ** read and write offsets.
826 for (pass = 1 ; pass <= 3 ; pass ++)
827 { orig [20] = pass * 2 ;
829 /* Write some data. */
830 test_write_[+ (get "data_type") +]_or_die (file, pass, orig, DATA_LENGTH, __LINE__) ;
832 test_read_write_position_or_die (file, __LINE__, pass, (pass - 1) * DATA_LENGTH, pass * DATA_LENGTH) ;
834 /* Read what we just wrote. */
835 test_read_[+ (get "data_type") +]_or_die (file, 0, test, DATA_LENGTH, __LINE__) ;
837 /* Check the data. */
838 for (k = 0 ; k < DATA_LENGTH ; k++)
839 if ([+ (get "error_func") +] (orig [k], test [k]))
840 { 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]) ;
841 oct_save_[+ (get "data_type") +] (orig, test, DATA_LENGTH) ;
845 test_read_write_position_or_die (file, __LINE__, pass, pass * DATA_LENGTH, pass * DATA_LENGTH) ;
846 } ; /* for (pass ...) */
850 /* Open the file again to check the data. */
851 file = test_open_file_or_die (filename, SFM_RDWR, &sfinfo, allow_fd, __LINE__) ;
853 if (sfinfo.format != format)
854 { printf ("\n\nLine %d : Returned format incorrect (0x%08X => 0x%08X).\n", __LINE__, format, sfinfo.format) ;
858 if (sfinfo.frames < 3 * DATA_LENGTH)
859 { printf ("\n\nLine %d : Not enough frames in file. (%ld < %d)\n", __LINE__, SF_COUNT_TO_LONG (sfinfo.frames), 3 * DATA_LENGTH ) ;
863 if (! long_file_ok && sfinfo.frames != 3 * DATA_LENGTH)
864 { 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 ) ;
868 if (sfinfo.channels != 1)
869 { printf ("\n\nLine %d : Incorrect number of channels in file.\n", __LINE__) ;
874 test_read_write_position_or_die (file, __LINE__, 0, 0, 3 * DATA_LENGTH) ;
876 test_seek_or_die (file, 3 * DATA_LENGTH, SFM_WRITE | SEEK_SET, 3 * DATA_LENGTH, sfinfo.channels, __LINE__) ;
878 for (pass = 1 ; pass <= 3 ; pass ++)
879 { orig [20] = pass * 2 ;
881 test_read_write_position_or_die (file, __LINE__, pass, (pass - 1) * DATA_LENGTH, 3 * DATA_LENGTH) ;
883 /* Read what we just wrote. */
884 test_read_[+ (get "data_type") +]_or_die (file, pass, test, DATA_LENGTH, __LINE__) ;
886 /* Check the data. */
887 for (k = 0 ; k < DATA_LENGTH ; k++)
888 if ([+ (get "error_func") +] (orig [k], test [k]))
889 { 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]) ;
890 oct_save_[+ (get "data_type") +] (orig, test, DATA_LENGTH) ;
894 } ; /* for (pass ...) */
897 } /* mono_rdwr_[+ (get "data_type") +]_test */
900 new_rdwr_[+ (get "type_name") +]_test (const char *filename, int format, int allow_fd)
901 { SNDFILE *wfile, *rwfile ;
903 [+ (get "data_type") +] *orig, *test ;
906 orig = orig_data.[+ (get "data_field") +] ;
907 test = test_data.[+ (get "data_field") +] ;
909 sfinfo.samplerate = 44100 ;
910 sfinfo.frames = SILLY_WRITE_COUNT ; /* Wrong length. Library should correct this on sf_close. */
911 sfinfo.channels = 2 ;
912 sfinfo.format = format ;
914 items = DATA_LENGTH ;
915 frames = items / sfinfo.channels ;
917 wfile = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, allow_fd, __LINE__) ;
918 sf_command (wfile, SFC_SET_UPDATE_HEADER_AUTO, NULL, SF_TRUE) ;
919 test_writef_[+ (get "data_type") +]_or_die (wfile, 1, orig, frames, __LINE__) ;
920 sf_write_sync (wfile) ;
921 test_writef_[+ (get "data_type") +]_or_die (wfile, 2, orig, frames, __LINE__) ;
922 sf_write_sync (wfile) ;
924 rwfile = test_open_file_or_die (filename, SFM_RDWR, &sfinfo, allow_fd, __LINE__) ;
925 if (sfinfo.frames != 2 * frames)
926 { 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) ;
930 test_writef_[+ (get "data_type") +]_or_die (wfile, 3, orig, frames, __LINE__) ;
932 test_readf_[+ (get "data_type") +]_or_die (rwfile, 1, test, frames, __LINE__) ;
933 test_readf_[+ (get "data_type") +]_or_die (rwfile, 2, test, frames, __LINE__) ;
937 } /* new_rdwr_[+ (get "type_name") +]_test */
939 [+ ENDFOR data_type +]
941 /*----------------------------------------------------------------------------------------
945 empty_file_test (const char *filename, int format)
950 /* Sd2 files cannot be opened from an existing file descriptor. */
951 allow_fd = ((format & SF_FORMAT_TYPEMASK) == SF_FORMAT_SD2) ? SF_FALSE : SF_TRUE ;
953 print_test_name ("empty_file_test", filename) ;
957 info.samplerate = 48000 ;
959 info.format = format ;
961 if (sf_format_check (&info) == SF_FALSE)
962 { info.channels = 1 ;
963 if (sf_format_check (&info) == SF_FALSE)
964 { puts ("invalid file format") ;
969 /* Create an empty file. */
970 file = test_open_file_or_die (filename, SFM_WRITE, &info, allow_fd, __LINE__) ;
973 /* Open for read and check the length. */
974 file = test_open_file_or_die (filename, SFM_READ, &info, allow_fd, __LINE__) ;
976 if (SF_COUNT_TO_LONG (info.frames) != 0)
977 { printf ("\n\nError : frame count (%ld) should be zero.\n", SF_COUNT_TO_LONG (info.frames)) ;
983 /* Open for read/write and check the length. */
984 file = test_open_file_or_die (filename, SFM_RDWR, &info, allow_fd, __LINE__) ;
986 if (SF_COUNT_TO_LONG (info.frames) != 0)
987 { printf ("\n\nError : frame count (%ld) should be zero.\n", SF_COUNT_TO_LONG (info.frames)) ;
993 /* Open for read and check the length. */
994 file = test_open_file_or_die (filename, SFM_READ, &info, allow_fd, __LINE__) ;
996 if (SF_COUNT_TO_LONG (info.frames) != 0)
997 { printf ("\n\nError : frame count (%ld) should be zero.\n", SF_COUNT_TO_LONG (info.frames)) ;
1003 check_open_file_count_or_die (__LINE__) ;
1009 } /* empty_file_test */
1012 /*----------------------------------------------------------------------------------------
1016 create_short_file (const char *filename)
1019 if (! (file = fopen (filename, "w")))
1020 { printf ("create_short_file : fopen (%s, \"w\") failed.", filename) ;
1026 fprintf (file, "This is the file data.\n") ;
1029 } /* create_short_file */
1031 #if (defined (WIN32) || defined (__WIN32))
1033 /* Win32 does not have truncate (nor does it have the POSIX function ftruncate).
1034 ** Hack somethng up here to over come this. This function can only truncate to a
1039 truncate (const char *filename, int ignored)
1044 if ((fd = open (filename, O_RDWR | O_TRUNC | O_BINARY)) < 0)
1055 multi_seek_test (const char * filename, int format)
1061 /* This test doesn't work on the following. */
1062 switch (format & SF_FORMAT_TYPEMASK)
1063 { case SF_FORMAT_RAW :
1070 memset (&info, 0, sizeof (info)) ;
1072 generate_file (filename, format, 88200) ;
1074 file = test_open_file_or_die (filename, SFM_READ, &info, SF_FALSE, __LINE__) ;
1076 for (k = 0 ; k < 10 ; k++)
1077 { pos = info.frames / (k + 2) ;
1078 test_seek_or_die (file, pos, SEEK_SET, pos, info.channels, __LINE__) ;
1082 } /* multi_seek_test */
1085 write_seek_extend_test (const char * filename, int format)
1088 short *orig, *test ;
1091 /* This test doesn't work on the following. */
1092 switch (format & SF_FORMAT_TYPEMASK)
1093 { case SF_FORMAT_FLAC :
1094 case SF_FORMAT_HTK :
1095 case SF_FORMAT_PAF :
1096 case SF_FORMAT_SDS :
1097 case SF_FORMAT_SVX :
1104 memset (&info, 0, sizeof (info)) ;
1106 info.samplerate = 48000 ;
1108 info.format = format ;
1111 exit_if_true (items > ARRAY_LEN (orig_data.s), "Line %d : Bad assumption.\n", __LINE__) ;
1113 orig = orig_data.s ;
1114 test = test_data.s ;
1116 for (k = 0 ; k < ARRAY_LEN (orig_data.s) ; k++)
1119 file = test_open_file_or_die (filename, SFM_WRITE, &info, SF_FALSE, __LINE__) ;
1120 test_write_short_or_die (file, 0, orig, items, __LINE__) ;
1122 /* Extend the file using a seek. */
1123 test_seek_or_die (file, 2 * items, SEEK_SET, 2 * items, info.channels, __LINE__) ;
1125 test_writef_short_or_die (file, 0, orig, items, __LINE__) ;
1128 file = test_open_file_or_die (filename, SFM_READ, &info, SF_FALSE, __LINE__) ;
1129 test_read_short_or_die (file, 0, test, 3 * items, __LINE__) ;
1132 /* Can't do these formats due to scaling. */
1133 switch (format & SF_FORMAT_SUBMASK)
1134 { case SF_FORMAT_PCM_S8 :
1135 case SF_FORMAT_PCM_U8 :
1141 for (k = 0 ; k < items ; k++)
1142 { exit_if_true (test [k] != 0x3fff, "Line %d : test [%d] == %d, should be 0x3fff.\n", __LINE__, k, test [k]) ;
1143 exit_if_true (test [items + k] != 0, "Line %d : test [%d] == %d, should be 0.\n", __LINE__, items + k, test [items + k]) ;
1144 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]) ;
1148 } /* write_seek_extend_test */