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