Chris@40
|
1 [+ AutoGen5 template c +]
|
Chris@40
|
2 /*
|
Chris@40
|
3 ** Copyright (C) 1999-2016 Erik de Castro Lopo <erikd@mega-nerd.com>
|
Chris@40
|
4 **
|
Chris@40
|
5 ** This program is free software; you can redistribute it and/or modify
|
Chris@40
|
6 ** it under the terms of the GNU General Public License as published by
|
Chris@40
|
7 ** the Free Software Foundation; either version 2 of the License, or
|
Chris@40
|
8 ** (at your option) any later version.
|
Chris@40
|
9 **
|
Chris@40
|
10 ** This program is distributed in the hope that it will be useful,
|
Chris@40
|
11 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
Chris@40
|
12 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
Chris@40
|
13 ** GNU General Public License for more details.
|
Chris@40
|
14 **
|
Chris@40
|
15 ** You should have received a copy of the GNU General Public License
|
Chris@40
|
16 ** along with this program; if not, write to the Free Software
|
Chris@40
|
17 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
Chris@40
|
18 */
|
Chris@40
|
19
|
Chris@40
|
20 #include "sfconfig.h"
|
Chris@40
|
21
|
Chris@40
|
22 #include <stdio.h>
|
Chris@40
|
23 #include <stdlib.h>
|
Chris@40
|
24 #include <string.h>
|
Chris@40
|
25 #include <math.h>
|
Chris@40
|
26 #include <inttypes.h>
|
Chris@40
|
27
|
Chris@40
|
28
|
Chris@40
|
29 #if HAVE_UNISTD_H
|
Chris@40
|
30 #include <unistd.h>
|
Chris@40
|
31 #endif
|
Chris@40
|
32
|
Chris@40
|
33 #include <sndfile.h>
|
Chris@40
|
34
|
Chris@40
|
35 #include "utils.h"
|
Chris@40
|
36 #include "generate.h"
|
Chris@40
|
37
|
Chris@40
|
38 #define SAMPLE_RATE 11025
|
Chris@40
|
39 #define DATA_LENGTH (1 << 12)
|
Chris@40
|
40
|
Chris@40
|
41 #define SILLY_WRITE_COUNT (234)
|
Chris@40
|
42
|
Chris@40
|
43 [+ FOR data_type
|
Chris@40
|
44 +]static void pcm_test_[+ (get "type_name") +] (const char *str, int format, int long_file_ok) ;
|
Chris@40
|
45 [+ ENDFOR data_type
|
Chris@40
|
46 +]
|
Chris@40
|
47 static void empty_file_test (const char *filename, int format) ;
|
Chris@40
|
48
|
Chris@40
|
49 typedef union
|
Chris@40
|
50 { double d [DATA_LENGTH] ;
|
Chris@40
|
51 float f [DATA_LENGTH] ;
|
Chris@40
|
52 int i [DATA_LENGTH] ;
|
Chris@40
|
53 short s [DATA_LENGTH] ;
|
Chris@40
|
54 char c [DATA_LENGTH] ;
|
Chris@40
|
55 } BUFFER ;
|
Chris@40
|
56
|
Chris@40
|
57 static BUFFER orig_data ;
|
Chris@40
|
58 static BUFFER test_data ;
|
Chris@40
|
59
|
Chris@40
|
60 int
|
Chris@40
|
61 main (int argc, char **argv)
|
Chris@40
|
62 { int do_all = 0 ;
|
Chris@40
|
63 int test_count = 0 ;
|
Chris@40
|
64
|
Chris@40
|
65 count_open_files () ;
|
Chris@40
|
66
|
Chris@40
|
67 if (argc != 2)
|
Chris@40
|
68 { printf ("Usage : %s <test>\n", argv [0]) ;
|
Chris@40
|
69 printf (" Where <test> is one of the following:\n") ;
|
Chris@40
|
70 printf (" wav - test WAV file functions (little endian)\n") ;
|
Chris@40
|
71 printf (" aiff - test AIFF file functions (big endian)\n") ;
|
Chris@40
|
72 printf (" au - test AU file functions\n") ;
|
Chris@40
|
73 printf (" avr - test AVR file functions\n") ;
|
Chris@40
|
74 printf (" caf - test CAF file functions\n") ;
|
Chris@40
|
75 printf (" raw - test RAW header-less PCM file functions\n") ;
|
Chris@40
|
76 printf (" paf - test PAF file functions\n") ;
|
Chris@40
|
77 printf (" svx - test 8SVX/16SV file functions\n") ;
|
Chris@40
|
78 printf (" nist - test NIST Sphere file functions\n") ;
|
Chris@40
|
79 printf (" ircam - test IRCAM file functions\n") ;
|
Chris@40
|
80 printf (" voc - Create Voice file functions\n") ;
|
Chris@40
|
81 printf (" w64 - Sonic Foundry's W64 file functions\n") ;
|
Chris@40
|
82 printf (" flac - test FLAC file functions\n") ;
|
Chris@40
|
83 printf (" mpc2k - test MPC 2000 file functions\n") ;
|
Chris@40
|
84 printf (" rf64 - test RF64 file functions\n") ;
|
Chris@40
|
85 printf (" all - perform all tests\n") ;
|
Chris@40
|
86 exit (1) ;
|
Chris@40
|
87 } ;
|
Chris@40
|
88
|
Chris@40
|
89 do_all = !strcmp (argv [1], "all") ;
|
Chris@40
|
90
|
Chris@40
|
91 if (do_all || ! strcmp (argv [1], "wav"))
|
Chris@40
|
92 { pcm_test_char ("char.wav" , SF_FORMAT_WAV | SF_FORMAT_PCM_U8, SF_FALSE) ;
|
Chris@40
|
93 pcm_test_short ("short.wav" , SF_FORMAT_WAV | SF_FORMAT_PCM_16, SF_FALSE) ;
|
Chris@40
|
94 pcm_test_24bit ("24bit.wav" , SF_FORMAT_WAV | SF_FORMAT_PCM_24, SF_FALSE) ;
|
Chris@40
|
95 pcm_test_int ("int.wav" , SF_FORMAT_WAV | SF_FORMAT_PCM_32, SF_FALSE) ;
|
Chris@40
|
96
|
Chris@40
|
97 pcm_test_char ("char.rifx" , SF_ENDIAN_BIG | SF_FORMAT_WAV | SF_FORMAT_PCM_U8, SF_FALSE) ;
|
Chris@40
|
98 pcm_test_short ("short.rifx" , SF_ENDIAN_BIG | SF_FORMAT_WAV | SF_FORMAT_PCM_16, SF_FALSE) ;
|
Chris@40
|
99 pcm_test_24bit ("24bit.rifx" , SF_ENDIAN_BIG | SF_FORMAT_WAV | SF_FORMAT_PCM_24, SF_FALSE) ;
|
Chris@40
|
100 pcm_test_int ("int.rifx" , SF_ENDIAN_BIG | SF_FORMAT_WAV | SF_FORMAT_PCM_32, SF_FALSE) ;
|
Chris@40
|
101
|
Chris@40
|
102 pcm_test_24bit ("24bit.wavex" , SF_FORMAT_WAVEX | SF_FORMAT_PCM_24, SF_FALSE) ;
|
Chris@40
|
103 pcm_test_int ("int.wavex" , SF_FORMAT_WAVEX | SF_FORMAT_PCM_32, SF_FALSE) ;
|
Chris@40
|
104
|
Chris@40
|
105 /* Lite remove start */
|
Chris@40
|
106 pcm_test_float ("float.wav" , SF_FORMAT_WAV | SF_FORMAT_FLOAT , SF_FALSE) ;
|
Chris@40
|
107 pcm_test_double ("double.wav" , SF_FORMAT_WAV | SF_FORMAT_DOUBLE, SF_FALSE) ;
|
Chris@40
|
108
|
Chris@40
|
109 pcm_test_float ("float.rifx" , SF_ENDIAN_BIG | SF_FORMAT_WAV | SF_FORMAT_FLOAT , SF_FALSE) ;
|
Chris@40
|
110 pcm_test_double ("double.rifx" , SF_ENDIAN_BIG | SF_FORMAT_WAV | SF_FORMAT_DOUBLE, SF_FALSE) ;
|
Chris@40
|
111
|
Chris@40
|
112 pcm_test_float ("float.wavex" , SF_FORMAT_WAVEX | SF_FORMAT_FLOAT , SF_FALSE) ;
|
Chris@40
|
113 pcm_test_double ("double.wavex" , SF_FORMAT_WAVEX | SF_FORMAT_DOUBLE, SF_FALSE) ;
|
Chris@40
|
114 /* Lite remove end */
|
Chris@40
|
115
|
Chris@40
|
116 empty_file_test ("empty_char.wav", SF_FORMAT_WAV | SF_FORMAT_PCM_U8) ;
|
Chris@40
|
117 empty_file_test ("empty_short.wav", SF_FORMAT_WAV | SF_FORMAT_PCM_16) ;
|
Chris@40
|
118 empty_file_test ("empty_float.wav", SF_FORMAT_WAV | SF_FORMAT_FLOAT) ;
|
Chris@40
|
119
|
Chris@40
|
120 test_count++ ;
|
Chris@40
|
121 } ;
|
Chris@40
|
122
|
Chris@40
|
123 if (do_all || ! strcmp (argv [1], "aiff"))
|
Chris@40
|
124 { pcm_test_char ("char_u8.aiff" , SF_FORMAT_AIFF | SF_FORMAT_PCM_U8, SF_FALSE) ;
|
Chris@40
|
125 pcm_test_char ("char_s8.aiff" , SF_FORMAT_AIFF | SF_FORMAT_PCM_S8, SF_FALSE) ;
|
Chris@40
|
126 pcm_test_short ("short.aiff" , SF_FORMAT_AIFF | SF_FORMAT_PCM_16, SF_FALSE) ;
|
Chris@40
|
127 pcm_test_24bit ("24bit.aiff" , SF_FORMAT_AIFF | SF_FORMAT_PCM_24, SF_FALSE) ;
|
Chris@40
|
128 pcm_test_int ("int.aiff" , SF_FORMAT_AIFF | SF_FORMAT_PCM_32, SF_FALSE) ;
|
Chris@40
|
129
|
Chris@40
|
130 pcm_test_short ("short_sowt.aifc" , SF_ENDIAN_LITTLE | SF_FORMAT_AIFF | SF_FORMAT_PCM_16, SF_FALSE) ;
|
Chris@40
|
131 pcm_test_24bit ("24bit_sowt.aifc" , SF_ENDIAN_LITTLE | SF_FORMAT_AIFF | SF_FORMAT_PCM_24, SF_FALSE) ;
|
Chris@40
|
132 pcm_test_int ("int_sowt.aifc" , SF_ENDIAN_LITTLE | SF_FORMAT_AIFF | SF_FORMAT_PCM_32, SF_FALSE) ;
|
Chris@40
|
133
|
Chris@40
|
134 pcm_test_short ("short_twos.aifc" , SF_ENDIAN_BIG | SF_FORMAT_AIFF | SF_FORMAT_PCM_16, SF_FALSE) ;
|
Chris@40
|
135 pcm_test_24bit ("24bit_twos.aifc" , SF_ENDIAN_BIG | SF_FORMAT_AIFF | SF_FORMAT_PCM_24, SF_FALSE) ;
|
Chris@40
|
136 pcm_test_int ("int_twos.aifc" , SF_ENDIAN_BIG | SF_FORMAT_AIFF | SF_FORMAT_PCM_32, SF_FALSE) ;
|
Chris@40
|
137
|
Chris@40
|
138 /* Lite remove start */
|
Chris@40
|
139 pcm_test_short ("dwvw16.aifc", SF_FORMAT_AIFF | SF_FORMAT_DWVW_16, SF_TRUE) ;
|
Chris@40
|
140 pcm_test_24bit ("dwvw24.aifc", SF_FORMAT_AIFF | SF_FORMAT_DWVW_24, SF_TRUE) ;
|
Chris@40
|
141
|
Chris@40
|
142 pcm_test_float ("float.aifc" , SF_FORMAT_AIFF | SF_FORMAT_FLOAT , SF_FALSE) ;
|
Chris@40
|
143 pcm_test_double ("double.aifc" , SF_FORMAT_AIFF | SF_FORMAT_DOUBLE, SF_FALSE) ;
|
Chris@40
|
144 /* Lite remove end */
|
Chris@40
|
145
|
Chris@40
|
146 empty_file_test ("empty_char.aiff", SF_FORMAT_AIFF | SF_FORMAT_PCM_U8) ;
|
Chris@40
|
147 empty_file_test ("empty_short.aiff", SF_FORMAT_AIFF | SF_FORMAT_PCM_16) ;
|
Chris@40
|
148 empty_file_test ("empty_float.aiff", SF_FORMAT_AIFF | SF_FORMAT_FLOAT) ;
|
Chris@40
|
149
|
Chris@40
|
150 test_count++ ;
|
Chris@40
|
151 } ;
|
Chris@40
|
152
|
Chris@40
|
153 if (do_all || ! strcmp (argv [1], "au"))
|
Chris@40
|
154 { pcm_test_char ("char.au" , SF_FORMAT_AU | SF_FORMAT_PCM_S8, SF_FALSE) ;
|
Chris@40
|
155 pcm_test_short ("short.au" , SF_FORMAT_AU | SF_FORMAT_PCM_16, SF_FALSE) ;
|
Chris@40
|
156 pcm_test_24bit ("24bit.au" , SF_FORMAT_AU | SF_FORMAT_PCM_24, SF_FALSE) ;
|
Chris@40
|
157 pcm_test_int ("int.au" , SF_FORMAT_AU | SF_FORMAT_PCM_32, SF_FALSE) ;
|
Chris@40
|
158 /* Lite remove start */
|
Chris@40
|
159 pcm_test_float ("float.au" , SF_FORMAT_AU | SF_FORMAT_FLOAT , SF_FALSE) ;
|
Chris@40
|
160 pcm_test_double ("double.au", SF_FORMAT_AU | SF_FORMAT_DOUBLE, SF_FALSE) ;
|
Chris@40
|
161 /* Lite remove end */
|
Chris@40
|
162
|
Chris@40
|
163 pcm_test_char ("char_le.au" , SF_ENDIAN_LITTLE | SF_FORMAT_AU | SF_FORMAT_PCM_S8, SF_FALSE) ;
|
Chris@40
|
164 pcm_test_short ("short_le.au" , SF_ENDIAN_LITTLE | SF_FORMAT_AU | SF_FORMAT_PCM_16, SF_FALSE) ;
|
Chris@40
|
165 pcm_test_24bit ("24bit_le.au" , SF_ENDIAN_LITTLE | SF_FORMAT_AU | SF_FORMAT_PCM_24, SF_FALSE) ;
|
Chris@40
|
166 pcm_test_int ("int_le.au" , SF_ENDIAN_LITTLE | SF_FORMAT_AU | SF_FORMAT_PCM_32, SF_FALSE) ;
|
Chris@40
|
167 /* Lite remove start */
|
Chris@40
|
168 pcm_test_float ("float_le.au" , SF_ENDIAN_LITTLE | SF_FORMAT_AU | SF_FORMAT_FLOAT , SF_FALSE) ;
|
Chris@40
|
169 pcm_test_double ("double_le.au" , SF_ENDIAN_LITTLE | SF_FORMAT_AU | SF_FORMAT_DOUBLE, SF_FALSE) ;
|
Chris@40
|
170 /* Lite remove end */
|
Chris@40
|
171 test_count++ ;
|
Chris@40
|
172 } ;
|
Chris@40
|
173
|
Chris@40
|
174 if (do_all || ! strcmp (argv [1], "caf"))
|
Chris@40
|
175 { pcm_test_char ("char.caf" , SF_FORMAT_CAF | SF_FORMAT_PCM_S8, SF_FALSE) ;
|
Chris@40
|
176 pcm_test_short ("short.caf" , SF_FORMAT_CAF | SF_FORMAT_PCM_16, SF_FALSE) ;
|
Chris@40
|
177 pcm_test_24bit ("24bit.caf" , SF_FORMAT_CAF | SF_FORMAT_PCM_24, SF_FALSE) ;
|
Chris@40
|
178 pcm_test_int ("int.caf" , SF_FORMAT_CAF | SF_FORMAT_PCM_32, SF_FALSE) ;
|
Chris@40
|
179 /* Lite remove start */
|
Chris@40
|
180 pcm_test_float ("float.caf" , SF_FORMAT_CAF | SF_FORMAT_FLOAT , SF_FALSE) ;
|
Chris@40
|
181 pcm_test_double ("double.caf" , SF_FORMAT_CAF | SF_FORMAT_DOUBLE, SF_FALSE) ;
|
Chris@40
|
182 /* Lite remove end */
|
Chris@40
|
183
|
Chris@40
|
184 pcm_test_short ("short_le.caf" , SF_ENDIAN_LITTLE | SF_FORMAT_CAF | SF_FORMAT_PCM_16, SF_FALSE) ;
|
Chris@40
|
185 pcm_test_24bit ("24bit_le.caf" , SF_ENDIAN_LITTLE | SF_FORMAT_CAF | SF_FORMAT_PCM_24, SF_FALSE) ;
|
Chris@40
|
186 pcm_test_int ("int_le.caf" , SF_ENDIAN_LITTLE | SF_FORMAT_CAF | SF_FORMAT_PCM_32, SF_FALSE) ;
|
Chris@40
|
187 /* Lite remove start */
|
Chris@40
|
188 pcm_test_float ("float_le.caf" , SF_ENDIAN_LITTLE | SF_FORMAT_CAF | SF_FORMAT_FLOAT , SF_FALSE) ;
|
Chris@40
|
189 pcm_test_double ("double_le.caf", SF_ENDIAN_LITTLE | SF_FORMAT_CAF | SF_FORMAT_DOUBLE, SF_FALSE) ;
|
Chris@40
|
190
|
Chris@40
|
191 pcm_test_short ("alac16.caf" , SF_FORMAT_CAF | SF_FORMAT_ALAC_16, SF_FALSE) ;
|
Chris@40
|
192 pcm_test_20bit ("alac20.caf" , SF_FORMAT_CAF | SF_FORMAT_ALAC_20, SF_FALSE) ;
|
Chris@40
|
193 pcm_test_24bit ("alac24.caf" , SF_FORMAT_CAF | SF_FORMAT_ALAC_24, SF_FALSE) ;
|
Chris@40
|
194 pcm_test_int ("alac32.caf" , SF_FORMAT_CAF | SF_FORMAT_ALAC_32, SF_FALSE) ;
|
Chris@40
|
195
|
Chris@40
|
196 /* Lite remove end */
|
Chris@40
|
197 test_count++ ;
|
Chris@40
|
198 } ;
|
Chris@40
|
199
|
Chris@40
|
200 if (do_all || ! strcmp (argv [1], "raw"))
|
Chris@40
|
201 { pcm_test_char ("char_s8.raw" , SF_FORMAT_RAW | SF_FORMAT_PCM_S8, SF_FALSE) ;
|
Chris@40
|
202 pcm_test_char ("char_u8.raw" , SF_FORMAT_RAW | SF_FORMAT_PCM_U8, SF_FALSE) ;
|
Chris@40
|
203
|
Chris@40
|
204 pcm_test_short ("short_le.raw" , SF_ENDIAN_LITTLE | SF_FORMAT_RAW | SF_FORMAT_PCM_16, SF_FALSE) ;
|
Chris@40
|
205 pcm_test_short ("short_be.raw" , SF_ENDIAN_BIG | SF_FORMAT_RAW | SF_FORMAT_PCM_16, SF_FALSE) ;
|
Chris@40
|
206 pcm_test_24bit ("24bit_le.raw" , SF_ENDIAN_LITTLE | SF_FORMAT_RAW | SF_FORMAT_PCM_24, SF_FALSE) ;
|
Chris@40
|
207 pcm_test_24bit ("24bit_be.raw" , SF_ENDIAN_BIG | SF_FORMAT_RAW | SF_FORMAT_PCM_24, SF_FALSE) ;
|
Chris@40
|
208 pcm_test_int ("int_le.raw" , SF_ENDIAN_LITTLE | SF_FORMAT_RAW | SF_FORMAT_PCM_32, SF_FALSE) ;
|
Chris@40
|
209 pcm_test_int ("int_be.raw" , SF_ENDIAN_BIG | SF_FORMAT_RAW | SF_FORMAT_PCM_32, SF_FALSE) ;
|
Chris@40
|
210
|
Chris@40
|
211 /* Lite remove start */
|
Chris@40
|
212 pcm_test_float ("float_le.raw" , SF_ENDIAN_LITTLE | SF_FORMAT_RAW | SF_FORMAT_FLOAT , SF_FALSE) ;
|
Chris@40
|
213 pcm_test_float ("float_be.raw" , SF_ENDIAN_BIG | SF_FORMAT_RAW | SF_FORMAT_FLOAT , SF_FALSE) ;
|
Chris@40
|
214
|
Chris@40
|
215 pcm_test_double ("double_le.raw", SF_ENDIAN_LITTLE | SF_FORMAT_RAW | SF_FORMAT_DOUBLE, SF_FALSE) ;
|
Chris@40
|
216 pcm_test_double ("double_be.raw", SF_ENDIAN_BIG | SF_FORMAT_RAW | SF_FORMAT_DOUBLE, SF_FALSE) ;
|
Chris@40
|
217 /* Lite remove end */
|
Chris@40
|
218 test_count++ ;
|
Chris@40
|
219 } ;
|
Chris@40
|
220
|
Chris@40
|
221 /* Lite remove start */
|
Chris@40
|
222 if (do_all || ! strcmp (argv [1], "paf"))
|
Chris@40
|
223 { pcm_test_char ("char_le.paf", SF_ENDIAN_LITTLE | SF_FORMAT_PAF | SF_FORMAT_PCM_S8, SF_FALSE) ;
|
Chris@40
|
224 pcm_test_char ("char_be.paf", SF_ENDIAN_BIG | SF_FORMAT_PAF | SF_FORMAT_PCM_S8, SF_FALSE) ;
|
Chris@40
|
225 pcm_test_short ("short_le.paf", SF_ENDIAN_LITTLE | SF_FORMAT_PAF | SF_FORMAT_PCM_16, SF_FALSE) ;
|
Chris@40
|
226 pcm_test_short ("short_be.paf", SF_ENDIAN_BIG | SF_FORMAT_PAF | SF_FORMAT_PCM_16, SF_FALSE) ;
|
Chris@40
|
227 pcm_test_24bit ("24bit_le.paf", SF_ENDIAN_LITTLE | SF_FORMAT_PAF | SF_FORMAT_PCM_24, SF_TRUE) ;
|
Chris@40
|
228 pcm_test_24bit ("24bit_be.paf", SF_ENDIAN_BIG | SF_FORMAT_PAF | SF_FORMAT_PCM_24, SF_TRUE) ;
|
Chris@40
|
229 test_count++ ;
|
Chris@40
|
230 } ;
|
Chris@40
|
231
|
Chris@40
|
232 if (do_all || ! strcmp (argv [1], "svx"))
|
Chris@40
|
233 { pcm_test_char ("char.svx" , SF_FORMAT_SVX | SF_FORMAT_PCM_S8, SF_FALSE) ;
|
Chris@40
|
234 pcm_test_short ("short.svx", SF_FORMAT_SVX | SF_FORMAT_PCM_16, SF_FALSE) ;
|
Chris@40
|
235
|
Chris@40
|
236 empty_file_test ("empty_char.svx", SF_FORMAT_SVX | SF_FORMAT_PCM_S8) ;
|
Chris@40
|
237 empty_file_test ("empty_short.svx", SF_FORMAT_SVX | SF_FORMAT_PCM_16) ;
|
Chris@40
|
238
|
Chris@40
|
239 test_count++ ;
|
Chris@40
|
240 } ;
|
Chris@40
|
241
|
Chris@40
|
242 if (do_all || ! strcmp (argv [1], "nist"))
|
Chris@40
|
243 { pcm_test_short ("short_le.nist", SF_ENDIAN_LITTLE | SF_FORMAT_NIST | SF_FORMAT_PCM_16, SF_FALSE) ;
|
Chris@40
|
244 pcm_test_short ("short_be.nist", SF_ENDIAN_BIG | SF_FORMAT_NIST | SF_FORMAT_PCM_16, SF_FALSE) ;
|
Chris@40
|
245 pcm_test_24bit ("24bit_le.nist", SF_ENDIAN_LITTLE | SF_FORMAT_NIST | SF_FORMAT_PCM_24, SF_FALSE) ;
|
Chris@40
|
246 pcm_test_24bit ("24bit_be.nist", SF_ENDIAN_BIG | SF_FORMAT_NIST | SF_FORMAT_PCM_24, SF_FALSE) ;
|
Chris@40
|
247 pcm_test_int ("int_le.nist" , SF_ENDIAN_LITTLE | SF_FORMAT_NIST | SF_FORMAT_PCM_32, SF_FALSE) ;
|
Chris@40
|
248 pcm_test_int ("int_be.nist" , SF_ENDIAN_BIG | SF_FORMAT_NIST | SF_FORMAT_PCM_32, SF_FALSE) ;
|
Chris@40
|
249
|
Chris@40
|
250 test_count++ ;
|
Chris@40
|
251 } ;
|
Chris@40
|
252
|
Chris@40
|
253 if (do_all || ! strcmp (argv [1], "ircam"))
|
Chris@40
|
254 { pcm_test_short ("short_be.ircam" , SF_ENDIAN_BIG | SF_FORMAT_IRCAM | SF_FORMAT_PCM_16, SF_FALSE) ;
|
Chris@40
|
255 pcm_test_short ("short_le.ircam" , SF_ENDIAN_LITTLE | SF_FORMAT_IRCAM | SF_FORMAT_PCM_16, SF_FALSE) ;
|
Chris@40
|
256 pcm_test_int ("int_be.ircam" , SF_ENDIAN_BIG | SF_FORMAT_IRCAM | SF_FORMAT_PCM_32, SF_FALSE) ;
|
Chris@40
|
257 pcm_test_int ("int_le.ircam" , SF_ENDIAN_LITTLE | SF_FORMAT_IRCAM | SF_FORMAT_PCM_32, SF_FALSE) ;
|
Chris@40
|
258 pcm_test_float ("float_be.ircam" , SF_ENDIAN_BIG | SF_FORMAT_IRCAM | SF_FORMAT_FLOAT , SF_FALSE) ;
|
Chris@40
|
259 pcm_test_float ("float_le.ircam" , SF_ENDIAN_LITTLE | SF_FORMAT_IRCAM | SF_FORMAT_FLOAT , SF_FALSE) ;
|
Chris@40
|
260
|
Chris@40
|
261 test_count++ ;
|
Chris@40
|
262 } ;
|
Chris@40
|
263
|
Chris@40
|
264 if (do_all || ! strcmp (argv [1], "voc"))
|
Chris@40
|
265 { pcm_test_char ("char.voc" , SF_FORMAT_VOC | SF_FORMAT_PCM_U8, SF_FALSE) ;
|
Chris@40
|
266 pcm_test_short ("short.voc", SF_FORMAT_VOC | SF_FORMAT_PCM_16, SF_FALSE) ;
|
Chris@40
|
267
|
Chris@40
|
268 test_count++ ;
|
Chris@40
|
269 } ;
|
Chris@40
|
270
|
Chris@40
|
271 if (do_all || ! strcmp (argv [1], "mat4"))
|
Chris@40
|
272 { pcm_test_short ("short_be.mat4" , SF_ENDIAN_BIG | SF_FORMAT_MAT4 | SF_FORMAT_PCM_16, SF_FALSE) ;
|
Chris@40
|
273 pcm_test_short ("short_le.mat4" , SF_ENDIAN_LITTLE | SF_FORMAT_MAT4 | SF_FORMAT_PCM_16, SF_FALSE) ;
|
Chris@40
|
274 pcm_test_int ("int_be.mat4" , SF_ENDIAN_BIG | SF_FORMAT_MAT4 | SF_FORMAT_PCM_32, SF_FALSE) ;
|
Chris@40
|
275 pcm_test_int ("int_le.mat4" , SF_ENDIAN_LITTLE | SF_FORMAT_MAT4 | SF_FORMAT_PCM_32, SF_FALSE) ;
|
Chris@40
|
276 pcm_test_float ("float_be.mat4" , SF_ENDIAN_BIG | SF_FORMAT_MAT4 | SF_FORMAT_FLOAT , SF_FALSE) ;
|
Chris@40
|
277 pcm_test_float ("float_le.mat4" , SF_ENDIAN_LITTLE | SF_FORMAT_MAT4 | SF_FORMAT_FLOAT , SF_FALSE) ;
|
Chris@40
|
278 pcm_test_double ("double_be.mat4" , SF_ENDIAN_BIG | SF_FORMAT_MAT4 | SF_FORMAT_DOUBLE, SF_FALSE) ;
|
Chris@40
|
279 pcm_test_double ("double_le.mat4" , SF_ENDIAN_LITTLE | SF_FORMAT_MAT4 | SF_FORMAT_DOUBLE, SF_FALSE) ;
|
Chris@40
|
280
|
Chris@40
|
281 empty_file_test ("empty_short.mat4", SF_FORMAT_MAT4 | SF_FORMAT_PCM_16) ;
|
Chris@40
|
282 empty_file_test ("empty_float.mat4", SF_FORMAT_MAT4 | SF_FORMAT_FLOAT) ;
|
Chris@40
|
283 test_count++ ;
|
Chris@40
|
284 } ;
|
Chris@40
|
285
|
Chris@40
|
286 if (do_all || ! strcmp (argv [1], "mat5"))
|
Chris@40
|
287 { pcm_test_char ("char_be.mat5" , SF_ENDIAN_BIG | SF_FORMAT_MAT5 | SF_FORMAT_PCM_U8, SF_FALSE) ;
|
Chris@40
|
288 pcm_test_char ("char_le.mat5" , SF_ENDIAN_LITTLE | SF_FORMAT_MAT5 | SF_FORMAT_PCM_U8, SF_FALSE) ;
|
Chris@40
|
289 pcm_test_short ("short_be.mat5" , SF_ENDIAN_BIG | SF_FORMAT_MAT5 | SF_FORMAT_PCM_16, SF_FALSE) ;
|
Chris@40
|
290 pcm_test_short ("short_le.mat5" , SF_ENDIAN_LITTLE | SF_FORMAT_MAT5 | SF_FORMAT_PCM_16, SF_FALSE) ;
|
Chris@40
|
291 pcm_test_int ("int_be.mat5" , SF_ENDIAN_BIG | SF_FORMAT_MAT5 | SF_FORMAT_PCM_32, SF_FALSE) ;
|
Chris@40
|
292 pcm_test_int ("int_le.mat5" , SF_ENDIAN_LITTLE | SF_FORMAT_MAT5 | SF_FORMAT_PCM_32, SF_FALSE) ;
|
Chris@40
|
293 pcm_test_float ("float_be.mat5" , SF_ENDIAN_BIG | SF_FORMAT_MAT5 | SF_FORMAT_FLOAT , SF_FALSE) ;
|
Chris@40
|
294 pcm_test_float ("float_le.mat5" , SF_ENDIAN_LITTLE | SF_FORMAT_MAT5 | SF_FORMAT_FLOAT , SF_FALSE) ;
|
Chris@40
|
295 pcm_test_double ("double_be.mat5" , SF_ENDIAN_BIG | SF_FORMAT_MAT5 | SF_FORMAT_DOUBLE, SF_FALSE) ;
|
Chris@40
|
296 pcm_test_double ("double_le.mat5" , SF_ENDIAN_LITTLE | SF_FORMAT_MAT5 | SF_FORMAT_DOUBLE, SF_FALSE) ;
|
Chris@40
|
297
|
Chris@40
|
298 increment_open_file_count () ;
|
Chris@40
|
299
|
Chris@40
|
300 empty_file_test ("empty_char.mat5", SF_FORMAT_MAT5 | SF_FORMAT_PCM_U8) ;
|
Chris@40
|
301 empty_file_test ("empty_short.mat5", SF_FORMAT_MAT5 | SF_FORMAT_PCM_16) ;
|
Chris@40
|
302 empty_file_test ("empty_float.mat5", SF_FORMAT_MAT5 | SF_FORMAT_FLOAT) ;
|
Chris@40
|
303
|
Chris@40
|
304 test_count++ ;
|
Chris@40
|
305 } ;
|
Chris@40
|
306
|
Chris@40
|
307 if (do_all || ! strcmp (argv [1], "pvf"))
|
Chris@40
|
308 { pcm_test_char ("char.pvf" , SF_FORMAT_PVF | SF_FORMAT_PCM_S8, SF_FALSE) ;
|
Chris@40
|
309 pcm_test_short ("short.pvf", SF_FORMAT_PVF | SF_FORMAT_PCM_16, SF_FALSE) ;
|
Chris@40
|
310 pcm_test_int ("int.pvf" , SF_FORMAT_PVF | SF_FORMAT_PCM_32, SF_FALSE) ;
|
Chris@40
|
311 test_count++ ;
|
Chris@40
|
312 } ;
|
Chris@40
|
313
|
Chris@40
|
314 if (do_all || ! strcmp (argv [1], "htk"))
|
Chris@40
|
315 { pcm_test_short ("short.htk", SF_FORMAT_HTK | SF_FORMAT_PCM_16, SF_FALSE) ;
|
Chris@40
|
316 test_count++ ;
|
Chris@40
|
317 } ;
|
Chris@40
|
318
|
Chris@40
|
319 if (do_all || ! strcmp (argv [1], "mpc2k"))
|
Chris@40
|
320 { pcm_test_short ("short.mpc", SF_FORMAT_MPC2K | SF_FORMAT_PCM_16, SF_FALSE) ;
|
Chris@40
|
321 test_count++ ;
|
Chris@40
|
322 } ;
|
Chris@40
|
323
|
Chris@40
|
324 if (do_all || ! strcmp (argv [1], "avr"))
|
Chris@40
|
325 { pcm_test_char ("char_u8.avr" , SF_FORMAT_AVR | SF_FORMAT_PCM_U8, SF_FALSE) ;
|
Chris@40
|
326 pcm_test_char ("char_s8.avr" , SF_FORMAT_AVR | SF_FORMAT_PCM_S8, SF_FALSE) ;
|
Chris@40
|
327 pcm_test_short ("short.avr" , SF_FORMAT_AVR | SF_FORMAT_PCM_16, SF_FALSE) ;
|
Chris@40
|
328 test_count++ ;
|
Chris@40
|
329 } ;
|
Chris@40
|
330 /* Lite remove end */
|
Chris@40
|
331
|
Chris@40
|
332 if (do_all || ! strcmp (argv [1], "w64"))
|
Chris@40
|
333 { pcm_test_char ("char.w64" , SF_FORMAT_W64 | SF_FORMAT_PCM_U8, SF_FALSE) ;
|
Chris@40
|
334 pcm_test_short ("short.w64" , SF_FORMAT_W64 | SF_FORMAT_PCM_16, SF_FALSE) ;
|
Chris@40
|
335 pcm_test_24bit ("24bit.w64" , SF_FORMAT_W64 | SF_FORMAT_PCM_24, SF_FALSE) ;
|
Chris@40
|
336 pcm_test_int ("int.w64" , SF_FORMAT_W64 | SF_FORMAT_PCM_32, SF_FALSE) ;
|
Chris@40
|
337 /* Lite remove start */
|
Chris@40
|
338 pcm_test_float ("float.w64" , SF_FORMAT_W64 | SF_FORMAT_FLOAT , SF_FALSE) ;
|
Chris@40
|
339 pcm_test_double ("double.w64" , SF_FORMAT_W64 | SF_FORMAT_DOUBLE, SF_FALSE) ;
|
Chris@40
|
340 /* Lite remove end */
|
Chris@40
|
341
|
Chris@40
|
342 empty_file_test ("empty_char.w64", SF_FORMAT_W64 | SF_FORMAT_PCM_U8) ;
|
Chris@40
|
343 empty_file_test ("empty_short.w64", SF_FORMAT_W64 | SF_FORMAT_PCM_16) ;
|
Chris@40
|
344 empty_file_test ("empty_float.w64", SF_FORMAT_W64 | SF_FORMAT_FLOAT) ;
|
Chris@40
|
345
|
Chris@40
|
346 test_count++ ;
|
Chris@40
|
347 } ;
|
Chris@40
|
348
|
Chris@40
|
349 if (do_all || ! strcmp (argv [1], "sds"))
|
Chris@40
|
350 { pcm_test_char ("char.sds" , SF_FORMAT_SDS | SF_FORMAT_PCM_S8, SF_FALSE) ;
|
Chris@40
|
351 pcm_test_short ("short.sds" , SF_FORMAT_SDS | SF_FORMAT_PCM_16, SF_FALSE) ;
|
Chris@40
|
352 pcm_test_24bit ("24bit.sds" , SF_FORMAT_SDS | SF_FORMAT_PCM_24, SF_FALSE) ;
|
Chris@40
|
353
|
Chris@40
|
354 empty_file_test ("empty_char.sds", SF_FORMAT_SDS | SF_FORMAT_PCM_S8) ;
|
Chris@40
|
355 empty_file_test ("empty_short.sds", SF_FORMAT_SDS | SF_FORMAT_PCM_16) ;
|
Chris@40
|
356
|
Chris@40
|
357 test_count++ ;
|
Chris@40
|
358 } ;
|
Chris@40
|
359
|
Chris@40
|
360 if (do_all || ! strcmp (argv [1], "sd2"))
|
Chris@40
|
361 { pcm_test_char ("char.sd2" , SF_FORMAT_SD2 | SF_FORMAT_PCM_S8, SF_TRUE) ;
|
Chris@40
|
362 pcm_test_short ("short.sd2" , SF_FORMAT_SD2 | SF_FORMAT_PCM_16, SF_TRUE) ;
|
Chris@40
|
363 pcm_test_24bit ("24bit.sd2" , SF_FORMAT_SD2 | SF_FORMAT_PCM_24, SF_TRUE) ;
|
Chris@40
|
364 pcm_test_int ("32bit.sd2" , SF_FORMAT_SD2 | SF_FORMAT_PCM_32, SF_TRUE) ;
|
Chris@40
|
365 test_count++ ;
|
Chris@40
|
366 } ;
|
Chris@40
|
367
|
Chris@40
|
368 if (do_all || ! strcmp (argv [1], "flac"))
|
Chris@40
|
369 { if (HAVE_EXTERNAL_XIPH_LIBS)
|
Chris@40
|
370 { pcm_test_char ("char.flac" , SF_FORMAT_FLAC | SF_FORMAT_PCM_S8, SF_TRUE) ;
|
Chris@40
|
371 pcm_test_short ("short.flac" , SF_FORMAT_FLAC | SF_FORMAT_PCM_16, SF_TRUE) ;
|
Chris@40
|
372 pcm_test_24bit ("24bit.flac" , SF_FORMAT_FLAC | SF_FORMAT_PCM_24, SF_TRUE) ;
|
Chris@40
|
373 }
|
Chris@40
|
374 else
|
Chris@40
|
375 puts (" No FLAC tests because FLAC support was not compiled in.") ;
|
Chris@40
|
376 test_count++ ;
|
Chris@40
|
377 } ;
|
Chris@40
|
378
|
Chris@40
|
379 if (do_all || ! strcmp (argv [1], "rf64"))
|
Chris@40
|
380 { pcm_test_char ("char.rf64" , SF_FORMAT_RF64 | SF_FORMAT_PCM_U8, SF_FALSE) ;
|
Chris@40
|
381 pcm_test_short ("short.rf64" , SF_FORMAT_RF64 | SF_FORMAT_PCM_16, SF_FALSE) ;
|
Chris@40
|
382 pcm_test_24bit ("24bit.rf64" , SF_FORMAT_RF64 | SF_FORMAT_PCM_24, SF_FALSE) ;
|
Chris@40
|
383 pcm_test_int ("int.rf64" , SF_FORMAT_RF64 | SF_FORMAT_PCM_32, SF_FALSE) ;
|
Chris@40
|
384
|
Chris@40
|
385 /* Lite remove start */
|
Chris@40
|
386 pcm_test_float ("float.rf64" , SF_FORMAT_RF64 | SF_FORMAT_FLOAT , SF_FALSE) ;
|
Chris@40
|
387 pcm_test_double ("double.rf64" , SF_FORMAT_RF64 | SF_FORMAT_DOUBLE, SF_FALSE) ;
|
Chris@40
|
388 empty_file_test ("empty_char.rf64", SF_FORMAT_RF64 | SF_FORMAT_PCM_U8) ;
|
Chris@40
|
389 empty_file_test ("empty_short.rf64", SF_FORMAT_RF64 | SF_FORMAT_PCM_16) ;
|
Chris@40
|
390 empty_file_test ("empty_float.rf64", SF_FORMAT_RF64 | SF_FORMAT_FLOAT) ;
|
Chris@40
|
391 /* Lite remove end */
|
Chris@40
|
392
|
Chris@40
|
393 test_count++ ;
|
Chris@40
|
394 } ;
|
Chris@40
|
395
|
Chris@40
|
396 if (test_count == 0)
|
Chris@40
|
397 { printf ("Mono : ************************************\n") ;
|
Chris@40
|
398 printf ("Mono : * No '%s' test defined.\n", argv [1]) ;
|
Chris@40
|
399 printf ("Mono : ************************************\n") ;
|
Chris@40
|
400 return 1 ;
|
Chris@40
|
401 } ;
|
Chris@40
|
402
|
Chris@40
|
403 /* Only open file descriptors should be stdin, stdout and stderr. */
|
Chris@40
|
404 check_open_file_count_or_die (__LINE__) ;
|
Chris@40
|
405
|
Chris@40
|
406 return 0 ;
|
Chris@40
|
407 } /* main */
|
Chris@40
|
408
|
Chris@40
|
409 /*============================================================================================
|
Chris@40
|
410 ** Helper functions and macros.
|
Chris@40
|
411 */
|
Chris@40
|
412
|
Chris@40
|
413 static void create_short_file (const char *filename) ;
|
Chris@40
|
414
|
Chris@40
|
415 #define CHAR_ERROR(x, y) (abs ((x) - (y)) > 255)
|
Chris@40
|
416 #define INT_ERROR(x, y) (((x) - (y)) != 0)
|
Chris@40
|
417 #define BIT_20_ERROR(x, y) (abs ((x) - (y)) > 4095)
|
Chris@40
|
418 #define TRIBYTE_ERROR(x, y) (abs ((x) - (y)) > 255)
|
Chris@40
|
419 #define FLOAT_ERROR(x, y) (fabs ((x) - (y)) > 1e-5)
|
Chris@40
|
420
|
Chris@40
|
421 #define CONVERT_DATA(k, len, new, orig) \
|
Chris@40
|
422 { for ((k) = 0 ; (k) < (len) ; (k) ++) \
|
Chris@40
|
423 (new) [k] = (orig) [k] ; \
|
Chris@40
|
424 }
|
Chris@40
|
425
|
Chris@40
|
426 [+ FOR data_type
|
Chris@40
|
427 +]
|
Chris@40
|
428 /*======================================================================================
|
Chris@40
|
429 */
|
Chris@40
|
430
|
Chris@40
|
431 static void mono_[+ (get "type_name") +]_test (const char *filename, int format, int long_file_ok, int allow_fd) ;
|
Chris@40
|
432 static void stereo_[+ (get "type_name") +]_test (const char *filename, int format, int long_file_ok, int allow_fd) ;
|
Chris@40
|
433 static void mono_rdwr_[+ (get "type_name") +]_test (const char *filename, int format, int long_file_ok, int allow_fd) ;
|
Chris@40
|
434 static void new_rdwr_[+ (get "type_name") +]_test (const char *filename, int format, int allow_fd) ;
|
Chris@40
|
435 static void multi_seek_test (const char * filename, int format) ;
|
Chris@40
|
436 static void write_seek_extend_test (const char * filename, int format) ;
|
Chris@40
|
437
|
Chris@40
|
438 static void
|
Chris@40
|
439 pcm_test_[+ (get "type_name") +] (const char *filename, int format, int long_file_ok)
|
Chris@40
|
440 { SF_INFO sfinfo ;
|
Chris@40
|
441 [+ (get "data_type") +] *orig ;
|
Chris@40
|
442 int k, allow_fd ;
|
Chris@40
|
443
|
Chris@40
|
444 /* Sd2 files cannot be opened from an existing file descriptor. */
|
Chris@40
|
445 allow_fd = ((format & SF_FORMAT_TYPEMASK) == SF_FORMAT_SD2) ? SF_FALSE : SF_TRUE ;
|
Chris@40
|
446
|
Chris@40
|
447 print_test_name ("pcm_test_[+ (get "type_name") +]", filename) ;
|
Chris@40
|
448
|
Chris@40
|
449 sfinfo.samplerate = 44100 ;
|
Chris@40
|
450 sfinfo.frames = SILLY_WRITE_COUNT ; /* Wrong length. Library should correct this on sf_close. */
|
Chris@40
|
451 sfinfo.channels = 1 ;
|
Chris@40
|
452 sfinfo.format = format ;
|
Chris@40
|
453
|
Chris@40
|
454 test_sf_format_or_die (&sfinfo, __LINE__) ;
|
Chris@40
|
455
|
Chris@40
|
456 gen_windowed_sine_double (orig_data.d, DATA_LENGTH, [+ (get "max_val") +]) ;
|
Chris@40
|
457
|
Chris@40
|
458 orig = orig_data.[+ (get "data_field") +] ;
|
Chris@40
|
459
|
Chris@40
|
460 /* Make this a macro so gdb steps over it in one go. */
|
Chris@40
|
461 CONVERT_DATA (k, DATA_LENGTH, orig, orig_data.d) ;
|
Chris@40
|
462
|
Chris@40
|
463 /* Some test broken out here. */
|
Chris@40
|
464
|
Chris@40
|
465 mono_[+ (get "type_name") +]_test (filename, format, long_file_ok, allow_fd) ;
|
Chris@40
|
466
|
Chris@40
|
467 /* Sub format DWVW does not allow seeking. */
|
Chris@40
|
468 if ((format & SF_FORMAT_SUBMASK) == SF_FORMAT_DWVW_16 ||
|
Chris@40
|
469 (format & SF_FORMAT_SUBMASK) == SF_FORMAT_DWVW_24)
|
Chris@40
|
470 { unlink (filename) ;
|
Chris@40
|
471 printf ("no seek : ok\n") ;
|
Chris@40
|
472 return ;
|
Chris@40
|
473 } ;
|
Chris@40
|
474
|
Chris@40
|
475 if ((format & SF_FORMAT_TYPEMASK) != SF_FORMAT_FLAC
|
Chris@40
|
476 && (format & SF_FORMAT_SUBMASK) != SF_FORMAT_ALAC_16
|
Chris@40
|
477 && (format & SF_FORMAT_SUBMASK) != SF_FORMAT_ALAC_20
|
Chris@40
|
478 && (format & SF_FORMAT_SUBMASK) != SF_FORMAT_ALAC_24
|
Chris@40
|
479 && (format & SF_FORMAT_SUBMASK) != SF_FORMAT_ALAC_32
|
Chris@40
|
480 )
|
Chris@40
|
481 mono_rdwr_[+ (get "type_name") +]_test (filename, format, long_file_ok, allow_fd) ;
|
Chris@40
|
482
|
Chris@40
|
483 /* If the format doesn't support stereo we're done. */
|
Chris@40
|
484 sfinfo.channels = 2 ;
|
Chris@40
|
485 if (sf_format_check (&sfinfo) == 0)
|
Chris@40
|
486 { unlink (filename) ;
|
Chris@40
|
487 puts ("no stereo : ok") ;
|
Chris@40
|
488 return ;
|
Chris@40
|
489 } ;
|
Chris@40
|
490
|
Chris@40
|
491 stereo_[+ (get "type_name") +]_test (filename, format, long_file_ok, allow_fd) ;
|
Chris@40
|
492
|
Chris@40
|
493 /* New read/write test. Not sure if this is needed yet. */
|
Chris@40
|
494
|
Chris@40
|
495 if ((format & SF_FORMAT_TYPEMASK) != SF_FORMAT_PAF
|
Chris@40
|
496 && (format & SF_FORMAT_TYPEMASK) != SF_FORMAT_VOC
|
Chris@40
|
497 && (format & SF_FORMAT_TYPEMASK) != SF_FORMAT_FLAC
|
Chris@40
|
498 && (format & SF_FORMAT_SUBMASK) != SF_FORMAT_ALAC_16
|
Chris@40
|
499 && (format & SF_FORMAT_SUBMASK) != SF_FORMAT_ALAC_20
|
Chris@40
|
500 && (format & SF_FORMAT_SUBMASK) != SF_FORMAT_ALAC_24
|
Chris@40
|
501 && (format & SF_FORMAT_SUBMASK) != SF_FORMAT_ALAC_32
|
Chris@40
|
502 )
|
Chris@40
|
503 new_rdwr_[+ (get "type_name") +]_test (filename, format, allow_fd) ;
|
Chris@40
|
504
|
Chris@40
|
505 delete_file (format, filename) ;
|
Chris@40
|
506
|
Chris@40
|
507 puts ("ok") ;
|
Chris@40
|
508 return ;
|
Chris@40
|
509 } /* pcm_test_[+ (get "type_name") +] */
|
Chris@40
|
510
|
Chris@40
|
511 static void
|
Chris@40
|
512 mono_[+ (get "type_name") +]_test (const char *filename, int format, int long_file_ok, int allow_fd)
|
Chris@40
|
513 { SNDFILE *file ;
|
Chris@40
|
514 SF_INFO sfinfo ;
|
Chris@40
|
515 [+ (get "data_type") +] *orig, *test ;
|
Chris@40
|
516 sf_count_t count ;
|
Chris@40
|
517 int k, items, total ;
|
Chris@40
|
518
|
Chris@40
|
519 sfinfo.samplerate = 44100 ;
|
Chris@40
|
520 sfinfo.frames = SILLY_WRITE_COUNT ; /* Wrong length. Library should correct this on sf_close. */
|
Chris@40
|
521 sfinfo.channels = 1 ;
|
Chris@40
|
522 sfinfo.format = format ;
|
Chris@40
|
523
|
Chris@40
|
524 orig = orig_data.[+ (get "data_field") +] ;
|
Chris@40
|
525 test = test_data.[+ (get "data_field") +] ;
|
Chris@40
|
526
|
Chris@40
|
527 items = DATA_LENGTH ;
|
Chris@40
|
528
|
Chris@40
|
529 file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, allow_fd, __LINE__) ;
|
Chris@40
|
530
|
Chris@40
|
531 if (sfinfo.frames || sfinfo.sections || sfinfo.seekable)
|
Chris@40
|
532 { printf ("\n\nLine %d : Weird SF_INFO fields.\n", __LINE__) ;
|
Chris@40
|
533 exit (1) ;
|
Chris@40
|
534 } ;
|
Chris@40
|
535
|
Chris@40
|
536 sf_set_string (file, SF_STR_ARTIST, "Your name here") ;
|
Chris@40
|
537
|
Chris@40
|
538 test_write_[+ (get "data_type") +]_or_die (file, 0, orig, items, __LINE__) ;
|
Chris@40
|
539 sf_write_sync (file) ;
|
Chris@40
|
540 test_write_[+ (get "data_type") +]_or_die (file, 0, orig, items, __LINE__) ;
|
Chris@40
|
541 sf_write_sync (file) ;
|
Chris@40
|
542
|
Chris@40
|
543 /* Add non-audio data after the audio. */
|
Chris@40
|
544 sf_set_string (file, SF_STR_COPYRIGHT, "Copyright (c) 2003") ;
|
Chris@40
|
545
|
Chris@40
|
546 sf_close (file) ;
|
Chris@40
|
547
|
Chris@40
|
548 memset (test, 0, items * sizeof ([+ (get "data_type") +])) ;
|
Chris@40
|
549
|
Chris@40
|
550 if ((format & SF_FORMAT_TYPEMASK) != SF_FORMAT_RAW)
|
Chris@40
|
551 memset (&sfinfo, 0, sizeof (sfinfo)) ;
|
Chris@40
|
552
|
Chris@40
|
553 file = test_open_file_or_die (filename, SFM_READ, &sfinfo, allow_fd, __LINE__) ;
|
Chris@40
|
554
|
Chris@40
|
555 if (sfinfo.format != format)
|
Chris@40
|
556 { printf ("\n\nLine %d : Mono : Returned format incorrect (0x%08X => 0x%08X).\n", __LINE__, format, sfinfo.format) ;
|
Chris@40
|
557 exit (1) ;
|
Chris@40
|
558 } ;
|
Chris@40
|
559
|
Chris@40
|
560 if (sfinfo.frames < 2 * items)
|
Chris@40
|
561 { printf ("\n\nLine %d : Mono : Incorrect number of frames in file (too short). (%" PRId64 " should be %d)\n", __LINE__, sfinfo.frames, items) ;
|
Chris@40
|
562 exit (1) ;
|
Chris@40
|
563 } ;
|
Chris@40
|
564
|
Chris@40
|
565 if (! long_file_ok && sfinfo.frames > 2 * items)
|
Chris@40
|
566 { printf ("\n\nLine %d : Mono : Incorrect number of frames in file (too long). (%" PRId64 " should be %d)\n", __LINE__, sfinfo.frames, items) ;
|
Chris@40
|
567 exit (1) ;
|
Chris@40
|
568 } ;
|
Chris@40
|
569
|
Chris@40
|
570 if (sfinfo.channels != 1)
|
Chris@40
|
571 { printf ("\n\nLine %d : Mono : Incorrect number of channels in file.\n", __LINE__) ;
|
Chris@40
|
572 exit (1) ;
|
Chris@40
|
573 } ;
|
Chris@40
|
574
|
Chris@40
|
575 if (sfinfo.seekable != 1)
|
Chris@40
|
576 { printf ("\n\nLine %d : File should be seekable.\n", __LINE__) ;
|
Chris@40
|
577 exit (1) ;
|
Chris@40
|
578 } ;
|
Chris@40
|
579
|
Chris@40
|
580 check_log_buffer_or_die (file, __LINE__) ;
|
Chris@40
|
581
|
Chris@40
|
582 test_read_[+ (get "data_type") +]_or_die (file, 0, test, items, __LINE__) ;
|
Chris@40
|
583 for (k = 0 ; k < items ; k++)
|
Chris@40
|
584 if ([+ (get "error_func") +] (orig [k], test [k]))
|
Chris@40
|
585 { printf ("\n\nLine %d: Mono : Incorrect sample A (#%d : [+ (get "format_char") +] => [+ (get "format_char") +]).\n", __LINE__, k, orig [k], test [k]) ;
|
Chris@40
|
586 oct_save_[+ (get "data_type") +] (orig, test, items) ;
|
Chris@40
|
587 exit (1) ;
|
Chris@40
|
588 } ;
|
Chris@40
|
589
|
Chris@40
|
590 /* Test multiple short reads. */
|
Chris@40
|
591 test_seek_or_die (file, 0, SEEK_SET, 0, sfinfo.channels, __LINE__) ;
|
Chris@40
|
592
|
Chris@40
|
593 total = 0 ;
|
Chris@40
|
594 for (k = 1 ; k <= 32 ; k++)
|
Chris@40
|
595 { int ik ;
|
Chris@40
|
596
|
Chris@40
|
597 test_read_[+ (get "data_type") +]_or_die (file, 0, test + total, k, __LINE__) ;
|
Chris@40
|
598 total += k ;
|
Chris@40
|
599
|
Chris@40
|
600 for (ik = 0 ; ik < total ; ik++)
|
Chris@40
|
601 if ([+ (get "error_func") +] (orig [ik], test [ik]))
|
Chris@40
|
602 { printf ("\n\nLine %d : Mono : Incorrect sample A (#%d : [+ (get "format_char") +] => [+ (get "format_char") +]).\n", __LINE__, ik, orig [ik], test [ik]) ;
|
Chris@40
|
603 exit (1) ;
|
Chris@40
|
604 } ;
|
Chris@40
|
605 } ;
|
Chris@40
|
606
|
Chris@40
|
607 /* Seek to start of file. */
|
Chris@40
|
608 test_seek_or_die (file, 0, SEEK_SET, 0, sfinfo.channels, __LINE__) ;
|
Chris@40
|
609
|
Chris@40
|
610 test_read_[+ (get "data_type") +]_or_die (file, 0, test, 4, __LINE__) ;
|
Chris@40
|
611 for (k = 0 ; k < 4 ; k++)
|
Chris@40
|
612 if ([+ (get "error_func") +] (orig [k], test [k]))
|
Chris@40
|
613 { printf ("\n\nLine %d : Mono : Incorrect sample A (#%d : [+ (get "format_char") +] => [+ (get "format_char") +]).\n", __LINE__, k, orig [k], test [k]) ;
|
Chris@40
|
614 exit (1) ;
|
Chris@40
|
615 } ;
|
Chris@40
|
616
|
Chris@40
|
617 /* For some codecs we can't go past here. */
|
Chris@40
|
618 if ((format & SF_FORMAT_SUBMASK) == SF_FORMAT_DWVW_16 ||
|
Chris@40
|
619 (format & SF_FORMAT_SUBMASK) == SF_FORMAT_DWVW_24)
|
Chris@40
|
620 { sf_close (file) ;
|
Chris@40
|
621 unlink (filename) ;
|
Chris@40
|
622 printf ("no seek : ") ;
|
Chris@40
|
623 return ;
|
Chris@40
|
624 } ;
|
Chris@40
|
625
|
Chris@40
|
626 /* Seek to offset from start of file. */
|
Chris@40
|
627 test_seek_or_die (file, items + 10, SEEK_SET, items + 10, sfinfo.channels, __LINE__) ;
|
Chris@40
|
628
|
Chris@40
|
629 test_read_[+ (get "data_type") +]_or_die (file, 0, test + 10, 4, __LINE__) ;
|
Chris@40
|
630 for (k = 10 ; k < 14 ; k++)
|
Chris@40
|
631 if ([+ (get "error_func") +] (orig [k], test [k]))
|
Chris@40
|
632 { printf ("\n\nLine %d : Mono : Incorrect sample A (#%d : [+ (get "format_char") +] => [+ (get "format_char") +]).\n", __LINE__, k, test [k], orig [k]) ;
|
Chris@40
|
633 exit (1) ;
|
Chris@40
|
634 } ;
|
Chris@40
|
635
|
Chris@40
|
636 /* Seek to offset from current position. */
|
Chris@40
|
637 test_seek_or_die (file, 6, SEEK_CUR, items + 20, sfinfo.channels, __LINE__) ;
|
Chris@40
|
638
|
Chris@40
|
639 test_read_[+ (get "data_type") +]_or_die (file, 0, test + 20, 4, __LINE__) ;
|
Chris@40
|
640 for (k = 20 ; k < 24 ; k++)
|
Chris@40
|
641 if ([+ (get "error_func") +] (orig [k], test [k]))
|
Chris@40
|
642 { printf ("\n\nLine %d : Mono : Incorrect sample A (#%d : [+ (get "format_char") +] => [+ (get "format_char") +]).\n", __LINE__, k, test [k], orig [k]) ;
|
Chris@40
|
643 exit (1) ;
|
Chris@40
|
644 } ;
|
Chris@40
|
645
|
Chris@40
|
646 /* Seek to offset from end of file. */
|
Chris@40
|
647 test_seek_or_die (file, -1 * (sfinfo.frames - 10), SEEK_END, 10, sfinfo.channels, __LINE__) ;
|
Chris@40
|
648
|
Chris@40
|
649 test_read_[+ (get "data_type") +]_or_die (file, 0, test + 10, 4, __LINE__) ;
|
Chris@40
|
650 for (k = 10 ; k < 14 ; k++)
|
Chris@40
|
651 if ([+ (get "error_func") +] (orig [k], test [k]))
|
Chris@40
|
652 { printf ("\n\nLine %d : Mono : Incorrect sample D (#%d : [+ (get "format_char") +] => [+ (get "format_char") +]).\n", __LINE__, k, test [k], orig [k]) ;
|
Chris@40
|
653 exit (1) ;
|
Chris@40
|
654 } ;
|
Chris@40
|
655
|
Chris@40
|
656 /* Check read past end of file followed by sf_seek (sndfile, 0, SEEK_CUR). */
|
Chris@40
|
657 test_seek_or_die (file, 0, SEEK_SET, 0, sfinfo.channels, __LINE__) ;
|
Chris@40
|
658
|
Chris@40
|
659 count = 0 ;
|
Chris@40
|
660 while (count < sfinfo.frames)
|
Chris@40
|
661 count += sf_read_[+ (get "data_type") +] (file, test, 311) ;
|
Chris@40
|
662
|
Chris@40
|
663 /* Check that no error has occurred. */
|
Chris@40
|
664 if (sf_error (file))
|
Chris@40
|
665 { printf ("\n\nLine %d : Mono : error where there shouldn't have been one.\n", __LINE__) ;
|
Chris@40
|
666 puts (sf_strerror (file)) ;
|
Chris@40
|
667 exit (1) ;
|
Chris@40
|
668 } ;
|
Chris@40
|
669
|
Chris@40
|
670 /* Check that we haven't read beyond EOF. */
|
Chris@40
|
671 if (count > sfinfo.frames)
|
Chris@40
|
672 { printf ("\n\nLines %d : read past end of file (%" PRId64 " should be %" PRId64 ")\n", __LINE__, count, sfinfo.frames) ;
|
Chris@40
|
673 exit (1) ;
|
Chris@40
|
674 } ;
|
Chris@40
|
675
|
Chris@40
|
676 test_seek_or_die (file, 0, SEEK_CUR, sfinfo.frames, sfinfo.channels, __LINE__) ;
|
Chris@40
|
677
|
Chris@40
|
678 sf_close (file) ;
|
Chris@40
|
679
|
Chris@40
|
680 multi_seek_test (filename, format) ;
|
Chris@40
|
681 write_seek_extend_test (filename, format) ;
|
Chris@40
|
682
|
Chris@40
|
683 } /* mono_[+ (get "type_name") +]_test */
|
Chris@40
|
684
|
Chris@40
|
685 static void
|
Chris@40
|
686 stereo_[+ (get "type_name") +]_test (const char *filename, int format, int long_file_ok, int allow_fd)
|
Chris@40
|
687 { SNDFILE *file ;
|
Chris@40
|
688 SF_INFO sfinfo ;
|
Chris@40
|
689 [+ (get "data_type") +] *orig, *test ;
|
Chris@40
|
690 int k, items, frames ;
|
Chris@40
|
691
|
Chris@40
|
692 sfinfo.samplerate = 44100 ;
|
Chris@40
|
693 sfinfo.frames = SILLY_WRITE_COUNT ; /* Wrong length. Library should correct this on sf_close. */
|
Chris@40
|
694 sfinfo.channels = 2 ;
|
Chris@40
|
695 sfinfo.format = format ;
|
Chris@40
|
696
|
Chris@40
|
697 gen_windowed_sine_double (orig_data.d, DATA_LENGTH, [+ (get "max_val") +]) ;
|
Chris@40
|
698
|
Chris@40
|
699 orig = orig_data.[+ (get "data_field") +] ;
|
Chris@40
|
700 test = test_data.[+ (get "data_field") +] ;
|
Chris@40
|
701
|
Chris@40
|
702 /* Make this a macro so gdb steps over it in one go. */
|
Chris@40
|
703 CONVERT_DATA (k, DATA_LENGTH, orig, orig_data.d) ;
|
Chris@40
|
704
|
Chris@40
|
705 items = DATA_LENGTH ;
|
Chris@40
|
706 frames = items / sfinfo.channels ;
|
Chris@40
|
707
|
Chris@40
|
708 file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, allow_fd, __LINE__) ;
|
Chris@40
|
709
|
Chris@40
|
710 sf_set_string (file, SF_STR_ARTIST, "Your name here") ;
|
Chris@40
|
711
|
Chris@40
|
712 test_writef_[+ (get "data_type") +]_or_die (file, 0, orig, frames, __LINE__) ;
|
Chris@40
|
713
|
Chris@40
|
714 sf_set_string (file, SF_STR_COPYRIGHT, "Copyright (c) 2003") ;
|
Chris@40
|
715
|
Chris@40
|
716 sf_close (file) ;
|
Chris@40
|
717
|
Chris@40
|
718 memset (test, 0, items * sizeof ([+ (get "data_type") +])) ;
|
Chris@40
|
719
|
Chris@40
|
720 if ((format & SF_FORMAT_TYPEMASK) != SF_FORMAT_RAW)
|
Chris@40
|
721 memset (&sfinfo, 0, sizeof (sfinfo)) ;
|
Chris@40
|
722
|
Chris@40
|
723 file = test_open_file_or_die (filename, SFM_READ, &sfinfo, allow_fd, __LINE__) ;
|
Chris@40
|
724
|
Chris@40
|
725 if (sfinfo.format != format)
|
Chris@40
|
726 { printf ("\n\nLine %d : Stereo : Returned format incorrect (0x%08X => 0x%08X).\n",
|
Chris@40
|
727 __LINE__, format, sfinfo.format) ;
|
Chris@40
|
728 exit (1) ;
|
Chris@40
|
729 } ;
|
Chris@40
|
730
|
Chris@40
|
731 if (sfinfo.frames < frames)
|
Chris@40
|
732 { printf ("\n\nLine %d : Stereo : Incorrect number of frames in file (too short). (%" PRId64 " should be %d)\n",
|
Chris@40
|
733 __LINE__, sfinfo.frames, frames) ;
|
Chris@40
|
734 exit (1) ;
|
Chris@40
|
735 } ;
|
Chris@40
|
736
|
Chris@40
|
737 if (! long_file_ok && sfinfo.frames > frames)
|
Chris@40
|
738 { printf ("\n\nLine %d : Stereo : Incorrect number of frames in file (too long). (%" PRId64 " should be %d)\n",
|
Chris@40
|
739 __LINE__, sfinfo.frames, frames) ;
|
Chris@40
|
740 exit (1) ;
|
Chris@40
|
741 } ;
|
Chris@40
|
742
|
Chris@40
|
743 if (sfinfo.channels != 2)
|
Chris@40
|
744 { printf ("\n\nLine %d : Stereo : Incorrect number of channels in file.\n", __LINE__) ;
|
Chris@40
|
745 exit (1) ;
|
Chris@40
|
746 } ;
|
Chris@40
|
747
|
Chris@40
|
748 check_log_buffer_or_die (file, __LINE__) ;
|
Chris@40
|
749
|
Chris@40
|
750 test_readf_[+ (get "data_type") +]_or_die (file, 0, test, frames, __LINE__) ;
|
Chris@40
|
751 for (k = 0 ; k < items ; k++)
|
Chris@40
|
752 if ([+ (get "error_func") +] (test [k], orig [k]))
|
Chris@40
|
753 { printf ("\n\nLine %d : Stereo : Incorrect sample (#%d : [+ (get "format_char") +] => [+ (get "format_char") +]).\n", __LINE__, k, orig [k], test [k]) ;
|
Chris@40
|
754 exit (1) ;
|
Chris@40
|
755 } ;
|
Chris@40
|
756
|
Chris@40
|
757 /* Seek to start of file. */
|
Chris@40
|
758 test_seek_or_die (file, 0, SEEK_SET, 0, sfinfo.channels, __LINE__) ;
|
Chris@40
|
759
|
Chris@40
|
760 test_readf_[+ (get "data_type") +]_or_die (file, 0, test, 2, __LINE__) ;
|
Chris@40
|
761 for (k = 0 ; k < 4 ; k++)
|
Chris@40
|
762 if ([+ (get "error_func") +] (test [k], orig [k]))
|
Chris@40
|
763 { printf ("\n\nLine %d : Stereo : Incorrect sample (#%d : [+ (get "format_char") +] => [+ (get "format_char") +]).\n", __LINE__, k, orig [k], test [k]) ;
|
Chris@40
|
764 exit (1) ;
|
Chris@40
|
765 } ;
|
Chris@40
|
766
|
Chris@40
|
767 /* Seek to offset from start of file. */
|
Chris@40
|
768 test_seek_or_die (file, 10, SEEK_SET, 10, sfinfo.channels, __LINE__) ;
|
Chris@40
|
769
|
Chris@40
|
770 /* Check for errors here. */
|
Chris@40
|
771 if (sf_error (file))
|
Chris@40
|
772 { printf ("Line %d: Should NOT return an error.\n", __LINE__) ;
|
Chris@40
|
773 puts (sf_strerror (file)) ;
|
Chris@40
|
774 exit (1) ;
|
Chris@40
|
775 } ;
|
Chris@40
|
776
|
Chris@40
|
777 if (sf_read_[+ (get "data_type") +] (file, test, 1) > 0)
|
Chris@40
|
778 { printf ("Line %d: Should return 0.\n", __LINE__) ;
|
Chris@40
|
779 exit (1) ;
|
Chris@40
|
780 } ;
|
Chris@40
|
781
|
Chris@40
|
782 if (! sf_error (file))
|
Chris@40
|
783 { printf ("Line %d: Should return an error.\n", __LINE__) ;
|
Chris@40
|
784 exit (1) ;
|
Chris@40
|
785 } ;
|
Chris@40
|
786 /*-----------------------*/
|
Chris@40
|
787
|
Chris@40
|
788 test_readf_[+ (get "data_type") +]_or_die (file, 0, test + 10, 2, __LINE__) ;
|
Chris@40
|
789 for (k = 20 ; k < 24 ; k++)
|
Chris@40
|
790 if ([+ (get "error_func") +] (test [k], orig [k]))
|
Chris@40
|
791 { printf ("\n\nLine %d : Stereo : Incorrect sample (#%d : [+ (get "format_char") +] => [+ (get "format_char") +]).\n", __LINE__, k, orig [k], test [k]) ;
|
Chris@40
|
792 exit (1) ;
|
Chris@40
|
793 } ;
|
Chris@40
|
794
|
Chris@40
|
795 /* Seek to offset from current position. */
|
Chris@40
|
796 test_seek_or_die (file, 8, SEEK_CUR, 20, sfinfo.channels, __LINE__) ;
|
Chris@40
|
797
|
Chris@40
|
798 test_readf_[+ (get "data_type") +]_or_die (file, 0, test + 20, 2, __LINE__) ;
|
Chris@40
|
799 for (k = 40 ; k < 44 ; k++)
|
Chris@40
|
800 if ([+ (get "error_func") +] (test [k], orig [k]))
|
Chris@40
|
801 { printf ("\n\nLine %d : Stereo : Incorrect sample (#%d : [+ (get "format_char") +] => [+ (get "format_char") +]).\n", __LINE__, k, orig [k], test [k]) ;
|
Chris@40
|
802 exit (1) ;
|
Chris@40
|
803 } ;
|
Chris@40
|
804
|
Chris@40
|
805 /* Seek to offset from end of file. */
|
Chris@40
|
806 test_seek_or_die (file, -1 * (sfinfo.frames - 10), SEEK_END, 10, sfinfo.channels, __LINE__) ;
|
Chris@40
|
807
|
Chris@40
|
808 test_readf_[+ (get "data_type") +]_or_die (file, 0, test + 20, 2, __LINE__) ;
|
Chris@40
|
809 for (k = 20 ; k < 24 ; k++)
|
Chris@40
|
810 if ([+ (get "error_func") +] (test [k], orig [k]))
|
Chris@40
|
811 { printf ("\n\nLine %d : Stereo : Incorrect sample (#%d : [+ (get "format_char") +] => [+ (get "format_char") +]).\n", __LINE__, k, orig [k], test [k]) ;
|
Chris@40
|
812 exit (1) ;
|
Chris@40
|
813 } ;
|
Chris@40
|
814
|
Chris@40
|
815 sf_close (file) ;
|
Chris@40
|
816 } /* stereo_[+ (get "type_name") +]_test */
|
Chris@40
|
817
|
Chris@40
|
818 static void
|
Chris@40
|
819 mono_rdwr_[+ (get "type_name") +]_test (const char *filename, int format, int long_file_ok, int allow_fd)
|
Chris@40
|
820 { SNDFILE *file ;
|
Chris@40
|
821 SF_INFO sfinfo ;
|
Chris@40
|
822 [+ (get "data_type") +] *orig, *test ;
|
Chris@40
|
823 int k, pass ;
|
Chris@40
|
824
|
Chris@40
|
825 switch (format & SF_FORMAT_SUBMASK)
|
Chris@40
|
826 { case SF_FORMAT_ALAC_16 :
|
Chris@40
|
827 case SF_FORMAT_ALAC_20 :
|
Chris@40
|
828 case SF_FORMAT_ALAC_24 :
|
Chris@40
|
829 case SF_FORMAT_ALAC_32 :
|
Chris@40
|
830 allow_fd = 0 ;
|
Chris@40
|
831 break ;
|
Chris@40
|
832
|
Chris@40
|
833 default :
|
Chris@40
|
834 break ;
|
Chris@40
|
835 } ;
|
Chris@40
|
836
|
Chris@40
|
837 orig = orig_data.[+ (get "data_field") +] ;
|
Chris@40
|
838 test = test_data.[+ (get "data_field") +] ;
|
Chris@40
|
839
|
Chris@40
|
840 sfinfo.samplerate = SAMPLE_RATE ;
|
Chris@40
|
841 sfinfo.frames = DATA_LENGTH ;
|
Chris@40
|
842 sfinfo.channels = 1 ;
|
Chris@40
|
843 sfinfo.format = format ;
|
Chris@40
|
844
|
Chris@40
|
845 if ((format & SF_FORMAT_TYPEMASK) == SF_FORMAT_RAW
|
Chris@40
|
846 || (format & SF_FORMAT_TYPEMASK) == SF_FORMAT_AU
|
Chris@40
|
847 || (format & SF_FORMAT_TYPEMASK) == SF_FORMAT_SD2)
|
Chris@40
|
848 unlink (filename) ;
|
Chris@40
|
849 else
|
Chris@40
|
850 { /* Create a short file. */
|
Chris@40
|
851 create_short_file (filename) ;
|
Chris@40
|
852
|
Chris@40
|
853 /* Opening a already existing short file (ie invalid header) RDWR is disallowed.
|
Chris@40
|
854 ** If this returns a valif pointer sf_open() screwed up.
|
Chris@40
|
855 */
|
Chris@40
|
856 if ((file = sf_open (filename, SFM_RDWR, &sfinfo)))
|
Chris@40
|
857 { printf ("\n\nLine %d: sf_open should (SFM_RDWR) have failed but didn't.\n", __LINE__) ;
|
Chris@40
|
858 exit (1) ;
|
Chris@40
|
859 } ;
|
Chris@40
|
860
|
Chris@40
|
861 /* Truncate the file to zero bytes. */
|
Chris@40
|
862 if (truncate (filename, 0) < 0)
|
Chris@40
|
863 { printf ("\n\nLine %d: truncate (%s) failed", __LINE__, filename) ;
|
Chris@40
|
864 perror (NULL) ;
|
Chris@40
|
865 exit (1) ;
|
Chris@40
|
866 } ;
|
Chris@40
|
867 } ;
|
Chris@40
|
868
|
Chris@40
|
869 /* Opening a zero length file RDWR is allowed, but the SF_INFO struct must contain
|
Chris@40
|
870 ** all the usual data required when opening the file in WRITE mode.
|
Chris@40
|
871 */
|
Chris@40
|
872 sfinfo.samplerate = SAMPLE_RATE ;
|
Chris@40
|
873 sfinfo.frames = DATA_LENGTH ;
|
Chris@40
|
874 sfinfo.channels = 1 ;
|
Chris@40
|
875 sfinfo.format = format ;
|
Chris@40
|
876
|
Chris@40
|
877 file = test_open_file_or_die (filename, SFM_RDWR, &sfinfo, allow_fd, __LINE__) ;
|
Chris@40
|
878
|
Chris@40
|
879 /* Do 3 writes followed by reads. After each, check the data and the current
|
Chris@40
|
880 ** read and write offsets.
|
Chris@40
|
881 */
|
Chris@40
|
882 for (pass = 1 ; pass <= 3 ; pass ++)
|
Chris@40
|
883 { orig [20] = pass * 2 ;
|
Chris@40
|
884
|
Chris@40
|
885 /* Write some data. */
|
Chris@40
|
886 test_write_[+ (get "data_type") +]_or_die (file, pass, orig, DATA_LENGTH, __LINE__) ;
|
Chris@40
|
887
|
Chris@40
|
888 test_read_write_position_or_die (file, __LINE__, pass, (pass - 1) * DATA_LENGTH, pass * DATA_LENGTH) ;
|
Chris@40
|
889
|
Chris@40
|
890 /* Read what we just wrote. */
|
Chris@40
|
891 test_read_[+ (get "data_type") +]_or_die (file, 0, test, DATA_LENGTH, __LINE__) ;
|
Chris@40
|
892
|
Chris@40
|
893 /* Check the data. */
|
Chris@40
|
894 for (k = 0 ; k < DATA_LENGTH ; k++)
|
Chris@40
|
895 if ([+ (get "error_func") +] (orig [k], test [k]))
|
Chris@40
|
896 { printf ("\n\nLine %d (pass %d) A : Error at sample %d ([+ (get "format_char") +] => [+ (get "format_char") +]).\n", __LINE__, pass, k, orig [k], test [k]) ;
|
Chris@40
|
897 oct_save_[+ (get "data_type") +] (orig, test, DATA_LENGTH) ;
|
Chris@40
|
898 exit (1) ;
|
Chris@40
|
899 } ;
|
Chris@40
|
900
|
Chris@40
|
901 test_read_write_position_or_die (file, __LINE__, pass, pass * DATA_LENGTH, pass * DATA_LENGTH) ;
|
Chris@40
|
902 } ; /* for (pass ...) */
|
Chris@40
|
903
|
Chris@40
|
904 sf_close (file) ;
|
Chris@40
|
905
|
Chris@40
|
906 /* Open the file again to check the data. */
|
Chris@40
|
907 file = test_open_file_or_die (filename, SFM_RDWR, &sfinfo, allow_fd, __LINE__) ;
|
Chris@40
|
908
|
Chris@40
|
909 if (sfinfo.format != format)
|
Chris@40
|
910 { printf ("\n\nLine %d : Returned format incorrect (0x%08X => 0x%08X).\n", __LINE__, format, sfinfo.format) ;
|
Chris@40
|
911 exit (1) ;
|
Chris@40
|
912 } ;
|
Chris@40
|
913
|
Chris@40
|
914 if (sfinfo.frames < 3 * DATA_LENGTH)
|
Chris@40
|
915 { printf ("\n\nLine %d : Not enough frames in file. (%" PRId64 " < %d)\n", __LINE__, sfinfo.frames, 3 * DATA_LENGTH) ;
|
Chris@40
|
916 exit (1) ;
|
Chris@40
|
917 }
|
Chris@40
|
918
|
Chris@40
|
919 if (! long_file_ok && sfinfo.frames != 3 * DATA_LENGTH)
|
Chris@40
|
920 { printf ("\n\nLine %d : Incorrect number of frames in file. (%" PRId64 " should be %d)\n", __LINE__, sfinfo.frames, 3 * DATA_LENGTH) ;
|
Chris@40
|
921 exit (1) ;
|
Chris@40
|
922 } ;
|
Chris@40
|
923
|
Chris@40
|
924 if (sfinfo.channels != 1)
|
Chris@40
|
925 { printf ("\n\nLine %d : Incorrect number of channels in file.\n", __LINE__) ;
|
Chris@40
|
926 exit (1) ;
|
Chris@40
|
927 } ;
|
Chris@40
|
928
|
Chris@40
|
929 if (! long_file_ok)
|
Chris@40
|
930 test_read_write_position_or_die (file, __LINE__, 0, 0, 3 * DATA_LENGTH) ;
|
Chris@40
|
931 else
|
Chris@40
|
932 test_seek_or_die (file, 3 * DATA_LENGTH, SFM_WRITE | SEEK_SET, 3 * DATA_LENGTH, sfinfo.channels, __LINE__) ;
|
Chris@40
|
933
|
Chris@40
|
934 for (pass = 1 ; pass <= 3 ; pass ++)
|
Chris@40
|
935 { orig [20] = pass * 2 ;
|
Chris@40
|
936
|
Chris@40
|
937 test_read_write_position_or_die (file, __LINE__, pass, (pass - 1) * DATA_LENGTH, 3 * DATA_LENGTH) ;
|
Chris@40
|
938
|
Chris@40
|
939 /* Read what we just wrote. */
|
Chris@40
|
940 test_read_[+ (get "data_type") +]_or_die (file, pass, test, DATA_LENGTH, __LINE__) ;
|
Chris@40
|
941
|
Chris@40
|
942 /* Check the data. */
|
Chris@40
|
943 for (k = 0 ; k < DATA_LENGTH ; k++)
|
Chris@40
|
944 if ([+ (get "error_func") +] (orig [k], test [k]))
|
Chris@40
|
945 { printf ("\n\nLine %d (pass %d) B : Error at sample %d ([+ (get "format_char") +] => [+ (get "format_char") +]).\n", __LINE__, pass, k, orig [k], test [k]) ;
|
Chris@40
|
946 oct_save_[+ (get "data_type") +] (orig, test, DATA_LENGTH) ;
|
Chris@40
|
947 exit (1) ;
|
Chris@40
|
948 } ;
|
Chris@40
|
949
|
Chris@40
|
950 } ; /* for (pass ...) */
|
Chris@40
|
951
|
Chris@40
|
952 sf_close (file) ;
|
Chris@40
|
953 } /* mono_rdwr_[+ (get "data_type") +]_test */
|
Chris@40
|
954
|
Chris@40
|
955 static void
|
Chris@40
|
956 new_rdwr_[+ (get "type_name") +]_test (const char *filename, int format, int allow_fd)
|
Chris@40
|
957 { SNDFILE *wfile, *rwfile ;
|
Chris@40
|
958 SF_INFO sfinfo ;
|
Chris@40
|
959 [+ (get "data_type") +] *orig, *test ;
|
Chris@40
|
960 int items, frames ;
|
Chris@40
|
961
|
Chris@40
|
962 orig = orig_data.[+ (get "data_field") +] ;
|
Chris@40
|
963 test = test_data.[+ (get "data_field") +] ;
|
Chris@40
|
964
|
Chris@40
|
965 sfinfo.samplerate = 44100 ;
|
Chris@40
|
966 sfinfo.frames = SILLY_WRITE_COUNT ; /* Wrong length. Library should correct this on sf_close. */
|
Chris@40
|
967 sfinfo.channels = 2 ;
|
Chris@40
|
968 sfinfo.format = format ;
|
Chris@40
|
969
|
Chris@40
|
970 items = DATA_LENGTH ;
|
Chris@40
|
971 frames = items / sfinfo.channels ;
|
Chris@40
|
972
|
Chris@40
|
973 wfile = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, allow_fd, __LINE__) ;
|
Chris@40
|
974 sf_command (wfile, SFC_SET_UPDATE_HEADER_AUTO, NULL, SF_TRUE) ;
|
Chris@40
|
975 test_writef_[+ (get "data_type") +]_or_die (wfile, 1, orig, frames, __LINE__) ;
|
Chris@40
|
976 sf_write_sync (wfile) ;
|
Chris@40
|
977 test_writef_[+ (get "data_type") +]_or_die (wfile, 2, orig, frames, __LINE__) ;
|
Chris@40
|
978 sf_write_sync (wfile) ;
|
Chris@40
|
979
|
Chris@40
|
980 rwfile = test_open_file_or_die (filename, SFM_RDWR, &sfinfo, allow_fd, __LINE__) ;
|
Chris@40
|
981 if (sfinfo.frames != 2 * frames)
|
Chris@40
|
982 { printf ("\n\nLine %d : incorrect number of frames in file (%" PRId64 " should be %d)\n\n", __LINE__, sfinfo.frames, 2 * frames) ;
|
Chris@40
|
983 exit (1) ;
|
Chris@40
|
984 } ;
|
Chris@40
|
985
|
Chris@40
|
986 test_writef_[+ (get "data_type") +]_or_die (wfile, 3, orig, frames, __LINE__) ;
|
Chris@40
|
987
|
Chris@40
|
988 test_readf_[+ (get "data_type") +]_or_die (rwfile, 1, test, frames, __LINE__) ;
|
Chris@40
|
989 test_readf_[+ (get "data_type") +]_or_die (rwfile, 2, test, frames, __LINE__) ;
|
Chris@40
|
990
|
Chris@40
|
991 sf_close (wfile) ;
|
Chris@40
|
992 sf_close (rwfile) ;
|
Chris@40
|
993 } /* new_rdwr_[+ (get "type_name") +]_test */
|
Chris@40
|
994
|
Chris@40
|
995 [+ ENDFOR data_type +]
|
Chris@40
|
996
|
Chris@40
|
997 /*----------------------------------------------------------------------------------------
|
Chris@40
|
998 */
|
Chris@40
|
999
|
Chris@40
|
1000 static void
|
Chris@40
|
1001 empty_file_test (const char *filename, int format)
|
Chris@40
|
1002 { SNDFILE *file ;
|
Chris@40
|
1003 SF_INFO info ;
|
Chris@40
|
1004 int allow_fd ;
|
Chris@40
|
1005
|
Chris@40
|
1006 /* Sd2 files cannot be opened from an existing file descriptor. */
|
Chris@40
|
1007 allow_fd = ((format & SF_FORMAT_TYPEMASK) == SF_FORMAT_SD2) ? SF_FALSE : SF_TRUE ;
|
Chris@40
|
1008
|
Chris@40
|
1009 print_test_name ("empty_file_test", filename) ;
|
Chris@40
|
1010
|
Chris@40
|
1011 unlink (filename) ;
|
Chris@40
|
1012
|
Chris@40
|
1013 info.samplerate = 48000 ;
|
Chris@40
|
1014 info.channels = 2 ;
|
Chris@40
|
1015 info.format = format ;
|
Chris@40
|
1016 info.frames = 0 ;
|
Chris@40
|
1017
|
Chris@40
|
1018 if (sf_format_check (&info) == SF_FALSE)
|
Chris@40
|
1019 { info.channels = 1 ;
|
Chris@40
|
1020 if (sf_format_check (&info) == SF_FALSE)
|
Chris@40
|
1021 { puts ("invalid file format") ;
|
Chris@40
|
1022 return ;
|
Chris@40
|
1023 } ;
|
Chris@40
|
1024 } ;
|
Chris@40
|
1025
|
Chris@40
|
1026 /* Create an empty file. */
|
Chris@40
|
1027 file = test_open_file_or_die (filename, SFM_WRITE, &info, allow_fd, __LINE__) ;
|
Chris@40
|
1028 sf_close (file) ;
|
Chris@40
|
1029
|
Chris@40
|
1030 /* Open for read and check the length. */
|
Chris@40
|
1031 file = test_open_file_or_die (filename, SFM_READ, &info, allow_fd, __LINE__) ;
|
Chris@40
|
1032
|
Chris@40
|
1033 if (info.frames != 0)
|
Chris@40
|
1034 { printf ("\n\nError : frame count (%" PRId64 ") should be zero.\n", info.frames) ;
|
Chris@40
|
1035 exit (1) ;
|
Chris@40
|
1036 } ;
|
Chris@40
|
1037
|
Chris@40
|
1038 sf_close (file) ;
|
Chris@40
|
1039
|
Chris@40
|
1040 /* Open for read/write and check the length. */
|
Chris@40
|
1041 file = test_open_file_or_die (filename, SFM_RDWR, &info, allow_fd, __LINE__) ;
|
Chris@40
|
1042
|
Chris@40
|
1043 if (info.frames != 0)
|
Chris@40
|
1044 { printf ("\n\nError : frame count (%" PRId64 ") should be zero.\n", info.frames) ;
|
Chris@40
|
1045 exit (1) ;
|
Chris@40
|
1046 } ;
|
Chris@40
|
1047
|
Chris@40
|
1048 sf_close (file) ;
|
Chris@40
|
1049
|
Chris@40
|
1050 /* Open for read and check the length. */
|
Chris@40
|
1051 file = test_open_file_or_die (filename, SFM_READ, &info, allow_fd, __LINE__) ;
|
Chris@40
|
1052
|
Chris@40
|
1053 if (info.frames != 0)
|
Chris@40
|
1054 { printf ("\n\nError : frame count (%" PRId64 ") should be zero.\n", info.frames) ;
|
Chris@40
|
1055 exit (1) ;
|
Chris@40
|
1056 } ;
|
Chris@40
|
1057
|
Chris@40
|
1058 sf_close (file) ;
|
Chris@40
|
1059
|
Chris@40
|
1060 check_open_file_count_or_die (__LINE__) ;
|
Chris@40
|
1061
|
Chris@40
|
1062 unlink (filename) ;
|
Chris@40
|
1063 puts ("ok") ;
|
Chris@40
|
1064
|
Chris@40
|
1065 return ;
|
Chris@40
|
1066 } /* empty_file_test */
|
Chris@40
|
1067
|
Chris@40
|
1068
|
Chris@40
|
1069 /*----------------------------------------------------------------------------------------
|
Chris@40
|
1070 */
|
Chris@40
|
1071
|
Chris@40
|
1072 static void
|
Chris@40
|
1073 create_short_file (const char *filename)
|
Chris@40
|
1074 { FILE *file ;
|
Chris@40
|
1075
|
Chris@40
|
1076 if (! (file = fopen (filename, "w")))
|
Chris@40
|
1077 { printf ("create_short_file : fopen (%s, \"w\") failed.", filename) ;
|
Chris@40
|
1078 fflush (stdout) ;
|
Chris@40
|
1079 perror (NULL) ;
|
Chris@40
|
1080 exit (1) ;
|
Chris@40
|
1081 } ;
|
Chris@40
|
1082
|
Chris@40
|
1083 fprintf (file, "This is the file data.\n") ;
|
Chris@40
|
1084
|
Chris@40
|
1085 fclose (file) ;
|
Chris@40
|
1086 } /* create_short_file */
|
Chris@40
|
1087
|
Chris@40
|
1088
|
Chris@40
|
1089 static void
|
Chris@40
|
1090 multi_seek_test (const char * filename, int format)
|
Chris@40
|
1091 { SNDFILE * file ;
|
Chris@40
|
1092 SF_INFO info ;
|
Chris@40
|
1093 sf_count_t pos ;
|
Chris@40
|
1094 int k ;
|
Chris@40
|
1095
|
Chris@40
|
1096 /* This test doesn't work on the following. */
|
Chris@40
|
1097 switch (format & SF_FORMAT_TYPEMASK)
|
Chris@40
|
1098 { case SF_FORMAT_RAW :
|
Chris@40
|
1099 return ;
|
Chris@40
|
1100
|
Chris@40
|
1101 default :
|
Chris@40
|
1102 break ;
|
Chris@40
|
1103 } ;
|
Chris@40
|
1104
|
Chris@40
|
1105 memset (&info, 0, sizeof (info)) ;
|
Chris@40
|
1106
|
Chris@40
|
1107 generate_file (filename, format, 88200) ;
|
Chris@40
|
1108
|
Chris@40
|
1109 file = test_open_file_or_die (filename, SFM_READ, &info, SF_FALSE, __LINE__) ;
|
Chris@40
|
1110
|
Chris@40
|
1111 for (k = 0 ; k < 10 ; k++)
|
Chris@40
|
1112 { pos = info.frames / (k + 2) ;
|
Chris@40
|
1113 test_seek_or_die (file, pos, SEEK_SET, pos, info.channels, __LINE__) ;
|
Chris@40
|
1114 } ;
|
Chris@40
|
1115
|
Chris@40
|
1116 sf_close (file) ;
|
Chris@40
|
1117 } /* multi_seek_test */
|
Chris@40
|
1118
|
Chris@40
|
1119 static void
|
Chris@40
|
1120 write_seek_extend_test (const char * filename, int format)
|
Chris@40
|
1121 { SNDFILE * file ;
|
Chris@40
|
1122 SF_INFO info ;
|
Chris@40
|
1123 short *orig, *test ;
|
Chris@40
|
1124 unsigned items, k ;
|
Chris@40
|
1125
|
Chris@40
|
1126 /* This test doesn't work on the following container formats. */
|
Chris@40
|
1127 switch (format & SF_FORMAT_TYPEMASK)
|
Chris@40
|
1128 { case SF_FORMAT_FLAC :
|
Chris@40
|
1129 case SF_FORMAT_HTK :
|
Chris@40
|
1130 case SF_FORMAT_PAF :
|
Chris@40
|
1131 case SF_FORMAT_SDS :
|
Chris@40
|
1132 case SF_FORMAT_SVX :
|
Chris@40
|
1133 return ;
|
Chris@40
|
1134
|
Chris@40
|
1135 default :
|
Chris@40
|
1136 break ;
|
Chris@40
|
1137 } ;
|
Chris@40
|
1138
|
Chris@40
|
1139 /* This test doesn't work on the following codec formats. */
|
Chris@40
|
1140 switch (format & SF_FORMAT_SUBMASK)
|
Chris@40
|
1141 { case SF_FORMAT_ALAC_16 :
|
Chris@40
|
1142 case SF_FORMAT_ALAC_20 :
|
Chris@40
|
1143 case SF_FORMAT_ALAC_24 :
|
Chris@40
|
1144 case SF_FORMAT_ALAC_32 :
|
Chris@40
|
1145 return ;
|
Chris@40
|
1146
|
Chris@40
|
1147 default :
|
Chris@40
|
1148 break ;
|
Chris@40
|
1149 } ;
|
Chris@40
|
1150
|
Chris@40
|
1151 memset (&info, 0, sizeof (info)) ;
|
Chris@40
|
1152
|
Chris@40
|
1153 info.samplerate = 48000 ;
|
Chris@40
|
1154 info.channels = 1 ;
|
Chris@40
|
1155 info.format = format ;
|
Chris@40
|
1156
|
Chris@40
|
1157 items = 512 ;
|
Chris@40
|
1158 exit_if_true (items > ARRAY_LEN (orig_data.s), "Line %d : Bad assumption.\n", __LINE__) ;
|
Chris@40
|
1159
|
Chris@40
|
1160 orig = orig_data.s ;
|
Chris@40
|
1161 test = test_data.s ;
|
Chris@40
|
1162
|
Chris@40
|
1163 for (k = 0 ; k < ARRAY_LEN (orig_data.s) ; k++)
|
Chris@40
|
1164 orig [k] = 0x3fff ;
|
Chris@40
|
1165
|
Chris@40
|
1166 file = test_open_file_or_die (filename, SFM_WRITE, &info, SF_FALSE, __LINE__) ;
|
Chris@40
|
1167 test_write_short_or_die (file, 0, orig, items, __LINE__) ;
|
Chris@40
|
1168
|
Chris@40
|
1169 /* Extend the file using a seek. */
|
Chris@40
|
1170 test_seek_or_die (file, 2 * items, SEEK_SET, 2 * items, info.channels, __LINE__) ;
|
Chris@40
|
1171
|
Chris@40
|
1172 test_writef_short_or_die (file, 0, orig, items, __LINE__) ;
|
Chris@40
|
1173 sf_close (file) ;
|
Chris@40
|
1174
|
Chris@40
|
1175 file = test_open_file_or_die (filename, SFM_READ, &info, SF_FALSE, __LINE__) ;
|
Chris@40
|
1176 test_read_short_or_die (file, 0, test, 3 * items, __LINE__) ;
|
Chris@40
|
1177 sf_close (file) ;
|
Chris@40
|
1178
|
Chris@40
|
1179 /* Can't do these formats due to scaling. */
|
Chris@40
|
1180 switch (format & SF_FORMAT_SUBMASK)
|
Chris@40
|
1181 { case SF_FORMAT_PCM_S8 :
|
Chris@40
|
1182 case SF_FORMAT_PCM_U8 :
|
Chris@40
|
1183 return ;
|
Chris@40
|
1184 default :
|
Chris@40
|
1185 break ;
|
Chris@40
|
1186 } ;
|
Chris@40
|
1187
|
Chris@40
|
1188 for (k = 0 ; k < items ; k++)
|
Chris@40
|
1189 { exit_if_true (test [k] != 0x3fff, "Line %d : test [%d] == %d, should be 0x3fff.\n", __LINE__, k, test [k]) ;
|
Chris@40
|
1190 exit_if_true (test [items + k] != 0, "Line %d : test [%d] == %d, should be 0.\n", __LINE__, items + k, test [items + k]) ;
|
Chris@40
|
1191 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]) ;
|
Chris@40
|
1192 } ;
|
Chris@40
|
1193
|
Chris@40
|
1194 return ;
|
Chris@40
|
1195 } /* write_seek_extend_test */
|
Chris@40
|
1196
|
Chris@40
|
1197
|