comparison atrac3.c @ 10150:29cedcc646fe libavcodec

Split out common routines needed in the atrac1 decoder from atrac3.c to atrac.c.
author banan
date Tue, 08 Sep 2009 19:25:54 +0000
parents 6f80791c9195
children b49a14edba84
comparison
equal deleted inserted replaced
10149:94cb694c2af7 10150:29cedcc646fe
39 #include "avcodec.h" 39 #include "avcodec.h"
40 #include "get_bits.h" 40 #include "get_bits.h"
41 #include "dsputil.h" 41 #include "dsputil.h"
42 #include "bytestream.h" 42 #include "bytestream.h"
43 43
44 #include "atrac.h"
44 #include "atrac3data.h" 45 #include "atrac3data.h"
45 46
46 #define JOINT_STEREO 0x12 47 #define JOINT_STEREO 0x12
47 #define STEREO 0x2 48 #define STEREO 0x2
48 49
117 int frame_factor; 118 int frame_factor;
118 //@} 119 //@}
119 } ATRAC3Context; 120 } ATRAC3Context;
120 121
121 static DECLARE_ALIGNED_16(float,mdct_window[512]); 122 static DECLARE_ALIGNED_16(float,mdct_window[512]);
122 static float qmf_window[48];
123 static VLC spectral_coeff_tab[7]; 123 static VLC spectral_coeff_tab[7];
124 static float SFTable[64];
125 static float gain_tab1[16]; 124 static float gain_tab1[16];
126 static float gain_tab2[31]; 125 static float gain_tab2[31];
127 static MDCTContext mdct_ctx; 126 static MDCTContext mdct_ctx;
128 static DSPContext dsp; 127 static DSPContext dsp;
129 128
130
131 /* quadrature mirror synthesis filter */
132
133 /**
134 * Quadrature mirror synthesis filter.
135 *
136 * @param inlo lower part of spectrum
137 * @param inhi higher part of spectrum
138 * @param nIn size of spectrum buffer
139 * @param pOut out buffer
140 * @param delayBuf delayBuf buffer
141 * @param temp temp buffer
142 */
143
144
145 static void iqmf (float *inlo, float *inhi, unsigned int nIn, float *pOut, float *delayBuf, float *temp)
146 {
147 int i, j;
148 float *p1, *p3;
149
150 memcpy(temp, delayBuf, 46*sizeof(float));
151
152 p3 = temp + 46;
153
154 /* loop1 */
155 for(i=0; i<nIn; i+=2){
156 p3[2*i+0] = inlo[i ] + inhi[i ];
157 p3[2*i+1] = inlo[i ] - inhi[i ];
158 p3[2*i+2] = inlo[i+1] + inhi[i+1];
159 p3[2*i+3] = inlo[i+1] - inhi[i+1];
160 }
161
162 /* loop2 */
163 p1 = temp;
164 for (j = nIn; j != 0; j--) {
165 float s1 = 0.0;
166 float s2 = 0.0;
167
168 for (i = 0; i < 48; i += 2) {
169 s1 += p1[i] * qmf_window[i];
170 s2 += p1[i+1] * qmf_window[i+1];
171 }
172
173 pOut[0] = s2;
174 pOut[1] = s1;
175
176 p1 += 2;
177 pOut += 2;
178 }
179
180 /* Update the delay buffer. */
181 memcpy(delayBuf, temp + nIn*2, 46*sizeof(float));
182 }
183 129
184 /** 130 /**
185 * Regular 512 points IMDCT without overlapping, with the exception of the swapping of odd bands 131 * Regular 512 points IMDCT without overlapping, with the exception of the swapping of odd bands
186 * caused by the reverse spectra of the QMF. 132 * caused by the reverse spectra of the QMF.
187 * 133 *
384 /* TODO: This can be done faster is several blocks share the 330 /* TODO: This can be done faster is several blocks share the
385 * same VLC selector (subband_vlc_index) */ 331 * same VLC selector (subband_vlc_index) */
386 readQuantSpectralCoeffs (gb, subband_vlc_index[cnt], codingMode, mantissas, subbWidth); 332 readQuantSpectralCoeffs (gb, subband_vlc_index[cnt], codingMode, mantissas, subbWidth);
387 333
388 /* Decode the scale factor for this subband. */ 334 /* Decode the scale factor for this subband. */
389 SF = SFTable[SF_idxs[cnt]] * iMaxQuant[subband_vlc_index[cnt]]; 335 SF = sf_table[SF_idxs[cnt]] * iMaxQuant[subband_vlc_index[cnt]];
390 336
391 /* Inverse quantize the coefficients. */ 337 /* Inverse quantize the coefficients. */
392 for (pIn=mantissas ; first<last; first++, pIn++) 338 for (pIn=mantissas ; first<last; first++, pIn++)
393 pOut[first] = *pIn * SF; 339 pOut[first] = *pIn * SF;
394 } else { 340 } else {
457 pComponent[component_count].pos = j * 64 + (get_bits(gb,6)); 403 pComponent[component_count].pos = j * 64 + (get_bits(gb,6));
458 max_coded_values = 1024 - pComponent[component_count].pos; 404 max_coded_values = 1024 - pComponent[component_count].pos;
459 coded_values = coded_values_per_component + 1; 405 coded_values = coded_values_per_component + 1;
460 coded_values = FFMIN(max_coded_values,coded_values); 406 coded_values = FFMIN(max_coded_values,coded_values);
461 407
462 scalefactor = SFTable[sfIndx] * iMaxQuant[quant_step_index]; 408 scalefactor = sf_table[sfIndx] * iMaxQuant[quant_step_index];
463 409
464 readQuantSpectralCoeffs(gb, quant_step_index, coding_mode, mantissa, coded_values); 410 readQuantSpectralCoeffs(gb, quant_step_index, coding_mode, mantissa, coded_values);
465 411
466 pComponent[component_count].numCoefs = coded_values; 412 pComponent[component_count].numCoefs = coded_values;
467 413
858 p1= q->outSamples; 804 p1= q->outSamples;
859 for (i=0 ; i<q->channels ; i++) { 805 for (i=0 ; i<q->channels ; i++) {
860 p2= p1+256; 806 p2= p1+256;
861 p3= p2+256; 807 p3= p2+256;
862 p4= p3+256; 808 p4= p3+256;
863 iqmf (p1, p2, 256, p1, q->pUnits[i].delayBuf1, q->tempBuf); 809 atrac_iqmf (p1, p2, 256, p1, q->pUnits[i].delayBuf1, q->tempBuf);
864 iqmf (p4, p3, 256, p3, q->pUnits[i].delayBuf2, q->tempBuf); 810 atrac_iqmf (p4, p3, 256, p3, q->pUnits[i].delayBuf2, q->tempBuf);
865 iqmf (p1, p3, 512, p1, q->pUnits[i].delayBuf3, q->tempBuf); 811 atrac_iqmf (p1, p3, 512, p1, q->pUnits[i].delayBuf3, q->tempBuf);
866 p1 +=1024; 812 p1 +=1024;
867 } 813 }
868 814
869 return 0; 815 return 0;
870 } 816 }
1036 vlcs_initialized = 1; 982 vlcs_initialized = 1;
1037 } 983 }
1038 984
1039 init_atrac3_transforms(q); 985 init_atrac3_transforms(q);
1040 986
1041 /* Generate the scale factors. */ 987 atrac_generate_tables();
1042 for (i=0 ; i<64 ; i++)
1043 SFTable[i] = pow(2.0, (i - 15) / 3.0);
1044 988
1045 /* Generate gain tables. */ 989 /* Generate gain tables. */
1046 for (i=0 ; i<16 ; i++) 990 for (i=0 ; i<16 ; i++)
1047 gain_tab1[i] = powf (2.0, (4 - i)); 991 gain_tab1[i] = powf (2.0, (4 - i));
1048 992