annotate adpcm.c @ 3907:6312aa265429

pass accel flags to a52_resample_init
author arpi
date Sun, 30 Dec 2001 20:42:49 +0000
parents e3caff2daa98
children 60db4273246d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3756
734d0c0a8ab0 Initial support for unified ADPCM decoder
melanson
parents:
diff changeset
1 /*
734d0c0a8ab0 Initial support for unified ADPCM decoder
melanson
parents:
diff changeset
2 Unified ADPCM Decoder for MPlayer
734d0c0a8ab0 Initial support for unified ADPCM decoder
melanson
parents:
diff changeset
3
3787
55603340d1b2 implemented open source MS ADPCM decoder
melanson
parents: 3763
diff changeset
4 This file is in charge of decoding all of the various ADPCM data
55603340d1b2 implemented open source MS ADPCM decoder
melanson
parents: 3763
diff changeset
5 formats that various entities have created. Details about the data
55603340d1b2 implemented open source MS ADPCM decoder
melanson
parents: 3763
diff changeset
6 formats can be found here:
55603340d1b2 implemented open source MS ADPCM decoder
melanson
parents: 3763
diff changeset
7 http://www.pcisys.net/~melanson/codecs/
55603340d1b2 implemented open source MS ADPCM decoder
melanson
parents: 3763
diff changeset
8
3756
734d0c0a8ab0 Initial support for unified ADPCM decoder
melanson
parents:
diff changeset
9 (C) 2001 Mike Melanson
734d0c0a8ab0 Initial support for unified ADPCM decoder
melanson
parents:
diff changeset
10 */
734d0c0a8ab0 Initial support for unified ADPCM decoder
melanson
parents:
diff changeset
11
734d0c0a8ab0 Initial support for unified ADPCM decoder
melanson
parents:
diff changeset
12 #include "config.h"
734d0c0a8ab0 Initial support for unified ADPCM decoder
melanson
parents:
diff changeset
13 #include "bswap.h"
734d0c0a8ab0 Initial support for unified ADPCM decoder
melanson
parents:
diff changeset
14 #include "adpcm.h"
734d0c0a8ab0 Initial support for unified ADPCM decoder
melanson
parents:
diff changeset
15
734d0c0a8ab0 Initial support for unified ADPCM decoder
melanson
parents:
diff changeset
16 #define BE_16(x) (be2me_16(*(unsigned short *)(x)))
734d0c0a8ab0 Initial support for unified ADPCM decoder
melanson
parents:
diff changeset
17 #define BE_32(x) (be2me_32(*(unsigned int *)(x)))
734d0c0a8ab0 Initial support for unified ADPCM decoder
melanson
parents:
diff changeset
18 #define LE_16(x) (le2me_16(*(unsigned short *)(x)))
734d0c0a8ab0 Initial support for unified ADPCM decoder
melanson
parents:
diff changeset
19 #define LE_32(x) (le2me_32(*(unsigned int *)(x)))
734d0c0a8ab0 Initial support for unified ADPCM decoder
melanson
parents:
diff changeset
20
3787
55603340d1b2 implemented open source MS ADPCM decoder
melanson
parents: 3763
diff changeset
21 // pertinent tables
55603340d1b2 implemented open source MS ADPCM decoder
melanson
parents: 3763
diff changeset
22 static int adpcm_step[89] =
55603340d1b2 implemented open source MS ADPCM decoder
melanson
parents: 3763
diff changeset
23 {
55603340d1b2 implemented open source MS ADPCM decoder
melanson
parents: 3763
diff changeset
24 7, 8, 9, 10, 11, 12, 13, 14, 16, 17,
55603340d1b2 implemented open source MS ADPCM decoder
melanson
parents: 3763
diff changeset
25 19, 21, 23, 25, 28, 31, 34, 37, 41, 45,
55603340d1b2 implemented open source MS ADPCM decoder
melanson
parents: 3763
diff changeset
26 50, 55, 60, 66, 73, 80, 88, 97, 107, 118,
55603340d1b2 implemented open source MS ADPCM decoder
melanson
parents: 3763
diff changeset
27 130, 143, 157, 173, 190, 209, 230, 253, 279, 307,
55603340d1b2 implemented open source MS ADPCM decoder
melanson
parents: 3763
diff changeset
28 337, 371, 408, 449, 494, 544, 598, 658, 724, 796,
55603340d1b2 implemented open source MS ADPCM decoder
melanson
parents: 3763
diff changeset
29 876, 963, 1060, 1166, 1282, 1411, 1552, 1707, 1878, 2066,
55603340d1b2 implemented open source MS ADPCM decoder
melanson
parents: 3763
diff changeset
30 2272, 2499, 2749, 3024, 3327, 3660, 4026, 4428, 4871, 5358,
55603340d1b2 implemented open source MS ADPCM decoder
melanson
parents: 3763
diff changeset
31 5894, 6484, 7132, 7845, 8630, 9493, 10442, 11487, 12635, 13899,
55603340d1b2 implemented open source MS ADPCM decoder
melanson
parents: 3763
diff changeset
32 15289, 16818, 18500, 20350, 22385, 24623, 27086, 29794, 32767
55603340d1b2 implemented open source MS ADPCM decoder
melanson
parents: 3763
diff changeset
33 };
55603340d1b2 implemented open source MS ADPCM decoder
melanson
parents: 3763
diff changeset
34
3826
8a88ed2473aa added initial, not-yet-functional, support for fox62 audio
melanson
parents: 3787
diff changeset
35 //static int fox62_step[89] =
8a88ed2473aa added initial, not-yet-functional, support for fox62 audio
melanson
parents: 3787
diff changeset
36 static int fox62_step[] =
8a88ed2473aa added initial, not-yet-functional, support for fox62 audio
melanson
parents: 3787
diff changeset
37 {
8a88ed2473aa added initial, not-yet-functional, support for fox62 audio
melanson
parents: 3787
diff changeset
38 0x7, 0x8, 0x9, 0xa,
8a88ed2473aa added initial, not-yet-functional, support for fox62 audio
melanson
parents: 3787
diff changeset
39 0xb, 0xc, 0xd, 0xf,
8a88ed2473aa added initial, not-yet-functional, support for fox62 audio
melanson
parents: 3787
diff changeset
40 0x10, 0x12, 0x13, 0x15,
8a88ed2473aa added initial, not-yet-functional, support for fox62 audio
melanson
parents: 3787
diff changeset
41 0x17, 0x1a, 0x1c, 0x1f,
8a88ed2473aa added initial, not-yet-functional, support for fox62 audio
melanson
parents: 3787
diff changeset
42 0x22, 0x26, 0x29, 0x2e,
8a88ed2473aa added initial, not-yet-functional, support for fox62 audio
melanson
parents: 3787
diff changeset
43 0x32, 0x37, 0x3d, 0x43,
8a88ed2473aa added initial, not-yet-functional, support for fox62 audio
melanson
parents: 3787
diff changeset
44 0x4a, 0x51, 0x59, 0x62,
8a88ed2473aa added initial, not-yet-functional, support for fox62 audio
melanson
parents: 3787
diff changeset
45 0x6c, 0x76, 0x82, 0x8f,
8a88ed2473aa added initial, not-yet-functional, support for fox62 audio
melanson
parents: 3787
diff changeset
46 0x9e, 0xad, 0xbf, 0xd2,
8a88ed2473aa added initial, not-yet-functional, support for fox62 audio
melanson
parents: 3787
diff changeset
47 0xe7, 0xfe, 0x117, 0x133,
8a88ed2473aa added initial, not-yet-functional, support for fox62 audio
melanson
parents: 3787
diff changeset
48 0x152, 0x174, 0x199, 0x1c2,
8a88ed2473aa added initial, not-yet-functional, support for fox62 audio
melanson
parents: 3787
diff changeset
49 0x1ef, 0x220, 0x256, 0x292,
8a88ed2473aa added initial, not-yet-functional, support for fox62 audio
melanson
parents: 3787
diff changeset
50 0x2d4, 0x31d, 0x36c, 0x3c4,
8a88ed2473aa added initial, not-yet-functional, support for fox62 audio
melanson
parents: 3787
diff changeset
51 0x424, 0x48e, 0x503, 0x583,
8a88ed2473aa added initial, not-yet-functional, support for fox62 audio
melanson
parents: 3787
diff changeset
52 0x610, 0x6ac, 0x756, 0x812,
8a88ed2473aa added initial, not-yet-functional, support for fox62 audio
melanson
parents: 3787
diff changeset
53 0x8e1, 0x9c4, 0xabe, 0x8d1,
8a88ed2473aa added initial, not-yet-functional, support for fox62 audio
melanson
parents: 3787
diff changeset
54 0xcff, 0xe4c, 0xfba, 0x114d,
8a88ed2473aa added initial, not-yet-functional, support for fox62 audio
melanson
parents: 3787
diff changeset
55 0x1308, 0x14ef, 0x1707, 0x1954,
8a88ed2473aa added initial, not-yet-functional, support for fox62 audio
melanson
parents: 3787
diff changeset
56 0x1bdd, 0x1ea6, 0x21b7, 0x2516,
8a88ed2473aa added initial, not-yet-functional, support for fox62 audio
melanson
parents: 3787
diff changeset
57 0x28cb, 0x2cdf, 0x315c, 0x364c,
8a88ed2473aa added initial, not-yet-functional, support for fox62 audio
melanson
parents: 3787
diff changeset
58 0x3bba, 0x41b2, 0x4844, 0x4f7e,
8a88ed2473aa added initial, not-yet-functional, support for fox62 audio
melanson
parents: 3787
diff changeset
59 0x5771, 0x6030, 0x69ce, 0x7463,
8a88ed2473aa added initial, not-yet-functional, support for fox62 audio
melanson
parents: 3787
diff changeset
60 0x7FFF
8a88ed2473aa added initial, not-yet-functional, support for fox62 audio
melanson
parents: 3787
diff changeset
61 };
8a88ed2473aa added initial, not-yet-functional, support for fox62 audio
melanson
parents: 3787
diff changeset
62
3787
55603340d1b2 implemented open source MS ADPCM decoder
melanson
parents: 3763
diff changeset
63 static int adpcm_index[16] =
55603340d1b2 implemented open source MS ADPCM decoder
melanson
parents: 3763
diff changeset
64 {
55603340d1b2 implemented open source MS ADPCM decoder
melanson
parents: 3763
diff changeset
65 -1, -1, -1, -1, 2, 4, 6, 8,
55603340d1b2 implemented open source MS ADPCM decoder
melanson
parents: 3763
diff changeset
66 -1, -1, -1, -1, 2, 4, 6, 8
55603340d1b2 implemented open source MS ADPCM decoder
melanson
parents: 3763
diff changeset
67 };
55603340d1b2 implemented open source MS ADPCM decoder
melanson
parents: 3763
diff changeset
68
3826
8a88ed2473aa added initial, not-yet-functional, support for fox62 audio
melanson
parents: 3787
diff changeset
69 static int fox62_extra_table[16] =
3787
55603340d1b2 implemented open source MS ADPCM decoder
melanson
parents: 3763
diff changeset
70 {
55603340d1b2 implemented open source MS ADPCM decoder
melanson
parents: 3763
diff changeset
71 1, 3, 5, 7, 9, 11, 13, 15,
55603340d1b2 implemented open source MS ADPCM decoder
melanson
parents: 3763
diff changeset
72 -1, -3, -5, -7, -9, -11, -13, -15
55603340d1b2 implemented open source MS ADPCM decoder
melanson
parents: 3763
diff changeset
73 };
55603340d1b2 implemented open source MS ADPCM decoder
melanson
parents: 3763
diff changeset
74
55603340d1b2 implemented open source MS ADPCM decoder
melanson
parents: 3763
diff changeset
75 static int ms_adapt_table[] =
55603340d1b2 implemented open source MS ADPCM decoder
melanson
parents: 3763
diff changeset
76 {
55603340d1b2 implemented open source MS ADPCM decoder
melanson
parents: 3763
diff changeset
77 230, 230, 230, 230, 307, 409, 512, 614,
55603340d1b2 implemented open source MS ADPCM decoder
melanson
parents: 3763
diff changeset
78 768, 614, 512, 409, 307, 230, 230, 230
55603340d1b2 implemented open source MS ADPCM decoder
melanson
parents: 3763
diff changeset
79 };
55603340d1b2 implemented open source MS ADPCM decoder
melanson
parents: 3763
diff changeset
80
55603340d1b2 implemented open source MS ADPCM decoder
melanson
parents: 3763
diff changeset
81 static int ms_adapt_coeff1[] =
55603340d1b2 implemented open source MS ADPCM decoder
melanson
parents: 3763
diff changeset
82 {
55603340d1b2 implemented open source MS ADPCM decoder
melanson
parents: 3763
diff changeset
83 256, 512, 0, 192, 240, 460, 392
55603340d1b2 implemented open source MS ADPCM decoder
melanson
parents: 3763
diff changeset
84 };
55603340d1b2 implemented open source MS ADPCM decoder
melanson
parents: 3763
diff changeset
85
55603340d1b2 implemented open source MS ADPCM decoder
melanson
parents: 3763
diff changeset
86 static int ms_adapt_coeff2[] =
55603340d1b2 implemented open source MS ADPCM decoder
melanson
parents: 3763
diff changeset
87 {
55603340d1b2 implemented open source MS ADPCM decoder
melanson
parents: 3763
diff changeset
88 0, -256, 0, 64, 0, -208, -232
55603340d1b2 implemented open source MS ADPCM decoder
melanson
parents: 3763
diff changeset
89 };
55603340d1b2 implemented open source MS ADPCM decoder
melanson
parents: 3763
diff changeset
90
55603340d1b2 implemented open source MS ADPCM decoder
melanson
parents: 3763
diff changeset
91 // useful macros
3756
734d0c0a8ab0 Initial support for unified ADPCM decoder
melanson
parents:
diff changeset
92 // clamp a number between 0 and 88
734d0c0a8ab0 Initial support for unified ADPCM decoder
melanson
parents:
diff changeset
93 #define CLAMP_0_TO_88(x) if (x < 0) x = 0; else if (x > 88) x = 88;
734d0c0a8ab0 Initial support for unified ADPCM decoder
melanson
parents:
diff changeset
94 // clamp a number within a signed 16-bit range
734d0c0a8ab0 Initial support for unified ADPCM decoder
melanson
parents:
diff changeset
95 #define CLAMP_S16(x) if (x < -32768) x = -32768; \
734d0c0a8ab0 Initial support for unified ADPCM decoder
melanson
parents:
diff changeset
96 else if (x > 32767) x = 32767;
3787
55603340d1b2 implemented open source MS ADPCM decoder
melanson
parents: 3763
diff changeset
97 // clamp a number above 16
55603340d1b2 implemented open source MS ADPCM decoder
melanson
parents: 3763
diff changeset
98 #define CLAMP_ABOVE_16(x) if (x < 16) x = 16;
3756
734d0c0a8ab0 Initial support for unified ADPCM decoder
melanson
parents:
diff changeset
99 // sign extend a 16-bit value
734d0c0a8ab0 Initial support for unified ADPCM decoder
melanson
parents:
diff changeset
100 #define SE_16BIT(x) if (x & 0x8000) x -= 0x10000;
3787
55603340d1b2 implemented open source MS ADPCM decoder
melanson
parents: 3763
diff changeset
101 // sign extend a 4-bit value
55603340d1b2 implemented open source MS ADPCM decoder
melanson
parents: 3763
diff changeset
102 #define SE_4BIT(x) if (x & 0x8) x -= 0x10;
3756
734d0c0a8ab0 Initial support for unified ADPCM decoder
melanson
parents:
diff changeset
103
734d0c0a8ab0 Initial support for unified ADPCM decoder
melanson
parents:
diff changeset
104 void ima_dvi_decode_nibbles(unsigned short *output, int channels,
734d0c0a8ab0 Initial support for unified ADPCM decoder
melanson
parents:
diff changeset
105 int predictor_l, int index_l,
734d0c0a8ab0 Initial support for unified ADPCM decoder
melanson
parents:
diff changeset
106 int predictor_r, int index_r)
734d0c0a8ab0 Initial support for unified ADPCM decoder
melanson
parents:
diff changeset
107 {
734d0c0a8ab0 Initial support for unified ADPCM decoder
melanson
parents:
diff changeset
108 int step[2];
734d0c0a8ab0 Initial support for unified ADPCM decoder
melanson
parents:
diff changeset
109 int predictor[2];
734d0c0a8ab0 Initial support for unified ADPCM decoder
melanson
parents:
diff changeset
110 int index[2];
734d0c0a8ab0 Initial support for unified ADPCM decoder
melanson
parents:
diff changeset
111 int diff;
734d0c0a8ab0 Initial support for unified ADPCM decoder
melanson
parents:
diff changeset
112 int i;
734d0c0a8ab0 Initial support for unified ADPCM decoder
melanson
parents:
diff changeset
113 int sign;
734d0c0a8ab0 Initial support for unified ADPCM decoder
melanson
parents:
diff changeset
114 int delta;
734d0c0a8ab0 Initial support for unified ADPCM decoder
melanson
parents:
diff changeset
115 int channel_number = 0;
734d0c0a8ab0 Initial support for unified ADPCM decoder
melanson
parents:
diff changeset
116
734d0c0a8ab0 Initial support for unified ADPCM decoder
melanson
parents:
diff changeset
117 step[0] = adpcm_step[index_l];
734d0c0a8ab0 Initial support for unified ADPCM decoder
melanson
parents:
diff changeset
118 step[1] = adpcm_step[index_r];
734d0c0a8ab0 Initial support for unified ADPCM decoder
melanson
parents:
diff changeset
119 predictor[0] = predictor_l;
734d0c0a8ab0 Initial support for unified ADPCM decoder
melanson
parents:
diff changeset
120 predictor[1] = predictor_r;
734d0c0a8ab0 Initial support for unified ADPCM decoder
melanson
parents:
diff changeset
121 index[0] = index_l;
734d0c0a8ab0 Initial support for unified ADPCM decoder
melanson
parents:
diff changeset
122 index[1] = index_r;
734d0c0a8ab0 Initial support for unified ADPCM decoder
melanson
parents:
diff changeset
123
734d0c0a8ab0 Initial support for unified ADPCM decoder
melanson
parents:
diff changeset
124 for (i = 0; i < IMA_ADPCM_SAMPLES_PER_BLOCK * channels; i++)
734d0c0a8ab0 Initial support for unified ADPCM decoder
melanson
parents:
diff changeset
125 {
734d0c0a8ab0 Initial support for unified ADPCM decoder
melanson
parents:
diff changeset
126 delta = output[i];
734d0c0a8ab0 Initial support for unified ADPCM decoder
melanson
parents:
diff changeset
127
734d0c0a8ab0 Initial support for unified ADPCM decoder
melanson
parents:
diff changeset
128 index[channel_number] += adpcm_index[delta];
734d0c0a8ab0 Initial support for unified ADPCM decoder
melanson
parents:
diff changeset
129 CLAMP_0_TO_88(index[channel_number]);
734d0c0a8ab0 Initial support for unified ADPCM decoder
melanson
parents:
diff changeset
130
734d0c0a8ab0 Initial support for unified ADPCM decoder
melanson
parents:
diff changeset
131 sign = delta & 8;
734d0c0a8ab0 Initial support for unified ADPCM decoder
melanson
parents:
diff changeset
132 delta = delta & 7;
734d0c0a8ab0 Initial support for unified ADPCM decoder
melanson
parents:
diff changeset
133
734d0c0a8ab0 Initial support for unified ADPCM decoder
melanson
parents:
diff changeset
134 diff = step[channel_number] >> 3;
734d0c0a8ab0 Initial support for unified ADPCM decoder
melanson
parents:
diff changeset
135 if (delta & 4) diff += step[channel_number];
734d0c0a8ab0 Initial support for unified ADPCM decoder
melanson
parents:
diff changeset
136 if (delta & 2) diff += step[channel_number] >> 1;
734d0c0a8ab0 Initial support for unified ADPCM decoder
melanson
parents:
diff changeset
137 if (delta & 1) diff += step[channel_number] >> 2;
734d0c0a8ab0 Initial support for unified ADPCM decoder
melanson
parents:
diff changeset
138
734d0c0a8ab0 Initial support for unified ADPCM decoder
melanson
parents:
diff changeset
139 if (sign)
734d0c0a8ab0 Initial support for unified ADPCM decoder
melanson
parents:
diff changeset
140 predictor[channel_number] -= diff;
734d0c0a8ab0 Initial support for unified ADPCM decoder
melanson
parents:
diff changeset
141 else
734d0c0a8ab0 Initial support for unified ADPCM decoder
melanson
parents:
diff changeset
142 predictor[channel_number] += diff;
734d0c0a8ab0 Initial support for unified ADPCM decoder
melanson
parents:
diff changeset
143
734d0c0a8ab0 Initial support for unified ADPCM decoder
melanson
parents:
diff changeset
144 CLAMP_S16(predictor[channel_number]);
734d0c0a8ab0 Initial support for unified ADPCM decoder
melanson
parents:
diff changeset
145 output[i] = predictor[channel_number];
734d0c0a8ab0 Initial support for unified ADPCM decoder
melanson
parents:
diff changeset
146 step[channel_number] = adpcm_step[index[channel_number]];
734d0c0a8ab0 Initial support for unified ADPCM decoder
melanson
parents:
diff changeset
147
734d0c0a8ab0 Initial support for unified ADPCM decoder
melanson
parents:
diff changeset
148 // toggle channel
734d0c0a8ab0 Initial support for unified ADPCM decoder
melanson
parents:
diff changeset
149 channel_number ^= channels - 1;
734d0c0a8ab0 Initial support for unified ADPCM decoder
melanson
parents:
diff changeset
150 }
734d0c0a8ab0 Initial support for unified ADPCM decoder
melanson
parents:
diff changeset
151 }
734d0c0a8ab0 Initial support for unified ADPCM decoder
melanson
parents:
diff changeset
152
734d0c0a8ab0 Initial support for unified ADPCM decoder
melanson
parents:
diff changeset
153 int ima_adpcm_decode_block(unsigned short *output, unsigned char *input,
734d0c0a8ab0 Initial support for unified ADPCM decoder
melanson
parents:
diff changeset
154 int channels)
734d0c0a8ab0 Initial support for unified ADPCM decoder
melanson
parents:
diff changeset
155 {
734d0c0a8ab0 Initial support for unified ADPCM decoder
melanson
parents:
diff changeset
156 int initial_predictor_l = 0;
734d0c0a8ab0 Initial support for unified ADPCM decoder
melanson
parents:
diff changeset
157 int initial_predictor_r = 0;
734d0c0a8ab0 Initial support for unified ADPCM decoder
melanson
parents:
diff changeset
158 int initial_index_l = 0;
734d0c0a8ab0 Initial support for unified ADPCM decoder
melanson
parents:
diff changeset
159 int initial_index_r = 0;
734d0c0a8ab0 Initial support for unified ADPCM decoder
melanson
parents:
diff changeset
160 int i;
734d0c0a8ab0 Initial support for unified ADPCM decoder
melanson
parents:
diff changeset
161
3763
81d84039dd17 fixed stereo IMA4 decoding
melanson
parents: 3756
diff changeset
162 initial_predictor_l = BE_16(&input[0]);
3756
734d0c0a8ab0 Initial support for unified ADPCM decoder
melanson
parents:
diff changeset
163 initial_index_l = initial_predictor_l;
734d0c0a8ab0 Initial support for unified ADPCM decoder
melanson
parents:
diff changeset
164
734d0c0a8ab0 Initial support for unified ADPCM decoder
melanson
parents:
diff changeset
165 // mask, sign-extend, and clamp the predictor portion
734d0c0a8ab0 Initial support for unified ADPCM decoder
melanson
parents:
diff changeset
166 initial_predictor_l &= 0xFF80;
734d0c0a8ab0 Initial support for unified ADPCM decoder
melanson
parents:
diff changeset
167 SE_16BIT(initial_predictor_l);
734d0c0a8ab0 Initial support for unified ADPCM decoder
melanson
parents:
diff changeset
168 CLAMP_S16(initial_predictor_l);
734d0c0a8ab0 Initial support for unified ADPCM decoder
melanson
parents:
diff changeset
169
734d0c0a8ab0 Initial support for unified ADPCM decoder
melanson
parents:
diff changeset
170 // mask and clamp the index portion
734d0c0a8ab0 Initial support for unified ADPCM decoder
melanson
parents:
diff changeset
171 initial_index_l &= 0x7F;
734d0c0a8ab0 Initial support for unified ADPCM decoder
melanson
parents:
diff changeset
172 CLAMP_0_TO_88(initial_index_l);
734d0c0a8ab0 Initial support for unified ADPCM decoder
melanson
parents:
diff changeset
173
734d0c0a8ab0 Initial support for unified ADPCM decoder
melanson
parents:
diff changeset
174 // handle stereo
734d0c0a8ab0 Initial support for unified ADPCM decoder
melanson
parents:
diff changeset
175 if (channels > 1)
734d0c0a8ab0 Initial support for unified ADPCM decoder
melanson
parents:
diff changeset
176 {
3763
81d84039dd17 fixed stereo IMA4 decoding
melanson
parents: 3756
diff changeset
177 initial_predictor_r = BE_16(&input[IMA_ADPCM_BLOCK_SIZE]);
3756
734d0c0a8ab0 Initial support for unified ADPCM decoder
melanson
parents:
diff changeset
178 initial_index_r = initial_predictor_r;
734d0c0a8ab0 Initial support for unified ADPCM decoder
melanson
parents:
diff changeset
179
734d0c0a8ab0 Initial support for unified ADPCM decoder
melanson
parents:
diff changeset
180 // mask, sign-extend, and clamp the predictor portion
734d0c0a8ab0 Initial support for unified ADPCM decoder
melanson
parents:
diff changeset
181 initial_predictor_r &= 0xFF80;
734d0c0a8ab0 Initial support for unified ADPCM decoder
melanson
parents:
diff changeset
182 SE_16BIT(initial_predictor_r);
734d0c0a8ab0 Initial support for unified ADPCM decoder
melanson
parents:
diff changeset
183 CLAMP_S16(initial_predictor_r);
734d0c0a8ab0 Initial support for unified ADPCM decoder
melanson
parents:
diff changeset
184
734d0c0a8ab0 Initial support for unified ADPCM decoder
melanson
parents:
diff changeset
185 // mask and clamp the index portion
734d0c0a8ab0 Initial support for unified ADPCM decoder
melanson
parents:
diff changeset
186 initial_index_r &= 0x7F;
734d0c0a8ab0 Initial support for unified ADPCM decoder
melanson
parents:
diff changeset
187 CLAMP_0_TO_88(initial_index_r);
734d0c0a8ab0 Initial support for unified ADPCM decoder
melanson
parents:
diff changeset
188 }
734d0c0a8ab0 Initial support for unified ADPCM decoder
melanson
parents:
diff changeset
189
734d0c0a8ab0 Initial support for unified ADPCM decoder
melanson
parents:
diff changeset
190 // break apart all of the nibbles in the block
734d0c0a8ab0 Initial support for unified ADPCM decoder
melanson
parents:
diff changeset
191 if (channels == 1)
734d0c0a8ab0 Initial support for unified ADPCM decoder
melanson
parents:
diff changeset
192 for (i = 0; i < IMA_ADPCM_SAMPLES_PER_BLOCK / 2; i++)
734d0c0a8ab0 Initial support for unified ADPCM decoder
melanson
parents:
diff changeset
193 {
3763
81d84039dd17 fixed stereo IMA4 decoding
melanson
parents: 3756
diff changeset
194 output[i * 2 + 0] = input[2 + i] & 0x0F;
81d84039dd17 fixed stereo IMA4 decoding
melanson
parents: 3756
diff changeset
195 output[i * 2 + 1] = input[2 + i] >> 4;
3756
734d0c0a8ab0 Initial support for unified ADPCM decoder
melanson
parents:
diff changeset
196 }
734d0c0a8ab0 Initial support for unified ADPCM decoder
melanson
parents:
diff changeset
197 else
734d0c0a8ab0 Initial support for unified ADPCM decoder
melanson
parents:
diff changeset
198 for (i = 0; i < IMA_ADPCM_SAMPLES_PER_BLOCK / 2 * 2; i++)
734d0c0a8ab0 Initial support for unified ADPCM decoder
melanson
parents:
diff changeset
199 {
3763
81d84039dd17 fixed stereo IMA4 decoding
melanson
parents: 3756
diff changeset
200 output[i * 4 + 0] = input[2 + i] & 0x0F;
81d84039dd17 fixed stereo IMA4 decoding
melanson
parents: 3756
diff changeset
201 output[i * 4 + 1] = input[2 + IMA_ADPCM_BLOCK_SIZE + i] & 0x0F;
81d84039dd17 fixed stereo IMA4 decoding
melanson
parents: 3756
diff changeset
202 output[i * 4 + 2] = input[2 + i] >> 4;
81d84039dd17 fixed stereo IMA4 decoding
melanson
parents: 3756
diff changeset
203 output[i * 4 + 3] = input[2 + IMA_ADPCM_BLOCK_SIZE + i] >> 4;
3756
734d0c0a8ab0 Initial support for unified ADPCM decoder
melanson
parents:
diff changeset
204 }
734d0c0a8ab0 Initial support for unified ADPCM decoder
melanson
parents:
diff changeset
205
734d0c0a8ab0 Initial support for unified ADPCM decoder
melanson
parents:
diff changeset
206 ima_dvi_decode_nibbles(output, channels,
734d0c0a8ab0 Initial support for unified ADPCM decoder
melanson
parents:
diff changeset
207 initial_predictor_l, initial_index_l,
734d0c0a8ab0 Initial support for unified ADPCM decoder
melanson
parents:
diff changeset
208 initial_predictor_r, initial_index_r);
734d0c0a8ab0 Initial support for unified ADPCM decoder
melanson
parents:
diff changeset
209
734d0c0a8ab0 Initial support for unified ADPCM decoder
melanson
parents:
diff changeset
210 return IMA_ADPCM_SAMPLES_PER_BLOCK * channels;
734d0c0a8ab0 Initial support for unified ADPCM decoder
melanson
parents:
diff changeset
211 }
3787
55603340d1b2 implemented open source MS ADPCM decoder
melanson
parents: 3763
diff changeset
212
55603340d1b2 implemented open source MS ADPCM decoder
melanson
parents: 3763
diff changeset
213 int ms_adpcm_decode_block(unsigned short *output, unsigned char *input,
3875
e3caff2daa98 fixed stereo MS ADPCM decoder and reinstated opensource decoder as the
melanson
parents: 3826
diff changeset
214 int channels, int block_size)
3787
55603340d1b2 implemented open source MS ADPCM decoder
melanson
parents: 3763
diff changeset
215 {
55603340d1b2 implemented open source MS ADPCM decoder
melanson
parents: 3763
diff changeset
216 int current_channel = 0;
55603340d1b2 implemented open source MS ADPCM decoder
melanson
parents: 3763
diff changeset
217 int idelta[2];
55603340d1b2 implemented open source MS ADPCM decoder
melanson
parents: 3763
diff changeset
218 int sample1[2];
55603340d1b2 implemented open source MS ADPCM decoder
melanson
parents: 3763
diff changeset
219 int sample2[2];
55603340d1b2 implemented open source MS ADPCM decoder
melanson
parents: 3763
diff changeset
220 int coeff1[2];
55603340d1b2 implemented open source MS ADPCM decoder
melanson
parents: 3763
diff changeset
221 int coeff2[2];
55603340d1b2 implemented open source MS ADPCM decoder
melanson
parents: 3763
diff changeset
222 int stream_ptr = 0;
55603340d1b2 implemented open source MS ADPCM decoder
melanson
parents: 3763
diff changeset
223 int out_ptr = 0;
55603340d1b2 implemented open source MS ADPCM decoder
melanson
parents: 3763
diff changeset
224 int upper_nibble = 1;
55603340d1b2 implemented open source MS ADPCM decoder
melanson
parents: 3763
diff changeset
225 int nibble;
55603340d1b2 implemented open source MS ADPCM decoder
melanson
parents: 3763
diff changeset
226 int snibble; // signed nibble
55603340d1b2 implemented open source MS ADPCM decoder
melanson
parents: 3763
diff changeset
227 int predictor;
55603340d1b2 implemented open source MS ADPCM decoder
melanson
parents: 3763
diff changeset
228
55603340d1b2 implemented open source MS ADPCM decoder
melanson
parents: 3763
diff changeset
229 // fetch the header information, in stereo if both channels are present
55603340d1b2 implemented open source MS ADPCM decoder
melanson
parents: 3763
diff changeset
230 coeff1[0] = ms_adapt_coeff1[input[stream_ptr]];
55603340d1b2 implemented open source MS ADPCM decoder
melanson
parents: 3763
diff changeset
231 coeff2[0] = ms_adapt_coeff2[input[stream_ptr]];
55603340d1b2 implemented open source MS ADPCM decoder
melanson
parents: 3763
diff changeset
232 stream_ptr++;
55603340d1b2 implemented open source MS ADPCM decoder
melanson
parents: 3763
diff changeset
233 if (channels == 2)
55603340d1b2 implemented open source MS ADPCM decoder
melanson
parents: 3763
diff changeset
234 {
55603340d1b2 implemented open source MS ADPCM decoder
melanson
parents: 3763
diff changeset
235 coeff1[1] = ms_adapt_coeff1[input[stream_ptr]];
55603340d1b2 implemented open source MS ADPCM decoder
melanson
parents: 3763
diff changeset
236 coeff2[1] = ms_adapt_coeff2[input[stream_ptr]];
55603340d1b2 implemented open source MS ADPCM decoder
melanson
parents: 3763
diff changeset
237 stream_ptr++;
55603340d1b2 implemented open source MS ADPCM decoder
melanson
parents: 3763
diff changeset
238 }
55603340d1b2 implemented open source MS ADPCM decoder
melanson
parents: 3763
diff changeset
239
55603340d1b2 implemented open source MS ADPCM decoder
melanson
parents: 3763
diff changeset
240 idelta[0] = LE_16(&input[stream_ptr]);
55603340d1b2 implemented open source MS ADPCM decoder
melanson
parents: 3763
diff changeset
241 stream_ptr += 2;
55603340d1b2 implemented open source MS ADPCM decoder
melanson
parents: 3763
diff changeset
242 SE_16BIT(idelta[0]);
55603340d1b2 implemented open source MS ADPCM decoder
melanson
parents: 3763
diff changeset
243 if (channels == 2)
55603340d1b2 implemented open source MS ADPCM decoder
melanson
parents: 3763
diff changeset
244 {
55603340d1b2 implemented open source MS ADPCM decoder
melanson
parents: 3763
diff changeset
245 idelta[1] = LE_16(&input[stream_ptr]);
55603340d1b2 implemented open source MS ADPCM decoder
melanson
parents: 3763
diff changeset
246 stream_ptr += 2;
55603340d1b2 implemented open source MS ADPCM decoder
melanson
parents: 3763
diff changeset
247 SE_16BIT(idelta[1]);
55603340d1b2 implemented open source MS ADPCM decoder
melanson
parents: 3763
diff changeset
248 }
55603340d1b2 implemented open source MS ADPCM decoder
melanson
parents: 3763
diff changeset
249
55603340d1b2 implemented open source MS ADPCM decoder
melanson
parents: 3763
diff changeset
250 sample1[0] = LE_16(&input[stream_ptr]);
55603340d1b2 implemented open source MS ADPCM decoder
melanson
parents: 3763
diff changeset
251 stream_ptr += 2;
55603340d1b2 implemented open source MS ADPCM decoder
melanson
parents: 3763
diff changeset
252 SE_16BIT(sample1[0]);
55603340d1b2 implemented open source MS ADPCM decoder
melanson
parents: 3763
diff changeset
253 if (channels == 2)
55603340d1b2 implemented open source MS ADPCM decoder
melanson
parents: 3763
diff changeset
254 {
55603340d1b2 implemented open source MS ADPCM decoder
melanson
parents: 3763
diff changeset
255 sample1[1] = LE_16(&input[stream_ptr]);
55603340d1b2 implemented open source MS ADPCM decoder
melanson
parents: 3763
diff changeset
256 stream_ptr += 2;
55603340d1b2 implemented open source MS ADPCM decoder
melanson
parents: 3763
diff changeset
257 SE_16BIT(sample1[1]);
55603340d1b2 implemented open source MS ADPCM decoder
melanson
parents: 3763
diff changeset
258 }
55603340d1b2 implemented open source MS ADPCM decoder
melanson
parents: 3763
diff changeset
259
55603340d1b2 implemented open source MS ADPCM decoder
melanson
parents: 3763
diff changeset
260 sample2[0] = LE_16(&input[stream_ptr]);
55603340d1b2 implemented open source MS ADPCM decoder
melanson
parents: 3763
diff changeset
261 stream_ptr += 2;
55603340d1b2 implemented open source MS ADPCM decoder
melanson
parents: 3763
diff changeset
262 SE_16BIT(sample2[0]);
55603340d1b2 implemented open source MS ADPCM decoder
melanson
parents: 3763
diff changeset
263 if (channels == 2)
55603340d1b2 implemented open source MS ADPCM decoder
melanson
parents: 3763
diff changeset
264 {
55603340d1b2 implemented open source MS ADPCM decoder
melanson
parents: 3763
diff changeset
265 sample2[1] = LE_16(&input[stream_ptr]);
55603340d1b2 implemented open source MS ADPCM decoder
melanson
parents: 3763
diff changeset
266 stream_ptr += 2;
55603340d1b2 implemented open source MS ADPCM decoder
melanson
parents: 3763
diff changeset
267 SE_16BIT(sample2[1]);
55603340d1b2 implemented open source MS ADPCM decoder
melanson
parents: 3763
diff changeset
268 }
55603340d1b2 implemented open source MS ADPCM decoder
melanson
parents: 3763
diff changeset
269
3875
e3caff2daa98 fixed stereo MS ADPCM decoder and reinstated opensource decoder as the
melanson
parents: 3826
diff changeset
270 while (stream_ptr < block_size)
3787
55603340d1b2 implemented open source MS ADPCM decoder
melanson
parents: 3763
diff changeset
271 {
55603340d1b2 implemented open source MS ADPCM decoder
melanson
parents: 3763
diff changeset
272 // get the next nibble
55603340d1b2 implemented open source MS ADPCM decoder
melanson
parents: 3763
diff changeset
273 if (upper_nibble)
55603340d1b2 implemented open source MS ADPCM decoder
melanson
parents: 3763
diff changeset
274 nibble = snibble = input[stream_ptr] >> 4;
55603340d1b2 implemented open source MS ADPCM decoder
melanson
parents: 3763
diff changeset
275 else
55603340d1b2 implemented open source MS ADPCM decoder
melanson
parents: 3763
diff changeset
276 nibble = snibble = input[stream_ptr++] & 0x0F;
55603340d1b2 implemented open source MS ADPCM decoder
melanson
parents: 3763
diff changeset
277 upper_nibble ^= 1;
55603340d1b2 implemented open source MS ADPCM decoder
melanson
parents: 3763
diff changeset
278 SE_4BIT(snibble);
55603340d1b2 implemented open source MS ADPCM decoder
melanson
parents: 3763
diff changeset
279
55603340d1b2 implemented open source MS ADPCM decoder
melanson
parents: 3763
diff changeset
280 predictor = (
55603340d1b2 implemented open source MS ADPCM decoder
melanson
parents: 3763
diff changeset
281 ((sample1[current_channel] * coeff1[current_channel]) +
55603340d1b2 implemented open source MS ADPCM decoder
melanson
parents: 3763
diff changeset
282 (sample2[current_channel] * coeff2[current_channel])) / 256) +
55603340d1b2 implemented open source MS ADPCM decoder
melanson
parents: 3763
diff changeset
283 (snibble * idelta[current_channel]);
55603340d1b2 implemented open source MS ADPCM decoder
melanson
parents: 3763
diff changeset
284 CLAMP_S16(predictor);
55603340d1b2 implemented open source MS ADPCM decoder
melanson
parents: 3763
diff changeset
285 sample2[current_channel] = sample1[current_channel];
55603340d1b2 implemented open source MS ADPCM decoder
melanson
parents: 3763
diff changeset
286 sample1[current_channel] = predictor;
55603340d1b2 implemented open source MS ADPCM decoder
melanson
parents: 3763
diff changeset
287 output[out_ptr++] = predictor;
55603340d1b2 implemented open source MS ADPCM decoder
melanson
parents: 3763
diff changeset
288
55603340d1b2 implemented open source MS ADPCM decoder
melanson
parents: 3763
diff changeset
289 // compute the next adaptive scale factor (a.k.a. the variable idelta)
55603340d1b2 implemented open source MS ADPCM decoder
melanson
parents: 3763
diff changeset
290 idelta[current_channel] =
55603340d1b2 implemented open source MS ADPCM decoder
melanson
parents: 3763
diff changeset
291 (ms_adapt_table[nibble] * idelta[current_channel]) / 256;
55603340d1b2 implemented open source MS ADPCM decoder
melanson
parents: 3763
diff changeset
292 CLAMP_ABOVE_16(idelta[current_channel]);
55603340d1b2 implemented open source MS ADPCM decoder
melanson
parents: 3763
diff changeset
293
55603340d1b2 implemented open source MS ADPCM decoder
melanson
parents: 3763
diff changeset
294 // toggle the channel
55603340d1b2 implemented open source MS ADPCM decoder
melanson
parents: 3763
diff changeset
295 current_channel ^= channels - 1;
55603340d1b2 implemented open source MS ADPCM decoder
melanson
parents: 3763
diff changeset
296 }
55603340d1b2 implemented open source MS ADPCM decoder
melanson
parents: 3763
diff changeset
297
3875
e3caff2daa98 fixed stereo MS ADPCM decoder and reinstated opensource decoder as the
melanson
parents: 3826
diff changeset
298 return (block_size - (MS_ADPCM_PREAMBLE_SIZE * channels)) * 2;
3787
55603340d1b2 implemented open source MS ADPCM decoder
melanson
parents: 3763
diff changeset
299 }
3826
8a88ed2473aa added initial, not-yet-functional, support for fox62 audio
melanson
parents: 3787
diff changeset
300
8a88ed2473aa added initial, not-yet-functional, support for fox62 audio
melanson
parents: 3787
diff changeset
301 // note: This decoder assumes the format 0x62 data always comes in
8a88ed2473aa added initial, not-yet-functional, support for fox62 audio
melanson
parents: 3787
diff changeset
302 // stereo flavor
8a88ed2473aa added initial, not-yet-functional, support for fox62 audio
melanson
parents: 3787
diff changeset
303 int fox62_adpcm_decode_block(unsigned short *output, unsigned char *input,
8a88ed2473aa added initial, not-yet-functional, support for fox62 audio
melanson
parents: 3787
diff changeset
304 int channels)
8a88ed2473aa added initial, not-yet-functional, support for fox62 audio
melanson
parents: 3787
diff changeset
305 {
8a88ed2473aa added initial, not-yet-functional, support for fox62 audio
melanson
parents: 3787
diff changeset
306 int predictor_l;
8a88ed2473aa added initial, not-yet-functional, support for fox62 audio
melanson
parents: 3787
diff changeset
307 int predictor_r;
8a88ed2473aa added initial, not-yet-functional, support for fox62 audio
melanson
parents: 3787
diff changeset
308 int index_l;
8a88ed2473aa added initial, not-yet-functional, support for fox62 audio
melanson
parents: 3787
diff changeset
309 int index_r;
8a88ed2473aa added initial, not-yet-functional, support for fox62 audio
melanson
parents: 3787
diff changeset
310 int code_l;
8a88ed2473aa added initial, not-yet-functional, support for fox62 audio
melanson
parents: 3787
diff changeset
311 int code_r;
8a88ed2473aa added initial, not-yet-functional, support for fox62 audio
melanson
parents: 3787
diff changeset
312 int i;
8a88ed2473aa added initial, not-yet-functional, support for fox62 audio
melanson
parents: 3787
diff changeset
313 int out_ptr = 0;
8a88ed2473aa added initial, not-yet-functional, support for fox62 audio
melanson
parents: 3787
diff changeset
314
8a88ed2473aa added initial, not-yet-functional, support for fox62 audio
melanson
parents: 3787
diff changeset
315 int temp1, temp2, edi, eax, edx;
8a88ed2473aa added initial, not-yet-functional, support for fox62 audio
melanson
parents: 3787
diff changeset
316 static int counter = 0;
8a88ed2473aa added initial, not-yet-functional, support for fox62 audio
melanson
parents: 3787
diff changeset
317
8a88ed2473aa added initial, not-yet-functional, support for fox62 audio
melanson
parents: 3787
diff changeset
318 predictor_l = LE_16(&input[10]);
8a88ed2473aa added initial, not-yet-functional, support for fox62 audio
melanson
parents: 3787
diff changeset
319 edi = predictor_r = LE_16(&input[12]);
8a88ed2473aa added initial, not-yet-functional, support for fox62 audio
melanson
parents: 3787
diff changeset
320 SE_16BIT(predictor_l);
8a88ed2473aa added initial, not-yet-functional, support for fox62 audio
melanson
parents: 3787
diff changeset
321 SE_16BIT(predictor_r);
8a88ed2473aa added initial, not-yet-functional, support for fox62 audio
melanson
parents: 3787
diff changeset
322 index_l = input[14];
8a88ed2473aa added initial, not-yet-functional, support for fox62 audio
melanson
parents: 3787
diff changeset
323 index_r = input[15];
8a88ed2473aa added initial, not-yet-functional, support for fox62 audio
melanson
parents: 3787
diff changeset
324
8a88ed2473aa added initial, not-yet-functional, support for fox62 audio
melanson
parents: 3787
diff changeset
325 for (i = 16; i < FOX62_ADPCM_BLOCK_SIZE; i++)
8a88ed2473aa added initial, not-yet-functional, support for fox62 audio
melanson
parents: 3787
diff changeset
326 {
8a88ed2473aa added initial, not-yet-functional, support for fox62 audio
melanson
parents: 3787
diff changeset
327 code_l = input[i] & 0x0F;
8a88ed2473aa added initial, not-yet-functional, support for fox62 audio
melanson
parents: 3787
diff changeset
328 code_r = input[i] >> 4;
8a88ed2473aa added initial, not-yet-functional, support for fox62 audio
melanson
parents: 3787
diff changeset
329 if (counter == 0)
8a88ed2473aa added initial, not-yet-functional, support for fox62 audio
melanson
parents: 3787
diff changeset
330 printf ("code_l = %02X, predictor_l = %04X, index_l = %02X\n",
8a88ed2473aa added initial, not-yet-functional, support for fox62 audio
melanson
parents: 3787
diff changeset
331 code_l, predictor_l, index_l);
8a88ed2473aa added initial, not-yet-functional, support for fox62 audio
melanson
parents: 3787
diff changeset
332 if (counter == 0)
8a88ed2473aa added initial, not-yet-functional, support for fox62 audio
melanson
parents: 3787
diff changeset
333 printf ("code_r = %02X, predictor_r = %04X, index_r = %02X\n",
8a88ed2473aa added initial, not-yet-functional, support for fox62 audio
melanson
parents: 3787
diff changeset
334 code_r, predictor_r, index_r);
8a88ed2473aa added initial, not-yet-functional, support for fox62 audio
melanson
parents: 3787
diff changeset
335
8a88ed2473aa added initial, not-yet-functional, support for fox62 audio
melanson
parents: 3787
diff changeset
336 // left side
8a88ed2473aa added initial, not-yet-functional, support for fox62 audio
melanson
parents: 3787
diff changeset
337 if (counter == 0)
8a88ed2473aa added initial, not-yet-functional, support for fox62 audio
melanson
parents: 3787
diff changeset
338 printf ("step = %04X, extra = %02X\n", fox62_step[index_l], fox62_extra_table[code_l]);
8a88ed2473aa added initial, not-yet-functional, support for fox62 audio
melanson
parents: 3787
diff changeset
339 temp1 = fox62_step[index_l] * fox62_extra_table[code_l];
8a88ed2473aa added initial, not-yet-functional, support for fox62 audio
melanson
parents: 3787
diff changeset
340 if (counter == 0)
8a88ed2473aa added initial, not-yet-functional, support for fox62 audio
melanson
parents: 3787
diff changeset
341 printf ("temp1 (before) = %04X\n", temp1);
8a88ed2473aa added initial, not-yet-functional, support for fox62 audio
melanson
parents: 3787
diff changeset
342 if (temp1 < 0)
8a88ed2473aa added initial, not-yet-functional, support for fox62 audio
melanson
parents: 3787
diff changeset
343 temp1 += 7;
8a88ed2473aa added initial, not-yet-functional, support for fox62 audio
melanson
parents: 3787
diff changeset
344 if (counter == 0)
8a88ed2473aa added initial, not-yet-functional, support for fox62 audio
melanson
parents: 3787
diff changeset
345 printf ("temp1 (after) = %04X\n", temp1);
8a88ed2473aa added initial, not-yet-functional, support for fox62 audio
melanson
parents: 3787
diff changeset
346
8a88ed2473aa added initial, not-yet-functional, support for fox62 audio
melanson
parents: 3787
diff changeset
347 temp2 = predictor_l;
8a88ed2473aa added initial, not-yet-functional, support for fox62 audio
melanson
parents: 3787
diff changeset
348 temp1 /= 8;
8a88ed2473aa added initial, not-yet-functional, support for fox62 audio
melanson
parents: 3787
diff changeset
349 if (counter == 0)
8a88ed2473aa added initial, not-yet-functional, support for fox62 audio
melanson
parents: 3787
diff changeset
350 printf ("temp1 (after div) = %04X\n", temp1);
8a88ed2473aa added initial, not-yet-functional, support for fox62 audio
melanson
parents: 3787
diff changeset
351 temp2 += temp1;
8a88ed2473aa added initial, not-yet-functional, support for fox62 audio
melanson
parents: 3787
diff changeset
352 if (counter == 0)
8a88ed2473aa added initial, not-yet-functional, support for fox62 audio
melanson
parents: 3787
diff changeset
353 printf ("temp2 (predictor_l before clamp) = %04X\n", temp2);
8a88ed2473aa added initial, not-yet-functional, support for fox62 audio
melanson
parents: 3787
diff changeset
354 CLAMP_S16(temp2);
8a88ed2473aa added initial, not-yet-functional, support for fox62 audio
melanson
parents: 3787
diff changeset
355 if (counter == 0)
8a88ed2473aa added initial, not-yet-functional, support for fox62 audio
melanson
parents: 3787
diff changeset
356 printf ("temp2 (predictor_l after clamp) = %04X\n", temp2);
8a88ed2473aa added initial, not-yet-functional, support for fox62 audio
melanson
parents: 3787
diff changeset
357 predictor_l = temp2;
8a88ed2473aa added initial, not-yet-functional, support for fox62 audio
melanson
parents: 3787
diff changeset
358
8a88ed2473aa added initial, not-yet-functional, support for fox62 audio
melanson
parents: 3787
diff changeset
359 index_l += adpcm_index[code_l];
8a88ed2473aa added initial, not-yet-functional, support for fox62 audio
melanson
parents: 3787
diff changeset
360 if (counter == 0)
8a88ed2473aa added initial, not-yet-functional, support for fox62 audio
melanson
parents: 3787
diff changeset
361 printf ("adjusted index_l = %02X\n", index_l);
8a88ed2473aa added initial, not-yet-functional, support for fox62 audio
melanson
parents: 3787
diff changeset
362 CLAMP_0_TO_88(index_l);
8a88ed2473aa added initial, not-yet-functional, support for fox62 audio
melanson
parents: 3787
diff changeset
363
8a88ed2473aa added initial, not-yet-functional, support for fox62 audio
melanson
parents: 3787
diff changeset
364 // right side
8a88ed2473aa added initial, not-yet-functional, support for fox62 audio
melanson
parents: 3787
diff changeset
365 if (counter == 0)
8a88ed2473aa added initial, not-yet-functional, support for fox62 audio
melanson
parents: 3787
diff changeset
366 printf ("step = %04X, extra = %02X\n", fox62_step[index_r], fox62_extra_table[code_r]);
8a88ed2473aa added initial, not-yet-functional, support for fox62 audio
melanson
parents: 3787
diff changeset
367 temp1 = fox62_step[index_r] * fox62_extra_table[code_r];
8a88ed2473aa added initial, not-yet-functional, support for fox62 audio
melanson
parents: 3787
diff changeset
368 if (counter == 0)
8a88ed2473aa added initial, not-yet-functional, support for fox62 audio
melanson
parents: 3787
diff changeset
369 printf ("temp1 (before) = %04X\n", temp1);
8a88ed2473aa added initial, not-yet-functional, support for fox62 audio
melanson
parents: 3787
diff changeset
370 if (temp1 < 0)
8a88ed2473aa added initial, not-yet-functional, support for fox62 audio
melanson
parents: 3787
diff changeset
371 temp1 += 7;
8a88ed2473aa added initial, not-yet-functional, support for fox62 audio
melanson
parents: 3787
diff changeset
372 if (counter == 0)
8a88ed2473aa added initial, not-yet-functional, support for fox62 audio
melanson
parents: 3787
diff changeset
373 printf ("temp1 (after) = %04X\n", temp1);
8a88ed2473aa added initial, not-yet-functional, support for fox62 audio
melanson
parents: 3787
diff changeset
374
8a88ed2473aa added initial, not-yet-functional, support for fox62 audio
melanson
parents: 3787
diff changeset
375 temp2 = predictor_r;
8a88ed2473aa added initial, not-yet-functional, support for fox62 audio
melanson
parents: 3787
diff changeset
376 temp1 /= 8;
8a88ed2473aa added initial, not-yet-functional, support for fox62 audio
melanson
parents: 3787
diff changeset
377 if (counter == 0)
8a88ed2473aa added initial, not-yet-functional, support for fox62 audio
melanson
parents: 3787
diff changeset
378 printf ("temp1 (after div) = %04X\n", temp1);
8a88ed2473aa added initial, not-yet-functional, support for fox62 audio
melanson
parents: 3787
diff changeset
379 temp2 += temp1;
8a88ed2473aa added initial, not-yet-functional, support for fox62 audio
melanson
parents: 3787
diff changeset
380 if (counter == 0)
8a88ed2473aa added initial, not-yet-functional, support for fox62 audio
melanson
parents: 3787
diff changeset
381 printf ("temp2 (predictor_r before clamp) = %04X\n", temp2);
8a88ed2473aa added initial, not-yet-functional, support for fox62 audio
melanson
parents: 3787
diff changeset
382 CLAMP_S16(temp2);
8a88ed2473aa added initial, not-yet-functional, support for fox62 audio
melanson
parents: 3787
diff changeset
383 if (counter == 0)
8a88ed2473aa added initial, not-yet-functional, support for fox62 audio
melanson
parents: 3787
diff changeset
384 printf ("temp2 (predictor_r after clamp) = %04X\n", temp2);
8a88ed2473aa added initial, not-yet-functional, support for fox62 audio
melanson
parents: 3787
diff changeset
385 predictor_r = temp2;
8a88ed2473aa added initial, not-yet-functional, support for fox62 audio
melanson
parents: 3787
diff changeset
386
8a88ed2473aa added initial, not-yet-functional, support for fox62 audio
melanson
parents: 3787
diff changeset
387 index_r += adpcm_index[code_r];
8a88ed2473aa added initial, not-yet-functional, support for fox62 audio
melanson
parents: 3787
diff changeset
388 if (counter == 0)
8a88ed2473aa added initial, not-yet-functional, support for fox62 audio
melanson
parents: 3787
diff changeset
389 printf ("adjusted index_r = %02X\n", index_r);
8a88ed2473aa added initial, not-yet-functional, support for fox62 audio
melanson
parents: 3787
diff changeset
390 CLAMP_0_TO_88(index_r);
8a88ed2473aa added initial, not-yet-functional, support for fox62 audio
melanson
parents: 3787
diff changeset
391
8a88ed2473aa added initial, not-yet-functional, support for fox62 audio
melanson
parents: 3787
diff changeset
392 // do the weird final output process
8a88ed2473aa added initial, not-yet-functional, support for fox62 audio
melanson
parents: 3787
diff changeset
393 edi += predictor_r;
8a88ed2473aa added initial, not-yet-functional, support for fox62 audio
melanson
parents: 3787
diff changeset
394 edi /= 2;
8a88ed2473aa added initial, not-yet-functional, support for fox62 audio
melanson
parents: 3787
diff changeset
395 eax = predictor_l + edi;
8a88ed2473aa added initial, not-yet-functional, support for fox62 audio
melanson
parents: 3787
diff changeset
396 edx = edi * 2;
8a88ed2473aa added initial, not-yet-functional, support for fox62 audio
melanson
parents: 3787
diff changeset
397 if (counter == 0)
8a88ed2473aa added initial, not-yet-functional, support for fox62 audio
melanson
parents: 3787
diff changeset
398 printf ("eax = %08X, edx = %08X, edi = %08X\n", eax, edx, edi);
8a88ed2473aa added initial, not-yet-functional, support for fox62 audio
melanson
parents: 3787
diff changeset
399 output[out_ptr++] = eax;
8a88ed2473aa added initial, not-yet-functional, support for fox62 audio
melanson
parents: 3787
diff changeset
400
8a88ed2473aa added initial, not-yet-functional, support for fox62 audio
melanson
parents: 3787
diff changeset
401 predictor_l = eax;
8a88ed2473aa added initial, not-yet-functional, support for fox62 audio
melanson
parents: 3787
diff changeset
402 eax -= edx;
8a88ed2473aa added initial, not-yet-functional, support for fox62 audio
melanson
parents: 3787
diff changeset
403 if (counter == 0)
8a88ed2473aa added initial, not-yet-functional, support for fox62 audio
melanson
parents: 3787
diff changeset
404 printf ("eax = %08X, edx = %08X, edi = %08X\n", eax, edx, edi);
8a88ed2473aa added initial, not-yet-functional, support for fox62 audio
melanson
parents: 3787
diff changeset
405 // x24 += 4
8a88ed2473aa added initial, not-yet-functional, support for fox62 audio
melanson
parents: 3787
diff changeset
406 output[out_ptr++] = eax;
8a88ed2473aa added initial, not-yet-functional, support for fox62 audio
melanson
parents: 3787
diff changeset
407 predictor_l = eax;
8a88ed2473aa added initial, not-yet-functional, support for fox62 audio
melanson
parents: 3787
diff changeset
408 eax += edi;
8a88ed2473aa added initial, not-yet-functional, support for fox62 audio
melanson
parents: 3787
diff changeset
409 if (counter == 0)
8a88ed2473aa added initial, not-yet-functional, support for fox62 audio
melanson
parents: 3787
diff changeset
410 printf ("eax = %08X, edx = %08X, edi = %08X\n", eax, edx, edi);
8a88ed2473aa added initial, not-yet-functional, support for fox62 audio
melanson
parents: 3787
diff changeset
411 edi = predictor_r;
8a88ed2473aa added initial, not-yet-functional, support for fox62 audio
melanson
parents: 3787
diff changeset
412 if (counter == 0)
8a88ed2473aa added initial, not-yet-functional, support for fox62 audio
melanson
parents: 3787
diff changeset
413 printf ("eax = %08X, edx = %08X, edi = %08X\n", eax, edx, edi);
8a88ed2473aa added initial, not-yet-functional, support for fox62 audio
melanson
parents: 3787
diff changeset
414 predictor_l = eax;
8a88ed2473aa added initial, not-yet-functional, support for fox62 audio
melanson
parents: 3787
diff changeset
415
8a88ed2473aa added initial, not-yet-functional, support for fox62 audio
melanson
parents: 3787
diff changeset
416 if (counter == 0)
8a88ed2473aa added initial, not-yet-functional, support for fox62 audio
melanson
parents: 3787
diff changeset
417 printf ("L-sample = %04X, R-sample = %04X\n",
8a88ed2473aa added initial, not-yet-functional, support for fox62 audio
melanson
parents: 3787
diff changeset
418 output[out_ptr-2], output[out_ptr-1]);
8a88ed2473aa added initial, not-yet-functional, support for fox62 audio
melanson
parents: 3787
diff changeset
419 counter++;
8a88ed2473aa added initial, not-yet-functional, support for fox62 audio
melanson
parents: 3787
diff changeset
420 }
8a88ed2473aa added initial, not-yet-functional, support for fox62 audio
melanson
parents: 3787
diff changeset
421
8a88ed2473aa added initial, not-yet-functional, support for fox62 audio
melanson
parents: 3787
diff changeset
422 return FOX62_ADPCM_SAMPLES_PER_BLOCK * channels;
8a88ed2473aa added initial, not-yet-functional, support for fox62 audio
melanson
parents: 3787
diff changeset
423 }