63f3bdae59af525ff89d5dff6c104249ac74193c
2 ** Copyright (C) 2007-2011 Erik de Castro Lopo <erikd@mega-nerd.com>
4 ** This program is free software; you can redistribute it and/or modify
5 ** it under the terms of the GNU General Public License as published by
6 ** the Free Software Foundation; either version 2 of the License, or
7 ** (at your option) any later version.
9 ** This program is distributed in the hope that it will be useful,
10 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
11 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 ** GNU General Public License for more details.
14 ** You should have received a copy of the GNU General Public License
15 ** along with this program; if not, write to the Free Software
16 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
32 #define SAMPLE_RATE 44100
33 #define DATA_LENGTH (SAMPLE_RATE / 8)
36 { double d
[DATA_LENGTH
] ;
37 float f
[DATA_LENGTH
] ;
39 short s
[DATA_LENGTH
] ;
42 static BUFFER data_out
;
43 static BUFFER data_in
;
47 { const char * filename
= "vorbis_short.oga" ;
51 short seek_data
[10] ;
54 print_test_name ("ogg_short_test", filename
) ;
56 /* Generate float data. */
57 gen_windowed_sine_float (data_out
.f
, ARRAY_LEN (data_out
.f
), 1.0 * 0x7F00) ;
59 /* Convert to shorteger. */
60 for (k
= 0 ; k
< ARRAY_LEN (data_out
.s
) ; k
++)
61 data_out
.s
[k
] = lrintf (data_out
.f
[k
]) ;
63 memset (&sfinfo
, 0, sizeof (sfinfo
)) ;
65 /* Set up output file type. */
66 sfinfo
.format
= SF_FORMAT_OGG
| SF_FORMAT_VORBIS
;
68 sfinfo
.samplerate
= SAMPLE_RATE
;
70 /* Write the output file. */
71 file
= test_open_file_or_die (filename
, SFM_WRITE
, &sfinfo
, SF_FALSE
, __LINE__
) ;
72 test_write_short_or_die (file
, 0, data_out
.s
, ARRAY_LEN (data_out
.s
), __LINE__
) ;
75 /* Read the file in again. */
76 memset (&sfinfo
, 0, sizeof (sfinfo
)) ;
78 file
= test_open_file_or_die (filename
, SFM_READ
, &sfinfo
, SF_FALSE
, __LINE__
) ;
79 test_read_short_or_die (file
, 0, data_in
.s
, ARRAY_LEN (data_in
.s
), __LINE__
) ;
85 print_test_name ("ogg_seek_test", filename
) ;
87 file
= test_open_file_or_die (filename
, SFM_READ
, &sfinfo
, SF_FALSE
, __LINE__
) ;
89 test_seek_or_die (file
, 10, SEEK_SET
, 10, sfinfo
.channels
, __LINE__
) ;
90 test_read_short_or_die (file
, 0, seek_data
, ARRAY_LEN (seek_data
), __LINE__
) ;
91 compare_short_or_die (seek_data
, data_in
.s
+ 10, ARRAY_LEN (seek_data
), __LINE__
) ;
98 } /* ogg_short_test */
102 { const char * filename
= "vorbis_int.oga" ;
109 print_test_name ("ogg_int_test", filename
) ;
111 /* Generate float data. */
112 gen_windowed_sine_float (data_out
.f
, ARRAY_LEN (data_out
.f
), 1.0 * 0x7FFF0000) ;
114 /* Convert to integer. */
115 for (k
= 0 ; k
< ARRAY_LEN (data_out
.i
) ; k
++)
116 data_out
.i
[k
] = lrintf (data_out
.f
[k
]) ;
118 memset (&sfinfo
, 0, sizeof (sfinfo
)) ;
120 /* Set up output file type. */
121 sfinfo
.format
= SF_FORMAT_OGG
| SF_FORMAT_VORBIS
;
122 sfinfo
.channels
= 1 ;
123 sfinfo
.samplerate
= SAMPLE_RATE
;
125 /* Write the output file. */
126 file
= test_open_file_or_die (filename
, SFM_WRITE
, &sfinfo
, SF_FALSE
, __LINE__
) ;
127 test_write_int_or_die (file
, 0, data_out
.i
, ARRAY_LEN (data_out
.i
), __LINE__
) ;
130 /* Read the file in again. */
131 memset (&sfinfo
, 0, sizeof (sfinfo
)) ;
133 file
= test_open_file_or_die (filename
, SFM_READ
, &sfinfo
, SF_FALSE
, __LINE__
) ;
134 test_read_int_or_die (file
, 0, data_in
.i
, ARRAY_LEN (data_in
.i
), __LINE__
) ;
140 print_test_name ("ogg_seek_test", filename
) ;
142 file
= test_open_file_or_die (filename
, SFM_READ
, &sfinfo
, SF_FALSE
, __LINE__
) ;
144 test_seek_or_die (file
, 10, SEEK_SET
, 10, sfinfo
.channels
, __LINE__
) ;
145 test_read_int_or_die (file
, 0, seek_data
, ARRAY_LEN (seek_data
), __LINE__
) ;
146 compare_int_or_die (seek_data
, data_in
.i
+ 10, ARRAY_LEN (seek_data
), __LINE__
) ;
156 ogg_float_test (void)
157 { const char * filename
= "vorbis_float.oga" ;
161 float seek_data
[10] ;
163 print_test_name ("ogg_float_test", filename
) ;
165 gen_windowed_sine_float (data_out
.f
, ARRAY_LEN (data_out
.f
), 0.95) ;
167 memset (&sfinfo
, 0, sizeof (sfinfo
)) ;
169 /* Set up output file type. */
170 sfinfo
.format
= SF_FORMAT_OGG
| SF_FORMAT_VORBIS
;
171 sfinfo
.channels
= 1 ;
172 sfinfo
.samplerate
= SAMPLE_RATE
;
174 /* Write the output file. */
175 file
= test_open_file_or_die (filename
, SFM_WRITE
, &sfinfo
, SF_FALSE
, __LINE__
) ;
176 test_write_float_or_die (file
, 0, data_out
.f
, ARRAY_LEN (data_out
.f
), __LINE__
) ;
179 /* Read the file in again. */
180 memset (&sfinfo
, 0, sizeof (sfinfo
)) ;
182 file
= test_open_file_or_die (filename
, SFM_READ
, &sfinfo
, SF_FALSE
, __LINE__
) ;
183 test_read_float_or_die (file
, 0, data_in
.f
, ARRAY_LEN (data_in
.f
), __LINE__
) ;
189 print_test_name ("ogg_seek_test", filename
) ;
191 file
= test_open_file_or_die (filename
, SFM_READ
, &sfinfo
, SF_FALSE
, __LINE__
) ;
193 test_seek_or_die (file
, 10, SEEK_SET
, 10, sfinfo
.channels
, __LINE__
) ;
194 test_read_float_or_die (file
, 0, seek_data
, ARRAY_LEN (seek_data
), __LINE__
) ;
195 compare_float_or_die (seek_data
, data_in
.f
+ 10, ARRAY_LEN (seek_data
), __LINE__
) ;
202 } /* ogg_float_test */
205 ogg_double_test (void)
206 { const char * filename
= "vorbis_double.oga" ;
210 double seek_data
[10] ;
212 print_test_name ("ogg_double_test", filename
) ;
214 gen_windowed_sine_double (data_out
.d
, ARRAY_LEN (data_out
.d
), 0.95) ;
216 memset (&sfinfo
, 0, sizeof (sfinfo
)) ;
218 /* Set up output file type. */
219 sfinfo
.format
= SF_FORMAT_OGG
| SF_FORMAT_VORBIS
;
220 sfinfo
.channels
= 1 ;
221 sfinfo
.samplerate
= SAMPLE_RATE
;
223 /* Write the output file. */
224 file
= test_open_file_or_die (filename
, SFM_WRITE
, &sfinfo
, SF_FALSE
, __LINE__
) ;
225 test_write_double_or_die (file
, 0, data_out
.d
, ARRAY_LEN (data_out
.d
), __LINE__
) ;
228 /* Read the file in again. */
229 memset (&sfinfo
, 0, sizeof (sfinfo
)) ;
231 file
= test_open_file_or_die (filename
, SFM_READ
, &sfinfo
, SF_FALSE
, __LINE__
) ;
232 test_read_double_or_die (file
, 0, data_in
.d
, ARRAY_LEN (data_in
.d
), __LINE__
) ;
238 print_test_name ("ogg_seek_test", filename
) ;
240 file
= test_open_file_or_die (filename
, SFM_READ
, &sfinfo
, SF_FALSE
, __LINE__
) ;
242 test_seek_or_die (file
, 10, SEEK_SET
, 10, sfinfo
.channels
, __LINE__
) ;
243 test_read_double_or_die (file
, 0, seek_data
, ARRAY_LEN (seek_data
), __LINE__
) ;
244 compare_double_or_die (seek_data
, data_in
.d
+ 10, ARRAY_LEN (seek_data
), __LINE__
) ;
251 } /* ogg_double_test */
255 ogg_stereo_seek_test (const char * filename
, int format
)
256 { static float data
[SAMPLE_RATE
] ;
257 static float stereo_out
[SAMPLE_RATE
* 2] ;
264 print_test_name (__func__
, filename
) ;
266 gen_windowed_sine_float (data
, ARRAY_LEN (data
), 0.95) ;
267 for (k
= 0 ; k
< ARRAY_LEN (data
) ; k
++)
268 { stereo_out
[2 * k
] = data
[k
] ;
269 stereo_out
[2 * k
+ 1] = data
[ARRAY_LEN (data
) - k
- 1] ;
272 memset (&sfinfo
, 0, sizeof (sfinfo
)) ;
274 /* Set up output file type. */
275 sfinfo
.format
= format
;
276 sfinfo
.channels
= 2 ;
277 sfinfo
.samplerate
= SAMPLE_RATE
;
279 /* Write the output file. */
280 file
= test_open_file_or_die (filename
, SFM_WRITE
, &sfinfo
, SF_FALSE
, __LINE__
) ;
281 test_write_float_or_die (file
, 0, stereo_out
, ARRAY_LEN (stereo_out
), __LINE__
) ;
284 /* Open file in again for reading. */
285 memset (&sfinfo
, 0, sizeof (sfinfo
)) ;
286 file
= test_open_file_or_die (filename
, SFM_READ
, &sfinfo
, SF_FALSE
, __LINE__
) ;
288 /* Read in the whole file. */
289 test_read_float_or_die (file
, 0, stereo_out
, ARRAY_LEN (stereo_out
), __LINE__
) ;
291 /* Now hammer seeking code. */
292 test_seek_or_die (file
, 234, SEEK_SET
, 234, sfinfo
.channels
, __LINE__
) ;
293 test_readf_float_or_die (file
, 0, data
, 10, __LINE__
) ;
294 compare_float_or_die (data
, stereo_out
+ (234 * sfinfo
.channels
), 10, __LINE__
) ;
296 test_seek_or_die (file
, 442, SEEK_SET
, 442, sfinfo
.channels
, __LINE__
) ;
297 test_readf_float_or_die (file
, 0, data
, 10, __LINE__
) ;
298 compare_float_or_die (data
, stereo_out
+ (442 * sfinfo
.channels
), 10, __LINE__
) ;
300 test_seek_or_die (file
, 12, SEEK_CUR
, 442 + 10 + 12, sfinfo
.channels
, __LINE__
) ;
301 test_readf_float_or_die (file
, 0, data
, 10, __LINE__
) ;
302 compare_float_or_die (data
, stereo_out
+ ((442 + 10 + 12) * sfinfo
.channels
), 10, __LINE__
) ;
304 test_seek_or_die (file
, 12, SEEK_CUR
, 442 + 20 + 24, sfinfo
.channels
, __LINE__
) ;
305 test_readf_float_or_die (file
, 0, data
, 10, __LINE__
) ;
306 compare_float_or_die (data
, stereo_out
+ ((442 + 20 + 24) * sfinfo
.channels
), 10, __LINE__
) ;
308 pos
= 500 - sfinfo
.frames
;
309 test_seek_or_die (file
, pos
, SEEK_END
, 500, sfinfo
.channels
, __LINE__
) ;
310 test_readf_float_or_die (file
, 0, data
, 10, __LINE__
) ;
311 compare_float_or_die (data
, stereo_out
+ (500 * sfinfo
.channels
), 10, __LINE__
) ;
313 pos
= 10 - sfinfo
.frames
;
314 test_seek_or_die (file
, pos
, SEEK_END
, 10, sfinfo
.channels
, __LINE__
) ;
315 test_readf_float_or_die (file
, 0, data
, 10, __LINE__
) ;
316 compare_float_or_die (data
, stereo_out
+ (10 * sfinfo
.channels
), 10, __LINE__
) ;
322 } /* ogg_stereo_seek_test */
328 if (HAVE_EXTERNAL_LIBS
)
329 { ogg_short_test () ;
334 /*-ogg_stereo_seek_test ("pcm.wav", SF_FORMAT_WAV | SF_FORMAT_PCM_16) ;-*/
335 ogg_stereo_seek_test ("vorbis_seek.ogg", SF_FORMAT_OGG
| SF_FORMAT_VORBIS
) ;
338 puts (" No Ogg/Vorbis tests because Ogg/Vorbis support was not compiled in.") ;