Mercurial > mplayer.hg
annotate adpcm.c @ 3848:f99944f9f427
fix for qnx
author | alex |
---|---|
date | Fri, 28 Dec 2001 20:21:32 +0000 |
parents | 8a88ed2473aa |
children | e3caff2daa98 |
rev | line source |
---|---|
3756 | 1 /* |
2 Unified ADPCM Decoder for MPlayer | |
3 | |
3787 | 4 This file is in charge of decoding all of the various ADPCM data |
5 formats that various entities have created. Details about the data | |
6 formats can be found here: | |
7 http://www.pcisys.net/~melanson/codecs/ | |
8 | |
3756 | 9 (C) 2001 Mike Melanson |
10 */ | |
11 | |
12 #include "config.h" | |
13 #include "bswap.h" | |
14 #include "adpcm.h" | |
15 | |
16 #define BE_16(x) (be2me_16(*(unsigned short *)(x))) | |
17 #define BE_32(x) (be2me_32(*(unsigned int *)(x))) | |
18 #define LE_16(x) (le2me_16(*(unsigned short *)(x))) | |
19 #define LE_32(x) (le2me_32(*(unsigned int *)(x))) | |
20 | |
3787 | 21 // pertinent tables |
22 static int adpcm_step[89] = | |
23 { | |
24 7, 8, 9, 10, 11, 12, 13, 14, 16, 17, | |
25 19, 21, 23, 25, 28, 31, 34, 37, 41, 45, | |
26 50, 55, 60, 66, 73, 80, 88, 97, 107, 118, | |
27 130, 143, 157, 173, 190, 209, 230, 253, 279, 307, | |
28 337, 371, 408, 449, 494, 544, 598, 658, 724, 796, | |
29 876, 963, 1060, 1166, 1282, 1411, 1552, 1707, 1878, 2066, | |
30 2272, 2499, 2749, 3024, 3327, 3660, 4026, 4428, 4871, 5358, | |
31 5894, 6484, 7132, 7845, 8630, 9493, 10442, 11487, 12635, 13899, | |
32 15289, 16818, 18500, 20350, 22385, 24623, 27086, 29794, 32767 | |
33 }; | |
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 | 63 static int adpcm_index[16] = |
64 { | |
65 -1, -1, -1, -1, 2, 4, 6, 8, | |
66 -1, -1, -1, -1, 2, 4, 6, 8 | |
67 }; | |
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 | 70 { |
71 1, 3, 5, 7, 9, 11, 13, 15, | |
72 -1, -3, -5, -7, -9, -11, -13, -15 | |
73 }; | |
74 | |
75 static int ms_adapt_table[] = | |
76 { | |
77 230, 230, 230, 230, 307, 409, 512, 614, | |
78 768, 614, 512, 409, 307, 230, 230, 230 | |
79 }; | |
80 | |
81 static int ms_adapt_coeff1[] = | |
82 { | |
83 256, 512, 0, 192, 240, 460, 392 | |
84 }; | |
85 | |
86 static int ms_adapt_coeff2[] = | |
87 { | |
88 0, -256, 0, 64, 0, -208, -232 | |
89 }; | |
90 | |
91 // useful macros | |
3756 | 92 // clamp a number between 0 and 88 |
93 #define CLAMP_0_TO_88(x) if (x < 0) x = 0; else if (x > 88) x = 88; | |
94 // clamp a number within a signed 16-bit range | |
95 #define CLAMP_S16(x) if (x < -32768) x = -32768; \ | |
96 else if (x > 32767) x = 32767; | |
3787 | 97 // clamp a number above 16 |
98 #define CLAMP_ABOVE_16(x) if (x < 16) x = 16; | |
3756 | 99 // sign extend a 16-bit value |
100 #define SE_16BIT(x) if (x & 0x8000) x -= 0x10000; | |
3787 | 101 // sign extend a 4-bit value |
102 #define SE_4BIT(x) if (x & 0x8) x -= 0x10; | |
3756 | 103 |
104 void ima_dvi_decode_nibbles(unsigned short *output, int channels, | |
105 int predictor_l, int index_l, | |
106 int predictor_r, int index_r) | |
107 { | |
108 int step[2]; | |
109 int predictor[2]; | |
110 int index[2]; | |
111 int diff; | |
112 int i; | |
113 int sign; | |
114 int delta; | |
115 int channel_number = 0; | |
116 | |
117 step[0] = adpcm_step[index_l]; | |
118 step[1] = adpcm_step[index_r]; | |
119 predictor[0] = predictor_l; | |
120 predictor[1] = predictor_r; | |
121 index[0] = index_l; | |
122 index[1] = index_r; | |
123 | |
124 for (i = 0; i < IMA_ADPCM_SAMPLES_PER_BLOCK * channels; i++) | |
125 { | |
126 delta = output[i]; | |
127 | |
128 index[channel_number] += adpcm_index[delta]; | |
129 CLAMP_0_TO_88(index[channel_number]); | |
130 | |
131 sign = delta & 8; | |
132 delta = delta & 7; | |
133 | |
134 diff = step[channel_number] >> 3; | |
135 if (delta & 4) diff += step[channel_number]; | |
136 if (delta & 2) diff += step[channel_number] >> 1; | |
137 if (delta & 1) diff += step[channel_number] >> 2; | |
138 | |
139 if (sign) | |
140 predictor[channel_number] -= diff; | |
141 else | |
142 predictor[channel_number] += diff; | |
143 | |
144 CLAMP_S16(predictor[channel_number]); | |
145 output[i] = predictor[channel_number]; | |
146 step[channel_number] = adpcm_step[index[channel_number]]; | |
147 | |
148 // toggle channel | |
149 channel_number ^= channels - 1; | |
150 } | |
151 } | |
152 | |
153 int ima_adpcm_decode_block(unsigned short *output, unsigned char *input, | |
154 int channels) | |
155 { | |
156 int initial_predictor_l = 0; | |
157 int initial_predictor_r = 0; | |
158 int initial_index_l = 0; | |
159 int initial_index_r = 0; | |
160 int i; | |
161 | |
3763 | 162 initial_predictor_l = BE_16(&input[0]); |
3756 | 163 initial_index_l = initial_predictor_l; |
164 | |
165 // mask, sign-extend, and clamp the predictor portion | |
166 initial_predictor_l &= 0xFF80; | |
167 SE_16BIT(initial_predictor_l); | |
168 CLAMP_S16(initial_predictor_l); | |
169 | |
170 // mask and clamp the index portion | |
171 initial_index_l &= 0x7F; | |
172 CLAMP_0_TO_88(initial_index_l); | |
173 | |
174 // handle stereo | |
175 if (channels > 1) | |
176 { | |
3763 | 177 initial_predictor_r = BE_16(&input[IMA_ADPCM_BLOCK_SIZE]); |
3756 | 178 initial_index_r = initial_predictor_r; |
179 | |
180 // mask, sign-extend, and clamp the predictor portion | |
181 initial_predictor_r &= 0xFF80; | |
182 SE_16BIT(initial_predictor_r); | |
183 CLAMP_S16(initial_predictor_r); | |
184 | |
185 // mask and clamp the index portion | |
186 initial_index_r &= 0x7F; | |
187 CLAMP_0_TO_88(initial_index_r); | |
188 } | |
189 | |
190 // break apart all of the nibbles in the block | |
191 if (channels == 1) | |
192 for (i = 0; i < IMA_ADPCM_SAMPLES_PER_BLOCK / 2; i++) | |
193 { | |
3763 | 194 output[i * 2 + 0] = input[2 + i] & 0x0F; |
195 output[i * 2 + 1] = input[2 + i] >> 4; | |
3756 | 196 } |
197 else | |
198 for (i = 0; i < IMA_ADPCM_SAMPLES_PER_BLOCK / 2 * 2; i++) | |
199 { | |
3763 | 200 output[i * 4 + 0] = input[2 + i] & 0x0F; |
201 output[i * 4 + 1] = input[2 + IMA_ADPCM_BLOCK_SIZE + i] & 0x0F; | |
202 output[i * 4 + 2] = input[2 + i] >> 4; | |
203 output[i * 4 + 3] = input[2 + IMA_ADPCM_BLOCK_SIZE + i] >> 4; | |
3756 | 204 } |
205 | |
206 ima_dvi_decode_nibbles(output, channels, | |
207 initial_predictor_l, initial_index_l, | |
208 initial_predictor_r, initial_index_r); | |
209 | |
210 return IMA_ADPCM_SAMPLES_PER_BLOCK * channels; | |
211 } | |
3787 | 212 |
213 int ms_adpcm_decode_block(unsigned short *output, unsigned char *input, | |
214 int channels) | |
215 { | |
216 int current_channel = 0; | |
217 int idelta[2]; | |
218 int sample1[2]; | |
219 int sample2[2]; | |
220 int coeff1[2]; | |
221 int coeff2[2]; | |
222 int stream_ptr = 0; | |
223 int out_ptr = 0; | |
224 int upper_nibble = 1; | |
225 int nibble; | |
226 int snibble; // signed nibble | |
227 int predictor; | |
228 | |
229 // fetch the header information, in stereo if both channels are present | |
230 coeff1[0] = ms_adapt_coeff1[input[stream_ptr]]; | |
231 coeff2[0] = ms_adapt_coeff2[input[stream_ptr]]; | |
232 stream_ptr++; | |
233 if (channels == 2) | |
234 { | |
235 coeff1[1] = ms_adapt_coeff1[input[stream_ptr]]; | |
236 coeff2[1] = ms_adapt_coeff2[input[stream_ptr]]; | |
237 stream_ptr++; | |
238 } | |
239 | |
240 idelta[0] = LE_16(&input[stream_ptr]); | |
241 stream_ptr += 2; | |
242 SE_16BIT(idelta[0]); | |
243 if (channels == 2) | |
244 { | |
245 idelta[1] = LE_16(&input[stream_ptr]); | |
246 stream_ptr += 2; | |
247 SE_16BIT(idelta[1]); | |
248 } | |
249 | |
250 sample1[0] = LE_16(&input[stream_ptr]); | |
251 stream_ptr += 2; | |
252 SE_16BIT(sample1[0]); | |
253 if (channels == 2) | |
254 { | |
255 sample1[1] = LE_16(&input[stream_ptr]); | |
256 stream_ptr += 2; | |
257 SE_16BIT(sample1[1]); | |
258 } | |
259 | |
260 sample2[0] = LE_16(&input[stream_ptr]); | |
261 stream_ptr += 2; | |
262 SE_16BIT(sample2[0]); | |
263 if (channels == 2) | |
264 { | |
265 sample2[1] = LE_16(&input[stream_ptr]); | |
266 stream_ptr += 2; | |
267 SE_16BIT(sample2[1]); | |
268 } | |
269 | |
270 while (stream_ptr < MS_ADPCM_BLOCK_SIZE * channels) | |
271 { | |
272 // get the next nibble | |
273 if (upper_nibble) | |
274 nibble = snibble = input[stream_ptr] >> 4; | |
275 else | |
276 nibble = snibble = input[stream_ptr++] & 0x0F; | |
277 upper_nibble ^= 1; | |
278 SE_4BIT(snibble); | |
279 | |
280 predictor = ( | |
281 ((sample1[current_channel] * coeff1[current_channel]) + | |
282 (sample2[current_channel] * coeff2[current_channel])) / 256) + | |
283 (snibble * idelta[current_channel]); | |
284 CLAMP_S16(predictor); | |
285 sample2[current_channel] = sample1[current_channel]; | |
286 sample1[current_channel] = predictor; | |
287 output[out_ptr++] = predictor; | |
288 | |
289 // compute the next adaptive scale factor (a.k.a. the variable idelta) | |
290 idelta[current_channel] = | |
291 (ms_adapt_table[nibble] * idelta[current_channel]) / 256; | |
292 CLAMP_ABOVE_16(idelta[current_channel]); | |
293 | |
294 // toggle the channel | |
295 current_channel ^= channels - 1; | |
296 } | |
297 | |
298 return MS_ADPCM_SAMPLES_PER_BLOCK * channels; | |
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 } |