66#include "format.h"
77#include "wav-format.h"
88
9+ void test_wav_types () {
10+
11+ assert (sizeof (WAV_PCM8 ) == 1 && "Invalid PCM8 size." );
12+ assert (sizeof (WAV_PCM16 ) == 2 && "Invalid PCM16 size." );
13+ assert (sizeof (WAV_PCM24 ) == 4 && "Invalid PCM32 size." );
14+ assert (sizeof (WAV_PCM32 ) == 4 && "Invalid PCM32 size." );
15+
16+ assert (WAV_PCM8_MIN == 0 && "Invalid PCM8 min. range." );
17+ assert (WAV_PCM8_MAX == 255 && "Invalid PCM8 max. range." );
18+
19+ assert (WAV_PCM16_MIN == -32768 && "Invalid PCM16 min. range." );
20+ assert (WAV_PCM16_MAX == 32767 && "Invalid PCM16 max. range." );
21+
22+ assert (WAV_PCM24_MIN == -8388607 && "Invalid PCM24 min. range." );
23+ assert (WAV_PCM24_MAX == 8388607 && "Invalid PCM24 max. range." );
24+
25+ assert (WAV_PCM32_MIN == -2147483647 && "Invalid PCM32 min. range." );
26+ assert (WAV_PCM32_MAX == 2147483647 && "Invalid PCM32 max. range." );
27+ }
28+
929void test_wav_open () {
1030
1131 printf ("[*] TEST: WAV Format -> Open\n" );
@@ -412,8 +432,117 @@ void test_wav_push() {
412432
413433}
414434
435+ void test_wav_next () {
436+
437+ printf ("[*] TEST: WAV Format -> Next\n" );
438+
439+ uint32_t i ;
440+
441+ bool test_general = false;
442+
443+ WAV_PCM32 buffer_1ch [42 ];
444+ WAV_PCM32 buffer_2ch [84 ];
445+ WAV_PCM32 lsample , rsample ;
446+
447+ const WAV_PCM32 data_1ch [42 ] = {
448+ 0x0A174730 , 0x1510F740 , 0x44815580 , 0xBF037E00 , 0x474C8E80 , 0x29AF8680 ,
449+ 0xB5883800 , 0x2475E280 , 0x0425A198 , 0xB4003500 , 0x3AC60F40 , 0xC091E780 ,
450+ 0x498C9300 , 0x25691800 , 0x42261D80 , 0x36713980 , 0x34513580 , 0xAEB9C400 ,
451+ 0xD67BACC0 , 0x5A864E80 , 0x9BA00400 , 0xCCF53380 , 0xDFB3BF80 , 0x251F7D80 ,
452+ 0xB969D900 , 0x36613980 , 0x41DFB700 , 0x08927730 , 0x0E6DB660 , 0x48149000 ,
453+ 0x1498F5A0 , 0x6484C900 , 0xBB684380 , 0xE0B08E00 , 0x5FB18C00 , 0xD00ED340 ,
454+ 0xEF8F1260 , 0x2EB790C0 , 0xC9BEC680 , 0x27778280 , 0xA5C1B200 , 0xC5A38B40
455+ };
456+
457+ const WAV_PCM32 data_2ch [84 ] = {
458+ 0xC5A399DB , 0x9DE1AEC7 , 0xC5A30D06 , 0x9DE1FE4D , 0xC5A3C130 , 0x9DE1AD46 ,
459+ 0xC5A33F3B , 0x9DE14B3A , 0xC5A31168 , 0x9DE11972 , 0xC5A3FBE2 , 0x9DE1BC73 ,
460+ 0xC5A3E156 , 0x9DE1FF30 , 0xC5A35119 , 0x9DE14F37 , 0xC5A3421D , 0x9DE1DD79 ,
461+ 0xC5A33281 , 0x9DE1FC21 , 0xC5A3BD43 , 0x9DE1AA06 , 0xC5A34982 , 0x9DE1B65A ,
462+ 0xC5A32B1D , 0x9DE14E4C , 0xC5A302C6 , 0x9DE1526A , 0xC5A3D7DB , 0x9DE10D67 ,
463+ 0xC5A39CAC , 0x9DE1050B , 0xC5A3AC52 , 0x9DE15B6E , 0xC5A3E43B , 0x9DE147EA ,
464+ 0xC5A3B7C9 , 0x9DE15689 , 0xC5A3BB90 , 0x9DE15EEC , 0xC5A36410 , 0x9DE13184 ,
465+ 0xC5A3F4DE , 0x9DE1C2EE , 0xC5A3B1FE , 0x9DE1F467 , 0xC5A39A8E , 0x9DE1DDA0 ,
466+ 0xC5A39B6D , 0x9DE1501E , 0xC5A3E6FE , 0x9DE145A9 , 0xC5A3067B , 0x9DE12AB3 ,
467+ 0xC5A30E95 , 0x9DE1247D , 0xC5A314D7 , 0x9DE1E843 , 0xC5A315F3 , 0x9DE152A8 ,
468+ 0xC5A3BBA4 , 0x9DE1FD66 , 0xC5A32165 , 0x9DE11E23 , 0xC5A3F5EC , 0x9DE1567C ,
469+ 0xC5A3E1B7 , 0x9DE14BAE , 0xC5A3A548 , 0x9DE1AE13 , 0xC5A3160D , 0x9DE1045A ,
470+ 0xC5A33A07 , 0x9DE1F1F3 , 0xC5A33DF9 , 0x9DE1B744 , 0xC5A30412 , 0x9DE1D1BD ,
471+ 0xC5A3D772 , 0x9DE13823 , 0xC5A34CFC , 0x9DE19DD0 , 0xC5A32E71 , 0x9DE1D9B3
472+ };
473+
474+ /* 1-Channel */
475+
476+ WAV_FILE file_1ch = wav_open ("test-files/wav-format/32bit-test.wav" , WAV_READ );
477+
478+ assert (wav_is_open (& file_1ch ) && "File couldn't be opened." );
479+ assert (wav_last_error (& file_1ch ) == WAV_ERR_NONE && "Error flag set." );
480+
481+ test_general = false;
482+
483+ i = 0 ;
484+
485+ while (wav_has_next (& file_1ch )) {
486+
487+ if (test_general ) {
488+ wav_next_sample (& file_1ch , & lsample , NULL );
489+ } else {
490+ wav_next_1ch_sample (& file_1ch , & lsample );
491+ }
492+
493+ assert (data_1ch [i ] == lsample && "Invalid sample value." );
494+
495+ test_general = !test_general ;
496+
497+ buffer_1ch [i ++ ] = lsample ;
498+
499+ if (i == 42 ) {
500+ break ;
501+ }
502+ }
503+
504+ assert (wav_close (& file_1ch ) && "File couldn't be closed." );
505+ assert (wav_last_error (& file_1ch ) == WAV_ERR_NONE && "Error flag set." );
506+
507+ /* 2-Channel */
508+
509+ WAV_FILE file_2ch = wav_open ("test-files/wav-format/2ch-test.wav" , WAV_READ );
510+
511+ assert (wav_is_open (& file_2ch ) && "File couldn't be opened." );
512+ assert (wav_last_error (& file_2ch ) == WAV_ERR_NONE && "Error flag set." );
513+
514+ test_general = false;
515+
516+ i = 0 ;
517+
518+ while (wav_has_next (& file_2ch )) {
519+
520+ if (test_general ) {
521+ wav_next_sample (& file_2ch , & lsample , & rsample );
522+ } else {
523+ wav_next_2ch_sample (& file_2ch , & lsample , & rsample );
524+ }
525+
526+ assert (data_2ch [i ] == lsample && "Invalid sample value - Left." );
527+ assert (data_2ch [i + 1 ] == rsample && "Invalid sample value - Right." );
528+
529+ test_general = !test_general ;
530+
531+ buffer_2ch [i ++ ] = lsample ;
532+ buffer_2ch [i ++ ] = rsample ;
533+
534+ if (i == 84 ) {
535+ break ;
536+ }
537+ }
538+
539+ assert (wav_close (& file_2ch ) && "File couldn't be closed." );
540+ assert (wav_last_error (& file_2ch ) == WAV_ERR_NONE && "Error flag set." );
541+ }
542+
415543void test_wav_format () {
416544
545+ test_wav_types ();
417546 test_wav_open ();
418547 test_wav_commit ();
419548 test_wav_general ();
@@ -423,4 +552,5 @@ void test_wav_format() {
423552 test_wav_get ();
424553 test_wav_set ();
425554 test_wav_push ();
555+ test_wav_next ();
426556}
0 commit comments