comparison adpcm.c @ 3933:60db4273246d

added initial support for format 0x61 ADPCM (sounds good, but still pops)
author melanson
date Tue, 01 Jan 2002 20:04:54 +0000
parents e3caff2daa98
children 6b31db273596
comparison
equal deleted inserted replaced
3932:277187affd9a 3933:60db4273246d
296 } 296 }
297 297
298 return (block_size - (MS_ADPCM_PREAMBLE_SIZE * channels)) * 2; 298 return (block_size - (MS_ADPCM_PREAMBLE_SIZE * channels)) * 2;
299 } 299 }
300 300
301 // note: This decoder assumes the format 0x61 data always comes in
302 // mono flavor
303 int fox61_adpcm_decode_block(unsigned short *output, unsigned char *input)
304 {
305 int i;
306 int out_ptr = 0;
307
308 int predictor;
309 int index;
310 int nibble;
311 int sign;
312 int delta;
313 int diff;
314 int step;
315
316 predictor = output[out_ptr++] = LE_16(&input[0]);
317 index = input[2];
318
319 // iterate through and decode the rest of the bytes
320 for (i = 4; i < FOX61_ADPCM_BLOCK_SIZE; i++)
321 {
322 nibble = (input[i] >> 4) & 0x0F;
323
324 step = adpcm_step[index];
325 sign = nibble & 8;
326 delta = nibble & 7;
327 diff = step >> 3;
328 if (delta & 4) diff += step;
329 if (delta & 2) diff += step >> 1;
330 if (delta & 1) diff += step >> 2;
331 if (sign)
332 predictor -= diff;
333 else
334 predictor += diff;
335 CLAMP_S16(predictor);
336 output[out_ptr++] = predictor;
337 index += adpcm_index[nibble];
338 CLAMP_0_TO_88(index);
339
340 nibble = input[i] & 0x0F;
341
342 step = adpcm_step[index];
343 sign = nibble & 8;
344 delta = nibble & 7;
345 diff = step >> 3;
346 if (delta & 4) diff += step;
347 if (delta & 2) diff += step >> 1;
348 if (delta & 1) diff += step >> 2;
349 if (sign)
350 predictor -= diff;
351 else
352 predictor += diff;
353 CLAMP_S16(predictor);
354 output[out_ptr++] = predictor;
355 index += adpcm_index[nibble];
356 CLAMP_0_TO_88(index);
357 }
358
359 return FOX61_ADPCM_SAMPLES_PER_BLOCK;
360 }
361
362
301 // note: This decoder assumes the format 0x62 data always comes in 363 // note: This decoder assumes the format 0x62 data always comes in
302 // stereo flavor 364 // stereo flavor
303 int fox62_adpcm_decode_block(unsigned short *output, unsigned char *input, 365 int fox62_adpcm_decode_block(unsigned short *output, unsigned char *input,
304 int channels) 366 int channels)
305 { 367 {