[FFmpeg-devel] [PATCH] Simplify IMDCT in dca.c
Michael Niedermayer
michaelni
Sat Aug 30 05:55:07 CEST 2008
Hi
patch below replaces the duplicated IMDCT in dca.c by the standard one.
code is faster, simpler nicer, ....
yes the QMF of dca is a windowed IMDCT
The patch is relative to my last not svn (the patch is smaller that way)
--- dca.ref 2008-08-30 04:14:01.000000000 +0200
+++ dca.c 2008-08-30 05:43:03.000000000 +0200
@@ -177,6 +177,7 @@
int debug_flag; ///< used for suppressing repeated error messages output
DSPContext dsp;
+ MDCTContext imdct;
} DCAContext;
static av_cold void dca_init_vlcs(void)
@@ -656,15 +657,16 @@
float scale, float bias)
{
const float *prCoeff;
- int i, j, k;
+ int i, j;
float praXin[33], *raXin = &praXin[1];
int hist_index= s->hist_index[chans];
float *subband_fir_hist2 = s->subband_fir_noidea[chans];
- int chindex = 0, subindex;
+ int subindex;
praXin[0] = 0.0;
+ scale *= sqrt(1/8.0);
/* Select filter */
if (!s->multirate_inter) /* Non-perfect reconstruction */
@@ -676,39 +678,39 @@
for (subindex = 0; subindex < 8; subindex++) {
float *subband_fir_hist = s->subband_fir_hist[chans] + hist_index;
/* Load in one sample from each subband and clear inactive subbands */
- for (i = 0; i < s->subband_activity[chans]; i++)
- raXin[i] = samples_in[i][subindex];
+ for (i = 0; i < s->subband_activity[chans]; i++){
+ if((i-1)&2) raXin[i] = -samples_in[i][subindex];
+ else raXin[i] = samples_in[i][subindex];
+ }
for (; i < 32; i++)
raXin[i] = 0.0;
- /* Multiply by cosine modulation coefficients and
- * create temporary arrays SUM and DIFF */
- for (j = 0, k = 0; k < 16; k++) {
- float t1 = 0.0;
- float t2 = 0.0;
- for (i = 0; i < 16; i++, j++){
- t1 += (raXin[2 * i] + raXin[2 * i + 1]) * cos_mod[j];
- t2 += (raXin[2 * i] + raXin[2 * i - 1]) * cos_mod[j + 256];
- }
- subband_fir_hist[ k ] = cos_mod[k+512 ] * (t1 + t2);
- subband_fir_hist[32-k-1] = cos_mod[k+512+16] * (t1 - t2);
- }
+ ff_imdct_half(&s->imdct, subband_fir_hist, raXin);
/* Multiply by filter coefficients */
- for (k = 31, i = 0; i < 32; i++, k--){
- float a= subband_fir_hist2[i];
- float b= 0;
+ for (i = 0; i < 16; i++){
+ float a= subband_fir_hist2[i ];
+ float b= subband_fir_hist2[i+16];
+ float c= 0;
+ float d= 0;
for (j = 0; j < 512-hist_index; j += 64){
- a += prCoeff[i+j ]*( subband_fir_hist[i+j] - subband_fir_hist[j+k]);
- b += prCoeff[i+j+32]*(-subband_fir_hist[i+j] - subband_fir_hist[j+k]);
+ a += prCoeff[i+j ]*(-subband_fir_hist[15-i+j]);
+ b += prCoeff[i+j+16]*( subband_fir_hist[ i+j]);
+ c += prCoeff[i+j+32]*( subband_fir_hist[16+i+j]);
+ d += prCoeff[i+j+48]*( subband_fir_hist[31-i+j]);
}
for ( ; j < 512; j += 64){
- a += prCoeff[i+j ]*( subband_fir_hist[i+j-512] - subband_fir_hist[j+k-512]);
- b += prCoeff[i+j+32]*(-subband_fir_hist[i+j-512] - subband_fir_hist[j+k-512]);
+ a += prCoeff[i+j ]*(-subband_fir_hist[15-i+j-512]);
+ b += prCoeff[i+j+16]*( subband_fir_hist[ i+j-512]);
+ c += prCoeff[i+j+32]*( subband_fir_hist[16+i+j-512]);
+ d += prCoeff[i+j+48]*( subband_fir_hist[31-i+j-512]);
}
- samples_out[chindex++] = a * scale + bias;
- subband_fir_hist2[i] = b;
+ samples_out[i ] = a * scale + bias;
+ samples_out[i+16] = b * scale + bias;
+ subband_fir_hist2[i ] = c;
+ subband_fir_hist2[i+16] = d;
}
+ samples_out+= 32;
hist_index = (hist_index-32)&511;
}
@@ -1237,6 +1239,7 @@
pre_calc_cosmod(s);
dsputil_init(&s->dsp, avctx);
+ ff_mdct_init(&s->imdct, 6, 1);
/* allow downmixing to stereo */
if (avctx->channels > 0 && avctx->request_channels < avctx->channels &&
@@ -1249,6 +1252,12 @@
return 0;
}
+static av_cold int dca_decode_end(AVCodecContext * avctx)
+{
+ DCAContext *s = avctx->priv_data;
+ ff_mdct_end(&s->imdct);
+ return 0;
+}
AVCodec dca_decoder = {
.name = "dca",
@@ -1257,5 +1266,6 @@
.priv_data_size = sizeof(DCAContext),
.init = dca_decode_init,
.decode = dca_decode_frame,
+ .close = dca_decode_end,
.long_name = NULL_IF_CONFIG_SMALL("DCA (DTS Coherent Acoustics)"),
};
--
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
I do not agree with what you have to say, but I'll defend to the death your
right to say it. -- Voltaire
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20080830/fb44ed9b/attachment.pgp>
More information about the ffmpeg-devel
mailing list