21 #include "../SDL_internal.h" 62 rogue_feel = (
Uint8 *) format +
sizeof(*format);
63 if (
sizeof(*format) == 16) {
65 rogue_feel +=
sizeof(
Uint16);
68 rogue_feel +=
sizeof(
Uint16);
70 rogue_feel +=
sizeof(
Uint16);
77 rogue_feel +=
sizeof(
Uint16);
79 rogue_feel +=
sizeof(
Uint16);
88 const Sint32 max_audioval = ((1 << (16 - 1)) - 1);
89 const Sint32 min_audioval = -(1 << (16 - 1));
90 const Sint32 adaptive[] = {
91 230, 230, 230, 230, 307, 409, 512, 614,
92 768, 614, 512, 409, 307, 230, 230, 230
96 new_sample = ((state->
iSamp1 * coeff[0]) +
97 (state->
iSamp2 * coeff[1])) / 256;
99 new_sample += state->
iDelta * (nybble - 0x10);
101 new_sample += state->
iDelta * nybble;
103 if (new_sample < min_audioval) {
104 new_sample = min_audioval;
105 }
else if (new_sample > max_audioval) {
106 new_sample = max_audioval;
108 delta = ((
Sint32) state->
iDelta * adaptive[nybble]) / 256;
122 Uint8 *freeable, *encoded, *decoded;
123 Sint32 encoded_len, samplesleft;
130 encoded_len = *audio_len;
131 encoded = *audio_buf;
132 freeable = *audio_buf;
137 if (*audio_buf ==
NULL) {
140 decoded = *audio_buf;
152 state[0]->
iDelta = ((encoded[1] << 8) | encoded[0]);
153 encoded +=
sizeof(
Sint16);
155 state[1]->
iDelta = ((encoded[1] << 8) | encoded[0]);
156 encoded +=
sizeof(
Sint16);
158 state[0]->
iSamp1 = ((encoded[1] << 8) | encoded[0]);
159 encoded +=
sizeof(
Sint16);
161 state[1]->
iSamp1 = ((encoded[1] << 8) | encoded[0]);
162 encoded +=
sizeof(
Sint16);
164 state[0]->
iSamp2 = ((encoded[1] << 8) | encoded[0]);
165 encoded +=
sizeof(
Sint16);
167 state[1]->
iSamp2 = ((encoded[1] << 8) | encoded[0]);
168 encoded +=
sizeof(
Sint16);
174 decoded[0] = state[0]->
iSamp2 & 0xFF;
175 decoded[1] = state[0]->
iSamp2 >> 8;
178 decoded[0] = state[1]->
iSamp2 & 0xFF;
179 decoded[1] = state[1]->
iSamp2 >> 8;
182 decoded[0] = state[0]->
iSamp1 & 0xFF;
183 decoded[1] = state[0]->
iSamp1 >> 8;
186 decoded[0] = state[1]->
iSamp1 & 0xFF;
187 decoded[1] = state[1]->
iSamp1 >> 8;
194 while (samplesleft > 0) {
195 nybble = (*encoded) >> 4;
197 decoded[0] = new_sample & 0xFF;
199 decoded[1] = new_sample & 0xFF;
202 nybble = (*encoded) & 0x0F;
204 decoded[0] = new_sample & 0xFF;
206 decoded[1] = new_sample & 0xFF;
244 rogue_feel = (
Uint8 *) format +
sizeof(*format);
245 if (
sizeof(*format) == 16) {
247 rogue_feel +=
sizeof(
Uint16);
256 const Sint32 max_audioval = ((1 << (16 - 1)) - 1);
257 const Sint32 min_audioval = -(1 << (16 - 1));
258 const int index_table[16] = {
264 const Sint32 step_table[89] = {
265 7, 8, 9, 10, 11, 12, 13, 14, 16, 17, 19, 21, 23, 25, 28, 31,
266 34, 37, 41, 45, 50, 55, 60, 66, 73, 80, 88, 97, 107, 118, 130,
267 143, 157, 173, 190, 209, 230, 253, 279, 307, 337, 371, 408,
268 449, 494, 544, 598, 658, 724, 796, 876, 963, 1060, 1166, 1282,
269 1411, 1552, 1707, 1878, 2066, 2272, 2499, 2749, 3024, 3327,
270 3660, 4026, 4428, 4871, 5358, 5894, 6484, 7132, 7845, 8630,
271 9493, 10442, 11487, 12635, 13899, 15289, 16818, 18500, 20350,
272 22385, 24623, 27086, 29794, 32767
277 if (state->
index > 88) {
279 }
else if (state->
index < 0) {
283 step = step_table[(int)state->
index];
288 delta += (step >> 1);
290 delta += (step >> 2);
296 state->
index += index_table[nybble];
299 if (state->
sample > max_audioval) {
300 state->
sample = max_audioval;
301 }
else if (state->
sample < min_audioval) {
302 state->
sample = min_audioval;
310 int channel,
int numchannels,
317 decoded += (channel * 2);
318 for (i = 0; i < 4; ++
i) {
319 nybble = (*encoded) & 0x0F;
321 decoded[0] = new_sample & 0xFF;
323 decoded[1] = new_sample & 0xFF;
324 decoded += 2 * numchannels;
326 nybble = (*encoded) >> 4;
328 decoded[0] = new_sample & 0xFF;
330 decoded[1] = new_sample & 0xFF;
331 decoded += 2 * numchannels;
341 Uint8 *freeable, *encoded, *decoded;
342 Sint32 encoded_len, samplesleft;
343 unsigned int c, channels;
348 SDL_SetError(
"IMA ADPCM decoder can only handle %u channels",
355 encoded_len = *audio_len;
356 encoded = *audio_buf;
357 freeable = *audio_buf;
362 if (*audio_buf ==
NULL) {
365 decoded = *audio_buf;
370 for (c = 0; c < channels; ++
c) {
372 state[
c].
sample = ((encoded[1] << 8) | encoded[0]);
374 if (state[c].
sample & 0x8000) {
377 state[
c].
index = *encoded++;
379 if (*encoded++ != 0) {
391 while (samplesleft > 0) {
392 for (c = 0; c < channels; ++
c) {
394 c, channels, &state[c]);
398 decoded += (channels * 8 * 2);
410 const double DIVBY8388608 = 0.00000011920928955078125;
411 const Uint32 original_len = *audio_len;
424 *audio_len = expanded_len;
427 src = (ptr + original_len) - 3;
428 dst = ((
Uint32 *) (ptr + expanded_len)) - 1;
429 for (i = 0; i <
samples; i++) {
432 (((
Uint32) src[1]) << 16) |
433 (((
Uint32) src[0]) << 8) )) >> 8;
434 const double scaled = (((double) converted) * DIVBY8388608);
436 *(dst--) = (
Sint32) (scaled * 2147483647.0);
444 static const Uint8 extensible_pcm_guid[16] = { 1, 0, 0, 0, 0, 0, 16, 0, 128, 0, 0, 170, 0, 56, 155, 113 };
445 static const Uint8 extensible_ieee_guid[16] = { 3, 0, 0, 0, 0, 0, 16, 0, 128, 0, 0, 170, 0, 56, 155, 113 };
454 int IEEE_float_encoded, MS_ADPCM_encoded, IMA_ADPCM_encoded;
479 if (wavelen ==
WAVE) {
486 if ((RIFFchunk !=
RIFF) || (WAVEmagic !=
WAVE)) {
491 headerDiff +=
sizeof(
Uint32);
504 headerDiff += lenread + 2 *
sizeof(
Uint32);
514 IEEE_float_encoded = MS_ADPCM_encoded = IMA_ADPCM_encoded = 0;
520 IEEE_float_encoded = 1;
529 MS_ADPCM_encoded = 1;
537 IMA_ADPCM_encoded = 1;
553 IEEE_float_encoded = 1;
570 if (IEEE_float_encoded) {
579 if (MS_ADPCM_encoded || IMA_ADPCM_encoded) {
621 *audio_len = lenread;
622 *audio_buf = chunk.
data;
624 headerDiff += lenread + 2 *
sizeof(
Uint32);
626 headerDiff += 2 *
sizeof(
Uint32);
628 if (MS_ADPCM_encoded) {
634 if (IMA_ADPCM_encoded) {
650 *audio_len &= ~(samplesize - 1);
static int InitIMA_ADPCM(WaveFMT *format)
static void Fill_IMA_ADPCM_block(Uint8 *decoded, Uint8 *encoded, int channel, int numchannels, struct IMA_ADPCM_decodestate *state)
set set set set set set set set set set set set set set set set set set set set *set set set macro pixldst op &r &cond WK op &r &cond WK op &r &cond WK else op &m &cond &ia op &r &cond WK else op &m &cond &ia elseif elseif else error unsupported base if elseif elseif else error unsupported unaligned pixldst unaligned endm macro pixst base base else pixldst base endif endm macro PF ptr
set set set set set set set macro pixldst1 abits if abits op else op endif endm macro pixldst2 abits if abits op else op endif endm macro pixldst4 abits if abits op else op endif endm macro pixldst0 abits op endm macro pixldst3 mem_operand op endm macro pixldst30 mem_operand op endm macro pixldst abits if abits elseif abits elseif abits elseif abits elseif abits pixldst0 abits else pixldst0 abits pixldst0 abits pixldst0 abits pixldst0 abits endif elseif abits else pixldst0 abits pixldst0 abits endif elseif abits else error unsupported bpp *numpix else pixst endif endm macro pixld1_s mem_operand if asr adds SRC_WIDTH_FIXED bpl add asl mov asr adds SRC_WIDTH_FIXED bpl add asl mov asr adds SRC_WIDTH_FIXED bpl add asl mov asr adds SRC_WIDTH_FIXED bpl add asl elseif asr adds SRC_WIDTH_FIXED bpl add asl mov asr adds SRC_WIDTH_FIXED bpl add asl else error unsupported endif endm macro pixld2_s mem_operand if mov asr add asl add asl mov asr sub UNIT_X add asl mov asr add asl add asl mov asr add UNIT_X add asl else pixld1_s mem_operand pixld1_s mem_operand endif endm macro pixld0_s mem_operand if asr adds SRC_WIDTH_FIXED bpl add asl elseif asr adds SRC_WIDTH_FIXED bpl add asl endif endm macro pixld_s_internal mem_operand if mem_operand pixld2_s mem_operand pixdeinterleave basereg elseif mem_operand elseif mem_operand elseif mem_operand elseif mem_operand pixld0_s mem_operand else pixld0_s mem_operand pixld0_s mem_operand pixld0_s mem_operand pixld0_s mem_operand endif elseif mem_operand else pixld0_s mem_operand pixld0_s mem_operand endif elseif mem_operand else error unsupported mem_operand if bpp mem_operand endif endm macro vuzp8 reg2 vuzp d d ®2 endm macro vzip8 reg2 vzip d d ®2 endm macro pixdeinterleave basereg basereg basereg basereg basereg endif endm macro pixinterleave basereg basereg basereg basereg basereg endif endm macro PF boost_increment endif if endif PF tst PF addne PF subne PF cmp ORIG_W if endif if endif if endif PF subge ORIG_W PF subges if endif if endif if endif endif endm macro cache_preload_simple endif if dst_r_bpp pld [DST_R, #(PREFETCH_DISTANCE_SIMPLE *dst_r_bpp/8)] endif if mask_bpp pld if[MASK, #(PREFETCH_DISTANCE_SIMPLE *mask_bpp/8)] endif endif endm macro fetch_mask_pixblock pixld mask_basereg pixblock_size MASK endm macro ensure_destination_ptr_alignment process_pixblock_tail_head if beq irp local skip1(dst_w_bpp<=(lowbit *8)) &&((lowbit *8)<(pixblock_size *dst_w_bpp)) .if lowbit< 16 tst DST_R
void SDL_FreeWAV(Uint8 *audio_buf)
#define SDL_RWread(ctx, ptr, size, n)
static struct IMA_ADPCM_decoder IMA_ADPCM_state
SDL_AudioSpec * SDL_LoadWAV_RW(SDL_RWops *src, int freesrc, SDL_AudioSpec *spec, Uint8 **audio_buf, Uint32 *audio_len)
struct MS_ADPCM_decodestate state[2]
static Sint32 MS_ADPCM_nibble(struct MS_ADPCM_decodestate *state, Uint8 nybble, Sint16 *coeff)
static int MS_ADPCM_decode(Uint8 **audio_buf, Uint32 *audio_len)
#define SDL_RWseek(ctx, offset, whence)
static const Uint8 extensible_ieee_guid[16]
GLint GLint GLsizei GLsizei GLsizei GLint GLenum format
static int IMA_ADPCM_decode(Uint8 **audio_buf, Uint32 *audio_len)
#define SDL_AUDIO_BITSIZE(x)
static int ConvertSint24ToSint32(Uint8 **audio_buf, Uint32 *audio_len)
static const Uint8 extensible_pcm_guid[16]
struct IMA_ADPCM_decodestate state[2]
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 Sint32 IMA_ADPCM_nibble(struct IMA_ADPCM_decodestate *state, Uint8 nybble)
#define SDL_OutOfMemory()
static int InitMS_ADPCM(WaveFMT *format)
#define SDL_arraysize(array)
static int ReadChunk(SDL_RWops *src, Chunk *chunk)
static struct MS_ADPCM_decoder MS_ADPCM_state