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