Skip to content

Commit 6cf7dbe

Browse files
committed
Expanded Format tests.
1 parent 108a756 commit 6cf7dbe

4 files changed

Lines changed: 154 additions & 22 deletions

File tree

78.2 KB
Binary file not shown.

tests/functionality.c

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ void test_func_1ch_mutation() {
1717
uint32_t sample_rate = 44100;
1818
uint32_t total_samples = duration * sample_rate * 2;
1919
uint16_t tone_frequency = 1000;
20+
uint16_t tone_spp = (sample_rate / tone_frequency) / 2;
21+
bool tone_hstate = false;
2022

21-
int16_t tone_high = (pow(2, 16) - 1) / 2;
22-
int16_t tone_low = tone_high * -1;
23-
int16_t tone_spp = (sample_rate / tone_frequency) / 2;
24-
int16_t* tone_val = &tone_low;
25-
bool tone_hstate = false;
23+
WAV_PCM16 tone_high = WAV_PCM16_MAX;
24+
WAV_PCM16 tone_low = WAV_PCM16_MIN;
25+
WAV_PCM16* tone_val = &tone_low;
2626

2727
WAV_FILE file = wav_open("test-files/1ch-mutation.wav", WAV_NEW);
2828

@@ -64,17 +64,18 @@ void test_func_2ch_mutation() {
6464
uint16_t tone1_frequency = 1000;
6565
uint16_t tone2_frequency = 500;
6666

67-
int32_t tone1_high = (pow(2, 16) - 1) / 2;
68-
int32_t tone1_low = tone1_high * -1;
69-
int32_t* tone1_current = &tone1_low;
70-
int32_t tone1_spp = (sample_rate / tone1_frequency) / 2;
71-
bool tone1_hstate = false;
67+
int32_t tone1_spp = (sample_rate / tone1_frequency) / 2;
68+
bool tone1_hstate = false;
69+
int32_t tone2_spp = (sample_rate / tone2_frequency) / 2;
70+
bool tone2_hstate = false;
7271

73-
int32_t tone2_high = (pow(2, 16) - 1) / 2;
74-
int32_t tone2_low = tone2_high * -1;
75-
int32_t* tone2_current = &tone2_low;
76-
int32_t tone2_spp = (sample_rate / tone2_frequency) / 2;
77-
bool tone2_hstate = false;
72+
WAV_PCM16 tone1_high = WAV_PCM16_MAX;
73+
WAV_PCM16 tone1_low = WAV_PCM16_MIN;
74+
WAV_PCM16* tone1_current = &tone1_low;
75+
76+
WAV_PCM16 tone2_high = WAV_PCM16_MAX;
77+
WAV_PCM16 tone2_low = WAV_PCM16_MIN;
78+
WAV_PCM16* tone2_current = &tone2_low;
7879

7980
WAV_FILE file = wav_open("test-files/2ch-mutation.wav", WAV_NEW);
8081

@@ -119,9 +120,9 @@ void test_func_1ch_edit() {
119120

120121
printf("[*] TEST: Functionality -> 1-Channel Edit\n");
121122

122-
int16_t in_sample;
123-
int16_t out_sample;
124-
float attenuation;
123+
WAV_PCM16 in_sample;
124+
WAV_PCM16 out_sample;
125+
float attenuation;
125126

126127
WAV_FILE input = wav_open("test-files/1ch-mutation.wav", WAV_READ);
127128
WAV_FILE output = wav_open("test-files/1ch-edit.wav", WAV_NEW);
@@ -155,9 +156,9 @@ void test_func_2ch_edit() {
155156

156157
printf("[*] TEST: Functionality -> 2-Channel Edit\n");
157158

158-
int16_t lin_sample, rin_sample;
159-
int16_t lout_sample, rout_sample;
160-
float latten, ratten;
159+
WAV_PCM16 lin_sample, rin_sample;
160+
WAV_PCM16 lout_sample, rout_sample;
161+
float latten, ratten;
161162

162163
WAV_FILE input = wav_open("test-files/2ch-mutation.wav", WAV_READ);
163164
WAV_FILE output = wav_open("test-files/2ch-edit.wav", WAV_NEW);

tests/wav-format.c

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,26 @@
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+
929
void 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+
415543
void 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
}

tests/wav-format.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
#ifndef C89_WAV_FORMAT
22

33
#define C89_WAV_FORMAT
4-
4+
5+
void test_wav_types();
56
void test_wav_open();
67
void test_wav_commit();
78
void test_wav_general();

0 commit comments

Comments
 (0)