diff options
Diffstat (limited to 'apps/codecs/libatrac/atrac3.c')
-rw-r--r-- | apps/codecs/libatrac/atrac3.c | 208 |
1 files changed, 88 insertions, 120 deletions
diff --git a/apps/codecs/libatrac/atrac3.c b/apps/codecs/libatrac/atrac3.c index a800511397..838bbca48a 100644 --- a/apps/codecs/libatrac/atrac3.c +++ b/apps/codecs/libatrac/atrac3.c | |||
@@ -38,7 +38,6 @@ | |||
38 | 38 | ||
39 | #include "avcodec.h" | 39 | #include "avcodec.h" |
40 | #include "bitstream.h" | 40 | #include "bitstream.h" |
41 | #include "dsputil.h" | ||
42 | #include "bytestream.h" | 41 | #include "bytestream.h" |
43 | 42 | ||
44 | #include <stdint.h> | 43 | #include <stdint.h> |
@@ -50,6 +49,10 @@ | |||
50 | 49 | ||
51 | #include "../librm/rm.h" | 50 | #include "../librm/rm.h" |
52 | #include "atrac3data.h" | 51 | #include "atrac3data.h" |
52 | #include "atrac3data_fixed.h" | ||
53 | #include "fixp_math.h" | ||
54 | //#include "fixp_mdct.h" | ||
55 | #include "../lib/mdct2.h" | ||
53 | 56 | ||
54 | #define JOINT_STEREO 0x12 | 57 | #define JOINT_STEREO 0x12 |
55 | #define STEREO 0x2 | 58 | #define STEREO 0x2 |
@@ -70,23 +73,23 @@ typedef struct { | |||
70 | typedef struct { | 73 | typedef struct { |
71 | int pos; | 74 | int pos; |
72 | int numCoefs; | 75 | int numCoefs; |
73 | float coef[8]; | 76 | int32_t coef[8]; |
74 | } tonal_component; | 77 | } tonal_component; |
75 | 78 | ||
76 | typedef struct { | 79 | typedef struct { |
77 | int bandsCoded; | 80 | int bandsCoded; |
78 | int numComponents; | 81 | int numComponents; |
79 | tonal_component components[64]; | 82 | tonal_component components[64]; |
80 | float prevFrame[1024]; | 83 | int32_t prevFrame[1024]; |
81 | int gcBlkSwitch; | 84 | int gcBlkSwitch; |
82 | gain_block gainBlock[2]; | 85 | gain_block gainBlock[2]; |
83 | 86 | ||
84 | DECLARE_ALIGNED_16(float, spectrum[1024]); | 87 | int32_t spectrum[1024] __attribute__((aligned(16))); |
85 | DECLARE_ALIGNED_16(float, IMDCT_buf[1024]); | 88 | int32_t IMDCT_buf[1024] __attribute__((aligned(16))); |
86 | 89 | ||
87 | float delayBuf1[46]; ///<qmf delay buffers | 90 | int32_t delayBuf1[46]; ///<qmf delay buffers |
88 | float delayBuf2[46]; | 91 | int32_t delayBuf2[46]; |
89 | float delayBuf3[46]; | 92 | int32_t delayBuf3[46]; |
90 | } channel_unit; | 93 | } channel_unit; |
91 | 94 | ||
92 | typedef struct { | 95 | typedef struct { |
@@ -114,9 +117,9 @@ typedef struct { | |||
114 | //@} | 117 | //@} |
115 | //@{ | 118 | //@{ |
116 | /** data buffers */ | 119 | /** data buffers */ |
117 | float outSamples[2048]; | 120 | int32_t outSamples[2048]; |
118 | uint8_t* decoded_bytes_buffer; | 121 | uint8_t* decoded_bytes_buffer; |
119 | float tempBuf[1070]; | 122 | int32_t tempBuf[1070]; |
120 | //@} | 123 | //@} |
121 | //@{ | 124 | //@{ |
122 | /** extradata */ | 125 | /** extradata */ |
@@ -127,17 +130,8 @@ typedef struct { | |||
127 | //@} | 130 | //@} |
128 | } ATRAC3Context; | 131 | } ATRAC3Context; |
129 | 132 | ||
130 | static DECLARE_ALIGNED_16(float,mdct_window[512]); | 133 | static int32_t qmf_window[48]; |
131 | static float qmf_window[48]; | ||
132 | static VLC spectral_coeff_tab[7]; | 134 | static VLC spectral_coeff_tab[7]; |
133 | static float SFTable[64]; | ||
134 | static float gain_tab1[16]; | ||
135 | static float gain_tab2[31]; | ||
136 | static MDCTContext mdct_ctx; | ||
137 | static DSPContext dsp; | ||
138 | |||
139 | |||
140 | /* quadrature mirror synthesis filter */ | ||
141 | 135 | ||
142 | /** | 136 | /** |
143 | * Quadrature mirror synthesis filter. | 137 | * Quadrature mirror synthesis filter. |
@@ -149,14 +143,12 @@ static DSPContext dsp; | |||
149 | * @param delayBuf delayBuf buffer | 143 | * @param delayBuf delayBuf buffer |
150 | * @param temp temp buffer | 144 | * @param temp temp buffer |
151 | */ | 145 | */ |
152 | 146 | static void iqmf (int32_t *inlo, int32_t *inhi, unsigned int nIn, int32_t *pOut, int32_t *delayBuf, int32_t *temp) | |
153 | |||
154 | static void iqmf (float *inlo, float *inhi, unsigned int nIn, float *pOut, float *delayBuf, float *temp) | ||
155 | { | 147 | { |
156 | int i, j; | 148 | int i, j; |
157 | float *p1, *p3; | 149 | int32_t *p1, *p3; |
158 | 150 | ||
159 | memcpy(temp, delayBuf, 46*sizeof(float)); | 151 | memcpy(temp, delayBuf, 46*sizeof(int32_t)); |
160 | 152 | ||
161 | p3 = temp + 46; | 153 | p3 = temp + 46; |
162 | 154 | ||
@@ -171,12 +163,12 @@ static void iqmf (float *inlo, float *inhi, unsigned int nIn, float *pOut, float | |||
171 | /* loop2 */ | 163 | /* loop2 */ |
172 | p1 = temp; | 164 | p1 = temp; |
173 | for (j = nIn; j != 0; j--) { | 165 | for (j = nIn; j != 0; j--) { |
174 | float s1 = 0.0; | 166 | int32_t s1 = 0; |
175 | float s2 = 0.0; | 167 | int32_t s2 = 0; |
176 | 168 | ||
177 | for (i = 0; i < 48; i += 2) { | 169 | for (i = 0; i < 48; i += 2) { |
178 | s1 += p1[i] * qmf_window[i]; | 170 | s1 += fixmul31(p1[i], qmf_window[i]); |
179 | s2 += p1[i+1] * qmf_window[i+1]; | 171 | s2 += fixmul31(p1[i+1], qmf_window[i+1]); |
180 | } | 172 | } |
181 | 173 | ||
182 | pOut[0] = s2; | 174 | pOut[0] = s2; |
@@ -187,7 +179,7 @@ static void iqmf (float *inlo, float *inhi, unsigned int nIn, float *pOut, float | |||
187 | } | 179 | } |
188 | 180 | ||
189 | /* Update the delay buffer. */ | 181 | /* Update the delay buffer. */ |
190 | memcpy(delayBuf, temp + nIn*2, 46*sizeof(float)); | 182 | memcpy(delayBuf, temp + (nIn << 1), 46*sizeof(int32_t)); |
191 | } | 183 | } |
192 | 184 | ||
193 | /** | 185 | /** |
@@ -199,10 +191,9 @@ static void iqmf (float *inlo, float *inhi, unsigned int nIn, float *pOut, float | |||
199 | * @param odd_band 1 if the band is an odd band | 191 | * @param odd_band 1 if the band is an odd band |
200 | */ | 192 | */ |
201 | 193 | ||
202 | static void IMLT(float *pInput, float *pOutput, int odd_band) | 194 | static void IMLT(int32_t *pInput, int32_t *pOutput, int odd_band) |
203 | { | 195 | { |
204 | int i; | 196 | int i; |
205 | |||
206 | if (odd_band) { | 197 | if (odd_band) { |
207 | /** | 198 | /** |
208 | * Reverse the odd bands before IMDCT, this is an effect of the QMF transform | 199 | * Reverse the odd bands before IMDCT, this is an effect of the QMF transform |
@@ -214,13 +205,15 @@ static void IMLT(float *pInput, float *pOutput, int odd_band) | |||
214 | */ | 205 | */ |
215 | 206 | ||
216 | for (i=0; i<128; i++) | 207 | for (i=0; i<128; i++) |
217 | FFSWAP(float, pInput[i], pInput[255-i]); | 208 | FFSWAP(int32_t, pInput[i], pInput[255-i]); |
218 | } | 209 | } |
210 | |||
211 | /* Apply the imdct. */ | ||
212 | mdct_backward(512, pInput, pOutput); | ||
219 | 213 | ||
220 | ff_imdct_calc(&mdct_ctx,pOutput,pInput); | 214 | /* Windowing. */ |
221 | 215 | for(i = 0; i<512; i++) | |
222 | /* Perform windowing on the output. */ | 216 | pOutput[i] = fixmul31(pOutput[i], window_lookup[i]); |
223 | dsp.vector_fmul(pOutput,mdct_window,512); | ||
224 | 217 | ||
225 | } | 218 | } |
226 | 219 | ||
@@ -259,30 +252,20 @@ static int decode_bytes(const uint8_t* inbuffer, uint8_t* out, int bytes){ | |||
259 | 252 | ||
260 | 253 | ||
261 | static av_cold void init_atrac3_transforms(ATRAC3Context *q) { | 254 | static av_cold void init_atrac3_transforms(ATRAC3Context *q) { |
262 | float enc_window[256]; | 255 | int32_t s; |
263 | float s; | ||
264 | int i; | 256 | int i; |
265 | 257 | ||
266 | /* Generate the mdct window, for details see | 258 | /* Generate the mdct window, for details see |
267 | * http://wiki.multimedia.cx/index.php?title=RealAudio_atrc#Windows */ | 259 | * http://wiki.multimedia.cx/index.php?title=RealAudio_atrc#Windows */ |
268 | for (i=0 ; i<256; i++) | ||
269 | enc_window[i] = (sin(((i + 0.5) / 256.0 - 0.5) * M_PI) + 1.0) * 0.5; | ||
270 | 260 | ||
271 | if (!mdct_window[0]) | 261 | /* mdct window had been generated and saved as a lookup table in atrac3data_fixed.h */ |
272 | for (i=0 ; i<256; i++) { | ||
273 | mdct_window[i] = enc_window[i]/(enc_window[i]*enc_window[i] + enc_window[255-i]*enc_window[255-i]); | ||
274 | mdct_window[511-i] = mdct_window[i]; | ||
275 | } | ||
276 | 262 | ||
277 | /* Generate the QMF window. */ | 263 | /* Generate the QMF window. */ |
278 | for (i=0 ; i<24; i++) { | 264 | for (i=0 ; i<24; i++) { |
279 | s = qmf_48tap_half[i] * 2.0; | 265 | s = qmf_48tap_half_fix[i] << 1; |
280 | qmf_window[i] = s; | 266 | qmf_window[i] = s; |
281 | qmf_window[47 - i] = s; | 267 | qmf_window[47 - i] = s; |
282 | } | 268 | } |
283 | |||
284 | /* Initialize the MDCT transform. */ | ||
285 | ff_mdct_init(&mdct_ctx, 9, 1); | ||
286 | } | 269 | } |
287 | 270 | ||
288 | /** | 271 | /** |
@@ -367,12 +350,12 @@ static void readQuantSpectralCoeffs (GetBitContext *gb, int selector, int coding | |||
367 | * @return outSubbands subband counter, fix for broken specification/files | 350 | * @return outSubbands subband counter, fix for broken specification/files |
368 | */ | 351 | */ |
369 | 352 | ||
370 | static int decodeSpectrum (GetBitContext *gb, float *pOut) | 353 | static int decodeSpectrum (GetBitContext *gb, int32_t *pOut) |
371 | { | 354 | { |
372 | int numSubbands, codingMode, cnt, first, last, subbWidth, *pIn; | 355 | int numSubbands, codingMode, cnt, first, last, subbWidth, *pIn; |
373 | int subband_vlc_index[32], SF_idxs[32]; | 356 | int subband_vlc_index[32], SF_idxs[32]; |
374 | int mantissas[128]; | 357 | int mantissas[128]; |
375 | float SF; | 358 | int32_t SF; |
376 | 359 | ||
377 | numSubbands = get_bits(gb, 5); // number of coded subbands | 360 | numSubbands = get_bits(gb, 5); // number of coded subbands |
378 | codingMode = get_bits1(gb); // coding Mode: 0 - VLC/ 1-CLC | 361 | codingMode = get_bits1(gb); // coding Mode: 0 - VLC/ 1-CLC |
@@ -400,20 +383,20 @@ static int decodeSpectrum (GetBitContext *gb, float *pOut) | |||
400 | readQuantSpectralCoeffs (gb, subband_vlc_index[cnt], codingMode, mantissas, subbWidth); | 383 | readQuantSpectralCoeffs (gb, subband_vlc_index[cnt], codingMode, mantissas, subbWidth); |
401 | 384 | ||
402 | /* Decode the scale factor for this subband. */ | 385 | /* Decode the scale factor for this subband. */ |
403 | SF = SFTable[SF_idxs[cnt]] * iMaxQuant[subband_vlc_index[cnt]]; | 386 | SF = fixmul31(SFTable_fixed[SF_idxs[cnt]], iMaxQuant_fix[subband_vlc_index[cnt]]); |
404 | 387 | ||
405 | /* Inverse quantize the coefficients. */ | 388 | /* Inverse quantize the coefficients. */ |
406 | for (pIn=mantissas ; first<last; first++, pIn++) | 389 | for (pIn=mantissas ; first<last; first++, pIn++) |
407 | pOut[first] = *pIn * SF; | 390 | pOut[first] = fixmul16(*pIn, SF); |
408 | } else { | 391 | } else { |
409 | /* This subband was not coded, so zero the entire subband. */ | 392 | /* This subband was not coded, so zero the entire subband. */ |
410 | memset(pOut+first, 0, subbWidth*sizeof(float)); | 393 | memset(pOut+first, 0, subbWidth*sizeof(int32_t)); |
411 | } | 394 | } |
412 | } | 395 | } |
413 | 396 | ||
414 | /* Clear the subbands that were not coded. */ | 397 | /* Clear the subbands that were not coded. */ |
415 | first = subbandTab[cnt]; | 398 | first = subbandTab[cnt]; |
416 | memset(pOut+first, 0, (1024 - first) * sizeof(float)); | 399 | memset(pOut+first, 0, (1024 - first) * sizeof(int32_t)); |
417 | return numSubbands; | 400 | return numSubbands; |
418 | } | 401 | } |
419 | 402 | ||
@@ -431,8 +414,8 @@ static int decodeTonalComponents (GetBitContext *gb, tonal_component *pComponent | |||
431 | int components, coding_mode_selector, coding_mode, coded_values_per_component; | 414 | int components, coding_mode_selector, coding_mode, coded_values_per_component; |
432 | int sfIndx, coded_values, max_coded_values, quant_step_index, coded_components; | 415 | int sfIndx, coded_values, max_coded_values, quant_step_index, coded_components; |
433 | int band_flags[4], mantissa[8]; | 416 | int band_flags[4], mantissa[8]; |
434 | float *pCoef; | 417 | int32_t *pCoef; |
435 | float scalefactor; | 418 | int32_t scalefactor; |
436 | int component_count = 0; | 419 | int component_count = 0; |
437 | 420 | ||
438 | components = get_bits(gb,5); | 421 | components = get_bits(gb,5); |
@@ -473,7 +456,7 @@ static int decodeTonalComponents (GetBitContext *gb, tonal_component *pComponent | |||
473 | coded_values = coded_values_per_component + 1; | 456 | coded_values = coded_values_per_component + 1; |
474 | coded_values = FFMIN(max_coded_values,coded_values); | 457 | coded_values = FFMIN(max_coded_values,coded_values); |
475 | 458 | ||
476 | scalefactor = SFTable[sfIndx] * iMaxQuant[quant_step_index]; | 459 | scalefactor = fixmul31(SFTable_fixed[sfIndx], iMaxQuant_fix[quant_step_index]); |
477 | 460 | ||
478 | readQuantSpectralCoeffs(gb, quant_step_index, coding_mode, mantissa, coded_values); | 461 | readQuantSpectralCoeffs(gb, quant_step_index, coding_mode, mantissa, coded_values); |
479 | 462 | ||
@@ -482,7 +465,7 @@ static int decodeTonalComponents (GetBitContext *gb, tonal_component *pComponent | |||
482 | /* inverse quant */ | 465 | /* inverse quant */ |
483 | pCoef = pComponent[component_count].coef; | 466 | pCoef = pComponent[component_count].coef; |
484 | for (cnt = 0; cnt < coded_values; cnt++) | 467 | for (cnt = 0; cnt < coded_values; cnt++) |
485 | pCoef[cnt] = mantissa[cnt] * scalefactor; | 468 | pCoef[cnt] = fixmul16(mantissa[cnt], scalefactor); |
486 | 469 | ||
487 | component_count++; | 470 | component_count++; |
488 | } | 471 | } |
@@ -539,21 +522,21 @@ static int decodeGainControl (GetBitContext *gb, gain_block *pGb, int numBands) | |||
539 | * @param pGain2 next band gain info | 522 | * @param pGain2 next band gain info |
540 | */ | 523 | */ |
541 | 524 | ||
542 | static void gainCompensateAndOverlap (float *pIn, float *pPrev, float *pOut, gain_info *pGain1, gain_info *pGain2) | 525 | static void gainCompensateAndOverlap (int32_t *pIn, int32_t *pPrev, int32_t *pOut, gain_info *pGain1, gain_info *pGain2) |
543 | { | 526 | { |
544 | /* gain compensation function */ | 527 | /* gain compensation function */ |
545 | float gain1, gain2, gain_inc; | 528 | int32_t gain1, gain2, gain_inc; |
546 | int cnt, numdata, nsample, startLoc, endLoc; | 529 | int cnt, numdata, nsample, startLoc, endLoc; |
547 | 530 | ||
548 | 531 | ||
549 | if (pGain2->num_gain_data == 0) | 532 | if (pGain2->num_gain_data == 0) |
550 | gain1 = 1.0; | 533 | gain1 = ONE_16; |
551 | else | 534 | else |
552 | gain1 = gain_tab1[pGain2->levcode[0]]; | 535 | gain1 = gain_tab1[pGain2->levcode[0]]; |
553 | 536 | ||
554 | if (pGain1->num_gain_data == 0) { | 537 | if (pGain1->num_gain_data == 0) { |
555 | for (cnt = 0; cnt < 256; cnt++) | 538 | for (cnt = 0; cnt < 256; cnt++) |
556 | pOut[cnt] = pIn[cnt] * gain1 + pPrev[cnt]; | 539 | pOut[cnt] = fixmul16(pIn[cnt], gain1) + pPrev[cnt]; |
557 | } else { | 540 | } else { |
558 | numdata = pGain1->num_gain_data; | 541 | numdata = pGain1->num_gain_data; |
559 | pGain1->loccode[numdata] = 32; | 542 | pGain1->loccode[numdata] = 32; |
@@ -570,36 +553,38 @@ static void gainCompensateAndOverlap (float *pIn, float *pPrev, float *pOut, gai | |||
570 | 553 | ||
571 | /* interpolate */ | 554 | /* interpolate */ |
572 | for (; nsample < startLoc; nsample++) | 555 | for (; nsample < startLoc; nsample++) |
573 | pOut[nsample] = (pIn[nsample] * gain1 + pPrev[nsample]) * gain2; | 556 | pOut[nsample] = fixmul16((fixmul16(pIn[nsample], gain1) + pPrev[nsample]), gain2); |
574 | 557 | ||
575 | /* interpolation is done over eight samples */ | 558 | /* interpolation is done over eight samples */ |
576 | for (; nsample < endLoc; nsample++) { | 559 | for (; nsample < endLoc; nsample++) { |
577 | pOut[nsample] = (pIn[nsample] * gain1 + pPrev[nsample]) * gain2; | 560 | pOut[nsample] = fixmul16((fixmul16(pIn[nsample], gain1) + pPrev[nsample]),gain2); |
578 | gain2 *= gain_inc; | 561 | gain2 = fixmul16(gain2, gain_inc); |
579 | } | 562 | } |
580 | } | 563 | } |
581 | 564 | ||
582 | for (; nsample < 256; nsample++) | 565 | for (; nsample < 256; nsample++) |
583 | pOut[nsample] = (pIn[nsample] * gain1) + pPrev[nsample]; | 566 | pOut[nsample] = fixmul16(pIn[nsample], gain1) + pPrev[nsample]; |
584 | } | 567 | } |
585 | 568 | ||
586 | /* Delay for the overlapping part. */ | 569 | /* Delay for the overlapping part. */ |
587 | memcpy(pPrev, &pIn[256], 256*sizeof(float)); | 570 | memcpy(pPrev, &pIn[256], 256*sizeof(int32_t)); |
588 | } | 571 | } |
589 | 572 | ||
590 | /** | 573 | /** |
591 | * Combine the tonal band spectrum and regular band spectrum | 574 | * Combine the tonal band spectrum and regular band spectrum |
592 | * Return position of the last tonal coefficient | 575 | * Return position of the last tonal coefficient |
576 | |||
593 | * | 577 | * |
594 | * @param pSpectrum output spectrum buffer | 578 | * @param pSpectrum output spectrum buffer |
595 | * @param numComponents amount of tonal components | 579 | * @param numComponents amount of tonal components |
596 | * @param pComponent tonal components for this band | 580 | * @param pComponent tonal components for this band |
597 | */ | 581 | */ |
598 | 582 | ||
599 | static int addTonalComponents (float *pSpectrum, int numComponents, tonal_component *pComponent) | 583 | static int addTonalComponents (int32_t *pSpectrum, int numComponents, tonal_component *pComponent) |
600 | { | 584 | { |
601 | int cnt, i, lastPos = -1; | 585 | int cnt, i, lastPos = -1; |
602 | float *pIn, *pOut; | 586 | int32_t *pOut; |
587 | int32_t *pIn; | ||
603 | 588 | ||
604 | for (cnt = 0; cnt < numComponents; cnt++){ | 589 | for (cnt = 0; cnt < numComponents; cnt++){ |
605 | lastPos = FFMAX(pComponent[cnt].pos + pComponent[cnt].numCoefs, lastPos); | 590 | lastPos = FFMAX(pComponent[cnt].pos + pComponent[cnt].numCoefs, lastPos); |
@@ -614,13 +599,13 @@ static int addTonalComponents (float *pSpectrum, int numComponents, tonal_compon | |||
614 | } | 599 | } |
615 | 600 | ||
616 | 601 | ||
617 | #define INTERPOLATE(old,new,nsample) ((old) + (nsample)*0.125*((new)-(old))) | 602 | #define INTERPOLATE(old,new,nsample) ((old*ONE_16) + fixmul16(((nsample*ONE_16)>>3), (((new) - (old))*ONE_16))) |
618 | 603 | ||
619 | static void reverseMatrixing(float *su1, float *su2, int *pPrevCode, int *pCurrCode) | 604 | static void reverseMatrixing(int32_t *su1, int32_t *su2, int *pPrevCode, int *pCurrCode) |
620 | { | 605 | { |
621 | int i, band, nsample, s1, s2; | 606 | int i, band, nsample, s1, s2; |
622 | float c1, c2; | 607 | int32_t c1, c2; |
623 | float mc1_l, mc1_r, mc2_l, mc2_r; | 608 | int32_t mc1_l, mc1_r, mc2_l, mc2_r; |
624 | 609 | ||
625 | for (i=0,band = 0; band < 4*256; band+=256,i++) { | 610 | for (i=0,band = 0; band < 4*256; band+=256,i++) { |
626 | s1 = pPrevCode[i]; | 611 | s1 = pPrevCode[i]; |
@@ -629,18 +614,18 @@ static void reverseMatrixing(float *su1, float *su2, int *pPrevCode, int *pCurrC | |||
629 | 614 | ||
630 | if (s1 != s2) { | 615 | if (s1 != s2) { |
631 | /* Selector value changed, interpolation needed. */ | 616 | /* Selector value changed, interpolation needed. */ |
632 | mc1_l = matrixCoeffs[s1*2]; | 617 | mc1_l = matrixCoeffs_fix[s1<<1]; |
633 | mc1_r = matrixCoeffs[s1*2+1]; | 618 | mc1_r = matrixCoeffs_fix[(s1<<1)+1]; |
634 | mc2_l = matrixCoeffs[s2*2]; | 619 | mc2_l = matrixCoeffs_fix[s2<<1]; |
635 | mc2_r = matrixCoeffs[s2*2+1]; | 620 | mc2_r = matrixCoeffs_fix[(s2<<1)+1]; |
636 | 621 | ||
637 | /* Interpolation is done over the first eight samples. */ | 622 | /* Interpolation is done over the first eight samples. */ |
638 | for(; nsample < 8; nsample++) { | 623 | for(; nsample < 8; nsample++) { |
639 | c1 = su1[band+nsample]; | 624 | c1 = su1[band+nsample]; |
640 | c2 = su2[band+nsample]; | 625 | c2 = su2[band+nsample]; |
641 | c2 = c1 * INTERPOLATE(mc1_l,mc2_l,nsample) + c2 * INTERPOLATE(mc1_r,mc2_r,nsample); | 626 | c2 = fixmul16(c1, INTERPOLATE(mc1_l, mc2_l, nsample)) + fixmul16(c2, INTERPOLATE(mc1_r, mc2_r, nsample)); |
642 | su1[band+nsample] = c2; | 627 | su1[band+nsample] = c2; |
643 | su2[band+nsample] = c1 * 2.0 - c2; | 628 | su2[band+nsample] = (c1 << 1) - c2; |
644 | } | 629 | } |
645 | } | 630 | } |
646 | 631 | ||
@@ -650,8 +635,8 @@ static void reverseMatrixing(float *su1, float *su2, int *pPrevCode, int *pCurrC | |||
650 | for (; nsample < 256; nsample++) { | 635 | for (; nsample < 256; nsample++) { |
651 | c1 = su1[band+nsample]; | 636 | c1 = su1[band+nsample]; |
652 | c2 = su2[band+nsample]; | 637 | c2 = su2[band+nsample]; |
653 | su1[band+nsample] = c2 * 2.0; | 638 | su1[band+nsample] = c2 << 1; |
654 | su2[band+nsample] = (c1 - c2) * 2.0; | 639 | su2[band+nsample] = (c1 - c2) << 1; |
655 | } | 640 | } |
656 | break; | 641 | break; |
657 | 642 | ||
@@ -659,8 +644,8 @@ static void reverseMatrixing(float *su1, float *su2, int *pPrevCode, int *pCurrC | |||
659 | for (; nsample < 256; nsample++) { | 644 | for (; nsample < 256; nsample++) { |
660 | c1 = su1[band+nsample]; | 645 | c1 = su1[band+nsample]; |
661 | c2 = su2[band+nsample]; | 646 | c2 = su2[band+nsample]; |
662 | su1[band+nsample] = (c1 + c2) * 2.0; | 647 | su1[band+nsample] = (c1 + c2) << 1; |
663 | su2[band+nsample] = c2 * -2.0; | 648 | su2[band+nsample] = -1*(c2 << 1); |
664 | } | 649 | } |
665 | break; | 650 | break; |
666 | case 2: | 651 | case 2: |
@@ -678,24 +663,23 @@ static void reverseMatrixing(float *su1, float *su2, int *pPrevCode, int *pCurrC | |||
678 | } | 663 | } |
679 | } | 664 | } |
680 | 665 | ||
681 | static void getChannelWeights (int indx, int flag, float ch[2]){ | 666 | static void getChannelWeights (int indx, int flag, int32_t ch[2]){ |
682 | |||
683 | if (indx == 7) { | 667 | if (indx == 7) { |
684 | ch[0] = 1.0; | 668 | ch[0] = ONE_16; |
685 | ch[1] = 1.0; | 669 | ch[1] = ONE_16; |
686 | } else { | 670 | } else { |
687 | ch[0] = (float)(indx & 7) / 7.0; | 671 | ch[0] = fixdiv16(((indx & 7)*ONE_16), 7*ONE_16); |
688 | ch[1] = sqrt(2 - ch[0]*ch[0]); | 672 | ch[1] = fastSqrt((ONE_16 << 1) - fixmul16(ch[0], ch[0])); |
689 | if(flag) | 673 | if(flag) |
690 | FFSWAP(float, ch[0], ch[1]); | 674 | FFSWAP(int32_t, ch[0], ch[1]); |
691 | } | 675 | } |
692 | } | 676 | } |
693 | 677 | ||
694 | static void channelWeighting (float *su1, float *su2, int *p3) | 678 | static void channelWeighting (int32_t *su1, int32_t *su2, int *p3) |
695 | { | 679 | { |
696 | int band, nsample; | 680 | int band, nsample; |
697 | /* w[x][y] y=0 is left y=1 is right */ | 681 | /* w[x][y] y=0 is left y=1 is right */ |
698 | float w[2][2]; | 682 | int32_t w[2][2]; |
699 | 683 | ||
700 | if (p3[1] != 7 || p3[3] != 7){ | 684 | if (p3[1] != 7 || p3[3] != 7){ |
701 | getChannelWeights(p3[1], p3[0], w[0]); | 685 | getChannelWeights(p3[1], p3[0], w[0]); |
@@ -704,13 +688,13 @@ static void channelWeighting (float *su1, float *su2, int *p3) | |||
704 | for(band = 1; band < 4; band++) { | 688 | for(band = 1; band < 4; band++) { |
705 | /* scale the channels by the weights */ | 689 | /* scale the channels by the weights */ |
706 | for(nsample = 0; nsample < 8; nsample++) { | 690 | for(nsample = 0; nsample < 8; nsample++) { |
707 | su1[band*256+nsample] *= INTERPOLATE(w[0][0], w[0][1], nsample); | 691 | su1[band*256+nsample] = fixmul16(su1[band*256+nsample], INTERPOLATE(w[0][0], w[0][1], nsample)); |
708 | su2[band*256+nsample] *= INTERPOLATE(w[1][0], w[1][1], nsample); | 692 | su2[band*256+nsample] = fixmul16(su2[band*256+nsample], INTERPOLATE(w[1][0], w[1][1], nsample)); |
709 | } | 693 | } |
710 | 694 | ||
711 | for(; nsample < 256; nsample++) { | 695 | for(; nsample < 256; nsample++) { |
712 | su1[band*256+nsample] *= w[1][0]; | 696 | su1[band*256+nsample] = fixmul16(su1[band*256+nsample], w[1][0]); |
713 | su2[band*256+nsample] *= w[1][1]; | 697 | su2[band*256+nsample] = fixmul16(su2[band*256+nsample], w[1][1]); |
714 | } | 698 | } |
715 | } | 699 | } |
716 | } | 700 | } |
@@ -728,10 +712,9 @@ static void channelWeighting (float *su1, float *su2, int *p3) | |||
728 | */ | 712 | */ |
729 | 713 | ||
730 | 714 | ||
731 | static int decodeChannelSoundUnit (ATRAC3Context *q, GetBitContext *gb, channel_unit *pSnd, float *pOut, int channelNum, int codingMode) | 715 | static int decodeChannelSoundUnit (ATRAC3Context *q, GetBitContext *gb, channel_unit *pSnd, int32_t *pOut, int channelNum, int codingMode) |
732 | { | 716 | { |
733 | int band, result=0, numSubbands, lastTonal, numBands; | 717 | int band, result=0, numSubbands, lastTonal, numBands; |
734 | |||
735 | if (codingMode == JOINT_STEREO && channelNum == 1) { | 718 | if (codingMode == JOINT_STEREO && channelNum == 1) { |
736 | if (get_bits(gb,2) != 3) { | 719 | if (get_bits(gb,2) != 3) { |
737 | av_log(NULL,AV_LOG_ERROR,"JS mono Sound Unit id != 3.\n"); | 720 | av_log(NULL,AV_LOG_ERROR,"JS mono Sound Unit id != 3.\n"); |
@@ -771,7 +754,7 @@ static int decodeChannelSoundUnit (ATRAC3Context *q, GetBitContext *gb, channel_ | |||
771 | if (band <= numBands) { | 754 | if (band <= numBands) { |
772 | IMLT(&(pSnd->spectrum[band*256]), pSnd->IMDCT_buf, band&1); | 755 | IMLT(&(pSnd->spectrum[band*256]), pSnd->IMDCT_buf, band&1); |
773 | } else | 756 | } else |
774 | memset(pSnd->IMDCT_buf, 0, 512 * sizeof(float)); | 757 | memset(pSnd->IMDCT_buf, 0, 512 * sizeof(int32_t)); |
775 | 758 | ||
776 | /* gain compensation and overlapping */ | 759 | /* gain compensation and overlapping */ |
777 | gainCompensateAndOverlap (pSnd->IMDCT_buf, &(pSnd->prevFrame[band*256]), &(pOut[band*256]), | 760 | gainCompensateAndOverlap (pSnd->IMDCT_buf, &(pSnd->prevFrame[band*256]), &(pOut[band*256]), |
@@ -795,7 +778,7 @@ static int decodeChannelSoundUnit (ATRAC3Context *q, GetBitContext *gb, channel_ | |||
795 | static int decodeFrame(ATRAC3Context *q, const uint8_t* databuf) | 778 | static int decodeFrame(ATRAC3Context *q, const uint8_t* databuf) |
796 | { | 779 | { |
797 | int result, i; | 780 | int result, i; |
798 | float *p1, *p2, *p3, *p4; | 781 | int32_t *p1, *p2, *p3, *p4; |
799 | uint8_t *ptr1; | 782 | uint8_t *ptr1; |
800 | 783 | ||
801 | if (q->codingMode == JOINT_STEREO) { | 784 | if (q->codingMode == JOINT_STEREO) { |
@@ -893,7 +876,6 @@ static int decodeFrame(ATRAC3Context *q, const uint8_t* databuf) | |||
893 | static int atrac3_decode_frame(RMContext *rmctx, ATRAC3Context *q, | 876 | static int atrac3_decode_frame(RMContext *rmctx, ATRAC3Context *q, |
894 | void *data, int *data_size, | 877 | void *data, int *data_size, |
895 | const uint8_t *buf, int buf_size) { | 878 | const uint8_t *buf, int buf_size) { |
896 | //ATRAC3Context *q = rmctx->priv_data; | ||
897 | int result = 0, i; | 879 | int result = 0, i; |
898 | const uint8_t* databuf; | 880 | const uint8_t* databuf; |
899 | int16_t* samples = data; | 881 | int16_t* samples = data; |
@@ -919,13 +901,13 @@ static int atrac3_decode_frame(RMContext *rmctx, ATRAC3Context *q, | |||
919 | if (q->channels == 1) { | 901 | if (q->channels == 1) { |
920 | /* mono */ | 902 | /* mono */ |
921 | for (i = 0; i<1024; i++) | 903 | for (i = 0; i<1024; i++) |
922 | samples[i] = av_clip_int16(round(q->outSamples[i])); | 904 | samples[i] = av_clip_int16(q->outSamples[i]); |
923 | *data_size = 1024 * sizeof(int16_t); | 905 | *data_size = 1024 * sizeof(int16_t); |
924 | } else { | 906 | } else { |
925 | /* stereo */ | 907 | /* stereo */ |
926 | for (i = 0; i < 1024; i++) { | 908 | for (i = 0; i < 1024; i++) { |
927 | samples[i*2] = av_clip_int16(round(q->outSamples[i])); | 909 | samples[i*2] = av_clip_int16(q->outSamples[i]); |
928 | samples[i*2+1] = av_clip_int16(round(q->outSamples[1024+i])); | 910 | samples[i*2+1] = av_clip_int16(q->outSamples[1024+i]); |
929 | } | 911 | } |
930 | *data_size = 2048 * sizeof(int16_t); | 912 | *data_size = 2048 * sizeof(int16_t); |
931 | } | 913 | } |
@@ -944,7 +926,6 @@ static av_cold int atrac3_decode_init(ATRAC3Context *q, RMContext *rmctx) | |||
944 | { | 926 | { |
945 | int i; | 927 | int i; |
946 | const uint8_t *edata_ptr = rmctx->codec_extradata; | 928 | const uint8_t *edata_ptr = rmctx->codec_extradata; |
947 | //ATRAC3Context *q = rmctx->priv_data; | ||
948 | static VLC_TYPE atrac3_vlc_table[4096][2]; | 929 | static VLC_TYPE atrac3_vlc_table[4096][2]; |
949 | static int vlcs_initialized = 0; | 930 | static int vlcs_initialized = 0; |
950 | 931 | ||
@@ -1051,17 +1032,6 @@ static av_cold int atrac3_decode_init(ATRAC3Context *q, RMContext *rmctx) | |||
1051 | 1032 | ||
1052 | init_atrac3_transforms(q); | 1033 | init_atrac3_transforms(q); |
1053 | 1034 | ||
1054 | /* Generate the scale factors. */ | ||
1055 | for (i=0 ; i<64 ; i++) | ||
1056 | SFTable[i] = pow(2.0, (i - 15) / 3.0); | ||
1057 | |||
1058 | /* Generate gain tables. */ | ||
1059 | for (i=0 ; i<16 ; i++) | ||
1060 | gain_tab1[i] = powf (2.0, (4 - i)); | ||
1061 | |||
1062 | for (i=-15 ; i<16 ; i++) | ||
1063 | gain_tab2[i+15] = powf (2.0, i * -0.125); | ||
1064 | |||
1065 | /* init the joint-stereo decoding data */ | 1035 | /* init the joint-stereo decoding data */ |
1066 | q->weighting_delay[0] = 0; | 1036 | q->weighting_delay[0] = 0; |
1067 | q->weighting_delay[1] = 7; | 1037 | q->weighting_delay[1] = 7; |
@@ -1076,8 +1046,6 @@ static av_cold int atrac3_decode_init(ATRAC3Context *q, RMContext *rmctx) | |||
1076 | q->matrix_coeff_index_next[i] = 3; | 1046 | q->matrix_coeff_index_next[i] = 3; |
1077 | } | 1047 | } |
1078 | 1048 | ||
1079 | dsputil_init(&dsp); | ||
1080 | |||
1081 | q->pUnits = av_mallocz(sizeof(channel_unit)*q->channels); | 1049 | q->pUnits = av_mallocz(sizeof(channel_unit)*q->channels); |
1082 | if (!q->pUnits) { | 1050 | if (!q->pUnits) { |
1083 | av_free(q->decoded_bytes_buffer); | 1051 | av_free(q->decoded_bytes_buffer); |