2 ** Copyright (C) 1999-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.
31 #if (defined (WIN32) || defined (_WIN32))
33 static int truncate (const char *filename
, int ignored
) ;
41 #define SAMPLE_RATE 11025
42 #define DATA_LENGTH (1<<12)
44 #define SILLY_WRITE_COUNT (234)
46 static void pcm_test_char (const char *str
, int format
, int long_file_okz
) ;
47 static void pcm_test_short (const char *str
, int format
, int long_file_okz
) ;
48 static void pcm_test_24bit (const char *str
, int format
, int long_file_okz
) ;
49 static void pcm_test_int (const char *str
, int format
, int long_file_okz
) ;
50 static void pcm_test_float (const char *str
, int format
, int long_file_okz
) ;
51 static void pcm_test_double (const char *str
, int format
, int long_file_okz
) ;
53 static void empty_file_test (const char *filename
, int format
) ;
56 { double d
[DATA_LENGTH
] ;
57 float f
[DATA_LENGTH
] ;
59 short s
[DATA_LENGTH
] ;
60 char c
[DATA_LENGTH
] ;
63 static BUFFER orig_data
;
64 static BUFFER test_data
;
67 main (int argc
, char **argv
)
74 { printf ("Usage : %s <test>\n", argv
[0]) ;
75 printf (" Where <test> is one of the following:\n") ;
76 printf (" wav - test WAV file functions (little endian)\n") ;
77 printf (" aiff - test AIFF file functions (big endian)\n") ;
78 printf (" au - test AU file functions\n") ;
79 printf (" avr - test AVR file functions\n") ;
80 printf (" caf - test CAF file functions\n") ;
81 printf (" raw - test RAW header-less PCM file functions\n") ;
82 printf (" paf - test PAF file functions\n") ;
83 printf (" svx - test 8SVX/16SV file functions\n") ;
84 printf (" nist - test NIST Sphere file functions\n") ;
85 printf (" ircam - test IRCAM file functions\n") ;
86 printf (" voc - Create Voice file functions\n") ;
87 printf (" w64 - Sonic Foundry's W64 file functions\n") ;
88 printf (" flac - test FLAC file functions\n") ;
89 printf (" mpc2k - test MPC 2000 file functions\n") ;
90 printf (" rf64 - test RF64 file functions\n") ;
91 printf (" all - perform all tests\n") ;
95 do_all
= !strcmp (argv
[1], "all") ;
97 if (do_all
|| ! strcmp (argv
[1], "wav"))
98 { pcm_test_char ("char.wav" , SF_FORMAT_WAV
| SF_FORMAT_PCM_U8
, SF_FALSE
) ;
99 pcm_test_short ("short.wav" , SF_FORMAT_WAV
| SF_FORMAT_PCM_16
, SF_FALSE
) ;
100 pcm_test_24bit ("24bit.wav" , SF_FORMAT_WAV
| SF_FORMAT_PCM_24
, SF_FALSE
) ;
101 pcm_test_int ("int.wav" , SF_FORMAT_WAV
| SF_FORMAT_PCM_32
, SF_FALSE
) ;
103 pcm_test_char ("char.rifx" , SF_ENDIAN_BIG
| SF_FORMAT_WAV
| SF_FORMAT_PCM_U8
, SF_FALSE
) ;
104 pcm_test_short ("short.rifx" , SF_ENDIAN_BIG
| SF_FORMAT_WAV
| SF_FORMAT_PCM_16
, SF_FALSE
) ;
105 pcm_test_24bit ("24bit.rifx" , SF_ENDIAN_BIG
| SF_FORMAT_WAV
| SF_FORMAT_PCM_24
, SF_FALSE
) ;
106 pcm_test_int ("int.rifx" , SF_ENDIAN_BIG
| SF_FORMAT_WAV
| SF_FORMAT_PCM_32
, SF_FALSE
) ;
108 pcm_test_24bit ("24bit.wavex" , SF_FORMAT_WAVEX
| SF_FORMAT_PCM_24
, SF_FALSE
) ;
109 pcm_test_int ("int.wavex" , SF_FORMAT_WAVEX
| SF_FORMAT_PCM_32
, SF_FALSE
) ;
111 /* Lite remove start */
112 pcm_test_float ("float.wav" , SF_FORMAT_WAV
| SF_FORMAT_FLOAT
, SF_FALSE
) ;
113 pcm_test_double ("double.wav" , SF_FORMAT_WAV
| SF_FORMAT_DOUBLE
, SF_FALSE
) ;
115 pcm_test_float ("float.rifx" , SF_ENDIAN_BIG
| SF_FORMAT_WAV
| SF_FORMAT_FLOAT
, SF_FALSE
) ;
116 pcm_test_double ("double.rifx" , SF_ENDIAN_BIG
| SF_FORMAT_WAV
| SF_FORMAT_DOUBLE
, SF_FALSE
) ;
118 pcm_test_float ("float.wavex" , SF_FORMAT_WAVEX
| SF_FORMAT_FLOAT
, SF_FALSE
) ;
119 pcm_test_double ("double.wavex" , SF_FORMAT_WAVEX
| SF_FORMAT_DOUBLE
, SF_FALSE
) ;
120 /* Lite remove end */
122 empty_file_test ("empty_char.wav", SF_FORMAT_WAV
| SF_FORMAT_PCM_U8
) ;
123 empty_file_test ("empty_short.wav", SF_FORMAT_WAV
| SF_FORMAT_PCM_16
) ;
124 empty_file_test ("empty_float.wav", SF_FORMAT_WAV
| SF_FORMAT_FLOAT
) ;
129 if (do_all
|| ! strcmp (argv
[1], "aiff"))
130 { pcm_test_char ("char_u8.aiff" , SF_FORMAT_AIFF
| SF_FORMAT_PCM_U8
, SF_FALSE
) ;
131 pcm_test_char ("char_s8.aiff" , SF_FORMAT_AIFF
| SF_FORMAT_PCM_S8
, SF_FALSE
) ;
132 pcm_test_short ("short.aiff" , SF_FORMAT_AIFF
| SF_FORMAT_PCM_16
, SF_FALSE
) ;
133 pcm_test_24bit ("24bit.aiff" , SF_FORMAT_AIFF
| SF_FORMAT_PCM_24
, SF_FALSE
) ;
134 pcm_test_int ("int.aiff" , SF_FORMAT_AIFF
| SF_FORMAT_PCM_32
, SF_FALSE
) ;
136 pcm_test_short ("short_sowt.aifc" , SF_ENDIAN_LITTLE
| SF_FORMAT_AIFF
| SF_FORMAT_PCM_16
, SF_FALSE
) ;
137 pcm_test_24bit ("24bit_sowt.aifc" , SF_ENDIAN_LITTLE
| SF_FORMAT_AIFF
| SF_FORMAT_PCM_24
, SF_FALSE
) ;
138 pcm_test_int ("int_sowt.aifc" , SF_ENDIAN_LITTLE
| SF_FORMAT_AIFF
| SF_FORMAT_PCM_32
, SF_FALSE
) ;
140 pcm_test_short ("short_twos.aifc" , SF_ENDIAN_BIG
| SF_FORMAT_AIFF
| SF_FORMAT_PCM_16
, SF_FALSE
) ;
141 pcm_test_24bit ("24bit_twos.aifc" , SF_ENDIAN_BIG
| SF_FORMAT_AIFF
| SF_FORMAT_PCM_24
, SF_FALSE
) ;
142 pcm_test_int ("int_twos.aifc" , SF_ENDIAN_BIG
| SF_FORMAT_AIFF
| SF_FORMAT_PCM_32
, SF_FALSE
) ;
144 /* Lite remove start */
145 pcm_test_short ("dwvw16.aifc", SF_FORMAT_AIFF
| SF_FORMAT_DWVW_16
, SF_TRUE
) ;
146 pcm_test_24bit ("dwvw24.aifc", SF_FORMAT_AIFF
| SF_FORMAT_DWVW_24
, SF_TRUE
) ;
148 pcm_test_float ("float.aifc" , SF_FORMAT_AIFF
| SF_FORMAT_FLOAT
, SF_FALSE
) ;
149 pcm_test_double ("double.aifc" , SF_FORMAT_AIFF
| SF_FORMAT_DOUBLE
, SF_FALSE
) ;
150 /* Lite remove end */
152 empty_file_test ("empty_char.aiff", SF_FORMAT_AIFF
| SF_FORMAT_PCM_U8
) ;
153 empty_file_test ("empty_short.aiff", SF_FORMAT_AIFF
| SF_FORMAT_PCM_16
) ;
154 empty_file_test ("empty_float.aiff", SF_FORMAT_AIFF
| SF_FORMAT_FLOAT
) ;
159 if (do_all
|| ! strcmp (argv
[1], "au"))
160 { pcm_test_char ("char.au" , SF_FORMAT_AU
| SF_FORMAT_PCM_S8
, SF_FALSE
) ;
161 pcm_test_short ("short.au" , SF_FORMAT_AU
| SF_FORMAT_PCM_16
, SF_FALSE
) ;
162 pcm_test_24bit ("24bit.au" , SF_FORMAT_AU
| SF_FORMAT_PCM_24
, SF_FALSE
) ;
163 pcm_test_int ("int.au" , SF_FORMAT_AU
| SF_FORMAT_PCM_32
, SF_FALSE
) ;
164 /* Lite remove start */
165 pcm_test_float ("float.au" , SF_FORMAT_AU
| SF_FORMAT_FLOAT
, SF_FALSE
) ;
166 pcm_test_double ("double.au", SF_FORMAT_AU
| SF_FORMAT_DOUBLE
, SF_FALSE
) ;
167 /* Lite remove end */
169 pcm_test_char ("char_le.au" , SF_ENDIAN_LITTLE
| SF_FORMAT_AU
| SF_FORMAT_PCM_S8
, SF_FALSE
) ;
170 pcm_test_short ("short_le.au" , SF_ENDIAN_LITTLE
| SF_FORMAT_AU
| SF_FORMAT_PCM_16
, SF_FALSE
) ;
171 pcm_test_24bit ("24bit_le.au" , SF_ENDIAN_LITTLE
| SF_FORMAT_AU
| SF_FORMAT_PCM_24
, SF_FALSE
) ;
172 pcm_test_int ("int_le.au" , SF_ENDIAN_LITTLE
| SF_FORMAT_AU
| SF_FORMAT_PCM_32
, SF_FALSE
) ;
173 /* Lite remove start */
174 pcm_test_float ("float_le.au" , SF_ENDIAN_LITTLE
| SF_FORMAT_AU
| SF_FORMAT_FLOAT
, SF_FALSE
) ;
175 pcm_test_double ("double_le.au" , SF_ENDIAN_LITTLE
| SF_FORMAT_AU
| SF_FORMAT_DOUBLE
, SF_FALSE
) ;
176 /* Lite remove end */
180 if (do_all
|| ! strcmp (argv
[1], "caf"))
181 { pcm_test_char ("char.caf" , SF_FORMAT_CAF
| SF_FORMAT_PCM_S8
, SF_FALSE
) ;
182 pcm_test_short ("short.caf" , SF_FORMAT_CAF
| SF_FORMAT_PCM_16
, SF_FALSE
) ;
183 pcm_test_24bit ("24bit.caf" , SF_FORMAT_CAF
| SF_FORMAT_PCM_24
, SF_FALSE
) ;
184 pcm_test_int ("int.caf" , SF_FORMAT_CAF
| SF_FORMAT_PCM_32
, SF_FALSE
) ;
185 /* Lite remove start */
186 pcm_test_float ("float.caf" , SF_FORMAT_CAF
| SF_FORMAT_FLOAT
, SF_FALSE
) ;
187 pcm_test_double ("double.caf" , SF_FORMAT_CAF
| SF_FORMAT_DOUBLE
, SF_FALSE
) ;
188 /* Lite remove end */
190 pcm_test_short ("short_le.caf" , SF_ENDIAN_LITTLE
| SF_FORMAT_CAF
| SF_FORMAT_PCM_16
, SF_FALSE
) ;
191 pcm_test_24bit ("24bit_le.caf" , SF_ENDIAN_LITTLE
| SF_FORMAT_CAF
| SF_FORMAT_PCM_24
, SF_FALSE
) ;
192 pcm_test_int ("int_le.caf" , SF_ENDIAN_LITTLE
| SF_FORMAT_CAF
| SF_FORMAT_PCM_32
, SF_FALSE
) ;
193 /* Lite remove start */
194 pcm_test_float ("float_le.caf" , SF_ENDIAN_LITTLE
| SF_FORMAT_CAF
| SF_FORMAT_FLOAT
, SF_FALSE
) ;
195 pcm_test_double ("double_le.caf", SF_ENDIAN_LITTLE
| SF_FORMAT_CAF
| SF_FORMAT_DOUBLE
, SF_FALSE
) ;
196 /* Lite remove end */
200 if (do_all
|| ! strcmp (argv
[1], "raw"))
201 { pcm_test_char ("char_s8.raw" , SF_FORMAT_RAW
| SF_FORMAT_PCM_S8
, SF_FALSE
) ;
202 pcm_test_char ("char_u8.raw" , SF_FORMAT_RAW
| SF_FORMAT_PCM_U8
, SF_FALSE
) ;
204 pcm_test_short ("short_le.raw" , SF_ENDIAN_LITTLE
| SF_FORMAT_RAW
| SF_FORMAT_PCM_16
, SF_FALSE
) ;
205 pcm_test_short ("short_be.raw" , SF_ENDIAN_BIG
| SF_FORMAT_RAW
| SF_FORMAT_PCM_16
, SF_FALSE
) ;
206 pcm_test_24bit ("24bit_le.raw" , SF_ENDIAN_LITTLE
| SF_FORMAT_RAW
| SF_FORMAT_PCM_24
, SF_FALSE
) ;
207 pcm_test_24bit ("24bit_be.raw" , SF_ENDIAN_BIG
| SF_FORMAT_RAW
| SF_FORMAT_PCM_24
, SF_FALSE
) ;
208 pcm_test_int ("int_le.raw" , SF_ENDIAN_LITTLE
| SF_FORMAT_RAW
| SF_FORMAT_PCM_32
, SF_FALSE
) ;
209 pcm_test_int ("int_be.raw" , SF_ENDIAN_BIG
| SF_FORMAT_RAW
| SF_FORMAT_PCM_32
, SF_FALSE
) ;
211 /* Lite remove start */
212 pcm_test_float ("float_le.raw" , SF_ENDIAN_LITTLE
| SF_FORMAT_RAW
| SF_FORMAT_FLOAT
, SF_FALSE
) ;
213 pcm_test_float ("float_be.raw" , SF_ENDIAN_BIG
| SF_FORMAT_RAW
| SF_FORMAT_FLOAT
, SF_FALSE
) ;
215 pcm_test_double ("double_le.raw", SF_ENDIAN_LITTLE
| SF_FORMAT_RAW
| SF_FORMAT_DOUBLE
, SF_FALSE
) ;
216 pcm_test_double ("double_be.raw", SF_ENDIAN_BIG
| SF_FORMAT_RAW
| SF_FORMAT_DOUBLE
, SF_FALSE
) ;
217 /* Lite remove end */
221 /* Lite remove start */
222 if (do_all
|| ! strcmp (argv
[1], "paf"))
223 { pcm_test_char ("char_le.paf", SF_ENDIAN_LITTLE
| SF_FORMAT_PAF
| SF_FORMAT_PCM_S8
, SF_FALSE
) ;
224 pcm_test_char ("char_be.paf", SF_ENDIAN_BIG
| SF_FORMAT_PAF
| SF_FORMAT_PCM_S8
, SF_FALSE
) ;
225 pcm_test_short ("short_le.paf", SF_ENDIAN_LITTLE
| SF_FORMAT_PAF
| SF_FORMAT_PCM_16
, SF_FALSE
) ;
226 pcm_test_short ("short_be.paf", SF_ENDIAN_BIG
| SF_FORMAT_PAF
| SF_FORMAT_PCM_16
, SF_FALSE
) ;
227 pcm_test_24bit ("24bit_le.paf", SF_ENDIAN_LITTLE
| SF_FORMAT_PAF
| SF_FORMAT_PCM_24
, SF_TRUE
) ;
228 pcm_test_24bit ("24bit_be.paf", SF_ENDIAN_BIG
| SF_FORMAT_PAF
| SF_FORMAT_PCM_24
, SF_TRUE
) ;
232 if (do_all
|| ! strcmp (argv
[1], "svx"))
233 { pcm_test_char ("char.svx" , SF_FORMAT_SVX
| SF_FORMAT_PCM_S8
, SF_FALSE
) ;
234 pcm_test_short ("short.svx", SF_FORMAT_SVX
| SF_FORMAT_PCM_16
, SF_FALSE
) ;
236 empty_file_test ("empty_char.svx", SF_FORMAT_SVX
| SF_FORMAT_PCM_S8
) ;
237 empty_file_test ("empty_short.svx", SF_FORMAT_SVX
| SF_FORMAT_PCM_16
) ;
242 if (do_all
|| ! strcmp (argv
[1], "nist"))
243 { pcm_test_short ("short_le.nist", SF_ENDIAN_LITTLE
| SF_FORMAT_NIST
| SF_FORMAT_PCM_16
, SF_FALSE
) ;
244 pcm_test_short ("short_be.nist", SF_ENDIAN_BIG
| SF_FORMAT_NIST
| SF_FORMAT_PCM_16
, SF_FALSE
) ;
245 pcm_test_24bit ("24bit_le.nist", SF_ENDIAN_LITTLE
| SF_FORMAT_NIST
| SF_FORMAT_PCM_24
, SF_FALSE
) ;
246 pcm_test_24bit ("24bit_be.nist", SF_ENDIAN_BIG
| SF_FORMAT_NIST
| SF_FORMAT_PCM_24
, SF_FALSE
) ;
247 pcm_test_int ("int_le.nist" , SF_ENDIAN_LITTLE
| SF_FORMAT_NIST
| SF_FORMAT_PCM_32
, SF_FALSE
) ;
248 pcm_test_int ("int_be.nist" , SF_ENDIAN_BIG
| SF_FORMAT_NIST
| SF_FORMAT_PCM_32
, SF_FALSE
) ;
253 if (do_all
|| ! strcmp (argv
[1], "ircam"))
254 { pcm_test_short ("short_be.ircam" , SF_ENDIAN_BIG
| SF_FORMAT_IRCAM
| SF_FORMAT_PCM_16
, SF_FALSE
) ;
255 pcm_test_short ("short_le.ircam" , SF_ENDIAN_LITTLE
| SF_FORMAT_IRCAM
| SF_FORMAT_PCM_16
, SF_FALSE
) ;
256 pcm_test_int ("int_be.ircam" , SF_ENDIAN_BIG
| SF_FORMAT_IRCAM
| SF_FORMAT_PCM_32
, SF_FALSE
) ;
257 pcm_test_int ("int_le.ircam" , SF_ENDIAN_LITTLE
| SF_FORMAT_IRCAM
| SF_FORMAT_PCM_32
, SF_FALSE
) ;
258 pcm_test_float ("float_be.ircam" , SF_ENDIAN_BIG
| SF_FORMAT_IRCAM
| SF_FORMAT_FLOAT
, SF_FALSE
) ;
259 pcm_test_float ("float_le.ircam" , SF_ENDIAN_LITTLE
| SF_FORMAT_IRCAM
| SF_FORMAT_FLOAT
, SF_FALSE
) ;
264 if (do_all
|| ! strcmp (argv
[1], "voc"))
265 { pcm_test_char ("char.voc" , SF_FORMAT_VOC
| SF_FORMAT_PCM_U8
, SF_FALSE
) ;
266 pcm_test_short ("short.voc", SF_FORMAT_VOC
| SF_FORMAT_PCM_16
, SF_FALSE
) ;
271 if (do_all
|| ! strcmp (argv
[1], "mat4"))
272 { pcm_test_short ("short_be.mat4" , SF_ENDIAN_BIG
| SF_FORMAT_MAT4
| SF_FORMAT_PCM_16
, SF_FALSE
) ;
273 pcm_test_short ("short_le.mat4" , SF_ENDIAN_LITTLE
| SF_FORMAT_MAT4
| SF_FORMAT_PCM_16
, SF_FALSE
) ;
274 pcm_test_int ("int_be.mat4" , SF_ENDIAN_BIG
| SF_FORMAT_MAT4
| SF_FORMAT_PCM_32
, SF_FALSE
) ;
275 pcm_test_int ("int_le.mat4" , SF_ENDIAN_LITTLE
| SF_FORMAT_MAT4
| SF_FORMAT_PCM_32
, SF_FALSE
) ;
276 pcm_test_float ("float_be.mat4" , SF_ENDIAN_BIG
| SF_FORMAT_MAT4
| SF_FORMAT_FLOAT
, SF_FALSE
) ;
277 pcm_test_float ("float_le.mat4" , SF_ENDIAN_LITTLE
| SF_FORMAT_MAT4
| SF_FORMAT_FLOAT
, SF_FALSE
) ;
278 pcm_test_double ("double_be.mat4" , SF_ENDIAN_BIG
| SF_FORMAT_MAT4
| SF_FORMAT_DOUBLE
, SF_FALSE
) ;
279 pcm_test_double ("double_le.mat4" , SF_ENDIAN_LITTLE
| SF_FORMAT_MAT4
| SF_FORMAT_DOUBLE
, SF_FALSE
) ;
281 empty_file_test ("empty_short.mat4", SF_FORMAT_MAT4
| SF_FORMAT_PCM_16
) ;
282 empty_file_test ("empty_float.mat4", SF_FORMAT_MAT4
| SF_FORMAT_FLOAT
) ;
286 if (do_all
|| ! strcmp (argv
[1], "mat5"))
287 { pcm_test_char ("char_be.mat5" , SF_ENDIAN_BIG
| SF_FORMAT_MAT5
| SF_FORMAT_PCM_U8
, SF_FALSE
) ;
288 pcm_test_char ("char_le.mat5" , SF_ENDIAN_LITTLE
| SF_FORMAT_MAT5
| SF_FORMAT_PCM_U8
, SF_FALSE
) ;
289 pcm_test_short ("short_be.mat5" , SF_ENDIAN_BIG
| SF_FORMAT_MAT5
| SF_FORMAT_PCM_16
, SF_FALSE
) ;
290 pcm_test_short ("short_le.mat5" , SF_ENDIAN_LITTLE
| SF_FORMAT_MAT5
| SF_FORMAT_PCM_16
, SF_FALSE
) ;
291 pcm_test_int ("int_be.mat5" , SF_ENDIAN_BIG
| SF_FORMAT_MAT5
| SF_FORMAT_PCM_32
, SF_FALSE
) ;
292 pcm_test_int ("int_le.mat5" , SF_ENDIAN_LITTLE
| SF_FORMAT_MAT5
| SF_FORMAT_PCM_32
, SF_FALSE
) ;
293 pcm_test_float ("float_be.mat5" , SF_ENDIAN_BIG
| SF_FORMAT_MAT5
| SF_FORMAT_FLOAT
, SF_FALSE
) ;
294 pcm_test_float ("float_le.mat5" , SF_ENDIAN_LITTLE
| SF_FORMAT_MAT5
| SF_FORMAT_FLOAT
, SF_FALSE
) ;
295 pcm_test_double ("double_be.mat5" , SF_ENDIAN_BIG
| SF_FORMAT_MAT5
| SF_FORMAT_DOUBLE
, SF_FALSE
) ;
296 pcm_test_double ("double_le.mat5" , SF_ENDIAN_LITTLE
| SF_FORMAT_MAT5
| SF_FORMAT_DOUBLE
, SF_FALSE
) ;
298 increment_open_file_count () ;
300 empty_file_test ("empty_char.mat5", SF_FORMAT_MAT5
| SF_FORMAT_PCM_U8
) ;
301 empty_file_test ("empty_short.mat5", SF_FORMAT_MAT5
| SF_FORMAT_PCM_16
) ;
302 empty_file_test ("empty_float.mat5", SF_FORMAT_MAT5
| SF_FORMAT_FLOAT
) ;
307 if (do_all
|| ! strcmp (argv
[1], "pvf"))
308 { pcm_test_char ("char.pvf" , SF_FORMAT_PVF
| SF_FORMAT_PCM_S8
, SF_FALSE
) ;
309 pcm_test_short ("short.pvf", SF_FORMAT_PVF
| SF_FORMAT_PCM_16
, SF_FALSE
) ;
310 pcm_test_int ("int.pvf" , SF_FORMAT_PVF
| SF_FORMAT_PCM_32
, SF_FALSE
) ;
314 if (do_all
|| ! strcmp (argv
[1], "htk"))
315 { pcm_test_short ("short.htk", SF_FORMAT_HTK
| SF_FORMAT_PCM_16
, SF_FALSE
) ;
319 if (do_all
|| ! strcmp (argv
[1], "mpc2k"))
320 { pcm_test_short ("short.mpc", SF_FORMAT_MPC2K
| SF_FORMAT_PCM_16
, SF_FALSE
) ;
324 if (do_all
|| ! strcmp (argv
[1], "avr"))
325 { pcm_test_char ("char_u8.avr" , SF_FORMAT_AVR
| SF_FORMAT_PCM_U8
, SF_FALSE
) ;
326 pcm_test_char ("char_s8.avr" , SF_FORMAT_AVR
| SF_FORMAT_PCM_S8
, SF_FALSE
) ;
327 pcm_test_short ("short.avr" , SF_FORMAT_AVR
| SF_FORMAT_PCM_16
, SF_FALSE
) ;
330 /* Lite remove end */
332 if (do_all
|| ! strcmp (argv
[1], "w64"))
333 { pcm_test_char ("char.w64" , SF_FORMAT_W64
| SF_FORMAT_PCM_U8
, SF_FALSE
) ;
334 pcm_test_short ("short.w64" , SF_FORMAT_W64
| SF_FORMAT_PCM_16
, SF_FALSE
) ;
335 pcm_test_24bit ("24bit.w64" , SF_FORMAT_W64
| SF_FORMAT_PCM_24
, SF_FALSE
) ;
336 pcm_test_int ("int.w64" , SF_FORMAT_W64
| SF_FORMAT_PCM_32
, SF_FALSE
) ;
337 /* Lite remove start */
338 pcm_test_float ("float.w64" , SF_FORMAT_W64
| SF_FORMAT_FLOAT
, SF_FALSE
) ;
339 pcm_test_double ("double.w64" , SF_FORMAT_W64
| SF_FORMAT_DOUBLE
, SF_FALSE
) ;
340 /* Lite remove end */
342 empty_file_test ("empty_char.w64", SF_FORMAT_W64
| SF_FORMAT_PCM_U8
) ;
343 empty_file_test ("empty_short.w64", SF_FORMAT_W64
| SF_FORMAT_PCM_16
) ;
344 empty_file_test ("empty_float.w64", SF_FORMAT_W64
| SF_FORMAT_FLOAT
) ;
349 if (do_all
|| ! strcmp (argv
[1], "sds"))
350 { pcm_test_char ("char.sds" , SF_FORMAT_SDS
| SF_FORMAT_PCM_S8
, SF_FALSE
) ;
351 pcm_test_short ("short.sds" , SF_FORMAT_SDS
| SF_FORMAT_PCM_16
, SF_FALSE
) ;
352 pcm_test_24bit ("24bit.sds" , SF_FORMAT_SDS
| SF_FORMAT_PCM_24
, SF_FALSE
) ;
354 empty_file_test ("empty_char.sds", SF_FORMAT_SDS
| SF_FORMAT_PCM_S8
) ;
355 empty_file_test ("empty_short.sds", SF_FORMAT_SDS
| SF_FORMAT_PCM_16
) ;
360 if (do_all
|| ! strcmp (argv
[1], "sd2"))
361 { pcm_test_char ("char.sd2" , SF_FORMAT_SD2
| SF_FORMAT_PCM_S8
, SF_TRUE
) ;
362 pcm_test_short ("short.sd2" , SF_FORMAT_SD2
| SF_FORMAT_PCM_16
, SF_TRUE
) ;
363 pcm_test_24bit ("24bit.sd2" , SF_FORMAT_SD2
| SF_FORMAT_PCM_24
, SF_TRUE
) ;
367 if (do_all
|| ! strcmp (argv
[1], "flac"))
368 { if (HAVE_EXTERNAL_LIBS
)
369 { pcm_test_char ("char.flac" , SF_FORMAT_FLAC
| SF_FORMAT_PCM_S8
, SF_TRUE
) ;
370 pcm_test_short ("short.flac" , SF_FORMAT_FLAC
| SF_FORMAT_PCM_16
, SF_TRUE
) ;
371 pcm_test_24bit ("24bit.flac" , SF_FORMAT_FLAC
| SF_FORMAT_PCM_24
, SF_TRUE
) ;
374 puts (" No FLAC tests because FLAC support was not compiled in.") ;
378 if (do_all
|| ! strcmp (argv
[1], "rf64"))
379 { pcm_test_char ("char.rf64" , SF_FORMAT_RF64
| SF_FORMAT_PCM_U8
, SF_FALSE
) ;
380 pcm_test_short ("short.rf64" , SF_FORMAT_RF64
| SF_FORMAT_PCM_16
, SF_FALSE
) ;
381 pcm_test_24bit ("24bit.rf64" , SF_FORMAT_RF64
| SF_FORMAT_PCM_24
, SF_FALSE
) ;
382 pcm_test_int ("int.rf64" , SF_FORMAT_RF64
| SF_FORMAT_PCM_32
, SF_FALSE
) ;
384 /* Lite remove start */
385 pcm_test_float ("float.rf64" , SF_FORMAT_RF64
| SF_FORMAT_FLOAT
, SF_FALSE
) ;
386 pcm_test_double ("double.rf64" , SF_FORMAT_RF64
| SF_FORMAT_DOUBLE
, SF_FALSE
) ;
387 empty_file_test ("empty_char.rf64", SF_FORMAT_RF64
| SF_FORMAT_PCM_U8
) ;
388 empty_file_test ("empty_short.rf64", SF_FORMAT_RF64
| SF_FORMAT_PCM_16
) ;
389 empty_file_test ("empty_float.rf64", SF_FORMAT_RF64
| SF_FORMAT_FLOAT
) ;
390 /* Lite remove end */
396 { printf ("Mono : ************************************\n") ;
397 printf ("Mono : * No '%s' test defined.\n", argv
[1]) ;
398 printf ("Mono : ************************************\n") ;
402 /* Only open file descriptors should be stdin, stdout and stderr. */
403 check_open_file_count_or_die (__LINE__
) ;
408 /*============================================================================================
409 ** Helper functions and macros.
412 static void create_short_file (const char *filename
) ;
414 #define CHAR_ERROR(x,y) (abs ((x) - (y)) > 255)
415 #define INT_ERROR(x,y) (((x) - (y)) != 0)
416 #define TRIBYTE_ERROR(x,y) (abs ((x) - (y)) > 255)
417 #define FLOAT_ERROR(x,y) (fabs ((x) - (y)) > 1e-5)
419 #define CONVERT_DATA(k,len,new,orig) \
420 { for ((k) = 0 ; (k) < (len) ; (k) ++) \
421 (new) [k] = (orig) [k] ; \
425 /*======================================================================================
428 static void mono_char_test (const char *filename
, int format
, int long_file_ok
, int allow_fd
) ;
429 static void stereo_char_test (const char *filename
, int format
, int long_file_ok
, int allow_fd
) ;
430 static void mono_rdwr_char_test (const char *filename
, int format
, int long_file_ok
, int allow_fd
) ;
431 static void new_rdwr_char_test (const char *filename
, int format
, int allow_fd
) ;
432 static void multi_seek_test (const char * filename
, int format
) ;
433 static void write_seek_extend_test (const char * filename
, int format
) ;
436 pcm_test_char (const char *filename
, int format
, int long_file_ok
)
441 /* Sd2 files cannot be opened from an existing file descriptor. */
442 allow_fd
= ((format
& SF_FORMAT_TYPEMASK
) == SF_FORMAT_SD2
) ? SF_FALSE
: SF_TRUE
;
444 print_test_name ("pcm_test_char", filename
) ;
446 sfinfo
.samplerate
= 44100 ;
447 sfinfo
.frames
= SILLY_WRITE_COUNT
; /* Wrong length. Library should correct this on sf_close. */
448 sfinfo
.channels
= 1 ;
449 sfinfo
.format
= format
;
451 gen_windowed_sine_double (orig_data
.d
, DATA_LENGTH
, 32000.0) ;
455 /* Make this a macro so gdb steps over it in one go. */
456 CONVERT_DATA (k
, DATA_LENGTH
, orig
, orig_data
.d
) ;
458 /* Some test broken out here. */
460 mono_char_test (filename
, format
, long_file_ok
, allow_fd
) ;
462 /* Sub format DWVW does not allow seeking. */
463 if ((format
& SF_FORMAT_SUBMASK
) == SF_FORMAT_DWVW_16
||
464 (format
& SF_FORMAT_SUBMASK
) == SF_FORMAT_DWVW_24
)
465 { unlink (filename
) ;
466 printf ("no seek : ok\n") ;
470 if ((format
& SF_FORMAT_TYPEMASK
) != SF_FORMAT_FLAC
)
471 mono_rdwr_char_test (filename
, format
, long_file_ok
, allow_fd
) ;
473 /* If the format doesn't support stereo we're done. */
474 sfinfo
.channels
= 2 ;
475 if (sf_format_check (&sfinfo
) == 0)
476 { unlink (filename
) ;
477 puts ("no stereo : ok") ;
481 stereo_char_test (filename
, format
, long_file_ok
, allow_fd
) ;
483 /* New read/write test. Not sure if this is needed yet. */
485 if ((format
& SF_FORMAT_TYPEMASK
) != SF_FORMAT_PAF
&&
486 (format
& SF_FORMAT_TYPEMASK
) != SF_FORMAT_VOC
&&
487 (format
& SF_FORMAT_TYPEMASK
) != SF_FORMAT_FLAC
)
488 new_rdwr_char_test (filename
, format
, allow_fd
) ;
490 delete_file (format
, filename
) ;
494 } /* pcm_test_char */
497 mono_char_test (const char *filename
, int format
, int long_file_ok
, int allow_fd
)
504 sfinfo
.samplerate
= 44100 ;
505 sfinfo
.frames
= SILLY_WRITE_COUNT
; /* Wrong length. Library should correct this on sf_close. */
506 sfinfo
.channels
= 1 ;
507 sfinfo
.format
= format
;
512 items
= DATA_LENGTH
;
514 file
= test_open_file_or_die (filename
, SFM_WRITE
, &sfinfo
, allow_fd
, __LINE__
) ;
516 sf_set_string (file
, SF_STR_ARTIST
, "Your name here") ;
518 test_write_short_or_die (file
, 0, orig
, items
, __LINE__
) ;
519 sf_write_sync (file
) ;
520 test_write_short_or_die (file
, 0, orig
, items
, __LINE__
) ;
521 sf_write_sync (file
) ;
523 /* Add non-audio data after the audio. */
524 sf_set_string (file
, SF_STR_COPYRIGHT
, "Copyright (c) 2003") ;
528 memset (test
, 0, items
* sizeof (short)) ;
530 if ((format
& SF_FORMAT_TYPEMASK
) != SF_FORMAT_RAW
)
531 memset (&sfinfo
, 0, sizeof (sfinfo
)) ;
533 file
= test_open_file_or_die (filename
, SFM_READ
, &sfinfo
, allow_fd
, __LINE__
) ;
535 if (sfinfo
.format
!= format
)
536 { printf ("\n\nLine %d : Mono : Returned format incorrect (0x%08X => 0x%08X).\n", __LINE__
, format
, sfinfo
.format
) ;
540 if (sfinfo
.frames
< 2 * items
)
541 { 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
) ;
545 if (! long_file_ok
&& sfinfo
.frames
> 2 * items
)
546 { 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
) ;
550 if (sfinfo
.channels
!= 1)
551 { printf ("\n\nLine %d : Mono : Incorrect number of channels in file.\n", __LINE__
) ;
555 check_log_buffer_or_die (file
, __LINE__
) ;
557 test_read_short_or_die (file
, 0, test
, items
, __LINE__
) ;
558 for (k
= 0 ; k
< items
; k
++)
559 if (CHAR_ERROR (orig
[k
], test
[k
]))
560 { printf ("\n\nLine %d: Mono : Incorrect sample A (#%d : 0x%X => 0x%X).\n", __LINE__
, k
, orig
[k
], test
[k
]) ;
561 oct_save_short (orig
, test
, items
) ;
565 /* Seek to start of file. */
566 test_seek_or_die (file
, 0, SEEK_SET
, 0, sfinfo
.channels
, __LINE__
) ;
568 test_read_short_or_die (file
, 0, test
, 4, __LINE__
) ;
569 for (k
= 0 ; k
< 4 ; k
++)
570 if (CHAR_ERROR (orig
[k
], test
[k
]))
571 { printf ("\n\nLine %d : Mono : Incorrect sample A (#%d : 0x%X => 0x%X).\n", __LINE__
, k
, orig
[k
], test
[k
]) ;
575 if ((format
& SF_FORMAT_SUBMASK
) == SF_FORMAT_DWVW_16
||
576 (format
& SF_FORMAT_SUBMASK
) == SF_FORMAT_DWVW_24
)
579 printf ("no seek : ") ;
583 /* Seek to offset from start of file. */
584 test_seek_or_die (file
, items
+ 10, SEEK_SET
, items
+ 10, sfinfo
.channels
, __LINE__
) ;
586 test_read_short_or_die (file
, 0, test
+ 10, 4, __LINE__
) ;
587 for (k
= 10 ; k
< 14 ; k
++)
588 if (CHAR_ERROR (orig
[k
], test
[k
]))
589 { printf ("\n\nLine %d : Mono : Incorrect sample A (#%d : 0x%X => 0x%X).\n", __LINE__
, k
, test
[k
], orig
[k
]) ;
593 /* Seek to offset from current position. */
594 test_seek_or_die (file
, 6, SEEK_CUR
, items
+ 20, sfinfo
.channels
, __LINE__
) ;
596 test_read_short_or_die (file
, 0, test
+ 20, 4, __LINE__
) ;
597 for (k
= 20 ; k
< 24 ; k
++)
598 if (CHAR_ERROR (orig
[k
], test
[k
]))
599 { printf ("\n\nLine %d : Mono : Incorrect sample A (#%d : 0x%X => 0x%X).\n", __LINE__
, k
, test
[k
], orig
[k
]) ;
603 /* Seek to offset from end of file. */
604 test_seek_or_die (file
, -1 * (sfinfo
.frames
- 10), SEEK_END
, 10, sfinfo
.channels
, __LINE__
) ;
606 test_read_short_or_die (file
, 0, test
+ 10, 4, __LINE__
) ;
607 for (k
= 10 ; k
< 14 ; k
++)
608 if (CHAR_ERROR (orig
[k
], test
[k
]))
609 { printf ("\n\nLine %d : Mono : Incorrect sample D (#%d : 0x%X => 0x%X).\n", __LINE__
, k
, test
[k
], orig
[k
]) ;
613 /* Check read past end of file followed by sf_seek (sndfile, 0, SEEK_CUR). */
614 test_seek_or_die (file
, 0, SEEK_SET
, 0, sfinfo
.channels
, __LINE__
) ;
617 while (count
< sfinfo
.frames
)
618 count
+= sf_read_short (file
, test
, 311) ;
620 /* Check that no error has occurred. */
622 { printf ("\n\nLine %d : Mono : error where there shouldn't have been one.\n", __LINE__
) ;
623 puts (sf_strerror (file
)) ;
627 /* Check that we haven't read beyond EOF. */
628 if (count
> sfinfo
.frames
)
629 { printf ("\n\nLines %d : read past end of file (%ld should be %ld)\n", __LINE__
, (long) count
, (long) sfinfo
.frames
) ;
633 test_seek_or_die (file
, 0, SEEK_CUR
, sfinfo
.frames
, sfinfo
.channels
, __LINE__
) ;
637 multi_seek_test (filename
, format
) ;
638 write_seek_extend_test (filename
, format
) ;
640 } /* mono_char_test */
643 stereo_char_test (const char *filename
, int format
, int long_file_ok
, int allow_fd
)
647 int k
, items
, frames
;
649 sfinfo
.samplerate
= 44100 ;
650 sfinfo
.frames
= SILLY_WRITE_COUNT
; /* Wrong length. Library should correct this on sf_close. */
651 sfinfo
.channels
= 2 ;
652 sfinfo
.format
= format
;
654 gen_windowed_sine_double (orig_data
.d
, DATA_LENGTH
, 32000.0) ;
659 /* Make this a macro so gdb steps over it in one go. */
660 CONVERT_DATA (k
, DATA_LENGTH
, orig
, orig_data
.d
) ;
662 items
= DATA_LENGTH
;
663 frames
= items
/ sfinfo
.channels
;
665 file
= test_open_file_or_die (filename
, SFM_WRITE
, &sfinfo
, allow_fd
, __LINE__
) ;
667 sf_set_string (file
, SF_STR_ARTIST
, "Your name here") ;
669 test_writef_short_or_die (file
, 0, orig
, frames
, __LINE__
) ;
671 sf_set_string (file
, SF_STR_COPYRIGHT
, "Copyright (c) 2003") ;
675 memset (test
, 0, items
* sizeof (short)) ;
677 if ((format
& SF_FORMAT_TYPEMASK
) != SF_FORMAT_RAW
)
678 memset (&sfinfo
, 0, sizeof (sfinfo
)) ;
680 file
= test_open_file_or_die (filename
, SFM_READ
, &sfinfo
, allow_fd
, __LINE__
) ;
682 if (sfinfo
.format
!= format
)
683 { printf ("\n\nLine %d : Stereo : Returned format incorrect (0x%08X => 0x%08X).\n",
684 __LINE__
, format
, sfinfo
.format
) ;
688 if (sfinfo
.frames
< frames
)
689 { printf ("\n\nLine %d : Stereo : Incorrect number of frames in file (too short). (%ld should be %d)\n",
690 __LINE__
, SF_COUNT_TO_LONG (sfinfo
.frames
), frames
) ;
694 if (! long_file_ok
&& sfinfo
.frames
> frames
)
695 { printf ("\n\nLine %d : Stereo : Incorrect number of frames in file (too long). (%ld should be %d)\n",
696 __LINE__
, SF_COUNT_TO_LONG (sfinfo
.frames
), frames
) ;
700 if (sfinfo
.channels
!= 2)
701 { printf ("\n\nLine %d : Stereo : Incorrect number of channels in file.\n", __LINE__
) ;
705 check_log_buffer_or_die (file
, __LINE__
) ;
707 test_readf_short_or_die (file
, 0, test
, frames
, __LINE__
) ;
708 for (k
= 0 ; k
< items
; k
++)
709 if (CHAR_ERROR (test
[k
], orig
[k
]))
710 { printf ("\n\nLine %d : Stereo : Incorrect sample (#%d : 0x%X => 0x%X).\n", __LINE__
, k
, orig
[k
], test
[k
]) ;
714 /* Seek to start of file. */
715 test_seek_or_die (file
, 0, SEEK_SET
, 0, sfinfo
.channels
, __LINE__
) ;
717 test_readf_short_or_die (file
, 0, test
, 2, __LINE__
) ;
718 for (k
= 0 ; k
< 4 ; k
++)
719 if (CHAR_ERROR (test
[k
], orig
[k
]))
720 { printf ("\n\nLine %d : Stereo : Incorrect sample (#%d : 0x%X => 0x%X).\n", __LINE__
, k
, orig
[k
], test
[k
]) ;
724 /* Seek to offset from start of file. */
725 test_seek_or_die (file
, 10, SEEK_SET
, 10, sfinfo
.channels
, __LINE__
) ;
727 /* Check for errors here. */
729 { printf ("Line %d: Should NOT return an error.\n", __LINE__
) ;
730 puts (sf_strerror (file
)) ;
734 if (sf_read_short (file
, test
, 1) > 0)
735 { printf ("Line %d: Should return 0.\n", __LINE__
) ;
739 if (! sf_error (file
))
740 { printf ("Line %d: Should return an error.\n", __LINE__
) ;
743 /*-----------------------*/
745 test_readf_short_or_die (file
, 0, test
+ 10, 2, __LINE__
) ;
746 for (k
= 20 ; k
< 24 ; k
++)
747 if (CHAR_ERROR (test
[k
], orig
[k
]))
748 { printf ("\n\nLine %d : Stereo : Incorrect sample (#%d : 0x%X => 0x%X).\n", __LINE__
, k
, orig
[k
], test
[k
]) ;
752 /* Seek to offset from current position. */
753 test_seek_or_die (file
, 8, SEEK_CUR
, 20, sfinfo
.channels
, __LINE__
) ;
755 test_readf_short_or_die (file
, 0, test
+ 20, 2, __LINE__
) ;
756 for (k
= 40 ; k
< 44 ; k
++)
757 if (CHAR_ERROR (test
[k
], orig
[k
]))
758 { printf ("\n\nLine %d : Stereo : Incorrect sample (#%d : 0x%X => 0x%X).\n", __LINE__
, k
, orig
[k
], test
[k
]) ;
762 /* Seek to offset from end of file. */
763 test_seek_or_die (file
, -1 * (sfinfo
.frames
- 10), SEEK_END
, 10, sfinfo
.channels
, __LINE__
) ;
765 test_readf_short_or_die (file
, 0, test
+ 20, 2, __LINE__
) ;
766 for (k
= 20 ; k
< 24 ; k
++)
767 if (CHAR_ERROR (test
[k
], orig
[k
]))
768 { printf ("\n\nLine %d : Stereo : Incorrect sample (#%d : 0x%X => 0x%X).\n", __LINE__
, k
, orig
[k
], test
[k
]) ;
773 } /* stereo_char_test */
776 mono_rdwr_char_test (const char *filename
, int format
, int long_file_ok
, int allow_fd
)
785 sfinfo
.samplerate
= SAMPLE_RATE
;
786 sfinfo
.frames
= DATA_LENGTH
;
787 sfinfo
.channels
= 1 ;
788 sfinfo
.format
= format
;
790 if ((format
& SF_FORMAT_TYPEMASK
) == SF_FORMAT_RAW
791 || (format
& SF_FORMAT_TYPEMASK
) == SF_FORMAT_AU
792 || (format
& SF_FORMAT_TYPEMASK
) == SF_FORMAT_SD2
)
795 { /* Create a short file. */
796 create_short_file (filename
) ;
798 /* Opening a already existing short file (ie invalid header) RDWR is disallowed.
799 ** If this returns a valif pointer sf_open() screwed up.
801 if ((file
= sf_open (filename
, SFM_RDWR
, &sfinfo
)))
802 { printf ("\n\nLine %d: sf_open should (SFM_RDWR) have failed but didn't.\n", __LINE__
) ;
806 /* Truncate the file to zero bytes. */
807 if (truncate (filename
, 0) < 0)
808 { printf ("\n\nLine %d: truncate (%s) failed", __LINE__
, filename
) ;
814 /* Opening a zero length file RDWR is allowed, but the SF_INFO struct must contain
815 ** all the usual data required when opening the file in WRITE mode.
817 sfinfo
.samplerate
= SAMPLE_RATE
;
818 sfinfo
.frames
= DATA_LENGTH
;
819 sfinfo
.channels
= 1 ;
820 sfinfo
.format
= format
;
822 file
= test_open_file_or_die (filename
, SFM_RDWR
, &sfinfo
, allow_fd
, __LINE__
) ;
824 /* Do 3 writes followed by reads. After each, check the data and the current
825 ** read and write offsets.
827 for (pass
= 1 ; pass
<= 3 ; pass
++)
828 { orig
[20] = pass
* 2 ;
830 /* Write some data. */
831 test_write_short_or_die (file
, pass
, orig
, DATA_LENGTH
, __LINE__
) ;
833 test_read_write_position_or_die (file
, __LINE__
, pass
, (pass
- 1) * DATA_LENGTH
, pass
* DATA_LENGTH
) ;
835 /* Read what we just wrote. */
836 test_read_short_or_die (file
, 0, test
, DATA_LENGTH
, __LINE__
) ;
838 /* Check the data. */
839 for (k
= 0 ; k
< DATA_LENGTH
; k
++)
840 if (CHAR_ERROR (orig
[k
], test
[k
]))
841 { printf ("\n\nLine %d (pass %d) A : Error at sample %d (0x%X => 0x%X).\n", __LINE__
, pass
, k
, orig
[k
], test
[k
]) ;
842 oct_save_short (orig
, test
, DATA_LENGTH
) ;
846 test_read_write_position_or_die (file
, __LINE__
, pass
, pass
* DATA_LENGTH
, pass
* DATA_LENGTH
) ;
847 } ; /* for (pass ...) */
851 /* Open the file again to check the data. */
852 file
= test_open_file_or_die (filename
, SFM_RDWR
, &sfinfo
, allow_fd
, __LINE__
) ;
854 if (sfinfo
.format
!= format
)
855 { printf ("\n\nLine %d : Returned format incorrect (0x%08X => 0x%08X).\n", __LINE__
, format
, sfinfo
.format
) ;
859 if (sfinfo
.frames
< 3 * DATA_LENGTH
)
860 { printf ("\n\nLine %d : Not enough frames in file. (%ld < %d)\n", __LINE__
, SF_COUNT_TO_LONG (sfinfo
.frames
), 3 * DATA_LENGTH
) ;
864 if (! long_file_ok
&& sfinfo
.frames
!= 3 * DATA_LENGTH
)
865 { 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
) ;
869 if (sfinfo
.channels
!= 1)
870 { printf ("\n\nLine %d : Incorrect number of channels in file.\n", __LINE__
) ;
875 test_read_write_position_or_die (file
, __LINE__
, 0, 0, 3 * DATA_LENGTH
) ;
877 test_seek_or_die (file
, 3 * DATA_LENGTH
, SFM_WRITE
| SEEK_SET
, 3 * DATA_LENGTH
, sfinfo
.channels
, __LINE__
) ;
879 for (pass
= 1 ; pass
<= 3 ; pass
++)
880 { orig
[20] = pass
* 2 ;
882 test_read_write_position_or_die (file
, __LINE__
, pass
, (pass
- 1) * DATA_LENGTH
, 3 * DATA_LENGTH
) ;
884 /* Read what we just wrote. */
885 test_read_short_or_die (file
, pass
, test
, DATA_LENGTH
, __LINE__
) ;
887 /* Check the data. */
888 for (k
= 0 ; k
< DATA_LENGTH
; k
++)
889 if (CHAR_ERROR (orig
[k
], test
[k
]))
890 { printf ("\n\nLine %d (pass %d) B : Error at sample %d (0x%X => 0x%X).\n", __LINE__
, pass
, k
, orig
[k
], test
[k
]) ;
891 oct_save_short (orig
, test
, DATA_LENGTH
) ;
895 } ; /* for (pass ...) */
898 } /* mono_rdwr_short_test */
901 new_rdwr_char_test (const char *filename
, int format
, int allow_fd
)
902 { SNDFILE
*wfile
, *rwfile
;
910 sfinfo
.samplerate
= 44100 ;
911 sfinfo
.frames
= SILLY_WRITE_COUNT
; /* Wrong length. Library should correct this on sf_close. */
912 sfinfo
.channels
= 2 ;
913 sfinfo
.format
= format
;
915 items
= DATA_LENGTH
;
916 frames
= items
/ sfinfo
.channels
;
918 wfile
= test_open_file_or_die (filename
, SFM_WRITE
, &sfinfo
, allow_fd
, __LINE__
) ;
919 sf_command (wfile
, SFC_SET_UPDATE_HEADER_AUTO
, NULL
, SF_TRUE
) ;
920 test_writef_short_or_die (wfile
, 1, orig
, frames
, __LINE__
) ;
921 sf_write_sync (wfile
) ;
922 test_writef_short_or_die (wfile
, 2, orig
, frames
, __LINE__
) ;
923 sf_write_sync (wfile
) ;
925 rwfile
= test_open_file_or_die (filename
, SFM_RDWR
, &sfinfo
, allow_fd
, __LINE__
) ;
926 if (sfinfo
.frames
!= 2 * frames
)
927 { 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
) ;
931 test_writef_short_or_die (wfile
, 3, orig
, frames
, __LINE__
) ;
933 test_readf_short_or_die (rwfile
, 1, test
, frames
, __LINE__
) ;
934 test_readf_short_or_die (rwfile
, 2, test
, frames
, __LINE__
) ;
938 } /* new_rdwr_char_test */
941 /*======================================================================================
944 static void mono_short_test (const char *filename
, int format
, int long_file_ok
, int allow_fd
) ;
945 static void stereo_short_test (const char *filename
, int format
, int long_file_ok
, int allow_fd
) ;
946 static void mono_rdwr_short_test (const char *filename
, int format
, int long_file_ok
, int allow_fd
) ;
947 static void new_rdwr_short_test (const char *filename
, int format
, int allow_fd
) ;
948 static void multi_seek_test (const char * filename
, int format
) ;
949 static void write_seek_extend_test (const char * filename
, int format
) ;
952 pcm_test_short (const char *filename
, int format
, int long_file_ok
)
957 /* Sd2 files cannot be opened from an existing file descriptor. */
958 allow_fd
= ((format
& SF_FORMAT_TYPEMASK
) == SF_FORMAT_SD2
) ? SF_FALSE
: SF_TRUE
;
960 print_test_name ("pcm_test_short", filename
) ;
962 sfinfo
.samplerate
= 44100 ;
963 sfinfo
.frames
= SILLY_WRITE_COUNT
; /* Wrong length. Library should correct this on sf_close. */
964 sfinfo
.channels
= 1 ;
965 sfinfo
.format
= format
;
967 gen_windowed_sine_double (orig_data
.d
, DATA_LENGTH
, 32000.0) ;
971 /* Make this a macro so gdb steps over it in one go. */
972 CONVERT_DATA (k
, DATA_LENGTH
, orig
, orig_data
.d
) ;
974 /* Some test broken out here. */
976 mono_short_test (filename
, format
, long_file_ok
, allow_fd
) ;
978 /* Sub format DWVW does not allow seeking. */
979 if ((format
& SF_FORMAT_SUBMASK
) == SF_FORMAT_DWVW_16
||
980 (format
& SF_FORMAT_SUBMASK
) == SF_FORMAT_DWVW_24
)
981 { unlink (filename
) ;
982 printf ("no seek : ok\n") ;
986 if ((format
& SF_FORMAT_TYPEMASK
) != SF_FORMAT_FLAC
)
987 mono_rdwr_short_test (filename
, format
, long_file_ok
, allow_fd
) ;
989 /* If the format doesn't support stereo we're done. */
990 sfinfo
.channels
= 2 ;
991 if (sf_format_check (&sfinfo
) == 0)
992 { unlink (filename
) ;
993 puts ("no stereo : ok") ;
997 stereo_short_test (filename
, format
, long_file_ok
, allow_fd
) ;
999 /* New read/write test. Not sure if this is needed yet. */
1001 if ((format
& SF_FORMAT_TYPEMASK
) != SF_FORMAT_PAF
&&
1002 (format
& SF_FORMAT_TYPEMASK
) != SF_FORMAT_VOC
&&
1003 (format
& SF_FORMAT_TYPEMASK
) != SF_FORMAT_FLAC
)
1004 new_rdwr_short_test (filename
, format
, allow_fd
) ;
1006 delete_file (format
, filename
) ;
1010 } /* pcm_test_short */
1013 mono_short_test (const char *filename
, int format
, int long_file_ok
, int allow_fd
)
1016 short *orig
, *test
;
1020 sfinfo
.samplerate
= 44100 ;
1021 sfinfo
.frames
= SILLY_WRITE_COUNT
; /* Wrong length. Library should correct this on sf_close. */
1022 sfinfo
.channels
= 1 ;
1023 sfinfo
.format
= format
;
1025 orig
= orig_data
.s
;
1026 test
= test_data
.s
;
1028 items
= DATA_LENGTH
;
1030 file
= test_open_file_or_die (filename
, SFM_WRITE
, &sfinfo
, allow_fd
, __LINE__
) ;
1032 sf_set_string (file
, SF_STR_ARTIST
, "Your name here") ;
1034 test_write_short_or_die (file
, 0, orig
, items
, __LINE__
) ;
1035 sf_write_sync (file
) ;
1036 test_write_short_or_die (file
, 0, orig
, items
, __LINE__
) ;
1037 sf_write_sync (file
) ;
1039 /* Add non-audio data after the audio. */
1040 sf_set_string (file
, SF_STR_COPYRIGHT
, "Copyright (c) 2003") ;
1044 memset (test
, 0, items
* sizeof (short)) ;
1046 if ((format
& SF_FORMAT_TYPEMASK
) != SF_FORMAT_RAW
)
1047 memset (&sfinfo
, 0, sizeof (sfinfo
)) ;
1049 file
= test_open_file_or_die (filename
, SFM_READ
, &sfinfo
, allow_fd
, __LINE__
) ;
1051 if (sfinfo
.format
!= format
)
1052 { printf ("\n\nLine %d : Mono : Returned format incorrect (0x%08X => 0x%08X).\n", __LINE__
, format
, sfinfo
.format
) ;
1056 if (sfinfo
.frames
< 2 * items
)
1057 { 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
) ;
1061 if (! long_file_ok
&& sfinfo
.frames
> 2 * items
)
1062 { 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
) ;
1066 if (sfinfo
.channels
!= 1)
1067 { printf ("\n\nLine %d : Mono : Incorrect number of channels in file.\n", __LINE__
) ;
1071 check_log_buffer_or_die (file
, __LINE__
) ;
1073 test_read_short_or_die (file
, 0, test
, items
, __LINE__
) ;
1074 for (k
= 0 ; k
< items
; k
++)
1075 if (INT_ERROR (orig
[k
], test
[k
]))
1076 { printf ("\n\nLine %d: Mono : Incorrect sample A (#%d : 0x%X => 0x%X).\n", __LINE__
, k
, orig
[k
], test
[k
]) ;
1077 oct_save_short (orig
, test
, items
) ;
1081 /* Seek to start of file. */
1082 test_seek_or_die (file
, 0, SEEK_SET
, 0, sfinfo
.channels
, __LINE__
) ;
1084 test_read_short_or_die (file
, 0, test
, 4, __LINE__
) ;
1085 for (k
= 0 ; k
< 4 ; k
++)
1086 if (INT_ERROR (orig
[k
], test
[k
]))
1087 { printf ("\n\nLine %d : Mono : Incorrect sample A (#%d : 0x%X => 0x%X).\n", __LINE__
, k
, orig
[k
], test
[k
]) ;
1091 if ((format
& SF_FORMAT_SUBMASK
) == SF_FORMAT_DWVW_16
||
1092 (format
& SF_FORMAT_SUBMASK
) == SF_FORMAT_DWVW_24
)
1095 printf ("no seek : ") ;
1099 /* Seek to offset from start of file. */
1100 test_seek_or_die (file
, items
+ 10, SEEK_SET
, items
+ 10, sfinfo
.channels
, __LINE__
) ;
1102 test_read_short_or_die (file
, 0, test
+ 10, 4, __LINE__
) ;
1103 for (k
= 10 ; k
< 14 ; k
++)
1104 if (INT_ERROR (orig
[k
], test
[k
]))
1105 { printf ("\n\nLine %d : Mono : Incorrect sample A (#%d : 0x%X => 0x%X).\n", __LINE__
, k
, test
[k
], orig
[k
]) ;
1109 /* Seek to offset from current position. */
1110 test_seek_or_die (file
, 6, SEEK_CUR
, items
+ 20, sfinfo
.channels
, __LINE__
) ;
1112 test_read_short_or_die (file
, 0, test
+ 20, 4, __LINE__
) ;
1113 for (k
= 20 ; k
< 24 ; k
++)
1114 if (INT_ERROR (orig
[k
], test
[k
]))
1115 { printf ("\n\nLine %d : Mono : Incorrect sample A (#%d : 0x%X => 0x%X).\n", __LINE__
, k
, test
[k
], orig
[k
]) ;
1119 /* Seek to offset from end of file. */
1120 test_seek_or_die (file
, -1 * (sfinfo
.frames
- 10), SEEK_END
, 10, sfinfo
.channels
, __LINE__
) ;
1122 test_read_short_or_die (file
, 0, test
+ 10, 4, __LINE__
) ;
1123 for (k
= 10 ; k
< 14 ; k
++)
1124 if (INT_ERROR (orig
[k
], test
[k
]))
1125 { printf ("\n\nLine %d : Mono : Incorrect sample D (#%d : 0x%X => 0x%X).\n", __LINE__
, k
, test
[k
], orig
[k
]) ;
1129 /* Check read past end of file followed by sf_seek (sndfile, 0, SEEK_CUR). */
1130 test_seek_or_die (file
, 0, SEEK_SET
, 0, sfinfo
.channels
, __LINE__
) ;
1133 while (count
< sfinfo
.frames
)
1134 count
+= sf_read_short (file
, test
, 311) ;
1136 /* Check that no error has occurred. */
1137 if (sf_error (file
))
1138 { printf ("\n\nLine %d : Mono : error where there shouldn't have been one.\n", __LINE__
) ;
1139 puts (sf_strerror (file
)) ;
1143 /* Check that we haven't read beyond EOF. */
1144 if (count
> sfinfo
.frames
)
1145 { printf ("\n\nLines %d : read past end of file (%ld should be %ld)\n", __LINE__
, (long) count
, (long) sfinfo
.frames
) ;
1149 test_seek_or_die (file
, 0, SEEK_CUR
, sfinfo
.frames
, sfinfo
.channels
, __LINE__
) ;
1153 multi_seek_test (filename
, format
) ;
1154 write_seek_extend_test (filename
, format
) ;
1156 } /* mono_short_test */
1159 stereo_short_test (const char *filename
, int format
, int long_file_ok
, int allow_fd
)
1162 short *orig
, *test
;
1163 int k
, items
, frames
;
1165 sfinfo
.samplerate
= 44100 ;
1166 sfinfo
.frames
= SILLY_WRITE_COUNT
; /* Wrong length. Library should correct this on sf_close. */
1167 sfinfo
.channels
= 2 ;
1168 sfinfo
.format
= format
;
1170 gen_windowed_sine_double (orig_data
.d
, DATA_LENGTH
, 32000.0) ;
1172 orig
= orig_data
.s
;
1173 test
= test_data
.s
;
1175 /* Make this a macro so gdb steps over it in one go. */
1176 CONVERT_DATA (k
, DATA_LENGTH
, orig
, orig_data
.d
) ;
1178 items
= DATA_LENGTH
;
1179 frames
= items
/ sfinfo
.channels
;
1181 file
= test_open_file_or_die (filename
, SFM_WRITE
, &sfinfo
, allow_fd
, __LINE__
) ;
1183 sf_set_string (file
, SF_STR_ARTIST
, "Your name here") ;
1185 test_writef_short_or_die (file
, 0, orig
, frames
, __LINE__
) ;
1187 sf_set_string (file
, SF_STR_COPYRIGHT
, "Copyright (c) 2003") ;
1191 memset (test
, 0, items
* sizeof (short)) ;
1193 if ((format
& SF_FORMAT_TYPEMASK
) != SF_FORMAT_RAW
)
1194 memset (&sfinfo
, 0, sizeof (sfinfo
)) ;
1196 file
= test_open_file_or_die (filename
, SFM_READ
, &sfinfo
, allow_fd
, __LINE__
) ;
1198 if (sfinfo
.format
!= format
)
1199 { printf ("\n\nLine %d : Stereo : Returned format incorrect (0x%08X => 0x%08X).\n",
1200 __LINE__
, format
, sfinfo
.format
) ;
1204 if (sfinfo
.frames
< frames
)
1205 { printf ("\n\nLine %d : Stereo : Incorrect number of frames in file (too short). (%ld should be %d)\n",
1206 __LINE__
, SF_COUNT_TO_LONG (sfinfo
.frames
), frames
) ;
1210 if (! long_file_ok
&& sfinfo
.frames
> frames
)
1211 { printf ("\n\nLine %d : Stereo : Incorrect number of frames in file (too long). (%ld should be %d)\n",
1212 __LINE__
, SF_COUNT_TO_LONG (sfinfo
.frames
), frames
) ;
1216 if (sfinfo
.channels
!= 2)
1217 { printf ("\n\nLine %d : Stereo : Incorrect number of channels in file.\n", __LINE__
) ;
1221 check_log_buffer_or_die (file
, __LINE__
) ;
1223 test_readf_short_or_die (file
, 0, test
, frames
, __LINE__
) ;
1224 for (k
= 0 ; k
< items
; k
++)
1225 if (INT_ERROR (test
[k
], orig
[k
]))
1226 { printf ("\n\nLine %d : Stereo : Incorrect sample (#%d : 0x%X => 0x%X).\n", __LINE__
, k
, orig
[k
], test
[k
]) ;
1230 /* Seek to start of file. */
1231 test_seek_or_die (file
, 0, SEEK_SET
, 0, sfinfo
.channels
, __LINE__
) ;
1233 test_readf_short_or_die (file
, 0, test
, 2, __LINE__
) ;
1234 for (k
= 0 ; k
< 4 ; k
++)
1235 if (INT_ERROR (test
[k
], orig
[k
]))
1236 { printf ("\n\nLine %d : Stereo : Incorrect sample (#%d : 0x%X => 0x%X).\n", __LINE__
, k
, orig
[k
], test
[k
]) ;
1240 /* Seek to offset from start of file. */
1241 test_seek_or_die (file
, 10, SEEK_SET
, 10, sfinfo
.channels
, __LINE__
) ;
1243 /* Check for errors here. */
1244 if (sf_error (file
))
1245 { printf ("Line %d: Should NOT return an error.\n", __LINE__
) ;
1246 puts (sf_strerror (file
)) ;
1250 if (sf_read_short (file
, test
, 1) > 0)
1251 { printf ("Line %d: Should return 0.\n", __LINE__
) ;
1255 if (! sf_error (file
))
1256 { printf ("Line %d: Should return an error.\n", __LINE__
) ;
1259 /*-----------------------*/
1261 test_readf_short_or_die (file
, 0, test
+ 10, 2, __LINE__
) ;
1262 for (k
= 20 ; k
< 24 ; k
++)
1263 if (INT_ERROR (test
[k
], orig
[k
]))
1264 { printf ("\n\nLine %d : Stereo : Incorrect sample (#%d : 0x%X => 0x%X).\n", __LINE__
, k
, orig
[k
], test
[k
]) ;
1268 /* Seek to offset from current position. */
1269 test_seek_or_die (file
, 8, SEEK_CUR
, 20, sfinfo
.channels
, __LINE__
) ;
1271 test_readf_short_or_die (file
, 0, test
+ 20, 2, __LINE__
) ;
1272 for (k
= 40 ; k
< 44 ; k
++)
1273 if (INT_ERROR (test
[k
], orig
[k
]))
1274 { printf ("\n\nLine %d : Stereo : Incorrect sample (#%d : 0x%X => 0x%X).\n", __LINE__
, k
, orig
[k
], test
[k
]) ;
1278 /* Seek to offset from end of file. */
1279 test_seek_or_die (file
, -1 * (sfinfo
.frames
- 10), SEEK_END
, 10, sfinfo
.channels
, __LINE__
) ;
1281 test_readf_short_or_die (file
, 0, test
+ 20, 2, __LINE__
) ;
1282 for (k
= 20 ; k
< 24 ; k
++)
1283 if (INT_ERROR (test
[k
], orig
[k
]))
1284 { printf ("\n\nLine %d : Stereo : Incorrect sample (#%d : 0x%X => 0x%X).\n", __LINE__
, k
, orig
[k
], test
[k
]) ;
1289 } /* stereo_short_test */
1292 mono_rdwr_short_test (const char *filename
, int format
, int long_file_ok
, int allow_fd
)
1295 short *orig
, *test
;
1298 orig
= orig_data
.s
;
1299 test
= test_data
.s
;
1301 sfinfo
.samplerate
= SAMPLE_RATE
;
1302 sfinfo
.frames
= DATA_LENGTH
;
1303 sfinfo
.channels
= 1 ;
1304 sfinfo
.format
= format
;
1306 if ((format
& SF_FORMAT_TYPEMASK
) == SF_FORMAT_RAW
1307 || (format
& SF_FORMAT_TYPEMASK
) == SF_FORMAT_AU
1308 || (format
& SF_FORMAT_TYPEMASK
) == SF_FORMAT_SD2
)
1311 { /* Create a short file. */
1312 create_short_file (filename
) ;
1314 /* Opening a already existing short file (ie invalid header) RDWR is disallowed.
1315 ** If this returns a valif pointer sf_open() screwed up.
1317 if ((file
= sf_open (filename
, SFM_RDWR
, &sfinfo
)))
1318 { printf ("\n\nLine %d: sf_open should (SFM_RDWR) have failed but didn't.\n", __LINE__
) ;
1322 /* Truncate the file to zero bytes. */
1323 if (truncate (filename
, 0) < 0)
1324 { printf ("\n\nLine %d: truncate (%s) failed", __LINE__
, filename
) ;
1330 /* Opening a zero length file RDWR is allowed, but the SF_INFO struct must contain
1331 ** all the usual data required when opening the file in WRITE mode.
1333 sfinfo
.samplerate
= SAMPLE_RATE
;
1334 sfinfo
.frames
= DATA_LENGTH
;
1335 sfinfo
.channels
= 1 ;
1336 sfinfo
.format
= format
;
1338 file
= test_open_file_or_die (filename
, SFM_RDWR
, &sfinfo
, allow_fd
, __LINE__
) ;
1340 /* Do 3 writes followed by reads. After each, check the data and the current
1341 ** read and write offsets.
1343 for (pass
= 1 ; pass
<= 3 ; pass
++)
1344 { orig
[20] = pass
* 2 ;
1346 /* Write some data. */
1347 test_write_short_or_die (file
, pass
, orig
, DATA_LENGTH
, __LINE__
) ;
1349 test_read_write_position_or_die (file
, __LINE__
, pass
, (pass
- 1) * DATA_LENGTH
, pass
* DATA_LENGTH
) ;
1351 /* Read what we just wrote. */
1352 test_read_short_or_die (file
, 0, test
, DATA_LENGTH
, __LINE__
) ;
1354 /* Check the data. */
1355 for (k
= 0 ; k
< DATA_LENGTH
; k
++)
1356 if (INT_ERROR (orig
[k
], test
[k
]))
1357 { printf ("\n\nLine %d (pass %d) A : Error at sample %d (0x%X => 0x%X).\n", __LINE__
, pass
, k
, orig
[k
], test
[k
]) ;
1358 oct_save_short (orig
, test
, DATA_LENGTH
) ;
1362 test_read_write_position_or_die (file
, __LINE__
, pass
, pass
* DATA_LENGTH
, pass
* DATA_LENGTH
) ;
1363 } ; /* for (pass ...) */
1367 /* Open the file again to check the data. */
1368 file
= test_open_file_or_die (filename
, SFM_RDWR
, &sfinfo
, allow_fd
, __LINE__
) ;
1370 if (sfinfo
.format
!= format
)
1371 { printf ("\n\nLine %d : Returned format incorrect (0x%08X => 0x%08X).\n", __LINE__
, format
, sfinfo
.format
) ;
1375 if (sfinfo
.frames
< 3 * DATA_LENGTH
)
1376 { printf ("\n\nLine %d : Not enough frames in file. (%ld < %d)\n", __LINE__
, SF_COUNT_TO_LONG (sfinfo
.frames
), 3 * DATA_LENGTH
) ;
1380 if (! long_file_ok
&& sfinfo
.frames
!= 3 * DATA_LENGTH
)
1381 { 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
) ;
1385 if (sfinfo
.channels
!= 1)
1386 { printf ("\n\nLine %d : Incorrect number of channels in file.\n", __LINE__
) ;
1391 test_read_write_position_or_die (file
, __LINE__
, 0, 0, 3 * DATA_LENGTH
) ;
1393 test_seek_or_die (file
, 3 * DATA_LENGTH
, SFM_WRITE
| SEEK_SET
, 3 * DATA_LENGTH
, sfinfo
.channels
, __LINE__
) ;
1395 for (pass
= 1 ; pass
<= 3 ; pass
++)
1396 { orig
[20] = pass
* 2 ;
1398 test_read_write_position_or_die (file
, __LINE__
, pass
, (pass
- 1) * DATA_LENGTH
, 3 * DATA_LENGTH
) ;
1400 /* Read what we just wrote. */
1401 test_read_short_or_die (file
, pass
, test
, DATA_LENGTH
, __LINE__
) ;
1403 /* Check the data. */
1404 for (k
= 0 ; k
< DATA_LENGTH
; k
++)
1405 if (INT_ERROR (orig
[k
], test
[k
]))
1406 { printf ("\n\nLine %d (pass %d) B : Error at sample %d (0x%X => 0x%X).\n", __LINE__
, pass
, k
, orig
[k
], test
[k
]) ;
1407 oct_save_short (orig
, test
, DATA_LENGTH
) ;
1411 } ; /* for (pass ...) */
1414 } /* mono_rdwr_short_test */
1417 new_rdwr_short_test (const char *filename
, int format
, int allow_fd
)
1418 { SNDFILE
*wfile
, *rwfile
;
1420 short *orig
, *test
;
1423 orig
= orig_data
.s
;
1424 test
= test_data
.s
;
1426 sfinfo
.samplerate
= 44100 ;
1427 sfinfo
.frames
= SILLY_WRITE_COUNT
; /* Wrong length. Library should correct this on sf_close. */
1428 sfinfo
.channels
= 2 ;
1429 sfinfo
.format
= format
;
1431 items
= DATA_LENGTH
;
1432 frames
= items
/ sfinfo
.channels
;
1434 wfile
= test_open_file_or_die (filename
, SFM_WRITE
, &sfinfo
, allow_fd
, __LINE__
) ;
1435 sf_command (wfile
, SFC_SET_UPDATE_HEADER_AUTO
, NULL
, SF_TRUE
) ;
1436 test_writef_short_or_die (wfile
, 1, orig
, frames
, __LINE__
) ;
1437 sf_write_sync (wfile
) ;
1438 test_writef_short_or_die (wfile
, 2, orig
, frames
, __LINE__
) ;
1439 sf_write_sync (wfile
) ;
1441 rwfile
= test_open_file_or_die (filename
, SFM_RDWR
, &sfinfo
, allow_fd
, __LINE__
) ;
1442 if (sfinfo
.frames
!= 2 * frames
)
1443 { 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
) ;
1447 test_writef_short_or_die (wfile
, 3, orig
, frames
, __LINE__
) ;
1449 test_readf_short_or_die (rwfile
, 1, test
, frames
, __LINE__
) ;
1450 test_readf_short_or_die (rwfile
, 2, test
, frames
, __LINE__
) ;
1454 } /* new_rdwr_short_test */
1457 /*======================================================================================
1460 static void mono_24bit_test (const char *filename
, int format
, int long_file_ok
, int allow_fd
) ;
1461 static void stereo_24bit_test (const char *filename
, int format
, int long_file_ok
, int allow_fd
) ;
1462 static void mono_rdwr_24bit_test (const char *filename
, int format
, int long_file_ok
, int allow_fd
) ;
1463 static void new_rdwr_24bit_test (const char *filename
, int format
, int allow_fd
) ;
1464 static void multi_seek_test (const char * filename
, int format
) ;
1465 static void write_seek_extend_test (const char * filename
, int format
) ;
1468 pcm_test_24bit (const char *filename
, int format
, int long_file_ok
)
1473 /* Sd2 files cannot be opened from an existing file descriptor. */
1474 allow_fd
= ((format
& SF_FORMAT_TYPEMASK
) == SF_FORMAT_SD2
) ? SF_FALSE
: SF_TRUE
;
1476 print_test_name ("pcm_test_24bit", filename
) ;
1478 sfinfo
.samplerate
= 44100 ;
1479 sfinfo
.frames
= SILLY_WRITE_COUNT
; /* Wrong length. Library should correct this on sf_close. */
1480 sfinfo
.channels
= 1 ;
1481 sfinfo
.format
= format
;
1483 gen_windowed_sine_double (orig_data
.d
, DATA_LENGTH
, (1.0 * 0x7F000000)) ;
1485 orig
= orig_data
.i
;
1487 /* Make this a macro so gdb steps over it in one go. */
1488 CONVERT_DATA (k
, DATA_LENGTH
, orig
, orig_data
.d
) ;
1490 /* Some test broken out here. */
1492 mono_24bit_test (filename
, format
, long_file_ok
, allow_fd
) ;
1494 /* Sub format DWVW does not allow seeking. */
1495 if ((format
& SF_FORMAT_SUBMASK
) == SF_FORMAT_DWVW_16
||
1496 (format
& SF_FORMAT_SUBMASK
) == SF_FORMAT_DWVW_24
)
1497 { unlink (filename
) ;
1498 printf ("no seek : ok\n") ;
1502 if ((format
& SF_FORMAT_TYPEMASK
) != SF_FORMAT_FLAC
)
1503 mono_rdwr_24bit_test (filename
, format
, long_file_ok
, allow_fd
) ;
1505 /* If the format doesn't support stereo we're done. */
1506 sfinfo
.channels
= 2 ;
1507 if (sf_format_check (&sfinfo
) == 0)
1508 { unlink (filename
) ;
1509 puts ("no stereo : ok") ;
1513 stereo_24bit_test (filename
, format
, long_file_ok
, allow_fd
) ;
1515 /* New read/write test. Not sure if this is needed yet. */
1517 if ((format
& SF_FORMAT_TYPEMASK
) != SF_FORMAT_PAF
&&
1518 (format
& SF_FORMAT_TYPEMASK
) != SF_FORMAT_VOC
&&
1519 (format
& SF_FORMAT_TYPEMASK
) != SF_FORMAT_FLAC
)
1520 new_rdwr_24bit_test (filename
, format
, allow_fd
) ;
1522 delete_file (format
, filename
) ;
1526 } /* pcm_test_24bit */
1529 mono_24bit_test (const char *filename
, int format
, int long_file_ok
, int allow_fd
)
1536 sfinfo
.samplerate
= 44100 ;
1537 sfinfo
.frames
= SILLY_WRITE_COUNT
; /* Wrong length. Library should correct this on sf_close. */
1538 sfinfo
.channels
= 1 ;
1539 sfinfo
.format
= format
;
1541 orig
= orig_data
.i
;
1542 test
= test_data
.i
;
1544 items
= DATA_LENGTH
;
1546 file
= test_open_file_or_die (filename
, SFM_WRITE
, &sfinfo
, allow_fd
, __LINE__
) ;
1548 sf_set_string (file
, SF_STR_ARTIST
, "Your name here") ;
1550 test_write_int_or_die (file
, 0, orig
, items
, __LINE__
) ;
1551 sf_write_sync (file
) ;
1552 test_write_int_or_die (file
, 0, orig
, items
, __LINE__
) ;
1553 sf_write_sync (file
) ;
1555 /* Add non-audio data after the audio. */
1556 sf_set_string (file
, SF_STR_COPYRIGHT
, "Copyright (c) 2003") ;
1560 memset (test
, 0, items
* sizeof (int)) ;
1562 if ((format
& SF_FORMAT_TYPEMASK
) != SF_FORMAT_RAW
)
1563 memset (&sfinfo
, 0, sizeof (sfinfo
)) ;
1565 file
= test_open_file_or_die (filename
, SFM_READ
, &sfinfo
, allow_fd
, __LINE__
) ;
1567 if (sfinfo
.format
!= format
)
1568 { printf ("\n\nLine %d : Mono : Returned format incorrect (0x%08X => 0x%08X).\n", __LINE__
, format
, sfinfo
.format
) ;
1572 if (sfinfo
.frames
< 2 * items
)
1573 { 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
) ;
1577 if (! long_file_ok
&& sfinfo
.frames
> 2 * items
)
1578 { 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
) ;
1582 if (sfinfo
.channels
!= 1)
1583 { printf ("\n\nLine %d : Mono : Incorrect number of channels in file.\n", __LINE__
) ;
1587 check_log_buffer_or_die (file
, __LINE__
) ;
1589 test_read_int_or_die (file
, 0, test
, items
, __LINE__
) ;
1590 for (k
= 0 ; k
< items
; k
++)
1591 if (TRIBYTE_ERROR (orig
[k
], test
[k
]))
1592 { printf ("\n\nLine %d: Mono : Incorrect sample A (#%d : 0x%X => 0x%X).\n", __LINE__
, k
, orig
[k
], test
[k
]) ;
1593 oct_save_int (orig
, test
, items
) ;
1597 /* Seek to start of file. */
1598 test_seek_or_die (file
, 0, SEEK_SET
, 0, sfinfo
.channels
, __LINE__
) ;
1600 test_read_int_or_die (file
, 0, test
, 4, __LINE__
) ;
1601 for (k
= 0 ; k
< 4 ; k
++)
1602 if (TRIBYTE_ERROR (orig
[k
], test
[k
]))
1603 { printf ("\n\nLine %d : Mono : Incorrect sample A (#%d : 0x%X => 0x%X).\n", __LINE__
, k
, orig
[k
], test
[k
]) ;
1607 if ((format
& SF_FORMAT_SUBMASK
) == SF_FORMAT_DWVW_16
||
1608 (format
& SF_FORMAT_SUBMASK
) == SF_FORMAT_DWVW_24
)
1611 printf ("no seek : ") ;
1615 /* Seek to offset from start of file. */
1616 test_seek_or_die (file
, items
+ 10, SEEK_SET
, items
+ 10, sfinfo
.channels
, __LINE__
) ;
1618 test_read_int_or_die (file
, 0, test
+ 10, 4, __LINE__
) ;
1619 for (k
= 10 ; k
< 14 ; k
++)
1620 if (TRIBYTE_ERROR (orig
[k
], test
[k
]))
1621 { printf ("\n\nLine %d : Mono : Incorrect sample A (#%d : 0x%X => 0x%X).\n", __LINE__
, k
, test
[k
], orig
[k
]) ;
1625 /* Seek to offset from current position. */
1626 test_seek_or_die (file
, 6, SEEK_CUR
, items
+ 20, sfinfo
.channels
, __LINE__
) ;
1628 test_read_int_or_die (file
, 0, test
+ 20, 4, __LINE__
) ;
1629 for (k
= 20 ; k
< 24 ; k
++)
1630 if (TRIBYTE_ERROR (orig
[k
], test
[k
]))
1631 { printf ("\n\nLine %d : Mono : Incorrect sample A (#%d : 0x%X => 0x%X).\n", __LINE__
, k
, test
[k
], orig
[k
]) ;
1635 /* Seek to offset from end of file. */
1636 test_seek_or_die (file
, -1 * (sfinfo
.frames
- 10), SEEK_END
, 10, sfinfo
.channels
, __LINE__
) ;
1638 test_read_int_or_die (file
, 0, test
+ 10, 4, __LINE__
) ;
1639 for (k
= 10 ; k
< 14 ; k
++)
1640 if (TRIBYTE_ERROR (orig
[k
], test
[k
]))
1641 { printf ("\n\nLine %d : Mono : Incorrect sample D (#%d : 0x%X => 0x%X).\n", __LINE__
, k
, test
[k
], orig
[k
]) ;
1645 /* Check read past end of file followed by sf_seek (sndfile, 0, SEEK_CUR). */
1646 test_seek_or_die (file
, 0, SEEK_SET
, 0, sfinfo
.channels
, __LINE__
) ;
1649 while (count
< sfinfo
.frames
)
1650 count
+= sf_read_int (file
, test
, 311) ;
1652 /* Check that no error has occurred. */
1653 if (sf_error (file
))
1654 { printf ("\n\nLine %d : Mono : error where there shouldn't have been one.\n", __LINE__
) ;
1655 puts (sf_strerror (file
)) ;
1659 /* Check that we haven't read beyond EOF. */
1660 if (count
> sfinfo
.frames
)
1661 { printf ("\n\nLines %d : read past end of file (%ld should be %ld)\n", __LINE__
, (long) count
, (long) sfinfo
.frames
) ;
1665 test_seek_or_die (file
, 0, SEEK_CUR
, sfinfo
.frames
, sfinfo
.channels
, __LINE__
) ;
1669 multi_seek_test (filename
, format
) ;
1670 write_seek_extend_test (filename
, format
) ;
1672 } /* mono_24bit_test */
1675 stereo_24bit_test (const char *filename
, int format
, int long_file_ok
, int allow_fd
)
1679 int k
, items
, frames
;
1681 sfinfo
.samplerate
= 44100 ;
1682 sfinfo
.frames
= SILLY_WRITE_COUNT
; /* Wrong length. Library should correct this on sf_close. */
1683 sfinfo
.channels
= 2 ;
1684 sfinfo
.format
= format
;
1686 gen_windowed_sine_double (orig_data
.d
, DATA_LENGTH
, (1.0 * 0x7F000000)) ;
1688 orig
= orig_data
.i
;
1689 test
= test_data
.i
;
1691 /* Make this a macro so gdb steps over it in one go. */
1692 CONVERT_DATA (k
, DATA_LENGTH
, orig
, orig_data
.d
) ;
1694 items
= DATA_LENGTH
;
1695 frames
= items
/ sfinfo
.channels
;
1697 file
= test_open_file_or_die (filename
, SFM_WRITE
, &sfinfo
, allow_fd
, __LINE__
) ;
1699 sf_set_string (file
, SF_STR_ARTIST
, "Your name here") ;
1701 test_writef_int_or_die (file
, 0, orig
, frames
, __LINE__
) ;
1703 sf_set_string (file
, SF_STR_COPYRIGHT
, "Copyright (c) 2003") ;
1707 memset (test
, 0, items
* sizeof (int)) ;
1709 if ((format
& SF_FORMAT_TYPEMASK
) != SF_FORMAT_RAW
)
1710 memset (&sfinfo
, 0, sizeof (sfinfo
)) ;
1712 file
= test_open_file_or_die (filename
, SFM_READ
, &sfinfo
, allow_fd
, __LINE__
) ;
1714 if (sfinfo
.format
!= format
)
1715 { printf ("\n\nLine %d : Stereo : Returned format incorrect (0x%08X => 0x%08X).\n",
1716 __LINE__
, format
, sfinfo
.format
) ;
1720 if (sfinfo
.frames
< frames
)
1721 { printf ("\n\nLine %d : Stereo : Incorrect number of frames in file (too short). (%ld should be %d)\n",
1722 __LINE__
, SF_COUNT_TO_LONG (sfinfo
.frames
), frames
) ;
1726 if (! long_file_ok
&& sfinfo
.frames
> frames
)
1727 { printf ("\n\nLine %d : Stereo : Incorrect number of frames in file (too long). (%ld should be %d)\n",
1728 __LINE__
, SF_COUNT_TO_LONG (sfinfo
.frames
), frames
) ;
1732 if (sfinfo
.channels
!= 2)
1733 { printf ("\n\nLine %d : Stereo : Incorrect number of channels in file.\n", __LINE__
) ;
1737 check_log_buffer_or_die (file
, __LINE__
) ;
1739 test_readf_int_or_die (file
, 0, test
, frames
, __LINE__
) ;
1740 for (k
= 0 ; k
< items
; k
++)
1741 if (TRIBYTE_ERROR (test
[k
], orig
[k
]))
1742 { printf ("\n\nLine %d : Stereo : Incorrect sample (#%d : 0x%X => 0x%X).\n", __LINE__
, k
, orig
[k
], test
[k
]) ;
1746 /* Seek to start of file. */
1747 test_seek_or_die (file
, 0, SEEK_SET
, 0, sfinfo
.channels
, __LINE__
) ;
1749 test_readf_int_or_die (file
, 0, test
, 2, __LINE__
) ;
1750 for (k
= 0 ; k
< 4 ; k
++)
1751 if (TRIBYTE_ERROR (test
[k
], orig
[k
]))
1752 { printf ("\n\nLine %d : Stereo : Incorrect sample (#%d : 0x%X => 0x%X).\n", __LINE__
, k
, orig
[k
], test
[k
]) ;
1756 /* Seek to offset from start of file. */
1757 test_seek_or_die (file
, 10, SEEK_SET
, 10, sfinfo
.channels
, __LINE__
) ;
1759 /* Check for errors here. */
1760 if (sf_error (file
))
1761 { printf ("Line %d: Should NOT return an error.\n", __LINE__
) ;
1762 puts (sf_strerror (file
)) ;
1766 if (sf_read_int (file
, test
, 1) > 0)
1767 { printf ("Line %d: Should return 0.\n", __LINE__
) ;
1771 if (! sf_error (file
))
1772 { printf ("Line %d: Should return an error.\n", __LINE__
) ;
1775 /*-----------------------*/
1777 test_readf_int_or_die (file
, 0, test
+ 10, 2, __LINE__
) ;
1778 for (k
= 20 ; k
< 24 ; k
++)
1779 if (TRIBYTE_ERROR (test
[k
], orig
[k
]))
1780 { printf ("\n\nLine %d : Stereo : Incorrect sample (#%d : 0x%X => 0x%X).\n", __LINE__
, k
, orig
[k
], test
[k
]) ;
1784 /* Seek to offset from current position. */
1785 test_seek_or_die (file
, 8, SEEK_CUR
, 20, sfinfo
.channels
, __LINE__
) ;
1787 test_readf_int_or_die (file
, 0, test
+ 20, 2, __LINE__
) ;
1788 for (k
= 40 ; k
< 44 ; k
++)
1789 if (TRIBYTE_ERROR (test
[k
], orig
[k
]))
1790 { printf ("\n\nLine %d : Stereo : Incorrect sample (#%d : 0x%X => 0x%X).\n", __LINE__
, k
, orig
[k
], test
[k
]) ;
1794 /* Seek to offset from end of file. */
1795 test_seek_or_die (file
, -1 * (sfinfo
.frames
- 10), SEEK_END
, 10, sfinfo
.channels
, __LINE__
) ;
1797 test_readf_int_or_die (file
, 0, test
+ 20, 2, __LINE__
) ;
1798 for (k
= 20 ; k
< 24 ; k
++)
1799 if (TRIBYTE_ERROR (test
[k
], orig
[k
]))
1800 { printf ("\n\nLine %d : Stereo : Incorrect sample (#%d : 0x%X => 0x%X).\n", __LINE__
, k
, orig
[k
], test
[k
]) ;
1805 } /* stereo_24bit_test */
1808 mono_rdwr_24bit_test (const char *filename
, int format
, int long_file_ok
, int allow_fd
)
1814 orig
= orig_data
.i
;
1815 test
= test_data
.i
;
1817 sfinfo
.samplerate
= SAMPLE_RATE
;
1818 sfinfo
.frames
= DATA_LENGTH
;
1819 sfinfo
.channels
= 1 ;
1820 sfinfo
.format
= format
;
1822 if ((format
& SF_FORMAT_TYPEMASK
) == SF_FORMAT_RAW
1823 || (format
& SF_FORMAT_TYPEMASK
) == SF_FORMAT_AU
1824 || (format
& SF_FORMAT_TYPEMASK
) == SF_FORMAT_SD2
)
1827 { /* Create a short file. */
1828 create_short_file (filename
) ;
1830 /* Opening a already existing short file (ie invalid header) RDWR is disallowed.
1831 ** If this returns a valif pointer sf_open() screwed up.
1833 if ((file
= sf_open (filename
, SFM_RDWR
, &sfinfo
)))
1834 { printf ("\n\nLine %d: sf_open should (SFM_RDWR) have failed but didn't.\n", __LINE__
) ;
1838 /* Truncate the file to zero bytes. */
1839 if (truncate (filename
, 0) < 0)
1840 { printf ("\n\nLine %d: truncate (%s) failed", __LINE__
, filename
) ;
1846 /* Opening a zero length file RDWR is allowed, but the SF_INFO struct must contain
1847 ** all the usual data required when opening the file in WRITE mode.
1849 sfinfo
.samplerate
= SAMPLE_RATE
;
1850 sfinfo
.frames
= DATA_LENGTH
;
1851 sfinfo
.channels
= 1 ;
1852 sfinfo
.format
= format
;
1854 file
= test_open_file_or_die (filename
, SFM_RDWR
, &sfinfo
, allow_fd
, __LINE__
) ;
1856 /* Do 3 writes followed by reads. After each, check the data and the current
1857 ** read and write offsets.
1859 for (pass
= 1 ; pass
<= 3 ; pass
++)
1860 { orig
[20] = pass
* 2 ;
1862 /* Write some data. */
1863 test_write_int_or_die (file
, pass
, orig
, DATA_LENGTH
, __LINE__
) ;
1865 test_read_write_position_or_die (file
, __LINE__
, pass
, (pass
- 1) * DATA_LENGTH
, pass
* DATA_LENGTH
) ;
1867 /* Read what we just wrote. */
1868 test_read_int_or_die (file
, 0, test
, DATA_LENGTH
, __LINE__
) ;
1870 /* Check the data. */
1871 for (k
= 0 ; k
< DATA_LENGTH
; k
++)
1872 if (TRIBYTE_ERROR (orig
[k
], test
[k
]))
1873 { printf ("\n\nLine %d (pass %d) A : Error at sample %d (0x%X => 0x%X).\n", __LINE__
, pass
, k
, orig
[k
], test
[k
]) ;
1874 oct_save_int (orig
, test
, DATA_LENGTH
) ;
1878 test_read_write_position_or_die (file
, __LINE__
, pass
, pass
* DATA_LENGTH
, pass
* DATA_LENGTH
) ;
1879 } ; /* for (pass ...) */
1883 /* Open the file again to check the data. */
1884 file
= test_open_file_or_die (filename
, SFM_RDWR
, &sfinfo
, allow_fd
, __LINE__
) ;
1886 if (sfinfo
.format
!= format
)
1887 { printf ("\n\nLine %d : Returned format incorrect (0x%08X => 0x%08X).\n", __LINE__
, format
, sfinfo
.format
) ;
1891 if (sfinfo
.frames
< 3 * DATA_LENGTH
)
1892 { printf ("\n\nLine %d : Not enough frames in file. (%ld < %d)\n", __LINE__
, SF_COUNT_TO_LONG (sfinfo
.frames
), 3 * DATA_LENGTH
) ;
1896 if (! long_file_ok
&& sfinfo
.frames
!= 3 * DATA_LENGTH
)
1897 { 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
) ;
1901 if (sfinfo
.channels
!= 1)
1902 { printf ("\n\nLine %d : Incorrect number of channels in file.\n", __LINE__
) ;
1907 test_read_write_position_or_die (file
, __LINE__
, 0, 0, 3 * DATA_LENGTH
) ;
1909 test_seek_or_die (file
, 3 * DATA_LENGTH
, SFM_WRITE
| SEEK_SET
, 3 * DATA_LENGTH
, sfinfo
.channels
, __LINE__
) ;
1911 for (pass
= 1 ; pass
<= 3 ; pass
++)
1912 { orig
[20] = pass
* 2 ;
1914 test_read_write_position_or_die (file
, __LINE__
, pass
, (pass
- 1) * DATA_LENGTH
, 3 * DATA_LENGTH
) ;
1916 /* Read what we just wrote. */
1917 test_read_int_or_die (file
, pass
, test
, DATA_LENGTH
, __LINE__
) ;
1919 /* Check the data. */
1920 for (k
= 0 ; k
< DATA_LENGTH
; k
++)
1921 if (TRIBYTE_ERROR (orig
[k
], test
[k
]))
1922 { printf ("\n\nLine %d (pass %d) B : Error at sample %d (0x%X => 0x%X).\n", __LINE__
, pass
, k
, orig
[k
], test
[k
]) ;
1923 oct_save_int (orig
, test
, DATA_LENGTH
) ;
1927 } ; /* for (pass ...) */
1930 } /* mono_rdwr_int_test */
1933 new_rdwr_24bit_test (const char *filename
, int format
, int allow_fd
)
1934 { SNDFILE
*wfile
, *rwfile
;
1939 orig
= orig_data
.i
;
1940 test
= test_data
.i
;
1942 sfinfo
.samplerate
= 44100 ;
1943 sfinfo
.frames
= SILLY_WRITE_COUNT
; /* Wrong length. Library should correct this on sf_close. */
1944 sfinfo
.channels
= 2 ;
1945 sfinfo
.format
= format
;
1947 items
= DATA_LENGTH
;
1948 frames
= items
/ sfinfo
.channels
;
1950 wfile
= test_open_file_or_die (filename
, SFM_WRITE
, &sfinfo
, allow_fd
, __LINE__
) ;
1951 sf_command (wfile
, SFC_SET_UPDATE_HEADER_AUTO
, NULL
, SF_TRUE
) ;
1952 test_writef_int_or_die (wfile
, 1, orig
, frames
, __LINE__
) ;
1953 sf_write_sync (wfile
) ;
1954 test_writef_int_or_die (wfile
, 2, orig
, frames
, __LINE__
) ;
1955 sf_write_sync (wfile
) ;
1957 rwfile
= test_open_file_or_die (filename
, SFM_RDWR
, &sfinfo
, allow_fd
, __LINE__
) ;
1958 if (sfinfo
.frames
!= 2 * frames
)
1959 { 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
) ;
1963 test_writef_int_or_die (wfile
, 3, orig
, frames
, __LINE__
) ;
1965 test_readf_int_or_die (rwfile
, 1, test
, frames
, __LINE__
) ;
1966 test_readf_int_or_die (rwfile
, 2, test
, frames
, __LINE__
) ;
1970 } /* new_rdwr_24bit_test */
1973 /*======================================================================================
1976 static void mono_int_test (const char *filename
, int format
, int long_file_ok
, int allow_fd
) ;
1977 static void stereo_int_test (const char *filename
, int format
, int long_file_ok
, int allow_fd
) ;
1978 static void mono_rdwr_int_test (const char *filename
, int format
, int long_file_ok
, int allow_fd
) ;
1979 static void new_rdwr_int_test (const char *filename
, int format
, int allow_fd
) ;
1980 static void multi_seek_test (const char * filename
, int format
) ;
1981 static void write_seek_extend_test (const char * filename
, int format
) ;
1984 pcm_test_int (const char *filename
, int format
, int long_file_ok
)
1989 /* Sd2 files cannot be opened from an existing file descriptor. */
1990 allow_fd
= ((format
& SF_FORMAT_TYPEMASK
) == SF_FORMAT_SD2
) ? SF_FALSE
: SF_TRUE
;
1992 print_test_name ("pcm_test_int", filename
) ;
1994 sfinfo
.samplerate
= 44100 ;
1995 sfinfo
.frames
= SILLY_WRITE_COUNT
; /* Wrong length. Library should correct this on sf_close. */
1996 sfinfo
.channels
= 1 ;
1997 sfinfo
.format
= format
;
1999 gen_windowed_sine_double (orig_data
.d
, DATA_LENGTH
, (1.0 * 0x7F000000)) ;
2001 orig
= orig_data
.i
;
2003 /* Make this a macro so gdb steps over it in one go. */
2004 CONVERT_DATA (k
, DATA_LENGTH
, orig
, orig_data
.d
) ;
2006 /* Some test broken out here. */
2008 mono_int_test (filename
, format
, long_file_ok
, allow_fd
) ;
2010 /* Sub format DWVW does not allow seeking. */
2011 if ((format
& SF_FORMAT_SUBMASK
) == SF_FORMAT_DWVW_16
||
2012 (format
& SF_FORMAT_SUBMASK
) == SF_FORMAT_DWVW_24
)
2013 { unlink (filename
) ;
2014 printf ("no seek : ok\n") ;
2018 if ((format
& SF_FORMAT_TYPEMASK
) != SF_FORMAT_FLAC
)
2019 mono_rdwr_int_test (filename
, format
, long_file_ok
, allow_fd
) ;
2021 /* If the format doesn't support stereo we're done. */
2022 sfinfo
.channels
= 2 ;
2023 if (sf_format_check (&sfinfo
) == 0)
2024 { unlink (filename
) ;
2025 puts ("no stereo : ok") ;
2029 stereo_int_test (filename
, format
, long_file_ok
, allow_fd
) ;
2031 /* New read/write test. Not sure if this is needed yet. */
2033 if ((format
& SF_FORMAT_TYPEMASK
) != SF_FORMAT_PAF
&&
2034 (format
& SF_FORMAT_TYPEMASK
) != SF_FORMAT_VOC
&&
2035 (format
& SF_FORMAT_TYPEMASK
) != SF_FORMAT_FLAC
)
2036 new_rdwr_int_test (filename
, format
, allow_fd
) ;
2038 delete_file (format
, filename
) ;
2042 } /* pcm_test_int */
2045 mono_int_test (const char *filename
, int format
, int long_file_ok
, int allow_fd
)
2052 sfinfo
.samplerate
= 44100 ;
2053 sfinfo
.frames
= SILLY_WRITE_COUNT
; /* Wrong length. Library should correct this on sf_close. */
2054 sfinfo
.channels
= 1 ;
2055 sfinfo
.format
= format
;
2057 orig
= orig_data
.i
;
2058 test
= test_data
.i
;
2060 items
= DATA_LENGTH
;
2062 file
= test_open_file_or_die (filename
, SFM_WRITE
, &sfinfo
, allow_fd
, __LINE__
) ;
2064 sf_set_string (file
, SF_STR_ARTIST
, "Your name here") ;
2066 test_write_int_or_die (file
, 0, orig
, items
, __LINE__
) ;
2067 sf_write_sync (file
) ;
2068 test_write_int_or_die (file
, 0, orig
, items
, __LINE__
) ;
2069 sf_write_sync (file
) ;
2071 /* Add non-audio data after the audio. */
2072 sf_set_string (file
, SF_STR_COPYRIGHT
, "Copyright (c) 2003") ;
2076 memset (test
, 0, items
* sizeof (int)) ;
2078 if ((format
& SF_FORMAT_TYPEMASK
) != SF_FORMAT_RAW
)
2079 memset (&sfinfo
, 0, sizeof (sfinfo
)) ;
2081 file
= test_open_file_or_die (filename
, SFM_READ
, &sfinfo
, allow_fd
, __LINE__
) ;
2083 if (sfinfo
.format
!= format
)
2084 { printf ("\n\nLine %d : Mono : Returned format incorrect (0x%08X => 0x%08X).\n", __LINE__
, format
, sfinfo
.format
) ;
2088 if (sfinfo
.frames
< 2 * items
)
2089 { 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
) ;
2093 if (! long_file_ok
&& sfinfo
.frames
> 2 * items
)
2094 { 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
) ;
2098 if (sfinfo
.channels
!= 1)
2099 { printf ("\n\nLine %d : Mono : Incorrect number of channels in file.\n", __LINE__
) ;
2103 check_log_buffer_or_die (file
, __LINE__
) ;
2105 test_read_int_or_die (file
, 0, test
, items
, __LINE__
) ;
2106 for (k
= 0 ; k
< items
; k
++)
2107 if (INT_ERROR (orig
[k
], test
[k
]))
2108 { printf ("\n\nLine %d: Mono : Incorrect sample A (#%d : 0x%X => 0x%X).\n", __LINE__
, k
, orig
[k
], test
[k
]) ;
2109 oct_save_int (orig
, test
, items
) ;
2113 /* Seek to start of file. */
2114 test_seek_or_die (file
, 0, SEEK_SET
, 0, sfinfo
.channels
, __LINE__
) ;
2116 test_read_int_or_die (file
, 0, test
, 4, __LINE__
) ;
2117 for (k
= 0 ; k
< 4 ; k
++)
2118 if (INT_ERROR (orig
[k
], test
[k
]))
2119 { printf ("\n\nLine %d : Mono : Incorrect sample A (#%d : 0x%X => 0x%X).\n", __LINE__
, k
, orig
[k
], test
[k
]) ;
2123 if ((format
& SF_FORMAT_SUBMASK
) == SF_FORMAT_DWVW_16
||
2124 (format
& SF_FORMAT_SUBMASK
) == SF_FORMAT_DWVW_24
)
2127 printf ("no seek : ") ;
2131 /* Seek to offset from start of file. */
2132 test_seek_or_die (file
, items
+ 10, SEEK_SET
, items
+ 10, sfinfo
.channels
, __LINE__
) ;
2134 test_read_int_or_die (file
, 0, test
+ 10, 4, __LINE__
) ;
2135 for (k
= 10 ; k
< 14 ; k
++)
2136 if (INT_ERROR (orig
[k
], test
[k
]))
2137 { printf ("\n\nLine %d : Mono : Incorrect sample A (#%d : 0x%X => 0x%X).\n", __LINE__
, k
, test
[k
], orig
[k
]) ;
2141 /* Seek to offset from current position. */
2142 test_seek_or_die (file
, 6, SEEK_CUR
, items
+ 20, sfinfo
.channels
, __LINE__
) ;
2144 test_read_int_or_die (file
, 0, test
+ 20, 4, __LINE__
) ;
2145 for (k
= 20 ; k
< 24 ; k
++)
2146 if (INT_ERROR (orig
[k
], test
[k
]))
2147 { printf ("\n\nLine %d : Mono : Incorrect sample A (#%d : 0x%X => 0x%X).\n", __LINE__
, k
, test
[k
], orig
[k
]) ;
2151 /* Seek to offset from end of file. */
2152 test_seek_or_die (file
, -1 * (sfinfo
.frames
- 10), SEEK_END
, 10, sfinfo
.channels
, __LINE__
) ;
2154 test_read_int_or_die (file
, 0, test
+ 10, 4, __LINE__
) ;
2155 for (k
= 10 ; k
< 14 ; k
++)
2156 if (INT_ERROR (orig
[k
], test
[k
]))
2157 { printf ("\n\nLine %d : Mono : Incorrect sample D (#%d : 0x%X => 0x%X).\n", __LINE__
, k
, test
[k
], orig
[k
]) ;
2161 /* Check read past end of file followed by sf_seek (sndfile, 0, SEEK_CUR). */
2162 test_seek_or_die (file
, 0, SEEK_SET
, 0, sfinfo
.channels
, __LINE__
) ;
2165 while (count
< sfinfo
.frames
)
2166 count
+= sf_read_int (file
, test
, 311) ;
2168 /* Check that no error has occurred. */
2169 if (sf_error (file
))
2170 { printf ("\n\nLine %d : Mono : error where there shouldn't have been one.\n", __LINE__
) ;
2171 puts (sf_strerror (file
)) ;
2175 /* Check that we haven't read beyond EOF. */
2176 if (count
> sfinfo
.frames
)
2177 { printf ("\n\nLines %d : read past end of file (%ld should be %ld)\n", __LINE__
, (long) count
, (long) sfinfo
.frames
) ;
2181 test_seek_or_die (file
, 0, SEEK_CUR
, sfinfo
.frames
, sfinfo
.channels
, __LINE__
) ;
2185 multi_seek_test (filename
, format
) ;
2186 write_seek_extend_test (filename
, format
) ;
2188 } /* mono_int_test */
2191 stereo_int_test (const char *filename
, int format
, int long_file_ok
, int allow_fd
)
2195 int k
, items
, frames
;
2197 sfinfo
.samplerate
= 44100 ;
2198 sfinfo
.frames
= SILLY_WRITE_COUNT
; /* Wrong length. Library should correct this on sf_close. */
2199 sfinfo
.channels
= 2 ;
2200 sfinfo
.format
= format
;
2202 gen_windowed_sine_double (orig_data
.d
, DATA_LENGTH
, (1.0 * 0x7F000000)) ;
2204 orig
= orig_data
.i
;
2205 test
= test_data
.i
;
2207 /* Make this a macro so gdb steps over it in one go. */
2208 CONVERT_DATA (k
, DATA_LENGTH
, orig
, orig_data
.d
) ;
2210 items
= DATA_LENGTH
;
2211 frames
= items
/ sfinfo
.channels
;
2213 file
= test_open_file_or_die (filename
, SFM_WRITE
, &sfinfo
, allow_fd
, __LINE__
) ;
2215 sf_set_string (file
, SF_STR_ARTIST
, "Your name here") ;
2217 test_writef_int_or_die (file
, 0, orig
, frames
, __LINE__
) ;
2219 sf_set_string (file
, SF_STR_COPYRIGHT
, "Copyright (c) 2003") ;
2223 memset (test
, 0, items
* sizeof (int)) ;
2225 if ((format
& SF_FORMAT_TYPEMASK
) != SF_FORMAT_RAW
)
2226 memset (&sfinfo
, 0, sizeof (sfinfo
)) ;
2228 file
= test_open_file_or_die (filename
, SFM_READ
, &sfinfo
, allow_fd
, __LINE__
) ;
2230 if (sfinfo
.format
!= format
)
2231 { printf ("\n\nLine %d : Stereo : Returned format incorrect (0x%08X => 0x%08X).\n",
2232 __LINE__
, format
, sfinfo
.format
) ;
2236 if (sfinfo
.frames
< frames
)
2237 { printf ("\n\nLine %d : Stereo : Incorrect number of frames in file (too short). (%ld should be %d)\n",
2238 __LINE__
, SF_COUNT_TO_LONG (sfinfo
.frames
), frames
) ;
2242 if (! long_file_ok
&& sfinfo
.frames
> frames
)
2243 { printf ("\n\nLine %d : Stereo : Incorrect number of frames in file (too long). (%ld should be %d)\n",
2244 __LINE__
, SF_COUNT_TO_LONG (sfinfo
.frames
), frames
) ;
2248 if (sfinfo
.channels
!= 2)
2249 { printf ("\n\nLine %d : Stereo : Incorrect number of channels in file.\n", __LINE__
) ;
2253 check_log_buffer_or_die (file
, __LINE__
) ;
2255 test_readf_int_or_die (file
, 0, test
, frames
, __LINE__
) ;
2256 for (k
= 0 ; k
< items
; k
++)
2257 if (INT_ERROR (test
[k
], orig
[k
]))
2258 { printf ("\n\nLine %d : Stereo : Incorrect sample (#%d : 0x%X => 0x%X).\n", __LINE__
, k
, orig
[k
], test
[k
]) ;
2262 /* Seek to start of file. */
2263 test_seek_or_die (file
, 0, SEEK_SET
, 0, sfinfo
.channels
, __LINE__
) ;
2265 test_readf_int_or_die (file
, 0, test
, 2, __LINE__
) ;
2266 for (k
= 0 ; k
< 4 ; k
++)
2267 if (INT_ERROR (test
[k
], orig
[k
]))
2268 { printf ("\n\nLine %d : Stereo : Incorrect sample (#%d : 0x%X => 0x%X).\n", __LINE__
, k
, orig
[k
], test
[k
]) ;
2272 /* Seek to offset from start of file. */
2273 test_seek_or_die (file
, 10, SEEK_SET
, 10, sfinfo
.channels
, __LINE__
) ;
2275 /* Check for errors here. */
2276 if (sf_error (file
))
2277 { printf ("Line %d: Should NOT return an error.\n", __LINE__
) ;
2278 puts (sf_strerror (file
)) ;
2282 if (sf_read_int (file
, test
, 1) > 0)
2283 { printf ("Line %d: Should return 0.\n", __LINE__
) ;
2287 if (! sf_error (file
))
2288 { printf ("Line %d: Should return an error.\n", __LINE__
) ;
2291 /*-----------------------*/
2293 test_readf_int_or_die (file
, 0, test
+ 10, 2, __LINE__
) ;
2294 for (k
= 20 ; k
< 24 ; k
++)
2295 if (INT_ERROR (test
[k
], orig
[k
]))
2296 { printf ("\n\nLine %d : Stereo : Incorrect sample (#%d : 0x%X => 0x%X).\n", __LINE__
, k
, orig
[k
], test
[k
]) ;
2300 /* Seek to offset from current position. */
2301 test_seek_or_die (file
, 8, SEEK_CUR
, 20, sfinfo
.channels
, __LINE__
) ;
2303 test_readf_int_or_die (file
, 0, test
+ 20, 2, __LINE__
) ;
2304 for (k
= 40 ; k
< 44 ; k
++)
2305 if (INT_ERROR (test
[k
], orig
[k
]))
2306 { printf ("\n\nLine %d : Stereo : Incorrect sample (#%d : 0x%X => 0x%X).\n", __LINE__
, k
, orig
[k
], test
[k
]) ;
2310 /* Seek to offset from end of file. */
2311 test_seek_or_die (file
, -1 * (sfinfo
.frames
- 10), SEEK_END
, 10, sfinfo
.channels
, __LINE__
) ;
2313 test_readf_int_or_die (file
, 0, test
+ 20, 2, __LINE__
) ;
2314 for (k
= 20 ; k
< 24 ; k
++)
2315 if (INT_ERROR (test
[k
], orig
[k
]))
2316 { printf ("\n\nLine %d : Stereo : Incorrect sample (#%d : 0x%X => 0x%X).\n", __LINE__
, k
, orig
[k
], test
[k
]) ;
2321 } /* stereo_int_test */
2324 mono_rdwr_int_test (const char *filename
, int format
, int long_file_ok
, int allow_fd
)
2330 orig
= orig_data
.i
;
2331 test
= test_data
.i
;
2333 sfinfo
.samplerate
= SAMPLE_RATE
;
2334 sfinfo
.frames
= DATA_LENGTH
;
2335 sfinfo
.channels
= 1 ;
2336 sfinfo
.format
= format
;
2338 if ((format
& SF_FORMAT_TYPEMASK
) == SF_FORMAT_RAW
2339 || (format
& SF_FORMAT_TYPEMASK
) == SF_FORMAT_AU
2340 || (format
& SF_FORMAT_TYPEMASK
) == SF_FORMAT_SD2
)
2343 { /* Create a short file. */
2344 create_short_file (filename
) ;
2346 /* Opening a already existing short file (ie invalid header) RDWR is disallowed.
2347 ** If this returns a valif pointer sf_open() screwed up.
2349 if ((file
= sf_open (filename
, SFM_RDWR
, &sfinfo
)))
2350 { printf ("\n\nLine %d: sf_open should (SFM_RDWR) have failed but didn't.\n", __LINE__
) ;
2354 /* Truncate the file to zero bytes. */
2355 if (truncate (filename
, 0) < 0)
2356 { printf ("\n\nLine %d: truncate (%s) failed", __LINE__
, filename
) ;
2362 /* Opening a zero length file RDWR is allowed, but the SF_INFO struct must contain
2363 ** all the usual data required when opening the file in WRITE mode.
2365 sfinfo
.samplerate
= SAMPLE_RATE
;
2366 sfinfo
.frames
= DATA_LENGTH
;
2367 sfinfo
.channels
= 1 ;
2368 sfinfo
.format
= format
;
2370 file
= test_open_file_or_die (filename
, SFM_RDWR
, &sfinfo
, allow_fd
, __LINE__
) ;
2372 /* Do 3 writes followed by reads. After each, check the data and the current
2373 ** read and write offsets.
2375 for (pass
= 1 ; pass
<= 3 ; pass
++)
2376 { orig
[20] = pass
* 2 ;
2378 /* Write some data. */
2379 test_write_int_or_die (file
, pass
, orig
, DATA_LENGTH
, __LINE__
) ;
2381 test_read_write_position_or_die (file
, __LINE__
, pass
, (pass
- 1) * DATA_LENGTH
, pass
* DATA_LENGTH
) ;
2383 /* Read what we just wrote. */
2384 test_read_int_or_die (file
, 0, test
, DATA_LENGTH
, __LINE__
) ;
2386 /* Check the data. */
2387 for (k
= 0 ; k
< DATA_LENGTH
; k
++)
2388 if (INT_ERROR (orig
[k
], test
[k
]))
2389 { printf ("\n\nLine %d (pass %d) A : Error at sample %d (0x%X => 0x%X).\n", __LINE__
, pass
, k
, orig
[k
], test
[k
]) ;
2390 oct_save_int (orig
, test
, DATA_LENGTH
) ;
2394 test_read_write_position_or_die (file
, __LINE__
, pass
, pass
* DATA_LENGTH
, pass
* DATA_LENGTH
) ;
2395 } ; /* for (pass ...) */
2399 /* Open the file again to check the data. */
2400 file
= test_open_file_or_die (filename
, SFM_RDWR
, &sfinfo
, allow_fd
, __LINE__
) ;
2402 if (sfinfo
.format
!= format
)
2403 { printf ("\n\nLine %d : Returned format incorrect (0x%08X => 0x%08X).\n", __LINE__
, format
, sfinfo
.format
) ;
2407 if (sfinfo
.frames
< 3 * DATA_LENGTH
)
2408 { printf ("\n\nLine %d : Not enough frames in file. (%ld < %d)\n", __LINE__
, SF_COUNT_TO_LONG (sfinfo
.frames
), 3 * DATA_LENGTH
) ;
2412 if (! long_file_ok
&& sfinfo
.frames
!= 3 * DATA_LENGTH
)
2413 { 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
) ;
2417 if (sfinfo
.channels
!= 1)
2418 { printf ("\n\nLine %d : Incorrect number of channels in file.\n", __LINE__
) ;
2423 test_read_write_position_or_die (file
, __LINE__
, 0, 0, 3 * DATA_LENGTH
) ;
2425 test_seek_or_die (file
, 3 * DATA_LENGTH
, SFM_WRITE
| SEEK_SET
, 3 * DATA_LENGTH
, sfinfo
.channels
, __LINE__
) ;
2427 for (pass
= 1 ; pass
<= 3 ; pass
++)
2428 { orig
[20] = pass
* 2 ;
2430 test_read_write_position_or_die (file
, __LINE__
, pass
, (pass
- 1) * DATA_LENGTH
, 3 * DATA_LENGTH
) ;
2432 /* Read what we just wrote. */
2433 test_read_int_or_die (file
, pass
, test
, DATA_LENGTH
, __LINE__
) ;
2435 /* Check the data. */
2436 for (k
= 0 ; k
< DATA_LENGTH
; k
++)
2437 if (INT_ERROR (orig
[k
], test
[k
]))
2438 { printf ("\n\nLine %d (pass %d) B : Error at sample %d (0x%X => 0x%X).\n", __LINE__
, pass
, k
, orig
[k
], test
[k
]) ;
2439 oct_save_int (orig
, test
, DATA_LENGTH
) ;
2443 } ; /* for (pass ...) */
2446 } /* mono_rdwr_int_test */
2449 new_rdwr_int_test (const char *filename
, int format
, int allow_fd
)
2450 { SNDFILE
*wfile
, *rwfile
;
2455 orig
= orig_data
.i
;
2456 test
= test_data
.i
;
2458 sfinfo
.samplerate
= 44100 ;
2459 sfinfo
.frames
= SILLY_WRITE_COUNT
; /* Wrong length. Library should correct this on sf_close. */
2460 sfinfo
.channels
= 2 ;
2461 sfinfo
.format
= format
;
2463 items
= DATA_LENGTH
;
2464 frames
= items
/ sfinfo
.channels
;
2466 wfile
= test_open_file_or_die (filename
, SFM_WRITE
, &sfinfo
, allow_fd
, __LINE__
) ;
2467 sf_command (wfile
, SFC_SET_UPDATE_HEADER_AUTO
, NULL
, SF_TRUE
) ;
2468 test_writef_int_or_die (wfile
, 1, orig
, frames
, __LINE__
) ;
2469 sf_write_sync (wfile
) ;
2470 test_writef_int_or_die (wfile
, 2, orig
, frames
, __LINE__
) ;
2471 sf_write_sync (wfile
) ;
2473 rwfile
= test_open_file_or_die (filename
, SFM_RDWR
, &sfinfo
, allow_fd
, __LINE__
) ;
2474 if (sfinfo
.frames
!= 2 * frames
)
2475 { 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
) ;
2479 test_writef_int_or_die (wfile
, 3, orig
, frames
, __LINE__
) ;
2481 test_readf_int_or_die (rwfile
, 1, test
, frames
, __LINE__
) ;
2482 test_readf_int_or_die (rwfile
, 2, test
, frames
, __LINE__
) ;
2486 } /* new_rdwr_int_test */
2489 /*======================================================================================
2492 static void mono_float_test (const char *filename
, int format
, int long_file_ok
, int allow_fd
) ;
2493 static void stereo_float_test (const char *filename
, int format
, int long_file_ok
, int allow_fd
) ;
2494 static void mono_rdwr_float_test (const char *filename
, int format
, int long_file_ok
, int allow_fd
) ;
2495 static void new_rdwr_float_test (const char *filename
, int format
, int allow_fd
) ;
2496 static void multi_seek_test (const char * filename
, int format
) ;
2497 static void write_seek_extend_test (const char * filename
, int format
) ;
2500 pcm_test_float (const char *filename
, int format
, int long_file_ok
)
2505 /* Sd2 files cannot be opened from an existing file descriptor. */
2506 allow_fd
= ((format
& SF_FORMAT_TYPEMASK
) == SF_FORMAT_SD2
) ? SF_FALSE
: SF_TRUE
;
2508 print_test_name ("pcm_test_float", filename
) ;
2510 sfinfo
.samplerate
= 44100 ;
2511 sfinfo
.frames
= SILLY_WRITE_COUNT
; /* Wrong length. Library should correct this on sf_close. */
2512 sfinfo
.channels
= 1 ;
2513 sfinfo
.format
= format
;
2515 gen_windowed_sine_double (orig_data
.d
, DATA_LENGTH
, 1.0) ;
2517 orig
= orig_data
.f
;
2519 /* Make this a macro so gdb steps over it in one go. */
2520 CONVERT_DATA (k
, DATA_LENGTH
, orig
, orig_data
.d
) ;
2522 /* Some test broken out here. */
2524 mono_float_test (filename
, format
, long_file_ok
, allow_fd
) ;
2526 /* Sub format DWVW does not allow seeking. */
2527 if ((format
& SF_FORMAT_SUBMASK
) == SF_FORMAT_DWVW_16
||
2528 (format
& SF_FORMAT_SUBMASK
) == SF_FORMAT_DWVW_24
)
2529 { unlink (filename
) ;
2530 printf ("no seek : ok\n") ;
2534 if ((format
& SF_FORMAT_TYPEMASK
) != SF_FORMAT_FLAC
)
2535 mono_rdwr_float_test (filename
, format
, long_file_ok
, allow_fd
) ;
2537 /* If the format doesn't support stereo we're done. */
2538 sfinfo
.channels
= 2 ;
2539 if (sf_format_check (&sfinfo
) == 0)
2540 { unlink (filename
) ;
2541 puts ("no stereo : ok") ;
2545 stereo_float_test (filename
, format
, long_file_ok
, allow_fd
) ;
2547 /* New read/write test. Not sure if this is needed yet. */
2549 if ((format
& SF_FORMAT_TYPEMASK
) != SF_FORMAT_PAF
&&
2550 (format
& SF_FORMAT_TYPEMASK
) != SF_FORMAT_VOC
&&
2551 (format
& SF_FORMAT_TYPEMASK
) != SF_FORMAT_FLAC
)
2552 new_rdwr_float_test (filename
, format
, allow_fd
) ;
2554 delete_file (format
, filename
) ;
2558 } /* pcm_test_float */
2561 mono_float_test (const char *filename
, int format
, int long_file_ok
, int allow_fd
)
2564 float *orig
, *test
;
2568 sfinfo
.samplerate
= 44100 ;
2569 sfinfo
.frames
= SILLY_WRITE_COUNT
; /* Wrong length. Library should correct this on sf_close. */
2570 sfinfo
.channels
= 1 ;
2571 sfinfo
.format
= format
;
2573 orig
= orig_data
.f
;
2574 test
= test_data
.f
;
2576 items
= DATA_LENGTH
;
2578 file
= test_open_file_or_die (filename
, SFM_WRITE
, &sfinfo
, allow_fd
, __LINE__
) ;
2580 sf_set_string (file
, SF_STR_ARTIST
, "Your name here") ;
2582 test_write_float_or_die (file
, 0, orig
, items
, __LINE__
) ;
2583 sf_write_sync (file
) ;
2584 test_write_float_or_die (file
, 0, orig
, items
, __LINE__
) ;
2585 sf_write_sync (file
) ;
2587 /* Add non-audio data after the audio. */
2588 sf_set_string (file
, SF_STR_COPYRIGHT
, "Copyright (c) 2003") ;
2592 memset (test
, 0, items
* sizeof (float)) ;
2594 if ((format
& SF_FORMAT_TYPEMASK
) != SF_FORMAT_RAW
)
2595 memset (&sfinfo
, 0, sizeof (sfinfo
)) ;
2597 file
= test_open_file_or_die (filename
, SFM_READ
, &sfinfo
, allow_fd
, __LINE__
) ;
2599 if (sfinfo
.format
!= format
)
2600 { printf ("\n\nLine %d : Mono : Returned format incorrect (0x%08X => 0x%08X).\n", __LINE__
, format
, sfinfo
.format
) ;
2604 if (sfinfo
.frames
< 2 * items
)
2605 { 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
) ;
2609 if (! long_file_ok
&& sfinfo
.frames
> 2 * items
)
2610 { 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
) ;
2614 if (sfinfo
.channels
!= 1)
2615 { printf ("\n\nLine %d : Mono : Incorrect number of channels in file.\n", __LINE__
) ;
2619 check_log_buffer_or_die (file
, __LINE__
) ;
2621 test_read_float_or_die (file
, 0, test
, items
, __LINE__
) ;
2622 for (k
= 0 ; k
< items
; k
++)
2623 if (FLOAT_ERROR (orig
[k
], test
[k
]))
2624 { printf ("\n\nLine %d: Mono : Incorrect sample A (#%d : %g => %g).\n", __LINE__
, k
, orig
[k
], test
[k
]) ;
2625 oct_save_float (orig
, test
, items
) ;
2629 /* Seek to start of file. */
2630 test_seek_or_die (file
, 0, SEEK_SET
, 0, sfinfo
.channels
, __LINE__
) ;
2632 test_read_float_or_die (file
, 0, test
, 4, __LINE__
) ;
2633 for (k
= 0 ; k
< 4 ; k
++)
2634 if (FLOAT_ERROR (orig
[k
], test
[k
]))
2635 { printf ("\n\nLine %d : Mono : Incorrect sample A (#%d : %g => %g).\n", __LINE__
, k
, orig
[k
], test
[k
]) ;
2639 if ((format
& SF_FORMAT_SUBMASK
) == SF_FORMAT_DWVW_16
||
2640 (format
& SF_FORMAT_SUBMASK
) == SF_FORMAT_DWVW_24
)
2643 printf ("no seek : ") ;
2647 /* Seek to offset from start of file. */
2648 test_seek_or_die (file
, items
+ 10, SEEK_SET
, items
+ 10, sfinfo
.channels
, __LINE__
) ;
2650 test_read_float_or_die (file
, 0, test
+ 10, 4, __LINE__
) ;
2651 for (k
= 10 ; k
< 14 ; k
++)
2652 if (FLOAT_ERROR (orig
[k
], test
[k
]))
2653 { printf ("\n\nLine %d : Mono : Incorrect sample A (#%d : %g => %g).\n", __LINE__
, k
, test
[k
], orig
[k
]) ;
2657 /* Seek to offset from current position. */
2658 test_seek_or_die (file
, 6, SEEK_CUR
, items
+ 20, sfinfo
.channels
, __LINE__
) ;
2660 test_read_float_or_die (file
, 0, test
+ 20, 4, __LINE__
) ;
2661 for (k
= 20 ; k
< 24 ; k
++)
2662 if (FLOAT_ERROR (orig
[k
], test
[k
]))
2663 { printf ("\n\nLine %d : Mono : Incorrect sample A (#%d : %g => %g).\n", __LINE__
, k
, test
[k
], orig
[k
]) ;
2667 /* Seek to offset from end of file. */
2668 test_seek_or_die (file
, -1 * (sfinfo
.frames
- 10), SEEK_END
, 10, sfinfo
.channels
, __LINE__
) ;
2670 test_read_float_or_die (file
, 0, test
+ 10, 4, __LINE__
) ;
2671 for (k
= 10 ; k
< 14 ; k
++)
2672 if (FLOAT_ERROR (orig
[k
], test
[k
]))
2673 { printf ("\n\nLine %d : Mono : Incorrect sample D (#%d : %g => %g).\n", __LINE__
, k
, test
[k
], orig
[k
]) ;
2677 /* Check read past end of file followed by sf_seek (sndfile, 0, SEEK_CUR). */
2678 test_seek_or_die (file
, 0, SEEK_SET
, 0, sfinfo
.channels
, __LINE__
) ;
2681 while (count
< sfinfo
.frames
)
2682 count
+= sf_read_float (file
, test
, 311) ;
2684 /* Check that no error has occurred. */
2685 if (sf_error (file
))
2686 { printf ("\n\nLine %d : Mono : error where there shouldn't have been one.\n", __LINE__
) ;
2687 puts (sf_strerror (file
)) ;
2691 /* Check that we haven't read beyond EOF. */
2692 if (count
> sfinfo
.frames
)
2693 { printf ("\n\nLines %d : read past end of file (%ld should be %ld)\n", __LINE__
, (long) count
, (long) sfinfo
.frames
) ;
2697 test_seek_or_die (file
, 0, SEEK_CUR
, sfinfo
.frames
, sfinfo
.channels
, __LINE__
) ;
2701 multi_seek_test (filename
, format
) ;
2702 write_seek_extend_test (filename
, format
) ;
2704 } /* mono_float_test */
2707 stereo_float_test (const char *filename
, int format
, int long_file_ok
, int allow_fd
)
2710 float *orig
, *test
;
2711 int k
, items
, frames
;
2713 sfinfo
.samplerate
= 44100 ;
2714 sfinfo
.frames
= SILLY_WRITE_COUNT
; /* Wrong length. Library should correct this on sf_close. */
2715 sfinfo
.channels
= 2 ;
2716 sfinfo
.format
= format
;
2718 gen_windowed_sine_double (orig_data
.d
, DATA_LENGTH
, 1.0) ;
2720 orig
= orig_data
.f
;
2721 test
= test_data
.f
;
2723 /* Make this a macro so gdb steps over it in one go. */
2724 CONVERT_DATA (k
, DATA_LENGTH
, orig
, orig_data
.d
) ;
2726 items
= DATA_LENGTH
;
2727 frames
= items
/ sfinfo
.channels
;
2729 file
= test_open_file_or_die (filename
, SFM_WRITE
, &sfinfo
, allow_fd
, __LINE__
) ;
2731 sf_set_string (file
, SF_STR_ARTIST
, "Your name here") ;
2733 test_writef_float_or_die (file
, 0, orig
, frames
, __LINE__
) ;
2735 sf_set_string (file
, SF_STR_COPYRIGHT
, "Copyright (c) 2003") ;
2739 memset (test
, 0, items
* sizeof (float)) ;
2741 if ((format
& SF_FORMAT_TYPEMASK
) != SF_FORMAT_RAW
)
2742 memset (&sfinfo
, 0, sizeof (sfinfo
)) ;
2744 file
= test_open_file_or_die (filename
, SFM_READ
, &sfinfo
, allow_fd
, __LINE__
) ;
2746 if (sfinfo
.format
!= format
)
2747 { printf ("\n\nLine %d : Stereo : Returned format incorrect (0x%08X => 0x%08X).\n",
2748 __LINE__
, format
, sfinfo
.format
) ;
2752 if (sfinfo
.frames
< frames
)
2753 { printf ("\n\nLine %d : Stereo : Incorrect number of frames in file (too short). (%ld should be %d)\n",
2754 __LINE__
, SF_COUNT_TO_LONG (sfinfo
.frames
), frames
) ;
2758 if (! long_file_ok
&& sfinfo
.frames
> frames
)
2759 { printf ("\n\nLine %d : Stereo : Incorrect number of frames in file (too long). (%ld should be %d)\n",
2760 __LINE__
, SF_COUNT_TO_LONG (sfinfo
.frames
), frames
) ;
2764 if (sfinfo
.channels
!= 2)
2765 { printf ("\n\nLine %d : Stereo : Incorrect number of channels in file.\n", __LINE__
) ;
2769 check_log_buffer_or_die (file
, __LINE__
) ;
2771 test_readf_float_or_die (file
, 0, test
, frames
, __LINE__
) ;
2772 for (k
= 0 ; k
< items
; k
++)
2773 if (FLOAT_ERROR (test
[k
], orig
[k
]))
2774 { printf ("\n\nLine %d : Stereo : Incorrect sample (#%d : %g => %g).\n", __LINE__
, k
, orig
[k
], test
[k
]) ;
2778 /* Seek to start of file. */
2779 test_seek_or_die (file
, 0, SEEK_SET
, 0, sfinfo
.channels
, __LINE__
) ;
2781 test_readf_float_or_die (file
, 0, test
, 2, __LINE__
) ;
2782 for (k
= 0 ; k
< 4 ; k
++)
2783 if (FLOAT_ERROR (test
[k
], orig
[k
]))
2784 { printf ("\n\nLine %d : Stereo : Incorrect sample (#%d : %g => %g).\n", __LINE__
, k
, orig
[k
], test
[k
]) ;
2788 /* Seek to offset from start of file. */
2789 test_seek_or_die (file
, 10, SEEK_SET
, 10, sfinfo
.channels
, __LINE__
) ;
2791 /* Check for errors here. */
2792 if (sf_error (file
))
2793 { printf ("Line %d: Should NOT return an error.\n", __LINE__
) ;
2794 puts (sf_strerror (file
)) ;
2798 if (sf_read_float (file
, test
, 1) > 0)
2799 { printf ("Line %d: Should return 0.\n", __LINE__
) ;
2803 if (! sf_error (file
))
2804 { printf ("Line %d: Should return an error.\n", __LINE__
) ;
2807 /*-----------------------*/
2809 test_readf_float_or_die (file
, 0, test
+ 10, 2, __LINE__
) ;
2810 for (k
= 20 ; k
< 24 ; k
++)
2811 if (FLOAT_ERROR (test
[k
], orig
[k
]))
2812 { printf ("\n\nLine %d : Stereo : Incorrect sample (#%d : %g => %g).\n", __LINE__
, k
, orig
[k
], test
[k
]) ;
2816 /* Seek to offset from current position. */
2817 test_seek_or_die (file
, 8, SEEK_CUR
, 20, sfinfo
.channels
, __LINE__
) ;
2819 test_readf_float_or_die (file
, 0, test
+ 20, 2, __LINE__
) ;
2820 for (k
= 40 ; k
< 44 ; k
++)
2821 if (FLOAT_ERROR (test
[k
], orig
[k
]))
2822 { printf ("\n\nLine %d : Stereo : Incorrect sample (#%d : %g => %g).\n", __LINE__
, k
, orig
[k
], test
[k
]) ;
2826 /* Seek to offset from end of file. */
2827 test_seek_or_die (file
, -1 * (sfinfo
.frames
- 10), SEEK_END
, 10, sfinfo
.channels
, __LINE__
) ;
2829 test_readf_float_or_die (file
, 0, test
+ 20, 2, __LINE__
) ;
2830 for (k
= 20 ; k
< 24 ; k
++)
2831 if (FLOAT_ERROR (test
[k
], orig
[k
]))
2832 { printf ("\n\nLine %d : Stereo : Incorrect sample (#%d : %g => %g).\n", __LINE__
, k
, orig
[k
], test
[k
]) ;
2837 } /* stereo_float_test */
2840 mono_rdwr_float_test (const char *filename
, int format
, int long_file_ok
, int allow_fd
)
2843 float *orig
, *test
;
2846 orig
= orig_data
.f
;
2847 test
= test_data
.f
;
2849 sfinfo
.samplerate
= SAMPLE_RATE
;
2850 sfinfo
.frames
= DATA_LENGTH
;
2851 sfinfo
.channels
= 1 ;
2852 sfinfo
.format
= format
;
2854 if ((format
& SF_FORMAT_TYPEMASK
) == SF_FORMAT_RAW
2855 || (format
& SF_FORMAT_TYPEMASK
) == SF_FORMAT_AU
2856 || (format
& SF_FORMAT_TYPEMASK
) == SF_FORMAT_SD2
)
2859 { /* Create a short file. */
2860 create_short_file (filename
) ;
2862 /* Opening a already existing short file (ie invalid header) RDWR is disallowed.
2863 ** If this returns a valif pointer sf_open() screwed up.
2865 if ((file
= sf_open (filename
, SFM_RDWR
, &sfinfo
)))
2866 { printf ("\n\nLine %d: sf_open should (SFM_RDWR) have failed but didn't.\n", __LINE__
) ;
2870 /* Truncate the file to zero bytes. */
2871 if (truncate (filename
, 0) < 0)
2872 { printf ("\n\nLine %d: truncate (%s) failed", __LINE__
, filename
) ;
2878 /* Opening a zero length file RDWR is allowed, but the SF_INFO struct must contain
2879 ** all the usual data required when opening the file in WRITE mode.
2881 sfinfo
.samplerate
= SAMPLE_RATE
;
2882 sfinfo
.frames
= DATA_LENGTH
;
2883 sfinfo
.channels
= 1 ;
2884 sfinfo
.format
= format
;
2886 file
= test_open_file_or_die (filename
, SFM_RDWR
, &sfinfo
, allow_fd
, __LINE__
) ;
2888 /* Do 3 writes followed by reads. After each, check the data and the current
2889 ** read and write offsets.
2891 for (pass
= 1 ; pass
<= 3 ; pass
++)
2892 { orig
[20] = pass
* 2 ;
2894 /* Write some data. */
2895 test_write_float_or_die (file
, pass
, orig
, DATA_LENGTH
, __LINE__
) ;
2897 test_read_write_position_or_die (file
, __LINE__
, pass
, (pass
- 1) * DATA_LENGTH
, pass
* DATA_LENGTH
) ;
2899 /* Read what we just wrote. */
2900 test_read_float_or_die (file
, 0, test
, DATA_LENGTH
, __LINE__
) ;
2902 /* Check the data. */
2903 for (k
= 0 ; k
< DATA_LENGTH
; k
++)
2904 if (FLOAT_ERROR (orig
[k
], test
[k
]))
2905 { printf ("\n\nLine %d (pass %d) A : Error at sample %d (%g => %g).\n", __LINE__
, pass
, k
, orig
[k
], test
[k
]) ;
2906 oct_save_float (orig
, test
, DATA_LENGTH
) ;
2910 test_read_write_position_or_die (file
, __LINE__
, pass
, pass
* DATA_LENGTH
, pass
* DATA_LENGTH
) ;
2911 } ; /* for (pass ...) */
2915 /* Open the file again to check the data. */
2916 file
= test_open_file_or_die (filename
, SFM_RDWR
, &sfinfo
, allow_fd
, __LINE__
) ;
2918 if (sfinfo
.format
!= format
)
2919 { printf ("\n\nLine %d : Returned format incorrect (0x%08X => 0x%08X).\n", __LINE__
, format
, sfinfo
.format
) ;
2923 if (sfinfo
.frames
< 3 * DATA_LENGTH
)
2924 { printf ("\n\nLine %d : Not enough frames in file. (%ld < %d)\n", __LINE__
, SF_COUNT_TO_LONG (sfinfo
.frames
), 3 * DATA_LENGTH
) ;
2928 if (! long_file_ok
&& sfinfo
.frames
!= 3 * DATA_LENGTH
)
2929 { 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
) ;
2933 if (sfinfo
.channels
!= 1)
2934 { printf ("\n\nLine %d : Incorrect number of channels in file.\n", __LINE__
) ;
2939 test_read_write_position_or_die (file
, __LINE__
, 0, 0, 3 * DATA_LENGTH
) ;
2941 test_seek_or_die (file
, 3 * DATA_LENGTH
, SFM_WRITE
| SEEK_SET
, 3 * DATA_LENGTH
, sfinfo
.channels
, __LINE__
) ;
2943 for (pass
= 1 ; pass
<= 3 ; pass
++)
2944 { orig
[20] = pass
* 2 ;
2946 test_read_write_position_or_die (file
, __LINE__
, pass
, (pass
- 1) * DATA_LENGTH
, 3 * DATA_LENGTH
) ;
2948 /* Read what we just wrote. */
2949 test_read_float_or_die (file
, pass
, test
, DATA_LENGTH
, __LINE__
) ;
2951 /* Check the data. */
2952 for (k
= 0 ; k
< DATA_LENGTH
; k
++)
2953 if (FLOAT_ERROR (orig
[k
], test
[k
]))
2954 { printf ("\n\nLine %d (pass %d) B : Error at sample %d (%g => %g).\n", __LINE__
, pass
, k
, orig
[k
], test
[k
]) ;
2955 oct_save_float (orig
, test
, DATA_LENGTH
) ;
2959 } ; /* for (pass ...) */
2962 } /* mono_rdwr_float_test */
2965 new_rdwr_float_test (const char *filename
, int format
, int allow_fd
)
2966 { SNDFILE
*wfile
, *rwfile
;
2968 float *orig
, *test
;
2971 orig
= orig_data
.f
;
2972 test
= test_data
.f
;
2974 sfinfo
.samplerate
= 44100 ;
2975 sfinfo
.frames
= SILLY_WRITE_COUNT
; /* Wrong length. Library should correct this on sf_close. */
2976 sfinfo
.channels
= 2 ;
2977 sfinfo
.format
= format
;
2979 items
= DATA_LENGTH
;
2980 frames
= items
/ sfinfo
.channels
;
2982 wfile
= test_open_file_or_die (filename
, SFM_WRITE
, &sfinfo
, allow_fd
, __LINE__
) ;
2983 sf_command (wfile
, SFC_SET_UPDATE_HEADER_AUTO
, NULL
, SF_TRUE
) ;
2984 test_writef_float_or_die (wfile
, 1, orig
, frames
, __LINE__
) ;
2985 sf_write_sync (wfile
) ;
2986 test_writef_float_or_die (wfile
, 2, orig
, frames
, __LINE__
) ;
2987 sf_write_sync (wfile
) ;
2989 rwfile
= test_open_file_or_die (filename
, SFM_RDWR
, &sfinfo
, allow_fd
, __LINE__
) ;
2990 if (sfinfo
.frames
!= 2 * frames
)
2991 { 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
) ;
2995 test_writef_float_or_die (wfile
, 3, orig
, frames
, __LINE__
) ;
2997 test_readf_float_or_die (rwfile
, 1, test
, frames
, __LINE__
) ;
2998 test_readf_float_or_die (rwfile
, 2, test
, frames
, __LINE__
) ;
3002 } /* new_rdwr_float_test */
3005 /*======================================================================================
3008 static void mono_double_test (const char *filename
, int format
, int long_file_ok
, int allow_fd
) ;
3009 static void stereo_double_test (const char *filename
, int format
, int long_file_ok
, int allow_fd
) ;
3010 static void mono_rdwr_double_test (const char *filename
, int format
, int long_file_ok
, int allow_fd
) ;
3011 static void new_rdwr_double_test (const char *filename
, int format
, int allow_fd
) ;
3012 static void multi_seek_test (const char * filename
, int format
) ;
3013 static void write_seek_extend_test (const char * filename
, int format
) ;
3016 pcm_test_double (const char *filename
, int format
, int long_file_ok
)
3021 /* Sd2 files cannot be opened from an existing file descriptor. */
3022 allow_fd
= ((format
& SF_FORMAT_TYPEMASK
) == SF_FORMAT_SD2
) ? SF_FALSE
: SF_TRUE
;
3024 print_test_name ("pcm_test_double", filename
) ;
3026 sfinfo
.samplerate
= 44100 ;
3027 sfinfo
.frames
= SILLY_WRITE_COUNT
; /* Wrong length. Library should correct this on sf_close. */
3028 sfinfo
.channels
= 1 ;
3029 sfinfo
.format
= format
;
3031 gen_windowed_sine_double (orig_data
.d
, DATA_LENGTH
, 1.0) ;
3033 orig
= orig_data
.d
;
3035 /* Make this a macro so gdb steps over it in one go. */
3036 CONVERT_DATA (k
, DATA_LENGTH
, orig
, orig_data
.d
) ;
3038 /* Some test broken out here. */
3040 mono_double_test (filename
, format
, long_file_ok
, allow_fd
) ;
3042 /* Sub format DWVW does not allow seeking. */
3043 if ((format
& SF_FORMAT_SUBMASK
) == SF_FORMAT_DWVW_16
||
3044 (format
& SF_FORMAT_SUBMASK
) == SF_FORMAT_DWVW_24
)
3045 { unlink (filename
) ;
3046 printf ("no seek : ok\n") ;
3050 if ((format
& SF_FORMAT_TYPEMASK
) != SF_FORMAT_FLAC
)
3051 mono_rdwr_double_test (filename
, format
, long_file_ok
, allow_fd
) ;
3053 /* If the format doesn't support stereo we're done. */
3054 sfinfo
.channels
= 2 ;
3055 if (sf_format_check (&sfinfo
) == 0)
3056 { unlink (filename
) ;
3057 puts ("no stereo : ok") ;
3061 stereo_double_test (filename
, format
, long_file_ok
, allow_fd
) ;
3063 /* New read/write test. Not sure if this is needed yet. */
3065 if ((format
& SF_FORMAT_TYPEMASK
) != SF_FORMAT_PAF
&&
3066 (format
& SF_FORMAT_TYPEMASK
) != SF_FORMAT_VOC
&&
3067 (format
& SF_FORMAT_TYPEMASK
) != SF_FORMAT_FLAC
)
3068 new_rdwr_double_test (filename
, format
, allow_fd
) ;
3070 delete_file (format
, filename
) ;
3074 } /* pcm_test_double */
3077 mono_double_test (const char *filename
, int format
, int long_file_ok
, int allow_fd
)
3080 double *orig
, *test
;
3084 sfinfo
.samplerate
= 44100 ;
3085 sfinfo
.frames
= SILLY_WRITE_COUNT
; /* Wrong length. Library should correct this on sf_close. */
3086 sfinfo
.channels
= 1 ;
3087 sfinfo
.format
= format
;
3089 orig
= orig_data
.d
;
3090 test
= test_data
.d
;
3092 items
= DATA_LENGTH
;
3094 file
= test_open_file_or_die (filename
, SFM_WRITE
, &sfinfo
, allow_fd
, __LINE__
) ;
3096 sf_set_string (file
, SF_STR_ARTIST
, "Your name here") ;
3098 test_write_double_or_die (file
, 0, orig
, items
, __LINE__
) ;
3099 sf_write_sync (file
) ;
3100 test_write_double_or_die (file
, 0, orig
, items
, __LINE__
) ;
3101 sf_write_sync (file
) ;
3103 /* Add non-audio data after the audio. */
3104 sf_set_string (file
, SF_STR_COPYRIGHT
, "Copyright (c) 2003") ;
3108 memset (test
, 0, items
* sizeof (double)) ;
3110 if ((format
& SF_FORMAT_TYPEMASK
) != SF_FORMAT_RAW
)
3111 memset (&sfinfo
, 0, sizeof (sfinfo
)) ;
3113 file
= test_open_file_or_die (filename
, SFM_READ
, &sfinfo
, allow_fd
, __LINE__
) ;
3115 if (sfinfo
.format
!= format
)
3116 { printf ("\n\nLine %d : Mono : Returned format incorrect (0x%08X => 0x%08X).\n", __LINE__
, format
, sfinfo
.format
) ;
3120 if (sfinfo
.frames
< 2 * items
)
3121 { 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
) ;
3125 if (! long_file_ok
&& sfinfo
.frames
> 2 * items
)
3126 { 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
) ;
3130 if (sfinfo
.channels
!= 1)
3131 { printf ("\n\nLine %d : Mono : Incorrect number of channels in file.\n", __LINE__
) ;
3135 check_log_buffer_or_die (file
, __LINE__
) ;
3137 test_read_double_or_die (file
, 0, test
, items
, __LINE__
) ;
3138 for (k
= 0 ; k
< items
; k
++)
3139 if (FLOAT_ERROR (orig
[k
], test
[k
]))
3140 { printf ("\n\nLine %d: Mono : Incorrect sample A (#%d : %g => %g).\n", __LINE__
, k
, orig
[k
], test
[k
]) ;
3141 oct_save_double (orig
, test
, items
) ;
3145 /* Seek to start of file. */
3146 test_seek_or_die (file
, 0, SEEK_SET
, 0, sfinfo
.channels
, __LINE__
) ;
3148 test_read_double_or_die (file
, 0, test
, 4, __LINE__
) ;
3149 for (k
= 0 ; k
< 4 ; k
++)
3150 if (FLOAT_ERROR (orig
[k
], test
[k
]))
3151 { printf ("\n\nLine %d : Mono : Incorrect sample A (#%d : %g => %g).\n", __LINE__
, k
, orig
[k
], test
[k
]) ;
3155 if ((format
& SF_FORMAT_SUBMASK
) == SF_FORMAT_DWVW_16
||
3156 (format
& SF_FORMAT_SUBMASK
) == SF_FORMAT_DWVW_24
)
3159 printf ("no seek : ") ;
3163 /* Seek to offset from start of file. */
3164 test_seek_or_die (file
, items
+ 10, SEEK_SET
, items
+ 10, sfinfo
.channels
, __LINE__
) ;
3166 test_read_double_or_die (file
, 0, test
+ 10, 4, __LINE__
) ;
3167 for (k
= 10 ; k
< 14 ; k
++)
3168 if (FLOAT_ERROR (orig
[k
], test
[k
]))
3169 { printf ("\n\nLine %d : Mono : Incorrect sample A (#%d : %g => %g).\n", __LINE__
, k
, test
[k
], orig
[k
]) ;
3173 /* Seek to offset from current position. */
3174 test_seek_or_die (file
, 6, SEEK_CUR
, items
+ 20, sfinfo
.channels
, __LINE__
) ;
3176 test_read_double_or_die (file
, 0, test
+ 20, 4, __LINE__
) ;
3177 for (k
= 20 ; k
< 24 ; k
++)
3178 if (FLOAT_ERROR (orig
[k
], test
[k
]))
3179 { printf ("\n\nLine %d : Mono : Incorrect sample A (#%d : %g => %g).\n", __LINE__
, k
, test
[k
], orig
[k
]) ;
3183 /* Seek to offset from end of file. */
3184 test_seek_or_die (file
, -1 * (sfinfo
.frames
- 10), SEEK_END
, 10, sfinfo
.channels
, __LINE__
) ;
3186 test_read_double_or_die (file
, 0, test
+ 10, 4, __LINE__
) ;
3187 for (k
= 10 ; k
< 14 ; k
++)
3188 if (FLOAT_ERROR (orig
[k
], test
[k
]))
3189 { printf ("\n\nLine %d : Mono : Incorrect sample D (#%d : %g => %g).\n", __LINE__
, k
, test
[k
], orig
[k
]) ;
3193 /* Check read past end of file followed by sf_seek (sndfile, 0, SEEK_CUR). */
3194 test_seek_or_die (file
, 0, SEEK_SET
, 0, sfinfo
.channels
, __LINE__
) ;
3197 while (count
< sfinfo
.frames
)
3198 count
+= sf_read_double (file
, test
, 311) ;
3200 /* Check that no error has occurred. */
3201 if (sf_error (file
))
3202 { printf ("\n\nLine %d : Mono : error where there shouldn't have been one.\n", __LINE__
) ;
3203 puts (sf_strerror (file
)) ;
3207 /* Check that we haven't read beyond EOF. */
3208 if (count
> sfinfo
.frames
)
3209 { printf ("\n\nLines %d : read past end of file (%ld should be %ld)\n", __LINE__
, (long) count
, (long) sfinfo
.frames
) ;
3213 test_seek_or_die (file
, 0, SEEK_CUR
, sfinfo
.frames
, sfinfo
.channels
, __LINE__
) ;
3217 multi_seek_test (filename
, format
) ;
3218 write_seek_extend_test (filename
, format
) ;
3220 } /* mono_double_test */
3223 stereo_double_test (const char *filename
, int format
, int long_file_ok
, int allow_fd
)
3226 double *orig
, *test
;
3227 int k
, items
, frames
;
3229 sfinfo
.samplerate
= 44100 ;
3230 sfinfo
.frames
= SILLY_WRITE_COUNT
; /* Wrong length. Library should correct this on sf_close. */
3231 sfinfo
.channels
= 2 ;
3232 sfinfo
.format
= format
;
3234 gen_windowed_sine_double (orig_data
.d
, DATA_LENGTH
, 1.0) ;
3236 orig
= orig_data
.d
;
3237 test
= test_data
.d
;
3239 /* Make this a macro so gdb steps over it in one go. */
3240 CONVERT_DATA (k
, DATA_LENGTH
, orig
, orig_data
.d
) ;
3242 items
= DATA_LENGTH
;
3243 frames
= items
/ sfinfo
.channels
;
3245 file
= test_open_file_or_die (filename
, SFM_WRITE
, &sfinfo
, allow_fd
, __LINE__
) ;
3247 sf_set_string (file
, SF_STR_ARTIST
, "Your name here") ;
3249 test_writef_double_or_die (file
, 0, orig
, frames
, __LINE__
) ;
3251 sf_set_string (file
, SF_STR_COPYRIGHT
, "Copyright (c) 2003") ;
3255 memset (test
, 0, items
* sizeof (double)) ;
3257 if ((format
& SF_FORMAT_TYPEMASK
) != SF_FORMAT_RAW
)
3258 memset (&sfinfo
, 0, sizeof (sfinfo
)) ;
3260 file
= test_open_file_or_die (filename
, SFM_READ
, &sfinfo
, allow_fd
, __LINE__
) ;
3262 if (sfinfo
.format
!= format
)
3263 { printf ("\n\nLine %d : Stereo : Returned format incorrect (0x%08X => 0x%08X).\n",
3264 __LINE__
, format
, sfinfo
.format
) ;
3268 if (sfinfo
.frames
< frames
)
3269 { printf ("\n\nLine %d : Stereo : Incorrect number of frames in file (too short). (%ld should be %d)\n",
3270 __LINE__
, SF_COUNT_TO_LONG (sfinfo
.frames
), frames
) ;
3274 if (! long_file_ok
&& sfinfo
.frames
> frames
)
3275 { printf ("\n\nLine %d : Stereo : Incorrect number of frames in file (too long). (%ld should be %d)\n",
3276 __LINE__
, SF_COUNT_TO_LONG (sfinfo
.frames
), frames
) ;
3280 if (sfinfo
.channels
!= 2)
3281 { printf ("\n\nLine %d : Stereo : Incorrect number of channels in file.\n", __LINE__
) ;
3285 check_log_buffer_or_die (file
, __LINE__
) ;
3287 test_readf_double_or_die (file
, 0, test
, frames
, __LINE__
) ;
3288 for (k
= 0 ; k
< items
; k
++)
3289 if (FLOAT_ERROR (test
[k
], orig
[k
]))
3290 { printf ("\n\nLine %d : Stereo : Incorrect sample (#%d : %g => %g).\n", __LINE__
, k
, orig
[k
], test
[k
]) ;
3294 /* Seek to start of file. */
3295 test_seek_or_die (file
, 0, SEEK_SET
, 0, sfinfo
.channels
, __LINE__
) ;
3297 test_readf_double_or_die (file
, 0, test
, 2, __LINE__
) ;
3298 for (k
= 0 ; k
< 4 ; k
++)
3299 if (FLOAT_ERROR (test
[k
], orig
[k
]))
3300 { printf ("\n\nLine %d : Stereo : Incorrect sample (#%d : %g => %g).\n", __LINE__
, k
, orig
[k
], test
[k
]) ;
3304 /* Seek to offset from start of file. */
3305 test_seek_or_die (file
, 10, SEEK_SET
, 10, sfinfo
.channels
, __LINE__
) ;
3307 /* Check for errors here. */
3308 if (sf_error (file
))
3309 { printf ("Line %d: Should NOT return an error.\n", __LINE__
) ;
3310 puts (sf_strerror (file
)) ;
3314 if (sf_read_double (file
, test
, 1) > 0)
3315 { printf ("Line %d: Should return 0.\n", __LINE__
) ;
3319 if (! sf_error (file
))
3320 { printf ("Line %d: Should return an error.\n", __LINE__
) ;
3323 /*-----------------------*/
3325 test_readf_double_or_die (file
, 0, test
+ 10, 2, __LINE__
) ;
3326 for (k
= 20 ; k
< 24 ; k
++)
3327 if (FLOAT_ERROR (test
[k
], orig
[k
]))
3328 { printf ("\n\nLine %d : Stereo : Incorrect sample (#%d : %g => %g).\n", __LINE__
, k
, orig
[k
], test
[k
]) ;
3332 /* Seek to offset from current position. */
3333 test_seek_or_die (file
, 8, SEEK_CUR
, 20, sfinfo
.channels
, __LINE__
) ;
3335 test_readf_double_or_die (file
, 0, test
+ 20, 2, __LINE__
) ;
3336 for (k
= 40 ; k
< 44 ; k
++)
3337 if (FLOAT_ERROR (test
[k
], orig
[k
]))
3338 { printf ("\n\nLine %d : Stereo : Incorrect sample (#%d : %g => %g).\n", __LINE__
, k
, orig
[k
], test
[k
]) ;
3342 /* Seek to offset from end of file. */
3343 test_seek_or_die (file
, -1 * (sfinfo
.frames
- 10), SEEK_END
, 10, sfinfo
.channels
, __LINE__
) ;
3345 test_readf_double_or_die (file
, 0, test
+ 20, 2, __LINE__
) ;
3346 for (k
= 20 ; k
< 24 ; k
++)
3347 if (FLOAT_ERROR (test
[k
], orig
[k
]))
3348 { printf ("\n\nLine %d : Stereo : Incorrect sample (#%d : %g => %g).\n", __LINE__
, k
, orig
[k
], test
[k
]) ;
3353 } /* stereo_double_test */
3356 mono_rdwr_double_test (const char *filename
, int format
, int long_file_ok
, int allow_fd
)
3359 double *orig
, *test
;
3362 orig
= orig_data
.d
;
3363 test
= test_data
.d
;
3365 sfinfo
.samplerate
= SAMPLE_RATE
;
3366 sfinfo
.frames
= DATA_LENGTH
;
3367 sfinfo
.channels
= 1 ;
3368 sfinfo
.format
= format
;
3370 if ((format
& SF_FORMAT_TYPEMASK
) == SF_FORMAT_RAW
3371 || (format
& SF_FORMAT_TYPEMASK
) == SF_FORMAT_AU
3372 || (format
& SF_FORMAT_TYPEMASK
) == SF_FORMAT_SD2
)
3375 { /* Create a short file. */
3376 create_short_file (filename
) ;
3378 /* Opening a already existing short file (ie invalid header) RDWR is disallowed.
3379 ** If this returns a valif pointer sf_open() screwed up.
3381 if ((file
= sf_open (filename
, SFM_RDWR
, &sfinfo
)))
3382 { printf ("\n\nLine %d: sf_open should (SFM_RDWR) have failed but didn't.\n", __LINE__
) ;
3386 /* Truncate the file to zero bytes. */
3387 if (truncate (filename
, 0) < 0)
3388 { printf ("\n\nLine %d: truncate (%s) failed", __LINE__
, filename
) ;
3394 /* Opening a zero length file RDWR is allowed, but the SF_INFO struct must contain
3395 ** all the usual data required when opening the file in WRITE mode.
3397 sfinfo
.samplerate
= SAMPLE_RATE
;
3398 sfinfo
.frames
= DATA_LENGTH
;
3399 sfinfo
.channels
= 1 ;
3400 sfinfo
.format
= format
;
3402 file
= test_open_file_or_die (filename
, SFM_RDWR
, &sfinfo
, allow_fd
, __LINE__
) ;
3404 /* Do 3 writes followed by reads. After each, check the data and the current
3405 ** read and write offsets.
3407 for (pass
= 1 ; pass
<= 3 ; pass
++)
3408 { orig
[20] = pass
* 2 ;
3410 /* Write some data. */
3411 test_write_double_or_die (file
, pass
, orig
, DATA_LENGTH
, __LINE__
) ;
3413 test_read_write_position_or_die (file
, __LINE__
, pass
, (pass
- 1) * DATA_LENGTH
, pass
* DATA_LENGTH
) ;
3415 /* Read what we just wrote. */
3416 test_read_double_or_die (file
, 0, test
, DATA_LENGTH
, __LINE__
) ;
3418 /* Check the data. */
3419 for (k
= 0 ; k
< DATA_LENGTH
; k
++)
3420 if (FLOAT_ERROR (orig
[k
], test
[k
]))
3421 { printf ("\n\nLine %d (pass %d) A : Error at sample %d (%g => %g).\n", __LINE__
, pass
, k
, orig
[k
], test
[k
]) ;
3422 oct_save_double (orig
, test
, DATA_LENGTH
) ;
3426 test_read_write_position_or_die (file
, __LINE__
, pass
, pass
* DATA_LENGTH
, pass
* DATA_LENGTH
) ;
3427 } ; /* for (pass ...) */
3431 /* Open the file again to check the data. */
3432 file
= test_open_file_or_die (filename
, SFM_RDWR
, &sfinfo
, allow_fd
, __LINE__
) ;
3434 if (sfinfo
.format
!= format
)
3435 { printf ("\n\nLine %d : Returned format incorrect (0x%08X => 0x%08X).\n", __LINE__
, format
, sfinfo
.format
) ;
3439 if (sfinfo
.frames
< 3 * DATA_LENGTH
)
3440 { printf ("\n\nLine %d : Not enough frames in file. (%ld < %d)\n", __LINE__
, SF_COUNT_TO_LONG (sfinfo
.frames
), 3 * DATA_LENGTH
) ;
3444 if (! long_file_ok
&& sfinfo
.frames
!= 3 * DATA_LENGTH
)
3445 { 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
) ;
3449 if (sfinfo
.channels
!= 1)
3450 { printf ("\n\nLine %d : Incorrect number of channels in file.\n", __LINE__
) ;
3455 test_read_write_position_or_die (file
, __LINE__
, 0, 0, 3 * DATA_LENGTH
) ;
3457 test_seek_or_die (file
, 3 * DATA_LENGTH
, SFM_WRITE
| SEEK_SET
, 3 * DATA_LENGTH
, sfinfo
.channels
, __LINE__
) ;
3459 for (pass
= 1 ; pass
<= 3 ; pass
++)
3460 { orig
[20] = pass
* 2 ;
3462 test_read_write_position_or_die (file
, __LINE__
, pass
, (pass
- 1) * DATA_LENGTH
, 3 * DATA_LENGTH
) ;
3464 /* Read what we just wrote. */
3465 test_read_double_or_die (file
, pass
, test
, DATA_LENGTH
, __LINE__
) ;
3467 /* Check the data. */
3468 for (k
= 0 ; k
< DATA_LENGTH
; k
++)
3469 if (FLOAT_ERROR (orig
[k
], test
[k
]))
3470 { printf ("\n\nLine %d (pass %d) B : Error at sample %d (%g => %g).\n", __LINE__
, pass
, k
, orig
[k
], test
[k
]) ;
3471 oct_save_double (orig
, test
, DATA_LENGTH
) ;
3475 } ; /* for (pass ...) */
3478 } /* mono_rdwr_double_test */
3481 new_rdwr_double_test (const char *filename
, int format
, int allow_fd
)
3482 { SNDFILE
*wfile
, *rwfile
;
3484 double *orig
, *test
;
3487 orig
= orig_data
.d
;
3488 test
= test_data
.d
;
3490 sfinfo
.samplerate
= 44100 ;
3491 sfinfo
.frames
= SILLY_WRITE_COUNT
; /* Wrong length. Library should correct this on sf_close. */
3492 sfinfo
.channels
= 2 ;
3493 sfinfo
.format
= format
;
3495 items
= DATA_LENGTH
;
3496 frames
= items
/ sfinfo
.channels
;
3498 wfile
= test_open_file_or_die (filename
, SFM_WRITE
, &sfinfo
, allow_fd
, __LINE__
) ;
3499 sf_command (wfile
, SFC_SET_UPDATE_HEADER_AUTO
, NULL
, SF_TRUE
) ;
3500 test_writef_double_or_die (wfile
, 1, orig
, frames
, __LINE__
) ;
3501 sf_write_sync (wfile
) ;
3502 test_writef_double_or_die (wfile
, 2, orig
, frames
, __LINE__
) ;
3503 sf_write_sync (wfile
) ;
3505 rwfile
= test_open_file_or_die (filename
, SFM_RDWR
, &sfinfo
, allow_fd
, __LINE__
) ;
3506 if (sfinfo
.frames
!= 2 * frames
)
3507 { 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
) ;
3511 test_writef_double_or_die (wfile
, 3, orig
, frames
, __LINE__
) ;
3513 test_readf_double_or_die (rwfile
, 1, test
, frames
, __LINE__
) ;
3514 test_readf_double_or_die (rwfile
, 2, test
, frames
, __LINE__
) ;
3518 } /* new_rdwr_double_test */
3522 /*----------------------------------------------------------------------------------------
3526 empty_file_test (const char *filename
, int format
)
3531 /* Sd2 files cannot be opened from an existing file descriptor. */
3532 allow_fd
= ((format
& SF_FORMAT_TYPEMASK
) == SF_FORMAT_SD2
) ? SF_FALSE
: SF_TRUE
;
3534 print_test_name ("empty_file_test", filename
) ;
3538 info
.samplerate
= 48000 ;
3540 info
.format
= format
;
3542 if (sf_format_check (&info
) == SF_FALSE
)
3543 { info
.channels
= 1 ;
3544 if (sf_format_check (&info
) == SF_FALSE
)
3545 { puts ("invalid file format") ;
3550 /* Create an empty file. */
3551 file
= test_open_file_or_die (filename
, SFM_WRITE
, &info
, allow_fd
, __LINE__
) ;
3554 /* Open for read and check the length. */
3555 file
= test_open_file_or_die (filename
, SFM_READ
, &info
, allow_fd
, __LINE__
) ;
3557 if (SF_COUNT_TO_LONG (info
.frames
) != 0)
3558 { printf ("\n\nError : frame count (%ld) should be zero.\n", SF_COUNT_TO_LONG (info
.frames
)) ;
3564 /* Open for read/write and check the length. */
3565 file
= test_open_file_or_die (filename
, SFM_RDWR
, &info
, allow_fd
, __LINE__
) ;
3567 if (SF_COUNT_TO_LONG (info
.frames
) != 0)
3568 { printf ("\n\nError : frame count (%ld) should be zero.\n", SF_COUNT_TO_LONG (info
.frames
)) ;
3574 /* Open for read and check the length. */
3575 file
= test_open_file_or_die (filename
, SFM_READ
, &info
, allow_fd
, __LINE__
) ;
3577 if (SF_COUNT_TO_LONG (info
.frames
) != 0)
3578 { printf ("\n\nError : frame count (%ld) should be zero.\n", SF_COUNT_TO_LONG (info
.frames
)) ;
3584 check_open_file_count_or_die (__LINE__
) ;
3590 } /* empty_file_test */
3593 /*----------------------------------------------------------------------------------------
3597 create_short_file (const char *filename
)
3600 if (! (file
= fopen (filename
, "w")))
3601 { printf ("create_short_file : fopen (%s, \"w\") failed.", filename
) ;
3607 fprintf (file
, "This is the file data.\n") ;
3610 } /* create_short_file */
3612 #if (defined (WIN32) || defined (__WIN32))
3614 /* Win32 does not have truncate (nor does it have the POSIX function ftruncate).
3615 ** Hack somethng up here to over come this. This function can only truncate to a
3620 truncate (const char *filename
, int ignored
)
3625 if ((fd
= open (filename
, O_RDWR
| O_TRUNC
| O_BINARY
)) < 0)
3636 multi_seek_test (const char * filename
, int format
)
3642 /* This test doesn't work on the following. */
3643 switch (format
& SF_FORMAT_TYPEMASK
)
3644 { case SF_FORMAT_RAW
:
3651 memset (&info
, 0, sizeof (info
)) ;
3653 generate_file (filename
, format
, 88200) ;
3655 file
= test_open_file_or_die (filename
, SFM_READ
, &info
, SF_FALSE
, __LINE__
) ;
3657 for (k
= 0 ; k
< 10 ; k
++)
3658 { pos
= info
.frames
/ (k
+ 2) ;
3659 test_seek_or_die (file
, pos
, SEEK_SET
, pos
, info
.channels
, __LINE__
) ;
3663 } /* multi_seek_test */
3666 write_seek_extend_test (const char * filename
, int format
)
3669 short *orig
, *test
;
3672 /* This test doesn't work on the following. */
3673 switch (format
& SF_FORMAT_TYPEMASK
)
3674 { case SF_FORMAT_FLAC
:
3675 case SF_FORMAT_HTK
:
3676 case SF_FORMAT_PAF
:
3677 case SF_FORMAT_SDS
:
3678 case SF_FORMAT_SVX
:
3685 memset (&info
, 0, sizeof (info
)) ;
3687 info
.samplerate
= 48000 ;
3689 info
.format
= format
;
3692 exit_if_true (items
> ARRAY_LEN (orig_data
.s
), "Line %d : Bad assumption.\n", __LINE__
) ;
3694 orig
= orig_data
.s
;
3695 test
= test_data
.s
;
3697 for (k
= 0 ; k
< ARRAY_LEN (orig_data
.s
) ; k
++)
3700 file
= test_open_file_or_die (filename
, SFM_WRITE
, &info
, SF_FALSE
, __LINE__
) ;
3701 test_write_short_or_die (file
, 0, orig
, items
, __LINE__
) ;
3703 /* Extend the file using a seek. */
3704 test_seek_or_die (file
, 2 * items
, SEEK_SET
, 2 * items
, info
.channels
, __LINE__
) ;
3706 test_writef_short_or_die (file
, 0, orig
, items
, __LINE__
) ;
3709 file
= test_open_file_or_die (filename
, SFM_READ
, &info
, SF_FALSE
, __LINE__
) ;
3710 test_read_short_or_die (file
, 0, test
, 3 * items
, __LINE__
) ;
3713 /* Can't do these formats due to scaling. */
3714 switch (format
& SF_FORMAT_SUBMASK
)
3715 { case SF_FORMAT_PCM_S8
:
3716 case SF_FORMAT_PCM_U8
:
3722 for (k
= 0 ; k
< items
; k
++)
3723 { exit_if_true (test
[k
] != 0x3fff, "Line %d : test [%d] == %d, should be 0x3fff.\n", __LINE__
, k
, test
[k
]) ;
3724 exit_if_true (test
[items
+ k
] != 0, "Line %d : test [%d] == %d, should be 0.\n", __LINE__
, items
+ k
, test
[items
+ k
]) ;
3725 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
]) ;
3729 } /* write_seek_extend_test */