comparison atrac1.c @ 10185:25752b5ce17a libavcodec

Only use one mdct window size in atrac1.
author banan
date Thu, 17 Sep 2009 18:52:11 +0000
parents e1bb4cf6e659
children de34f74fb758
comparison
equal deleted inserted replaced
10184:9a577b684548 10185:25752b5ce17a
71 * The atrac1 context, holds all needed parameters for decoding 71 * The atrac1 context, holds all needed parameters for decoding
72 */ 72 */
73 typedef struct { 73 typedef struct {
74 AT1SUCtx SUs[AT1_MAX_CHANNELS]; ///< channel sound unit 74 AT1SUCtx SUs[AT1_MAX_CHANNELS]; ///< channel sound unit
75 DECLARE_ALIGNED_16(float,spec[AT1_SU_SAMPLES]); ///< the mdct spectrum buffer 75 DECLARE_ALIGNED_16(float,spec[AT1_SU_SAMPLES]); ///< the mdct spectrum buffer
76 DECLARE_ALIGNED_16(float,short_buf[64]); ///< buffer for the short mode 76 DECLARE_ALIGNED_16(float,short_buf[512]); ///< buffer for the short mode
77
77 DECLARE_ALIGNED_16(float, low[256]); 78 DECLARE_ALIGNED_16(float, low[256]);
78 DECLARE_ALIGNED_16(float, mid[256]); 79 DECLARE_ALIGNED_16(float, mid[256]);
79 DECLARE_ALIGNED_16(float,high[512]); 80 DECLARE_ALIGNED_16(float,high[512]);
80 float* bands[3]; 81 float* bands[3];
81 float out_samples[AT1_MAX_CHANNELS][AT1_SU_SAMPLES]; 82 float out_samples[AT1_MAX_CHANNELS][AT1_SU_SAMPLES];
82 MDCTContext mdct_ctx[3]; 83 MDCTContext mdct_ctx[3];
83 int channels; 84 int channels;
84 DSPContext dsp; 85 DSPContext dsp;
85 } AT1Ctx; 86 } AT1Ctx;
86 87
87 static float *short_window; 88 DECLARE_ALIGNED_16(static float, short_window[32]);
88 static float *mid_window;
89 DECLARE_ALIGNED_16(static float, long_window[256]);
90 static float *window_per_band[3];
91 89
92 /** size of the transform in samples in the long mode for each QMF band */ 90 /** 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}; 91 static const uint16_t samples_per_band[3] = {128, 128, 256};
94 static const uint8_t mdct_long_nbits[3] = {7, 7, 8}; 92 static const uint8_t mdct_long_nbits[3] = {7, 7, 8};
95 93
135 return -1; 133 return -1;
136 134
137 if (num_blocks == 1) { 135 if (num_blocks == 1) {
138 at1_imdct(q, &q->spec[pos], &su->spectrum[0][ref_pos], nbits, band_num); 136 at1_imdct(q, &q->spec[pos], &su->spectrum[0][ref_pos], nbits, band_num);
139 pos += block_size; // move to the next mdct block in the spectrum 137 pos += block_size; // move to the next mdct block in the spectrum
138
139 /* overlap and window long blocks */
140 q->dsp.vector_fmul_window(q->bands[band_num], &su->spectrum[1][ref_pos+band_samples-16],
141 &su->spectrum[0][ref_pos], short_window, 0, 16);
142 memcpy(q->bands[band_num]+32, &su->spectrum[0][ref_pos+16], 240 * sizeof(float));
143
140 } else { 144 } else {
141 /* calc start position for the 1st short block: 96(128) or 112(256) */ 145 /* calc start position for the 1st short block: 96(128) or 112(256) */
146 int short_pos = 32;
147 float *prev_buf;
142 start_pos = (band_samples * (num_blocks - 1)) >> (log2_block_count + 1); 148 start_pos = (band_samples * (num_blocks - 1)) >> (log2_block_count + 1);
143 memset(&su->spectrum[0][ref_pos], 0, sizeof(float) * (band_samples * 2)); 149 memset(&su->spectrum[0][ref_pos], 0, sizeof(float) * (band_samples * 2));
144 150
151 prev_buf = &su->spectrum[1][ref_pos+band_samples-16];
145 for (; num_blocks!=0 ; num_blocks--) { 152 for (; num_blocks!=0 ; num_blocks--) {
146 /* use hardcoded nbits for the short mode */ 153 /* use hardcoded nbits for the short mode */
147 at1_imdct(q, &q->spec[pos], q->short_buf, 5, band_num); 154 at1_imdct(q, &q->spec[pos], &q->short_buf[short_pos], 5, band_num);
148 155
149 /* overlap and window between short blocks */ 156 /* overlap and window between short blocks */
150 q->dsp.vector_fmul_window(&su->spectrum[0][ref_pos+start_pos], 157 q->dsp.vector_fmul_window(&su->spectrum[0][ref_pos+start_pos],
151 &su->spectrum[0][ref_pos+start_pos], 158 &q->short_buf[short_pos-16],
152 q->short_buf,short_window, 0, 16); 159 &q->short_buf[short_pos],short_window, 0, 16);
160
161 prev_buf = &q->short_buf[short_pos+16];
162
153 start_pos += 32; // use hardcoded block_size 163 start_pos += 32; // use hardcoded block_size
154 pos += 32; 164 pos += 32;
165 short_pos +=32;
155 } 166 }
167 memcpy(q->bands[band_num], &su->spectrum[0][ref_pos], band_samples*sizeof(float));
156 } 168 }
157
158 /* overlap and window with the previous frame and output the result */
159 q->dsp.vector_fmul_window(q->bands[band_num], &su->spectrum[1][ref_pos+band_samples/2],
160 &su->spectrum[0][ref_pos], window_per_band[band_num], 0, band_samples/2);
161
162 ref_pos += band_samples; 169 ref_pos += band_samples;
163 } 170 }
164 171
165 /* Swap buffers so the mdct overlap works */ 172 /* Swap buffers so the mdct overlap works */
166 FFSWAP(float*, su->spectrum[0], su->spectrum[1]); 173 FFSWAP(float*, su->spectrum[0], su->spectrum[1]);
329 *data_size = q->channels * AT1_SU_SAMPLES * sizeof(*samples); 336 *data_size = q->channels * AT1_SU_SAMPLES * sizeof(*samples);
330 return avctx->block_align; 337 return avctx->block_align;
331 } 338 }
332 339
333 340
334 static av_cold void init_mdct_windows(void)
335 {
336 int i;
337
338 /** The mid and long windows uses the same sine window splitted
339 * in the middle and wrapped into zero/one regions as follows:
340 *
341 * region of "ones"
342 * -------------
343 * /
344 * / 1st half
345 * / of the sine
346 * / window
347 * ---------/
348 * zero region
349 *
350 * The mid and short windows are subsets of the long window.
351 */
352
353 /* Build "zero" region */
354 memset(long_window, 0, sizeof(long_window));
355 /* Build sine window region */
356 short_window = &long_window[112];
357 ff_sine_window_init(short_window,32);
358 /* Build "ones" region */
359 for (i = 0; i < 112; i++)
360 long_window[144 + i] = 1.0f;
361 /* Save the mid window subset start */
362 mid_window = &long_window[64];
363
364 /* Prepare the window table */
365 window_per_band[0] = mid_window;
366 window_per_band[1] = mid_window;
367 window_per_band[2] = long_window;
368 }
369
370 static av_cold int atrac1_decode_init(AVCodecContext *avctx) 341 static av_cold int atrac1_decode_init(AVCodecContext *avctx)
371 { 342 {
372 AT1Ctx *q = avctx->priv_data; 343 AT1Ctx *q = avctx->priv_data;
373 344
374 avctx->sample_fmt = SAMPLE_FMT_FLT; 345 avctx->sample_fmt = SAMPLE_FMT_FLT;
377 348
378 /* Init the mdct transforms */ 349 /* Init the mdct transforms */
379 ff_mdct_init(&q->mdct_ctx[0], 6, 1, -1.0/ (1<<15)); 350 ff_mdct_init(&q->mdct_ctx[0], 6, 1, -1.0/ (1<<15));
380 ff_mdct_init(&q->mdct_ctx[1], 8, 1, -1.0/ (1<<15)); 351 ff_mdct_init(&q->mdct_ctx[1], 8, 1, -1.0/ (1<<15));
381 ff_mdct_init(&q->mdct_ctx[2], 9, 1, -1.0/ (1<<15)); 352 ff_mdct_init(&q->mdct_ctx[2], 9, 1, -1.0/ (1<<15));
382 init_mdct_windows(); 353
354 ff_sine_window_init(short_window, 32);
383 355
384 atrac_generate_tables(); 356 atrac_generate_tables();
385 357
386 dsputil_init(&q->dsp, avctx); 358 dsputil_init(&q->dsp, avctx);
387 359