comparison adpcm.c @ 3826:8a88ed2473aa

added initial, not-yet-functional, support for fox62 audio
author melanson
date Fri, 28 Dec 2001 06:47:15 +0000
parents 55603340d1b2
children e3caff2daa98
comparison
equal deleted inserted replaced
3825:7735c5a87121 3826:8a88ed2473aa
30 2272, 2499, 2749, 3024, 3327, 3660, 4026, 4428, 4871, 5358, 30 2272, 2499, 2749, 3024, 3327, 3660, 4026, 4428, 4871, 5358,
31 5894, 6484, 7132, 7845, 8630, 9493, 10442, 11487, 12635, 13899, 31 5894, 6484, 7132, 7845, 8630, 9493, 10442, 11487, 12635, 13899,
32 15289, 16818, 18500, 20350, 22385, 24623, 27086, 29794, 32767 32 15289, 16818, 18500, 20350, 22385, 24623, 27086, 29794, 32767
33 }; 33 };
34 34
35 //static int fox62_step[89] =
36 static int fox62_step[] =
37 {
38 0x7, 0x8, 0x9, 0xa,
39 0xb, 0xc, 0xd, 0xf,
40 0x10, 0x12, 0x13, 0x15,
41 0x17, 0x1a, 0x1c, 0x1f,
42 0x22, 0x26, 0x29, 0x2e,
43 0x32, 0x37, 0x3d, 0x43,
44 0x4a, 0x51, 0x59, 0x62,
45 0x6c, 0x76, 0x82, 0x8f,
46 0x9e, 0xad, 0xbf, 0xd2,
47 0xe7, 0xfe, 0x117, 0x133,
48 0x152, 0x174, 0x199, 0x1c2,
49 0x1ef, 0x220, 0x256, 0x292,
50 0x2d4, 0x31d, 0x36c, 0x3c4,
51 0x424, 0x48e, 0x503, 0x583,
52 0x610, 0x6ac, 0x756, 0x812,
53 0x8e1, 0x9c4, 0xabe, 0x8d1,
54 0xcff, 0xe4c, 0xfba, 0x114d,
55 0x1308, 0x14ef, 0x1707, 0x1954,
56 0x1bdd, 0x1ea6, 0x21b7, 0x2516,
57 0x28cb, 0x2cdf, 0x315c, 0x364c,
58 0x3bba, 0x41b2, 0x4844, 0x4f7e,
59 0x5771, 0x6030, 0x69ce, 0x7463,
60 0x7FFF
61 };
62
35 static int adpcm_index[16] = 63 static int adpcm_index[16] =
36 { 64 {
37 -1, -1, -1, -1, 2, 4, 6, 8, 65 -1, -1, -1, -1, 2, 4, 6, 8,
38 -1, -1, -1, -1, 2, 4, 6, 8 66 -1, -1, -1, -1, 2, 4, 6, 8
39 }; 67 };
40 68
41 static int format_0x62_table[16] = 69 static int fox62_extra_table[16] =
42 { 70 {
43 1, 3, 5, 7, 9, 11, 13, 15, 71 1, 3, 5, 7, 9, 11, 13, 15,
44 -1, -3, -5, -7, -9, -11, -13, -15 72 -1, -3, -5, -7, -9, -11, -13, -15
45 }; 73 };
46 74
267 current_channel ^= channels - 1; 295 current_channel ^= channels - 1;
268 } 296 }
269 297
270 return MS_ADPCM_SAMPLES_PER_BLOCK * channels; 298 return MS_ADPCM_SAMPLES_PER_BLOCK * channels;
271 } 299 }
300
301 // note: This decoder assumes the format 0x62 data always comes in
302 // stereo flavor
303 int fox62_adpcm_decode_block(unsigned short *output, unsigned char *input,
304 int channels)
305 {
306 int predictor_l;
307 int predictor_r;
308 int index_l;
309 int index_r;
310 int code_l;
311 int code_r;
312 int i;
313 int out_ptr = 0;
314
315 int temp1, temp2, edi, eax, edx;
316 static int counter = 0;
317
318 predictor_l = LE_16(&input[10]);
319 edi = predictor_r = LE_16(&input[12]);
320 SE_16BIT(predictor_l);
321 SE_16BIT(predictor_r);
322 index_l = input[14];
323 index_r = input[15];
324
325 for (i = 16; i < FOX62_ADPCM_BLOCK_SIZE; i++)
326 {
327 code_l = input[i] & 0x0F;
328 code_r = input[i] >> 4;
329 if (counter == 0)
330 printf ("code_l = %02X, predictor_l = %04X, index_l = %02X\n",
331 code_l, predictor_l, index_l);
332 if (counter == 0)
333 printf ("code_r = %02X, predictor_r = %04X, index_r = %02X\n",
334 code_r, predictor_r, index_r);
335
336 // left side
337 if (counter == 0)
338 printf ("step = %04X, extra = %02X\n", fox62_step[index_l], fox62_extra_table[code_l]);
339 temp1 = fox62_step[index_l] * fox62_extra_table[code_l];
340 if (counter == 0)
341 printf ("temp1 (before) = %04X\n", temp1);
342 if (temp1 < 0)
343 temp1 += 7;
344 if (counter == 0)
345 printf ("temp1 (after) = %04X\n", temp1);
346
347 temp2 = predictor_l;
348 temp1 /= 8;
349 if (counter == 0)
350 printf ("temp1 (after div) = %04X\n", temp1);
351 temp2 += temp1;
352 if (counter == 0)
353 printf ("temp2 (predictor_l before clamp) = %04X\n", temp2);
354 CLAMP_S16(temp2);
355 if (counter == 0)
356 printf ("temp2 (predictor_l after clamp) = %04X\n", temp2);
357 predictor_l = temp2;
358
359 index_l += adpcm_index[code_l];
360 if (counter == 0)
361 printf ("adjusted index_l = %02X\n", index_l);
362 CLAMP_0_TO_88(index_l);
363
364 // right side
365 if (counter == 0)
366 printf ("step = %04X, extra = %02X\n", fox62_step[index_r], fox62_extra_table[code_r]);
367 temp1 = fox62_step[index_r] * fox62_extra_table[code_r];
368 if (counter == 0)
369 printf ("temp1 (before) = %04X\n", temp1);
370 if (temp1 < 0)
371 temp1 += 7;
372 if (counter == 0)
373 printf ("temp1 (after) = %04X\n", temp1);
374
375 temp2 = predictor_r;
376 temp1 /= 8;
377 if (counter == 0)
378 printf ("temp1 (after div) = %04X\n", temp1);
379 temp2 += temp1;
380 if (counter == 0)
381 printf ("temp2 (predictor_r before clamp) = %04X\n", temp2);
382 CLAMP_S16(temp2);
383 if (counter == 0)
384 printf ("temp2 (predictor_r after clamp) = %04X\n", temp2);
385 predictor_r = temp2;
386
387 index_r += adpcm_index[code_r];
388 if (counter == 0)
389 printf ("adjusted index_r = %02X\n", index_r);
390 CLAMP_0_TO_88(index_r);
391
392 // do the weird final output process
393 edi += predictor_r;
394 edi /= 2;
395 eax = predictor_l + edi;
396 edx = edi * 2;
397 if (counter == 0)
398 printf ("eax = %08X, edx = %08X, edi = %08X\n", eax, edx, edi);
399 output[out_ptr++] = eax;
400
401 predictor_l = eax;
402 eax -= edx;
403 if (counter == 0)
404 printf ("eax = %08X, edx = %08X, edi = %08X\n", eax, edx, edi);
405 // x24 += 4
406 output[out_ptr++] = eax;
407 predictor_l = eax;
408 eax += edi;
409 if (counter == 0)
410 printf ("eax = %08X, edx = %08X, edi = %08X\n", eax, edx, edi);
411 edi = predictor_r;
412 if (counter == 0)
413 printf ("eax = %08X, edx = %08X, edi = %08X\n", eax, edx, edi);
414 predictor_l = eax;
415
416 if (counter == 0)
417 printf ("L-sample = %04X, R-sample = %04X\n",
418 output[out_ptr-2], output[out_ptr-1]);
419 counter++;
420 }
421
422 return FOX62_ADPCM_SAMPLES_PER_BLOCK * channels;
423 }