21 #include "../SDL_internal.h" 27 #define SIZE_MAX ((size_t)-1) 31 #define INT_MAX SDL_MAX_SINT32 50 if (*f1 > 0 &&
SIZE_MAX / *f1 <= f2) {
105 #ifdef SDL_WAVE_DEBUG_LOG_FORMAT 110 const char *fmtstr =
"WAVE file: %s, %u Hz, %s, %u bits, %u %s/s";
111 const char *waveformat, *wavechannel, *wavebpsunit =
"B";
122 waveformat =
"IEEE Float";
125 waveformat =
"A-law";
128 waveformat =
"\xc2\xb5-law";
131 waveformat =
"MS ADPCM";
134 waveformat =
"IMA ADPCM";
137 waveformat =
"Unknown";
141 #define SDL_WAVE_DEBUG_CHANNELCFG(STR, CODE) case CODE: wavechannel = STR; break; 142 #define SDL_WAVE_DEBUG_CHANNELSTR(STR, CODE) if (format->channelmask & CODE) { \ 143 SDL_strlcat(channelstr, channelstr[0] ? "-" STR : STR, sizeof(channelstr));} 147 SDL_WAVE_DEBUG_CHANNELCFG(
"1.0 Mono", 0x4)
148 SDL_WAVE_DEBUG_CHANNELCFG(
"1.1 Mono", 0xc)
149 SDL_WAVE_DEBUG_CHANNELCFG(
"2.0 Stereo", 0x3)
150 SDL_WAVE_DEBUG_CHANNELCFG(
"2.1 Stereo", 0xb)
151 SDL_WAVE_DEBUG_CHANNELCFG(
"3.0 Stereo", 0x7)
152 SDL_WAVE_DEBUG_CHANNELCFG(
"3.1 Stereo", 0xf)
153 SDL_WAVE_DEBUG_CHANNELCFG(
"3.0 Surround", 0x103)
154 SDL_WAVE_DEBUG_CHANNELCFG(
"3.1 Surround", 0x10b)
155 SDL_WAVE_DEBUG_CHANNELCFG(
"4.0 Quad", 0x33)
156 SDL_WAVE_DEBUG_CHANNELCFG(
"4.1 Quad", 0x3b)
157 SDL_WAVE_DEBUG_CHANNELCFG(
"4.0 Surround", 0x107)
158 SDL_WAVE_DEBUG_CHANNELCFG(
"4.1 Surround", 0x10f)
159 SDL_WAVE_DEBUG_CHANNELCFG(
"5.0", 0x37)
160 SDL_WAVE_DEBUG_CHANNELCFG(
"5.1", 0x3f)
161 SDL_WAVE_DEBUG_CHANNELCFG(
"5.0 Side", 0x607)
162 SDL_WAVE_DEBUG_CHANNELCFG(
"5.1 Side", 0x60f)
163 SDL_WAVE_DEBUG_CHANNELCFG(
"6.0", 0x137)
164 SDL_WAVE_DEBUG_CHANNELCFG(
"6.1", 0x13f)
165 SDL_WAVE_DEBUG_CHANNELCFG(
"6.0 Side", 0x707)
166 SDL_WAVE_DEBUG_CHANNELCFG(
"6.1 Side", 0x70f)
167 SDL_WAVE_DEBUG_CHANNELCFG(
"7.0", 0xf7)
168 SDL_WAVE_DEBUG_CHANNELCFG(
"7.1", 0xff)
169 SDL_WAVE_DEBUG_CHANNELCFG(
"7.0 Side", 0x6c7)
170 SDL_WAVE_DEBUG_CHANNELCFG(
"7.1 Side", 0x6cf)
171 SDL_WAVE_DEBUG_CHANNELCFG(
"7.0 Surround", 0x637)
172 SDL_WAVE_DEBUG_CHANNELCFG(
"7.1 Surround", 0x63f)
173 SDL_WAVE_DEBUG_CHANNELCFG(
"9.0 Surround", 0x5637)
174 SDL_WAVE_DEBUG_CHANNELCFG(
"9.1 Surround", 0x563f)
175 SDL_WAVE_DEBUG_CHANNELCFG(
"11.0 Surround", 0x56f7)
176 SDL_WAVE_DEBUG_CHANNELCFG(
"11.1 Surround", 0x56ff)
178 SDL_WAVE_DEBUG_CHANNELSTR(
"FL", 0
x1)
179 SDL_WAVE_DEBUG_CHANNELSTR(
"FR", 0
x2)
180 SDL_WAVE_DEBUG_CHANNELSTR(
"FC", 0x4)
181 SDL_WAVE_DEBUG_CHANNELSTR(
"LF", 0x8)
182 SDL_WAVE_DEBUG_CHANNELSTR(
"BL", 0x10)
183 SDL_WAVE_DEBUG_CHANNELSTR(
"BR", 0x20)
184 SDL_WAVE_DEBUG_CHANNELSTR(
"FLC", 0x40)
185 SDL_WAVE_DEBUG_CHANNELSTR(
"FRC", 0x80)
186 SDL_WAVE_DEBUG_CHANNELSTR(
"BC", 0x100)
187 SDL_WAVE_DEBUG_CHANNELSTR(
"SL", 0x200)
188 SDL_WAVE_DEBUG_CHANNELSTR(
"SR", 0x400)
189 SDL_WAVE_DEBUG_CHANNELSTR(
"TC", 0x800)
190 SDL_WAVE_DEBUG_CHANNELSTR(
"TFL", 0x1000)
191 SDL_WAVE_DEBUG_CHANNELSTR(
"TFC", 0x2000)
192 SDL_WAVE_DEBUG_CHANNELSTR(
"TFR", 0x4000)
193 SDL_WAVE_DEBUG_CHANNELSTR(
"TBL", 0x8000)
194 SDL_WAVE_DEBUG_CHANNELSTR(
"TBC", 0x10000)
195 SDL_WAVE_DEBUG_CHANNELSTR(
"TBR", 0x20000)
202 wavechannel = channelstr;
206 wavechannel =
"Unknown";
209 wavechannel =
"Mono";
212 wavechannel =
"Setero";
217 #undef SDL_WAVE_DEBUG_CHANNELCFG 218 #undef SDL_WAVE_DEBUG_CHANNELSTR 220 if (wavebps >= 1024) {
222 wavebps = wavebps / 1024 + (wavebps & 0x3ff ? 1 : 0);
229 #ifdef SDL_WAVE_DEBUG_DUMP_FORMAT 234 const char *fmtstr1 =
"WAVE chunk dump:\n" 235 "-------------------------------------------\n" 237 "-------------------------------------------\n" 239 " wFormatTag 0x%04x\n" 241 " nSamplesPerSec %11u\n" 242 " nAvgBytesPerSec %11u\n" 243 " nBlockAlign %11u\n";
244 const char *fmtstr2 =
" wBitsPerSample %11u\n";
245 const char *fmtstr3 =
" cbSize %11u\n";
246 const char *fmtstr4a =
" wValidBitsPerSample %11u\n";
247 const char *fmtstr4b =
" wSamplesPerBlock %11u\n";
248 const char *fmtstr5 =
" dwChannelMask 0x%08x\n" 250 " %08x-%04x-%04x-%02x%02x%02x%02x%02x%02x%02x%02x\n";
251 const char *fmtstr6 =
"-------------------------------------------\n" 253 " dwSampleLength %11u\n";
254 const char *fmtstr7 =
"-------------------------------------------\n" 256 "-------------------------------------------\n";
263 if (dumpstr ==
NULL) {
269 dumppos += res > 0 ?
res : 0;
272 dumppos += res > 0 ?
res : 0;
276 dumppos += res > 0 ?
res : 0;
287 dumppos += res > 0 ?
res : 0;
292 dumppos += res > 0 ?
res : 0;
295 res =
SDL_snprintf(dumpstr + dumppos, bufsize - dumppos, fmtstr5, format->
channelmask, g1, g2, g3, g[8], g[9], g[10], g[11], g[12], g[13], g[14], g[15]);
296 dumppos += res > 0 ?
res : 0;
301 if (fmtlen >= 20 && format->
extsize >= 2) {
303 dumppos += res > 0 ?
res : 0;
310 dumppos += res > 0 ?
res : 0;
312 res =
SDL_snprintf(dumpstr + dumppos, bufsize - dumppos, fmtstr7, datalen);
313 dumppos += res > 0 ?
res : 0;
326 return SDL_SetError(
"Invalid number of sample frames in WAVE fact chunk (too many)");
346 if (datalength < blockheadersize || trailingdata > 0) {
353 if (trailingdata > 0) {
357 if (trailingdata >= blockheadersize) {
358 size_t trailingsamples = 2 + (trailingdata -
blockheadersize) * 8 / blockframebitsize;
383 const size_t blockdatasamples = (blockdatasize * 8) / blockframebitsize;
384 const Sint16 presetcoeffs[14] = {256, 0, 512, -256, 0, 0, 192, 64, 240, 0, 460, -208, 392, -232};
385 size_t i, coeffcount;
404 return SDL_SetError(
"Invalid MS ADPCM block size (nBlockAlign)");
412 return SDL_SetError(
"MS ADPCM with the extensible header is not supported");
418 if (chunk->
size < 22) {
419 return SDL_SetError(
"Could not read MS ADPCM format header");
429 if (coeffcount > 256) {
433 if (chunk->
size < 22 + coeffcount * 4) {
434 return SDL_SetError(
"Could not read custom coefficients in MS ADPCM format header");
435 }
else if (format->
extsize < 4 + coeffcount * 4) {
436 return SDL_SetError(
"Invalid MS ADPCM format header (too small)");
437 }
else if (coeffcount < 7) {
438 return SDL_SetError(
"Missing required coefficients in MS ADPCM format header");
443 if (coeffdata ==
NULL) {
450 for (i = 0; i < coeffcount * 2; i++) {
455 if (i < 14 && c != presetcoeffs[i]) {
456 return SDL_SetError(
"Wrong preset coefficients in MS ADPCM format header");
484 return SDL_SetError(
"Invalid number of samples per MS ADPCM block (wSamplesPerBlock)");
497 const Sint32 max_audioval = 32767;
498 const Sint32 min_audioval = -32768;
499 const Uint16 max_deltaval = 65535;
500 const Uint16 adaptive[] = {
501 230, 230, 230, 230, 307, 409, 512, 614,
502 768, 614, 512, 409, 307, 230, 230, 230
508 new_sample = (sample1 * cstate->
coeff1 + sample2 * cstate->
coeff2) / 256;
510 errordelta = (
Sint32)nybble - (nybble >= 0x08 ? 0x10 : 0);
511 new_sample += (
Sint32)delta * errordelta;
512 if (new_sample < min_audioval) {
513 new_sample = min_audioval;
514 }
else if (new_sample > max_audioval) {
515 new_sample = max_audioval;
517 delta = (delta * adaptive[nybble]) / 256;
520 }
else if (delta > max_deltaval) {
524 delta = max_deltaval;
528 return (
Sint16)new_sample;
546 if (coeffindex >
ddata->coeffcount) {
547 return SDL_SetError(
"Invalid MS ADPCM coefficient index in block header");
553 o = channels + c * 2;
559 o = channels * 3 + c * 2;
561 if (sample >= 0x8000) {
566 o = channels * 5 + c * 2;
568 if (sample >= 0x8000) {
611 while (blockframesleft > 0) {
613 if (nybble & 0x4000) {
616 nybble = state->
block.
data[blockpos++] | 0x4000;
625 sample2 = state->
output.
data[outpos - channels * 2];
644 size_t bytesleft, outputsize;
706 return SDL_SetError(
"Unexpected overflow in MS ADPCM decoder");
735 *audio_len = (
Uint32)outputsize;
745 const size_t subblockframesize = (
size_t)format->
channels * 4;
746 const size_t availableblocks = datalength / format->
blockalign;
747 const size_t trailingdata = datalength % format->
blockalign;
751 if (datalength < blockheadersize || trailingdata > 0) {
758 if (trailingdata > 0) {
764 size_t trailingsamples = 1;
766 if (trailingdata > blockheadersize) {
769 const size_t trailingsubblockdata = trailingblockdata % subblockframesize;
770 trailingsamples += (trailingblockdata / subblockframesize) * 8;
774 if (trailingsubblockdata > subblockframesize - 4) {
775 trailingsamples += (trailingsubblockdata % 4) * 2;
802 const size_t blockdatasamples = (blockdatasize * 8) / blockframebitsize;
808 return SDL_SetError(
"3-bit IMA ADPCM currently not supported");
817 return SDL_SetError(
"Invalid IMA ADPCM block size (nBlockAlign)");
850 return SDL_SetError(
"Invalid number of samples per IMA ADPCM block (wSamplesPerBlock)");
863 const Sint32 max_audioval = 32767;
864 const Sint32 min_audioval = -32768;
865 const Sint8 index_table_4b[16] = {
871 const Uint16 step_table[89] = {
872 7, 8, 9, 10, 11, 12, 13, 14, 16, 17, 19, 21, 23, 25, 28, 31,
873 34, 37, 41, 45, 50, 55, 60, 66, 73, 80, 88, 97, 107, 118, 130,
874 143, 157, 173, 190, 209, 230, 253, 279, 307, 337, 371, 408,
875 449, 494, 544, 598, 658, 724, 796, 876, 963, 1060, 1166, 1282,
876 1411, 1552, 1707, 1878, 2066, 2272, 2499, 2749, 3024, 3327,
877 3660, 4026, 4428, 4871, 5358, 5894, 6484, 7132, 7845, 8630,
878 9493, 10442, 11487, 12635, 13899, 15289, 16818, 18500, 20350,
879 22385, 24623, 27086, 29794, 32767
888 }
else if (index < 0) {
893 step = step_table[(
size_t)index];
896 *cindex = index + index_table_4b[nybble];
914 sample = lastsample + delta;
917 if (sample > max_audioval) {
918 sample = max_audioval;
919 }
else if (sample < min_audioval) {
920 sample = min_audioval;
933 for (c = 0; c < state->
channels; c++) {
934 size_t o = state->
block.
pos + c * 4;
938 if (sample >= 0x8000) {
945 cstate[c] = (
Sint8)(step > 0x80 ? step - 0x100 : step);
972 const size_t subblockframesize = channels * 4;
978 size_t blockleft = blocksize - blockpos;
987 bytesrequired = (blockframesleft + 7) / 8 * subblockframesize;
988 if (blockleft < bytesrequired) {
990 const size_t guaranteedframes = blockleft / subblockframesize;
991 const size_t remainingbytes = blockleft % subblockframesize;
992 blockframesleft = guaranteedframes;
993 if (remainingbytes > subblockframesize - 4) {
994 blockframesleft += (remainingbytes % 4) * 2;
1005 while (blockframesleft > 0) {
1006 const size_t subblocksamples = blockframesleft < 8 ? (
size_t)blockframesleft : 8;
1013 for (i = 0; i < subblocksamples; i++) {
1025 outpos += channels * subblocksamples;
1027 blockframesleft -= subblocksamples;
1040 size_t bytesleft, outputsize;
1088 if (cstate ==
NULL) {
1105 return SDL_SetError(
"Unexpected overflow in IMA ADPCM decoder");
1133 *audio_len = (
Uint32)outputsize;
1157 return SDL_SetError(
"Truncated data chunk in WAVE file");
1172 #ifdef SDL_WAVE_LAW_LUT 1173 const Sint16 alaw_lut[256] = {
1174 -5504, -5248, -6016, -5760, -4480, -4224, -4992, -4736, -7552, -7296, -8064, -7808, -6528, -6272, -7040, -6784, -2752,
1175 -2624, -3008, -2880, -2240, -2112, -2496, -2368, -3776, -3648, -4032, -3904, -3264, -3136, -3520, -3392, -22016,
1176 -20992, -24064, -23040, -17920, -16896, -19968, -18944, -30208, -29184, -32256, -31232, -26112, -25088, -28160, -27136, -11008,
1177 -10496, -12032, -11520, -8960, -8448, -9984, -9472, -15104, -14592, -16128, -15616, -13056, -12544, -14080, -13568, -344,
1178 -328, -376, -360, -280, -264, -312, -296, -472, -456, -504, -488, -408, -392, -440, -424, -88,
1179 -72, -120, -104, -24, -8, -56, -40, -216, -200, -248, -232, -152, -136, -184, -168, -1376,
1180 -1312, -1504, -1440, -1120, -1056, -1248, -1184, -1888, -1824, -2016, -1952, -1632, -1568, -1760, -1696, -688,
1181 -656, -752, -720, -560, -528, -624, -592, -944, -912, -1008, -976, -816, -784, -880, -848, 5504,
1182 5248, 6016, 5760, 4480, 4224, 4992, 4736, 7552, 7296, 8064, 7808, 6528, 6272, 7040, 6784, 2752,
1183 2624, 3008, 2880, 2240, 2112, 2496, 2368, 3776, 3648, 4032, 3904, 3264, 3136, 3520, 3392, 22016,
1184 20992, 24064, 23040, 17920, 16896, 19968, 18944, 30208, 29184, 32256, 31232, 26112, 25088, 28160, 27136, 11008,
1185 10496, 12032, 11520, 8960, 8448, 9984, 9472, 15104, 14592, 16128, 15616, 13056, 12544, 14080, 13568, 344,
1186 328, 376, 360, 280, 264, 312, 296, 472, 456, 504, 488, 408, 392, 440, 424, 88,
1187 72, 120, 104, 24, 8, 56, 40, 216, 200, 248, 232, 152, 136, 184, 168, 1376,
1188 1312, 1504, 1440, 1120, 1056, 1248, 1184, 1888, 1824, 2016, 1952, 1632, 1568, 1760, 1696, 688,
1189 656, 752, 720, 560, 528, 624, 592, 944, 912, 1008, 976, 816, 784, 880, 848
1191 const Sint16 mulaw_lut[256] = {
1192 -32124, -31100, -30076, -29052, -28028, -27004, -25980, -24956, -23932, -22908, -21884, -20860, -19836, -18812, -17788, -16764, -15996,
1193 -15484, -14972, -14460, -13948, -13436, -12924, -12412, -11900, -11388, -10876, -10364, -9852, -9340, -8828, -8316, -7932,
1194 -7676, -7420, -7164, -6908, -6652, -6396, -6140, -5884, -5628, -5372, -5116, -4860, -4604, -4348, -4092, -3900,
1195 -3772, -3644, -3516, -3388, -3260, -3132, -3004, -2876, -2748, -2620, -2492, -2364, -2236, -2108, -1980, -1884,
1196 -1820, -1756, -1692, -1628, -1564, -1500, -1436, -1372, -1308, -1244, -1180, -1116, -1052, -988, -924, -876,
1197 -844, -812, -780, -748, -716, -684, -652, -620, -588, -556, -524, -492, -460, -428, -396, -372,
1198 -356, -340, -324, -308, -292, -276, -260, -244, -228, -212, -196, -180, -164, -148, -132, -120,
1199 -112, -104, -96, -88, -80, -72, -64, -56, -48, -40, -32, -24, -16, -8, 0, 32124,
1200 31100, 30076, 29052, 28028, 27004, 25980, 24956, 23932, 22908, 21884, 20860, 19836, 18812, 17788, 16764, 15996,
1201 15484, 14972, 14460, 13948, 13436, 12924, 12412, 11900, 11388, 10876, 10364, 9852, 9340, 8828, 8316, 7932,
1202 7676, 7420, 7164, 6908, 6652, 6396, 6140, 5884, 5628, 5372, 5116, 4860, 4604, 4348, 4092, 3900,
1203 3772, 3644, 3516, 3388, 3260, 3132, 3004, 2876, 2748, 2620, 2492, 2364, 2236, 2108, 1980, 1884,
1204 1820, 1756, 1692, 1628, 1564, 1500, 1436, 1372, 1308, 1244, 1180, 1116, 1052, 988, 924, 876,
1205 844, 812, 780, 748, 716, 684, 652, 620, 588, 556, 524, 492, 460, 428, 396, 372,
1206 356, 340, 324, 308, 292, 276, 260, 244, 228, 212, 196, 180, 164, 148, 132, 120,
1207 112, 104, 96, 88, 80, 72, 64, 56, 48, 40, 32, 24, 16, 8, 0
1213 size_t i, sample_count, expanded_len;
1236 expanded_len = sample_count;
1258 #ifdef SDL_WAVE_LAW_LUT 1261 dst[
i] = alaw_lut[src[
i]];
1266 dst[
i] = mulaw_lut[src[
i]];
1274 Sint16 mantissa = exponent & 0xf;
1280 mantissa = (mantissa << 4) | 0x8;
1282 mantissa <<= exponent - 1;
1285 dst[
i] = nibble & 0x80 ? mantissa : -mantissa;
1291 Sint16 mantissa = nibble & 0xf;
1293 Sint16 step = 4 << (exponent + 1);
1295 mantissa = (0x80 <<
exponent) + step * mantissa + step / 2 - 132;
1297 dst[
i] = nibble & 0x80 ? -mantissa : mantissa;
1307 *audio_len = (
Uint32)expanded_len;
1343 return SDL_SetError(
"Truncated data chunk in WAVE file");
1360 size_t i, expanded_len, sample_count;
1368 expanded_len = sample_count;
1386 *audio_len = (
Uint32)expanded_len;
1389 for (i = sample_count; i > 0; i--) {
1390 const size_t o = i - 1;
1395 b[2] = ptr[o * 3 + 1];
1396 b[3] = ptr[o * 3 + 2];
1398 ptr[o * 4 + 0] = b[0];
1399 ptr[o * 4 + 1] = b[1];
1400 ptr[o * 4 + 2] = b[2];
1401 ptr[o * 4 + 3] = b[3];
1440 *audio_buf = chunk->
data;
1441 *audio_len = (
Uint32)outputsize;
1458 }
else if (
SDL_strcmp(hint,
"ignore") == 0) {
1460 }
else if (
SDL_strcmp(hint,
"ignorezero") == 0) {
1462 }
else if (
SDL_strcmp(hint,
"maximum") == 0) {
1478 }
else if (
SDL_strcmp(hint,
"strict") == 0) {
1480 }
else if (
SDL_strcmp(hint,
"dropframe") == 0) {
1482 }
else if (
SDL_strcmp(hint,
"dropblock") == 0) {
1498 }
else if (
SDL_strcmp(hint,
"strict") == 0) {
1500 }
else if (
SDL_strcmp(hint,
"ignorezero") == 0) {
1502 }
else if (
SDL_strcmp(hint,
"ignore") == 0) {
1542 }
else if (
SDL_RWread(src, chunkheader, 4, 2) != 2) {
1548 chunk->
position = nextposition + 8;
1558 if (length > chunk->
length) {
1574 if (chunk->
size != length) {
1594 #define WAVE_FORMATTAG_GUID(tag) {(tag) & 0xff, (tag) >> 8, 0, 0, 0, 0, 16, 0, 128, 0, 0, 170, 0, 56, 155, 113} 1622 size_t fmtlen = chunk->
size;
1629 if (fmtsrc ==
NULL) {
1645 return SDL_SetError(
"Missing wBitsPerSample field in WAVE fmt chunk");
1661 if (fmtlen < 40 || format->extsize < 22) {
1663 return SDL_SetError(
"Extensible WAVE header too small");
1687 }
else if (format->
channels > 255) {
1689 return SDL_SetError(
"Number of channels exceeds limit of 255");
1701 return SDL_SetError(
"Invalid fact chunk in WAVE file");
1716 return SDL_SetError(
"Missing fact chunk in WAVE file");
1722 return SDL_SetError(
"Missing wBitsPerSample field in WAVE fmt chunk");
1748 if (
PCM_Init(file, datalength) < 0) {
1754 if (
LAW_Init(file, datalength) < 0) {
1773 const char *errstr =
"Unknown WAVE format GUID: %08x-%04x-%04x-%02x%02x%02x%02x%02x%02x%02x%02x";
1778 return SDL_SetError(errstr, g1, g2, g3, g[8], g[9], g[10], g[11], g[12], g[13], g[14], g[15]);
1791 Uint32 chunkcountlimit = 10000;
1792 char *envchunkcountlimit;
1793 Sint64 RIFFstart, RIFFend, lastchunkpos;
1805 envchunkcountlimit =
SDL_getenv(
"SDL_WAVE_CHUNK_LIMIT");
1806 if (envchunkcountlimit !=
NULL) {
1808 if (
SDL_sscanf(envchunkcountlimit,
"%u", &count) == 1) {
1814 if (RIFFstart < 0) {
1830 return SDL_SetError(
"RIFF form type is not WAVE (not a Waveform file)");
1837 return SDL_SetError(
"Could not find RIFF or WAVE identifiers (not a Waveform file)");
1853 if (RIFFchunk.
length == 0) {
1873 if (chunkcount++ >= chunkcountlimit) {
1874 return SDL_SetError(
"Chunk count in WAVE file exceeds limit of %u", chunkcountlimit);
1885 }
else if (result == -2) {
1886 return SDL_SetError(
"Could not seek to WAVE chunk header");
1895 return SDL_SetError(
"fmt chunk after data chunk in WAVE file");
1952 return SDL_SetError(
"Missing data chunk in WAVE file");
1961 return SDL_SetError(
"Could not seek to WAVE chunk data");
1962 }
else if (
SDL_RWread(src, &tmp, 1, 1) != 1) {
1975 return SDL_SetError(
"Could not read data of WAVE fmt chunk");
1981 if (chunk->
length < 14) {
1982 return SDL_SetError(
"Invalid WAVE fmt chunk length (too small)");
1983 }
else if (chunk->
size < 14) {
1984 return SDL_SetError(
"Could not read data of WAVE fmt chunk");
1991 #ifdef SDL_WAVE_DEBUG_LOG_FORMAT 1992 WaveDebugLogFormat(file);
1994 #ifdef SDL_WAVE_DEBUG_DUMP_FORMAT 2007 }
else if (result == -2) {
2008 return SDL_SetError(
"Could not seek data of WAVE data chunk");
2015 return SDL_SetError(
"Could not read data of WAVE data chunk");
2024 if (
PCM_Decode(file, audio_buf, audio_len) < 0) {
2030 if (
LAW_Decode(file, audio_buf, audio_len) < 0) {
2085 if (RIFFlengthknown) {
2106 }
else if (spec ==
NULL) {
2109 }
else if (audio_buf ==
NULL) {
2112 }
else if (audio_len ==
NULL) {
2124 result =
WaveLoad(src, &file, spec, audio_buf, audio_len);
static int IMA_ADPCM_DecodeBlockHeader(ADPCM_DecoderState *state)
static int IMA_ADPCM_Decode(WaveFile *file, Uint8 **audio_buf, Uint32 *audio_len)
#define SDL_MAX_SINT64
A signed 64-bit integer type.
GLuint GLfloat GLfloat GLfloat x1
static int SafeMult(size_t *f1, size_t f2)
static int IMA_ADPCM_DecodeBlockData(ADPCM_DecoderState *state)
static Sint16 IMA_ADPCM_ProcessNibble(Sint8 *cindex, Sint16 lastsample, Uint8 nybble)
GLuint GLuint GLsizei count
static int MS_ADPCM_CalculateSampleFrames(WaveFile *file, size_t datalength)
struct ADPCM_DecoderState::@20 input
#define SDL_MAX_UINT32
An unsigned 32-bit integer type.
static int WaveLoad(SDL_RWops *src, WaveFile *file, SDL_AudioSpec *spec, Uint8 **audio_buf, Uint32 *audio_len)
WaveRiffSizeHint riffhint
void SDL_FreeWAV(Uint8 *audio_buf)
struct ADPCM_DecoderState::@22 output
static int IMA_ADPCM_Init(WaveFile *file, size_t datalength)
static void WaveFreeChunkData(WaveChunk *chunk)
#define SDL_MAX_SINT32
A signed 32-bit integer type.
#define SDL_InvalidParamError(param)
static int MS_ADPCM_Init(WaveFile *file, size_t datalength)
SDL_AudioSpec * SDL_LoadWAV_RW(SDL_RWops *src, int freesrc, SDL_AudioSpec *spec, Uint8 **audio_buf, Uint32 *audio_len)
Load the audio data of a WAVE file into memory.
static int WaveReadPartialChunkData(SDL_RWops *src, WaveChunk *chunk, size_t length)
static int IMA_ADPCM_CalculateSampleFrames(WaveFile *file, size_t datalength)
static int WaveReadChunkData(SDL_RWops *src, WaveChunk *chunk)
static int WaveNextChunk(SDL_RWops *src, WaveChunk *chunk)
GLenum GLuint GLsizei bufsize
WaveFactChunkHint facthint
GLint GLint GLsizei GLsizei GLsizei GLint GLenum format
static int MS_ADPCM_Decode(WaveFile *file, Uint8 **audio_buf, Uint32 *audio_len)
static int MS_ADPCM_DecodeBlockHeader(ADPCM_DecoderState *state)
struct ADPCM_DecoderState::@21 block
WaveTruncationHint trunchint
static int LAW_Init(WaveFile *file, size_t datalength)
static WaveTruncationHint WaveGetTruncationHint()
static Sint16 MS_ADPCM_ProcessNibble(MS_ADPCM_ChannelState *cstate, Sint32 sample1, Sint32 sample2, Uint8 nybble)
return Display return Display Bool Bool int int int return Display XEvent Bool(*) XPointer return Display return Display Drawable _Xconst char unsigned int unsigned int return Display Pixmap Pixmap XColor XColor unsigned int unsigned int return Display _Xconst char char int char return Display Visual unsigned int int int char unsigned int unsigned int in i)
static int PCM_Init(WaveFile *file, size_t datalength)
#define SDL_OutOfMemory()
static WaveRiffSizeHint WaveGetRiffSizeHint()
static unsigned char nibble(char c)
#define SDL_HINT_WAVE_FACT_CHUNK
Controls how the fact chunk affects the loading of a WAVE file.
#define SDL_HINT_WAVE_TRUNCATION
Controls how a truncated WAVE file is handled.
static Uint16 WaveGetFormatGUIDEncoding(WaveFormat *format)
static WaveFactChunkHint WaveGetFactChunkHint()
#define SDL_arraysize(array)
static Sint64 WaveAdjustToFactValue(WaveFile *file, Sint64 sampleframes)
#define SDL_HINT_WAVE_RIFF_CHUNK_SIZE
Controls how the size of the RIFF chunk affects the loading of a WAVE file.
#define SDL_RWFromConstMem
#define WAVE_FORMATTAG_GUID(tag)
static int WaveCheckFormat(WaveFile *file, size_t datalength)
static int LAW_Decode(WaveFile *file, Uint8 **audio_buf, Uint32 *audio_len)
static int PCM_Decode(WaveFile *file, Uint8 **audio_buf, Uint32 *audio_len)
GLuint GLsizei GLsizei * length
static int MS_ADPCM_DecodeBlockData(ADPCM_DecoderState *state)
GLboolean GLboolean GLboolean b
static WaveExtensibleGUID extensible_guids[]
static int WaveReadFormat(WaveFile *file)
static int PCM_ConvertSint24ToSint32(WaveFile *file, Uint8 **audio_buf, Uint32 *audio_len)