Chris@0
|
1 /*
|
Chris@0
|
2 ** Copyright (C) 1999-2011 Erik de Castro Lopo <erikd@mega-nerd.com>
|
Chris@0
|
3 **
|
Chris@0
|
4 ** This program is free software; you can redistribute it and/or modify
|
Chris@0
|
5 ** it under the terms of the GNU General Public License as published by
|
Chris@0
|
6 ** the Free Software Foundation; either version 2 of the License, or
|
Chris@0
|
7 ** (at your option) any later version.
|
Chris@0
|
8 **
|
Chris@0
|
9 ** This program is distributed in the hope that it will be useful,
|
Chris@0
|
10 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
Chris@0
|
11 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
Chris@0
|
12 ** GNU General Public License for more details.
|
Chris@0
|
13 **
|
Chris@0
|
14 ** You should have received a copy of the GNU General Public License
|
Chris@0
|
15 ** along with this program; if not, write to the Free Software
|
Chris@0
|
16 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
Chris@0
|
17 */
|
Chris@0
|
18
|
Chris@0
|
19 #include "sfconfig.h"
|
Chris@0
|
20
|
Chris@0
|
21 #include <stdio.h>
|
Chris@0
|
22 #include <stdlib.h>
|
Chris@0
|
23 #include <string.h>
|
Chris@0
|
24
|
Chris@0
|
25 #if HAVE_UNISTD_H
|
Chris@0
|
26 #include <unistd.h>
|
Chris@0
|
27 #endif
|
Chris@0
|
28
|
Chris@0
|
29 #include <math.h>
|
Chris@0
|
30
|
Chris@0
|
31 #if (defined (WIN32) || defined (_WIN32))
|
Chris@0
|
32 #include <fcntl.h>
|
Chris@0
|
33 static int truncate (const char *filename, int ignored) ;
|
Chris@0
|
34 #endif
|
Chris@0
|
35
|
Chris@0
|
36 #include <sndfile.h>
|
Chris@0
|
37
|
Chris@0
|
38 #include "utils.h"
|
Chris@0
|
39 #include "generate.h"
|
Chris@0
|
40
|
Chris@0
|
41 #define SAMPLE_RATE 11025
|
Chris@0
|
42 #define DATA_LENGTH (1<<12)
|
Chris@0
|
43
|
Chris@0
|
44 #define SILLY_WRITE_COUNT (234)
|
Chris@0
|
45
|
Chris@0
|
46 static void pcm_test_char (const char *str, int format, int long_file_okz) ;
|
Chris@0
|
47 static void pcm_test_short (const char *str, int format, int long_file_okz) ;
|
Chris@0
|
48 static void pcm_test_24bit (const char *str, int format, int long_file_okz) ;
|
Chris@0
|
49 static void pcm_test_int (const char *str, int format, int long_file_okz) ;
|
Chris@0
|
50 static void pcm_test_float (const char *str, int format, int long_file_okz) ;
|
Chris@0
|
51 static void pcm_test_double (const char *str, int format, int long_file_okz) ;
|
Chris@0
|
52
|
Chris@0
|
53 static void empty_file_test (const char *filename, int format) ;
|
Chris@0
|
54
|
Chris@0
|
55 typedef union
|
Chris@0
|
56 { double d [DATA_LENGTH] ;
|
Chris@0
|
57 float f [DATA_LENGTH] ;
|
Chris@0
|
58 int i [DATA_LENGTH] ;
|
Chris@0
|
59 short s [DATA_LENGTH] ;
|
Chris@0
|
60 char c [DATA_LENGTH] ;
|
Chris@0
|
61 } BUFFER ;
|
Chris@0
|
62
|
Chris@0
|
63 static BUFFER orig_data ;
|
Chris@0
|
64 static BUFFER test_data ;
|
Chris@0
|
65
|
Chris@0
|
66 int
|
Chris@0
|
67 main (int argc, char **argv)
|
Chris@0
|
68 { int do_all = 0 ;
|
Chris@0
|
69 int test_count = 0 ;
|
Chris@0
|
70
|
Chris@0
|
71 count_open_files () ;
|
Chris@0
|
72
|
Chris@0
|
73 if (argc != 2)
|
Chris@0
|
74 { printf ("Usage : %s <test>\n", argv [0]) ;
|
Chris@0
|
75 printf (" Where <test> is one of the following:\n") ;
|
Chris@0
|
76 printf (" wav - test WAV file functions (little endian)\n") ;
|
Chris@0
|
77 printf (" aiff - test AIFF file functions (big endian)\n") ;
|
Chris@0
|
78 printf (" au - test AU file functions\n") ;
|
Chris@0
|
79 printf (" avr - test AVR file functions\n") ;
|
Chris@0
|
80 printf (" caf - test CAF file functions\n") ;
|
Chris@0
|
81 printf (" raw - test RAW header-less PCM file functions\n") ;
|
Chris@0
|
82 printf (" paf - test PAF file functions\n") ;
|
Chris@0
|
83 printf (" svx - test 8SVX/16SV file functions\n") ;
|
Chris@0
|
84 printf (" nist - test NIST Sphere file functions\n") ;
|
Chris@0
|
85 printf (" ircam - test IRCAM file functions\n") ;
|
Chris@0
|
86 printf (" voc - Create Voice file functions\n") ;
|
Chris@0
|
87 printf (" w64 - Sonic Foundry's W64 file functions\n") ;
|
Chris@0
|
88 printf (" flac - test FLAC file functions\n") ;
|
Chris@0
|
89 printf (" mpc2k - test MPC 2000 file functions\n") ;
|
Chris@0
|
90 printf (" rf64 - test RF64 file functions\n") ;
|
Chris@0
|
91 printf (" all - perform all tests\n") ;
|
Chris@0
|
92 exit (1) ;
|
Chris@0
|
93 } ;
|
Chris@0
|
94
|
Chris@0
|
95 do_all = !strcmp (argv [1], "all") ;
|
Chris@0
|
96
|
Chris@0
|
97 if (do_all || ! strcmp (argv [1], "wav"))
|
Chris@0
|
98 { pcm_test_char ("char.wav" , SF_FORMAT_WAV | SF_FORMAT_PCM_U8, SF_FALSE) ;
|
Chris@0
|
99 pcm_test_short ("short.wav" , SF_FORMAT_WAV | SF_FORMAT_PCM_16, SF_FALSE) ;
|
Chris@0
|
100 pcm_test_24bit ("24bit.wav" , SF_FORMAT_WAV | SF_FORMAT_PCM_24, SF_FALSE) ;
|
Chris@0
|
101 pcm_test_int ("int.wav" , SF_FORMAT_WAV | SF_FORMAT_PCM_32, SF_FALSE) ;
|
Chris@0
|
102
|
Chris@0
|
103 pcm_test_char ("char.rifx" , SF_ENDIAN_BIG | SF_FORMAT_WAV | SF_FORMAT_PCM_U8, SF_FALSE) ;
|
Chris@0
|
104 pcm_test_short ("short.rifx" , SF_ENDIAN_BIG | SF_FORMAT_WAV | SF_FORMAT_PCM_16, SF_FALSE) ;
|
Chris@0
|
105 pcm_test_24bit ("24bit.rifx" , SF_ENDIAN_BIG | SF_FORMAT_WAV | SF_FORMAT_PCM_24, SF_FALSE) ;
|
Chris@0
|
106 pcm_test_int ("int.rifx" , SF_ENDIAN_BIG | SF_FORMAT_WAV | SF_FORMAT_PCM_32, SF_FALSE) ;
|
Chris@0
|
107
|
Chris@0
|
108 pcm_test_24bit ("24bit.wavex" , SF_FORMAT_WAVEX | SF_FORMAT_PCM_24, SF_FALSE) ;
|
Chris@0
|
109 pcm_test_int ("int.wavex" , SF_FORMAT_WAVEX | SF_FORMAT_PCM_32, SF_FALSE) ;
|
Chris@0
|
110
|
Chris@0
|
111 /* Lite remove start */
|
Chris@0
|
112 pcm_test_float ("float.wav" , SF_FORMAT_WAV | SF_FORMAT_FLOAT , SF_FALSE) ;
|
Chris@0
|
113 pcm_test_double ("double.wav" , SF_FORMAT_WAV | SF_FORMAT_DOUBLE, SF_FALSE) ;
|
Chris@0
|
114
|
Chris@0
|
115 pcm_test_float ("float.rifx" , SF_ENDIAN_BIG | SF_FORMAT_WAV | SF_FORMAT_FLOAT , SF_FALSE) ;
|
Chris@0
|
116 pcm_test_double ("double.rifx" , SF_ENDIAN_BIG | SF_FORMAT_WAV | SF_FORMAT_DOUBLE, SF_FALSE) ;
|
Chris@0
|
117
|
Chris@0
|
118 pcm_test_float ("float.wavex" , SF_FORMAT_WAVEX | SF_FORMAT_FLOAT , SF_FALSE) ;
|
Chris@0
|
119 pcm_test_double ("double.wavex" , SF_FORMAT_WAVEX | SF_FORMAT_DOUBLE, SF_FALSE) ;
|
Chris@0
|
120 /* Lite remove end */
|
Chris@0
|
121
|
Chris@0
|
122 empty_file_test ("empty_char.wav", SF_FORMAT_WAV | SF_FORMAT_PCM_U8) ;
|
Chris@0
|
123 empty_file_test ("empty_short.wav", SF_FORMAT_WAV | SF_FORMAT_PCM_16) ;
|
Chris@0
|
124 empty_file_test ("empty_float.wav", SF_FORMAT_WAV | SF_FORMAT_FLOAT) ;
|
Chris@0
|
125
|
Chris@0
|
126 test_count++ ;
|
Chris@0
|
127 } ;
|
Chris@0
|
128
|
Chris@0
|
129 if (do_all || ! strcmp (argv [1], "aiff"))
|
Chris@0
|
130 { pcm_test_char ("char_u8.aiff" , SF_FORMAT_AIFF | SF_FORMAT_PCM_U8, SF_FALSE) ;
|
Chris@0
|
131 pcm_test_char ("char_s8.aiff" , SF_FORMAT_AIFF | SF_FORMAT_PCM_S8, SF_FALSE) ;
|
Chris@0
|
132 pcm_test_short ("short.aiff" , SF_FORMAT_AIFF | SF_FORMAT_PCM_16, SF_FALSE) ;
|
Chris@0
|
133 pcm_test_24bit ("24bit.aiff" , SF_FORMAT_AIFF | SF_FORMAT_PCM_24, SF_FALSE) ;
|
Chris@0
|
134 pcm_test_int ("int.aiff" , SF_FORMAT_AIFF | SF_FORMAT_PCM_32, SF_FALSE) ;
|
Chris@0
|
135
|
Chris@0
|
136 pcm_test_short ("short_sowt.aifc" , SF_ENDIAN_LITTLE | SF_FORMAT_AIFF | SF_FORMAT_PCM_16, SF_FALSE) ;
|
Chris@0
|
137 pcm_test_24bit ("24bit_sowt.aifc" , SF_ENDIAN_LITTLE | SF_FORMAT_AIFF | SF_FORMAT_PCM_24, SF_FALSE) ;
|
Chris@0
|
138 pcm_test_int ("int_sowt.aifc" , SF_ENDIAN_LITTLE | SF_FORMAT_AIFF | SF_FORMAT_PCM_32, SF_FALSE) ;
|
Chris@0
|
139
|
Chris@0
|
140 pcm_test_short ("short_twos.aifc" , SF_ENDIAN_BIG | SF_FORMAT_AIFF | SF_FORMAT_PCM_16, SF_FALSE) ;
|
Chris@0
|
141 pcm_test_24bit ("24bit_twos.aifc" , SF_ENDIAN_BIG | SF_FORMAT_AIFF | SF_FORMAT_PCM_24, SF_FALSE) ;
|
Chris@0
|
142 pcm_test_int ("int_twos.aifc" , SF_ENDIAN_BIG | SF_FORMAT_AIFF | SF_FORMAT_PCM_32, SF_FALSE) ;
|
Chris@0
|
143
|
Chris@0
|
144 /* Lite remove start */
|
Chris@0
|
145 pcm_test_short ("dwvw16.aifc", SF_FORMAT_AIFF | SF_FORMAT_DWVW_16, SF_TRUE) ;
|
Chris@0
|
146 pcm_test_24bit ("dwvw24.aifc", SF_FORMAT_AIFF | SF_FORMAT_DWVW_24, SF_TRUE) ;
|
Chris@0
|
147
|
Chris@0
|
148 pcm_test_float ("float.aifc" , SF_FORMAT_AIFF | SF_FORMAT_FLOAT , SF_FALSE) ;
|
Chris@0
|
149 pcm_test_double ("double.aifc" , SF_FORMAT_AIFF | SF_FORMAT_DOUBLE, SF_FALSE) ;
|
Chris@0
|
150 /* Lite remove end */
|
Chris@0
|
151
|
Chris@0
|
152 empty_file_test ("empty_char.aiff", SF_FORMAT_AIFF | SF_FORMAT_PCM_U8) ;
|
Chris@0
|
153 empty_file_test ("empty_short.aiff", SF_FORMAT_AIFF | SF_FORMAT_PCM_16) ;
|
Chris@0
|
154 empty_file_test ("empty_float.aiff", SF_FORMAT_AIFF | SF_FORMAT_FLOAT) ;
|
Chris@0
|
155
|
Chris@0
|
156 test_count++ ;
|
Chris@0
|
157 } ;
|
Chris@0
|
158
|
Chris@0
|
159 if (do_all || ! strcmp (argv [1], "au"))
|
Chris@0
|
160 { pcm_test_char ("char.au" , SF_FORMAT_AU | SF_FORMAT_PCM_S8, SF_FALSE) ;
|
Chris@0
|
161 pcm_test_short ("short.au" , SF_FORMAT_AU | SF_FORMAT_PCM_16, SF_FALSE) ;
|
Chris@0
|
162 pcm_test_24bit ("24bit.au" , SF_FORMAT_AU | SF_FORMAT_PCM_24, SF_FALSE) ;
|
Chris@0
|
163 pcm_test_int ("int.au" , SF_FORMAT_AU | SF_FORMAT_PCM_32, SF_FALSE) ;
|
Chris@0
|
164 /* Lite remove start */
|
Chris@0
|
165 pcm_test_float ("float.au" , SF_FORMAT_AU | SF_FORMAT_FLOAT , SF_FALSE) ;
|
Chris@0
|
166 pcm_test_double ("double.au", SF_FORMAT_AU | SF_FORMAT_DOUBLE, SF_FALSE) ;
|
Chris@0
|
167 /* Lite remove end */
|
Chris@0
|
168
|
Chris@0
|
169 pcm_test_char ("char_le.au" , SF_ENDIAN_LITTLE | SF_FORMAT_AU | SF_FORMAT_PCM_S8, SF_FALSE) ;
|
Chris@0
|
170 pcm_test_short ("short_le.au" , SF_ENDIAN_LITTLE | SF_FORMAT_AU | SF_FORMAT_PCM_16, SF_FALSE) ;
|
Chris@0
|
171 pcm_test_24bit ("24bit_le.au" , SF_ENDIAN_LITTLE | SF_FORMAT_AU | SF_FORMAT_PCM_24, SF_FALSE) ;
|
Chris@0
|
172 pcm_test_int ("int_le.au" , SF_ENDIAN_LITTLE | SF_FORMAT_AU | SF_FORMAT_PCM_32, SF_FALSE) ;
|
Chris@0
|
173 /* Lite remove start */
|
Chris@0
|
174 pcm_test_float ("float_le.au" , SF_ENDIAN_LITTLE | SF_FORMAT_AU | SF_FORMAT_FLOAT , SF_FALSE) ;
|
Chris@0
|
175 pcm_test_double ("double_le.au" , SF_ENDIAN_LITTLE | SF_FORMAT_AU | SF_FORMAT_DOUBLE, SF_FALSE) ;
|
Chris@0
|
176 /* Lite remove end */
|
Chris@0
|
177 test_count++ ;
|
Chris@0
|
178 } ;
|
Chris@0
|
179
|
Chris@0
|
180 if (do_all || ! strcmp (argv [1], "caf"))
|
Chris@0
|
181 { pcm_test_char ("char.caf" , SF_FORMAT_CAF | SF_FORMAT_PCM_S8, SF_FALSE) ;
|
Chris@0
|
182 pcm_test_short ("short.caf" , SF_FORMAT_CAF | SF_FORMAT_PCM_16, SF_FALSE) ;
|
Chris@0
|
183 pcm_test_24bit ("24bit.caf" , SF_FORMAT_CAF | SF_FORMAT_PCM_24, SF_FALSE) ;
|
Chris@0
|
184 pcm_test_int ("int.caf" , SF_FORMAT_CAF | SF_FORMAT_PCM_32, SF_FALSE) ;
|
Chris@0
|
185 /* Lite remove start */
|
Chris@0
|
186 pcm_test_float ("float.caf" , SF_FORMAT_CAF | SF_FORMAT_FLOAT , SF_FALSE) ;
|
Chris@0
|
187 pcm_test_double ("double.caf" , SF_FORMAT_CAF | SF_FORMAT_DOUBLE, SF_FALSE) ;
|
Chris@0
|
188 /* Lite remove end */
|
Chris@0
|
189
|
Chris@0
|
190 pcm_test_short ("short_le.caf" , SF_ENDIAN_LITTLE | SF_FORMAT_CAF | SF_FORMAT_PCM_16, SF_FALSE) ;
|
Chris@0
|
191 pcm_test_24bit ("24bit_le.caf" , SF_ENDIAN_LITTLE | SF_FORMAT_CAF | SF_FORMAT_PCM_24, SF_FALSE) ;
|
Chris@0
|
192 pcm_test_int ("int_le.caf" , SF_ENDIAN_LITTLE | SF_FORMAT_CAF | SF_FORMAT_PCM_32, SF_FALSE) ;
|
Chris@0
|
193 /* Lite remove start */
|
Chris@0
|
194 pcm_test_float ("float_le.caf" , SF_ENDIAN_LITTLE | SF_FORMAT_CAF | SF_FORMAT_FLOAT , SF_FALSE) ;
|
Chris@0
|
195 pcm_test_double ("double_le.caf", SF_ENDIAN_LITTLE | SF_FORMAT_CAF | SF_FORMAT_DOUBLE, SF_FALSE) ;
|
Chris@0
|
196 /* Lite remove end */
|
Chris@0
|
197 test_count++ ;
|
Chris@0
|
198 } ;
|
Chris@0
|
199
|
Chris@0
|
200 if (do_all || ! strcmp (argv [1], "raw"))
|
Chris@0
|
201 { pcm_test_char ("char_s8.raw" , SF_FORMAT_RAW | SF_FORMAT_PCM_S8, SF_FALSE) ;
|
Chris@0
|
202 pcm_test_char ("char_u8.raw" , SF_FORMAT_RAW | SF_FORMAT_PCM_U8, SF_FALSE) ;
|
Chris@0
|
203
|
Chris@0
|
204 pcm_test_short ("short_le.raw" , SF_ENDIAN_LITTLE | SF_FORMAT_RAW | SF_FORMAT_PCM_16, SF_FALSE) ;
|
Chris@0
|
205 pcm_test_short ("short_be.raw" , SF_ENDIAN_BIG | SF_FORMAT_RAW | SF_FORMAT_PCM_16, SF_FALSE) ;
|
Chris@0
|
206 pcm_test_24bit ("24bit_le.raw" , SF_ENDIAN_LITTLE | SF_FORMAT_RAW | SF_FORMAT_PCM_24, SF_FALSE) ;
|
Chris@0
|
207 pcm_test_24bit ("24bit_be.raw" , SF_ENDIAN_BIG | SF_FORMAT_RAW | SF_FORMAT_PCM_24, SF_FALSE) ;
|
Chris@0
|
208 pcm_test_int ("int_le.raw" , SF_ENDIAN_LITTLE | SF_FORMAT_RAW | SF_FORMAT_PCM_32, SF_FALSE) ;
|
Chris@0
|
209 pcm_test_int ("int_be.raw" , SF_ENDIAN_BIG | SF_FORMAT_RAW | SF_FORMAT_PCM_32, SF_FALSE) ;
|
Chris@0
|
210
|
Chris@0
|
211 /* Lite remove start */
|
Chris@0
|
212 pcm_test_float ("float_le.raw" , SF_ENDIAN_LITTLE | SF_FORMAT_RAW | SF_FORMAT_FLOAT , SF_FALSE) ;
|
Chris@0
|
213 pcm_test_float ("float_be.raw" , SF_ENDIAN_BIG | SF_FORMAT_RAW | SF_FORMAT_FLOAT , SF_FALSE) ;
|
Chris@0
|
214
|
Chris@0
|
215 pcm_test_double ("double_le.raw", SF_ENDIAN_LITTLE | SF_FORMAT_RAW | SF_FORMAT_DOUBLE, SF_FALSE) ;
|
Chris@0
|
216 pcm_test_double ("double_be.raw", SF_ENDIAN_BIG | SF_FORMAT_RAW | SF_FORMAT_DOUBLE, SF_FALSE) ;
|
Chris@0
|
217 /* Lite remove end */
|
Chris@0
|
218 test_count++ ;
|
Chris@0
|
219 } ;
|
Chris@0
|
220
|
Chris@0
|
221 /* Lite remove start */
|
Chris@0
|
222 if (do_all || ! strcmp (argv [1], "paf"))
|
Chris@0
|
223 { pcm_test_char ("char_le.paf", SF_ENDIAN_LITTLE | SF_FORMAT_PAF | SF_FORMAT_PCM_S8, SF_FALSE) ;
|
Chris@0
|
224 pcm_test_char ("char_be.paf", SF_ENDIAN_BIG | SF_FORMAT_PAF | SF_FORMAT_PCM_S8, SF_FALSE) ;
|
Chris@0
|
225 pcm_test_short ("short_le.paf", SF_ENDIAN_LITTLE | SF_FORMAT_PAF | SF_FORMAT_PCM_16, SF_FALSE) ;
|
Chris@0
|
226 pcm_test_short ("short_be.paf", SF_ENDIAN_BIG | SF_FORMAT_PAF | SF_FORMAT_PCM_16, SF_FALSE) ;
|
Chris@0
|
227 pcm_test_24bit ("24bit_le.paf", SF_ENDIAN_LITTLE | SF_FORMAT_PAF | SF_FORMAT_PCM_24, SF_TRUE) ;
|
Chris@0
|
228 pcm_test_24bit ("24bit_be.paf", SF_ENDIAN_BIG | SF_FORMAT_PAF | SF_FORMAT_PCM_24, SF_TRUE) ;
|
Chris@0
|
229 test_count++ ;
|
Chris@0
|
230 } ;
|
Chris@0
|
231
|
Chris@0
|
232 if (do_all || ! strcmp (argv [1], "svx"))
|
Chris@0
|
233 { pcm_test_char ("char.svx" , SF_FORMAT_SVX | SF_FORMAT_PCM_S8, SF_FALSE) ;
|
Chris@0
|
234 pcm_test_short ("short.svx", SF_FORMAT_SVX | SF_FORMAT_PCM_16, SF_FALSE) ;
|
Chris@0
|
235
|
Chris@0
|
236 empty_file_test ("empty_char.svx", SF_FORMAT_SVX | SF_FORMAT_PCM_S8) ;
|
Chris@0
|
237 empty_file_test ("empty_short.svx", SF_FORMAT_SVX | SF_FORMAT_PCM_16) ;
|
Chris@0
|
238
|
Chris@0
|
239 test_count++ ;
|
Chris@0
|
240 } ;
|
Chris@0
|
241
|
Chris@0
|
242 if (do_all || ! strcmp (argv [1], "nist"))
|
Chris@0
|
243 { pcm_test_short ("short_le.nist", SF_ENDIAN_LITTLE | SF_FORMAT_NIST | SF_FORMAT_PCM_16, SF_FALSE) ;
|
Chris@0
|
244 pcm_test_short ("short_be.nist", SF_ENDIAN_BIG | SF_FORMAT_NIST | SF_FORMAT_PCM_16, SF_FALSE) ;
|
Chris@0
|
245 pcm_test_24bit ("24bit_le.nist", SF_ENDIAN_LITTLE | SF_FORMAT_NIST | SF_FORMAT_PCM_24, SF_FALSE) ;
|
Chris@0
|
246 pcm_test_24bit ("24bit_be.nist", SF_ENDIAN_BIG | SF_FORMAT_NIST | SF_FORMAT_PCM_24, SF_FALSE) ;
|
Chris@0
|
247 pcm_test_int ("int_le.nist" , SF_ENDIAN_LITTLE | SF_FORMAT_NIST | SF_FORMAT_PCM_32, SF_FALSE) ;
|
Chris@0
|
248 pcm_test_int ("int_be.nist" , SF_ENDIAN_BIG | SF_FORMAT_NIST | SF_FORMAT_PCM_32, SF_FALSE) ;
|
Chris@0
|
249
|
Chris@0
|
250 test_count++ ;
|
Chris@0
|
251 } ;
|
Chris@0
|
252
|
Chris@0
|
253 if (do_all || ! strcmp (argv [1], "ircam"))
|
Chris@0
|
254 { pcm_test_short ("short_be.ircam" , SF_ENDIAN_BIG | SF_FORMAT_IRCAM | SF_FORMAT_PCM_16, SF_FALSE) ;
|
Chris@0
|
255 pcm_test_short ("short_le.ircam" , SF_ENDIAN_LITTLE | SF_FORMAT_IRCAM | SF_FORMAT_PCM_16, SF_FALSE) ;
|
Chris@0
|
256 pcm_test_int ("int_be.ircam" , SF_ENDIAN_BIG | SF_FORMAT_IRCAM | SF_FORMAT_PCM_32, SF_FALSE) ;
|
Chris@0
|
257 pcm_test_int ("int_le.ircam" , SF_ENDIAN_LITTLE | SF_FORMAT_IRCAM | SF_FORMAT_PCM_32, SF_FALSE) ;
|
Chris@0
|
258 pcm_test_float ("float_be.ircam" , SF_ENDIAN_BIG | SF_FORMAT_IRCAM | SF_FORMAT_FLOAT , SF_FALSE) ;
|
Chris@0
|
259 pcm_test_float ("float_le.ircam" , SF_ENDIAN_LITTLE | SF_FORMAT_IRCAM | SF_FORMAT_FLOAT , SF_FALSE) ;
|
Chris@0
|
260
|
Chris@0
|
261 test_count++ ;
|
Chris@0
|
262 } ;
|
Chris@0
|
263
|
Chris@0
|
264 if (do_all || ! strcmp (argv [1], "voc"))
|
Chris@0
|
265 { pcm_test_char ("char.voc" , SF_FORMAT_VOC | SF_FORMAT_PCM_U8, SF_FALSE) ;
|
Chris@0
|
266 pcm_test_short ("short.voc", SF_FORMAT_VOC | SF_FORMAT_PCM_16, SF_FALSE) ;
|
Chris@0
|
267
|
Chris@0
|
268 test_count++ ;
|
Chris@0
|
269 } ;
|
Chris@0
|
270
|
Chris@0
|
271 if (do_all || ! strcmp (argv [1], "mat4"))
|
Chris@0
|
272 { pcm_test_short ("short_be.mat4" , SF_ENDIAN_BIG | SF_FORMAT_MAT4 | SF_FORMAT_PCM_16, SF_FALSE) ;
|
Chris@0
|
273 pcm_test_short ("short_le.mat4" , SF_ENDIAN_LITTLE | SF_FORMAT_MAT4 | SF_FORMAT_PCM_16, SF_FALSE) ;
|
Chris@0
|
274 pcm_test_int ("int_be.mat4" , SF_ENDIAN_BIG | SF_FORMAT_MAT4 | SF_FORMAT_PCM_32, SF_FALSE) ;
|
Chris@0
|
275 pcm_test_int ("int_le.mat4" , SF_ENDIAN_LITTLE | SF_FORMAT_MAT4 | SF_FORMAT_PCM_32, SF_FALSE) ;
|
Chris@0
|
276 pcm_test_float ("float_be.mat4" , SF_ENDIAN_BIG | SF_FORMAT_MAT4 | SF_FORMAT_FLOAT , SF_FALSE) ;
|
Chris@0
|
277 pcm_test_float ("float_le.mat4" , SF_ENDIAN_LITTLE | SF_FORMAT_MAT4 | SF_FORMAT_FLOAT , SF_FALSE) ;
|
Chris@0
|
278 pcm_test_double ("double_be.mat4" , SF_ENDIAN_BIG | SF_FORMAT_MAT4 | SF_FORMAT_DOUBLE, SF_FALSE) ;
|
Chris@0
|
279 pcm_test_double ("double_le.mat4" , SF_ENDIAN_LITTLE | SF_FORMAT_MAT4 | SF_FORMAT_DOUBLE, SF_FALSE) ;
|
Chris@0
|
280
|
Chris@0
|
281 empty_file_test ("empty_short.mat4", SF_FORMAT_MAT4 | SF_FORMAT_PCM_16) ;
|
Chris@0
|
282 empty_file_test ("empty_float.mat4", SF_FORMAT_MAT4 | SF_FORMAT_FLOAT) ;
|
Chris@0
|
283 test_count++ ;
|
Chris@0
|
284 } ;
|
Chris@0
|
285
|
Chris@0
|
286 if (do_all || ! strcmp (argv [1], "mat5"))
|
Chris@0
|
287 { pcm_test_char ("char_be.mat5" , SF_ENDIAN_BIG | SF_FORMAT_MAT5 | SF_FORMAT_PCM_U8, SF_FALSE) ;
|
Chris@0
|
288 pcm_test_char ("char_le.mat5" , SF_ENDIAN_LITTLE | SF_FORMAT_MAT5 | SF_FORMAT_PCM_U8, SF_FALSE) ;
|
Chris@0
|
289 pcm_test_short ("short_be.mat5" , SF_ENDIAN_BIG | SF_FORMAT_MAT5 | SF_FORMAT_PCM_16, SF_FALSE) ;
|
Chris@0
|
290 pcm_test_short ("short_le.mat5" , SF_ENDIAN_LITTLE | SF_FORMAT_MAT5 | SF_FORMAT_PCM_16, SF_FALSE) ;
|
Chris@0
|
291 pcm_test_int ("int_be.mat5" , SF_ENDIAN_BIG | SF_FORMAT_MAT5 | SF_FORMAT_PCM_32, SF_FALSE) ;
|
Chris@0
|
292 pcm_test_int ("int_le.mat5" , SF_ENDIAN_LITTLE | SF_FORMAT_MAT5 | SF_FORMAT_PCM_32, SF_FALSE) ;
|
Chris@0
|
293 pcm_test_float ("float_be.mat5" , SF_ENDIAN_BIG | SF_FORMAT_MAT5 | SF_FORMAT_FLOAT , SF_FALSE) ;
|
Chris@0
|
294 pcm_test_float ("float_le.mat5" , SF_ENDIAN_LITTLE | SF_FORMAT_MAT5 | SF_FORMAT_FLOAT , SF_FALSE) ;
|
Chris@0
|
295 pcm_test_double ("double_be.mat5" , SF_ENDIAN_BIG | SF_FORMAT_MAT5 | SF_FORMAT_DOUBLE, SF_FALSE) ;
|
Chris@0
|
296 pcm_test_double ("double_le.mat5" , SF_ENDIAN_LITTLE | SF_FORMAT_MAT5 | SF_FORMAT_DOUBLE, SF_FALSE) ;
|
Chris@0
|
297
|
Chris@0
|
298 increment_open_file_count () ;
|
Chris@0
|
299
|
Chris@0
|
300 empty_file_test ("empty_char.mat5", SF_FORMAT_MAT5 | SF_FORMAT_PCM_U8) ;
|
Chris@0
|
301 empty_file_test ("empty_short.mat5", SF_FORMAT_MAT5 | SF_FORMAT_PCM_16) ;
|
Chris@0
|
302 empty_file_test ("empty_float.mat5", SF_FORMAT_MAT5 | SF_FORMAT_FLOAT) ;
|
Chris@0
|
303
|
Chris@0
|
304 test_count++ ;
|
Chris@0
|
305 } ;
|
Chris@0
|
306
|
Chris@0
|
307 if (do_all || ! strcmp (argv [1], "pvf"))
|
Chris@0
|
308 { pcm_test_char ("char.pvf" , SF_FORMAT_PVF | SF_FORMAT_PCM_S8, SF_FALSE) ;
|
Chris@0
|
309 pcm_test_short ("short.pvf", SF_FORMAT_PVF | SF_FORMAT_PCM_16, SF_FALSE) ;
|
Chris@0
|
310 pcm_test_int ("int.pvf" , SF_FORMAT_PVF | SF_FORMAT_PCM_32, SF_FALSE) ;
|
Chris@0
|
311 test_count++ ;
|
Chris@0
|
312 } ;
|
Chris@0
|
313
|
Chris@0
|
314 if (do_all || ! strcmp (argv [1], "htk"))
|
Chris@0
|
315 { pcm_test_short ("short.htk", SF_FORMAT_HTK | SF_FORMAT_PCM_16, SF_FALSE) ;
|
Chris@0
|
316 test_count++ ;
|
Chris@0
|
317 } ;
|
Chris@0
|
318
|
Chris@0
|
319 if (do_all || ! strcmp (argv [1], "mpc2k"))
|
Chris@0
|
320 { pcm_test_short ("short.mpc", SF_FORMAT_MPC2K | SF_FORMAT_PCM_16, SF_FALSE) ;
|
Chris@0
|
321 test_count++ ;
|
Chris@0
|
322 } ;
|
Chris@0
|
323
|
Chris@0
|
324 if (do_all || ! strcmp (argv [1], "avr"))
|
Chris@0
|
325 { pcm_test_char ("char_u8.avr" , SF_FORMAT_AVR | SF_FORMAT_PCM_U8, SF_FALSE) ;
|
Chris@0
|
326 pcm_test_char ("char_s8.avr" , SF_FORMAT_AVR | SF_FORMAT_PCM_S8, SF_FALSE) ;
|
Chris@0
|
327 pcm_test_short ("short.avr" , SF_FORMAT_AVR | SF_FORMAT_PCM_16, SF_FALSE) ;
|
Chris@0
|
328 test_count++ ;
|
Chris@0
|
329 } ;
|
Chris@0
|
330 /* Lite remove end */
|
Chris@0
|
331
|
Chris@0
|
332 if (do_all || ! strcmp (argv [1], "w64"))
|
Chris@0
|
333 { pcm_test_char ("char.w64" , SF_FORMAT_W64 | SF_FORMAT_PCM_U8, SF_FALSE) ;
|
Chris@0
|
334 pcm_test_short ("short.w64" , SF_FORMAT_W64 | SF_FORMAT_PCM_16, SF_FALSE) ;
|
Chris@0
|
335 pcm_test_24bit ("24bit.w64" , SF_FORMAT_W64 | SF_FORMAT_PCM_24, SF_FALSE) ;
|
Chris@0
|
336 pcm_test_int ("int.w64" , SF_FORMAT_W64 | SF_FORMAT_PCM_32, SF_FALSE) ;
|
Chris@0
|
337 /* Lite remove start */
|
Chris@0
|
338 pcm_test_float ("float.w64" , SF_FORMAT_W64 | SF_FORMAT_FLOAT , SF_FALSE) ;
|
Chris@0
|
339 pcm_test_double ("double.w64" , SF_FORMAT_W64 | SF_FORMAT_DOUBLE, SF_FALSE) ;
|
Chris@0
|
340 /* Lite remove end */
|
Chris@0
|
341
|
Chris@0
|
342 empty_file_test ("empty_char.w64", SF_FORMAT_W64 | SF_FORMAT_PCM_U8) ;
|
Chris@0
|
343 empty_file_test ("empty_short.w64", SF_FORMAT_W64 | SF_FORMAT_PCM_16) ;
|
Chris@0
|
344 empty_file_test ("empty_float.w64", SF_FORMAT_W64 | SF_FORMAT_FLOAT) ;
|
Chris@0
|
345
|
Chris@0
|
346 test_count++ ;
|
Chris@0
|
347 } ;
|
Chris@0
|
348
|
Chris@0
|
349 if (do_all || ! strcmp (argv [1], "sds"))
|
Chris@0
|
350 { pcm_test_char ("char.sds" , SF_FORMAT_SDS | SF_FORMAT_PCM_S8, SF_FALSE) ;
|
Chris@0
|
351 pcm_test_short ("short.sds" , SF_FORMAT_SDS | SF_FORMAT_PCM_16, SF_FALSE) ;
|
Chris@0
|
352 pcm_test_24bit ("24bit.sds" , SF_FORMAT_SDS | SF_FORMAT_PCM_24, SF_FALSE) ;
|
Chris@0
|
353
|
Chris@0
|
354 empty_file_test ("empty_char.sds", SF_FORMAT_SDS | SF_FORMAT_PCM_S8) ;
|
Chris@0
|
355 empty_file_test ("empty_short.sds", SF_FORMAT_SDS | SF_FORMAT_PCM_16) ;
|
Chris@0
|
356
|
Chris@0
|
357 test_count++ ;
|
Chris@0
|
358 } ;
|
Chris@0
|
359
|
Chris@0
|
360 if (do_all || ! strcmp (argv [1], "sd2"))
|
Chris@0
|
361 { pcm_test_char ("char.sd2" , SF_FORMAT_SD2 | SF_FORMAT_PCM_S8, SF_TRUE) ;
|
Chris@0
|
362 pcm_test_short ("short.sd2" , SF_FORMAT_SD2 | SF_FORMAT_PCM_16, SF_TRUE) ;
|
Chris@0
|
363 pcm_test_24bit ("24bit.sd2" , SF_FORMAT_SD2 | SF_FORMAT_PCM_24, SF_TRUE) ;
|
Chris@0
|
364 test_count++ ;
|
Chris@0
|
365 } ;
|
Chris@0
|
366
|
Chris@0
|
367 if (do_all || ! strcmp (argv [1], "flac"))
|
Chris@0
|
368 { if (HAVE_EXTERNAL_LIBS)
|
Chris@0
|
369 { pcm_test_char ("char.flac" , SF_FORMAT_FLAC | SF_FORMAT_PCM_S8, SF_TRUE) ;
|
Chris@0
|
370 pcm_test_short ("short.flac" , SF_FORMAT_FLAC | SF_FORMAT_PCM_16, SF_TRUE) ;
|
Chris@0
|
371 pcm_test_24bit ("24bit.flac" , SF_FORMAT_FLAC | SF_FORMAT_PCM_24, SF_TRUE) ;
|
Chris@0
|
372 }
|
Chris@0
|
373 else
|
Chris@0
|
374 puts (" No FLAC tests because FLAC support was not compiled in.") ;
|
Chris@0
|
375 test_count++ ;
|
Chris@0
|
376 } ;
|
Chris@0
|
377
|
Chris@0
|
378 if (do_all || ! strcmp (argv [1], "rf64"))
|
Chris@0
|
379 { pcm_test_char ("char.rf64" , SF_FORMAT_RF64 | SF_FORMAT_PCM_U8, SF_FALSE) ;
|
Chris@0
|
380 pcm_test_short ("short.rf64" , SF_FORMAT_RF64 | SF_FORMAT_PCM_16, SF_FALSE) ;
|
Chris@0
|
381 pcm_test_24bit ("24bit.rf64" , SF_FORMAT_RF64 | SF_FORMAT_PCM_24, SF_FALSE) ;
|
Chris@0
|
382 pcm_test_int ("int.rf64" , SF_FORMAT_RF64 | SF_FORMAT_PCM_32, SF_FALSE) ;
|
Chris@0
|
383
|
Chris@0
|
384 /* Lite remove start */
|
Chris@0
|
385 pcm_test_float ("float.rf64" , SF_FORMAT_RF64 | SF_FORMAT_FLOAT , SF_FALSE) ;
|
Chris@0
|
386 pcm_test_double ("double.rf64" , SF_FORMAT_RF64 | SF_FORMAT_DOUBLE, SF_FALSE) ;
|
Chris@0
|
387 empty_file_test ("empty_char.rf64", SF_FORMAT_RF64 | SF_FORMAT_PCM_U8) ;
|
Chris@0
|
388 empty_file_test ("empty_short.rf64", SF_FORMAT_RF64 | SF_FORMAT_PCM_16) ;
|
Chris@0
|
389 empty_file_test ("empty_float.rf64", SF_FORMAT_RF64 | SF_FORMAT_FLOAT) ;
|
Chris@0
|
390 /* Lite remove end */
|
Chris@0
|
391
|
Chris@0
|
392 test_count++ ;
|
Chris@0
|
393 } ;
|
Chris@0
|
394
|
Chris@0
|
395 if (test_count == 0)
|
Chris@0
|
396 { printf ("Mono : ************************************\n") ;
|
Chris@0
|
397 printf ("Mono : * No '%s' test defined.\n", argv [1]) ;
|
Chris@0
|
398 printf ("Mono : ************************************\n") ;
|
Chris@0
|
399 return 1 ;
|
Chris@0
|
400 } ;
|
Chris@0
|
401
|
Chris@0
|
402 /* Only open file descriptors should be stdin, stdout and stderr. */
|
Chris@0
|
403 check_open_file_count_or_die (__LINE__) ;
|
Chris@0
|
404
|
Chris@0
|
405 return 0 ;
|
Chris@0
|
406 } /* main */
|
Chris@0
|
407
|
Chris@0
|
408 /*============================================================================================
|
Chris@0
|
409 ** Helper functions and macros.
|
Chris@0
|
410 */
|
Chris@0
|
411
|
Chris@0
|
412 static void create_short_file (const char *filename) ;
|
Chris@0
|
413
|
Chris@0
|
414 #define CHAR_ERROR(x,y) (abs ((x) - (y)) > 255)
|
Chris@0
|
415 #define INT_ERROR(x,y) (((x) - (y)) != 0)
|
Chris@0
|
416 #define TRIBYTE_ERROR(x,y) (abs ((x) - (y)) > 255)
|
Chris@0
|
417 #define FLOAT_ERROR(x,y) (fabs ((x) - (y)) > 1e-5)
|
Chris@0
|
418
|
Chris@0
|
419 #define CONVERT_DATA(k,len,new,orig) \
|
Chris@0
|
420 { for ((k) = 0 ; (k) < (len) ; (k) ++) \
|
Chris@0
|
421 (new) [k] = (orig) [k] ; \
|
Chris@0
|
422 }
|
Chris@0
|
423
|
Chris@0
|
424
|
Chris@0
|
425 /*======================================================================================
|
Chris@0
|
426 */
|
Chris@0
|
427
|
Chris@0
|
428 static void mono_char_test (const char *filename, int format, int long_file_ok, int allow_fd) ;
|
Chris@0
|
429 static void stereo_char_test (const char *filename, int format, int long_file_ok, int allow_fd) ;
|
Chris@0
|
430 static void mono_rdwr_char_test (const char *filename, int format, int long_file_ok, int allow_fd) ;
|
Chris@0
|
431 static void new_rdwr_char_test (const char *filename, int format, int allow_fd) ;
|
Chris@0
|
432 static void multi_seek_test (const char * filename, int format) ;
|
Chris@0
|
433 static void write_seek_extend_test (const char * filename, int format) ;
|
Chris@0
|
434
|
Chris@0
|
435 static void
|
Chris@0
|
436 pcm_test_char (const char *filename, int format, int long_file_ok)
|
Chris@0
|
437 { SF_INFO sfinfo ;
|
Chris@0
|
438 short *orig ;
|
Chris@0
|
439 int k, allow_fd ;
|
Chris@0
|
440
|
Chris@0
|
441 /* Sd2 files cannot be opened from an existing file descriptor. */
|
Chris@0
|
442 allow_fd = ((format & SF_FORMAT_TYPEMASK) == SF_FORMAT_SD2) ? SF_FALSE : SF_TRUE ;
|
Chris@0
|
443
|
Chris@0
|
444 print_test_name ("pcm_test_char", filename) ;
|
Chris@0
|
445
|
Chris@0
|
446 sfinfo.samplerate = 44100 ;
|
Chris@0
|
447 sfinfo.frames = SILLY_WRITE_COUNT ; /* Wrong length. Library should correct this on sf_close. */
|
Chris@0
|
448 sfinfo.channels = 1 ;
|
Chris@0
|
449 sfinfo.format = format ;
|
Chris@0
|
450
|
Chris@0
|
451 gen_windowed_sine_double (orig_data.d, DATA_LENGTH, 32000.0) ;
|
Chris@0
|
452
|
Chris@0
|
453 orig = orig_data.s ;
|
Chris@0
|
454
|
Chris@0
|
455 /* Make this a macro so gdb steps over it in one go. */
|
Chris@0
|
456 CONVERT_DATA (k, DATA_LENGTH, orig, orig_data.d) ;
|
Chris@0
|
457
|
Chris@0
|
458 /* Some test broken out here. */
|
Chris@0
|
459
|
Chris@0
|
460 mono_char_test (filename, format, long_file_ok, allow_fd) ;
|
Chris@0
|
461
|
Chris@0
|
462 /* Sub format DWVW does not allow seeking. */
|
Chris@0
|
463 if ((format & SF_FORMAT_SUBMASK) == SF_FORMAT_DWVW_16 ||
|
Chris@0
|
464 (format & SF_FORMAT_SUBMASK) == SF_FORMAT_DWVW_24)
|
Chris@0
|
465 { unlink (filename) ;
|
Chris@0
|
466 printf ("no seek : ok\n") ;
|
Chris@0
|
467 return ;
|
Chris@0
|
468 } ;
|
Chris@0
|
469
|
Chris@0
|
470 if ((format & SF_FORMAT_TYPEMASK) != SF_FORMAT_FLAC)
|
Chris@0
|
471 mono_rdwr_char_test (filename, format, long_file_ok, allow_fd) ;
|
Chris@0
|
472
|
Chris@0
|
473 /* If the format doesn't support stereo we're done. */
|
Chris@0
|
474 sfinfo.channels = 2 ;
|
Chris@0
|
475 if (sf_format_check (&sfinfo) == 0)
|
Chris@0
|
476 { unlink (filename) ;
|
Chris@0
|
477 puts ("no stereo : ok") ;
|
Chris@0
|
478 return ;
|
Chris@0
|
479 } ;
|
Chris@0
|
480
|
Chris@0
|
481 stereo_char_test (filename, format, long_file_ok, allow_fd) ;
|
Chris@0
|
482
|
Chris@0
|
483 /* New read/write test. Not sure if this is needed yet. */
|
Chris@0
|
484
|
Chris@0
|
485 if ((format & SF_FORMAT_TYPEMASK) != SF_FORMAT_PAF &&
|
Chris@0
|
486 (format & SF_FORMAT_TYPEMASK) != SF_FORMAT_VOC &&
|
Chris@0
|
487 (format & SF_FORMAT_TYPEMASK) != SF_FORMAT_FLAC)
|
Chris@0
|
488 new_rdwr_char_test (filename, format, allow_fd) ;
|
Chris@0
|
489
|
Chris@0
|
490 delete_file (format, filename) ;
|
Chris@0
|
491
|
Chris@0
|
492 puts ("ok") ;
|
Chris@0
|
493 return ;
|
Chris@0
|
494 } /* pcm_test_char */
|
Chris@0
|
495
|
Chris@0
|
496 static void
|
Chris@0
|
497 mono_char_test (const char *filename, int format, int long_file_ok, int allow_fd)
|
Chris@0
|
498 { SNDFILE *file ;
|
Chris@0
|
499 SF_INFO sfinfo ;
|
Chris@0
|
500 short *orig, *test ;
|
Chris@0
|
501 sf_count_t count ;
|
Chris@0
|
502 int k, items ;
|
Chris@0
|
503
|
Chris@0
|
504 sfinfo.samplerate = 44100 ;
|
Chris@0
|
505 sfinfo.frames = SILLY_WRITE_COUNT ; /* Wrong length. Library should correct this on sf_close. */
|
Chris@0
|
506 sfinfo.channels = 1 ;
|
Chris@0
|
507 sfinfo.format = format ;
|
Chris@0
|
508
|
Chris@0
|
509 orig = orig_data.s ;
|
Chris@0
|
510 test = test_data.s ;
|
Chris@0
|
511
|
Chris@0
|
512 items = DATA_LENGTH ;
|
Chris@0
|
513
|
Chris@0
|
514 file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, allow_fd, __LINE__) ;
|
Chris@0
|
515
|
Chris@0
|
516 sf_set_string (file, SF_STR_ARTIST, "Your name here") ;
|
Chris@0
|
517
|
Chris@0
|
518 test_write_short_or_die (file, 0, orig, items, __LINE__) ;
|
Chris@0
|
519 sf_write_sync (file) ;
|
Chris@0
|
520 test_write_short_or_die (file, 0, orig, items, __LINE__) ;
|
Chris@0
|
521 sf_write_sync (file) ;
|
Chris@0
|
522
|
Chris@0
|
523 /* Add non-audio data after the audio. */
|
Chris@0
|
524 sf_set_string (file, SF_STR_COPYRIGHT, "Copyright (c) 2003") ;
|
Chris@0
|
525
|
Chris@0
|
526 sf_close (file) ;
|
Chris@0
|
527
|
Chris@0
|
528 memset (test, 0, items * sizeof (short)) ;
|
Chris@0
|
529
|
Chris@0
|
530 if ((format & SF_FORMAT_TYPEMASK) != SF_FORMAT_RAW)
|
Chris@0
|
531 memset (&sfinfo, 0, sizeof (sfinfo)) ;
|
Chris@0
|
532
|
Chris@0
|
533 file = test_open_file_or_die (filename, SFM_READ, &sfinfo, allow_fd, __LINE__) ;
|
Chris@0
|
534
|
Chris@0
|
535 if (sfinfo.format != format)
|
Chris@0
|
536 { printf ("\n\nLine %d : Mono : Returned format incorrect (0x%08X => 0x%08X).\n", __LINE__, format, sfinfo.format) ;
|
Chris@0
|
537 exit (1) ;
|
Chris@0
|
538 } ;
|
Chris@0
|
539
|
Chris@0
|
540 if (sfinfo.frames < 2 * items)
|
Chris@0
|
541 { printf ("\n\nLine %d : Mono : Incorrect number of frames in file (too short). (%ld should be %d)\n", __LINE__, SF_COUNT_TO_LONG (sfinfo.frames), items) ;
|
Chris@0
|
542 exit (1) ;
|
Chris@0
|
543 } ;
|
Chris@0
|
544
|
Chris@0
|
545 if (! long_file_ok && sfinfo.frames > 2 * items)
|
Chris@0
|
546 { printf ("\n\nLine %d : Mono : Incorrect number of frames in file (too long). (%ld should be %d)\n", __LINE__, SF_COUNT_TO_LONG (sfinfo.frames), items) ;
|
Chris@0
|
547 exit (1) ;
|
Chris@0
|
548 } ;
|
Chris@0
|
549
|
Chris@0
|
550 if (sfinfo.channels != 1)
|
Chris@0
|
551 { printf ("\n\nLine %d : Mono : Incorrect number of channels in file.\n", __LINE__) ;
|
Chris@0
|
552 exit (1) ;
|
Chris@0
|
553 } ;
|
Chris@0
|
554
|
Chris@0
|
555 check_log_buffer_or_die (file, __LINE__) ;
|
Chris@0
|
556
|
Chris@0
|
557 test_read_short_or_die (file, 0, test, items, __LINE__) ;
|
Chris@0
|
558 for (k = 0 ; k < items ; k++)
|
Chris@0
|
559 if (CHAR_ERROR (orig [k], test [k]))
|
Chris@0
|
560 { printf ("\n\nLine %d: Mono : Incorrect sample A (#%d : 0x%X => 0x%X).\n", __LINE__, k, orig [k], test [k]) ;
|
Chris@0
|
561 oct_save_short (orig, test, items) ;
|
Chris@0
|
562 exit (1) ;
|
Chris@0
|
563 } ;
|
Chris@0
|
564
|
Chris@0
|
565 /* Seek to start of file. */
|
Chris@0
|
566 test_seek_or_die (file, 0, SEEK_SET, 0, sfinfo.channels, __LINE__) ;
|
Chris@0
|
567
|
Chris@0
|
568 test_read_short_or_die (file, 0, test, 4, __LINE__) ;
|
Chris@0
|
569 for (k = 0 ; k < 4 ; k++)
|
Chris@0
|
570 if (CHAR_ERROR (orig [k], test [k]))
|
Chris@0
|
571 { printf ("\n\nLine %d : Mono : Incorrect sample A (#%d : 0x%X => 0x%X).\n", __LINE__, k, orig [k], test [k]) ;
|
Chris@0
|
572 exit (1) ;
|
Chris@0
|
573 } ;
|
Chris@0
|
574
|
Chris@0
|
575 if ((format & SF_FORMAT_SUBMASK) == SF_FORMAT_DWVW_16 ||
|
Chris@0
|
576 (format & SF_FORMAT_SUBMASK) == SF_FORMAT_DWVW_24)
|
Chris@0
|
577 { sf_close (file) ;
|
Chris@0
|
578 unlink (filename) ;
|
Chris@0
|
579 printf ("no seek : ") ;
|
Chris@0
|
580 return ;
|
Chris@0
|
581 } ;
|
Chris@0
|
582
|
Chris@0
|
583 /* Seek to offset from start of file. */
|
Chris@0
|
584 test_seek_or_die (file, items + 10, SEEK_SET, items + 10, sfinfo.channels, __LINE__) ;
|
Chris@0
|
585
|
Chris@0
|
586 test_read_short_or_die (file, 0, test + 10, 4, __LINE__) ;
|
Chris@0
|
587 for (k = 10 ; k < 14 ; k++)
|
Chris@0
|
588 if (CHAR_ERROR (orig [k], test [k]))
|
Chris@0
|
589 { printf ("\n\nLine %d : Mono : Incorrect sample A (#%d : 0x%X => 0x%X).\n", __LINE__, k, test [k], orig [k]) ;
|
Chris@0
|
590 exit (1) ;
|
Chris@0
|
591 } ;
|
Chris@0
|
592
|
Chris@0
|
593 /* Seek to offset from current position. */
|
Chris@0
|
594 test_seek_or_die (file, 6, SEEK_CUR, items + 20, sfinfo.channels, __LINE__) ;
|
Chris@0
|
595
|
Chris@0
|
596 test_read_short_or_die (file, 0, test + 20, 4, __LINE__) ;
|
Chris@0
|
597 for (k = 20 ; k < 24 ; k++)
|
Chris@0
|
598 if (CHAR_ERROR (orig [k], test [k]))
|
Chris@0
|
599 { printf ("\n\nLine %d : Mono : Incorrect sample A (#%d : 0x%X => 0x%X).\n", __LINE__, k, test [k], orig [k]) ;
|
Chris@0
|
600 exit (1) ;
|
Chris@0
|
601 } ;
|
Chris@0
|
602
|
Chris@0
|
603 /* Seek to offset from end of file. */
|
Chris@0
|
604 test_seek_or_die (file, -1 * (sfinfo.frames - 10), SEEK_END, 10, sfinfo.channels, __LINE__) ;
|
Chris@0
|
605
|
Chris@0
|
606 test_read_short_or_die (file, 0, test + 10, 4, __LINE__) ;
|
Chris@0
|
607 for (k = 10 ; k < 14 ; k++)
|
Chris@0
|
608 if (CHAR_ERROR (orig [k], test [k]))
|
Chris@0
|
609 { printf ("\n\nLine %d : Mono : Incorrect sample D (#%d : 0x%X => 0x%X).\n", __LINE__, k, test [k], orig [k]) ;
|
Chris@0
|
610 exit (1) ;
|
Chris@0
|
611 } ;
|
Chris@0
|
612
|
Chris@0
|
613 /* Check read past end of file followed by sf_seek (sndfile, 0, SEEK_CUR). */
|
Chris@0
|
614 test_seek_or_die (file, 0, SEEK_SET, 0, sfinfo.channels, __LINE__) ;
|
Chris@0
|
615
|
Chris@0
|
616 count = 0 ;
|
Chris@0
|
617 while (count < sfinfo.frames)
|
Chris@0
|
618 count += sf_read_short (file, test, 311) ;
|
Chris@0
|
619
|
Chris@0
|
620 /* Check that no error has occurred. */
|
Chris@0
|
621 if (sf_error (file))
|
Chris@0
|
622 { printf ("\n\nLine %d : Mono : error where there shouldn't have been one.\n", __LINE__) ;
|
Chris@0
|
623 puts (sf_strerror (file)) ;
|
Chris@0
|
624 exit (1) ;
|
Chris@0
|
625 } ;
|
Chris@0
|
626
|
Chris@0
|
627 /* Check that we haven't read beyond EOF. */
|
Chris@0
|
628 if (count > sfinfo.frames)
|
Chris@0
|
629 { printf ("\n\nLines %d : read past end of file (%ld should be %ld)\n", __LINE__, (long) count, (long) sfinfo.frames) ;
|
Chris@0
|
630 exit (1) ;
|
Chris@0
|
631 } ;
|
Chris@0
|
632
|
Chris@0
|
633 test_seek_or_die (file, 0, SEEK_CUR, sfinfo.frames, sfinfo.channels, __LINE__) ;
|
Chris@0
|
634
|
Chris@0
|
635 sf_close (file) ;
|
Chris@0
|
636
|
Chris@0
|
637 multi_seek_test (filename, format) ;
|
Chris@0
|
638 write_seek_extend_test (filename, format) ;
|
Chris@0
|
639
|
Chris@0
|
640 } /* mono_char_test */
|
Chris@0
|
641
|
Chris@0
|
642 static void
|
Chris@0
|
643 stereo_char_test (const char *filename, int format, int long_file_ok, int allow_fd)
|
Chris@0
|
644 { SNDFILE *file ;
|
Chris@0
|
645 SF_INFO sfinfo ;
|
Chris@0
|
646 short *orig, *test ;
|
Chris@0
|
647 int k, items, frames ;
|
Chris@0
|
648
|
Chris@0
|
649 sfinfo.samplerate = 44100 ;
|
Chris@0
|
650 sfinfo.frames = SILLY_WRITE_COUNT ; /* Wrong length. Library should correct this on sf_close. */
|
Chris@0
|
651 sfinfo.channels = 2 ;
|
Chris@0
|
652 sfinfo.format = format ;
|
Chris@0
|
653
|
Chris@0
|
654 gen_windowed_sine_double (orig_data.d, DATA_LENGTH, 32000.0) ;
|
Chris@0
|
655
|
Chris@0
|
656 orig = orig_data.s ;
|
Chris@0
|
657 test = test_data.s ;
|
Chris@0
|
658
|
Chris@0
|
659 /* Make this a macro so gdb steps over it in one go. */
|
Chris@0
|
660 CONVERT_DATA (k, DATA_LENGTH, orig, orig_data.d) ;
|
Chris@0
|
661
|
Chris@0
|
662 items = DATA_LENGTH ;
|
Chris@0
|
663 frames = items / sfinfo.channels ;
|
Chris@0
|
664
|
Chris@0
|
665 file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, allow_fd, __LINE__) ;
|
Chris@0
|
666
|
Chris@0
|
667 sf_set_string (file, SF_STR_ARTIST, "Your name here") ;
|
Chris@0
|
668
|
Chris@0
|
669 test_writef_short_or_die (file, 0, orig, frames, __LINE__) ;
|
Chris@0
|
670
|
Chris@0
|
671 sf_set_string (file, SF_STR_COPYRIGHT, "Copyright (c) 2003") ;
|
Chris@0
|
672
|
Chris@0
|
673 sf_close (file) ;
|
Chris@0
|
674
|
Chris@0
|
675 memset (test, 0, items * sizeof (short)) ;
|
Chris@0
|
676
|
Chris@0
|
677 if ((format & SF_FORMAT_TYPEMASK) != SF_FORMAT_RAW)
|
Chris@0
|
678 memset (&sfinfo, 0, sizeof (sfinfo)) ;
|
Chris@0
|
679
|
Chris@0
|
680 file = test_open_file_or_die (filename, SFM_READ, &sfinfo, allow_fd, __LINE__) ;
|
Chris@0
|
681
|
Chris@0
|
682 if (sfinfo.format != format)
|
Chris@0
|
683 { printf ("\n\nLine %d : Stereo : Returned format incorrect (0x%08X => 0x%08X).\n",
|
Chris@0
|
684 __LINE__, format, sfinfo.format) ;
|
Chris@0
|
685 exit (1) ;
|
Chris@0
|
686 } ;
|
Chris@0
|
687
|
Chris@0
|
688 if (sfinfo.frames < frames)
|
Chris@0
|
689 { printf ("\n\nLine %d : Stereo : Incorrect number of frames in file (too short). (%ld should be %d)\n",
|
Chris@0
|
690 __LINE__, SF_COUNT_TO_LONG (sfinfo.frames), frames) ;
|
Chris@0
|
691 exit (1) ;
|
Chris@0
|
692 } ;
|
Chris@0
|
693
|
Chris@0
|
694 if (! long_file_ok && sfinfo.frames > frames)
|
Chris@0
|
695 { printf ("\n\nLine %d : Stereo : Incorrect number of frames in file (too long). (%ld should be %d)\n",
|
Chris@0
|
696 __LINE__, SF_COUNT_TO_LONG (sfinfo.frames), frames) ;
|
Chris@0
|
697 exit (1) ;
|
Chris@0
|
698 } ;
|
Chris@0
|
699
|
Chris@0
|
700 if (sfinfo.channels != 2)
|
Chris@0
|
701 { printf ("\n\nLine %d : Stereo : Incorrect number of channels in file.\n", __LINE__) ;
|
Chris@0
|
702 exit (1) ;
|
Chris@0
|
703 } ;
|
Chris@0
|
704
|
Chris@0
|
705 check_log_buffer_or_die (file, __LINE__) ;
|
Chris@0
|
706
|
Chris@0
|
707 test_readf_short_or_die (file, 0, test, frames, __LINE__) ;
|
Chris@0
|
708 for (k = 0 ; k < items ; k++)
|
Chris@0
|
709 if (CHAR_ERROR (test [k], orig [k]))
|
Chris@0
|
710 { printf ("\n\nLine %d : Stereo : Incorrect sample (#%d : 0x%X => 0x%X).\n", __LINE__, k, orig [k], test [k]) ;
|
Chris@0
|
711 exit (1) ;
|
Chris@0
|
712 } ;
|
Chris@0
|
713
|
Chris@0
|
714 /* Seek to start of file. */
|
Chris@0
|
715 test_seek_or_die (file, 0, SEEK_SET, 0, sfinfo.channels, __LINE__) ;
|
Chris@0
|
716
|
Chris@0
|
717 test_readf_short_or_die (file, 0, test, 2, __LINE__) ;
|
Chris@0
|
718 for (k = 0 ; k < 4 ; k++)
|
Chris@0
|
719 if (CHAR_ERROR (test [k], orig [k]))
|
Chris@0
|
720 { printf ("\n\nLine %d : Stereo : Incorrect sample (#%d : 0x%X => 0x%X).\n", __LINE__, k, orig [k], test [k]) ;
|
Chris@0
|
721 exit (1) ;
|
Chris@0
|
722 } ;
|
Chris@0
|
723
|
Chris@0
|
724 /* Seek to offset from start of file. */
|
Chris@0
|
725 test_seek_or_die (file, 10, SEEK_SET, 10, sfinfo.channels, __LINE__) ;
|
Chris@0
|
726
|
Chris@0
|
727 /* Check for errors here. */
|
Chris@0
|
728 if (sf_error (file))
|
Chris@0
|
729 { printf ("Line %d: Should NOT return an error.\n", __LINE__) ;
|
Chris@0
|
730 puts (sf_strerror (file)) ;
|
Chris@0
|
731 exit (1) ;
|
Chris@0
|
732 } ;
|
Chris@0
|
733
|
Chris@0
|
734 if (sf_read_short (file, test, 1) > 0)
|
Chris@0
|
735 { printf ("Line %d: Should return 0.\n", __LINE__) ;
|
Chris@0
|
736 exit (1) ;
|
Chris@0
|
737 } ;
|
Chris@0
|
738
|
Chris@0
|
739 if (! sf_error (file))
|
Chris@0
|
740 { printf ("Line %d: Should return an error.\n", __LINE__) ;
|
Chris@0
|
741 exit (1) ;
|
Chris@0
|
742 } ;
|
Chris@0
|
743 /*-----------------------*/
|
Chris@0
|
744
|
Chris@0
|
745 test_readf_short_or_die (file, 0, test + 10, 2, __LINE__) ;
|
Chris@0
|
746 for (k = 20 ; k < 24 ; k++)
|
Chris@0
|
747 if (CHAR_ERROR (test [k], orig [k]))
|
Chris@0
|
748 { printf ("\n\nLine %d : Stereo : Incorrect sample (#%d : 0x%X => 0x%X).\n", __LINE__, k, orig [k], test [k]) ;
|
Chris@0
|
749 exit (1) ;
|
Chris@0
|
750 } ;
|
Chris@0
|
751
|
Chris@0
|
752 /* Seek to offset from current position. */
|
Chris@0
|
753 test_seek_or_die (file, 8, SEEK_CUR, 20, sfinfo.channels, __LINE__) ;
|
Chris@0
|
754
|
Chris@0
|
755 test_readf_short_or_die (file, 0, test + 20, 2, __LINE__) ;
|
Chris@0
|
756 for (k = 40 ; k < 44 ; k++)
|
Chris@0
|
757 if (CHAR_ERROR (test [k], orig [k]))
|
Chris@0
|
758 { printf ("\n\nLine %d : Stereo : Incorrect sample (#%d : 0x%X => 0x%X).\n", __LINE__, k, orig [k], test [k]) ;
|
Chris@0
|
759 exit (1) ;
|
Chris@0
|
760 } ;
|
Chris@0
|
761
|
Chris@0
|
762 /* Seek to offset from end of file. */
|
Chris@0
|
763 test_seek_or_die (file, -1 * (sfinfo.frames - 10), SEEK_END, 10, sfinfo.channels, __LINE__) ;
|
Chris@0
|
764
|
Chris@0
|
765 test_readf_short_or_die (file, 0, test + 20, 2, __LINE__) ;
|
Chris@0
|
766 for (k = 20 ; k < 24 ; k++)
|
Chris@0
|
767 if (CHAR_ERROR (test [k], orig [k]))
|
Chris@0
|
768 { printf ("\n\nLine %d : Stereo : Incorrect sample (#%d : 0x%X => 0x%X).\n", __LINE__, k, orig [k], test [k]) ;
|
Chris@0
|
769 exit (1) ;
|
Chris@0
|
770 } ;
|
Chris@0
|
771
|
Chris@0
|
772 sf_close (file) ;
|
Chris@0
|
773 } /* stereo_char_test */
|
Chris@0
|
774
|
Chris@0
|
775 static void
|
Chris@0
|
776 mono_rdwr_char_test (const char *filename, int format, int long_file_ok, int allow_fd)
|
Chris@0
|
777 { SNDFILE *file ;
|
Chris@0
|
778 SF_INFO sfinfo ;
|
Chris@0
|
779 short *orig, *test ;
|
Chris@0
|
780 int k, pass ;
|
Chris@0
|
781
|
Chris@0
|
782 orig = orig_data.s ;
|
Chris@0
|
783 test = test_data.s ;
|
Chris@0
|
784
|
Chris@0
|
785 sfinfo.samplerate = SAMPLE_RATE ;
|
Chris@0
|
786 sfinfo.frames = DATA_LENGTH ;
|
Chris@0
|
787 sfinfo.channels = 1 ;
|
Chris@0
|
788 sfinfo.format = format ;
|
Chris@0
|
789
|
Chris@0
|
790 if ((format & SF_FORMAT_TYPEMASK) == SF_FORMAT_RAW
|
Chris@0
|
791 || (format & SF_FORMAT_TYPEMASK) == SF_FORMAT_AU
|
Chris@0
|
792 || (format & SF_FORMAT_TYPEMASK) == SF_FORMAT_SD2)
|
Chris@0
|
793 unlink (filename) ;
|
Chris@0
|
794 else
|
Chris@0
|
795 { /* Create a short file. */
|
Chris@0
|
796 create_short_file (filename) ;
|
Chris@0
|
797
|
Chris@0
|
798 /* Opening a already existing short file (ie invalid header) RDWR is disallowed.
|
Chris@0
|
799 ** If this returns a valif pointer sf_open() screwed up.
|
Chris@0
|
800 */
|
Chris@0
|
801 if ((file = sf_open (filename, SFM_RDWR, &sfinfo)))
|
Chris@0
|
802 { printf ("\n\nLine %d: sf_open should (SFM_RDWR) have failed but didn't.\n", __LINE__) ;
|
Chris@0
|
803 exit (1) ;
|
Chris@0
|
804 } ;
|
Chris@0
|
805
|
Chris@0
|
806 /* Truncate the file to zero bytes. */
|
Chris@0
|
807 if (truncate (filename, 0) < 0)
|
Chris@0
|
808 { printf ("\n\nLine %d: truncate (%s) failed", __LINE__, filename) ;
|
Chris@0
|
809 perror (NULL) ;
|
Chris@0
|
810 exit (1) ;
|
Chris@0
|
811 } ;
|
Chris@0
|
812 } ;
|
Chris@0
|
813
|
Chris@0
|
814 /* Opening a zero length file RDWR is allowed, but the SF_INFO struct must contain
|
Chris@0
|
815 ** all the usual data required when opening the file in WRITE mode.
|
Chris@0
|
816 */
|
Chris@0
|
817 sfinfo.samplerate = SAMPLE_RATE ;
|
Chris@0
|
818 sfinfo.frames = DATA_LENGTH ;
|
Chris@0
|
819 sfinfo.channels = 1 ;
|
Chris@0
|
820 sfinfo.format = format ;
|
Chris@0
|
821
|
Chris@0
|
822 file = test_open_file_or_die (filename, SFM_RDWR, &sfinfo, allow_fd, __LINE__) ;
|
Chris@0
|
823
|
Chris@0
|
824 /* Do 3 writes followed by reads. After each, check the data and the current
|
Chris@0
|
825 ** read and write offsets.
|
Chris@0
|
826 */
|
Chris@0
|
827 for (pass = 1 ; pass <= 3 ; pass ++)
|
Chris@0
|
828 { orig [20] = pass * 2 ;
|
Chris@0
|
829
|
Chris@0
|
830 /* Write some data. */
|
Chris@0
|
831 test_write_short_or_die (file, pass, orig, DATA_LENGTH, __LINE__) ;
|
Chris@0
|
832
|
Chris@0
|
833 test_read_write_position_or_die (file, __LINE__, pass, (pass - 1) * DATA_LENGTH, pass * DATA_LENGTH) ;
|
Chris@0
|
834
|
Chris@0
|
835 /* Read what we just wrote. */
|
Chris@0
|
836 test_read_short_or_die (file, 0, test, DATA_LENGTH, __LINE__) ;
|
Chris@0
|
837
|
Chris@0
|
838 /* Check the data. */
|
Chris@0
|
839 for (k = 0 ; k < DATA_LENGTH ; k++)
|
Chris@0
|
840 if (CHAR_ERROR (orig [k], test [k]))
|
Chris@0
|
841 { printf ("\n\nLine %d (pass %d) A : Error at sample %d (0x%X => 0x%X).\n", __LINE__, pass, k, orig [k], test [k]) ;
|
Chris@0
|
842 oct_save_short (orig, test, DATA_LENGTH) ;
|
Chris@0
|
843 exit (1) ;
|
Chris@0
|
844 } ;
|
Chris@0
|
845
|
Chris@0
|
846 test_read_write_position_or_die (file, __LINE__, pass, pass * DATA_LENGTH, pass * DATA_LENGTH) ;
|
Chris@0
|
847 } ; /* for (pass ...) */
|
Chris@0
|
848
|
Chris@0
|
849 sf_close (file) ;
|
Chris@0
|
850
|
Chris@0
|
851 /* Open the file again to check the data. */
|
Chris@0
|
852 file = test_open_file_or_die (filename, SFM_RDWR, &sfinfo, allow_fd, __LINE__) ;
|
Chris@0
|
853
|
Chris@0
|
854 if (sfinfo.format != format)
|
Chris@0
|
855 { printf ("\n\nLine %d : Returned format incorrect (0x%08X => 0x%08X).\n", __LINE__, format, sfinfo.format) ;
|
Chris@0
|
856 exit (1) ;
|
Chris@0
|
857 } ;
|
Chris@0
|
858
|
Chris@0
|
859 if (sfinfo.frames < 3 * DATA_LENGTH)
|
Chris@0
|
860 { printf ("\n\nLine %d : Not enough frames in file. (%ld < %d)\n", __LINE__, SF_COUNT_TO_LONG (sfinfo.frames), 3 * DATA_LENGTH ) ;
|
Chris@0
|
861 exit (1) ;
|
Chris@0
|
862 }
|
Chris@0
|
863
|
Chris@0
|
864 if (! long_file_ok && sfinfo.frames != 3 * DATA_LENGTH)
|
Chris@0
|
865 { printf ("\n\nLine %d : Incorrect number of frames in file. (%ld should be %d)\n", __LINE__, SF_COUNT_TO_LONG (sfinfo.frames), 3 * DATA_LENGTH ) ;
|
Chris@0
|
866 exit (1) ;
|
Chris@0
|
867 } ;
|
Chris@0
|
868
|
Chris@0
|
869 if (sfinfo.channels != 1)
|
Chris@0
|
870 { printf ("\n\nLine %d : Incorrect number of channels in file.\n", __LINE__) ;
|
Chris@0
|
871 exit (1) ;
|
Chris@0
|
872 } ;
|
Chris@0
|
873
|
Chris@0
|
874 if (! long_file_ok)
|
Chris@0
|
875 test_read_write_position_or_die (file, __LINE__, 0, 0, 3 * DATA_LENGTH) ;
|
Chris@0
|
876 else
|
Chris@0
|
877 test_seek_or_die (file, 3 * DATA_LENGTH, SFM_WRITE | SEEK_SET, 3 * DATA_LENGTH, sfinfo.channels, __LINE__) ;
|
Chris@0
|
878
|
Chris@0
|
879 for (pass = 1 ; pass <= 3 ; pass ++)
|
Chris@0
|
880 { orig [20] = pass * 2 ;
|
Chris@0
|
881
|
Chris@0
|
882 test_read_write_position_or_die (file, __LINE__, pass, (pass - 1) * DATA_LENGTH, 3 * DATA_LENGTH) ;
|
Chris@0
|
883
|
Chris@0
|
884 /* Read what we just wrote. */
|
Chris@0
|
885 test_read_short_or_die (file, pass, test, DATA_LENGTH, __LINE__) ;
|
Chris@0
|
886
|
Chris@0
|
887 /* Check the data. */
|
Chris@0
|
888 for (k = 0 ; k < DATA_LENGTH ; k++)
|
Chris@0
|
889 if (CHAR_ERROR (orig [k], test [k]))
|
Chris@0
|
890 { printf ("\n\nLine %d (pass %d) B : Error at sample %d (0x%X => 0x%X).\n", __LINE__, pass, k, orig [k], test [k]) ;
|
Chris@0
|
891 oct_save_short (orig, test, DATA_LENGTH) ;
|
Chris@0
|
892 exit (1) ;
|
Chris@0
|
893 } ;
|
Chris@0
|
894
|
Chris@0
|
895 } ; /* for (pass ...) */
|
Chris@0
|
896
|
Chris@0
|
897 sf_close (file) ;
|
Chris@0
|
898 } /* mono_rdwr_short_test */
|
Chris@0
|
899
|
Chris@0
|
900 static void
|
Chris@0
|
901 new_rdwr_char_test (const char *filename, int format, int allow_fd)
|
Chris@0
|
902 { SNDFILE *wfile, *rwfile ;
|
Chris@0
|
903 SF_INFO sfinfo ;
|
Chris@0
|
904 short *orig, *test ;
|
Chris@0
|
905 int items, frames ;
|
Chris@0
|
906
|
Chris@0
|
907 orig = orig_data.s ;
|
Chris@0
|
908 test = test_data.s ;
|
Chris@0
|
909
|
Chris@0
|
910 sfinfo.samplerate = 44100 ;
|
Chris@0
|
911 sfinfo.frames = SILLY_WRITE_COUNT ; /* Wrong length. Library should correct this on sf_close. */
|
Chris@0
|
912 sfinfo.channels = 2 ;
|
Chris@0
|
913 sfinfo.format = format ;
|
Chris@0
|
914
|
Chris@0
|
915 items = DATA_LENGTH ;
|
Chris@0
|
916 frames = items / sfinfo.channels ;
|
Chris@0
|
917
|
Chris@0
|
918 wfile = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, allow_fd, __LINE__) ;
|
Chris@0
|
919 sf_command (wfile, SFC_SET_UPDATE_HEADER_AUTO, NULL, SF_TRUE) ;
|
Chris@0
|
920 test_writef_short_or_die (wfile, 1, orig, frames, __LINE__) ;
|
Chris@0
|
921 sf_write_sync (wfile) ;
|
Chris@0
|
922 test_writef_short_or_die (wfile, 2, orig, frames, __LINE__) ;
|
Chris@0
|
923 sf_write_sync (wfile) ;
|
Chris@0
|
924
|
Chris@0
|
925 rwfile = test_open_file_or_die (filename, SFM_RDWR, &sfinfo, allow_fd, __LINE__) ;
|
Chris@0
|
926 if (sfinfo.frames != 2 * frames)
|
Chris@0
|
927 { printf ("\n\nLine %d : incorrect number of frames in file (%ld should be %d)\n\n", __LINE__, SF_COUNT_TO_LONG (sfinfo.frames), 2 * frames) ;
|
Chris@0
|
928 exit (1) ;
|
Chris@0
|
929 } ;
|
Chris@0
|
930
|
Chris@0
|
931 test_writef_short_or_die (wfile, 3, orig, frames, __LINE__) ;
|
Chris@0
|
932
|
Chris@0
|
933 test_readf_short_or_die (rwfile, 1, test, frames, __LINE__) ;
|
Chris@0
|
934 test_readf_short_or_die (rwfile, 2, test, frames, __LINE__) ;
|
Chris@0
|
935
|
Chris@0
|
936 sf_close (wfile) ;
|
Chris@0
|
937 sf_close (rwfile) ;
|
Chris@0
|
938 } /* new_rdwr_char_test */
|
Chris@0
|
939
|
Chris@0
|
940
|
Chris@0
|
941 /*======================================================================================
|
Chris@0
|
942 */
|
Chris@0
|
943
|
Chris@0
|
944 static void mono_short_test (const char *filename, int format, int long_file_ok, int allow_fd) ;
|
Chris@0
|
945 static void stereo_short_test (const char *filename, int format, int long_file_ok, int allow_fd) ;
|
Chris@0
|
946 static void mono_rdwr_short_test (const char *filename, int format, int long_file_ok, int allow_fd) ;
|
Chris@0
|
947 static void new_rdwr_short_test (const char *filename, int format, int allow_fd) ;
|
Chris@0
|
948 static void multi_seek_test (const char * filename, int format) ;
|
Chris@0
|
949 static void write_seek_extend_test (const char * filename, int format) ;
|
Chris@0
|
950
|
Chris@0
|
951 static void
|
Chris@0
|
952 pcm_test_short (const char *filename, int format, int long_file_ok)
|
Chris@0
|
953 { SF_INFO sfinfo ;
|
Chris@0
|
954 short *orig ;
|
Chris@0
|
955 int k, allow_fd ;
|
Chris@0
|
956
|
Chris@0
|
957 /* Sd2 files cannot be opened from an existing file descriptor. */
|
Chris@0
|
958 allow_fd = ((format & SF_FORMAT_TYPEMASK) == SF_FORMAT_SD2) ? SF_FALSE : SF_TRUE ;
|
Chris@0
|
959
|
Chris@0
|
960 print_test_name ("pcm_test_short", filename) ;
|
Chris@0
|
961
|
Chris@0
|
962 sfinfo.samplerate = 44100 ;
|
Chris@0
|
963 sfinfo.frames = SILLY_WRITE_COUNT ; /* Wrong length. Library should correct this on sf_close. */
|
Chris@0
|
964 sfinfo.channels = 1 ;
|
Chris@0
|
965 sfinfo.format = format ;
|
Chris@0
|
966
|
Chris@0
|
967 gen_windowed_sine_double (orig_data.d, DATA_LENGTH, 32000.0) ;
|
Chris@0
|
968
|
Chris@0
|
969 orig = orig_data.s ;
|
Chris@0
|
970
|
Chris@0
|
971 /* Make this a macro so gdb steps over it in one go. */
|
Chris@0
|
972 CONVERT_DATA (k, DATA_LENGTH, orig, orig_data.d) ;
|
Chris@0
|
973
|
Chris@0
|
974 /* Some test broken out here. */
|
Chris@0
|
975
|
Chris@0
|
976 mono_short_test (filename, format, long_file_ok, allow_fd) ;
|
Chris@0
|
977
|
Chris@0
|
978 /* Sub format DWVW does not allow seeking. */
|
Chris@0
|
979 if ((format & SF_FORMAT_SUBMASK) == SF_FORMAT_DWVW_16 ||
|
Chris@0
|
980 (format & SF_FORMAT_SUBMASK) == SF_FORMAT_DWVW_24)
|
Chris@0
|
981 { unlink (filename) ;
|
Chris@0
|
982 printf ("no seek : ok\n") ;
|
Chris@0
|
983 return ;
|
Chris@0
|
984 } ;
|
Chris@0
|
985
|
Chris@0
|
986 if ((format & SF_FORMAT_TYPEMASK) != SF_FORMAT_FLAC)
|
Chris@0
|
987 mono_rdwr_short_test (filename, format, long_file_ok, allow_fd) ;
|
Chris@0
|
988
|
Chris@0
|
989 /* If the format doesn't support stereo we're done. */
|
Chris@0
|
990 sfinfo.channels = 2 ;
|
Chris@0
|
991 if (sf_format_check (&sfinfo) == 0)
|
Chris@0
|
992 { unlink (filename) ;
|
Chris@0
|
993 puts ("no stereo : ok") ;
|
Chris@0
|
994 return ;
|
Chris@0
|
995 } ;
|
Chris@0
|
996
|
Chris@0
|
997 stereo_short_test (filename, format, long_file_ok, allow_fd) ;
|
Chris@0
|
998
|
Chris@0
|
999 /* New read/write test. Not sure if this is needed yet. */
|
Chris@0
|
1000
|
Chris@0
|
1001 if ((format & SF_FORMAT_TYPEMASK) != SF_FORMAT_PAF &&
|
Chris@0
|
1002 (format & SF_FORMAT_TYPEMASK) != SF_FORMAT_VOC &&
|
Chris@0
|
1003 (format & SF_FORMAT_TYPEMASK) != SF_FORMAT_FLAC)
|
Chris@0
|
1004 new_rdwr_short_test (filename, format, allow_fd) ;
|
Chris@0
|
1005
|
Chris@0
|
1006 delete_file (format, filename) ;
|
Chris@0
|
1007
|
Chris@0
|
1008 puts ("ok") ;
|
Chris@0
|
1009 return ;
|
Chris@0
|
1010 } /* pcm_test_short */
|
Chris@0
|
1011
|
Chris@0
|
1012 static void
|
Chris@0
|
1013 mono_short_test (const char *filename, int format, int long_file_ok, int allow_fd)
|
Chris@0
|
1014 { SNDFILE *file ;
|
Chris@0
|
1015 SF_INFO sfinfo ;
|
Chris@0
|
1016 short *orig, *test ;
|
Chris@0
|
1017 sf_count_t count ;
|
Chris@0
|
1018 int k, items ;
|
Chris@0
|
1019
|
Chris@0
|
1020 sfinfo.samplerate = 44100 ;
|
Chris@0
|
1021 sfinfo.frames = SILLY_WRITE_COUNT ; /* Wrong length. Library should correct this on sf_close. */
|
Chris@0
|
1022 sfinfo.channels = 1 ;
|
Chris@0
|
1023 sfinfo.format = format ;
|
Chris@0
|
1024
|
Chris@0
|
1025 orig = orig_data.s ;
|
Chris@0
|
1026 test = test_data.s ;
|
Chris@0
|
1027
|
Chris@0
|
1028 items = DATA_LENGTH ;
|
Chris@0
|
1029
|
Chris@0
|
1030 file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, allow_fd, __LINE__) ;
|
Chris@0
|
1031
|
Chris@0
|
1032 sf_set_string (file, SF_STR_ARTIST, "Your name here") ;
|
Chris@0
|
1033
|
Chris@0
|
1034 test_write_short_or_die (file, 0, orig, items, __LINE__) ;
|
Chris@0
|
1035 sf_write_sync (file) ;
|
Chris@0
|
1036 test_write_short_or_die (file, 0, orig, items, __LINE__) ;
|
Chris@0
|
1037 sf_write_sync (file) ;
|
Chris@0
|
1038
|
Chris@0
|
1039 /* Add non-audio data after the audio. */
|
Chris@0
|
1040 sf_set_string (file, SF_STR_COPYRIGHT, "Copyright (c) 2003") ;
|
Chris@0
|
1041
|
Chris@0
|
1042 sf_close (file) ;
|
Chris@0
|
1043
|
Chris@0
|
1044 memset (test, 0, items * sizeof (short)) ;
|
Chris@0
|
1045
|
Chris@0
|
1046 if ((format & SF_FORMAT_TYPEMASK) != SF_FORMAT_RAW)
|
Chris@0
|
1047 memset (&sfinfo, 0, sizeof (sfinfo)) ;
|
Chris@0
|
1048
|
Chris@0
|
1049 file = test_open_file_or_die (filename, SFM_READ, &sfinfo, allow_fd, __LINE__) ;
|
Chris@0
|
1050
|
Chris@0
|
1051 if (sfinfo.format != format)
|
Chris@0
|
1052 { printf ("\n\nLine %d : Mono : Returned format incorrect (0x%08X => 0x%08X).\n", __LINE__, format, sfinfo.format) ;
|
Chris@0
|
1053 exit (1) ;
|
Chris@0
|
1054 } ;
|
Chris@0
|
1055
|
Chris@0
|
1056 if (sfinfo.frames < 2 * items)
|
Chris@0
|
1057 { printf ("\n\nLine %d : Mono : Incorrect number of frames in file (too short). (%ld should be %d)\n", __LINE__, SF_COUNT_TO_LONG (sfinfo.frames), items) ;
|
Chris@0
|
1058 exit (1) ;
|
Chris@0
|
1059 } ;
|
Chris@0
|
1060
|
Chris@0
|
1061 if (! long_file_ok && sfinfo.frames > 2 * items)
|
Chris@0
|
1062 { printf ("\n\nLine %d : Mono : Incorrect number of frames in file (too long). (%ld should be %d)\n", __LINE__, SF_COUNT_TO_LONG (sfinfo.frames), items) ;
|
Chris@0
|
1063 exit (1) ;
|
Chris@0
|
1064 } ;
|
Chris@0
|
1065
|
Chris@0
|
1066 if (sfinfo.channels != 1)
|
Chris@0
|
1067 { printf ("\n\nLine %d : Mono : Incorrect number of channels in file.\n", __LINE__) ;
|
Chris@0
|
1068 exit (1) ;
|
Chris@0
|
1069 } ;
|
Chris@0
|
1070
|
Chris@0
|
1071 check_log_buffer_or_die (file, __LINE__) ;
|
Chris@0
|
1072
|
Chris@0
|
1073 test_read_short_or_die (file, 0, test, items, __LINE__) ;
|
Chris@0
|
1074 for (k = 0 ; k < items ; k++)
|
Chris@0
|
1075 if (INT_ERROR (orig [k], test [k]))
|
Chris@0
|
1076 { printf ("\n\nLine %d: Mono : Incorrect sample A (#%d : 0x%X => 0x%X).\n", __LINE__, k, orig [k], test [k]) ;
|
Chris@0
|
1077 oct_save_short (orig, test, items) ;
|
Chris@0
|
1078 exit (1) ;
|
Chris@0
|
1079 } ;
|
Chris@0
|
1080
|
Chris@0
|
1081 /* Seek to start of file. */
|
Chris@0
|
1082 test_seek_or_die (file, 0, SEEK_SET, 0, sfinfo.channels, __LINE__) ;
|
Chris@0
|
1083
|
Chris@0
|
1084 test_read_short_or_die (file, 0, test, 4, __LINE__) ;
|
Chris@0
|
1085 for (k = 0 ; k < 4 ; k++)
|
Chris@0
|
1086 if (INT_ERROR (orig [k], test [k]))
|
Chris@0
|
1087 { printf ("\n\nLine %d : Mono : Incorrect sample A (#%d : 0x%X => 0x%X).\n", __LINE__, k, orig [k], test [k]) ;
|
Chris@0
|
1088 exit (1) ;
|
Chris@0
|
1089 } ;
|
Chris@0
|
1090
|
Chris@0
|
1091 if ((format & SF_FORMAT_SUBMASK) == SF_FORMAT_DWVW_16 ||
|
Chris@0
|
1092 (format & SF_FORMAT_SUBMASK) == SF_FORMAT_DWVW_24)
|
Chris@0
|
1093 { sf_close (file) ;
|
Chris@0
|
1094 unlink (filename) ;
|
Chris@0
|
1095 printf ("no seek : ") ;
|
Chris@0
|
1096 return ;
|
Chris@0
|
1097 } ;
|
Chris@0
|
1098
|
Chris@0
|
1099 /* Seek to offset from start of file. */
|
Chris@0
|
1100 test_seek_or_die (file, items + 10, SEEK_SET, items + 10, sfinfo.channels, __LINE__) ;
|
Chris@0
|
1101
|
Chris@0
|
1102 test_read_short_or_die (file, 0, test + 10, 4, __LINE__) ;
|
Chris@0
|
1103 for (k = 10 ; k < 14 ; k++)
|
Chris@0
|
1104 if (INT_ERROR (orig [k], test [k]))
|
Chris@0
|
1105 { printf ("\n\nLine %d : Mono : Incorrect sample A (#%d : 0x%X => 0x%X).\n", __LINE__, k, test [k], orig [k]) ;
|
Chris@0
|
1106 exit (1) ;
|
Chris@0
|
1107 } ;
|
Chris@0
|
1108
|
Chris@0
|
1109 /* Seek to offset from current position. */
|
Chris@0
|
1110 test_seek_or_die (file, 6, SEEK_CUR, items + 20, sfinfo.channels, __LINE__) ;
|
Chris@0
|
1111
|
Chris@0
|
1112 test_read_short_or_die (file, 0, test + 20, 4, __LINE__) ;
|
Chris@0
|
1113 for (k = 20 ; k < 24 ; k++)
|
Chris@0
|
1114 if (INT_ERROR (orig [k], test [k]))
|
Chris@0
|
1115 { printf ("\n\nLine %d : Mono : Incorrect sample A (#%d : 0x%X => 0x%X).\n", __LINE__, k, test [k], orig [k]) ;
|
Chris@0
|
1116 exit (1) ;
|
Chris@0
|
1117 } ;
|
Chris@0
|
1118
|
Chris@0
|
1119 /* Seek to offset from end of file. */
|
Chris@0
|
1120 test_seek_or_die (file, -1 * (sfinfo.frames - 10), SEEK_END, 10, sfinfo.channels, __LINE__) ;
|
Chris@0
|
1121
|
Chris@0
|
1122 test_read_short_or_die (file, 0, test + 10, 4, __LINE__) ;
|
Chris@0
|
1123 for (k = 10 ; k < 14 ; k++)
|
Chris@0
|
1124 if (INT_ERROR (orig [k], test [k]))
|
Chris@0
|
1125 { printf ("\n\nLine %d : Mono : Incorrect sample D (#%d : 0x%X => 0x%X).\n", __LINE__, k, test [k], orig [k]) ;
|
Chris@0
|
1126 exit (1) ;
|
Chris@0
|
1127 } ;
|
Chris@0
|
1128
|
Chris@0
|
1129 /* Check read past end of file followed by sf_seek (sndfile, 0, SEEK_CUR). */
|
Chris@0
|
1130 test_seek_or_die (file, 0, SEEK_SET, 0, sfinfo.channels, __LINE__) ;
|
Chris@0
|
1131
|
Chris@0
|
1132 count = 0 ;
|
Chris@0
|
1133 while (count < sfinfo.frames)
|
Chris@0
|
1134 count += sf_read_short (file, test, 311) ;
|
Chris@0
|
1135
|
Chris@0
|
1136 /* Check that no error has occurred. */
|
Chris@0
|
1137 if (sf_error (file))
|
Chris@0
|
1138 { printf ("\n\nLine %d : Mono : error where there shouldn't have been one.\n", __LINE__) ;
|
Chris@0
|
1139 puts (sf_strerror (file)) ;
|
Chris@0
|
1140 exit (1) ;
|
Chris@0
|
1141 } ;
|
Chris@0
|
1142
|
Chris@0
|
1143 /* Check that we haven't read beyond EOF. */
|
Chris@0
|
1144 if (count > sfinfo.frames)
|
Chris@0
|
1145 { printf ("\n\nLines %d : read past end of file (%ld should be %ld)\n", __LINE__, (long) count, (long) sfinfo.frames) ;
|
Chris@0
|
1146 exit (1) ;
|
Chris@0
|
1147 } ;
|
Chris@0
|
1148
|
Chris@0
|
1149 test_seek_or_die (file, 0, SEEK_CUR, sfinfo.frames, sfinfo.channels, __LINE__) ;
|
Chris@0
|
1150
|
Chris@0
|
1151 sf_close (file) ;
|
Chris@0
|
1152
|
Chris@0
|
1153 multi_seek_test (filename, format) ;
|
Chris@0
|
1154 write_seek_extend_test (filename, format) ;
|
Chris@0
|
1155
|
Chris@0
|
1156 } /* mono_short_test */
|
Chris@0
|
1157
|
Chris@0
|
1158 static void
|
Chris@0
|
1159 stereo_short_test (const char *filename, int format, int long_file_ok, int allow_fd)
|
Chris@0
|
1160 { SNDFILE *file ;
|
Chris@0
|
1161 SF_INFO sfinfo ;
|
Chris@0
|
1162 short *orig, *test ;
|
Chris@0
|
1163 int k, items, frames ;
|
Chris@0
|
1164
|
Chris@0
|
1165 sfinfo.samplerate = 44100 ;
|
Chris@0
|
1166 sfinfo.frames = SILLY_WRITE_COUNT ; /* Wrong length. Library should correct this on sf_close. */
|
Chris@0
|
1167 sfinfo.channels = 2 ;
|
Chris@0
|
1168 sfinfo.format = format ;
|
Chris@0
|
1169
|
Chris@0
|
1170 gen_windowed_sine_double (orig_data.d, DATA_LENGTH, 32000.0) ;
|
Chris@0
|
1171
|
Chris@0
|
1172 orig = orig_data.s ;
|
Chris@0
|
1173 test = test_data.s ;
|
Chris@0
|
1174
|
Chris@0
|
1175 /* Make this a macro so gdb steps over it in one go. */
|
Chris@0
|
1176 CONVERT_DATA (k, DATA_LENGTH, orig, orig_data.d) ;
|
Chris@0
|
1177
|
Chris@0
|
1178 items = DATA_LENGTH ;
|
Chris@0
|
1179 frames = items / sfinfo.channels ;
|
Chris@0
|
1180
|
Chris@0
|
1181 file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, allow_fd, __LINE__) ;
|
Chris@0
|
1182
|
Chris@0
|
1183 sf_set_string (file, SF_STR_ARTIST, "Your name here") ;
|
Chris@0
|
1184
|
Chris@0
|
1185 test_writef_short_or_die (file, 0, orig, frames, __LINE__) ;
|
Chris@0
|
1186
|
Chris@0
|
1187 sf_set_string (file, SF_STR_COPYRIGHT, "Copyright (c) 2003") ;
|
Chris@0
|
1188
|
Chris@0
|
1189 sf_close (file) ;
|
Chris@0
|
1190
|
Chris@0
|
1191 memset (test, 0, items * sizeof (short)) ;
|
Chris@0
|
1192
|
Chris@0
|
1193 if ((format & SF_FORMAT_TYPEMASK) != SF_FORMAT_RAW)
|
Chris@0
|
1194 memset (&sfinfo, 0, sizeof (sfinfo)) ;
|
Chris@0
|
1195
|
Chris@0
|
1196 file = test_open_file_or_die (filename, SFM_READ, &sfinfo, allow_fd, __LINE__) ;
|
Chris@0
|
1197
|
Chris@0
|
1198 if (sfinfo.format != format)
|
Chris@0
|
1199 { printf ("\n\nLine %d : Stereo : Returned format incorrect (0x%08X => 0x%08X).\n",
|
Chris@0
|
1200 __LINE__, format, sfinfo.format) ;
|
Chris@0
|
1201 exit (1) ;
|
Chris@0
|
1202 } ;
|
Chris@0
|
1203
|
Chris@0
|
1204 if (sfinfo.frames < frames)
|
Chris@0
|
1205 { printf ("\n\nLine %d : Stereo : Incorrect number of frames in file (too short). (%ld should be %d)\n",
|
Chris@0
|
1206 __LINE__, SF_COUNT_TO_LONG (sfinfo.frames), frames) ;
|
Chris@0
|
1207 exit (1) ;
|
Chris@0
|
1208 } ;
|
Chris@0
|
1209
|
Chris@0
|
1210 if (! long_file_ok && sfinfo.frames > frames)
|
Chris@0
|
1211 { printf ("\n\nLine %d : Stereo : Incorrect number of frames in file (too long). (%ld should be %d)\n",
|
Chris@0
|
1212 __LINE__, SF_COUNT_TO_LONG (sfinfo.frames), frames) ;
|
Chris@0
|
1213 exit (1) ;
|
Chris@0
|
1214 } ;
|
Chris@0
|
1215
|
Chris@0
|
1216 if (sfinfo.channels != 2)
|
Chris@0
|
1217 { printf ("\n\nLine %d : Stereo : Incorrect number of channels in file.\n", __LINE__) ;
|
Chris@0
|
1218 exit (1) ;
|
Chris@0
|
1219 } ;
|
Chris@0
|
1220
|
Chris@0
|
1221 check_log_buffer_or_die (file, __LINE__) ;
|
Chris@0
|
1222
|
Chris@0
|
1223 test_readf_short_or_die (file, 0, test, frames, __LINE__) ;
|
Chris@0
|
1224 for (k = 0 ; k < items ; k++)
|
Chris@0
|
1225 if (INT_ERROR (test [k], orig [k]))
|
Chris@0
|
1226 { printf ("\n\nLine %d : Stereo : Incorrect sample (#%d : 0x%X => 0x%X).\n", __LINE__, k, orig [k], test [k]) ;
|
Chris@0
|
1227 exit (1) ;
|
Chris@0
|
1228 } ;
|
Chris@0
|
1229
|
Chris@0
|
1230 /* Seek to start of file. */
|
Chris@0
|
1231 test_seek_or_die (file, 0, SEEK_SET, 0, sfinfo.channels, __LINE__) ;
|
Chris@0
|
1232
|
Chris@0
|
1233 test_readf_short_or_die (file, 0, test, 2, __LINE__) ;
|
Chris@0
|
1234 for (k = 0 ; k < 4 ; k++)
|
Chris@0
|
1235 if (INT_ERROR (test [k], orig [k]))
|
Chris@0
|
1236 { printf ("\n\nLine %d : Stereo : Incorrect sample (#%d : 0x%X => 0x%X).\n", __LINE__, k, orig [k], test [k]) ;
|
Chris@0
|
1237 exit (1) ;
|
Chris@0
|
1238 } ;
|
Chris@0
|
1239
|
Chris@0
|
1240 /* Seek to offset from start of file. */
|
Chris@0
|
1241 test_seek_or_die (file, 10, SEEK_SET, 10, sfinfo.channels, __LINE__) ;
|
Chris@0
|
1242
|
Chris@0
|
1243 /* Check for errors here. */
|
Chris@0
|
1244 if (sf_error (file))
|
Chris@0
|
1245 { printf ("Line %d: Should NOT return an error.\n", __LINE__) ;
|
Chris@0
|
1246 puts (sf_strerror (file)) ;
|
Chris@0
|
1247 exit (1) ;
|
Chris@0
|
1248 } ;
|
Chris@0
|
1249
|
Chris@0
|
1250 if (sf_read_short (file, test, 1) > 0)
|
Chris@0
|
1251 { printf ("Line %d: Should return 0.\n", __LINE__) ;
|
Chris@0
|
1252 exit (1) ;
|
Chris@0
|
1253 } ;
|
Chris@0
|
1254
|
Chris@0
|
1255 if (! sf_error (file))
|
Chris@0
|
1256 { printf ("Line %d: Should return an error.\n", __LINE__) ;
|
Chris@0
|
1257 exit (1) ;
|
Chris@0
|
1258 } ;
|
Chris@0
|
1259 /*-----------------------*/
|
Chris@0
|
1260
|
Chris@0
|
1261 test_readf_short_or_die (file, 0, test + 10, 2, __LINE__) ;
|
Chris@0
|
1262 for (k = 20 ; k < 24 ; k++)
|
Chris@0
|
1263 if (INT_ERROR (test [k], orig [k]))
|
Chris@0
|
1264 { printf ("\n\nLine %d : Stereo : Incorrect sample (#%d : 0x%X => 0x%X).\n", __LINE__, k, orig [k], test [k]) ;
|
Chris@0
|
1265 exit (1) ;
|
Chris@0
|
1266 } ;
|
Chris@0
|
1267
|
Chris@0
|
1268 /* Seek to offset from current position. */
|
Chris@0
|
1269 test_seek_or_die (file, 8, SEEK_CUR, 20, sfinfo.channels, __LINE__) ;
|
Chris@0
|
1270
|
Chris@0
|
1271 test_readf_short_or_die (file, 0, test + 20, 2, __LINE__) ;
|
Chris@0
|
1272 for (k = 40 ; k < 44 ; k++)
|
Chris@0
|
1273 if (INT_ERROR (test [k], orig [k]))
|
Chris@0
|
1274 { printf ("\n\nLine %d : Stereo : Incorrect sample (#%d : 0x%X => 0x%X).\n", __LINE__, k, orig [k], test [k]) ;
|
Chris@0
|
1275 exit (1) ;
|
Chris@0
|
1276 } ;
|
Chris@0
|
1277
|
Chris@0
|
1278 /* Seek to offset from end of file. */
|
Chris@0
|
1279 test_seek_or_die (file, -1 * (sfinfo.frames - 10), SEEK_END, 10, sfinfo.channels, __LINE__) ;
|
Chris@0
|
1280
|
Chris@0
|
1281 test_readf_short_or_die (file, 0, test + 20, 2, __LINE__) ;
|
Chris@0
|
1282 for (k = 20 ; k < 24 ; k++)
|
Chris@0
|
1283 if (INT_ERROR (test [k], orig [k]))
|
Chris@0
|
1284 { printf ("\n\nLine %d : Stereo : Incorrect sample (#%d : 0x%X => 0x%X).\n", __LINE__, k, orig [k], test [k]) ;
|
Chris@0
|
1285 exit (1) ;
|
Chris@0
|
1286 } ;
|
Chris@0
|
1287
|
Chris@0
|
1288 sf_close (file) ;
|
Chris@0
|
1289 } /* stereo_short_test */
|
Chris@0
|
1290
|
Chris@0
|
1291 static void
|
Chris@0
|
1292 mono_rdwr_short_test (const char *filename, int format, int long_file_ok, int allow_fd)
|
Chris@0
|
1293 { SNDFILE *file ;
|
Chris@0
|
1294 SF_INFO sfinfo ;
|
Chris@0
|
1295 short *orig, *test ;
|
Chris@0
|
1296 int k, pass ;
|
Chris@0
|
1297
|
Chris@0
|
1298 orig = orig_data.s ;
|
Chris@0
|
1299 test = test_data.s ;
|
Chris@0
|
1300
|
Chris@0
|
1301 sfinfo.samplerate = SAMPLE_RATE ;
|
Chris@0
|
1302 sfinfo.frames = DATA_LENGTH ;
|
Chris@0
|
1303 sfinfo.channels = 1 ;
|
Chris@0
|
1304 sfinfo.format = format ;
|
Chris@0
|
1305
|
Chris@0
|
1306 if ((format & SF_FORMAT_TYPEMASK) == SF_FORMAT_RAW
|
Chris@0
|
1307 || (format & SF_FORMAT_TYPEMASK) == SF_FORMAT_AU
|
Chris@0
|
1308 || (format & SF_FORMAT_TYPEMASK) == SF_FORMAT_SD2)
|
Chris@0
|
1309 unlink (filename) ;
|
Chris@0
|
1310 else
|
Chris@0
|
1311 { /* Create a short file. */
|
Chris@0
|
1312 create_short_file (filename) ;
|
Chris@0
|
1313
|
Chris@0
|
1314 /* Opening a already existing short file (ie invalid header) RDWR is disallowed.
|
Chris@0
|
1315 ** If this returns a valif pointer sf_open() screwed up.
|
Chris@0
|
1316 */
|
Chris@0
|
1317 if ((file = sf_open (filename, SFM_RDWR, &sfinfo)))
|
Chris@0
|
1318 { printf ("\n\nLine %d: sf_open should (SFM_RDWR) have failed but didn't.\n", __LINE__) ;
|
Chris@0
|
1319 exit (1) ;
|
Chris@0
|
1320 } ;
|
Chris@0
|
1321
|
Chris@0
|
1322 /* Truncate the file to zero bytes. */
|
Chris@0
|
1323 if (truncate (filename, 0) < 0)
|
Chris@0
|
1324 { printf ("\n\nLine %d: truncate (%s) failed", __LINE__, filename) ;
|
Chris@0
|
1325 perror (NULL) ;
|
Chris@0
|
1326 exit (1) ;
|
Chris@0
|
1327 } ;
|
Chris@0
|
1328 } ;
|
Chris@0
|
1329
|
Chris@0
|
1330 /* Opening a zero length file RDWR is allowed, but the SF_INFO struct must contain
|
Chris@0
|
1331 ** all the usual data required when opening the file in WRITE mode.
|
Chris@0
|
1332 */
|
Chris@0
|
1333 sfinfo.samplerate = SAMPLE_RATE ;
|
Chris@0
|
1334 sfinfo.frames = DATA_LENGTH ;
|
Chris@0
|
1335 sfinfo.channels = 1 ;
|
Chris@0
|
1336 sfinfo.format = format ;
|
Chris@0
|
1337
|
Chris@0
|
1338 file = test_open_file_or_die (filename, SFM_RDWR, &sfinfo, allow_fd, __LINE__) ;
|
Chris@0
|
1339
|
Chris@0
|
1340 /* Do 3 writes followed by reads. After each, check the data and the current
|
Chris@0
|
1341 ** read and write offsets.
|
Chris@0
|
1342 */
|
Chris@0
|
1343 for (pass = 1 ; pass <= 3 ; pass ++)
|
Chris@0
|
1344 { orig [20] = pass * 2 ;
|
Chris@0
|
1345
|
Chris@0
|
1346 /* Write some data. */
|
Chris@0
|
1347 test_write_short_or_die (file, pass, orig, DATA_LENGTH, __LINE__) ;
|
Chris@0
|
1348
|
Chris@0
|
1349 test_read_write_position_or_die (file, __LINE__, pass, (pass - 1) * DATA_LENGTH, pass * DATA_LENGTH) ;
|
Chris@0
|
1350
|
Chris@0
|
1351 /* Read what we just wrote. */
|
Chris@0
|
1352 test_read_short_or_die (file, 0, test, DATA_LENGTH, __LINE__) ;
|
Chris@0
|
1353
|
Chris@0
|
1354 /* Check the data. */
|
Chris@0
|
1355 for (k = 0 ; k < DATA_LENGTH ; k++)
|
Chris@0
|
1356 if (INT_ERROR (orig [k], test [k]))
|
Chris@0
|
1357 { printf ("\n\nLine %d (pass %d) A : Error at sample %d (0x%X => 0x%X).\n", __LINE__, pass, k, orig [k], test [k]) ;
|
Chris@0
|
1358 oct_save_short (orig, test, DATA_LENGTH) ;
|
Chris@0
|
1359 exit (1) ;
|
Chris@0
|
1360 } ;
|
Chris@0
|
1361
|
Chris@0
|
1362 test_read_write_position_or_die (file, __LINE__, pass, pass * DATA_LENGTH, pass * DATA_LENGTH) ;
|
Chris@0
|
1363 } ; /* for (pass ...) */
|
Chris@0
|
1364
|
Chris@0
|
1365 sf_close (file) ;
|
Chris@0
|
1366
|
Chris@0
|
1367 /* Open the file again to check the data. */
|
Chris@0
|
1368 file = test_open_file_or_die (filename, SFM_RDWR, &sfinfo, allow_fd, __LINE__) ;
|
Chris@0
|
1369
|
Chris@0
|
1370 if (sfinfo.format != format)
|
Chris@0
|
1371 { printf ("\n\nLine %d : Returned format incorrect (0x%08X => 0x%08X).\n", __LINE__, format, sfinfo.format) ;
|
Chris@0
|
1372 exit (1) ;
|
Chris@0
|
1373 } ;
|
Chris@0
|
1374
|
Chris@0
|
1375 if (sfinfo.frames < 3 * DATA_LENGTH)
|
Chris@0
|
1376 { printf ("\n\nLine %d : Not enough frames in file. (%ld < %d)\n", __LINE__, SF_COUNT_TO_LONG (sfinfo.frames), 3 * DATA_LENGTH ) ;
|
Chris@0
|
1377 exit (1) ;
|
Chris@0
|
1378 }
|
Chris@0
|
1379
|
Chris@0
|
1380 if (! long_file_ok && sfinfo.frames != 3 * DATA_LENGTH)
|
Chris@0
|
1381 { printf ("\n\nLine %d : Incorrect number of frames in file. (%ld should be %d)\n", __LINE__, SF_COUNT_TO_LONG (sfinfo.frames), 3 * DATA_LENGTH ) ;
|
Chris@0
|
1382 exit (1) ;
|
Chris@0
|
1383 } ;
|
Chris@0
|
1384
|
Chris@0
|
1385 if (sfinfo.channels != 1)
|
Chris@0
|
1386 { printf ("\n\nLine %d : Incorrect number of channels in file.\n", __LINE__) ;
|
Chris@0
|
1387 exit (1) ;
|
Chris@0
|
1388 } ;
|
Chris@0
|
1389
|
Chris@0
|
1390 if (! long_file_ok)
|
Chris@0
|
1391 test_read_write_position_or_die (file, __LINE__, 0, 0, 3 * DATA_LENGTH) ;
|
Chris@0
|
1392 else
|
Chris@0
|
1393 test_seek_or_die (file, 3 * DATA_LENGTH, SFM_WRITE | SEEK_SET, 3 * DATA_LENGTH, sfinfo.channels, __LINE__) ;
|
Chris@0
|
1394
|
Chris@0
|
1395 for (pass = 1 ; pass <= 3 ; pass ++)
|
Chris@0
|
1396 { orig [20] = pass * 2 ;
|
Chris@0
|
1397
|
Chris@0
|
1398 test_read_write_position_or_die (file, __LINE__, pass, (pass - 1) * DATA_LENGTH, 3 * DATA_LENGTH) ;
|
Chris@0
|
1399
|
Chris@0
|
1400 /* Read what we just wrote. */
|
Chris@0
|
1401 test_read_short_or_die (file, pass, test, DATA_LENGTH, __LINE__) ;
|
Chris@0
|
1402
|
Chris@0
|
1403 /* Check the data. */
|
Chris@0
|
1404 for (k = 0 ; k < DATA_LENGTH ; k++)
|
Chris@0
|
1405 if (INT_ERROR (orig [k], test [k]))
|
Chris@0
|
1406 { printf ("\n\nLine %d (pass %d) B : Error at sample %d (0x%X => 0x%X).\n", __LINE__, pass, k, orig [k], test [k]) ;
|
Chris@0
|
1407 oct_save_short (orig, test, DATA_LENGTH) ;
|
Chris@0
|
1408 exit (1) ;
|
Chris@0
|
1409 } ;
|
Chris@0
|
1410
|
Chris@0
|
1411 } ; /* for (pass ...) */
|
Chris@0
|
1412
|
Chris@0
|
1413 sf_close (file) ;
|
Chris@0
|
1414 } /* mono_rdwr_short_test */
|
Chris@0
|
1415
|
Chris@0
|
1416 static void
|
Chris@0
|
1417 new_rdwr_short_test (const char *filename, int format, int allow_fd)
|
Chris@0
|
1418 { SNDFILE *wfile, *rwfile ;
|
Chris@0
|
1419 SF_INFO sfinfo ;
|
Chris@0
|
1420 short *orig, *test ;
|
Chris@0
|
1421 int items, frames ;
|
Chris@0
|
1422
|
Chris@0
|
1423 orig = orig_data.s ;
|
Chris@0
|
1424 test = test_data.s ;
|
Chris@0
|
1425
|
Chris@0
|
1426 sfinfo.samplerate = 44100 ;
|
Chris@0
|
1427 sfinfo.frames = SILLY_WRITE_COUNT ; /* Wrong length. Library should correct this on sf_close. */
|
Chris@0
|
1428 sfinfo.channels = 2 ;
|
Chris@0
|
1429 sfinfo.format = format ;
|
Chris@0
|
1430
|
Chris@0
|
1431 items = DATA_LENGTH ;
|
Chris@0
|
1432 frames = items / sfinfo.channels ;
|
Chris@0
|
1433
|
Chris@0
|
1434 wfile = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, allow_fd, __LINE__) ;
|
Chris@0
|
1435 sf_command (wfile, SFC_SET_UPDATE_HEADER_AUTO, NULL, SF_TRUE) ;
|
Chris@0
|
1436 test_writef_short_or_die (wfile, 1, orig, frames, __LINE__) ;
|
Chris@0
|
1437 sf_write_sync (wfile) ;
|
Chris@0
|
1438 test_writef_short_or_die (wfile, 2, orig, frames, __LINE__) ;
|
Chris@0
|
1439 sf_write_sync (wfile) ;
|
Chris@0
|
1440
|
Chris@0
|
1441 rwfile = test_open_file_or_die (filename, SFM_RDWR, &sfinfo, allow_fd, __LINE__) ;
|
Chris@0
|
1442 if (sfinfo.frames != 2 * frames)
|
Chris@0
|
1443 { printf ("\n\nLine %d : incorrect number of frames in file (%ld should be %d)\n\n", __LINE__, SF_COUNT_TO_LONG (sfinfo.frames), 2 * frames) ;
|
Chris@0
|
1444 exit (1) ;
|
Chris@0
|
1445 } ;
|
Chris@0
|
1446
|
Chris@0
|
1447 test_writef_short_or_die (wfile, 3, orig, frames, __LINE__) ;
|
Chris@0
|
1448
|
Chris@0
|
1449 test_readf_short_or_die (rwfile, 1, test, frames, __LINE__) ;
|
Chris@0
|
1450 test_readf_short_or_die (rwfile, 2, test, frames, __LINE__) ;
|
Chris@0
|
1451
|
Chris@0
|
1452 sf_close (wfile) ;
|
Chris@0
|
1453 sf_close (rwfile) ;
|
Chris@0
|
1454 } /* new_rdwr_short_test */
|
Chris@0
|
1455
|
Chris@0
|
1456
|
Chris@0
|
1457 /*======================================================================================
|
Chris@0
|
1458 */
|
Chris@0
|
1459
|
Chris@0
|
1460 static void mono_24bit_test (const char *filename, int format, int long_file_ok, int allow_fd) ;
|
Chris@0
|
1461 static void stereo_24bit_test (const char *filename, int format, int long_file_ok, int allow_fd) ;
|
Chris@0
|
1462 static void mono_rdwr_24bit_test (const char *filename, int format, int long_file_ok, int allow_fd) ;
|
Chris@0
|
1463 static void new_rdwr_24bit_test (const char *filename, int format, int allow_fd) ;
|
Chris@0
|
1464 static void multi_seek_test (const char * filename, int format) ;
|
Chris@0
|
1465 static void write_seek_extend_test (const char * filename, int format) ;
|
Chris@0
|
1466
|
Chris@0
|
1467 static void
|
Chris@0
|
1468 pcm_test_24bit (const char *filename, int format, int long_file_ok)
|
Chris@0
|
1469 { SF_INFO sfinfo ;
|
Chris@0
|
1470 int *orig ;
|
Chris@0
|
1471 int k, allow_fd ;
|
Chris@0
|
1472
|
Chris@0
|
1473 /* Sd2 files cannot be opened from an existing file descriptor. */
|
Chris@0
|
1474 allow_fd = ((format & SF_FORMAT_TYPEMASK) == SF_FORMAT_SD2) ? SF_FALSE : SF_TRUE ;
|
Chris@0
|
1475
|
Chris@0
|
1476 print_test_name ("pcm_test_24bit", filename) ;
|
Chris@0
|
1477
|
Chris@0
|
1478 sfinfo.samplerate = 44100 ;
|
Chris@0
|
1479 sfinfo.frames = SILLY_WRITE_COUNT ; /* Wrong length. Library should correct this on sf_close. */
|
Chris@0
|
1480 sfinfo.channels = 1 ;
|
Chris@0
|
1481 sfinfo.format = format ;
|
Chris@0
|
1482
|
Chris@0
|
1483 gen_windowed_sine_double (orig_data.d, DATA_LENGTH, (1.0 * 0x7F000000)) ;
|
Chris@0
|
1484
|
Chris@0
|
1485 orig = orig_data.i ;
|
Chris@0
|
1486
|
Chris@0
|
1487 /* Make this a macro so gdb steps over it in one go. */
|
Chris@0
|
1488 CONVERT_DATA (k, DATA_LENGTH, orig, orig_data.d) ;
|
Chris@0
|
1489
|
Chris@0
|
1490 /* Some test broken out here. */
|
Chris@0
|
1491
|
Chris@0
|
1492 mono_24bit_test (filename, format, long_file_ok, allow_fd) ;
|
Chris@0
|
1493
|
Chris@0
|
1494 /* Sub format DWVW does not allow seeking. */
|
Chris@0
|
1495 if ((format & SF_FORMAT_SUBMASK) == SF_FORMAT_DWVW_16 ||
|
Chris@0
|
1496 (format & SF_FORMAT_SUBMASK) == SF_FORMAT_DWVW_24)
|
Chris@0
|
1497 { unlink (filename) ;
|
Chris@0
|
1498 printf ("no seek : ok\n") ;
|
Chris@0
|
1499 return ;
|
Chris@0
|
1500 } ;
|
Chris@0
|
1501
|
Chris@0
|
1502 if ((format & SF_FORMAT_TYPEMASK) != SF_FORMAT_FLAC)
|
Chris@0
|
1503 mono_rdwr_24bit_test (filename, format, long_file_ok, allow_fd) ;
|
Chris@0
|
1504
|
Chris@0
|
1505 /* If the format doesn't support stereo we're done. */
|
Chris@0
|
1506 sfinfo.channels = 2 ;
|
Chris@0
|
1507 if (sf_format_check (&sfinfo) == 0)
|
Chris@0
|
1508 { unlink (filename) ;
|
Chris@0
|
1509 puts ("no stereo : ok") ;
|
Chris@0
|
1510 return ;
|
Chris@0
|
1511 } ;
|
Chris@0
|
1512
|
Chris@0
|
1513 stereo_24bit_test (filename, format, long_file_ok, allow_fd) ;
|
Chris@0
|
1514
|
Chris@0
|
1515 /* New read/write test. Not sure if this is needed yet. */
|
Chris@0
|
1516
|
Chris@0
|
1517 if ((format & SF_FORMAT_TYPEMASK) != SF_FORMAT_PAF &&
|
Chris@0
|
1518 (format & SF_FORMAT_TYPEMASK) != SF_FORMAT_VOC &&
|
Chris@0
|
1519 (format & SF_FORMAT_TYPEMASK) != SF_FORMAT_FLAC)
|
Chris@0
|
1520 new_rdwr_24bit_test (filename, format, allow_fd) ;
|
Chris@0
|
1521
|
Chris@0
|
1522 delete_file (format, filename) ;
|
Chris@0
|
1523
|
Chris@0
|
1524 puts ("ok") ;
|
Chris@0
|
1525 return ;
|
Chris@0
|
1526 } /* pcm_test_24bit */
|
Chris@0
|
1527
|
Chris@0
|
1528 static void
|
Chris@0
|
1529 mono_24bit_test (const char *filename, int format, int long_file_ok, int allow_fd)
|
Chris@0
|
1530 { SNDFILE *file ;
|
Chris@0
|
1531 SF_INFO sfinfo ;
|
Chris@0
|
1532 int *orig, *test ;
|
Chris@0
|
1533 sf_count_t count ;
|
Chris@0
|
1534 int k, items ;
|
Chris@0
|
1535
|
Chris@0
|
1536 sfinfo.samplerate = 44100 ;
|
Chris@0
|
1537 sfinfo.frames = SILLY_WRITE_COUNT ; /* Wrong length. Library should correct this on sf_close. */
|
Chris@0
|
1538 sfinfo.channels = 1 ;
|
Chris@0
|
1539 sfinfo.format = format ;
|
Chris@0
|
1540
|
Chris@0
|
1541 orig = orig_data.i ;
|
Chris@0
|
1542 test = test_data.i ;
|
Chris@0
|
1543
|
Chris@0
|
1544 items = DATA_LENGTH ;
|
Chris@0
|
1545
|
Chris@0
|
1546 file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, allow_fd, __LINE__) ;
|
Chris@0
|
1547
|
Chris@0
|
1548 sf_set_string (file, SF_STR_ARTIST, "Your name here") ;
|
Chris@0
|
1549
|
Chris@0
|
1550 test_write_int_or_die (file, 0, orig, items, __LINE__) ;
|
Chris@0
|
1551 sf_write_sync (file) ;
|
Chris@0
|
1552 test_write_int_or_die (file, 0, orig, items, __LINE__) ;
|
Chris@0
|
1553 sf_write_sync (file) ;
|
Chris@0
|
1554
|
Chris@0
|
1555 /* Add non-audio data after the audio. */
|
Chris@0
|
1556 sf_set_string (file, SF_STR_COPYRIGHT, "Copyright (c) 2003") ;
|
Chris@0
|
1557
|
Chris@0
|
1558 sf_close (file) ;
|
Chris@0
|
1559
|
Chris@0
|
1560 memset (test, 0, items * sizeof (int)) ;
|
Chris@0
|
1561
|
Chris@0
|
1562 if ((format & SF_FORMAT_TYPEMASK) != SF_FORMAT_RAW)
|
Chris@0
|
1563 memset (&sfinfo, 0, sizeof (sfinfo)) ;
|
Chris@0
|
1564
|
Chris@0
|
1565 file = test_open_file_or_die (filename, SFM_READ, &sfinfo, allow_fd, __LINE__) ;
|
Chris@0
|
1566
|
Chris@0
|
1567 if (sfinfo.format != format)
|
Chris@0
|
1568 { printf ("\n\nLine %d : Mono : Returned format incorrect (0x%08X => 0x%08X).\n", __LINE__, format, sfinfo.format) ;
|
Chris@0
|
1569 exit (1) ;
|
Chris@0
|
1570 } ;
|
Chris@0
|
1571
|
Chris@0
|
1572 if (sfinfo.frames < 2 * items)
|
Chris@0
|
1573 { printf ("\n\nLine %d : Mono : Incorrect number of frames in file (too short). (%ld should be %d)\n", __LINE__, SF_COUNT_TO_LONG (sfinfo.frames), items) ;
|
Chris@0
|
1574 exit (1) ;
|
Chris@0
|
1575 } ;
|
Chris@0
|
1576
|
Chris@0
|
1577 if (! long_file_ok && sfinfo.frames > 2 * items)
|
Chris@0
|
1578 { printf ("\n\nLine %d : Mono : Incorrect number of frames in file (too long). (%ld should be %d)\n", __LINE__, SF_COUNT_TO_LONG (sfinfo.frames), items) ;
|
Chris@0
|
1579 exit (1) ;
|
Chris@0
|
1580 } ;
|
Chris@0
|
1581
|
Chris@0
|
1582 if (sfinfo.channels != 1)
|
Chris@0
|
1583 { printf ("\n\nLine %d : Mono : Incorrect number of channels in file.\n", __LINE__) ;
|
Chris@0
|
1584 exit (1) ;
|
Chris@0
|
1585 } ;
|
Chris@0
|
1586
|
Chris@0
|
1587 check_log_buffer_or_die (file, __LINE__) ;
|
Chris@0
|
1588
|
Chris@0
|
1589 test_read_int_or_die (file, 0, test, items, __LINE__) ;
|
Chris@0
|
1590 for (k = 0 ; k < items ; k++)
|
Chris@0
|
1591 if (TRIBYTE_ERROR (orig [k], test [k]))
|
Chris@0
|
1592 { printf ("\n\nLine %d: Mono : Incorrect sample A (#%d : 0x%X => 0x%X).\n", __LINE__, k, orig [k], test [k]) ;
|
Chris@0
|
1593 oct_save_int (orig, test, items) ;
|
Chris@0
|
1594 exit (1) ;
|
Chris@0
|
1595 } ;
|
Chris@0
|
1596
|
Chris@0
|
1597 /* Seek to start of file. */
|
Chris@0
|
1598 test_seek_or_die (file, 0, SEEK_SET, 0, sfinfo.channels, __LINE__) ;
|
Chris@0
|
1599
|
Chris@0
|
1600 test_read_int_or_die (file, 0, test, 4, __LINE__) ;
|
Chris@0
|
1601 for (k = 0 ; k < 4 ; k++)
|
Chris@0
|
1602 if (TRIBYTE_ERROR (orig [k], test [k]))
|
Chris@0
|
1603 { printf ("\n\nLine %d : Mono : Incorrect sample A (#%d : 0x%X => 0x%X).\n", __LINE__, k, orig [k], test [k]) ;
|
Chris@0
|
1604 exit (1) ;
|
Chris@0
|
1605 } ;
|
Chris@0
|
1606
|
Chris@0
|
1607 if ((format & SF_FORMAT_SUBMASK) == SF_FORMAT_DWVW_16 ||
|
Chris@0
|
1608 (format & SF_FORMAT_SUBMASK) == SF_FORMAT_DWVW_24)
|
Chris@0
|
1609 { sf_close (file) ;
|
Chris@0
|
1610 unlink (filename) ;
|
Chris@0
|
1611 printf ("no seek : ") ;
|
Chris@0
|
1612 return ;
|
Chris@0
|
1613 } ;
|
Chris@0
|
1614
|
Chris@0
|
1615 /* Seek to offset from start of file. */
|
Chris@0
|
1616 test_seek_or_die (file, items + 10, SEEK_SET, items + 10, sfinfo.channels, __LINE__) ;
|
Chris@0
|
1617
|
Chris@0
|
1618 test_read_int_or_die (file, 0, test + 10, 4, __LINE__) ;
|
Chris@0
|
1619 for (k = 10 ; k < 14 ; k++)
|
Chris@0
|
1620 if (TRIBYTE_ERROR (orig [k], test [k]))
|
Chris@0
|
1621 { printf ("\n\nLine %d : Mono : Incorrect sample A (#%d : 0x%X => 0x%X).\n", __LINE__, k, test [k], orig [k]) ;
|
Chris@0
|
1622 exit (1) ;
|
Chris@0
|
1623 } ;
|
Chris@0
|
1624
|
Chris@0
|
1625 /* Seek to offset from current position. */
|
Chris@0
|
1626 test_seek_or_die (file, 6, SEEK_CUR, items + 20, sfinfo.channels, __LINE__) ;
|
Chris@0
|
1627
|
Chris@0
|
1628 test_read_int_or_die (file, 0, test + 20, 4, __LINE__) ;
|
Chris@0
|
1629 for (k = 20 ; k < 24 ; k++)
|
Chris@0
|
1630 if (TRIBYTE_ERROR (orig [k], test [k]))
|
Chris@0
|
1631 { printf ("\n\nLine %d : Mono : Incorrect sample A (#%d : 0x%X => 0x%X).\n", __LINE__, k, test [k], orig [k]) ;
|
Chris@0
|
1632 exit (1) ;
|
Chris@0
|
1633 } ;
|
Chris@0
|
1634
|
Chris@0
|
1635 /* Seek to offset from end of file. */
|
Chris@0
|
1636 test_seek_or_die (file, -1 * (sfinfo.frames - 10), SEEK_END, 10, sfinfo.channels, __LINE__) ;
|
Chris@0
|
1637
|
Chris@0
|
1638 test_read_int_or_die (file, 0, test + 10, 4, __LINE__) ;
|
Chris@0
|
1639 for (k = 10 ; k < 14 ; k++)
|
Chris@0
|
1640 if (TRIBYTE_ERROR (orig [k], test [k]))
|
Chris@0
|
1641 { printf ("\n\nLine %d : Mono : Incorrect sample D (#%d : 0x%X => 0x%X).\n", __LINE__, k, test [k], orig [k]) ;
|
Chris@0
|
1642 exit (1) ;
|
Chris@0
|
1643 } ;
|
Chris@0
|
1644
|
Chris@0
|
1645 /* Check read past end of file followed by sf_seek (sndfile, 0, SEEK_CUR). */
|
Chris@0
|
1646 test_seek_or_die (file, 0, SEEK_SET, 0, sfinfo.channels, __LINE__) ;
|
Chris@0
|
1647
|
Chris@0
|
1648 count = 0 ;
|
Chris@0
|
1649 while (count < sfinfo.frames)
|
Chris@0
|
1650 count += sf_read_int (file, test, 311) ;
|
Chris@0
|
1651
|
Chris@0
|
1652 /* Check that no error has occurred. */
|
Chris@0
|
1653 if (sf_error (file))
|
Chris@0
|
1654 { printf ("\n\nLine %d : Mono : error where there shouldn't have been one.\n", __LINE__) ;
|
Chris@0
|
1655 puts (sf_strerror (file)) ;
|
Chris@0
|
1656 exit (1) ;
|
Chris@0
|
1657 } ;
|
Chris@0
|
1658
|
Chris@0
|
1659 /* Check that we haven't read beyond EOF. */
|
Chris@0
|
1660 if (count > sfinfo.frames)
|
Chris@0
|
1661 { printf ("\n\nLines %d : read past end of file (%ld should be %ld)\n", __LINE__, (long) count, (long) sfinfo.frames) ;
|
Chris@0
|
1662 exit (1) ;
|
Chris@0
|
1663 } ;
|
Chris@0
|
1664
|
Chris@0
|
1665 test_seek_or_die (file, 0, SEEK_CUR, sfinfo.frames, sfinfo.channels, __LINE__) ;
|
Chris@0
|
1666
|
Chris@0
|
1667 sf_close (file) ;
|
Chris@0
|
1668
|
Chris@0
|
1669 multi_seek_test (filename, format) ;
|
Chris@0
|
1670 write_seek_extend_test (filename, format) ;
|
Chris@0
|
1671
|
Chris@0
|
1672 } /* mono_24bit_test */
|
Chris@0
|
1673
|
Chris@0
|
1674 static void
|
Chris@0
|
1675 stereo_24bit_test (const char *filename, int format, int long_file_ok, int allow_fd)
|
Chris@0
|
1676 { SNDFILE *file ;
|
Chris@0
|
1677 SF_INFO sfinfo ;
|
Chris@0
|
1678 int *orig, *test ;
|
Chris@0
|
1679 int k, items, frames ;
|
Chris@0
|
1680
|
Chris@0
|
1681 sfinfo.samplerate = 44100 ;
|
Chris@0
|
1682 sfinfo.frames = SILLY_WRITE_COUNT ; /* Wrong length. Library should correct this on sf_close. */
|
Chris@0
|
1683 sfinfo.channels = 2 ;
|
Chris@0
|
1684 sfinfo.format = format ;
|
Chris@0
|
1685
|
Chris@0
|
1686 gen_windowed_sine_double (orig_data.d, DATA_LENGTH, (1.0 * 0x7F000000)) ;
|
Chris@0
|
1687
|
Chris@0
|
1688 orig = orig_data.i ;
|
Chris@0
|
1689 test = test_data.i ;
|
Chris@0
|
1690
|
Chris@0
|
1691 /* Make this a macro so gdb steps over it in one go. */
|
Chris@0
|
1692 CONVERT_DATA (k, DATA_LENGTH, orig, orig_data.d) ;
|
Chris@0
|
1693
|
Chris@0
|
1694 items = DATA_LENGTH ;
|
Chris@0
|
1695 frames = items / sfinfo.channels ;
|
Chris@0
|
1696
|
Chris@0
|
1697 file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, allow_fd, __LINE__) ;
|
Chris@0
|
1698
|
Chris@0
|
1699 sf_set_string (file, SF_STR_ARTIST, "Your name here") ;
|
Chris@0
|
1700
|
Chris@0
|
1701 test_writef_int_or_die (file, 0, orig, frames, __LINE__) ;
|
Chris@0
|
1702
|
Chris@0
|
1703 sf_set_string (file, SF_STR_COPYRIGHT, "Copyright (c) 2003") ;
|
Chris@0
|
1704
|
Chris@0
|
1705 sf_close (file) ;
|
Chris@0
|
1706
|
Chris@0
|
1707 memset (test, 0, items * sizeof (int)) ;
|
Chris@0
|
1708
|
Chris@0
|
1709 if ((format & SF_FORMAT_TYPEMASK) != SF_FORMAT_RAW)
|
Chris@0
|
1710 memset (&sfinfo, 0, sizeof (sfinfo)) ;
|
Chris@0
|
1711
|
Chris@0
|
1712 file = test_open_file_or_die (filename, SFM_READ, &sfinfo, allow_fd, __LINE__) ;
|
Chris@0
|
1713
|
Chris@0
|
1714 if (sfinfo.format != format)
|
Chris@0
|
1715 { printf ("\n\nLine %d : Stereo : Returned format incorrect (0x%08X => 0x%08X).\n",
|
Chris@0
|
1716 __LINE__, format, sfinfo.format) ;
|
Chris@0
|
1717 exit (1) ;
|
Chris@0
|
1718 } ;
|
Chris@0
|
1719
|
Chris@0
|
1720 if (sfinfo.frames < frames)
|
Chris@0
|
1721 { printf ("\n\nLine %d : Stereo : Incorrect number of frames in file (too short). (%ld should be %d)\n",
|
Chris@0
|
1722 __LINE__, SF_COUNT_TO_LONG (sfinfo.frames), frames) ;
|
Chris@0
|
1723 exit (1) ;
|
Chris@0
|
1724 } ;
|
Chris@0
|
1725
|
Chris@0
|
1726 if (! long_file_ok && sfinfo.frames > frames)
|
Chris@0
|
1727 { printf ("\n\nLine %d : Stereo : Incorrect number of frames in file (too long). (%ld should be %d)\n",
|
Chris@0
|
1728 __LINE__, SF_COUNT_TO_LONG (sfinfo.frames), frames) ;
|
Chris@0
|
1729 exit (1) ;
|
Chris@0
|
1730 } ;
|
Chris@0
|
1731
|
Chris@0
|
1732 if (sfinfo.channels != 2)
|
Chris@0
|
1733 { printf ("\n\nLine %d : Stereo : Incorrect number of channels in file.\n", __LINE__) ;
|
Chris@0
|
1734 exit (1) ;
|
Chris@0
|
1735 } ;
|
Chris@0
|
1736
|
Chris@0
|
1737 check_log_buffer_or_die (file, __LINE__) ;
|
Chris@0
|
1738
|
Chris@0
|
1739 test_readf_int_or_die (file, 0, test, frames, __LINE__) ;
|
Chris@0
|
1740 for (k = 0 ; k < items ; k++)
|
Chris@0
|
1741 if (TRIBYTE_ERROR (test [k], orig [k]))
|
Chris@0
|
1742 { printf ("\n\nLine %d : Stereo : Incorrect sample (#%d : 0x%X => 0x%X).\n", __LINE__, k, orig [k], test [k]) ;
|
Chris@0
|
1743 exit (1) ;
|
Chris@0
|
1744 } ;
|
Chris@0
|
1745
|
Chris@0
|
1746 /* Seek to start of file. */
|
Chris@0
|
1747 test_seek_or_die (file, 0, SEEK_SET, 0, sfinfo.channels, __LINE__) ;
|
Chris@0
|
1748
|
Chris@0
|
1749 test_readf_int_or_die (file, 0, test, 2, __LINE__) ;
|
Chris@0
|
1750 for (k = 0 ; k < 4 ; k++)
|
Chris@0
|
1751 if (TRIBYTE_ERROR (test [k], orig [k]))
|
Chris@0
|
1752 { printf ("\n\nLine %d : Stereo : Incorrect sample (#%d : 0x%X => 0x%X).\n", __LINE__, k, orig [k], test [k]) ;
|
Chris@0
|
1753 exit (1) ;
|
Chris@0
|
1754 } ;
|
Chris@0
|
1755
|
Chris@0
|
1756 /* Seek to offset from start of file. */
|
Chris@0
|
1757 test_seek_or_die (file, 10, SEEK_SET, 10, sfinfo.channels, __LINE__) ;
|
Chris@0
|
1758
|
Chris@0
|
1759 /* Check for errors here. */
|
Chris@0
|
1760 if (sf_error (file))
|
Chris@0
|
1761 { printf ("Line %d: Should NOT return an error.\n", __LINE__) ;
|
Chris@0
|
1762 puts (sf_strerror (file)) ;
|
Chris@0
|
1763 exit (1) ;
|
Chris@0
|
1764 } ;
|
Chris@0
|
1765
|
Chris@0
|
1766 if (sf_read_int (file, test, 1) > 0)
|
Chris@0
|
1767 { printf ("Line %d: Should return 0.\n", __LINE__) ;
|
Chris@0
|
1768 exit (1) ;
|
Chris@0
|
1769 } ;
|
Chris@0
|
1770
|
Chris@0
|
1771 if (! sf_error (file))
|
Chris@0
|
1772 { printf ("Line %d: Should return an error.\n", __LINE__) ;
|
Chris@0
|
1773 exit (1) ;
|
Chris@0
|
1774 } ;
|
Chris@0
|
1775 /*-----------------------*/
|
Chris@0
|
1776
|
Chris@0
|
1777 test_readf_int_or_die (file, 0, test + 10, 2, __LINE__) ;
|
Chris@0
|
1778 for (k = 20 ; k < 24 ; k++)
|
Chris@0
|
1779 if (TRIBYTE_ERROR (test [k], orig [k]))
|
Chris@0
|
1780 { printf ("\n\nLine %d : Stereo : Incorrect sample (#%d : 0x%X => 0x%X).\n", __LINE__, k, orig [k], test [k]) ;
|
Chris@0
|
1781 exit (1) ;
|
Chris@0
|
1782 } ;
|
Chris@0
|
1783
|
Chris@0
|
1784 /* Seek to offset from current position. */
|
Chris@0
|
1785 test_seek_or_die (file, 8, SEEK_CUR, 20, sfinfo.channels, __LINE__) ;
|
Chris@0
|
1786
|
Chris@0
|
1787 test_readf_int_or_die (file, 0, test + 20, 2, __LINE__) ;
|
Chris@0
|
1788 for (k = 40 ; k < 44 ; k++)
|
Chris@0
|
1789 if (TRIBYTE_ERROR (test [k], orig [k]))
|
Chris@0
|
1790 { printf ("\n\nLine %d : Stereo : Incorrect sample (#%d : 0x%X => 0x%X).\n", __LINE__, k, orig [k], test [k]) ;
|
Chris@0
|
1791 exit (1) ;
|
Chris@0
|
1792 } ;
|
Chris@0
|
1793
|
Chris@0
|
1794 /* Seek to offset from end of file. */
|
Chris@0
|
1795 test_seek_or_die (file, -1 * (sfinfo.frames - 10), SEEK_END, 10, sfinfo.channels, __LINE__) ;
|
Chris@0
|
1796
|
Chris@0
|
1797 test_readf_int_or_die (file, 0, test + 20, 2, __LINE__) ;
|
Chris@0
|
1798 for (k = 20 ; k < 24 ; k++)
|
Chris@0
|
1799 if (TRIBYTE_ERROR (test [k], orig [k]))
|
Chris@0
|
1800 { printf ("\n\nLine %d : Stereo : Incorrect sample (#%d : 0x%X => 0x%X).\n", __LINE__, k, orig [k], test [k]) ;
|
Chris@0
|
1801 exit (1) ;
|
Chris@0
|
1802 } ;
|
Chris@0
|
1803
|
Chris@0
|
1804 sf_close (file) ;
|
Chris@0
|
1805 } /* stereo_24bit_test */
|
Chris@0
|
1806
|
Chris@0
|
1807 static void
|
Chris@0
|
1808 mono_rdwr_24bit_test (const char *filename, int format, int long_file_ok, int allow_fd)
|
Chris@0
|
1809 { SNDFILE *file ;
|
Chris@0
|
1810 SF_INFO sfinfo ;
|
Chris@0
|
1811 int *orig, *test ;
|
Chris@0
|
1812 int k, pass ;
|
Chris@0
|
1813
|
Chris@0
|
1814 orig = orig_data.i ;
|
Chris@0
|
1815 test = test_data.i ;
|
Chris@0
|
1816
|
Chris@0
|
1817 sfinfo.samplerate = SAMPLE_RATE ;
|
Chris@0
|
1818 sfinfo.frames = DATA_LENGTH ;
|
Chris@0
|
1819 sfinfo.channels = 1 ;
|
Chris@0
|
1820 sfinfo.format = format ;
|
Chris@0
|
1821
|
Chris@0
|
1822 if ((format & SF_FORMAT_TYPEMASK) == SF_FORMAT_RAW
|
Chris@0
|
1823 || (format & SF_FORMAT_TYPEMASK) == SF_FORMAT_AU
|
Chris@0
|
1824 || (format & SF_FORMAT_TYPEMASK) == SF_FORMAT_SD2)
|
Chris@0
|
1825 unlink (filename) ;
|
Chris@0
|
1826 else
|
Chris@0
|
1827 { /* Create a short file. */
|
Chris@0
|
1828 create_short_file (filename) ;
|
Chris@0
|
1829
|
Chris@0
|
1830 /* Opening a already existing short file (ie invalid header) RDWR is disallowed.
|
Chris@0
|
1831 ** If this returns a valif pointer sf_open() screwed up.
|
Chris@0
|
1832 */
|
Chris@0
|
1833 if ((file = sf_open (filename, SFM_RDWR, &sfinfo)))
|
Chris@0
|
1834 { printf ("\n\nLine %d: sf_open should (SFM_RDWR) have failed but didn't.\n", __LINE__) ;
|
Chris@0
|
1835 exit (1) ;
|
Chris@0
|
1836 } ;
|
Chris@0
|
1837
|
Chris@0
|
1838 /* Truncate the file to zero bytes. */
|
Chris@0
|
1839 if (truncate (filename, 0) < 0)
|
Chris@0
|
1840 { printf ("\n\nLine %d: truncate (%s) failed", __LINE__, filename) ;
|
Chris@0
|
1841 perror (NULL) ;
|
Chris@0
|
1842 exit (1) ;
|
Chris@0
|
1843 } ;
|
Chris@0
|
1844 } ;
|
Chris@0
|
1845
|
Chris@0
|
1846 /* Opening a zero length file RDWR is allowed, but the SF_INFO struct must contain
|
Chris@0
|
1847 ** all the usual data required when opening the file in WRITE mode.
|
Chris@0
|
1848 */
|
Chris@0
|
1849 sfinfo.samplerate = SAMPLE_RATE ;
|
Chris@0
|
1850 sfinfo.frames = DATA_LENGTH ;
|
Chris@0
|
1851 sfinfo.channels = 1 ;
|
Chris@0
|
1852 sfinfo.format = format ;
|
Chris@0
|
1853
|
Chris@0
|
1854 file = test_open_file_or_die (filename, SFM_RDWR, &sfinfo, allow_fd, __LINE__) ;
|
Chris@0
|
1855
|
Chris@0
|
1856 /* Do 3 writes followed by reads. After each, check the data and the current
|
Chris@0
|
1857 ** read and write offsets.
|
Chris@0
|
1858 */
|
Chris@0
|
1859 for (pass = 1 ; pass <= 3 ; pass ++)
|
Chris@0
|
1860 { orig [20] = pass * 2 ;
|
Chris@0
|
1861
|
Chris@0
|
1862 /* Write some data. */
|
Chris@0
|
1863 test_write_int_or_die (file, pass, orig, DATA_LENGTH, __LINE__) ;
|
Chris@0
|
1864
|
Chris@0
|
1865 test_read_write_position_or_die (file, __LINE__, pass, (pass - 1) * DATA_LENGTH, pass * DATA_LENGTH) ;
|
Chris@0
|
1866
|
Chris@0
|
1867 /* Read what we just wrote. */
|
Chris@0
|
1868 test_read_int_or_die (file, 0, test, DATA_LENGTH, __LINE__) ;
|
Chris@0
|
1869
|
Chris@0
|
1870 /* Check the data. */
|
Chris@0
|
1871 for (k = 0 ; k < DATA_LENGTH ; k++)
|
Chris@0
|
1872 if (TRIBYTE_ERROR (orig [k], test [k]))
|
Chris@0
|
1873 { printf ("\n\nLine %d (pass %d) A : Error at sample %d (0x%X => 0x%X).\n", __LINE__, pass, k, orig [k], test [k]) ;
|
Chris@0
|
1874 oct_save_int (orig, test, DATA_LENGTH) ;
|
Chris@0
|
1875 exit (1) ;
|
Chris@0
|
1876 } ;
|
Chris@0
|
1877
|
Chris@0
|
1878 test_read_write_position_or_die (file, __LINE__, pass, pass * DATA_LENGTH, pass * DATA_LENGTH) ;
|
Chris@0
|
1879 } ; /* for (pass ...) */
|
Chris@0
|
1880
|
Chris@0
|
1881 sf_close (file) ;
|
Chris@0
|
1882
|
Chris@0
|
1883 /* Open the file again to check the data. */
|
Chris@0
|
1884 file = test_open_file_or_die (filename, SFM_RDWR, &sfinfo, allow_fd, __LINE__) ;
|
Chris@0
|
1885
|
Chris@0
|
1886 if (sfinfo.format != format)
|
Chris@0
|
1887 { printf ("\n\nLine %d : Returned format incorrect (0x%08X => 0x%08X).\n", __LINE__, format, sfinfo.format) ;
|
Chris@0
|
1888 exit (1) ;
|
Chris@0
|
1889 } ;
|
Chris@0
|
1890
|
Chris@0
|
1891 if (sfinfo.frames < 3 * DATA_LENGTH)
|
Chris@0
|
1892 { printf ("\n\nLine %d : Not enough frames in file. (%ld < %d)\n", __LINE__, SF_COUNT_TO_LONG (sfinfo.frames), 3 * DATA_LENGTH ) ;
|
Chris@0
|
1893 exit (1) ;
|
Chris@0
|
1894 }
|
Chris@0
|
1895
|
Chris@0
|
1896 if (! long_file_ok && sfinfo.frames != 3 * DATA_LENGTH)
|
Chris@0
|
1897 { printf ("\n\nLine %d : Incorrect number of frames in file. (%ld should be %d)\n", __LINE__, SF_COUNT_TO_LONG (sfinfo.frames), 3 * DATA_LENGTH ) ;
|
Chris@0
|
1898 exit (1) ;
|
Chris@0
|
1899 } ;
|
Chris@0
|
1900
|
Chris@0
|
1901 if (sfinfo.channels != 1)
|
Chris@0
|
1902 { printf ("\n\nLine %d : Incorrect number of channels in file.\n", __LINE__) ;
|
Chris@0
|
1903 exit (1) ;
|
Chris@0
|
1904 } ;
|
Chris@0
|
1905
|
Chris@0
|
1906 if (! long_file_ok)
|
Chris@0
|
1907 test_read_write_position_or_die (file, __LINE__, 0, 0, 3 * DATA_LENGTH) ;
|
Chris@0
|
1908 else
|
Chris@0
|
1909 test_seek_or_die (file, 3 * DATA_LENGTH, SFM_WRITE | SEEK_SET, 3 * DATA_LENGTH, sfinfo.channels, __LINE__) ;
|
Chris@0
|
1910
|
Chris@0
|
1911 for (pass = 1 ; pass <= 3 ; pass ++)
|
Chris@0
|
1912 { orig [20] = pass * 2 ;
|
Chris@0
|
1913
|
Chris@0
|
1914 test_read_write_position_or_die (file, __LINE__, pass, (pass - 1) * DATA_LENGTH, 3 * DATA_LENGTH) ;
|
Chris@0
|
1915
|
Chris@0
|
1916 /* Read what we just wrote. */
|
Chris@0
|
1917 test_read_int_or_die (file, pass, test, DATA_LENGTH, __LINE__) ;
|
Chris@0
|
1918
|
Chris@0
|
1919 /* Check the data. */
|
Chris@0
|
1920 for (k = 0 ; k < DATA_LENGTH ; k++)
|
Chris@0
|
1921 if (TRIBYTE_ERROR (orig [k], test [k]))
|
Chris@0
|
1922 { printf ("\n\nLine %d (pass %d) B : Error at sample %d (0x%X => 0x%X).\n", __LINE__, pass, k, orig [k], test [k]) ;
|
Chris@0
|
1923 oct_save_int (orig, test, DATA_LENGTH) ;
|
Chris@0
|
1924 exit (1) ;
|
Chris@0
|
1925 } ;
|
Chris@0
|
1926
|
Chris@0
|
1927 } ; /* for (pass ...) */
|
Chris@0
|
1928
|
Chris@0
|
1929 sf_close (file) ;
|
Chris@0
|
1930 } /* mono_rdwr_int_test */
|
Chris@0
|
1931
|
Chris@0
|
1932 static void
|
Chris@0
|
1933 new_rdwr_24bit_test (const char *filename, int format, int allow_fd)
|
Chris@0
|
1934 { SNDFILE *wfile, *rwfile ;
|
Chris@0
|
1935 SF_INFO sfinfo ;
|
Chris@0
|
1936 int *orig, *test ;
|
Chris@0
|
1937 int items, frames ;
|
Chris@0
|
1938
|
Chris@0
|
1939 orig = orig_data.i ;
|
Chris@0
|
1940 test = test_data.i ;
|
Chris@0
|
1941
|
Chris@0
|
1942 sfinfo.samplerate = 44100 ;
|
Chris@0
|
1943 sfinfo.frames = SILLY_WRITE_COUNT ; /* Wrong length. Library should correct this on sf_close. */
|
Chris@0
|
1944 sfinfo.channels = 2 ;
|
Chris@0
|
1945 sfinfo.format = format ;
|
Chris@0
|
1946
|
Chris@0
|
1947 items = DATA_LENGTH ;
|
Chris@0
|
1948 frames = items / sfinfo.channels ;
|
Chris@0
|
1949
|
Chris@0
|
1950 wfile = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, allow_fd, __LINE__) ;
|
Chris@0
|
1951 sf_command (wfile, SFC_SET_UPDATE_HEADER_AUTO, NULL, SF_TRUE) ;
|
Chris@0
|
1952 test_writef_int_or_die (wfile, 1, orig, frames, __LINE__) ;
|
Chris@0
|
1953 sf_write_sync (wfile) ;
|
Chris@0
|
1954 test_writef_int_or_die (wfile, 2, orig, frames, __LINE__) ;
|
Chris@0
|
1955 sf_write_sync (wfile) ;
|
Chris@0
|
1956
|
Chris@0
|
1957 rwfile = test_open_file_or_die (filename, SFM_RDWR, &sfinfo, allow_fd, __LINE__) ;
|
Chris@0
|
1958 if (sfinfo.frames != 2 * frames)
|
Chris@0
|
1959 { printf ("\n\nLine %d : incorrect number of frames in file (%ld should be %d)\n\n", __LINE__, SF_COUNT_TO_LONG (sfinfo.frames), 2 * frames) ;
|
Chris@0
|
1960 exit (1) ;
|
Chris@0
|
1961 } ;
|
Chris@0
|
1962
|
Chris@0
|
1963 test_writef_int_or_die (wfile, 3, orig, frames, __LINE__) ;
|
Chris@0
|
1964
|
Chris@0
|
1965 test_readf_int_or_die (rwfile, 1, test, frames, __LINE__) ;
|
Chris@0
|
1966 test_readf_int_or_die (rwfile, 2, test, frames, __LINE__) ;
|
Chris@0
|
1967
|
Chris@0
|
1968 sf_close (wfile) ;
|
Chris@0
|
1969 sf_close (rwfile) ;
|
Chris@0
|
1970 } /* new_rdwr_24bit_test */
|
Chris@0
|
1971
|
Chris@0
|
1972
|
Chris@0
|
1973 /*======================================================================================
|
Chris@0
|
1974 */
|
Chris@0
|
1975
|
Chris@0
|
1976 static void mono_int_test (const char *filename, int format, int long_file_ok, int allow_fd) ;
|
Chris@0
|
1977 static void stereo_int_test (const char *filename, int format, int long_file_ok, int allow_fd) ;
|
Chris@0
|
1978 static void mono_rdwr_int_test (const char *filename, int format, int long_file_ok, int allow_fd) ;
|
Chris@0
|
1979 static void new_rdwr_int_test (const char *filename, int format, int allow_fd) ;
|
Chris@0
|
1980 static void multi_seek_test (const char * filename, int format) ;
|
Chris@0
|
1981 static void write_seek_extend_test (const char * filename, int format) ;
|
Chris@0
|
1982
|
Chris@0
|
1983 static void
|
Chris@0
|
1984 pcm_test_int (const char *filename, int format, int long_file_ok)
|
Chris@0
|
1985 { SF_INFO sfinfo ;
|
Chris@0
|
1986 int *orig ;
|
Chris@0
|
1987 int k, allow_fd ;
|
Chris@0
|
1988
|
Chris@0
|
1989 /* Sd2 files cannot be opened from an existing file descriptor. */
|
Chris@0
|
1990 allow_fd = ((format & SF_FORMAT_TYPEMASK) == SF_FORMAT_SD2) ? SF_FALSE : SF_TRUE ;
|
Chris@0
|
1991
|
Chris@0
|
1992 print_test_name ("pcm_test_int", filename) ;
|
Chris@0
|
1993
|
Chris@0
|
1994 sfinfo.samplerate = 44100 ;
|
Chris@0
|
1995 sfinfo.frames = SILLY_WRITE_COUNT ; /* Wrong length. Library should correct this on sf_close. */
|
Chris@0
|
1996 sfinfo.channels = 1 ;
|
Chris@0
|
1997 sfinfo.format = format ;
|
Chris@0
|
1998
|
Chris@0
|
1999 gen_windowed_sine_double (orig_data.d, DATA_LENGTH, (1.0 * 0x7F000000)) ;
|
Chris@0
|
2000
|
Chris@0
|
2001 orig = orig_data.i ;
|
Chris@0
|
2002
|
Chris@0
|
2003 /* Make this a macro so gdb steps over it in one go. */
|
Chris@0
|
2004 CONVERT_DATA (k, DATA_LENGTH, orig, orig_data.d) ;
|
Chris@0
|
2005
|
Chris@0
|
2006 /* Some test broken out here. */
|
Chris@0
|
2007
|
Chris@0
|
2008 mono_int_test (filename, format, long_file_ok, allow_fd) ;
|
Chris@0
|
2009
|
Chris@0
|
2010 /* Sub format DWVW does not allow seeking. */
|
Chris@0
|
2011 if ((format & SF_FORMAT_SUBMASK) == SF_FORMAT_DWVW_16 ||
|
Chris@0
|
2012 (format & SF_FORMAT_SUBMASK) == SF_FORMAT_DWVW_24)
|
Chris@0
|
2013 { unlink (filename) ;
|
Chris@0
|
2014 printf ("no seek : ok\n") ;
|
Chris@0
|
2015 return ;
|
Chris@0
|
2016 } ;
|
Chris@0
|
2017
|
Chris@0
|
2018 if ((format & SF_FORMAT_TYPEMASK) != SF_FORMAT_FLAC)
|
Chris@0
|
2019 mono_rdwr_int_test (filename, format, long_file_ok, allow_fd) ;
|
Chris@0
|
2020
|
Chris@0
|
2021 /* If the format doesn't support stereo we're done. */
|
Chris@0
|
2022 sfinfo.channels = 2 ;
|
Chris@0
|
2023 if (sf_format_check (&sfinfo) == 0)
|
Chris@0
|
2024 { unlink (filename) ;
|
Chris@0
|
2025 puts ("no stereo : ok") ;
|
Chris@0
|
2026 return ;
|
Chris@0
|
2027 } ;
|
Chris@0
|
2028
|
Chris@0
|
2029 stereo_int_test (filename, format, long_file_ok, allow_fd) ;
|
Chris@0
|
2030
|
Chris@0
|
2031 /* New read/write test. Not sure if this is needed yet. */
|
Chris@0
|
2032
|
Chris@0
|
2033 if ((format & SF_FORMAT_TYPEMASK) != SF_FORMAT_PAF &&
|
Chris@0
|
2034 (format & SF_FORMAT_TYPEMASK) != SF_FORMAT_VOC &&
|
Chris@0
|
2035 (format & SF_FORMAT_TYPEMASK) != SF_FORMAT_FLAC)
|
Chris@0
|
2036 new_rdwr_int_test (filename, format, allow_fd) ;
|
Chris@0
|
2037
|
Chris@0
|
2038 delete_file (format, filename) ;
|
Chris@0
|
2039
|
Chris@0
|
2040 puts ("ok") ;
|
Chris@0
|
2041 return ;
|
Chris@0
|
2042 } /* pcm_test_int */
|
Chris@0
|
2043
|
Chris@0
|
2044 static void
|
Chris@0
|
2045 mono_int_test (const char *filename, int format, int long_file_ok, int allow_fd)
|
Chris@0
|
2046 { SNDFILE *file ;
|
Chris@0
|
2047 SF_INFO sfinfo ;
|
Chris@0
|
2048 int *orig, *test ;
|
Chris@0
|
2049 sf_count_t count ;
|
Chris@0
|
2050 int k, items ;
|
Chris@0
|
2051
|
Chris@0
|
2052 sfinfo.samplerate = 44100 ;
|
Chris@0
|
2053 sfinfo.frames = SILLY_WRITE_COUNT ; /* Wrong length. Library should correct this on sf_close. */
|
Chris@0
|
2054 sfinfo.channels = 1 ;
|
Chris@0
|
2055 sfinfo.format = format ;
|
Chris@0
|
2056
|
Chris@0
|
2057 orig = orig_data.i ;
|
Chris@0
|
2058 test = test_data.i ;
|
Chris@0
|
2059
|
Chris@0
|
2060 items = DATA_LENGTH ;
|
Chris@0
|
2061
|
Chris@0
|
2062 file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, allow_fd, __LINE__) ;
|
Chris@0
|
2063
|
Chris@0
|
2064 sf_set_string (file, SF_STR_ARTIST, "Your name here") ;
|
Chris@0
|
2065
|
Chris@0
|
2066 test_write_int_or_die (file, 0, orig, items, __LINE__) ;
|
Chris@0
|
2067 sf_write_sync (file) ;
|
Chris@0
|
2068 test_write_int_or_die (file, 0, orig, items, __LINE__) ;
|
Chris@0
|
2069 sf_write_sync (file) ;
|
Chris@0
|
2070
|
Chris@0
|
2071 /* Add non-audio data after the audio. */
|
Chris@0
|
2072 sf_set_string (file, SF_STR_COPYRIGHT, "Copyright (c) 2003") ;
|
Chris@0
|
2073
|
Chris@0
|
2074 sf_close (file) ;
|
Chris@0
|
2075
|
Chris@0
|
2076 memset (test, 0, items * sizeof (int)) ;
|
Chris@0
|
2077
|
Chris@0
|
2078 if ((format & SF_FORMAT_TYPEMASK) != SF_FORMAT_RAW)
|
Chris@0
|
2079 memset (&sfinfo, 0, sizeof (sfinfo)) ;
|
Chris@0
|
2080
|
Chris@0
|
2081 file = test_open_file_or_die (filename, SFM_READ, &sfinfo, allow_fd, __LINE__) ;
|
Chris@0
|
2082
|
Chris@0
|
2083 if (sfinfo.format != format)
|
Chris@0
|
2084 { printf ("\n\nLine %d : Mono : Returned format incorrect (0x%08X => 0x%08X).\n", __LINE__, format, sfinfo.format) ;
|
Chris@0
|
2085 exit (1) ;
|
Chris@0
|
2086 } ;
|
Chris@0
|
2087
|
Chris@0
|
2088 if (sfinfo.frames < 2 * items)
|
Chris@0
|
2089 { printf ("\n\nLine %d : Mono : Incorrect number of frames in file (too short). (%ld should be %d)\n", __LINE__, SF_COUNT_TO_LONG (sfinfo.frames), items) ;
|
Chris@0
|
2090 exit (1) ;
|
Chris@0
|
2091 } ;
|
Chris@0
|
2092
|
Chris@0
|
2093 if (! long_file_ok && sfinfo.frames > 2 * items)
|
Chris@0
|
2094 { printf ("\n\nLine %d : Mono : Incorrect number of frames in file (too long). (%ld should be %d)\n", __LINE__, SF_COUNT_TO_LONG (sfinfo.frames), items) ;
|
Chris@0
|
2095 exit (1) ;
|
Chris@0
|
2096 } ;
|
Chris@0
|
2097
|
Chris@0
|
2098 if (sfinfo.channels != 1)
|
Chris@0
|
2099 { printf ("\n\nLine %d : Mono : Incorrect number of channels in file.\n", __LINE__) ;
|
Chris@0
|
2100 exit (1) ;
|
Chris@0
|
2101 } ;
|
Chris@0
|
2102
|
Chris@0
|
2103 check_log_buffer_or_die (file, __LINE__) ;
|
Chris@0
|
2104
|
Chris@0
|
2105 test_read_int_or_die (file, 0, test, items, __LINE__) ;
|
Chris@0
|
2106 for (k = 0 ; k < items ; k++)
|
Chris@0
|
2107 if (INT_ERROR (orig [k], test [k]))
|
Chris@0
|
2108 { printf ("\n\nLine %d: Mono : Incorrect sample A (#%d : 0x%X => 0x%X).\n", __LINE__, k, orig [k], test [k]) ;
|
Chris@0
|
2109 oct_save_int (orig, test, items) ;
|
Chris@0
|
2110 exit (1) ;
|
Chris@0
|
2111 } ;
|
Chris@0
|
2112
|
Chris@0
|
2113 /* Seek to start of file. */
|
Chris@0
|
2114 test_seek_or_die (file, 0, SEEK_SET, 0, sfinfo.channels, __LINE__) ;
|
Chris@0
|
2115
|
Chris@0
|
2116 test_read_int_or_die (file, 0, test, 4, __LINE__) ;
|
Chris@0
|
2117 for (k = 0 ; k < 4 ; k++)
|
Chris@0
|
2118 if (INT_ERROR (orig [k], test [k]))
|
Chris@0
|
2119 { printf ("\n\nLine %d : Mono : Incorrect sample A (#%d : 0x%X => 0x%X).\n", __LINE__, k, orig [k], test [k]) ;
|
Chris@0
|
2120 exit (1) ;
|
Chris@0
|
2121 } ;
|
Chris@0
|
2122
|
Chris@0
|
2123 if ((format & SF_FORMAT_SUBMASK) == SF_FORMAT_DWVW_16 ||
|
Chris@0
|
2124 (format & SF_FORMAT_SUBMASK) == SF_FORMAT_DWVW_24)
|
Chris@0
|
2125 { sf_close (file) ;
|
Chris@0
|
2126 unlink (filename) ;
|
Chris@0
|
2127 printf ("no seek : ") ;
|
Chris@0
|
2128 return ;
|
Chris@0
|
2129 } ;
|
Chris@0
|
2130
|
Chris@0
|
2131 /* Seek to offset from start of file. */
|
Chris@0
|
2132 test_seek_or_die (file, items + 10, SEEK_SET, items + 10, sfinfo.channels, __LINE__) ;
|
Chris@0
|
2133
|
Chris@0
|
2134 test_read_int_or_die (file, 0, test + 10, 4, __LINE__) ;
|
Chris@0
|
2135 for (k = 10 ; k < 14 ; k++)
|
Chris@0
|
2136 if (INT_ERROR (orig [k], test [k]))
|
Chris@0
|
2137 { printf ("\n\nLine %d : Mono : Incorrect sample A (#%d : 0x%X => 0x%X).\n", __LINE__, k, test [k], orig [k]) ;
|
Chris@0
|
2138 exit (1) ;
|
Chris@0
|
2139 } ;
|
Chris@0
|
2140
|
Chris@0
|
2141 /* Seek to offset from current position. */
|
Chris@0
|
2142 test_seek_or_die (file, 6, SEEK_CUR, items + 20, sfinfo.channels, __LINE__) ;
|
Chris@0
|
2143
|
Chris@0
|
2144 test_read_int_or_die (file, 0, test + 20, 4, __LINE__) ;
|
Chris@0
|
2145 for (k = 20 ; k < 24 ; k++)
|
Chris@0
|
2146 if (INT_ERROR (orig [k], test [k]))
|
Chris@0
|
2147 { printf ("\n\nLine %d : Mono : Incorrect sample A (#%d : 0x%X => 0x%X).\n", __LINE__, k, test [k], orig [k]) ;
|
Chris@0
|
2148 exit (1) ;
|
Chris@0
|
2149 } ;
|
Chris@0
|
2150
|
Chris@0
|
2151 /* Seek to offset from end of file. */
|
Chris@0
|
2152 test_seek_or_die (file, -1 * (sfinfo.frames - 10), SEEK_END, 10, sfinfo.channels, __LINE__) ;
|
Chris@0
|
2153
|
Chris@0
|
2154 test_read_int_or_die (file, 0, test + 10, 4, __LINE__) ;
|
Chris@0
|
2155 for (k = 10 ; k < 14 ; k++)
|
Chris@0
|
2156 if (INT_ERROR (orig [k], test [k]))
|
Chris@0
|
2157 { printf ("\n\nLine %d : Mono : Incorrect sample D (#%d : 0x%X => 0x%X).\n", __LINE__, k, test [k], orig [k]) ;
|
Chris@0
|
2158 exit (1) ;
|
Chris@0
|
2159 } ;
|
Chris@0
|
2160
|
Chris@0
|
2161 /* Check read past end of file followed by sf_seek (sndfile, 0, SEEK_CUR). */
|
Chris@0
|
2162 test_seek_or_die (file, 0, SEEK_SET, 0, sfinfo.channels, __LINE__) ;
|
Chris@0
|
2163
|
Chris@0
|
2164 count = 0 ;
|
Chris@0
|
2165 while (count < sfinfo.frames)
|
Chris@0
|
2166 count += sf_read_int (file, test, 311) ;
|
Chris@0
|
2167
|
Chris@0
|
2168 /* Check that no error has occurred. */
|
Chris@0
|
2169 if (sf_error (file))
|
Chris@0
|
2170 { printf ("\n\nLine %d : Mono : error where there shouldn't have been one.\n", __LINE__) ;
|
Chris@0
|
2171 puts (sf_strerror (file)) ;
|
Chris@0
|
2172 exit (1) ;
|
Chris@0
|
2173 } ;
|
Chris@0
|
2174
|
Chris@0
|
2175 /* Check that we haven't read beyond EOF. */
|
Chris@0
|
2176 if (count > sfinfo.frames)
|
Chris@0
|
2177 { printf ("\n\nLines %d : read past end of file (%ld should be %ld)\n", __LINE__, (long) count, (long) sfinfo.frames) ;
|
Chris@0
|
2178 exit (1) ;
|
Chris@0
|
2179 } ;
|
Chris@0
|
2180
|
Chris@0
|
2181 test_seek_or_die (file, 0, SEEK_CUR, sfinfo.frames, sfinfo.channels, __LINE__) ;
|
Chris@0
|
2182
|
Chris@0
|
2183 sf_close (file) ;
|
Chris@0
|
2184
|
Chris@0
|
2185 multi_seek_test (filename, format) ;
|
Chris@0
|
2186 write_seek_extend_test (filename, format) ;
|
Chris@0
|
2187
|
Chris@0
|
2188 } /* mono_int_test */
|
Chris@0
|
2189
|
Chris@0
|
2190 static void
|
Chris@0
|
2191 stereo_int_test (const char *filename, int format, int long_file_ok, int allow_fd)
|
Chris@0
|
2192 { SNDFILE *file ;
|
Chris@0
|
2193 SF_INFO sfinfo ;
|
Chris@0
|
2194 int *orig, *test ;
|
Chris@0
|
2195 int k, items, frames ;
|
Chris@0
|
2196
|
Chris@0
|
2197 sfinfo.samplerate = 44100 ;
|
Chris@0
|
2198 sfinfo.frames = SILLY_WRITE_COUNT ; /* Wrong length. Library should correct this on sf_close. */
|
Chris@0
|
2199 sfinfo.channels = 2 ;
|
Chris@0
|
2200 sfinfo.format = format ;
|
Chris@0
|
2201
|
Chris@0
|
2202 gen_windowed_sine_double (orig_data.d, DATA_LENGTH, (1.0 * 0x7F000000)) ;
|
Chris@0
|
2203
|
Chris@0
|
2204 orig = orig_data.i ;
|
Chris@0
|
2205 test = test_data.i ;
|
Chris@0
|
2206
|
Chris@0
|
2207 /* Make this a macro so gdb steps over it in one go. */
|
Chris@0
|
2208 CONVERT_DATA (k, DATA_LENGTH, orig, orig_data.d) ;
|
Chris@0
|
2209
|
Chris@0
|
2210 items = DATA_LENGTH ;
|
Chris@0
|
2211 frames = items / sfinfo.channels ;
|
Chris@0
|
2212
|
Chris@0
|
2213 file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, allow_fd, __LINE__) ;
|
Chris@0
|
2214
|
Chris@0
|
2215 sf_set_string (file, SF_STR_ARTIST, "Your name here") ;
|
Chris@0
|
2216
|
Chris@0
|
2217 test_writef_int_or_die (file, 0, orig, frames, __LINE__) ;
|
Chris@0
|
2218
|
Chris@0
|
2219 sf_set_string (file, SF_STR_COPYRIGHT, "Copyright (c) 2003") ;
|
Chris@0
|
2220
|
Chris@0
|
2221 sf_close (file) ;
|
Chris@0
|
2222
|
Chris@0
|
2223 memset (test, 0, items * sizeof (int)) ;
|
Chris@0
|
2224
|
Chris@0
|
2225 if ((format & SF_FORMAT_TYPEMASK) != SF_FORMAT_RAW)
|
Chris@0
|
2226 memset (&sfinfo, 0, sizeof (sfinfo)) ;
|
Chris@0
|
2227
|
Chris@0
|
2228 file = test_open_file_or_die (filename, SFM_READ, &sfinfo, allow_fd, __LINE__) ;
|
Chris@0
|
2229
|
Chris@0
|
2230 if (sfinfo.format != format)
|
Chris@0
|
2231 { printf ("\n\nLine %d : Stereo : Returned format incorrect (0x%08X => 0x%08X).\n",
|
Chris@0
|
2232 __LINE__, format, sfinfo.format) ;
|
Chris@0
|
2233 exit (1) ;
|
Chris@0
|
2234 } ;
|
Chris@0
|
2235
|
Chris@0
|
2236 if (sfinfo.frames < frames)
|
Chris@0
|
2237 { printf ("\n\nLine %d : Stereo : Incorrect number of frames in file (too short). (%ld should be %d)\n",
|
Chris@0
|
2238 __LINE__, SF_COUNT_TO_LONG (sfinfo.frames), frames) ;
|
Chris@0
|
2239 exit (1) ;
|
Chris@0
|
2240 } ;
|
Chris@0
|
2241
|
Chris@0
|
2242 if (! long_file_ok && sfinfo.frames > frames)
|
Chris@0
|
2243 { printf ("\n\nLine %d : Stereo : Incorrect number of frames in file (too long). (%ld should be %d)\n",
|
Chris@0
|
2244 __LINE__, SF_COUNT_TO_LONG (sfinfo.frames), frames) ;
|
Chris@0
|
2245 exit (1) ;
|
Chris@0
|
2246 } ;
|
Chris@0
|
2247
|
Chris@0
|
2248 if (sfinfo.channels != 2)
|
Chris@0
|
2249 { printf ("\n\nLine %d : Stereo : Incorrect number of channels in file.\n", __LINE__) ;
|
Chris@0
|
2250 exit (1) ;
|
Chris@0
|
2251 } ;
|
Chris@0
|
2252
|
Chris@0
|
2253 check_log_buffer_or_die (file, __LINE__) ;
|
Chris@0
|
2254
|
Chris@0
|
2255 test_readf_int_or_die (file, 0, test, frames, __LINE__) ;
|
Chris@0
|
2256 for (k = 0 ; k < items ; k++)
|
Chris@0
|
2257 if (INT_ERROR (test [k], orig [k]))
|
Chris@0
|
2258 { printf ("\n\nLine %d : Stereo : Incorrect sample (#%d : 0x%X => 0x%X).\n", __LINE__, k, orig [k], test [k]) ;
|
Chris@0
|
2259 exit (1) ;
|
Chris@0
|
2260 } ;
|
Chris@0
|
2261
|
Chris@0
|
2262 /* Seek to start of file. */
|
Chris@0
|
2263 test_seek_or_die (file, 0, SEEK_SET, 0, sfinfo.channels, __LINE__) ;
|
Chris@0
|
2264
|
Chris@0
|
2265 test_readf_int_or_die (file, 0, test, 2, __LINE__) ;
|
Chris@0
|
2266 for (k = 0 ; k < 4 ; k++)
|
Chris@0
|
2267 if (INT_ERROR (test [k], orig [k]))
|
Chris@0
|
2268 { printf ("\n\nLine %d : Stereo : Incorrect sample (#%d : 0x%X => 0x%X).\n", __LINE__, k, orig [k], test [k]) ;
|
Chris@0
|
2269 exit (1) ;
|
Chris@0
|
2270 } ;
|
Chris@0
|
2271
|
Chris@0
|
2272 /* Seek to offset from start of file. */
|
Chris@0
|
2273 test_seek_or_die (file, 10, SEEK_SET, 10, sfinfo.channels, __LINE__) ;
|
Chris@0
|
2274
|
Chris@0
|
2275 /* Check for errors here. */
|
Chris@0
|
2276 if (sf_error (file))
|
Chris@0
|
2277 { printf ("Line %d: Should NOT return an error.\n", __LINE__) ;
|
Chris@0
|
2278 puts (sf_strerror (file)) ;
|
Chris@0
|
2279 exit (1) ;
|
Chris@0
|
2280 } ;
|
Chris@0
|
2281
|
Chris@0
|
2282 if (sf_read_int (file, test, 1) > 0)
|
Chris@0
|
2283 { printf ("Line %d: Should return 0.\n", __LINE__) ;
|
Chris@0
|
2284 exit (1) ;
|
Chris@0
|
2285 } ;
|
Chris@0
|
2286
|
Chris@0
|
2287 if (! sf_error (file))
|
Chris@0
|
2288 { printf ("Line %d: Should return an error.\n", __LINE__) ;
|
Chris@0
|
2289 exit (1) ;
|
Chris@0
|
2290 } ;
|
Chris@0
|
2291 /*-----------------------*/
|
Chris@0
|
2292
|
Chris@0
|
2293 test_readf_int_or_die (file, 0, test + 10, 2, __LINE__) ;
|
Chris@0
|
2294 for (k = 20 ; k < 24 ; k++)
|
Chris@0
|
2295 if (INT_ERROR (test [k], orig [k]))
|
Chris@0
|
2296 { printf ("\n\nLine %d : Stereo : Incorrect sample (#%d : 0x%X => 0x%X).\n", __LINE__, k, orig [k], test [k]) ;
|
Chris@0
|
2297 exit (1) ;
|
Chris@0
|
2298 } ;
|
Chris@0
|
2299
|
Chris@0
|
2300 /* Seek to offset from current position. */
|
Chris@0
|
2301 test_seek_or_die (file, 8, SEEK_CUR, 20, sfinfo.channels, __LINE__) ;
|
Chris@0
|
2302
|
Chris@0
|
2303 test_readf_int_or_die (file, 0, test + 20, 2, __LINE__) ;
|
Chris@0
|
2304 for (k = 40 ; k < 44 ; k++)
|
Chris@0
|
2305 if (INT_ERROR (test [k], orig [k]))
|
Chris@0
|
2306 { printf ("\n\nLine %d : Stereo : Incorrect sample (#%d : 0x%X => 0x%X).\n", __LINE__, k, orig [k], test [k]) ;
|
Chris@0
|
2307 exit (1) ;
|
Chris@0
|
2308 } ;
|
Chris@0
|
2309
|
Chris@0
|
2310 /* Seek to offset from end of file. */
|
Chris@0
|
2311 test_seek_or_die (file, -1 * (sfinfo.frames - 10), SEEK_END, 10, sfinfo.channels, __LINE__) ;
|
Chris@0
|
2312
|
Chris@0
|
2313 test_readf_int_or_die (file, 0, test + 20, 2, __LINE__) ;
|
Chris@0
|
2314 for (k = 20 ; k < 24 ; k++)
|
Chris@0
|
2315 if (INT_ERROR (test [k], orig [k]))
|
Chris@0
|
2316 { printf ("\n\nLine %d : Stereo : Incorrect sample (#%d : 0x%X => 0x%X).\n", __LINE__, k, orig [k], test [k]) ;
|
Chris@0
|
2317 exit (1) ;
|
Chris@0
|
2318 } ;
|
Chris@0
|
2319
|
Chris@0
|
2320 sf_close (file) ;
|
Chris@0
|
2321 } /* stereo_int_test */
|
Chris@0
|
2322
|
Chris@0
|
2323 static void
|
Chris@0
|
2324 mono_rdwr_int_test (const char *filename, int format, int long_file_ok, int allow_fd)
|
Chris@0
|
2325 { SNDFILE *file ;
|
Chris@0
|
2326 SF_INFO sfinfo ;
|
Chris@0
|
2327 int *orig, *test ;
|
Chris@0
|
2328 int k, pass ;
|
Chris@0
|
2329
|
Chris@0
|
2330 orig = orig_data.i ;
|
Chris@0
|
2331 test = test_data.i ;
|
Chris@0
|
2332
|
Chris@0
|
2333 sfinfo.samplerate = SAMPLE_RATE ;
|
Chris@0
|
2334 sfinfo.frames = DATA_LENGTH ;
|
Chris@0
|
2335 sfinfo.channels = 1 ;
|
Chris@0
|
2336 sfinfo.format = format ;
|
Chris@0
|
2337
|
Chris@0
|
2338 if ((format & SF_FORMAT_TYPEMASK) == SF_FORMAT_RAW
|
Chris@0
|
2339 || (format & SF_FORMAT_TYPEMASK) == SF_FORMAT_AU
|
Chris@0
|
2340 || (format & SF_FORMAT_TYPEMASK) == SF_FORMAT_SD2)
|
Chris@0
|
2341 unlink (filename) ;
|
Chris@0
|
2342 else
|
Chris@0
|
2343 { /* Create a short file. */
|
Chris@0
|
2344 create_short_file (filename) ;
|
Chris@0
|
2345
|
Chris@0
|
2346 /* Opening a already existing short file (ie invalid header) RDWR is disallowed.
|
Chris@0
|
2347 ** If this returns a valif pointer sf_open() screwed up.
|
Chris@0
|
2348 */
|
Chris@0
|
2349 if ((file = sf_open (filename, SFM_RDWR, &sfinfo)))
|
Chris@0
|
2350 { printf ("\n\nLine %d: sf_open should (SFM_RDWR) have failed but didn't.\n", __LINE__) ;
|
Chris@0
|
2351 exit (1) ;
|
Chris@0
|
2352 } ;
|
Chris@0
|
2353
|
Chris@0
|
2354 /* Truncate the file to zero bytes. */
|
Chris@0
|
2355 if (truncate (filename, 0) < 0)
|
Chris@0
|
2356 { printf ("\n\nLine %d: truncate (%s) failed", __LINE__, filename) ;
|
Chris@0
|
2357 perror (NULL) ;
|
Chris@0
|
2358 exit (1) ;
|
Chris@0
|
2359 } ;
|
Chris@0
|
2360 } ;
|
Chris@0
|
2361
|
Chris@0
|
2362 /* Opening a zero length file RDWR is allowed, but the SF_INFO struct must contain
|
Chris@0
|
2363 ** all the usual data required when opening the file in WRITE mode.
|
Chris@0
|
2364 */
|
Chris@0
|
2365 sfinfo.samplerate = SAMPLE_RATE ;
|
Chris@0
|
2366 sfinfo.frames = DATA_LENGTH ;
|
Chris@0
|
2367 sfinfo.channels = 1 ;
|
Chris@0
|
2368 sfinfo.format = format ;
|
Chris@0
|
2369
|
Chris@0
|
2370 file = test_open_file_or_die (filename, SFM_RDWR, &sfinfo, allow_fd, __LINE__) ;
|
Chris@0
|
2371
|
Chris@0
|
2372 /* Do 3 writes followed by reads. After each, check the data and the current
|
Chris@0
|
2373 ** read and write offsets.
|
Chris@0
|
2374 */
|
Chris@0
|
2375 for (pass = 1 ; pass <= 3 ; pass ++)
|
Chris@0
|
2376 { orig [20] = pass * 2 ;
|
Chris@0
|
2377
|
Chris@0
|
2378 /* Write some data. */
|
Chris@0
|
2379 test_write_int_or_die (file, pass, orig, DATA_LENGTH, __LINE__) ;
|
Chris@0
|
2380
|
Chris@0
|
2381 test_read_write_position_or_die (file, __LINE__, pass, (pass - 1) * DATA_LENGTH, pass * DATA_LENGTH) ;
|
Chris@0
|
2382
|
Chris@0
|
2383 /* Read what we just wrote. */
|
Chris@0
|
2384 test_read_int_or_die (file, 0, test, DATA_LENGTH, __LINE__) ;
|
Chris@0
|
2385
|
Chris@0
|
2386 /* Check the data. */
|
Chris@0
|
2387 for (k = 0 ; k < DATA_LENGTH ; k++)
|
Chris@0
|
2388 if (INT_ERROR (orig [k], test [k]))
|
Chris@0
|
2389 { printf ("\n\nLine %d (pass %d) A : Error at sample %d (0x%X => 0x%X).\n", __LINE__, pass, k, orig [k], test [k]) ;
|
Chris@0
|
2390 oct_save_int (orig, test, DATA_LENGTH) ;
|
Chris@0
|
2391 exit (1) ;
|
Chris@0
|
2392 } ;
|
Chris@0
|
2393
|
Chris@0
|
2394 test_read_write_position_or_die (file, __LINE__, pass, pass * DATA_LENGTH, pass * DATA_LENGTH) ;
|
Chris@0
|
2395 } ; /* for (pass ...) */
|
Chris@0
|
2396
|
Chris@0
|
2397 sf_close (file) ;
|
Chris@0
|
2398
|
Chris@0
|
2399 /* Open the file again to check the data. */
|
Chris@0
|
2400 file = test_open_file_or_die (filename, SFM_RDWR, &sfinfo, allow_fd, __LINE__) ;
|
Chris@0
|
2401
|
Chris@0
|
2402 if (sfinfo.format != format)
|
Chris@0
|
2403 { printf ("\n\nLine %d : Returned format incorrect (0x%08X => 0x%08X).\n", __LINE__, format, sfinfo.format) ;
|
Chris@0
|
2404 exit (1) ;
|
Chris@0
|
2405 } ;
|
Chris@0
|
2406
|
Chris@0
|
2407 if (sfinfo.frames < 3 * DATA_LENGTH)
|
Chris@0
|
2408 { printf ("\n\nLine %d : Not enough frames in file. (%ld < %d)\n", __LINE__, SF_COUNT_TO_LONG (sfinfo.frames), 3 * DATA_LENGTH ) ;
|
Chris@0
|
2409 exit (1) ;
|
Chris@0
|
2410 }
|
Chris@0
|
2411
|
Chris@0
|
2412 if (! long_file_ok && sfinfo.frames != 3 * DATA_LENGTH)
|
Chris@0
|
2413 { printf ("\n\nLine %d : Incorrect number of frames in file. (%ld should be %d)\n", __LINE__, SF_COUNT_TO_LONG (sfinfo.frames), 3 * DATA_LENGTH ) ;
|
Chris@0
|
2414 exit (1) ;
|
Chris@0
|
2415 } ;
|
Chris@0
|
2416
|
Chris@0
|
2417 if (sfinfo.channels != 1)
|
Chris@0
|
2418 { printf ("\n\nLine %d : Incorrect number of channels in file.\n", __LINE__) ;
|
Chris@0
|
2419 exit (1) ;
|
Chris@0
|
2420 } ;
|
Chris@0
|
2421
|
Chris@0
|
2422 if (! long_file_ok)
|
Chris@0
|
2423 test_read_write_position_or_die (file, __LINE__, 0, 0, 3 * DATA_LENGTH) ;
|
Chris@0
|
2424 else
|
Chris@0
|
2425 test_seek_or_die (file, 3 * DATA_LENGTH, SFM_WRITE | SEEK_SET, 3 * DATA_LENGTH, sfinfo.channels, __LINE__) ;
|
Chris@0
|
2426
|
Chris@0
|
2427 for (pass = 1 ; pass <= 3 ; pass ++)
|
Chris@0
|
2428 { orig [20] = pass * 2 ;
|
Chris@0
|
2429
|
Chris@0
|
2430 test_read_write_position_or_die (file, __LINE__, pass, (pass - 1) * DATA_LENGTH, 3 * DATA_LENGTH) ;
|
Chris@0
|
2431
|
Chris@0
|
2432 /* Read what we just wrote. */
|
Chris@0
|
2433 test_read_int_or_die (file, pass, test, DATA_LENGTH, __LINE__) ;
|
Chris@0
|
2434
|
Chris@0
|
2435 /* Check the data. */
|
Chris@0
|
2436 for (k = 0 ; k < DATA_LENGTH ; k++)
|
Chris@0
|
2437 if (INT_ERROR (orig [k], test [k]))
|
Chris@0
|
2438 { printf ("\n\nLine %d (pass %d) B : Error at sample %d (0x%X => 0x%X).\n", __LINE__, pass, k, orig [k], test [k]) ;
|
Chris@0
|
2439 oct_save_int (orig, test, DATA_LENGTH) ;
|
Chris@0
|
2440 exit (1) ;
|
Chris@0
|
2441 } ;
|
Chris@0
|
2442
|
Chris@0
|
2443 } ; /* for (pass ...) */
|
Chris@0
|
2444
|
Chris@0
|
2445 sf_close (file) ;
|
Chris@0
|
2446 } /* mono_rdwr_int_test */
|
Chris@0
|
2447
|
Chris@0
|
2448 static void
|
Chris@0
|
2449 new_rdwr_int_test (const char *filename, int format, int allow_fd)
|
Chris@0
|
2450 { SNDFILE *wfile, *rwfile ;
|
Chris@0
|
2451 SF_INFO sfinfo ;
|
Chris@0
|
2452 int *orig, *test ;
|
Chris@0
|
2453 int items, frames ;
|
Chris@0
|
2454
|
Chris@0
|
2455 orig = orig_data.i ;
|
Chris@0
|
2456 test = test_data.i ;
|
Chris@0
|
2457
|
Chris@0
|
2458 sfinfo.samplerate = 44100 ;
|
Chris@0
|
2459 sfinfo.frames = SILLY_WRITE_COUNT ; /* Wrong length. Library should correct this on sf_close. */
|
Chris@0
|
2460 sfinfo.channels = 2 ;
|
Chris@0
|
2461 sfinfo.format = format ;
|
Chris@0
|
2462
|
Chris@0
|
2463 items = DATA_LENGTH ;
|
Chris@0
|
2464 frames = items / sfinfo.channels ;
|
Chris@0
|
2465
|
Chris@0
|
2466 wfile = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, allow_fd, __LINE__) ;
|
Chris@0
|
2467 sf_command (wfile, SFC_SET_UPDATE_HEADER_AUTO, NULL, SF_TRUE) ;
|
Chris@0
|
2468 test_writef_int_or_die (wfile, 1, orig, frames, __LINE__) ;
|
Chris@0
|
2469 sf_write_sync (wfile) ;
|
Chris@0
|
2470 test_writef_int_or_die (wfile, 2, orig, frames, __LINE__) ;
|
Chris@0
|
2471 sf_write_sync (wfile) ;
|
Chris@0
|
2472
|
Chris@0
|
2473 rwfile = test_open_file_or_die (filename, SFM_RDWR, &sfinfo, allow_fd, __LINE__) ;
|
Chris@0
|
2474 if (sfinfo.frames != 2 * frames)
|
Chris@0
|
2475 { printf ("\n\nLine %d : incorrect number of frames in file (%ld should be %d)\n\n", __LINE__, SF_COUNT_TO_LONG (sfinfo.frames), 2 * frames) ;
|
Chris@0
|
2476 exit (1) ;
|
Chris@0
|
2477 } ;
|
Chris@0
|
2478
|
Chris@0
|
2479 test_writef_int_or_die (wfile, 3, orig, frames, __LINE__) ;
|
Chris@0
|
2480
|
Chris@0
|
2481 test_readf_int_or_die (rwfile, 1, test, frames, __LINE__) ;
|
Chris@0
|
2482 test_readf_int_or_die (rwfile, 2, test, frames, __LINE__) ;
|
Chris@0
|
2483
|
Chris@0
|
2484 sf_close (wfile) ;
|
Chris@0
|
2485 sf_close (rwfile) ;
|
Chris@0
|
2486 } /* new_rdwr_int_test */
|
Chris@0
|
2487
|
Chris@0
|
2488
|
Chris@0
|
2489 /*======================================================================================
|
Chris@0
|
2490 */
|
Chris@0
|
2491
|
Chris@0
|
2492 static void mono_float_test (const char *filename, int format, int long_file_ok, int allow_fd) ;
|
Chris@0
|
2493 static void stereo_float_test (const char *filename, int format, int long_file_ok, int allow_fd) ;
|
Chris@0
|
2494 static void mono_rdwr_float_test (const char *filename, int format, int long_file_ok, int allow_fd) ;
|
Chris@0
|
2495 static void new_rdwr_float_test (const char *filename, int format, int allow_fd) ;
|
Chris@0
|
2496 static void multi_seek_test (const char * filename, int format) ;
|
Chris@0
|
2497 static void write_seek_extend_test (const char * filename, int format) ;
|
Chris@0
|
2498
|
Chris@0
|
2499 static void
|
Chris@0
|
2500 pcm_test_float (const char *filename, int format, int long_file_ok)
|
Chris@0
|
2501 { SF_INFO sfinfo ;
|
Chris@0
|
2502 float *orig ;
|
Chris@0
|
2503 int k, allow_fd ;
|
Chris@0
|
2504
|
Chris@0
|
2505 /* Sd2 files cannot be opened from an existing file descriptor. */
|
Chris@0
|
2506 allow_fd = ((format & SF_FORMAT_TYPEMASK) == SF_FORMAT_SD2) ? SF_FALSE : SF_TRUE ;
|
Chris@0
|
2507
|
Chris@0
|
2508 print_test_name ("pcm_test_float", filename) ;
|
Chris@0
|
2509
|
Chris@0
|
2510 sfinfo.samplerate = 44100 ;
|
Chris@0
|
2511 sfinfo.frames = SILLY_WRITE_COUNT ; /* Wrong length. Library should correct this on sf_close. */
|
Chris@0
|
2512 sfinfo.channels = 1 ;
|
Chris@0
|
2513 sfinfo.format = format ;
|
Chris@0
|
2514
|
Chris@0
|
2515 gen_windowed_sine_double (orig_data.d, DATA_LENGTH, 1.0) ;
|
Chris@0
|
2516
|
Chris@0
|
2517 orig = orig_data.f ;
|
Chris@0
|
2518
|
Chris@0
|
2519 /* Make this a macro so gdb steps over it in one go. */
|
Chris@0
|
2520 CONVERT_DATA (k, DATA_LENGTH, orig, orig_data.d) ;
|
Chris@0
|
2521
|
Chris@0
|
2522 /* Some test broken out here. */
|
Chris@0
|
2523
|
Chris@0
|
2524 mono_float_test (filename, format, long_file_ok, allow_fd) ;
|
Chris@0
|
2525
|
Chris@0
|
2526 /* Sub format DWVW does not allow seeking. */
|
Chris@0
|
2527 if ((format & SF_FORMAT_SUBMASK) == SF_FORMAT_DWVW_16 ||
|
Chris@0
|
2528 (format & SF_FORMAT_SUBMASK) == SF_FORMAT_DWVW_24)
|
Chris@0
|
2529 { unlink (filename) ;
|
Chris@0
|
2530 printf ("no seek : ok\n") ;
|
Chris@0
|
2531 return ;
|
Chris@0
|
2532 } ;
|
Chris@0
|
2533
|
Chris@0
|
2534 if ((format & SF_FORMAT_TYPEMASK) != SF_FORMAT_FLAC)
|
Chris@0
|
2535 mono_rdwr_float_test (filename, format, long_file_ok, allow_fd) ;
|
Chris@0
|
2536
|
Chris@0
|
2537 /* If the format doesn't support stereo we're done. */
|
Chris@0
|
2538 sfinfo.channels = 2 ;
|
Chris@0
|
2539 if (sf_format_check (&sfinfo) == 0)
|
Chris@0
|
2540 { unlink (filename) ;
|
Chris@0
|
2541 puts ("no stereo : ok") ;
|
Chris@0
|
2542 return ;
|
Chris@0
|
2543 } ;
|
Chris@0
|
2544
|
Chris@0
|
2545 stereo_float_test (filename, format, long_file_ok, allow_fd) ;
|
Chris@0
|
2546
|
Chris@0
|
2547 /* New read/write test. Not sure if this is needed yet. */
|
Chris@0
|
2548
|
Chris@0
|
2549 if ((format & SF_FORMAT_TYPEMASK) != SF_FORMAT_PAF &&
|
Chris@0
|
2550 (format & SF_FORMAT_TYPEMASK) != SF_FORMAT_VOC &&
|
Chris@0
|
2551 (format & SF_FORMAT_TYPEMASK) != SF_FORMAT_FLAC)
|
Chris@0
|
2552 new_rdwr_float_test (filename, format, allow_fd) ;
|
Chris@0
|
2553
|
Chris@0
|
2554 delete_file (format, filename) ;
|
Chris@0
|
2555
|
Chris@0
|
2556 puts ("ok") ;
|
Chris@0
|
2557 return ;
|
Chris@0
|
2558 } /* pcm_test_float */
|
Chris@0
|
2559
|
Chris@0
|
2560 static void
|
Chris@0
|
2561 mono_float_test (const char *filename, int format, int long_file_ok, int allow_fd)
|
Chris@0
|
2562 { SNDFILE *file ;
|
Chris@0
|
2563 SF_INFO sfinfo ;
|
Chris@0
|
2564 float *orig, *test ;
|
Chris@0
|
2565 sf_count_t count ;
|
Chris@0
|
2566 int k, items ;
|
Chris@0
|
2567
|
Chris@0
|
2568 sfinfo.samplerate = 44100 ;
|
Chris@0
|
2569 sfinfo.frames = SILLY_WRITE_COUNT ; /* Wrong length. Library should correct this on sf_close. */
|
Chris@0
|
2570 sfinfo.channels = 1 ;
|
Chris@0
|
2571 sfinfo.format = format ;
|
Chris@0
|
2572
|
Chris@0
|
2573 orig = orig_data.f ;
|
Chris@0
|
2574 test = test_data.f ;
|
Chris@0
|
2575
|
Chris@0
|
2576 items = DATA_LENGTH ;
|
Chris@0
|
2577
|
Chris@0
|
2578 file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, allow_fd, __LINE__) ;
|
Chris@0
|
2579
|
Chris@0
|
2580 sf_set_string (file, SF_STR_ARTIST, "Your name here") ;
|
Chris@0
|
2581
|
Chris@0
|
2582 test_write_float_or_die (file, 0, orig, items, __LINE__) ;
|
Chris@0
|
2583 sf_write_sync (file) ;
|
Chris@0
|
2584 test_write_float_or_die (file, 0, orig, items, __LINE__) ;
|
Chris@0
|
2585 sf_write_sync (file) ;
|
Chris@0
|
2586
|
Chris@0
|
2587 /* Add non-audio data after the audio. */
|
Chris@0
|
2588 sf_set_string (file, SF_STR_COPYRIGHT, "Copyright (c) 2003") ;
|
Chris@0
|
2589
|
Chris@0
|
2590 sf_close (file) ;
|
Chris@0
|
2591
|
Chris@0
|
2592 memset (test, 0, items * sizeof (float)) ;
|
Chris@0
|
2593
|
Chris@0
|
2594 if ((format & SF_FORMAT_TYPEMASK) != SF_FORMAT_RAW)
|
Chris@0
|
2595 memset (&sfinfo, 0, sizeof (sfinfo)) ;
|
Chris@0
|
2596
|
Chris@0
|
2597 file = test_open_file_or_die (filename, SFM_READ, &sfinfo, allow_fd, __LINE__) ;
|
Chris@0
|
2598
|
Chris@0
|
2599 if (sfinfo.format != format)
|
Chris@0
|
2600 { printf ("\n\nLine %d : Mono : Returned format incorrect (0x%08X => 0x%08X).\n", __LINE__, format, sfinfo.format) ;
|
Chris@0
|
2601 exit (1) ;
|
Chris@0
|
2602 } ;
|
Chris@0
|
2603
|
Chris@0
|
2604 if (sfinfo.frames < 2 * items)
|
Chris@0
|
2605 { printf ("\n\nLine %d : Mono : Incorrect number of frames in file (too short). (%ld should be %d)\n", __LINE__, SF_COUNT_TO_LONG (sfinfo.frames), items) ;
|
Chris@0
|
2606 exit (1) ;
|
Chris@0
|
2607 } ;
|
Chris@0
|
2608
|
Chris@0
|
2609 if (! long_file_ok && sfinfo.frames > 2 * items)
|
Chris@0
|
2610 { printf ("\n\nLine %d : Mono : Incorrect number of frames in file (too long). (%ld should be %d)\n", __LINE__, SF_COUNT_TO_LONG (sfinfo.frames), items) ;
|
Chris@0
|
2611 exit (1) ;
|
Chris@0
|
2612 } ;
|
Chris@0
|
2613
|
Chris@0
|
2614 if (sfinfo.channels != 1)
|
Chris@0
|
2615 { printf ("\n\nLine %d : Mono : Incorrect number of channels in file.\n", __LINE__) ;
|
Chris@0
|
2616 exit (1) ;
|
Chris@0
|
2617 } ;
|
Chris@0
|
2618
|
Chris@0
|
2619 check_log_buffer_or_die (file, __LINE__) ;
|
Chris@0
|
2620
|
Chris@0
|
2621 test_read_float_or_die (file, 0, test, items, __LINE__) ;
|
Chris@0
|
2622 for (k = 0 ; k < items ; k++)
|
Chris@0
|
2623 if (FLOAT_ERROR (orig [k], test [k]))
|
Chris@0
|
2624 { printf ("\n\nLine %d: Mono : Incorrect sample A (#%d : %g => %g).\n", __LINE__, k, orig [k], test [k]) ;
|
Chris@0
|
2625 oct_save_float (orig, test, items) ;
|
Chris@0
|
2626 exit (1) ;
|
Chris@0
|
2627 } ;
|
Chris@0
|
2628
|
Chris@0
|
2629 /* Seek to start of file. */
|
Chris@0
|
2630 test_seek_or_die (file, 0, SEEK_SET, 0, sfinfo.channels, __LINE__) ;
|
Chris@0
|
2631
|
Chris@0
|
2632 test_read_float_or_die (file, 0, test, 4, __LINE__) ;
|
Chris@0
|
2633 for (k = 0 ; k < 4 ; k++)
|
Chris@0
|
2634 if (FLOAT_ERROR (orig [k], test [k]))
|
Chris@0
|
2635 { printf ("\n\nLine %d : Mono : Incorrect sample A (#%d : %g => %g).\n", __LINE__, k, orig [k], test [k]) ;
|
Chris@0
|
2636 exit (1) ;
|
Chris@0
|
2637 } ;
|
Chris@0
|
2638
|
Chris@0
|
2639 if ((format & SF_FORMAT_SUBMASK) == SF_FORMAT_DWVW_16 ||
|
Chris@0
|
2640 (format & SF_FORMAT_SUBMASK) == SF_FORMAT_DWVW_24)
|
Chris@0
|
2641 { sf_close (file) ;
|
Chris@0
|
2642 unlink (filename) ;
|
Chris@0
|
2643 printf ("no seek : ") ;
|
Chris@0
|
2644 return ;
|
Chris@0
|
2645 } ;
|
Chris@0
|
2646
|
Chris@0
|
2647 /* Seek to offset from start of file. */
|
Chris@0
|
2648 test_seek_or_die (file, items + 10, SEEK_SET, items + 10, sfinfo.channels, __LINE__) ;
|
Chris@0
|
2649
|
Chris@0
|
2650 test_read_float_or_die (file, 0, test + 10, 4, __LINE__) ;
|
Chris@0
|
2651 for (k = 10 ; k < 14 ; k++)
|
Chris@0
|
2652 if (FLOAT_ERROR (orig [k], test [k]))
|
Chris@0
|
2653 { printf ("\n\nLine %d : Mono : Incorrect sample A (#%d : %g => %g).\n", __LINE__, k, test [k], orig [k]) ;
|
Chris@0
|
2654 exit (1) ;
|
Chris@0
|
2655 } ;
|
Chris@0
|
2656
|
Chris@0
|
2657 /* Seek to offset from current position. */
|
Chris@0
|
2658 test_seek_or_die (file, 6, SEEK_CUR, items + 20, sfinfo.channels, __LINE__) ;
|
Chris@0
|
2659
|
Chris@0
|
2660 test_read_float_or_die (file, 0, test + 20, 4, __LINE__) ;
|
Chris@0
|
2661 for (k = 20 ; k < 24 ; k++)
|
Chris@0
|
2662 if (FLOAT_ERROR (orig [k], test [k]))
|
Chris@0
|
2663 { printf ("\n\nLine %d : Mono : Incorrect sample A (#%d : %g => %g).\n", __LINE__, k, test [k], orig [k]) ;
|
Chris@0
|
2664 exit (1) ;
|
Chris@0
|
2665 } ;
|
Chris@0
|
2666
|
Chris@0
|
2667 /* Seek to offset from end of file. */
|
Chris@0
|
2668 test_seek_or_die (file, -1 * (sfinfo.frames - 10), SEEK_END, 10, sfinfo.channels, __LINE__) ;
|
Chris@0
|
2669
|
Chris@0
|
2670 test_read_float_or_die (file, 0, test + 10, 4, __LINE__) ;
|
Chris@0
|
2671 for (k = 10 ; k < 14 ; k++)
|
Chris@0
|
2672 if (FLOAT_ERROR (orig [k], test [k]))
|
Chris@0
|
2673 { printf ("\n\nLine %d : Mono : Incorrect sample D (#%d : %g => %g).\n", __LINE__, k, test [k], orig [k]) ;
|
Chris@0
|
2674 exit (1) ;
|
Chris@0
|
2675 } ;
|
Chris@0
|
2676
|
Chris@0
|
2677 /* Check read past end of file followed by sf_seek (sndfile, 0, SEEK_CUR). */
|
Chris@0
|
2678 test_seek_or_die (file, 0, SEEK_SET, 0, sfinfo.channels, __LINE__) ;
|
Chris@0
|
2679
|
Chris@0
|
2680 count = 0 ;
|
Chris@0
|
2681 while (count < sfinfo.frames)
|
Chris@0
|
2682 count += sf_read_float (file, test, 311) ;
|
Chris@0
|
2683
|
Chris@0
|
2684 /* Check that no error has occurred. */
|
Chris@0
|
2685 if (sf_error (file))
|
Chris@0
|
2686 { printf ("\n\nLine %d : Mono : error where there shouldn't have been one.\n", __LINE__) ;
|
Chris@0
|
2687 puts (sf_strerror (file)) ;
|
Chris@0
|
2688 exit (1) ;
|
Chris@0
|
2689 } ;
|
Chris@0
|
2690
|
Chris@0
|
2691 /* Check that we haven't read beyond EOF. */
|
Chris@0
|
2692 if (count > sfinfo.frames)
|
Chris@0
|
2693 { printf ("\n\nLines %d : read past end of file (%ld should be %ld)\n", __LINE__, (long) count, (long) sfinfo.frames) ;
|
Chris@0
|
2694 exit (1) ;
|
Chris@0
|
2695 } ;
|
Chris@0
|
2696
|
Chris@0
|
2697 test_seek_or_die (file, 0, SEEK_CUR, sfinfo.frames, sfinfo.channels, __LINE__) ;
|
Chris@0
|
2698
|
Chris@0
|
2699 sf_close (file) ;
|
Chris@0
|
2700
|
Chris@0
|
2701 multi_seek_test (filename, format) ;
|
Chris@0
|
2702 write_seek_extend_test (filename, format) ;
|
Chris@0
|
2703
|
Chris@0
|
2704 } /* mono_float_test */
|
Chris@0
|
2705
|
Chris@0
|
2706 static void
|
Chris@0
|
2707 stereo_float_test (const char *filename, int format, int long_file_ok, int allow_fd)
|
Chris@0
|
2708 { SNDFILE *file ;
|
Chris@0
|
2709 SF_INFO sfinfo ;
|
Chris@0
|
2710 float *orig, *test ;
|
Chris@0
|
2711 int k, items, frames ;
|
Chris@0
|
2712
|
Chris@0
|
2713 sfinfo.samplerate = 44100 ;
|
Chris@0
|
2714 sfinfo.frames = SILLY_WRITE_COUNT ; /* Wrong length. Library should correct this on sf_close. */
|
Chris@0
|
2715 sfinfo.channels = 2 ;
|
Chris@0
|
2716 sfinfo.format = format ;
|
Chris@0
|
2717
|
Chris@0
|
2718 gen_windowed_sine_double (orig_data.d, DATA_LENGTH, 1.0) ;
|
Chris@0
|
2719
|
Chris@0
|
2720 orig = orig_data.f ;
|
Chris@0
|
2721 test = test_data.f ;
|
Chris@0
|
2722
|
Chris@0
|
2723 /* Make this a macro so gdb steps over it in one go. */
|
Chris@0
|
2724 CONVERT_DATA (k, DATA_LENGTH, orig, orig_data.d) ;
|
Chris@0
|
2725
|
Chris@0
|
2726 items = DATA_LENGTH ;
|
Chris@0
|
2727 frames = items / sfinfo.channels ;
|
Chris@0
|
2728
|
Chris@0
|
2729 file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, allow_fd, __LINE__) ;
|
Chris@0
|
2730
|
Chris@0
|
2731 sf_set_string (file, SF_STR_ARTIST, "Your name here") ;
|
Chris@0
|
2732
|
Chris@0
|
2733 test_writef_float_or_die (file, 0, orig, frames, __LINE__) ;
|
Chris@0
|
2734
|
Chris@0
|
2735 sf_set_string (file, SF_STR_COPYRIGHT, "Copyright (c) 2003") ;
|
Chris@0
|
2736
|
Chris@0
|
2737 sf_close (file) ;
|
Chris@0
|
2738
|
Chris@0
|
2739 memset (test, 0, items * sizeof (float)) ;
|
Chris@0
|
2740
|
Chris@0
|
2741 if ((format & SF_FORMAT_TYPEMASK) != SF_FORMAT_RAW)
|
Chris@0
|
2742 memset (&sfinfo, 0, sizeof (sfinfo)) ;
|
Chris@0
|
2743
|
Chris@0
|
2744 file = test_open_file_or_die (filename, SFM_READ, &sfinfo, allow_fd, __LINE__) ;
|
Chris@0
|
2745
|
Chris@0
|
2746 if (sfinfo.format != format)
|
Chris@0
|
2747 { printf ("\n\nLine %d : Stereo : Returned format incorrect (0x%08X => 0x%08X).\n",
|
Chris@0
|
2748 __LINE__, format, sfinfo.format) ;
|
Chris@0
|
2749 exit (1) ;
|
Chris@0
|
2750 } ;
|
Chris@0
|
2751
|
Chris@0
|
2752 if (sfinfo.frames < frames)
|
Chris@0
|
2753 { printf ("\n\nLine %d : Stereo : Incorrect number of frames in file (too short). (%ld should be %d)\n",
|
Chris@0
|
2754 __LINE__, SF_COUNT_TO_LONG (sfinfo.frames), frames) ;
|
Chris@0
|
2755 exit (1) ;
|
Chris@0
|
2756 } ;
|
Chris@0
|
2757
|
Chris@0
|
2758 if (! long_file_ok && sfinfo.frames > frames)
|
Chris@0
|
2759 { printf ("\n\nLine %d : Stereo : Incorrect number of frames in file (too long). (%ld should be %d)\n",
|
Chris@0
|
2760 __LINE__, SF_COUNT_TO_LONG (sfinfo.frames), frames) ;
|
Chris@0
|
2761 exit (1) ;
|
Chris@0
|
2762 } ;
|
Chris@0
|
2763
|
Chris@0
|
2764 if (sfinfo.channels != 2)
|
Chris@0
|
2765 { printf ("\n\nLine %d : Stereo : Incorrect number of channels in file.\n", __LINE__) ;
|
Chris@0
|
2766 exit (1) ;
|
Chris@0
|
2767 } ;
|
Chris@0
|
2768
|
Chris@0
|
2769 check_log_buffer_or_die (file, __LINE__) ;
|
Chris@0
|
2770
|
Chris@0
|
2771 test_readf_float_or_die (file, 0, test, frames, __LINE__) ;
|
Chris@0
|
2772 for (k = 0 ; k < items ; k++)
|
Chris@0
|
2773 if (FLOAT_ERROR (test [k], orig [k]))
|
Chris@0
|
2774 { printf ("\n\nLine %d : Stereo : Incorrect sample (#%d : %g => %g).\n", __LINE__, k, orig [k], test [k]) ;
|
Chris@0
|
2775 exit (1) ;
|
Chris@0
|
2776 } ;
|
Chris@0
|
2777
|
Chris@0
|
2778 /* Seek to start of file. */
|
Chris@0
|
2779 test_seek_or_die (file, 0, SEEK_SET, 0, sfinfo.channels, __LINE__) ;
|
Chris@0
|
2780
|
Chris@0
|
2781 test_readf_float_or_die (file, 0, test, 2, __LINE__) ;
|
Chris@0
|
2782 for (k = 0 ; k < 4 ; k++)
|
Chris@0
|
2783 if (FLOAT_ERROR (test [k], orig [k]))
|
Chris@0
|
2784 { printf ("\n\nLine %d : Stereo : Incorrect sample (#%d : %g => %g).\n", __LINE__, k, orig [k], test [k]) ;
|
Chris@0
|
2785 exit (1) ;
|
Chris@0
|
2786 } ;
|
Chris@0
|
2787
|
Chris@0
|
2788 /* Seek to offset from start of file. */
|
Chris@0
|
2789 test_seek_or_die (file, 10, SEEK_SET, 10, sfinfo.channels, __LINE__) ;
|
Chris@0
|
2790
|
Chris@0
|
2791 /* Check for errors here. */
|
Chris@0
|
2792 if (sf_error (file))
|
Chris@0
|
2793 { printf ("Line %d: Should NOT return an error.\n", __LINE__) ;
|
Chris@0
|
2794 puts (sf_strerror (file)) ;
|
Chris@0
|
2795 exit (1) ;
|
Chris@0
|
2796 } ;
|
Chris@0
|
2797
|
Chris@0
|
2798 if (sf_read_float (file, test, 1) > 0)
|
Chris@0
|
2799 { printf ("Line %d: Should return 0.\n", __LINE__) ;
|
Chris@0
|
2800 exit (1) ;
|
Chris@0
|
2801 } ;
|
Chris@0
|
2802
|
Chris@0
|
2803 if (! sf_error (file))
|
Chris@0
|
2804 { printf ("Line %d: Should return an error.\n", __LINE__) ;
|
Chris@0
|
2805 exit (1) ;
|
Chris@0
|
2806 } ;
|
Chris@0
|
2807 /*-----------------------*/
|
Chris@0
|
2808
|
Chris@0
|
2809 test_readf_float_or_die (file, 0, test + 10, 2, __LINE__) ;
|
Chris@0
|
2810 for (k = 20 ; k < 24 ; k++)
|
Chris@0
|
2811 if (FLOAT_ERROR (test [k], orig [k]))
|
Chris@0
|
2812 { printf ("\n\nLine %d : Stereo : Incorrect sample (#%d : %g => %g).\n", __LINE__, k, orig [k], test [k]) ;
|
Chris@0
|
2813 exit (1) ;
|
Chris@0
|
2814 } ;
|
Chris@0
|
2815
|
Chris@0
|
2816 /* Seek to offset from current position. */
|
Chris@0
|
2817 test_seek_or_die (file, 8, SEEK_CUR, 20, sfinfo.channels, __LINE__) ;
|
Chris@0
|
2818
|
Chris@0
|
2819 test_readf_float_or_die (file, 0, test + 20, 2, __LINE__) ;
|
Chris@0
|
2820 for (k = 40 ; k < 44 ; k++)
|
Chris@0
|
2821 if (FLOAT_ERROR (test [k], orig [k]))
|
Chris@0
|
2822 { printf ("\n\nLine %d : Stereo : Incorrect sample (#%d : %g => %g).\n", __LINE__, k, orig [k], test [k]) ;
|
Chris@0
|
2823 exit (1) ;
|
Chris@0
|
2824 } ;
|
Chris@0
|
2825
|
Chris@0
|
2826 /* Seek to offset from end of file. */
|
Chris@0
|
2827 test_seek_or_die (file, -1 * (sfinfo.frames - 10), SEEK_END, 10, sfinfo.channels, __LINE__) ;
|
Chris@0
|
2828
|
Chris@0
|
2829 test_readf_float_or_die (file, 0, test + 20, 2, __LINE__) ;
|
Chris@0
|
2830 for (k = 20 ; k < 24 ; k++)
|
Chris@0
|
2831 if (FLOAT_ERROR (test [k], orig [k]))
|
Chris@0
|
2832 { printf ("\n\nLine %d : Stereo : Incorrect sample (#%d : %g => %g).\n", __LINE__, k, orig [k], test [k]) ;
|
Chris@0
|
2833 exit (1) ;
|
Chris@0
|
2834 } ;
|
Chris@0
|
2835
|
Chris@0
|
2836 sf_close (file) ;
|
Chris@0
|
2837 } /* stereo_float_test */
|
Chris@0
|
2838
|
Chris@0
|
2839 static void
|
Chris@0
|
2840 mono_rdwr_float_test (const char *filename, int format, int long_file_ok, int allow_fd)
|
Chris@0
|
2841 { SNDFILE *file ;
|
Chris@0
|
2842 SF_INFO sfinfo ;
|
Chris@0
|
2843 float *orig, *test ;
|
Chris@0
|
2844 int k, pass ;
|
Chris@0
|
2845
|
Chris@0
|
2846 orig = orig_data.f ;
|
Chris@0
|
2847 test = test_data.f ;
|
Chris@0
|
2848
|
Chris@0
|
2849 sfinfo.samplerate = SAMPLE_RATE ;
|
Chris@0
|
2850 sfinfo.frames = DATA_LENGTH ;
|
Chris@0
|
2851 sfinfo.channels = 1 ;
|
Chris@0
|
2852 sfinfo.format = format ;
|
Chris@0
|
2853
|
Chris@0
|
2854 if ((format & SF_FORMAT_TYPEMASK) == SF_FORMAT_RAW
|
Chris@0
|
2855 || (format & SF_FORMAT_TYPEMASK) == SF_FORMAT_AU
|
Chris@0
|
2856 || (format & SF_FORMAT_TYPEMASK) == SF_FORMAT_SD2)
|
Chris@0
|
2857 unlink (filename) ;
|
Chris@0
|
2858 else
|
Chris@0
|
2859 { /* Create a short file. */
|
Chris@0
|
2860 create_short_file (filename) ;
|
Chris@0
|
2861
|
Chris@0
|
2862 /* Opening a already existing short file (ie invalid header) RDWR is disallowed.
|
Chris@0
|
2863 ** If this returns a valif pointer sf_open() screwed up.
|
Chris@0
|
2864 */
|
Chris@0
|
2865 if ((file = sf_open (filename, SFM_RDWR, &sfinfo)))
|
Chris@0
|
2866 { printf ("\n\nLine %d: sf_open should (SFM_RDWR) have failed but didn't.\n", __LINE__) ;
|
Chris@0
|
2867 exit (1) ;
|
Chris@0
|
2868 } ;
|
Chris@0
|
2869
|
Chris@0
|
2870 /* Truncate the file to zero bytes. */
|
Chris@0
|
2871 if (truncate (filename, 0) < 0)
|
Chris@0
|
2872 { printf ("\n\nLine %d: truncate (%s) failed", __LINE__, filename) ;
|
Chris@0
|
2873 perror (NULL) ;
|
Chris@0
|
2874 exit (1) ;
|
Chris@0
|
2875 } ;
|
Chris@0
|
2876 } ;
|
Chris@0
|
2877
|
Chris@0
|
2878 /* Opening a zero length file RDWR is allowed, but the SF_INFO struct must contain
|
Chris@0
|
2879 ** all the usual data required when opening the file in WRITE mode.
|
Chris@0
|
2880 */
|
Chris@0
|
2881 sfinfo.samplerate = SAMPLE_RATE ;
|
Chris@0
|
2882 sfinfo.frames = DATA_LENGTH ;
|
Chris@0
|
2883 sfinfo.channels = 1 ;
|
Chris@0
|
2884 sfinfo.format = format ;
|
Chris@0
|
2885
|
Chris@0
|
2886 file = test_open_file_or_die (filename, SFM_RDWR, &sfinfo, allow_fd, __LINE__) ;
|
Chris@0
|
2887
|
Chris@0
|
2888 /* Do 3 writes followed by reads. After each, check the data and the current
|
Chris@0
|
2889 ** read and write offsets.
|
Chris@0
|
2890 */
|
Chris@0
|
2891 for (pass = 1 ; pass <= 3 ; pass ++)
|
Chris@0
|
2892 { orig [20] = pass * 2 ;
|
Chris@0
|
2893
|
Chris@0
|
2894 /* Write some data. */
|
Chris@0
|
2895 test_write_float_or_die (file, pass, orig, DATA_LENGTH, __LINE__) ;
|
Chris@0
|
2896
|
Chris@0
|
2897 test_read_write_position_or_die (file, __LINE__, pass, (pass - 1) * DATA_LENGTH, pass * DATA_LENGTH) ;
|
Chris@0
|
2898
|
Chris@0
|
2899 /* Read what we just wrote. */
|
Chris@0
|
2900 test_read_float_or_die (file, 0, test, DATA_LENGTH, __LINE__) ;
|
Chris@0
|
2901
|
Chris@0
|
2902 /* Check the data. */
|
Chris@0
|
2903 for (k = 0 ; k < DATA_LENGTH ; k++)
|
Chris@0
|
2904 if (FLOAT_ERROR (orig [k], test [k]))
|
Chris@0
|
2905 { printf ("\n\nLine %d (pass %d) A : Error at sample %d (%g => %g).\n", __LINE__, pass, k, orig [k], test [k]) ;
|
Chris@0
|
2906 oct_save_float (orig, test, DATA_LENGTH) ;
|
Chris@0
|
2907 exit (1) ;
|
Chris@0
|
2908 } ;
|
Chris@0
|
2909
|
Chris@0
|
2910 test_read_write_position_or_die (file, __LINE__, pass, pass * DATA_LENGTH, pass * DATA_LENGTH) ;
|
Chris@0
|
2911 } ; /* for (pass ...) */
|
Chris@0
|
2912
|
Chris@0
|
2913 sf_close (file) ;
|
Chris@0
|
2914
|
Chris@0
|
2915 /* Open the file again to check the data. */
|
Chris@0
|
2916 file = test_open_file_or_die (filename, SFM_RDWR, &sfinfo, allow_fd, __LINE__) ;
|
Chris@0
|
2917
|
Chris@0
|
2918 if (sfinfo.format != format)
|
Chris@0
|
2919 { printf ("\n\nLine %d : Returned format incorrect (0x%08X => 0x%08X).\n", __LINE__, format, sfinfo.format) ;
|
Chris@0
|
2920 exit (1) ;
|
Chris@0
|
2921 } ;
|
Chris@0
|
2922
|
Chris@0
|
2923 if (sfinfo.frames < 3 * DATA_LENGTH)
|
Chris@0
|
2924 { printf ("\n\nLine %d : Not enough frames in file. (%ld < %d)\n", __LINE__, SF_COUNT_TO_LONG (sfinfo.frames), 3 * DATA_LENGTH ) ;
|
Chris@0
|
2925 exit (1) ;
|
Chris@0
|
2926 }
|
Chris@0
|
2927
|
Chris@0
|
2928 if (! long_file_ok && sfinfo.frames != 3 * DATA_LENGTH)
|
Chris@0
|
2929 { printf ("\n\nLine %d : Incorrect number of frames in file. (%ld should be %d)\n", __LINE__, SF_COUNT_TO_LONG (sfinfo.frames), 3 * DATA_LENGTH ) ;
|
Chris@0
|
2930 exit (1) ;
|
Chris@0
|
2931 } ;
|
Chris@0
|
2932
|
Chris@0
|
2933 if (sfinfo.channels != 1)
|
Chris@0
|
2934 { printf ("\n\nLine %d : Incorrect number of channels in file.\n", __LINE__) ;
|
Chris@0
|
2935 exit (1) ;
|
Chris@0
|
2936 } ;
|
Chris@0
|
2937
|
Chris@0
|
2938 if (! long_file_ok)
|
Chris@0
|
2939 test_read_write_position_or_die (file, __LINE__, 0, 0, 3 * DATA_LENGTH) ;
|
Chris@0
|
2940 else
|
Chris@0
|
2941 test_seek_or_die (file, 3 * DATA_LENGTH, SFM_WRITE | SEEK_SET, 3 * DATA_LENGTH, sfinfo.channels, __LINE__) ;
|
Chris@0
|
2942
|
Chris@0
|
2943 for (pass = 1 ; pass <= 3 ; pass ++)
|
Chris@0
|
2944 { orig [20] = pass * 2 ;
|
Chris@0
|
2945
|
Chris@0
|
2946 test_read_write_position_or_die (file, __LINE__, pass, (pass - 1) * DATA_LENGTH, 3 * DATA_LENGTH) ;
|
Chris@0
|
2947
|
Chris@0
|
2948 /* Read what we just wrote. */
|
Chris@0
|
2949 test_read_float_or_die (file, pass, test, DATA_LENGTH, __LINE__) ;
|
Chris@0
|
2950
|
Chris@0
|
2951 /* Check the data. */
|
Chris@0
|
2952 for (k = 0 ; k < DATA_LENGTH ; k++)
|
Chris@0
|
2953 if (FLOAT_ERROR (orig [k], test [k]))
|
Chris@0
|
2954 { printf ("\n\nLine %d (pass %d) B : Error at sample %d (%g => %g).\n", __LINE__, pass, k, orig [k], test [k]) ;
|
Chris@0
|
2955 oct_save_float (orig, test, DATA_LENGTH) ;
|
Chris@0
|
2956 exit (1) ;
|
Chris@0
|
2957 } ;
|
Chris@0
|
2958
|
Chris@0
|
2959 } ; /* for (pass ...) */
|
Chris@0
|
2960
|
Chris@0
|
2961 sf_close (file) ;
|
Chris@0
|
2962 } /* mono_rdwr_float_test */
|
Chris@0
|
2963
|
Chris@0
|
2964 static void
|
Chris@0
|
2965 new_rdwr_float_test (const char *filename, int format, int allow_fd)
|
Chris@0
|
2966 { SNDFILE *wfile, *rwfile ;
|
Chris@0
|
2967 SF_INFO sfinfo ;
|
Chris@0
|
2968 float *orig, *test ;
|
Chris@0
|
2969 int items, frames ;
|
Chris@0
|
2970
|
Chris@0
|
2971 orig = orig_data.f ;
|
Chris@0
|
2972 test = test_data.f ;
|
Chris@0
|
2973
|
Chris@0
|
2974 sfinfo.samplerate = 44100 ;
|
Chris@0
|
2975 sfinfo.frames = SILLY_WRITE_COUNT ; /* Wrong length. Library should correct this on sf_close. */
|
Chris@0
|
2976 sfinfo.channels = 2 ;
|
Chris@0
|
2977 sfinfo.format = format ;
|
Chris@0
|
2978
|
Chris@0
|
2979 items = DATA_LENGTH ;
|
Chris@0
|
2980 frames = items / sfinfo.channels ;
|
Chris@0
|
2981
|
Chris@0
|
2982 wfile = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, allow_fd, __LINE__) ;
|
Chris@0
|
2983 sf_command (wfile, SFC_SET_UPDATE_HEADER_AUTO, NULL, SF_TRUE) ;
|
Chris@0
|
2984 test_writef_float_or_die (wfile, 1, orig, frames, __LINE__) ;
|
Chris@0
|
2985 sf_write_sync (wfile) ;
|
Chris@0
|
2986 test_writef_float_or_die (wfile, 2, orig, frames, __LINE__) ;
|
Chris@0
|
2987 sf_write_sync (wfile) ;
|
Chris@0
|
2988
|
Chris@0
|
2989 rwfile = test_open_file_or_die (filename, SFM_RDWR, &sfinfo, allow_fd, __LINE__) ;
|
Chris@0
|
2990 if (sfinfo.frames != 2 * frames)
|
Chris@0
|
2991 { printf ("\n\nLine %d : incorrect number of frames in file (%ld should be %d)\n\n", __LINE__, SF_COUNT_TO_LONG (sfinfo.frames), 2 * frames) ;
|
Chris@0
|
2992 exit (1) ;
|
Chris@0
|
2993 } ;
|
Chris@0
|
2994
|
Chris@0
|
2995 test_writef_float_or_die (wfile, 3, orig, frames, __LINE__) ;
|
Chris@0
|
2996
|
Chris@0
|
2997 test_readf_float_or_die (rwfile, 1, test, frames, __LINE__) ;
|
Chris@0
|
2998 test_readf_float_or_die (rwfile, 2, test, frames, __LINE__) ;
|
Chris@0
|
2999
|
Chris@0
|
3000 sf_close (wfile) ;
|
Chris@0
|
3001 sf_close (rwfile) ;
|
Chris@0
|
3002 } /* new_rdwr_float_test */
|
Chris@0
|
3003
|
Chris@0
|
3004
|
Chris@0
|
3005 /*======================================================================================
|
Chris@0
|
3006 */
|
Chris@0
|
3007
|
Chris@0
|
3008 static void mono_double_test (const char *filename, int format, int long_file_ok, int allow_fd) ;
|
Chris@0
|
3009 static void stereo_double_test (const char *filename, int format, int long_file_ok, int allow_fd) ;
|
Chris@0
|
3010 static void mono_rdwr_double_test (const char *filename, int format, int long_file_ok, int allow_fd) ;
|
Chris@0
|
3011 static void new_rdwr_double_test (const char *filename, int format, int allow_fd) ;
|
Chris@0
|
3012 static void multi_seek_test (const char * filename, int format) ;
|
Chris@0
|
3013 static void write_seek_extend_test (const char * filename, int format) ;
|
Chris@0
|
3014
|
Chris@0
|
3015 static void
|
Chris@0
|
3016 pcm_test_double (const char *filename, int format, int long_file_ok)
|
Chris@0
|
3017 { SF_INFO sfinfo ;
|
Chris@0
|
3018 double *orig ;
|
Chris@0
|
3019 int k, allow_fd ;
|
Chris@0
|
3020
|
Chris@0
|
3021 /* Sd2 files cannot be opened from an existing file descriptor. */
|
Chris@0
|
3022 allow_fd = ((format & SF_FORMAT_TYPEMASK) == SF_FORMAT_SD2) ? SF_FALSE : SF_TRUE ;
|
Chris@0
|
3023
|
Chris@0
|
3024 print_test_name ("pcm_test_double", filename) ;
|
Chris@0
|
3025
|
Chris@0
|
3026 sfinfo.samplerate = 44100 ;
|
Chris@0
|
3027 sfinfo.frames = SILLY_WRITE_COUNT ; /* Wrong length. Library should correct this on sf_close. */
|
Chris@0
|
3028 sfinfo.channels = 1 ;
|
Chris@0
|
3029 sfinfo.format = format ;
|
Chris@0
|
3030
|
Chris@0
|
3031 gen_windowed_sine_double (orig_data.d, DATA_LENGTH, 1.0) ;
|
Chris@0
|
3032
|
Chris@0
|
3033 orig = orig_data.d ;
|
Chris@0
|
3034
|
Chris@0
|
3035 /* Make this a macro so gdb steps over it in one go. */
|
Chris@0
|
3036 CONVERT_DATA (k, DATA_LENGTH, orig, orig_data.d) ;
|
Chris@0
|
3037
|
Chris@0
|
3038 /* Some test broken out here. */
|
Chris@0
|
3039
|
Chris@0
|
3040 mono_double_test (filename, format, long_file_ok, allow_fd) ;
|
Chris@0
|
3041
|
Chris@0
|
3042 /* Sub format DWVW does not allow seeking. */
|
Chris@0
|
3043 if ((format & SF_FORMAT_SUBMASK) == SF_FORMAT_DWVW_16 ||
|
Chris@0
|
3044 (format & SF_FORMAT_SUBMASK) == SF_FORMAT_DWVW_24)
|
Chris@0
|
3045 { unlink (filename) ;
|
Chris@0
|
3046 printf ("no seek : ok\n") ;
|
Chris@0
|
3047 return ;
|
Chris@0
|
3048 } ;
|
Chris@0
|
3049
|
Chris@0
|
3050 if ((format & SF_FORMAT_TYPEMASK) != SF_FORMAT_FLAC)
|
Chris@0
|
3051 mono_rdwr_double_test (filename, format, long_file_ok, allow_fd) ;
|
Chris@0
|
3052
|
Chris@0
|
3053 /* If the format doesn't support stereo we're done. */
|
Chris@0
|
3054 sfinfo.channels = 2 ;
|
Chris@0
|
3055 if (sf_format_check (&sfinfo) == 0)
|
Chris@0
|
3056 { unlink (filename) ;
|
Chris@0
|
3057 puts ("no stereo : ok") ;
|
Chris@0
|
3058 return ;
|
Chris@0
|
3059 } ;
|
Chris@0
|
3060
|
Chris@0
|
3061 stereo_double_test (filename, format, long_file_ok, allow_fd) ;
|
Chris@0
|
3062
|
Chris@0
|
3063 /* New read/write test. Not sure if this is needed yet. */
|
Chris@0
|
3064
|
Chris@0
|
3065 if ((format & SF_FORMAT_TYPEMASK) != SF_FORMAT_PAF &&
|
Chris@0
|
3066 (format & SF_FORMAT_TYPEMASK) != SF_FORMAT_VOC &&
|
Chris@0
|
3067 (format & SF_FORMAT_TYPEMASK) != SF_FORMAT_FLAC)
|
Chris@0
|
3068 new_rdwr_double_test (filename, format, allow_fd) ;
|
Chris@0
|
3069
|
Chris@0
|
3070 delete_file (format, filename) ;
|
Chris@0
|
3071
|
Chris@0
|
3072 puts ("ok") ;
|
Chris@0
|
3073 return ;
|
Chris@0
|
3074 } /* pcm_test_double */
|
Chris@0
|
3075
|
Chris@0
|
3076 static void
|
Chris@0
|
3077 mono_double_test (const char *filename, int format, int long_file_ok, int allow_fd)
|
Chris@0
|
3078 { SNDFILE *file ;
|
Chris@0
|
3079 SF_INFO sfinfo ;
|
Chris@0
|
3080 double *orig, *test ;
|
Chris@0
|
3081 sf_count_t count ;
|
Chris@0
|
3082 int k, items ;
|
Chris@0
|
3083
|
Chris@0
|
3084 sfinfo.samplerate = 44100 ;
|
Chris@0
|
3085 sfinfo.frames = SILLY_WRITE_COUNT ; /* Wrong length. Library should correct this on sf_close. */
|
Chris@0
|
3086 sfinfo.channels = 1 ;
|
Chris@0
|
3087 sfinfo.format = format ;
|
Chris@0
|
3088
|
Chris@0
|
3089 orig = orig_data.d ;
|
Chris@0
|
3090 test = test_data.d ;
|
Chris@0
|
3091
|
Chris@0
|
3092 items = DATA_LENGTH ;
|
Chris@0
|
3093
|
Chris@0
|
3094 file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, allow_fd, __LINE__) ;
|
Chris@0
|
3095
|
Chris@0
|
3096 sf_set_string (file, SF_STR_ARTIST, "Your name here") ;
|
Chris@0
|
3097
|
Chris@0
|
3098 test_write_double_or_die (file, 0, orig, items, __LINE__) ;
|
Chris@0
|
3099 sf_write_sync (file) ;
|
Chris@0
|
3100 test_write_double_or_die (file, 0, orig, items, __LINE__) ;
|
Chris@0
|
3101 sf_write_sync (file) ;
|
Chris@0
|
3102
|
Chris@0
|
3103 /* Add non-audio data after the audio. */
|
Chris@0
|
3104 sf_set_string (file, SF_STR_COPYRIGHT, "Copyright (c) 2003") ;
|
Chris@0
|
3105
|
Chris@0
|
3106 sf_close (file) ;
|
Chris@0
|
3107
|
Chris@0
|
3108 memset (test, 0, items * sizeof (double)) ;
|
Chris@0
|
3109
|
Chris@0
|
3110 if ((format & SF_FORMAT_TYPEMASK) != SF_FORMAT_RAW)
|
Chris@0
|
3111 memset (&sfinfo, 0, sizeof (sfinfo)) ;
|
Chris@0
|
3112
|
Chris@0
|
3113 file = test_open_file_or_die (filename, SFM_READ, &sfinfo, allow_fd, __LINE__) ;
|
Chris@0
|
3114
|
Chris@0
|
3115 if (sfinfo.format != format)
|
Chris@0
|
3116 { printf ("\n\nLine %d : Mono : Returned format incorrect (0x%08X => 0x%08X).\n", __LINE__, format, sfinfo.format) ;
|
Chris@0
|
3117 exit (1) ;
|
Chris@0
|
3118 } ;
|
Chris@0
|
3119
|
Chris@0
|
3120 if (sfinfo.frames < 2 * items)
|
Chris@0
|
3121 { printf ("\n\nLine %d : Mono : Incorrect number of frames in file (too short). (%ld should be %d)\n", __LINE__, SF_COUNT_TO_LONG (sfinfo.frames), items) ;
|
Chris@0
|
3122 exit (1) ;
|
Chris@0
|
3123 } ;
|
Chris@0
|
3124
|
Chris@0
|
3125 if (! long_file_ok && sfinfo.frames > 2 * items)
|
Chris@0
|
3126 { printf ("\n\nLine %d : Mono : Incorrect number of frames in file (too long). (%ld should be %d)\n", __LINE__, SF_COUNT_TO_LONG (sfinfo.frames), items) ;
|
Chris@0
|
3127 exit (1) ;
|
Chris@0
|
3128 } ;
|
Chris@0
|
3129
|
Chris@0
|
3130 if (sfinfo.channels != 1)
|
Chris@0
|
3131 { printf ("\n\nLine %d : Mono : Incorrect number of channels in file.\n", __LINE__) ;
|
Chris@0
|
3132 exit (1) ;
|
Chris@0
|
3133 } ;
|
Chris@0
|
3134
|
Chris@0
|
3135 check_log_buffer_or_die (file, __LINE__) ;
|
Chris@0
|
3136
|
Chris@0
|
3137 test_read_double_or_die (file, 0, test, items, __LINE__) ;
|
Chris@0
|
3138 for (k = 0 ; k < items ; k++)
|
Chris@0
|
3139 if (FLOAT_ERROR (orig [k], test [k]))
|
Chris@0
|
3140 { printf ("\n\nLine %d: Mono : Incorrect sample A (#%d : %g => %g).\n", __LINE__, k, orig [k], test [k]) ;
|
Chris@0
|
3141 oct_save_double (orig, test, items) ;
|
Chris@0
|
3142 exit (1) ;
|
Chris@0
|
3143 } ;
|
Chris@0
|
3144
|
Chris@0
|
3145 /* Seek to start of file. */
|
Chris@0
|
3146 test_seek_or_die (file, 0, SEEK_SET, 0, sfinfo.channels, __LINE__) ;
|
Chris@0
|
3147
|
Chris@0
|
3148 test_read_double_or_die (file, 0, test, 4, __LINE__) ;
|
Chris@0
|
3149 for (k = 0 ; k < 4 ; k++)
|
Chris@0
|
3150 if (FLOAT_ERROR (orig [k], test [k]))
|
Chris@0
|
3151 { printf ("\n\nLine %d : Mono : Incorrect sample A (#%d : %g => %g).\n", __LINE__, k, orig [k], test [k]) ;
|
Chris@0
|
3152 exit (1) ;
|
Chris@0
|
3153 } ;
|
Chris@0
|
3154
|
Chris@0
|
3155 if ((format & SF_FORMAT_SUBMASK) == SF_FORMAT_DWVW_16 ||
|
Chris@0
|
3156 (format & SF_FORMAT_SUBMASK) == SF_FORMAT_DWVW_24)
|
Chris@0
|
3157 { sf_close (file) ;
|
Chris@0
|
3158 unlink (filename) ;
|
Chris@0
|
3159 printf ("no seek : ") ;
|
Chris@0
|
3160 return ;
|
Chris@0
|
3161 } ;
|
Chris@0
|
3162
|
Chris@0
|
3163 /* Seek to offset from start of file. */
|
Chris@0
|
3164 test_seek_or_die (file, items + 10, SEEK_SET, items + 10, sfinfo.channels, __LINE__) ;
|
Chris@0
|
3165
|
Chris@0
|
3166 test_read_double_or_die (file, 0, test + 10, 4, __LINE__) ;
|
Chris@0
|
3167 for (k = 10 ; k < 14 ; k++)
|
Chris@0
|
3168 if (FLOAT_ERROR (orig [k], test [k]))
|
Chris@0
|
3169 { printf ("\n\nLine %d : Mono : Incorrect sample A (#%d : %g => %g).\n", __LINE__, k, test [k], orig [k]) ;
|
Chris@0
|
3170 exit (1) ;
|
Chris@0
|
3171 } ;
|
Chris@0
|
3172
|
Chris@0
|
3173 /* Seek to offset from current position. */
|
Chris@0
|
3174 test_seek_or_die (file, 6, SEEK_CUR, items + 20, sfinfo.channels, __LINE__) ;
|
Chris@0
|
3175
|
Chris@0
|
3176 test_read_double_or_die (file, 0, test + 20, 4, __LINE__) ;
|
Chris@0
|
3177 for (k = 20 ; k < 24 ; k++)
|
Chris@0
|
3178 if (FLOAT_ERROR (orig [k], test [k]))
|
Chris@0
|
3179 { printf ("\n\nLine %d : Mono : Incorrect sample A (#%d : %g => %g).\n", __LINE__, k, test [k], orig [k]) ;
|
Chris@0
|
3180 exit (1) ;
|
Chris@0
|
3181 } ;
|
Chris@0
|
3182
|
Chris@0
|
3183 /* Seek to offset from end of file. */
|
Chris@0
|
3184 test_seek_or_die (file, -1 * (sfinfo.frames - 10), SEEK_END, 10, sfinfo.channels, __LINE__) ;
|
Chris@0
|
3185
|
Chris@0
|
3186 test_read_double_or_die (file, 0, test + 10, 4, __LINE__) ;
|
Chris@0
|
3187 for (k = 10 ; k < 14 ; k++)
|
Chris@0
|
3188 if (FLOAT_ERROR (orig [k], test [k]))
|
Chris@0
|
3189 { printf ("\n\nLine %d : Mono : Incorrect sample D (#%d : %g => %g).\n", __LINE__, k, test [k], orig [k]) ;
|
Chris@0
|
3190 exit (1) ;
|
Chris@0
|
3191 } ;
|
Chris@0
|
3192
|
Chris@0
|
3193 /* Check read past end of file followed by sf_seek (sndfile, 0, SEEK_CUR). */
|
Chris@0
|
3194 test_seek_or_die (file, 0, SEEK_SET, 0, sfinfo.channels, __LINE__) ;
|
Chris@0
|
3195
|
Chris@0
|
3196 count = 0 ;
|
Chris@0
|
3197 while (count < sfinfo.frames)
|
Chris@0
|
3198 count += sf_read_double (file, test, 311) ;
|
Chris@0
|
3199
|
Chris@0
|
3200 /* Check that no error has occurred. */
|
Chris@0
|
3201 if (sf_error (file))
|
Chris@0
|
3202 { printf ("\n\nLine %d : Mono : error where there shouldn't have been one.\n", __LINE__) ;
|
Chris@0
|
3203 puts (sf_strerror (file)) ;
|
Chris@0
|
3204 exit (1) ;
|
Chris@0
|
3205 } ;
|
Chris@0
|
3206
|
Chris@0
|
3207 /* Check that we haven't read beyond EOF. */
|
Chris@0
|
3208 if (count > sfinfo.frames)
|
Chris@0
|
3209 { printf ("\n\nLines %d : read past end of file (%ld should be %ld)\n", __LINE__, (long) count, (long) sfinfo.frames) ;
|
Chris@0
|
3210 exit (1) ;
|
Chris@0
|
3211 } ;
|
Chris@0
|
3212
|
Chris@0
|
3213 test_seek_or_die (file, 0, SEEK_CUR, sfinfo.frames, sfinfo.channels, __LINE__) ;
|
Chris@0
|
3214
|
Chris@0
|
3215 sf_close (file) ;
|
Chris@0
|
3216
|
Chris@0
|
3217 multi_seek_test (filename, format) ;
|
Chris@0
|
3218 write_seek_extend_test (filename, format) ;
|
Chris@0
|
3219
|
Chris@0
|
3220 } /* mono_double_test */
|
Chris@0
|
3221
|
Chris@0
|
3222 static void
|
Chris@0
|
3223 stereo_double_test (const char *filename, int format, int long_file_ok, int allow_fd)
|
Chris@0
|
3224 { SNDFILE *file ;
|
Chris@0
|
3225 SF_INFO sfinfo ;
|
Chris@0
|
3226 double *orig, *test ;
|
Chris@0
|
3227 int k, items, frames ;
|
Chris@0
|
3228
|
Chris@0
|
3229 sfinfo.samplerate = 44100 ;
|
Chris@0
|
3230 sfinfo.frames = SILLY_WRITE_COUNT ; /* Wrong length. Library should correct this on sf_close. */
|
Chris@0
|
3231 sfinfo.channels = 2 ;
|
Chris@0
|
3232 sfinfo.format = format ;
|
Chris@0
|
3233
|
Chris@0
|
3234 gen_windowed_sine_double (orig_data.d, DATA_LENGTH, 1.0) ;
|
Chris@0
|
3235
|
Chris@0
|
3236 orig = orig_data.d ;
|
Chris@0
|
3237 test = test_data.d ;
|
Chris@0
|
3238
|
Chris@0
|
3239 /* Make this a macro so gdb steps over it in one go. */
|
Chris@0
|
3240 CONVERT_DATA (k, DATA_LENGTH, orig, orig_data.d) ;
|
Chris@0
|
3241
|
Chris@0
|
3242 items = DATA_LENGTH ;
|
Chris@0
|
3243 frames = items / sfinfo.channels ;
|
Chris@0
|
3244
|
Chris@0
|
3245 file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, allow_fd, __LINE__) ;
|
Chris@0
|
3246
|
Chris@0
|
3247 sf_set_string (file, SF_STR_ARTIST, "Your name here") ;
|
Chris@0
|
3248
|
Chris@0
|
3249 test_writef_double_or_die (file, 0, orig, frames, __LINE__) ;
|
Chris@0
|
3250
|
Chris@0
|
3251 sf_set_string (file, SF_STR_COPYRIGHT, "Copyright (c) 2003") ;
|
Chris@0
|
3252
|
Chris@0
|
3253 sf_close (file) ;
|
Chris@0
|
3254
|
Chris@0
|
3255 memset (test, 0, items * sizeof (double)) ;
|
Chris@0
|
3256
|
Chris@0
|
3257 if ((format & SF_FORMAT_TYPEMASK) != SF_FORMAT_RAW)
|
Chris@0
|
3258 memset (&sfinfo, 0, sizeof (sfinfo)) ;
|
Chris@0
|
3259
|
Chris@0
|
3260 file = test_open_file_or_die (filename, SFM_READ, &sfinfo, allow_fd, __LINE__) ;
|
Chris@0
|
3261
|
Chris@0
|
3262 if (sfinfo.format != format)
|
Chris@0
|
3263 { printf ("\n\nLine %d : Stereo : Returned format incorrect (0x%08X => 0x%08X).\n",
|
Chris@0
|
3264 __LINE__, format, sfinfo.format) ;
|
Chris@0
|
3265 exit (1) ;
|
Chris@0
|
3266 } ;
|
Chris@0
|
3267
|
Chris@0
|
3268 if (sfinfo.frames < frames)
|
Chris@0
|
3269 { printf ("\n\nLine %d : Stereo : Incorrect number of frames in file (too short). (%ld should be %d)\n",
|
Chris@0
|
3270 __LINE__, SF_COUNT_TO_LONG (sfinfo.frames), frames) ;
|
Chris@0
|
3271 exit (1) ;
|
Chris@0
|
3272 } ;
|
Chris@0
|
3273
|
Chris@0
|
3274 if (! long_file_ok && sfinfo.frames > frames)
|
Chris@0
|
3275 { printf ("\n\nLine %d : Stereo : Incorrect number of frames in file (too long). (%ld should be %d)\n",
|
Chris@0
|
3276 __LINE__, SF_COUNT_TO_LONG (sfinfo.frames), frames) ;
|
Chris@0
|
3277 exit (1) ;
|
Chris@0
|
3278 } ;
|
Chris@0
|
3279
|
Chris@0
|
3280 if (sfinfo.channels != 2)
|
Chris@0
|
3281 { printf ("\n\nLine %d : Stereo : Incorrect number of channels in file.\n", __LINE__) ;
|
Chris@0
|
3282 exit (1) ;
|
Chris@0
|
3283 } ;
|
Chris@0
|
3284
|
Chris@0
|
3285 check_log_buffer_or_die (file, __LINE__) ;
|
Chris@0
|
3286
|
Chris@0
|
3287 test_readf_double_or_die (file, 0, test, frames, __LINE__) ;
|
Chris@0
|
3288 for (k = 0 ; k < items ; k++)
|
Chris@0
|
3289 if (FLOAT_ERROR (test [k], orig [k]))
|
Chris@0
|
3290 { printf ("\n\nLine %d : Stereo : Incorrect sample (#%d : %g => %g).\n", __LINE__, k, orig [k], test [k]) ;
|
Chris@0
|
3291 exit (1) ;
|
Chris@0
|
3292 } ;
|
Chris@0
|
3293
|
Chris@0
|
3294 /* Seek to start of file. */
|
Chris@0
|
3295 test_seek_or_die (file, 0, SEEK_SET, 0, sfinfo.channels, __LINE__) ;
|
Chris@0
|
3296
|
Chris@0
|
3297 test_readf_double_or_die (file, 0, test, 2, __LINE__) ;
|
Chris@0
|
3298 for (k = 0 ; k < 4 ; k++)
|
Chris@0
|
3299 if (FLOAT_ERROR (test [k], orig [k]))
|
Chris@0
|
3300 { printf ("\n\nLine %d : Stereo : Incorrect sample (#%d : %g => %g).\n", __LINE__, k, orig [k], test [k]) ;
|
Chris@0
|
3301 exit (1) ;
|
Chris@0
|
3302 } ;
|
Chris@0
|
3303
|
Chris@0
|
3304 /* Seek to offset from start of file. */
|
Chris@0
|
3305 test_seek_or_die (file, 10, SEEK_SET, 10, sfinfo.channels, __LINE__) ;
|
Chris@0
|
3306
|
Chris@0
|
3307 /* Check for errors here. */
|
Chris@0
|
3308 if (sf_error (file))
|
Chris@0
|
3309 { printf ("Line %d: Should NOT return an error.\n", __LINE__) ;
|
Chris@0
|
3310 puts (sf_strerror (file)) ;
|
Chris@0
|
3311 exit (1) ;
|
Chris@0
|
3312 } ;
|
Chris@0
|
3313
|
Chris@0
|
3314 if (sf_read_double (file, test, 1) > 0)
|
Chris@0
|
3315 { printf ("Line %d: Should return 0.\n", __LINE__) ;
|
Chris@0
|
3316 exit (1) ;
|
Chris@0
|
3317 } ;
|
Chris@0
|
3318
|
Chris@0
|
3319 if (! sf_error (file))
|
Chris@0
|
3320 { printf ("Line %d: Should return an error.\n", __LINE__) ;
|
Chris@0
|
3321 exit (1) ;
|
Chris@0
|
3322 } ;
|
Chris@0
|
3323 /*-----------------------*/
|
Chris@0
|
3324
|
Chris@0
|
3325 test_readf_double_or_die (file, 0, test + 10, 2, __LINE__) ;
|
Chris@0
|
3326 for (k = 20 ; k < 24 ; k++)
|
Chris@0
|
3327 if (FLOAT_ERROR (test [k], orig [k]))
|
Chris@0
|
3328 { printf ("\n\nLine %d : Stereo : Incorrect sample (#%d : %g => %g).\n", __LINE__, k, orig [k], test [k]) ;
|
Chris@0
|
3329 exit (1) ;
|
Chris@0
|
3330 } ;
|
Chris@0
|
3331
|
Chris@0
|
3332 /* Seek to offset from current position. */
|
Chris@0
|
3333 test_seek_or_die (file, 8, SEEK_CUR, 20, sfinfo.channels, __LINE__) ;
|
Chris@0
|
3334
|
Chris@0
|
3335 test_readf_double_or_die (file, 0, test + 20, 2, __LINE__) ;
|
Chris@0
|
3336 for (k = 40 ; k < 44 ; k++)
|
Chris@0
|
3337 if (FLOAT_ERROR (test [k], orig [k]))
|
Chris@0
|
3338 { printf ("\n\nLine %d : Stereo : Incorrect sample (#%d : %g => %g).\n", __LINE__, k, orig [k], test [k]) ;
|
Chris@0
|
3339 exit (1) ;
|
Chris@0
|
3340 } ;
|
Chris@0
|
3341
|
Chris@0
|
3342 /* Seek to offset from end of file. */
|
Chris@0
|
3343 test_seek_or_die (file, -1 * (sfinfo.frames - 10), SEEK_END, 10, sfinfo.channels, __LINE__) ;
|
Chris@0
|
3344
|
Chris@0
|
3345 test_readf_double_or_die (file, 0, test + 20, 2, __LINE__) ;
|
Chris@0
|
3346 for (k = 20 ; k < 24 ; k++)
|
Chris@0
|
3347 if (FLOAT_ERROR (test [k], orig [k]))
|
Chris@0
|
3348 { printf ("\n\nLine %d : Stereo : Incorrect sample (#%d : %g => %g).\n", __LINE__, k, orig [k], test [k]) ;
|
Chris@0
|
3349 exit (1) ;
|
Chris@0
|
3350 } ;
|
Chris@0
|
3351
|
Chris@0
|
3352 sf_close (file) ;
|
Chris@0
|
3353 } /* stereo_double_test */
|
Chris@0
|
3354
|
Chris@0
|
3355 static void
|
Chris@0
|
3356 mono_rdwr_double_test (const char *filename, int format, int long_file_ok, int allow_fd)
|
Chris@0
|
3357 { SNDFILE *file ;
|
Chris@0
|
3358 SF_INFO sfinfo ;
|
Chris@0
|
3359 double *orig, *test ;
|
Chris@0
|
3360 int k, pass ;
|
Chris@0
|
3361
|
Chris@0
|
3362 orig = orig_data.d ;
|
Chris@0
|
3363 test = test_data.d ;
|
Chris@0
|
3364
|
Chris@0
|
3365 sfinfo.samplerate = SAMPLE_RATE ;
|
Chris@0
|
3366 sfinfo.frames = DATA_LENGTH ;
|
Chris@0
|
3367 sfinfo.channels = 1 ;
|
Chris@0
|
3368 sfinfo.format = format ;
|
Chris@0
|
3369
|
Chris@0
|
3370 if ((format & SF_FORMAT_TYPEMASK) == SF_FORMAT_RAW
|
Chris@0
|
3371 || (format & SF_FORMAT_TYPEMASK) == SF_FORMAT_AU
|
Chris@0
|
3372 || (format & SF_FORMAT_TYPEMASK) == SF_FORMAT_SD2)
|
Chris@0
|
3373 unlink (filename) ;
|
Chris@0
|
3374 else
|
Chris@0
|
3375 { /* Create a short file. */
|
Chris@0
|
3376 create_short_file (filename) ;
|
Chris@0
|
3377
|
Chris@0
|
3378 /* Opening a already existing short file (ie invalid header) RDWR is disallowed.
|
Chris@0
|
3379 ** If this returns a valif pointer sf_open() screwed up.
|
Chris@0
|
3380 */
|
Chris@0
|
3381 if ((file = sf_open (filename, SFM_RDWR, &sfinfo)))
|
Chris@0
|
3382 { printf ("\n\nLine %d: sf_open should (SFM_RDWR) have failed but didn't.\n", __LINE__) ;
|
Chris@0
|
3383 exit (1) ;
|
Chris@0
|
3384 } ;
|
Chris@0
|
3385
|
Chris@0
|
3386 /* Truncate the file to zero bytes. */
|
Chris@0
|
3387 if (truncate (filename, 0) < 0)
|
Chris@0
|
3388 { printf ("\n\nLine %d: truncate (%s) failed", __LINE__, filename) ;
|
Chris@0
|
3389 perror (NULL) ;
|
Chris@0
|
3390 exit (1) ;
|
Chris@0
|
3391 } ;
|
Chris@0
|
3392 } ;
|
Chris@0
|
3393
|
Chris@0
|
3394 /* Opening a zero length file RDWR is allowed, but the SF_INFO struct must contain
|
Chris@0
|
3395 ** all the usual data required when opening the file in WRITE mode.
|
Chris@0
|
3396 */
|
Chris@0
|
3397 sfinfo.samplerate = SAMPLE_RATE ;
|
Chris@0
|
3398 sfinfo.frames = DATA_LENGTH ;
|
Chris@0
|
3399 sfinfo.channels = 1 ;
|
Chris@0
|
3400 sfinfo.format = format ;
|
Chris@0
|
3401
|
Chris@0
|
3402 file = test_open_file_or_die (filename, SFM_RDWR, &sfinfo, allow_fd, __LINE__) ;
|
Chris@0
|
3403
|
Chris@0
|
3404 /* Do 3 writes followed by reads. After each, check the data and the current
|
Chris@0
|
3405 ** read and write offsets.
|
Chris@0
|
3406 */
|
Chris@0
|
3407 for (pass = 1 ; pass <= 3 ; pass ++)
|
Chris@0
|
3408 { orig [20] = pass * 2 ;
|
Chris@0
|
3409
|
Chris@0
|
3410 /* Write some data. */
|
Chris@0
|
3411 test_write_double_or_die (file, pass, orig, DATA_LENGTH, __LINE__) ;
|
Chris@0
|
3412
|
Chris@0
|
3413 test_read_write_position_or_die (file, __LINE__, pass, (pass - 1) * DATA_LENGTH, pass * DATA_LENGTH) ;
|
Chris@0
|
3414
|
Chris@0
|
3415 /* Read what we just wrote. */
|
Chris@0
|
3416 test_read_double_or_die (file, 0, test, DATA_LENGTH, __LINE__) ;
|
Chris@0
|
3417
|
Chris@0
|
3418 /* Check the data. */
|
Chris@0
|
3419 for (k = 0 ; k < DATA_LENGTH ; k++)
|
Chris@0
|
3420 if (FLOAT_ERROR (orig [k], test [k]))
|
Chris@0
|
3421 { printf ("\n\nLine %d (pass %d) A : Error at sample %d (%g => %g).\n", __LINE__, pass, k, orig [k], test [k]) ;
|
Chris@0
|
3422 oct_save_double (orig, test, DATA_LENGTH) ;
|
Chris@0
|
3423 exit (1) ;
|
Chris@0
|
3424 } ;
|
Chris@0
|
3425
|
Chris@0
|
3426 test_read_write_position_or_die (file, __LINE__, pass, pass * DATA_LENGTH, pass * DATA_LENGTH) ;
|
Chris@0
|
3427 } ; /* for (pass ...) */
|
Chris@0
|
3428
|
Chris@0
|
3429 sf_close (file) ;
|
Chris@0
|
3430
|
Chris@0
|
3431 /* Open the file again to check the data. */
|
Chris@0
|
3432 file = test_open_file_or_die (filename, SFM_RDWR, &sfinfo, allow_fd, __LINE__) ;
|
Chris@0
|
3433
|
Chris@0
|
3434 if (sfinfo.format != format)
|
Chris@0
|
3435 { printf ("\n\nLine %d : Returned format incorrect (0x%08X => 0x%08X).\n", __LINE__, format, sfinfo.format) ;
|
Chris@0
|
3436 exit (1) ;
|
Chris@0
|
3437 } ;
|
Chris@0
|
3438
|
Chris@0
|
3439 if (sfinfo.frames < 3 * DATA_LENGTH)
|
Chris@0
|
3440 { printf ("\n\nLine %d : Not enough frames in file. (%ld < %d)\n", __LINE__, SF_COUNT_TO_LONG (sfinfo.frames), 3 * DATA_LENGTH ) ;
|
Chris@0
|
3441 exit (1) ;
|
Chris@0
|
3442 }
|
Chris@0
|
3443
|
Chris@0
|
3444 if (! long_file_ok && sfinfo.frames != 3 * DATA_LENGTH)
|
Chris@0
|
3445 { printf ("\n\nLine %d : Incorrect number of frames in file. (%ld should be %d)\n", __LINE__, SF_COUNT_TO_LONG (sfinfo.frames), 3 * DATA_LENGTH ) ;
|
Chris@0
|
3446 exit (1) ;
|
Chris@0
|
3447 } ;
|
Chris@0
|
3448
|
Chris@0
|
3449 if (sfinfo.channels != 1)
|
Chris@0
|
3450 { printf ("\n\nLine %d : Incorrect number of channels in file.\n", __LINE__) ;
|
Chris@0
|
3451 exit (1) ;
|
Chris@0
|
3452 } ;
|
Chris@0
|
3453
|
Chris@0
|
3454 if (! long_file_ok)
|
Chris@0
|
3455 test_read_write_position_or_die (file, __LINE__, 0, 0, 3 * DATA_LENGTH) ;
|
Chris@0
|
3456 else
|
Chris@0
|
3457 test_seek_or_die (file, 3 * DATA_LENGTH, SFM_WRITE | SEEK_SET, 3 * DATA_LENGTH, sfinfo.channels, __LINE__) ;
|
Chris@0
|
3458
|
Chris@0
|
3459 for (pass = 1 ; pass <= 3 ; pass ++)
|
Chris@0
|
3460 { orig [20] = pass * 2 ;
|
Chris@0
|
3461
|
Chris@0
|
3462 test_read_write_position_or_die (file, __LINE__, pass, (pass - 1) * DATA_LENGTH, 3 * DATA_LENGTH) ;
|
Chris@0
|
3463
|
Chris@0
|
3464 /* Read what we just wrote. */
|
Chris@0
|
3465 test_read_double_or_die (file, pass, test, DATA_LENGTH, __LINE__) ;
|
Chris@0
|
3466
|
Chris@0
|
3467 /* Check the data. */
|
Chris@0
|
3468 for (k = 0 ; k < DATA_LENGTH ; k++)
|
Chris@0
|
3469 if (FLOAT_ERROR (orig [k], test [k]))
|
Chris@0
|
3470 { printf ("\n\nLine %d (pass %d) B : Error at sample %d (%g => %g).\n", __LINE__, pass, k, orig [k], test [k]) ;
|
Chris@0
|
3471 oct_save_double (orig, test, DATA_LENGTH) ;
|
Chris@0
|
3472 exit (1) ;
|
Chris@0
|
3473 } ;
|
Chris@0
|
3474
|
Chris@0
|
3475 } ; /* for (pass ...) */
|
Chris@0
|
3476
|
Chris@0
|
3477 sf_close (file) ;
|
Chris@0
|
3478 } /* mono_rdwr_double_test */
|
Chris@0
|
3479
|
Chris@0
|
3480 static void
|
Chris@0
|
3481 new_rdwr_double_test (const char *filename, int format, int allow_fd)
|
Chris@0
|
3482 { SNDFILE *wfile, *rwfile ;
|
Chris@0
|
3483 SF_INFO sfinfo ;
|
Chris@0
|
3484 double *orig, *test ;
|
Chris@0
|
3485 int items, frames ;
|
Chris@0
|
3486
|
Chris@0
|
3487 orig = orig_data.d ;
|
Chris@0
|
3488 test = test_data.d ;
|
Chris@0
|
3489
|
Chris@0
|
3490 sfinfo.samplerate = 44100 ;
|
Chris@0
|
3491 sfinfo.frames = SILLY_WRITE_COUNT ; /* Wrong length. Library should correct this on sf_close. */
|
Chris@0
|
3492 sfinfo.channels = 2 ;
|
Chris@0
|
3493 sfinfo.format = format ;
|
Chris@0
|
3494
|
Chris@0
|
3495 items = DATA_LENGTH ;
|
Chris@0
|
3496 frames = items / sfinfo.channels ;
|
Chris@0
|
3497
|
Chris@0
|
3498 wfile = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, allow_fd, __LINE__) ;
|
Chris@0
|
3499 sf_command (wfile, SFC_SET_UPDATE_HEADER_AUTO, NULL, SF_TRUE) ;
|
Chris@0
|
3500 test_writef_double_or_die (wfile, 1, orig, frames, __LINE__) ;
|
Chris@0
|
3501 sf_write_sync (wfile) ;
|
Chris@0
|
3502 test_writef_double_or_die (wfile, 2, orig, frames, __LINE__) ;
|
Chris@0
|
3503 sf_write_sync (wfile) ;
|
Chris@0
|
3504
|
Chris@0
|
3505 rwfile = test_open_file_or_die (filename, SFM_RDWR, &sfinfo, allow_fd, __LINE__) ;
|
Chris@0
|
3506 if (sfinfo.frames != 2 * frames)
|
Chris@0
|
3507 { printf ("\n\nLine %d : incorrect number of frames in file (%ld should be %d)\n\n", __LINE__, SF_COUNT_TO_LONG (sfinfo.frames), 2 * frames) ;
|
Chris@0
|
3508 exit (1) ;
|
Chris@0
|
3509 } ;
|
Chris@0
|
3510
|
Chris@0
|
3511 test_writef_double_or_die (wfile, 3, orig, frames, __LINE__) ;
|
Chris@0
|
3512
|
Chris@0
|
3513 test_readf_double_or_die (rwfile, 1, test, frames, __LINE__) ;
|
Chris@0
|
3514 test_readf_double_or_die (rwfile, 2, test, frames, __LINE__) ;
|
Chris@0
|
3515
|
Chris@0
|
3516 sf_close (wfile) ;
|
Chris@0
|
3517 sf_close (rwfile) ;
|
Chris@0
|
3518 } /* new_rdwr_double_test */
|
Chris@0
|
3519
|
Chris@0
|
3520
|
Chris@0
|
3521
|
Chris@0
|
3522 /*----------------------------------------------------------------------------------------
|
Chris@0
|
3523 */
|
Chris@0
|
3524
|
Chris@0
|
3525 static void
|
Chris@0
|
3526 empty_file_test (const char *filename, int format)
|
Chris@0
|
3527 { SNDFILE *file ;
|
Chris@0
|
3528 SF_INFO info ;
|
Chris@0
|
3529 int allow_fd ;
|
Chris@0
|
3530
|
Chris@0
|
3531 /* Sd2 files cannot be opened from an existing file descriptor. */
|
Chris@0
|
3532 allow_fd = ((format & SF_FORMAT_TYPEMASK) == SF_FORMAT_SD2) ? SF_FALSE : SF_TRUE ;
|
Chris@0
|
3533
|
Chris@0
|
3534 print_test_name ("empty_file_test", filename) ;
|
Chris@0
|
3535
|
Chris@0
|
3536 unlink (filename) ;
|
Chris@0
|
3537
|
Chris@0
|
3538 info.samplerate = 48000 ;
|
Chris@0
|
3539 info.channels = 2 ;
|
Chris@0
|
3540 info.format = format ;
|
Chris@0
|
3541
|
Chris@0
|
3542 if (sf_format_check (&info) == SF_FALSE)
|
Chris@0
|
3543 { info.channels = 1 ;
|
Chris@0
|
3544 if (sf_format_check (&info) == SF_FALSE)
|
Chris@0
|
3545 { puts ("invalid file format") ;
|
Chris@0
|
3546 return ;
|
Chris@0
|
3547 } ;
|
Chris@0
|
3548 } ;
|
Chris@0
|
3549
|
Chris@0
|
3550 /* Create an empty file. */
|
Chris@0
|
3551 file = test_open_file_or_die (filename, SFM_WRITE, &info, allow_fd, __LINE__) ;
|
Chris@0
|
3552 sf_close (file) ;
|
Chris@0
|
3553
|
Chris@0
|
3554 /* Open for read and check the length. */
|
Chris@0
|
3555 file = test_open_file_or_die (filename, SFM_READ, &info, allow_fd, __LINE__) ;
|
Chris@0
|
3556
|
Chris@0
|
3557 if (SF_COUNT_TO_LONG (info.frames) != 0)
|
Chris@0
|
3558 { printf ("\n\nError : frame count (%ld) should be zero.\n", SF_COUNT_TO_LONG (info.frames)) ;
|
Chris@0
|
3559 exit (1) ;
|
Chris@0
|
3560 } ;
|
Chris@0
|
3561
|
Chris@0
|
3562 sf_close (file) ;
|
Chris@0
|
3563
|
Chris@0
|
3564 /* Open for read/write and check the length. */
|
Chris@0
|
3565 file = test_open_file_or_die (filename, SFM_RDWR, &info, allow_fd, __LINE__) ;
|
Chris@0
|
3566
|
Chris@0
|
3567 if (SF_COUNT_TO_LONG (info.frames) != 0)
|
Chris@0
|
3568 { printf ("\n\nError : frame count (%ld) should be zero.\n", SF_COUNT_TO_LONG (info.frames)) ;
|
Chris@0
|
3569 exit (1) ;
|
Chris@0
|
3570 } ;
|
Chris@0
|
3571
|
Chris@0
|
3572 sf_close (file) ;
|
Chris@0
|
3573
|
Chris@0
|
3574 /* Open for read and check the length. */
|
Chris@0
|
3575 file = test_open_file_or_die (filename, SFM_READ, &info, allow_fd, __LINE__) ;
|
Chris@0
|
3576
|
Chris@0
|
3577 if (SF_COUNT_TO_LONG (info.frames) != 0)
|
Chris@0
|
3578 { printf ("\n\nError : frame count (%ld) should be zero.\n", SF_COUNT_TO_LONG (info.frames)) ;
|
Chris@0
|
3579 exit (1) ;
|
Chris@0
|
3580 } ;
|
Chris@0
|
3581
|
Chris@0
|
3582 sf_close (file) ;
|
Chris@0
|
3583
|
Chris@0
|
3584 check_open_file_count_or_die (__LINE__) ;
|
Chris@0
|
3585
|
Chris@0
|
3586 unlink (filename) ;
|
Chris@0
|
3587 puts ("ok") ;
|
Chris@0
|
3588
|
Chris@0
|
3589 return ;
|
Chris@0
|
3590 } /* empty_file_test */
|
Chris@0
|
3591
|
Chris@0
|
3592
|
Chris@0
|
3593 /*----------------------------------------------------------------------------------------
|
Chris@0
|
3594 */
|
Chris@0
|
3595
|
Chris@0
|
3596 static void
|
Chris@0
|
3597 create_short_file (const char *filename)
|
Chris@0
|
3598 { FILE *file ;
|
Chris@0
|
3599
|
Chris@0
|
3600 if (! (file = fopen (filename, "w")))
|
Chris@0
|
3601 { printf ("create_short_file : fopen (%s, \"w\") failed.", filename) ;
|
Chris@0
|
3602 fflush (stdout) ;
|
Chris@0
|
3603 perror (NULL) ;
|
Chris@0
|
3604 exit (1) ;
|
Chris@0
|
3605 } ;
|
Chris@0
|
3606
|
Chris@0
|
3607 fprintf (file, "This is the file data.\n") ;
|
Chris@0
|
3608
|
Chris@0
|
3609 fclose (file) ;
|
Chris@0
|
3610 } /* create_short_file */
|
Chris@0
|
3611
|
Chris@0
|
3612 #if (defined (WIN32) || defined (__WIN32))
|
Chris@0
|
3613
|
Chris@0
|
3614 /* Win32 does not have truncate (nor does it have the POSIX function ftruncate).
|
Chris@0
|
3615 ** Hack somethng up here to over come this. This function can only truncate to a
|
Chris@0
|
3616 ** length of zero.
|
Chris@0
|
3617 */
|
Chris@0
|
3618
|
Chris@0
|
3619 static int
|
Chris@0
|
3620 truncate (const char *filename, int ignored)
|
Chris@0
|
3621 { int fd ;
|
Chris@0
|
3622
|
Chris@0
|
3623 ignored = 0 ;
|
Chris@0
|
3624
|
Chris@0
|
3625 if ((fd = open (filename, O_RDWR | O_TRUNC | O_BINARY)) < 0)
|
Chris@0
|
3626 return 0 ;
|
Chris@0
|
3627
|
Chris@0
|
3628 close (fd) ;
|
Chris@0
|
3629
|
Chris@0
|
3630 return 0 ;
|
Chris@0
|
3631 } /* truncate */
|
Chris@0
|
3632
|
Chris@0
|
3633 #endif
|
Chris@0
|
3634
|
Chris@0
|
3635 static void
|
Chris@0
|
3636 multi_seek_test (const char * filename, int format)
|
Chris@0
|
3637 { SNDFILE * file ;
|
Chris@0
|
3638 SF_INFO info ;
|
Chris@0
|
3639 sf_count_t pos ;
|
Chris@0
|
3640 int k ;
|
Chris@0
|
3641
|
Chris@0
|
3642 /* This test doesn't work on the following. */
|
Chris@0
|
3643 switch (format & SF_FORMAT_TYPEMASK)
|
Chris@0
|
3644 { case SF_FORMAT_RAW :
|
Chris@0
|
3645 return ;
|
Chris@0
|
3646
|
Chris@0
|
3647 default :
|
Chris@0
|
3648 break ;
|
Chris@0
|
3649 } ;
|
Chris@0
|
3650
|
Chris@0
|
3651 memset (&info, 0, sizeof (info)) ;
|
Chris@0
|
3652
|
Chris@0
|
3653 generate_file (filename, format, 88200) ;
|
Chris@0
|
3654
|
Chris@0
|
3655 file = test_open_file_or_die (filename, SFM_READ, &info, SF_FALSE, __LINE__) ;
|
Chris@0
|
3656
|
Chris@0
|
3657 for (k = 0 ; k < 10 ; k++)
|
Chris@0
|
3658 { pos = info.frames / (k + 2) ;
|
Chris@0
|
3659 test_seek_or_die (file, pos, SEEK_SET, pos, info.channels, __LINE__) ;
|
Chris@0
|
3660 } ;
|
Chris@0
|
3661
|
Chris@0
|
3662 sf_close (file) ;
|
Chris@0
|
3663 } /* multi_seek_test */
|
Chris@0
|
3664
|
Chris@0
|
3665 static void
|
Chris@0
|
3666 write_seek_extend_test (const char * filename, int format)
|
Chris@0
|
3667 { SNDFILE * file ;
|
Chris@0
|
3668 SF_INFO info ;
|
Chris@0
|
3669 short *orig, *test ;
|
Chris@0
|
3670 unsigned items, k ;
|
Chris@0
|
3671
|
Chris@0
|
3672 /* This test doesn't work on the following. */
|
Chris@0
|
3673 switch (format & SF_FORMAT_TYPEMASK)
|
Chris@0
|
3674 { case SF_FORMAT_FLAC :
|
Chris@0
|
3675 case SF_FORMAT_HTK :
|
Chris@0
|
3676 case SF_FORMAT_PAF :
|
Chris@0
|
3677 case SF_FORMAT_SDS :
|
Chris@0
|
3678 case SF_FORMAT_SVX :
|
Chris@0
|
3679 return ;
|
Chris@0
|
3680
|
Chris@0
|
3681 default :
|
Chris@0
|
3682 break ;
|
Chris@0
|
3683 } ;
|
Chris@0
|
3684
|
Chris@0
|
3685 memset (&info, 0, sizeof (info)) ;
|
Chris@0
|
3686
|
Chris@0
|
3687 info.samplerate = 48000 ;
|
Chris@0
|
3688 info.channels = 1 ;
|
Chris@0
|
3689 info.format = format ;
|
Chris@0
|
3690
|
Chris@0
|
3691 items = 512 ;
|
Chris@0
|
3692 exit_if_true (items > ARRAY_LEN (orig_data.s), "Line %d : Bad assumption.\n", __LINE__) ;
|
Chris@0
|
3693
|
Chris@0
|
3694 orig = orig_data.s ;
|
Chris@0
|
3695 test = test_data.s ;
|
Chris@0
|
3696
|
Chris@0
|
3697 for (k = 0 ; k < ARRAY_LEN (orig_data.s) ; k++)
|
Chris@0
|
3698 orig [k] = 0x3fff ;
|
Chris@0
|
3699
|
Chris@0
|
3700 file = test_open_file_or_die (filename, SFM_WRITE, &info, SF_FALSE, __LINE__) ;
|
Chris@0
|
3701 test_write_short_or_die (file, 0, orig, items, __LINE__) ;
|
Chris@0
|
3702
|
Chris@0
|
3703 /* Extend the file using a seek. */
|
Chris@0
|
3704 test_seek_or_die (file, 2 * items, SEEK_SET, 2 * items, info.channels, __LINE__) ;
|
Chris@0
|
3705
|
Chris@0
|
3706 test_writef_short_or_die (file, 0, orig, items, __LINE__) ;
|
Chris@0
|
3707 sf_close (file) ;
|
Chris@0
|
3708
|
Chris@0
|
3709 file = test_open_file_or_die (filename, SFM_READ, &info, SF_FALSE, __LINE__) ;
|
Chris@0
|
3710 test_read_short_or_die (file, 0, test, 3 * items, __LINE__) ;
|
Chris@0
|
3711 sf_close (file) ;
|
Chris@0
|
3712
|
Chris@0
|
3713 /* Can't do these formats due to scaling. */
|
Chris@0
|
3714 switch (format & SF_FORMAT_SUBMASK)
|
Chris@0
|
3715 { case SF_FORMAT_PCM_S8 :
|
Chris@0
|
3716 case SF_FORMAT_PCM_U8 :
|
Chris@0
|
3717 return ;
|
Chris@0
|
3718 default :
|
Chris@0
|
3719 break ;
|
Chris@0
|
3720 } ;
|
Chris@0
|
3721
|
Chris@0
|
3722 for (k = 0 ; k < items ; k++)
|
Chris@0
|
3723 { exit_if_true (test [k] != 0x3fff, "Line %d : test [%d] == %d, should be 0x3fff.\n", __LINE__, k, test [k]) ;
|
Chris@0
|
3724 exit_if_true (test [items + k] != 0, "Line %d : test [%d] == %d, should be 0.\n", __LINE__, items + k, test [items + k]) ;
|
Chris@0
|
3725 exit_if_true (test [2 * items + k] != 0x3fff, "Line %d : test [%d] == %d, should be 0x3fff.\n", __LINE__, 2 * items + k, test [2 * items + k]) ;
|
Chris@0
|
3726 } ;
|
Chris@0
|
3727
|
Chris@0
|
3728 return ;
|
Chris@0
|
3729 } /* write_seek_extend_test */
|
Chris@0
|
3730
|
Chris@0
|
3731
|