21 SECTION(
"empty file") {
27 CHECK(e.getMessage() ==
"Read beyond end of wav file.");
30 SECTION(
"garbage data") {
32 static constexpr auto buffer = std::to_array<uint8_t>({
33 0x00,0x01,0x02,0x03, 0x04,0x05,0x06,0x07, 0x08,0x09,0x0a,0x0b, 0x0c,0x0d,0x0e,0x0f,
34 0x10,0x11,0x12,0x13, 0x14,0x15,0x16,0x17, 0x18,0x19,0x1a,0x1b, 0x1c,0x1d,0x1e,0x1f,
41 CHECK(e.getMessage() ==
"Invalid WAV file.");
44 SECTION(
"unsupported format") {
46 static constexpr auto buffer = std::to_array<uint8_t>({
47 'R',
'I',
'F',
'F', 0x04,0x05,0x06,0x07,
'W',
'A',
'V',
'E',
'f',
'm',
't' ,
' ',
48 0x10,0x11,0x12,0x13, 0x14,0x15,0x16,0x17, 0x18,0x19,0x1a,0x1b, 0x1c,0x1d,0x1e,0x1f,
55 CHECK(e.getMessage() ==
"WAV format unsupported, must be 8 or 16 bit PCM.");
58 SECTION(
"missing data chunk") {
60 static constexpr auto buffer = std::to_array<uint8_t>({
61 'R',
'I',
'F',
'F', 0x04,0x05,0x06,0x07,
'W',
'A',
'V',
'E',
'f',
'm',
't' ,
' ',
62 0x10,0x00,0x00,0x00, 0x01,0x00,0x01,0x00, 0x44,0xac,0x00,0x00, 0x88,0x58,0x01,0x00,
69 CHECK(e.getMessage() ==
"Read beyond end of wav file.");
72 SECTION(
"data chunk with incorrect length") {
74 static constexpr auto buffer = std::to_array<uint8_t>({
75 'R',
'I',
'F',
'F', 0x04,0x05,0x06,0x07,
'W',
'A',
'V',
'E',
'f',
'm',
't' ,
' ',
76 0x10,0x00,0x00,0x00, 0x01,0x00,0x01,0x00, 0x44,0xac,0x00,0x00, 0x88,0x58,0x01,0x00,
77 0x02,0x00,0x10,0x00,
'd',
'a',
't',
'a', 0x64,0x00,0x00,0x00,
83 CHECK(e.getMessage() ==
"Read beyond end of wav file.");
86 SECTION(
"finally a correct, but empty wav file") {
88 static constexpr auto buffer = std::to_array<uint8_t>({
89 'R',
'I',
'F',
'F', 0x04,0x05,0x06,0x07,
'W',
'A',
'V',
'E',
'f',
'm',
't' ,
' ',
90 0x10,0x00,0x00,0x00, 0x01,0x00,0x01,0x00, 0x44,0xac,0x00,0x00, 0x88,0x58,0x01,0x00,
92 'd',
'a',
't',
'a', 0x00,0x00,0x00,0x00,
95 CHECK(wav.getSize() == 0);
96 CHECK(wav.getFreq() == 44100);
102 SECTION(
"mono, 8 bit") {
104 static constexpr auto buffer = std::to_array<uint8_t>({
105 'R',
'I',
'F',
'F', 0x04,0x05,0x06,0x07,
'W',
'A',
'V',
'E',
'f',
'm',
't' ,
' ',
106 0x10,0x00,0x00,0x00, 0x01,0x00,0x01,0x00, 0x44,0xac,0x00,0x00, 0x44,0xac,0x00,0x00,
108 'd',
'a',
't',
'a', 0x05,0x00,0x00,0x00,
109 0x00, 0x45, 0x80, 0xbe, 0xff
112 CHECK(wav.getSize() == 5);
113 CHECK(wav.getFreq() == 44100);
114 CHECK(wav.getSample(0) == -0x8000);
115 CHECK(wav.getSample(1) == -0x3b00);
116 CHECK(wav.getSample(2) == 0x0000);
117 CHECK(wav.getSample(3) == 0x3e00);
118 CHECK(wav.getSample(4) == 0x7f00);
119 CHECK(wav.getSample(5) == 0);
121 SECTION(
"mono, 16 bit") {
123 static constexpr auto buffer = std::to_array<uint8_t>({
124 'R',
'I',
'F',
'F', 0x04,0x05,0x06,0x07,
'W',
'A',
'V',
'E',
'f',
'm',
't' ,
' ',
125 0x10,0x00,0x00,0x00, 0x01,0x00,0x01,0x00, 0x44,0xac,0x00,0x00, 0x44,0xac,0x00,0x00,
127 'd',
'a',
't',
'a', 0x08,0x00,0x00,0x00,
128 0x23,0x45, 0x00,0x7e, 0xff,0xff, 0x23,0xc0
131 CHECK(wav.getSize() == 4);
132 CHECK(wav.getFreq() == 44100);
133 CHECK(wav.getSample(0) == 0x4523);
134 CHECK(wav.getSample(1) == 0x7e00);
135 CHECK(wav.getSample(2) == -0x0001);
136 CHECK(wav.getSample(3) == -0x3fdd);
137 CHECK(wav.getSample(4) == 0);
138 CHECK(wav.getSample(5) == 0);
140 SECTION(
"stereo, 8 bit") {
142 static constexpr auto buffer = std::to_array<uint8_t>({
143 'R',
'I',
'F',
'F', 0x04,0x05,0x06,0x07,
'W',
'A',
'V',
'E',
'f',
'm',
't' ,
' ',
144 0x10,0x00,0x00,0x00, 0x01,0x00,0x02,0x00, 0x44,0xac,0x00,0x00, 0x44,0xac,0x00,0x00,
146 'd',
'a',
't',
'a', 0x08,0x00,0x00,0x00,
147 0x00,0xff, 0x40,0xef, 0x80,0xdf, 0xc0,0xcf
150 CHECK(wav.getSize() == 4);
151 CHECK(wav.getFreq() == 44100);
152 CHECK(wav.getSample(0) == -0x8000);
153 CHECK(wav.getSample(1) == -0x4000);
154 CHECK(wav.getSample(2) == 0x0000);
155 CHECK(wav.getSample(3) == 0x4000);
156 CHECK(wav.getSample(4) == 0);
158 SECTION(
"stereo, 16 bit") {
160 static constexpr auto buffer = std::to_array<uint8_t>({
161 'R',
'I',
'F',
'F', 0x04,0x05,0x06,0x07,
'W',
'A',
'V',
'E',
'f',
'm',
't' ,
' ',
162 0x10,0x00,0x00,0x00, 0x01,0x00,0x02,0x00, 0x44,0xac,0x00,0x00, 0x44,0xac,0x00,0x00,
164 'd',
'a',
't',
'a', 0x10,0x00,0x00,0x00,
165 0x12,0x34,0xff,0xee, 0x56,0x78,0xdd,0xcc, 0x9a,0xbc,0xbb,0xaa, 0xde,0xf0,0x99,0x88,
168 CHECK(wav.getSize() == 4);
169 CHECK(wav.getFreq() == 44100);
170 CHECK(wav.getSample(0) == 0x3412);
171 CHECK(wav.getSample(1) == 0x7856);
172 CHECK(wav.getSample(2) == -0x4366);
173 CHECK(wav.getSample(3) == -0x0f22);
174 CHECK(wav.getSample(4) == 0);