comparison atrac1.c @ 10170:e1bb4cf6e659 libavcodec

Cosmetics. Renames, indentation and spacing.
author banan
date Sun, 13 Sep 2009 18:05:14 +0000
parents 178274d5fa1d
children 25752b5ce17a
comparison
equal deleted inserted replaced
10169:a48c43551737 10170:e1bb4cf6e659
92 /** size of the transform in samples in the long mode for each QMF band */ 92 /** size of the transform in samples in the long mode for each QMF band */
93 static const uint16_t samples_per_band[3] = {128, 128, 256}; 93 static const uint16_t samples_per_band[3] = {128, 128, 256};
94 static const uint8_t mdct_long_nbits[3] = {7, 7, 8}; 94 static const uint8_t mdct_long_nbits[3] = {7, 7, 8};
95 95
96 96
97 static void at1_imdct(AT1Ctx *q, float *spec, float *out, int nbits, int rev_spec) 97 static void at1_imdct(AT1Ctx *q, float *spec, float *out, int nbits,
98 int rev_spec)
98 { 99 {
99 MDCTContext* mdct_context; 100 MDCTContext* mdct_context;
100 int transf_size = 1 << nbits; 101 int transf_size = 1 << nbits;
101 102
102 mdct_context = &q->mdct_ctx[nbits - 5 - (nbits>6)]; 103 mdct_context = &q->mdct_ctx[nbits - 5 - (nbits>6)];
103 104
104 if (rev_spec) { 105 if (rev_spec) {
105 int i; 106 int i;
106 for (i=0 ; i<transf_size/2 ; i++) 107 for (i=0 ; i<transf_size/2 ; i++)
107 FFSWAP(float, spec[i], spec[transf_size-1-i]); 108 FFSWAP(float, spec[i], spec[transf_size - 1 - i]);
108 } 109 }
109 ff_imdct_half(mdct_context,out,spec); 110 ff_imdct_half(mdct_context, out, spec);
110 } 111 }
111 112
112 113
113 static int at1_imdct_block(AT1SUCtx* su, AT1Ctx *q) 114 static int at1_imdct_block(AT1SUCtx* su, AT1Ctx *q)
114 { 115 {
145 /* use hardcoded nbits for the short mode */ 146 /* use hardcoded nbits for the short mode */
146 at1_imdct(q, &q->spec[pos], q->short_buf, 5, band_num); 147 at1_imdct(q, &q->spec[pos], q->short_buf, 5, band_num);
147 148
148 /* overlap and window between short blocks */ 149 /* overlap and window between short blocks */
149 q->dsp.vector_fmul_window(&su->spectrum[0][ref_pos+start_pos], 150 q->dsp.vector_fmul_window(&su->spectrum[0][ref_pos+start_pos],
150 &su->spectrum[0][ref_pos+start_pos],q->short_buf,short_window, 0, 16); 151 &su->spectrum[0][ref_pos+start_pos],
152 q->short_buf,short_window, 0, 16);
151 start_pos += 32; // use hardcoded block_size 153 start_pos += 32; // use hardcoded block_size
152 pos += 32; 154 pos += 32;
153 } 155 }
154 } 156 }
155 157
164 FFSWAP(float*, su->spectrum[0], su->spectrum[1]); 166 FFSWAP(float*, su->spectrum[0], su->spectrum[1]);
165 167
166 return 0; 168 return 0;
167 } 169 }
168 170
169 171 /**
170 static int at1_parse_block_size_mode(GetBitContext* gb, int log2_block_count[AT1_QMF_BANDS]) 172 * Parse the block size mode byte
173 */
174
175 static int at1_parse_bsm(GetBitContext* gb, int log2_block_cnt[AT1_QMF_BANDS])
171 { 176 {
172 int log2_block_count_tmp, i; 177 int log2_block_count_tmp, i;
173 178
174 for(i=0 ; i<2 ; i++) { 179 for(i=0 ; i<2 ; i++) {
175 /* low and mid band */ 180 /* low and mid band */
176 log2_block_count_tmp = get_bits(gb, 2); 181 log2_block_count_tmp = get_bits(gb, 2);
177 if (log2_block_count_tmp & 1) 182 if (log2_block_count_tmp & 1)
178 return -1; 183 return -1;
179 log2_block_count[i] = 2 - log2_block_count_tmp; 184 log2_block_cnt[i] = 2 - log2_block_count_tmp;
180 } 185 }
181 186
182 /* high band */ 187 /* high band */
183 log2_block_count_tmp = get_bits(gb, 2); 188 log2_block_count_tmp = get_bits(gb, 2);
184 if (log2_block_count_tmp != 0 && log2_block_count_tmp != 3) 189 if (log2_block_count_tmp != 0 && log2_block_count_tmp != 3)
185 return -1; 190 return -1;
186 log2_block_count[IDX_HIGH_BAND] = 3 - log2_block_count_tmp; 191 log2_block_cnt[IDX_HIGH_BAND] = 3 - log2_block_count_tmp;
187 192
188 skip_bits(gb, 2); 193 skip_bits(gb, 2);
189 return 0; 194 return 0;
190 } 195 }
191 196
192 197
193 static int at1_unpack_dequant(GetBitContext* gb, AT1SUCtx* su, float spec[AT1_SU_SAMPLES]) 198 static int at1_unpack_dequant(GetBitContext* gb, AT1SUCtx* su,
199 float spec[AT1_SU_SAMPLES])
194 { 200 {
195 int bits_used, band_num, bfu_num, i; 201 int bits_used, band_num, bfu_num, i;
196 202
197 /* parse the info byte (2nd byte) telling how much BFUs were coded */ 203 /* parse the info byte (2nd byte) telling how much BFUs were coded */
198 su->num_bfus = bfu_amount_tab1[get_bits(gb, 3)]; 204 su->num_bfus = bfu_amount_tab1[get_bits(gb, 3)];
232 238
233 /* get the position of the 1st spec according to the block size mode */ 239 /* get the position of the 1st spec according to the block size mode */
234 pos = su->log2_block_count[band_num] ? bfu_start_short[bfu_num] : bfu_start_long[bfu_num]; 240 pos = su->log2_block_count[band_num] ? bfu_start_short[bfu_num] : bfu_start_long[bfu_num];
235 241
236 if (word_len) { 242 if (word_len) {
237 float max_quant = 1.0/(float)((1 << (word_len - 1)) - 1); 243 float max_quant = 1.0 / (float)((1 << (word_len - 1)) - 1);
238 244
239 for (i=0 ; i<num_specs ; i++) { 245 for (i=0 ; i<num_specs ; i++) {
240 /* read in a quantized spec and convert it to 246 /* read in a quantized spec and convert it to
241 * signed int and then inverse quantization 247 * signed int and then inverse quantization
242 */ 248 */
259 265
260 /* combine low and middle bands */ 266 /* combine low and middle bands */
261 atrac_iqmf(q->bands[0], q->bands[1], 128, temp, su->fst_qmf_delay, iqmf_temp); 267 atrac_iqmf(q->bands[0], q->bands[1], 128, temp, su->fst_qmf_delay, iqmf_temp);
262 268
263 /* delay the signal of the high band by 23 samples */ 269 /* delay the signal of the high band by 23 samples */
264 memcpy( su->last_qmf_delay, &su->last_qmf_delay[256], sizeof(float)*23); 270 memcpy( su->last_qmf_delay, &su->last_qmf_delay[256], sizeof(float)*23);
265 memcpy(&su->last_qmf_delay[23], q->bands[2], sizeof(float)*256); 271 memcpy(&su->last_qmf_delay[23], q->bands[2], sizeof(float)*256);
266 272
267 /* combine (low + middle) and high bands */ 273 /* combine (low + middle) and high bands */
268 atrac_iqmf(temp, su->last_qmf_delay, 256, pOut, su->snd_qmf_delay, iqmf_temp); 274 atrac_iqmf(temp, su->last_qmf_delay, 256, pOut, su->snd_qmf_delay, iqmf_temp);
269 } 275 }
270 276
271 277
272 static int atrac1_decode_frame(AVCodecContext *avctx, 278 static int atrac1_decode_frame(AVCodecContext *avctx, void *data,
273 void *data, int *data_size, 279 int *data_size, AVPacket *avpkt)
274 AVPacket *avpkt)
275 { 280 {
276 const uint8_t *buf = avpkt->data; 281 const uint8_t *buf = avpkt->data;
277 int buf_size = avpkt->size; 282 int buf_size = avpkt->size;
278 AT1Ctx *q = avctx->priv_data; 283 AT1Ctx *q = avctx->priv_data;
279 int ch, ret, i; 284 int ch, ret, i;
280 GetBitContext gb; 285 GetBitContext gb;
281 float* samples = data; 286 float* samples = data;
282 287
283 288
290 AT1SUCtx* su = &q->SUs[ch]; 295 AT1SUCtx* su = &q->SUs[ch];
291 296
292 init_get_bits(&gb, &buf[212*ch], 212*8); 297 init_get_bits(&gb, &buf[212*ch], 212*8);
293 298
294 /* parse block_size_mode, 1st byte */ 299 /* parse block_size_mode, 1st byte */
295 ret = at1_parse_block_size_mode(&gb, su->log2_block_count); 300 ret = at1_parse_bsm(&gb, su->log2_block_count);
296 if (ret < 0) 301 if (ret < 0)
297 return ret; 302 return ret;
298 303
299 ret = at1_unpack_dequant(&gb, su, q->spec); 304 ret = at1_unpack_dequant(&gb, su, q->spec);
300 if (ret < 0) 305 if (ret < 0)
307 } 312 }
308 313
309 /* round, convert to 16bit and interleave */ 314 /* round, convert to 16bit and interleave */
310 if (q->channels == 1) { 315 if (q->channels == 1) {
311 /* mono */ 316 /* mono */
312 q->dsp.vector_clipf(samples, q->out_samples[0], -32700./(1<<15), 32700./(1<<15), AT1_SU_SAMPLES); 317 q->dsp.vector_clipf(samples, q->out_samples[0], -32700.0 / (1<<15),
318 32700.0 / (1<<15), AT1_SU_SAMPLES);
313 } else { 319 } else {
314 /* stereo */ 320 /* stereo */
315 for (i = 0; i < AT1_SU_SAMPLES; i++) { 321 for (i = 0; i < AT1_SU_SAMPLES; i++) {
316 samples[i*2] = av_clipf(q->out_samples[0][i], -32700./(1<<15), 32700./(1<<15)); 322 samples[i*2] = av_clipf(q->out_samples[0][i], -32700.0 / (1<<15),
317 samples[i*2+1] = av_clipf(q->out_samples[1][i], -32700./(1<<15), 32700./(1<<15)); 323 32700.0 / (1<<15));
324 samples[i*2+1] = av_clipf(q->out_samples[1][i], -32700.0 / (1<<15),
325 32700.0 / (1<<15));
318 } 326 }
319 } 327 }
320 328
321 *data_size = q->channels * AT1_SU_SAMPLES * sizeof(*samples); 329 *data_size = q->channels * AT1_SU_SAMPLES * sizeof(*samples);
322 return avctx->block_align; 330 return avctx->block_align;