summaryrefslogtreecommitdiff
path: root/apps/codecs/libatrac/atrac3.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/codecs/libatrac/atrac3.c')
-rw-r--r--apps/codecs/libatrac/atrac3.c136
1 files changed, 103 insertions, 33 deletions
diff --git a/apps/codecs/libatrac/atrac3.c b/apps/codecs/libatrac/atrac3.c
index 47a63cae30..9ea2be8775 100644
--- a/apps/codecs/libatrac/atrac3.c
+++ b/apps/codecs/libatrac/atrac3.c
@@ -67,6 +67,101 @@ static inline int16_t av_clip_int16(int a)
67static int32_t qmf_window[48] IBSS_ATTR; 67static int32_t qmf_window[48] IBSS_ATTR;
68static VLC spectral_coeff_tab[7]; 68static VLC spectral_coeff_tab[7];
69static channel_unit channel_units[2]; 69static channel_unit channel_units[2];
70
71/**
72 * Matrixing within quadrature mirror synthesis filter.
73 *
74 * @param p3 output buffer
75 * @param inlo lower part of spectrum
76 * @param inhi higher part of spectrum
77 * @param nIn size of spectrum buffer
78 */
79
80#if defined(CPU_ARM)
81 extern void
82 atrac3_iqmf_matrixing(int32_t *p3,
83 int32_t *inlo,
84 int32_t *inhi,
85 unsigned int nIn);
86#else
87 static inline void
88 atrac3_iqmf_matrixing(int32_t *p3,
89 int32_t *inlo,
90 int32_t *inhi,
91 unsigned int nIn)
92 {
93 for(i=0; i<nIn; i+=2){
94 p3[2*i+0] = inlo[i ] + inhi[i ];
95 p3[2*i+1] = inlo[i ] - inhi[i ];
96 p3[2*i+2] = inlo[i+1] + inhi[i+1];
97 p3[2*i+3] = inlo[i+1] - inhi[i+1];
98 }
99 }
100#endif
101
102/**
103 * Matrixing within quadrature mirror synthesis filter.
104 *
105 * @param out output buffer
106 * @param in input buffer
107 * @param win windowing coefficients
108 * @param nIn size of spectrum buffer
109 */
110
111#if defined(CPU_ARM)
112 extern void
113 atrac3_iqmf_dewindowing(int32_t *out,
114 int32_t *in,
115 int32_t *win,
116 unsigned int nIn);
117#else
118 static inline void
119 atrac3_iqmf_dewindowing(int32_t *out,
120 int32_t *in,
121 int32_t *win,
122 unsigned int nIn)
123 {
124 int32_t i, j, s1, s2;
125
126 for (j = nIn; j != 0; j--) {
127 /* i=0 */
128 s1 = fixmul31(win[0], in[0]);
129 s2 = fixmul31(win[1], in[1]);
130
131 /* i=2..46 */
132 for (i = 2; i < 48; i += 2) {
133 s1 += fixmul31(win[i ], in[i ]);
134 s2 += fixmul31(win[i+1], in[i+1]);
135 }
136
137 out[0] = s2;
138 out[1] = s1;
139
140 in += 2;
141 out += 2;
142 }
143 }
144#endif
145
146/**
147 * IMDCT windowing.
148 *
149 * @param buffer sample buffer
150 * @param win window coefficients
151 */
152
153static inline void
154atrac3_imdct_windowing(int32_t *buffer,
155 const int32_t *win)
156{
157 int32_t i;
158 /* win[0..127] = win[511..384], win[128..383] = 1 */
159 for(i = 0; i<128; i++) {
160 buffer[ i] = fixmul31(win[i], buffer[ i]);
161 buffer[511-i] = fixmul31(win[i], buffer[511-i]);
162 }
163}
164
70/** 165/**
71 * Quadrature mirror synthesis filter. 166 * Quadrature mirror synthesis filter.
72 * 167 *
@@ -77,42 +172,19 @@ static channel_unit channel_units[2];
77 * @param delayBuf delayBuf buffer 172 * @param delayBuf delayBuf buffer
78 * @param temp temp buffer 173 * @param temp temp buffer
79 */ 174 */
175
80static void iqmf (int32_t *inlo, int32_t *inhi, unsigned int nIn, int32_t *pOut, int32_t *delayBuf, int32_t *temp) 176static void iqmf (int32_t *inlo, int32_t *inhi, unsigned int nIn, int32_t *pOut, int32_t *delayBuf, int32_t *temp)
81{ 177{
82 unsigned int i, j; 178 /* Restore the delay buffer */
83 int32_t *p1, *p3;
84
85 memcpy(temp, delayBuf, 46*sizeof(int32_t)); 179 memcpy(temp, delayBuf, 46*sizeof(int32_t));
86 180
87 p3 = temp + 46; 181 /* loop1: matrixing */
182 atrac3_iqmf_matrixing(temp + 46, inlo, inhi, nIn);
88 183
89 /* loop1 */ 184 /* loop2: dewindowing */
90 for(i=0; i<nIn; i+=2){ 185 atrac3_iqmf_dewindowing(pOut, temp, qmf_window, nIn);
91 p3[2*i+0] = inlo[i ] + inhi[i ];
92 p3[2*i+1] = inlo[i ] - inhi[i ];
93 p3[2*i+2] = inlo[i+1] + inhi[i+1];
94 p3[2*i+3] = inlo[i+1] - inhi[i+1];
95 }
96
97 /* loop2 */
98 p1 = temp;
99 for (j = nIn; j != 0; j--) {
100 int32_t s1 = 0;
101 int32_t s2 = 0;
102 186
103 for (i = 0; i < 48; i += 2) { 187 /* Save the delay buffer */
104 s1 += fixmul31(p1[i], qmf_window[i]);
105 s2 += fixmul31(p1[i+1], qmf_window[i+1]);
106 }
107
108 pOut[0] = s2;
109 pOut[1] = s1;
110
111 p1 += 2;
112 pOut += 2;
113 }
114
115 /* Update the delay buffer. */
116 memcpy(delayBuf, temp + (nIn << 1), 46*sizeof(int32_t)); 188 memcpy(delayBuf, temp + (nIn << 1), 46*sizeof(int32_t));
117} 189}
118 190
@@ -146,9 +218,7 @@ static void IMLT(int32_t *pInput, int32_t *pOutput, int odd_band)
146 mdct_backward(512, pInput, pOutput); 218 mdct_backward(512, pInput, pOutput);
147 219
148 /* Windowing. */ 220 /* Windowing. */
149 for(i = 0; i<512; i++) 221 atrac3_imdct_windowing(pOutput, window_lookup);
150 pOutput[i] = fixmul31(pOutput[i], window_lookup[i]);
151
152} 222}
153 223
154 224