#include <stddef.h>
#include <stdio.h>
+#include "libavutil/intmath.h"
+#include "libavutil/intreadwrite.h"
#include "avcodec.h"
#include "dsputil.h"
+#include "fft.h"
#include "get_bits.h"
#include "put_bits.h"
#include "dcadata.h"
#include "dcahuff.h"
#include "dca.h"
+#include "synth_filter.h"
//#define TRACE
/* Subband samples history (for ADPCM) */
float subband_samples_hist[DCA_PRIM_CHANNELS_MAX][DCA_SUBBANDS][4];
- DECLARE_ALIGNED_16(float, subband_fir_hist[DCA_PRIM_CHANNELS_MAX][512]);
- float subband_fir_noidea[DCA_PRIM_CHANNELS_MAX][32];
+ DECLARE_ALIGNED(16, float, subband_fir_hist)[DCA_PRIM_CHANNELS_MAX][512];
+ DECLARE_ALIGNED(16, float, subband_fir_noidea)[DCA_PRIM_CHANNELS_MAX][32];
int hist_index[DCA_PRIM_CHANNELS_MAX];
- DECLARE_ALIGNED_16(float, raXin[32]);
+ DECLARE_ALIGNED(16, float, raXin)[32];
int output; ///< type of output
float add_bias; ///< output bias
float scale_bias; ///< output scale
- DECLARE_ALIGNED_16(float, samples[1536]); /* 6 * 256 = 1536, might only need 5 */
+ DECLARE_ALIGNED(16, float, samples)[1536]; /* 6 * 256 = 1536, might only need 5 */
const float *samples_chanptr[6];
uint8_t dca_buffer[DCA_MAX_FRAME_SIZE];
int debug_flag; ///< used for suppressing repeated error messages output
DSPContext dsp;
FFTContext imdct;
+ SynthFilterContext synth;
} DCAContext;
static const uint16_t dca_vlc_offs[] = {
s->joint_scale_factor[j][k] = scale; /*joint_scale_table[scale]; */
}
- if (!s->debug_flag & 0x02) {
+ if (!(s->debug_flag & 0x02)) {
av_log(s->avctx, AV_LOG_DEBUG,
"Joint stereo coding not supported\n");
s->debug_flag |= 0x02;
float scale, float bias)
{
const float *prCoeff;
- int i, j;
-
- int hist_index= s->hist_index[chans];
- float *subband_fir_hist2 = s->subband_fir_noidea[chans];
+ int i;
+ int sb_act = s->subband_activity[chans];
int subindex;
scale *= sqrt(1/8.0);
/* Reconstructed channel sample index */
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++){
- if((i-1)&2) s->raXin[i] = -samples_in[i][subindex];
- else s->raXin[i] = samples_in[i][subindex];
+ for (i = 0; i < sb_act; i++){
+ uint32_t v = AV_RN32A(&samples_in[i][subindex]) ^ ((i-1)&2)<<30;
+ AV_WN32A(&s->raXin[i], v);
}
for (; i < 32; i++)
s->raXin[i] = 0.0;
- ff_imdct_half(&s->imdct, subband_fir_hist, s->raXin);
-
- /* Multiply by filter coefficients */
- 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[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[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[i ] = a * scale + bias;
- samples_out[i+16] = b * scale + bias;
- subband_fir_hist2[i ] = c;
- subband_fir_hist2[i+16] = d;
- }
+ s->synth.synth_filter_float(&s->imdct,
+ s->subband_fir_hist[chans], &s->hist_index[chans],
+ s->subband_fir_noidea[chans], prCoeff,
+ samples_out, s->raXin, scale, bias);
samples_out+= 32;
- hist_index = (hist_index-32)&511;
}
- s->hist_index[chans]= hist_index;
}
static void lfe_interpolation_fir(int decimation_select,
int decifactor, k, j;
const float *prCoeff;
-
- int interp_index = 0; /* Index to the interpolated samples */
int deciindex;
/* Select decimation filter */
if (decimation_select == 1) {
- decifactor = 128;
+ decifactor = 64;
prCoeff = lfe_fir_128;
} else {
- decifactor = 64;
+ decifactor = 32;
prCoeff = lfe_fir_64;
}
/* Interpolation */
for (deciindex = 0; deciindex < num_deci_sample; deciindex++) {
- /* One decimated sample generates decifactor interpolated ones */
+ float *samples_out2 = samples_out + decifactor;
+ const float *cf0 = prCoeff;
+ const float *cf1 = prCoeff + 256;
+
+ /* One decimated sample generates 2*decifactor interpolated ones */
for (k = 0; k < decifactor; k++) {
- float rTmp = 0.0;
- //FIXME the coeffs are symetric, fix that
- for (j = 0; j < 512 / decifactor; j++)
- rTmp += samples_in[deciindex - j] * prCoeff[k + j * decifactor];
- samples_out[interp_index++] = (rTmp * scale) + bias;
+ float v0 = 0.0;
+ float v1 = 0.0;
+ for (j = 0; j < 256 / decifactor; j++) {
+ float s = samples_in[-j];
+ v0 += s * *cf0++;
+ v1 += s * *--cf1;
+ }
+ *samples_out++ = (v0 * scale) + bias;
+ *samples_out2++ = (v1 * scale) + bias;
}
+
+ samples_in++;
+ samples_out += decifactor;
}
}
int offset = (levels - 1) >> 1;
for (i = 0; i < 4; i++) {
- values[i] = (code % levels) - offset;
- code /= levels;
+ int div = FASTDIV(code, levels);
+ values[i] = code - offset - div*levels;
+ code = div;
}
if (code == 0)
} else
s->channel_order_tab = dca_channel_reorder_nolfe[s->amode];
+ if (s->prim_channels > 0 &&
+ s->channel_order_tab[s->prim_channels - 1] < 0)
+ return -1;
+
if(avctx->request_channels == 2 && s->prim_channels > 2) {
channels = 2;
s->output = DCA_STEREO;
dsputil_init(&s->dsp, avctx);
ff_mdct_init(&s->imdct, 6, 1, 1.0);
+ ff_synth_filter_init(&s->synth);
for(i = 0; i < 6; i++)
s->samples_chanptr[i] = s->samples + i * 256;
AVCodec dca_decoder = {
.name = "dca",
- .type = CODEC_TYPE_AUDIO,
+ .type = AVMEDIA_TYPE_AUDIO,
.id = CODEC_ID_DTS,
.priv_data_size = sizeof(DCAContext),
.init = dca_decode_init,