21 #include "../SDL_internal.h" 27 #define SIZE_MAX ((size_t)-1) 31 #define INT_MAX (SDL_MAX_SINT32) 49 if (*f1 > 0 &&
SIZE_MAX / *f1 <= f2) {
104 #ifdef SDL_WAVE_DEBUG_LOG_FORMAT 109 const char *fmtstr =
"WAVE file: %s, %u Hz, %s, %u bits, %u %s/s";
110 const char *waveformat, *wavechannel, *wavebpsunit =
"B";
112 char channelstr[64] = {0};
119 waveformat =
"IEEE Float";
122 waveformat =
"A-law";
125 waveformat =
"\xc2\xb5-law";
128 waveformat =
"MS ADPCM";
131 waveformat =
"IMA ADPCM";
134 waveformat =
"Unknown";
138 #define SDL_WAVE_DEBUG_CHANNELCFG(STR, CODE) case CODE: wavechannel = STR; break; 139 #define SDL_WAVE_DEBUG_CHANNELSTR(STR, CODE) if (format->channelmask & CODE) { \ 140 SDL_strlcat(channelstr, channelstr[0] ? "-" STR : STR, sizeof(channelstr));} 144 SDL_WAVE_DEBUG_CHANNELCFG(
"1.0 Mono", 0x4)
145 SDL_WAVE_DEBUG_CHANNELCFG(
"1.1 Mono", 0xc)
146 SDL_WAVE_DEBUG_CHANNELCFG(
"2.0 Stereo", 0x3)
147 SDL_WAVE_DEBUG_CHANNELCFG(
"2.1 Stereo", 0xb)
148 SDL_WAVE_DEBUG_CHANNELCFG(
"3.0 Stereo", 0x7)
149 SDL_WAVE_DEBUG_CHANNELCFG(
"3.1 Stereo", 0xf)
150 SDL_WAVE_DEBUG_CHANNELCFG(
"3.0 Surround", 0x103)
151 SDL_WAVE_DEBUG_CHANNELCFG(
"3.1 Surround", 0x10b)
152 SDL_WAVE_DEBUG_CHANNELCFG(
"4.0 Quad", 0x33)
153 SDL_WAVE_DEBUG_CHANNELCFG(
"4.1 Quad", 0x3b)
154 SDL_WAVE_DEBUG_CHANNELCFG(
"4.0 Surround", 0x107)
155 SDL_WAVE_DEBUG_CHANNELCFG(
"4.1 Surround", 0x10f)
156 SDL_WAVE_DEBUG_CHANNELCFG(
"5.0", 0x37)
157 SDL_WAVE_DEBUG_CHANNELCFG(
"5.1", 0x3f)
158 SDL_WAVE_DEBUG_CHANNELCFG(
"5.0 Side", 0x607)
159 SDL_WAVE_DEBUG_CHANNELCFG(
"5.1 Side", 0x60f)
160 SDL_WAVE_DEBUG_CHANNELCFG(
"6.0", 0x137)
161 SDL_WAVE_DEBUG_CHANNELCFG(
"6.1", 0x13f)
162 SDL_WAVE_DEBUG_CHANNELCFG(
"6.0 Side", 0x707)
163 SDL_WAVE_DEBUG_CHANNELCFG(
"6.1 Side", 0x70f)
164 SDL_WAVE_DEBUG_CHANNELCFG(
"7.0", 0xf7)
165 SDL_WAVE_DEBUG_CHANNELCFG(
"7.1", 0xff)
166 SDL_WAVE_DEBUG_CHANNELCFG(
"7.0 Side", 0x6c7)
167 SDL_WAVE_DEBUG_CHANNELCFG(
"7.1 Side", 0x6cf)
168 SDL_WAVE_DEBUG_CHANNELCFG(
"7.0 Surround", 0x637)
169 SDL_WAVE_DEBUG_CHANNELCFG(
"7.1 Surround", 0x63f)
170 SDL_WAVE_DEBUG_CHANNELCFG(
"9.0 Surround", 0x5637)
171 SDL_WAVE_DEBUG_CHANNELCFG(
"9.1 Surround", 0x563f)
172 SDL_WAVE_DEBUG_CHANNELCFG(
"11.0 Surround", 0x56f7)
173 SDL_WAVE_DEBUG_CHANNELCFG(
"11.1 Surround", 0x56ff)
175 SDL_WAVE_DEBUG_CHANNELSTR(
"FL", 0
x1)
176 SDL_WAVE_DEBUG_CHANNELSTR(
"FR", 0
x2)
177 SDL_WAVE_DEBUG_CHANNELSTR(
"FC", 0x4)
178 SDL_WAVE_DEBUG_CHANNELSTR(
"LF", 0x8)
179 SDL_WAVE_DEBUG_CHANNELSTR(
"BL", 0x10)
180 SDL_WAVE_DEBUG_CHANNELSTR(
"BR", 0x20)
181 SDL_WAVE_DEBUG_CHANNELSTR(
"FLC", 0x40)
182 SDL_WAVE_DEBUG_CHANNELSTR(
"FRC", 0x80)
183 SDL_WAVE_DEBUG_CHANNELSTR(
"BC", 0x100)
184 SDL_WAVE_DEBUG_CHANNELSTR(
"SL", 0x200)
185 SDL_WAVE_DEBUG_CHANNELSTR(
"SR", 0x400)
186 SDL_WAVE_DEBUG_CHANNELSTR(
"TC", 0x800)
187 SDL_WAVE_DEBUG_CHANNELSTR(
"TFL", 0x1000)
188 SDL_WAVE_DEBUG_CHANNELSTR(
"TFC", 0x2000)
189 SDL_WAVE_DEBUG_CHANNELSTR(
"TFR", 0x4000)
190 SDL_WAVE_DEBUG_CHANNELSTR(
"TBL", 0x8000)
191 SDL_WAVE_DEBUG_CHANNELSTR(
"TBC", 0x10000)
192 SDL_WAVE_DEBUG_CHANNELSTR(
"TBR", 0x20000)
199 wavechannel = channelstr;
203 wavechannel =
"Unknown";
206 wavechannel =
"Mono";
209 wavechannel =
"Setero";
214 #undef SDL_WAVE_DEBUG_CHANNELCFG 215 #undef SDL_WAVE_DEBUG_CHANNELSTR 217 if (wavebps >= 1024) {
219 wavebps = wavebps / 1024 + (wavebps & 0x3ff ? 1 : 0);
226 #ifdef SDL_WAVE_DEBUG_DUMP_FORMAT 231 const char *fmtstr1 =
"WAVE chunk dump:\n" 232 "-------------------------------------------\n" 234 "-------------------------------------------\n" 236 " wFormatTag 0x%04x\n" 238 " nSamplesPerSec %11u\n" 239 " nAvgBytesPerSec %11u\n" 240 " nBlockAlign %11u\n";
241 const char *fmtstr2 =
" wBitsPerSample %11u\n";
242 const char *fmtstr3 =
" cbSize %11u\n";
243 const char *fmtstr4a =
" wValidBitsPerSample %11u\n";
244 const char *fmtstr4b =
" wSamplesPerBlock %11u\n";
245 const char *fmtstr5 =
" dwChannelMask 0x%08x\n" 247 " %08x-%04x-%04x-%02x%02x%02x%02x%02x%02x%02x%02x\n";
248 const char *fmtstr6 =
"-------------------------------------------\n" 250 " dwSampleLength %11u\n";
251 const char *fmtstr7 =
"-------------------------------------------\n" 253 "-------------------------------------------\n";
260 if (dumpstr ==
NULL) {
266 dumppos += res > 0 ?
res : 0;
269 dumppos += res > 0 ?
res : 0;
273 dumppos += res > 0 ?
res : 0;
284 dumppos += res > 0 ?
res : 0;
289 dumppos += res > 0 ?
res : 0;
292 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]);
293 dumppos += res > 0 ?
res : 0;
298 if (fmtlen >= 20 && format->
extsize >= 2) {
300 dumppos += res > 0 ?
res : 0;
307 dumppos += res > 0 ?
res : 0;
309 res =
SDL_snprintf(dumpstr + dumppos, bufsize - dumppos, fmtstr7, datalen);
310 dumppos += res > 0 ?
res : 0;
323 return SDL_SetError(
"Invalid number of sample frames in WAVE fact chunk (too many)");
343 if (datalength < blockheadersize || trailingdata > 0) {
350 if (trailingdata > 0) {
354 if (trailingdata >= blockheadersize) {
355 size_t trailingsamples = 2 + (trailingdata -
blockheadersize) * 8 / blockframebitsize;
380 const size_t blockdatasamples = (blockdatasize * 8) / blockframebitsize;
381 const Sint16 presetcoeffs[14] = {256, 0, 512, -256, 0, 0, 192, 64, 240, 0, 460, -208, 392, -232};
382 size_t i, coeffcount;
401 return SDL_SetError(
"Invalid MS ADPCM block size (nBlockAlign)");
409 return SDL_SetError(
"MS ADPCM with the extensible header is not supported");
415 if (chunk->
size < 22) {
416 return SDL_SetError(
"Could not read MS ADPCM format header");
426 if (coeffcount > 256) {
430 if (chunk->
size < 22 + coeffcount * 4) {
431 return SDL_SetError(
"Could not read custom coefficients in MS ADPCM format header");
432 }
else if (format->
extsize < 4 + coeffcount * 4) {
433 return SDL_SetError(
"Invalid MS ADPCM format header (too small)");
434 }
else if (coeffcount < 7) {
435 return SDL_SetError(
"Missing required coefficients in MS ADPCM format header");
440 if (coeffdata ==
NULL) {
447 for (i = 0; i < coeffcount * 2; i++) {
452 if (i < 14 && c != presetcoeffs[i]) {
453 return SDL_SetError(
"Wrong preset coefficients in MS ADPCM format header");
481 return SDL_SetError(
"Invalid number of samples per MS ADPCM block (wSamplesPerBlock)");
494 const Sint32 max_audioval = 32767;
495 const Sint32 min_audioval = -32768;
496 const Uint16 max_deltaval = 65535;
497 const Uint16 adaptive[] = {
498 230, 230, 230, 230, 307, 409, 512, 614,
499 768, 614, 512, 409, 307, 230, 230, 230
505 new_sample = (sample1 * cstate->
coeff1 + sample2 * cstate->
coeff2) / 256;
507 errordelta = (
Sint32)nybble - (nybble >= 0x08 ? 0x10 : 0);
508 new_sample += (
Sint32)delta * errordelta;
509 if (new_sample < min_audioval) {
510 new_sample = min_audioval;
511 }
else if (new_sample > max_audioval) {
512 new_sample = max_audioval;
514 delta = (delta * adaptive[nybble]) / 256;
517 }
else if (delta > max_deltaval) {
521 delta = max_deltaval;
525 return (
Sint16)new_sample;
543 if (coeffindex >
ddata->coeffcount) {
544 return SDL_SetError(
"Invalid MS ADPCM coefficient index in block header");
550 o = channels + c * 2;
556 o = channels * 3 + c * 2;
558 if (sample >= 0x8000) {
563 o = channels * 5 + c * 2;
565 if (sample >= 0x8000) {
608 while (blockframesleft > 0) {
610 if (nybble & 0x8000) {
613 nybble = state->
block.
data[blockpos++] | 0x8000;
622 sample2 = state->
output.
data[outpos - channels * 2];
641 size_t bytesleft, outputsize;
700 return SDL_SetError(
"Unexpected overflow in MS ADPCM decoder");
729 *audio_len = (
Uint32)outputsize;
739 const size_t subblockframesize = format->
channels * 4;
740 const size_t availableblocks = datalength / format->
blockalign;
741 const size_t trailingdata = datalength % format->
blockalign;
745 if (datalength < blockheadersize || trailingdata > 0) {
752 if (trailingdata > 0) {
758 size_t trailingsamples = 1;
760 if (trailingdata > blockheadersize) {
763 const size_t trailingsubblockdata = trailingblockdata % subblockframesize;
764 trailingsamples += (trailingblockdata / subblockframesize) * 8;
768 if (trailingsubblockdata > subblockframesize - 4) {
769 trailingsamples += (trailingsubblockdata % 4) * 2;
796 const size_t blockdatasamples = (blockdatasize * 8) / blockframebitsize;
802 return SDL_SetError(
"3-bit IMA ADPCM currently not supported");
811 return SDL_SetError(
"Invalid IMA ADPCM block size (nBlockAlign)");
844 return SDL_SetError(
"Invalid number of samples per IMA ADPCM block (wSamplesPerBlock)");
857 const Sint32 max_audioval = 32767;
858 const Sint32 min_audioval = -32768;
859 const Sint8 index_table_4b[16] = {
865 const Uint16 step_table[89] = {
866 7, 8, 9, 10, 11, 12, 13, 14, 16, 17, 19, 21, 23, 25, 28, 31,
867 34, 37, 41, 45, 50, 55, 60, 66, 73, 80, 88, 97, 107, 118, 130,
868 143, 157, 173, 190, 209, 230, 253, 279, 307, 337, 371, 408,
869 449, 494, 544, 598, 658, 724, 796, 876, 963, 1060, 1166, 1282,
870 1411, 1552, 1707, 1878, 2066, 2272, 2499, 2749, 3024, 3327,
871 3660, 4026, 4428, 4871, 5358, 5894, 6484, 7132, 7845, 8630,
872 9493, 10442, 11487, 12635, 13899, 15289, 16818, 18500, 20350,
873 22385, 24623, 27086, 29794, 32767
882 }
else if (index < 0) {
887 step = step_table[(
size_t)index];
890 *cindex = index + index_table_4b[nybble];
908 sample = lastsample + delta;
911 if (sample > max_audioval) {
912 sample = max_audioval;
913 }
else if (sample < min_audioval) {
914 sample = min_audioval;
927 for (c = 0; c < state->
channels; c++) {
928 size_t o = state->
block.
pos + c * 4;
932 if (sample >= 0x8000) {
939 cstate[c] = (
Sint8)(step > 0x80 ? step - 0x100 : step);
966 const size_t subblockframesize = channels * 4;
972 size_t blockleft = blocksize - blockpos;
981 bytesrequired = (blockframesleft + 7) / 8 * subblockframesize;
982 if (blockleft < bytesrequired) {
984 const size_t guaranteedframes = blockleft / subblockframesize;
985 const size_t remainingbytes = blockleft % subblockframesize;
986 blockframesleft = guaranteedframes;
987 if (remainingbytes > subblockframesize - 4) {
988 blockframesleft += (remainingbytes % 4) * 2;
999 while (blockframesleft > 0) {
1000 const size_t subblocksamples = blockframesleft < 8 ? (
size_t)blockframesleft : 8;
1007 for (i = 0; i < subblocksamples; i++) {
1019 outpos += channels * subblocksamples;
1021 blockframesleft -= subblocksamples;
1034 size_t bytesleft, outputsize;
1081 if (cstate ==
NULL) {
1098 return SDL_SetError(
"Unexpected overflow in IMA ADPCM decoder");
1124 *audio_len = (
Uint32)outputsize;
1148 return SDL_SetError(
"Truncated data chunk in WAVE file");
1163 #ifdef SDL_WAVE_LAW_LUT 1164 const Sint16 alaw_lut[256] = {
1165 -5504, -5248, -6016, -5760, -4480, -4224, -4992, -4736, -7552, -7296, -8064, -7808, -6528, -6272, -7040, -6784, -2752,
1166 -2624, -3008, -2880, -2240, -2112, -2496, -2368, -3776, -3648, -4032, -3904, -3264, -3136, -3520, -3392, -22016,
1167 -20992, -24064, -23040, -17920, -16896, -19968, -18944, -30208, -29184, -32256, -31232, -26112, -25088, -28160, -27136, -11008,
1168 -10496, -12032, -11520, -8960, -8448, -9984, -9472, -15104, -14592, -16128, -15616, -13056, -12544, -14080, -13568, -344,
1169 -328, -376, -360, -280, -264, -312, -296, -472, -456, -504, -488, -408, -392, -440, -424, -88,
1170 -72, -120, -104, -24, -8, -56, -40, -216, -200, -248, -232, -152, -136, -184, -168, -1376,
1171 -1312, -1504, -1440, -1120, -1056, -1248, -1184, -1888, -1824, -2016, -1952, -1632, -1568, -1760, -1696, -688,
1172 -656, -752, -720, -560, -528, -624, -592, -944, -912, -1008, -976, -816, -784, -880, -848, 5504,
1173 5248, 6016, 5760, 4480, 4224, 4992, 4736, 7552, 7296, 8064, 7808, 6528, 6272, 7040, 6784, 2752,
1174 2624, 3008, 2880, 2240, 2112, 2496, 2368, 3776, 3648, 4032, 3904, 3264, 3136, 3520, 3392, 22016,
1175 20992, 24064, 23040, 17920, 16896, 19968, 18944, 30208, 29184, 32256, 31232, 26112, 25088, 28160, 27136, 11008,
1176 10496, 12032, 11520, 8960, 8448, 9984, 9472, 15104, 14592, 16128, 15616, 13056, 12544, 14080, 13568, 344,
1177 328, 376, 360, 280, 264, 312, 296, 472, 456, 504, 488, 408, 392, 440, 424, 88,
1178 72, 120, 104, 24, 8, 56, 40, 216, 200, 248, 232, 152, 136, 184, 168, 1376,
1179 1312, 1504, 1440, 1120, 1056, 1248, 1184, 1888, 1824, 2016, 1952, 1632, 1568, 1760, 1696, 688,
1180 656, 752, 720, 560, 528, 624, 592, 944, 912, 1008, 976, 816, 784, 880, 848
1182 const Sint16 mulaw_lut[256] = {
1183 -32124, -31100, -30076, -29052, -28028, -27004, -25980, -24956, -23932, -22908, -21884, -20860, -19836, -18812, -17788, -16764, -15996,
1184 -15484, -14972, -14460, -13948, -13436, -12924, -12412, -11900, -11388, -10876, -10364, -9852, -9340, -8828, -8316, -7932,
1185 -7676, -7420, -7164, -6908, -6652, -6396, -6140, -5884, -5628, -5372, -5116, -4860, -4604, -4348, -4092, -3900,
1186 -3772, -3644, -3516, -3388, -3260, -3132, -3004, -2876, -2748, -2620, -2492, -2364, -2236, -2108, -1980, -1884,
1187 -1820, -1756, -1692, -1628, -1564, -1500, -1436, -1372, -1308, -1244, -1180, -1116, -1052, -988, -924, -876,
1188 -844, -812, -780, -748, -716, -684, -652, -620, -588, -556, -524, -492, -460, -428, -396, -372,
1189 -356, -340, -324, -308, -292, -276, -260, -244, -228, -212, -196, -180, -164, -148, -132, -120,
1190 -112, -104, -96, -88, -80, -72, -64, -56, -48, -40, -32, -24, -16, -8, 0, 32124,
1191 31100, 30076, 29052, 28028, 27004, 25980, 24956, 23932, 22908, 21884, 20860, 19836, 18812, 17788, 16764, 15996,
1192 15484, 14972, 14460, 13948, 13436, 12924, 12412, 11900, 11388, 10876, 10364, 9852, 9340, 8828, 8316, 7932,
1193 7676, 7420, 7164, 6908, 6652, 6396, 6140, 5884, 5628, 5372, 5116, 4860, 4604, 4348, 4092, 3900,
1194 3772, 3644, 3516, 3388, 3260, 3132, 3004, 2876, 2748, 2620, 2492, 2364, 2236, 2108, 1980, 1884,
1195 1820, 1756, 1692, 1628, 1564, 1500, 1436, 1372, 1308, 1244, 1180, 1116, 1052, 988, 924, 876,
1196 844, 812, 780, 748, 716, 684, 652, 620, 588, 556, 524, 492, 460, 428, 396, 372,
1197 356, 340, 324, 308, 292, 276, 260, 244, 228, 212, 196, 180, 164, 148, 132, 120,
1198 112, 104, 96, 88, 80, 72, 64, 56, 48, 40, 32, 24, 16, 8, 0
1204 size_t i, sample_count, expanded_len;
1227 expanded_len = sample_count;
1248 #ifdef SDL_WAVE_LAW_LUT 1251 dst[
i] = alaw_lut[src[
i]];
1256 dst[
i] = mulaw_lut[src[
i]];
1264 Sint16 mantissa = exponent & 0xf;
1270 mantissa = mantissa << 4 | 0x8;
1272 mantissa <<= exponent - 1;
1275 dst[
i] = nibble & 0x80 ? mantissa : -mantissa;
1281 Sint16 mantissa = nibble & 0xf;
1283 Sint16 step = 4 << (exponent + 1);
1285 mantissa = (0x80 <<
exponent) + step * mantissa + step / 2 - 132;
1287 dst[
i] = nibble & 0x80 ? -mantissa : mantissa;
1297 *audio_len = (
Uint32)expanded_len;
1333 return SDL_SetError(
"Truncated data chunk in WAVE file");
1350 size_t i, expanded_len, sample_count;
1358 expanded_len = sample_count;
1375 *audio_len = (
Uint32)expanded_len;
1378 for (i = sample_count; i > 0; i--) {
1379 const size_t o = i - 1;
1384 b[2] = ptr[o * 3 + 1];
1385 b[3] = ptr[o * 3 + 2];
1387 ptr[o * 4 + 0] = b[0];
1388 ptr[o * 4 + 1] = b[1];
1389 ptr[o * 4 + 2] = b[2];
1390 ptr[o * 4 + 3] = b[3];
1429 *audio_buf = chunk->
data;
1430 *audio_len = (
Uint32)outputsize;
1447 }
else if (
SDL_strcmp(hint,
"ignore") == 0) {
1449 }
else if (
SDL_strcmp(hint,
"ignorezero") == 0) {
1451 }
else if (
SDL_strcmp(hint,
"maximum") == 0) {
1467 }
else if (
SDL_strcmp(hint,
"strict") == 0) {
1469 }
else if (
SDL_strcmp(hint,
"dropframe") == 0) {
1471 }
else if (
SDL_strcmp(hint,
"dropblock") == 0) {
1487 }
else if (
SDL_strcmp(hint,
"strict") == 0) {
1489 }
else if (
SDL_strcmp(hint,
"ignorezero") == 0) {
1491 }
else if (
SDL_strcmp(hint,
"ignore") == 0) {
1526 }
else if (
SDL_RWread(src, chunkheader, 4, 2) != 2) {
1532 chunk->
position = nextposition + 8;
1542 if (length > chunk->
length) {
1558 if (chunk->
size != length) {
1578 #define WAVE_FORMATTAG_GUID(tag) {(tag) & 0xff, (tag) >> 8, 0, 0, 0, 0, 16, 0, 128, 0, 0, 170, 0, 56, 155, 113} 1606 size_t fmtlen = chunk->
size;
1613 if (fmtsrc ==
NULL) {
1629 return SDL_SetError(
"Missing wBitsPerSample field in WAVE fmt chunk");
1645 if (fmtlen < 40 || format->extsize < 22) {
1647 return SDL_SetError(
"Extensible WAVE header too small");
1671 }
else if (format->
channels > 255) {
1673 return SDL_SetError(
"Number of channels exceeds limit of 255");
1685 return SDL_SetError(
"Invalid fact chunk in WAVE file");
1700 return SDL_SetError(
"Missing fact chunk in WAVE file");
1706 return SDL_SetError(
"Missing wBitsPerSample field in WAVE fmt chunk");
1732 if (
PCM_Init(file, datalength) < 0) {
1738 if (
LAW_Init(file, datalength) < 0) {
1757 const char *errstr =
"Unknown WAVE format GUID: %08x-%04x-%04x-%02x%02x%02x%02x%02x%02x%02x%02x";
1762 return SDL_SetError(errstr, g1, g2, g3, g[8], g[9], g[10], g[11], g[12], g[13], g[14], g[15]);
1775 Uint32 chunkcountlimit = 10000;
1776 char *envchunkcountlimit;
1777 Sint64 RIFFstart, RIFFend, lastchunkpos;
1785 envchunkcountlimit =
SDL_getenv(
"SDL_WAVE_CHUNK_LIMIT");
1786 if (envchunkcountlimit !=
NULL) {
1788 if (
SDL_sscanf(envchunkcountlimit,
"%u", &count) == 1) {
1794 if (RIFFstart < 0) {
1810 return SDL_SetError(
"RIFF form type is not WAVE (not a Waveform file)");
1817 return SDL_SetError(
"Could not find RIFF or WAVE identifiers (not a Waveform file)");
1833 if (RIFFchunk.
length == 0) {
1853 if (chunkcount++ >= chunkcountlimit) {
1854 return SDL_SetError(
"Chunk count in WAVE file exceeds limit of %u", chunkcountlimit);
1865 }
else if (result == -2) {
1866 return SDL_SetError(
"Could not seek to WAVE chunk header");
1875 return SDL_SetError(
"fmt chunk after data chunk in WAVE file");
1911 if (RIFFend < chunk->position + chunk->
length) {
1932 return SDL_SetError(
"Missing data chunk in WAVE file");
1941 return SDL_SetError(
"Could not seek to WAVE chunk data");
1942 }
else if (
SDL_RWread(src, &tmp, 1, 1) != 1) {
1955 return SDL_SetError(
"Could not read data of WAVE fmt chunk");
1961 if (chunk->
length < 14) {
1962 return SDL_SetError(
"Invalid WAVE fmt chunk length (too small)");
1963 }
else if (chunk->
size < 14) {
1964 return SDL_SetError(
"Could not read data of WAVE fmt chunk");
1971 #ifdef SDL_WAVE_DEBUG_LOG_FORMAT 1972 WaveDebugLogFormat(file);
1974 #ifdef SDL_WAVE_DEBUG_DUMP_FORMAT 1987 }
else if (result == -2) {
1988 return SDL_SetError(
"Could not seek data of WAVE data chunk");
1995 return SDL_SetError(
"Could not read data of WAVE data chunk");
2004 if (
PCM_Decode(file, audio_buf, audio_len) < 0) {
2010 if (
LAW_Decode(file, audio_buf, audio_len) < 0) {
2065 if (RIFFlengthknown) {
2084 }
else if (spec ==
NULL) {
2087 }
else if (audio_buf ==
NULL) {
2090 }
else if (audio_len ==
NULL) {
2102 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 IMA_ADPCM_DecodeBlockData(ADPCM_DecoderState *state)
static Sint16 IMA_ADPCM_ProcessNibble(Sint8 *cindex, Sint16 lastsample, Uint8 nybble)
struct ADPCM_DecoderState::@23 output
GLuint GLuint GLsizei count
static int MS_ADPCM_CalculateSampleFrames(WaveFile *file, size_t datalength)
#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)
#define SDL_RWread(ctx, ptr, size, n)
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
#define SDL_RWseek(ctx, offset, whence)
static SDL_bool MultiplySize(size_t *f1, size_t f2)
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)
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)
struct ADPCM_DecoderState::@22 block
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)
struct ADPCM_DecoderState::@21 input
#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)