00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #include <math.h>
00030 #include <stddef.h>
00031 #include <stdio.h>
00032
00033 #include "avcodec.h"
00034 #include "dsputil.h"
00035 #include "bitstream.h"
00036 #include "dcadata.h"
00037 #include "dcahuff.h"
00038 #include "dca.h"
00039
00040
00041
00042 #define DCA_PRIM_CHANNELS_MAX (5)
00043 #define DCA_SUBBANDS (32)
00044 #define DCA_ABITS_MAX (32)
00045 #define DCA_SUBSUBFAMES_MAX (4)
00046 #define DCA_LFE_MAX (3)
00047
00048 enum DCAMode {
00049 DCA_MONO = 0,
00050 DCA_CHANNEL,
00051 DCA_STEREO,
00052 DCA_STEREO_SUMDIFF,
00053 DCA_STEREO_TOTAL,
00054 DCA_3F,
00055 DCA_2F1R,
00056 DCA_3F1R,
00057 DCA_2F2R,
00058 DCA_3F2R,
00059 DCA_4F2R
00060 };
00061
00062 #define DCA_DOLBY 101
00063
00064 #define DCA_CHANNEL_BITS 6
00065 #define DCA_CHANNEL_MASK 0x3F
00066
00067 #define DCA_LFE 0x80
00068
00069 #define HEADER_SIZE 14
00070 #define CONVERT_BIAS 384
00071
00072 #define DCA_MAX_FRAME_SIZE 16383
00073
00074
00075 typedef struct {
00076 int offset;
00077 int maxbits[8];
00078 int wrap;
00079 VLC vlc[8];
00080 } BitAlloc;
00081
00082 static BitAlloc dca_bitalloc_index;
00083 static BitAlloc dca_tmode;
00084 static BitAlloc dca_scalefactor;
00085 static BitAlloc dca_smpl_bitalloc[11];
00086
00087
00088 static float cos_mod[544];
00089
00090 static av_always_inline int get_bitalloc(GetBitContext *gb, BitAlloc *ba, int idx)
00091 {
00092 return get_vlc2(gb, ba->vlc[idx].table, ba->vlc[idx].bits, ba->wrap) + ba->offset;
00093 }
00094
00095 typedef struct {
00096 AVCodecContext *avctx;
00097
00098 int frame_type;
00099 int samples_deficit;
00100 int crc_present;
00101 int sample_blocks;
00102 int frame_size;
00103 int amode;
00104 int sample_rate;
00105 int bit_rate;
00106
00107 int downmix;
00108 int dynrange;
00109 int timestamp;
00110 int aux_data;
00111 int hdcd;
00112 int ext_descr;
00113 int ext_coding;
00114 int aspf;
00115 int lfe;
00116 int predictor_history;
00117 int header_crc;
00118 int multirate_inter;
00119 int version;
00120 int copy_history;
00121 int source_pcm_res;
00122 int front_sum;
00123 int surround_sum;
00124 int dialog_norm;
00125
00126
00127 int subframes;
00128 int total_channels;
00129 int prim_channels;
00130 int subband_activity[DCA_PRIM_CHANNELS_MAX];
00131 int vq_start_subband[DCA_PRIM_CHANNELS_MAX];
00132 int joint_intensity[DCA_PRIM_CHANNELS_MAX];
00133 int transient_huffman[DCA_PRIM_CHANNELS_MAX];
00134 int scalefactor_huffman[DCA_PRIM_CHANNELS_MAX];
00135 int bitalloc_huffman[DCA_PRIM_CHANNELS_MAX];
00136 int quant_index_huffman[DCA_PRIM_CHANNELS_MAX][DCA_ABITS_MAX];
00137 float scalefactor_adj[DCA_PRIM_CHANNELS_MAX][DCA_ABITS_MAX];
00138
00139
00140 int subsubframes;
00141 int partial_samples;
00142 int prediction_mode[DCA_PRIM_CHANNELS_MAX][DCA_SUBBANDS];
00143 int prediction_vq[DCA_PRIM_CHANNELS_MAX][DCA_SUBBANDS];
00144 int bitalloc[DCA_PRIM_CHANNELS_MAX][DCA_SUBBANDS];
00145 int transition_mode[DCA_PRIM_CHANNELS_MAX][DCA_SUBBANDS];
00146 int scale_factor[DCA_PRIM_CHANNELS_MAX][DCA_SUBBANDS][2];
00147 int joint_huff[DCA_PRIM_CHANNELS_MAX];
00148 int joint_scale_factor[DCA_PRIM_CHANNELS_MAX][DCA_SUBBANDS];
00149 int downmix_coef[DCA_PRIM_CHANNELS_MAX][2];
00150 int dynrange_coef;
00151
00152 int high_freq_vq[DCA_PRIM_CHANNELS_MAX][DCA_SUBBANDS];
00153
00154 float lfe_data[2 * DCA_SUBSUBFAMES_MAX * DCA_LFE_MAX *
00155 2 ];
00156 int lfe_scale_factor;
00157
00158
00159 float subband_samples_hist[DCA_PRIM_CHANNELS_MAX][DCA_SUBBANDS][4];
00160 float subband_fir_hist[DCA_PRIM_CHANNELS_MAX][512];
00161 float subband_fir_noidea[DCA_PRIM_CHANNELS_MAX][64];
00162
00163 int output;
00164 int bias;
00165
00166 DECLARE_ALIGNED_16(float, samples[1536]);
00167 DECLARE_ALIGNED_16(int16_t, tsamples[1536]);
00168
00169 uint8_t dca_buffer[DCA_MAX_FRAME_SIZE];
00170 int dca_buffer_size;
00171
00172 GetBitContext gb;
00173
00174 int current_subframe;
00175 int current_subsubframe;
00176
00177 int debug_flag;
00178 DSPContext dsp;
00179 } DCAContext;
00180
00181 static av_cold void dca_init_vlcs(void)
00182 {
00183 static int vlcs_initialized = 0;
00184 int i, j;
00185
00186 if (vlcs_initialized)
00187 return;
00188
00189 dca_bitalloc_index.offset = 1;
00190 dca_bitalloc_index.wrap = 2;
00191 for (i = 0; i < 5; i++)
00192 init_vlc(&dca_bitalloc_index.vlc[i], bitalloc_12_vlc_bits[i], 12,
00193 bitalloc_12_bits[i], 1, 1,
00194 bitalloc_12_codes[i], 2, 2, 1);
00195 dca_scalefactor.offset = -64;
00196 dca_scalefactor.wrap = 2;
00197 for (i = 0; i < 5; i++)
00198 init_vlc(&dca_scalefactor.vlc[i], SCALES_VLC_BITS, 129,
00199 scales_bits[i], 1, 1,
00200 scales_codes[i], 2, 2, 1);
00201 dca_tmode.offset = 0;
00202 dca_tmode.wrap = 1;
00203 for (i = 0; i < 4; i++)
00204 init_vlc(&dca_tmode.vlc[i], tmode_vlc_bits[i], 4,
00205 tmode_bits[i], 1, 1,
00206 tmode_codes[i], 2, 2, 1);
00207
00208 for(i = 0; i < 10; i++)
00209 for(j = 0; j < 7; j++){
00210 if(!bitalloc_codes[i][j]) break;
00211 dca_smpl_bitalloc[i+1].offset = bitalloc_offsets[i];
00212 dca_smpl_bitalloc[i+1].wrap = 1 + (j > 4);
00213 init_vlc(&dca_smpl_bitalloc[i+1].vlc[j], bitalloc_maxbits[i][j],
00214 bitalloc_sizes[i],
00215 bitalloc_bits[i][j], 1, 1,
00216 bitalloc_codes[i][j], 2, 2, 1);
00217 }
00218 vlcs_initialized = 1;
00219 }
00220
00221 static inline void get_array(GetBitContext *gb, int *dst, int len, int bits)
00222 {
00223 while(len--)
00224 *dst++ = get_bits(gb, bits);
00225 }
00226
00227 static int dca_parse_frame_header(DCAContext * s)
00228 {
00229 int i, j;
00230 static const float adj_table[4] = { 1.0, 1.1250, 1.2500, 1.4375 };
00231 static const int bitlen[11] = { 0, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3 };
00232 static const int thr[11] = { 0, 1, 3, 3, 3, 3, 7, 7, 7, 7, 7 };
00233
00234 s->bias = CONVERT_BIAS;
00235
00236 init_get_bits(&s->gb, s->dca_buffer, s->dca_buffer_size * 8);
00237
00238
00239 get_bits(&s->gb, 32);
00240
00241
00242 s->frame_type = get_bits(&s->gb, 1);
00243 s->samples_deficit = get_bits(&s->gb, 5) + 1;
00244 s->crc_present = get_bits(&s->gb, 1);
00245 s->sample_blocks = get_bits(&s->gb, 7) + 1;
00246 s->frame_size = get_bits(&s->gb, 14) + 1;
00247 if (s->frame_size < 95)
00248 return -1;
00249 s->amode = get_bits(&s->gb, 6);
00250 s->sample_rate = dca_sample_rates[get_bits(&s->gb, 4)];
00251 if (!s->sample_rate)
00252 return -1;
00253 s->bit_rate = dca_bit_rates[get_bits(&s->gb, 5)];
00254 if (!s->bit_rate)
00255 return -1;
00256
00257 s->downmix = get_bits(&s->gb, 1);
00258 s->dynrange = get_bits(&s->gb, 1);
00259 s->timestamp = get_bits(&s->gb, 1);
00260 s->aux_data = get_bits(&s->gb, 1);
00261 s->hdcd = get_bits(&s->gb, 1);
00262 s->ext_descr = get_bits(&s->gb, 3);
00263 s->ext_coding = get_bits(&s->gb, 1);
00264 s->aspf = get_bits(&s->gb, 1);
00265 s->lfe = get_bits(&s->gb, 2);
00266 s->predictor_history = get_bits(&s->gb, 1);
00267
00268
00269 if (s->crc_present)
00270 s->header_crc = get_bits(&s->gb, 16);
00271
00272 s->multirate_inter = get_bits(&s->gb, 1);
00273 s->version = get_bits(&s->gb, 4);
00274 s->copy_history = get_bits(&s->gb, 2);
00275 s->source_pcm_res = get_bits(&s->gb, 3);
00276 s->front_sum = get_bits(&s->gb, 1);
00277 s->surround_sum = get_bits(&s->gb, 1);
00278 s->dialog_norm = get_bits(&s->gb, 4);
00279
00280
00281 s->output = s->amode;
00282 if(s->lfe) s->output |= DCA_LFE;
00283
00284 #ifdef TRACE
00285 av_log(s->avctx, AV_LOG_DEBUG, "frame type: %i\n", s->frame_type);
00286 av_log(s->avctx, AV_LOG_DEBUG, "samples deficit: %i\n", s->samples_deficit);
00287 av_log(s->avctx, AV_LOG_DEBUG, "crc present: %i\n", s->crc_present);
00288 av_log(s->avctx, AV_LOG_DEBUG, "sample blocks: %i (%i samples)\n",
00289 s->sample_blocks, s->sample_blocks * 32);
00290 av_log(s->avctx, AV_LOG_DEBUG, "frame size: %i bytes\n", s->frame_size);
00291 av_log(s->avctx, AV_LOG_DEBUG, "amode: %i (%i channels)\n",
00292 s->amode, dca_channels[s->amode]);
00293 av_log(s->avctx, AV_LOG_DEBUG, "sample rate: %i (%i Hz)\n",
00294 s->sample_rate, dca_sample_rates[s->sample_rate]);
00295 av_log(s->avctx, AV_LOG_DEBUG, "bit rate: %i (%i bits/s)\n",
00296 s->bit_rate, dca_bit_rates[s->bit_rate]);
00297 av_log(s->avctx, AV_LOG_DEBUG, "downmix: %i\n", s->downmix);
00298 av_log(s->avctx, AV_LOG_DEBUG, "dynrange: %i\n", s->dynrange);
00299 av_log(s->avctx, AV_LOG_DEBUG, "timestamp: %i\n", s->timestamp);
00300 av_log(s->avctx, AV_LOG_DEBUG, "aux_data: %i\n", s->aux_data);
00301 av_log(s->avctx, AV_LOG_DEBUG, "hdcd: %i\n", s->hdcd);
00302 av_log(s->avctx, AV_LOG_DEBUG, "ext descr: %i\n", s->ext_descr);
00303 av_log(s->avctx, AV_LOG_DEBUG, "ext coding: %i\n", s->ext_coding);
00304 av_log(s->avctx, AV_LOG_DEBUG, "aspf: %i\n", s->aspf);
00305 av_log(s->avctx, AV_LOG_DEBUG, "lfe: %i\n", s->lfe);
00306 av_log(s->avctx, AV_LOG_DEBUG, "predictor history: %i\n",
00307 s->predictor_history);
00308 av_log(s->avctx, AV_LOG_DEBUG, "header crc: %i\n", s->header_crc);
00309 av_log(s->avctx, AV_LOG_DEBUG, "multirate inter: %i\n",
00310 s->multirate_inter);
00311 av_log(s->avctx, AV_LOG_DEBUG, "version number: %i\n", s->version);
00312 av_log(s->avctx, AV_LOG_DEBUG, "copy history: %i\n", s->copy_history);
00313 av_log(s->avctx, AV_LOG_DEBUG,
00314 "source pcm resolution: %i (%i bits/sample)\n",
00315 s->source_pcm_res, dca_bits_per_sample[s->source_pcm_res]);
00316 av_log(s->avctx, AV_LOG_DEBUG, "front sum: %i\n", s->front_sum);
00317 av_log(s->avctx, AV_LOG_DEBUG, "surround sum: %i\n", s->surround_sum);
00318 av_log(s->avctx, AV_LOG_DEBUG, "dialog norm: %i\n", s->dialog_norm);
00319 av_log(s->avctx, AV_LOG_DEBUG, "\n");
00320 #endif
00321
00322
00323 s->subframes = get_bits(&s->gb, 4) + 1;
00324 s->total_channels = get_bits(&s->gb, 3) + 1;
00325 s->prim_channels = s->total_channels;
00326 if (s->prim_channels > DCA_PRIM_CHANNELS_MAX)
00327 s->prim_channels = DCA_PRIM_CHANNELS_MAX;
00328
00329
00330 for (i = 0; i < s->prim_channels; i++) {
00331 s->subband_activity[i] = get_bits(&s->gb, 5) + 2;
00332 if (s->subband_activity[i] > DCA_SUBBANDS)
00333 s->subband_activity[i] = DCA_SUBBANDS;
00334 }
00335 for (i = 0; i < s->prim_channels; i++) {
00336 s->vq_start_subband[i] = get_bits(&s->gb, 5) + 1;
00337 if (s->vq_start_subband[i] > DCA_SUBBANDS)
00338 s->vq_start_subband[i] = DCA_SUBBANDS;
00339 }
00340 get_array(&s->gb, s->joint_intensity, s->prim_channels, 3);
00341 get_array(&s->gb, s->transient_huffman, s->prim_channels, 2);
00342 get_array(&s->gb, s->scalefactor_huffman, s->prim_channels, 3);
00343 get_array(&s->gb, s->bitalloc_huffman, s->prim_channels, 3);
00344
00345
00346 memset(s->quant_index_huffman, 0, sizeof(s->quant_index_huffman));
00347 for (j = 1; j < 11; j++)
00348 for (i = 0; i < s->prim_channels; i++)
00349 s->quant_index_huffman[i][j] = get_bits(&s->gb, bitlen[j]);
00350
00351
00352 for (j = 0; j < 11; j++)
00353 for (i = 0; i < s->prim_channels; i++)
00354 s->scalefactor_adj[i][j] = 1;
00355
00356 for (j = 1; j < 11; j++)
00357 for (i = 0; i < s->prim_channels; i++)
00358 if (s->quant_index_huffman[i][j] < thr[j])
00359 s->scalefactor_adj[i][j] = adj_table[get_bits(&s->gb, 2)];
00360
00361 if (s->crc_present) {
00362
00363 get_bits(&s->gb, 16);
00364 }
00365
00366 s->current_subframe = 0;
00367 s->current_subsubframe = 0;
00368
00369 #ifdef TRACE
00370 av_log(s->avctx, AV_LOG_DEBUG, "subframes: %i\n", s->subframes);
00371 av_log(s->avctx, AV_LOG_DEBUG, "prim channels: %i\n", s->prim_channels);
00372 for(i = 0; i < s->prim_channels; i++){
00373 av_log(s->avctx, AV_LOG_DEBUG, "subband activity: %i\n", s->subband_activity[i]);
00374 av_log(s->avctx, AV_LOG_DEBUG, "vq start subband: %i\n", s->vq_start_subband[i]);
00375 av_log(s->avctx, AV_LOG_DEBUG, "joint intensity: %i\n", s->joint_intensity[i]);
00376 av_log(s->avctx, AV_LOG_DEBUG, "transient mode codebook: %i\n", s->transient_huffman[i]);
00377 av_log(s->avctx, AV_LOG_DEBUG, "scale factor codebook: %i\n", s->scalefactor_huffman[i]);
00378 av_log(s->avctx, AV_LOG_DEBUG, "bit allocation quantizer: %i\n", s->bitalloc_huffman[i]);
00379 av_log(s->avctx, AV_LOG_DEBUG, "quant index huff:");
00380 for (j = 0; j < 11; j++)
00381 av_log(s->avctx, AV_LOG_DEBUG, " %i",
00382 s->quant_index_huffman[i][j]);
00383 av_log(s->avctx, AV_LOG_DEBUG, "\n");
00384 av_log(s->avctx, AV_LOG_DEBUG, "scalefac adj:");
00385 for (j = 0; j < 11; j++)
00386 av_log(s->avctx, AV_LOG_DEBUG, " %1.3f", s->scalefactor_adj[i][j]);
00387 av_log(s->avctx, AV_LOG_DEBUG, "\n");
00388 }
00389 #endif
00390
00391 return 0;
00392 }
00393
00394
00395 static inline int get_scale(GetBitContext *gb, int level, int value)
00396 {
00397 if (level < 5) {
00398
00399 value += get_bitalloc(gb, &dca_scalefactor, level);
00400 } else if(level < 8)
00401 value = get_bits(gb, level + 1);
00402 return value;
00403 }
00404
00405 static int dca_subframe_header(DCAContext * s)
00406 {
00407
00408 int j, k;
00409
00410 s->subsubframes = get_bits(&s->gb, 2) + 1;
00411 s->partial_samples = get_bits(&s->gb, 3);
00412 for (j = 0; j < s->prim_channels; j++) {
00413 for (k = 0; k < s->subband_activity[j]; k++)
00414 s->prediction_mode[j][k] = get_bits(&s->gb, 1);
00415 }
00416
00417
00418 for (j = 0; j < s->prim_channels; j++) {
00419 for (k = 0; k < s->subband_activity[j]; k++) {
00420 if (s->prediction_mode[j][k] > 0) {
00421
00422 s->prediction_vq[j][k] = get_bits(&s->gb, 12);
00423 }
00424 }
00425 }
00426
00427
00428 for (j = 0; j < s->prim_channels; j++) {
00429 for (k = 0; k < s->vq_start_subband[j]; k++) {
00430 if (s->bitalloc_huffman[j] == 6)
00431 s->bitalloc[j][k] = get_bits(&s->gb, 5);
00432 else if (s->bitalloc_huffman[j] == 5)
00433 s->bitalloc[j][k] = get_bits(&s->gb, 4);
00434 else if (s->bitalloc_huffman[j] == 7) {
00435 av_log(s->avctx, AV_LOG_ERROR,
00436 "Invalid bit allocation index\n");
00437 return -1;
00438 } else {
00439 s->bitalloc[j][k] =
00440 get_bitalloc(&s->gb, &dca_bitalloc_index, s->bitalloc_huffman[j]);
00441 }
00442
00443 if (s->bitalloc[j][k] > 26) {
00444
00445
00446 return -1;
00447 }
00448 }
00449 }
00450
00451
00452 for (j = 0; j < s->prim_channels; j++) {
00453 for (k = 0; k < s->subband_activity[j]; k++) {
00454 s->transition_mode[j][k] = 0;
00455 if (s->subsubframes > 1 &&
00456 k < s->vq_start_subband[j] && s->bitalloc[j][k] > 0) {
00457 s->transition_mode[j][k] =
00458 get_bitalloc(&s->gb, &dca_tmode, s->transient_huffman[j]);
00459 }
00460 }
00461 }
00462
00463 for (j = 0; j < s->prim_channels; j++) {
00464 const uint32_t *scale_table;
00465 int scale_sum;
00466
00467 memset(s->scale_factor[j], 0, s->subband_activity[j] * sizeof(s->scale_factor[0][0][0]) * 2);
00468
00469 if (s->scalefactor_huffman[j] == 6)
00470 scale_table = scale_factor_quant7;
00471 else
00472 scale_table = scale_factor_quant6;
00473
00474
00475 scale_sum = 0;
00476
00477 for (k = 0; k < s->subband_activity[j]; k++) {
00478 if (k >= s->vq_start_subband[j] || s->bitalloc[j][k] > 0) {
00479 scale_sum = get_scale(&s->gb, s->scalefactor_huffman[j], scale_sum);
00480 s->scale_factor[j][k][0] = scale_table[scale_sum];
00481 }
00482
00483 if (k < s->vq_start_subband[j] && s->transition_mode[j][k]) {
00484
00485 scale_sum = get_scale(&s->gb, s->scalefactor_huffman[j], scale_sum);
00486 s->scale_factor[j][k][1] = scale_table[scale_sum];
00487 }
00488 }
00489 }
00490
00491
00492 for (j = 0; j < s->prim_channels; j++) {
00493
00494 if (s->joint_intensity[j] > 0)
00495 s->joint_huff[j] = get_bits(&s->gb, 3);
00496 }
00497
00498
00499 for (j = 0; j < s->prim_channels; j++) {
00500 int source_channel;
00501
00502
00503 if (s->joint_intensity[j] > 0) {
00504 int scale = 0;
00505 source_channel = s->joint_intensity[j] - 1;
00506
00507
00508
00509
00510 for (k = s->subband_activity[j]; k < s->subband_activity[source_channel]; k++) {
00511 scale = get_scale(&s->gb, s->joint_huff[j], 0);
00512 scale += 64;
00513 s->joint_scale_factor[j][k] = scale;
00514 }
00515
00516 if (!s->debug_flag & 0x02) {
00517 av_log(s->avctx, AV_LOG_DEBUG,
00518 "Joint stereo coding not supported\n");
00519 s->debug_flag |= 0x02;
00520 }
00521 }
00522 }
00523
00524
00525 if (s->prim_channels > 2) {
00526 if(s->downmix) {
00527 for (j = 0; j < s->prim_channels; j++) {
00528 s->downmix_coef[j][0] = get_bits(&s->gb, 7);
00529 s->downmix_coef[j][1] = get_bits(&s->gb, 7);
00530 }
00531 } else {
00532 int am = s->amode & DCA_CHANNEL_MASK;
00533 for (j = 0; j < s->prim_channels; j++) {
00534 s->downmix_coef[j][0] = dca_default_coeffs[am][j][0];
00535 s->downmix_coef[j][1] = dca_default_coeffs[am][j][1];
00536 }
00537 }
00538 }
00539
00540
00541 if (s->dynrange)
00542 s->dynrange_coef = get_bits(&s->gb, 8);
00543
00544
00545 if (s->crc_present) {
00546 get_bits(&s->gb, 16);
00547 }
00548
00549
00550
00551
00552
00553
00554 for (j = 0; j < s->prim_channels; j++)
00555 for (k = s->vq_start_subband[j]; k < s->subband_activity[j]; k++)
00556
00557 s->high_freq_vq[j][k] = get_bits(&s->gb, 10);
00558
00559
00560 if (s->lfe) {
00561
00562 int lfe_samples = 2 * s->lfe * s->subsubframes;
00563 float lfe_scale;
00564
00565 for (j = lfe_samples; j < lfe_samples * 2; j++) {
00566
00567 s->lfe_data[j] = get_sbits(&s->gb, 8);
00568 }
00569
00570
00571 s->lfe_scale_factor = scale_factor_quant7[get_bits(&s->gb, 8)];
00572
00573
00574 lfe_scale = 0.035 * s->lfe_scale_factor;
00575
00576 for (j = lfe_samples; j < lfe_samples * 2; j++)
00577 s->lfe_data[j] *= lfe_scale;
00578 }
00579
00580 #ifdef TRACE
00581 av_log(s->avctx, AV_LOG_DEBUG, "subsubframes: %i\n", s->subsubframes);
00582 av_log(s->avctx, AV_LOG_DEBUG, "partial samples: %i\n",
00583 s->partial_samples);
00584 for (j = 0; j < s->prim_channels; j++) {
00585 av_log(s->avctx, AV_LOG_DEBUG, "prediction mode:");
00586 for (k = 0; k < s->subband_activity[j]; k++)
00587 av_log(s->avctx, AV_LOG_DEBUG, " %i", s->prediction_mode[j][k]);
00588 av_log(s->avctx, AV_LOG_DEBUG, "\n");
00589 }
00590 for (j = 0; j < s->prim_channels; j++) {
00591 for (k = 0; k < s->subband_activity[j]; k++)
00592 av_log(s->avctx, AV_LOG_DEBUG,
00593 "prediction coefs: %f, %f, %f, %f\n",
00594 (float) adpcm_vb[s->prediction_vq[j][k]][0] / 8192,
00595 (float) adpcm_vb[s->prediction_vq[j][k]][1] / 8192,
00596 (float) adpcm_vb[s->prediction_vq[j][k]][2] / 8192,
00597 (float) adpcm_vb[s->prediction_vq[j][k]][3] / 8192);
00598 }
00599 for (j = 0; j < s->prim_channels; j++) {
00600 av_log(s->avctx, AV_LOG_DEBUG, "bitalloc index: ");
00601 for (k = 0; k < s->vq_start_subband[j]; k++)
00602 av_log(s->avctx, AV_LOG_DEBUG, "%2.2i ", s->bitalloc[j][k]);
00603 av_log(s->avctx, AV_LOG_DEBUG, "\n");
00604 }
00605 for (j = 0; j < s->prim_channels; j++) {
00606 av_log(s->avctx, AV_LOG_DEBUG, "Transition mode:");
00607 for (k = 0; k < s->subband_activity[j]; k++)
00608 av_log(s->avctx, AV_LOG_DEBUG, " %i", s->transition_mode[j][k]);
00609 av_log(s->avctx, AV_LOG_DEBUG, "\n");
00610 }
00611 for (j = 0; j < s->prim_channels; j++) {
00612 av_log(s->avctx, AV_LOG_DEBUG, "Scale factor:");
00613 for (k = 0; k < s->subband_activity[j]; k++) {
00614 if (k >= s->vq_start_subband[j] || s->bitalloc[j][k] > 0)
00615 av_log(s->avctx, AV_LOG_DEBUG, " %i", s->scale_factor[j][k][0]);
00616 if (k < s->vq_start_subband[j] && s->transition_mode[j][k])
00617 av_log(s->avctx, AV_LOG_DEBUG, " %i(t)", s->scale_factor[j][k][1]);
00618 }
00619 av_log(s->avctx, AV_LOG_DEBUG, "\n");
00620 }
00621 for (j = 0; j < s->prim_channels; j++) {
00622 if (s->joint_intensity[j] > 0) {
00623 int source_channel = s->joint_intensity[j] - 1;
00624 av_log(s->avctx, AV_LOG_DEBUG, "Joint scale factor index:\n");
00625 for (k = s->subband_activity[j]; k < s->subband_activity[source_channel]; k++)
00626 av_log(s->avctx, AV_LOG_DEBUG, " %i", s->joint_scale_factor[j][k]);
00627 av_log(s->avctx, AV_LOG_DEBUG, "\n");
00628 }
00629 }
00630 if (s->prim_channels > 2 && s->downmix) {
00631 av_log(s->avctx, AV_LOG_DEBUG, "Downmix coeffs:\n");
00632 for (j = 0; j < s->prim_channels; j++) {
00633 av_log(s->avctx, AV_LOG_DEBUG, "Channel 0,%d = %f\n", j, dca_downmix_coeffs[s->downmix_coef[j][0]]);
00634 av_log(s->avctx, AV_LOG_DEBUG, "Channel 1,%d = %f\n", j, dca_downmix_coeffs[s->downmix_coef[j][1]]);
00635 }
00636 av_log(s->avctx, AV_LOG_DEBUG, "\n");
00637 }
00638 for (j = 0; j < s->prim_channels; j++)
00639 for (k = s->vq_start_subband[j]; k < s->subband_activity[j]; k++)
00640 av_log(s->avctx, AV_LOG_DEBUG, "VQ index: %i\n", s->high_freq_vq[j][k]);
00641 if(s->lfe){
00642 int lfe_samples = 2 * s->lfe * s->subsubframes;
00643 av_log(s->avctx, AV_LOG_DEBUG, "LFE samples:\n");
00644 for (j = lfe_samples; j < lfe_samples * 2; j++)
00645 av_log(s->avctx, AV_LOG_DEBUG, " %f", s->lfe_data[j]);
00646 av_log(s->avctx, AV_LOG_DEBUG, "\n");
00647 }
00648 #endif
00649
00650 return 0;
00651 }
00652
00653 static void qmf_32_subbands(DCAContext * s, int chans,
00654 float samples_in[32][8], float *samples_out,
00655 float scale, float bias)
00656 {
00657 const float *prCoeff;
00658 int i, j, k;
00659 float praXin[33], *raXin = &praXin[1];
00660
00661 float *subband_fir_hist = s->subband_fir_hist[chans];
00662 float *subband_fir_hist2 = s->subband_fir_noidea[chans];
00663
00664 int chindex = 0, subindex;
00665
00666 praXin[0] = 0.0;
00667
00668
00669 if (!s->multirate_inter)
00670 prCoeff = fir_32bands_nonperfect;
00671 else
00672 prCoeff = fir_32bands_perfect;
00673
00674
00675 for (subindex = 0; subindex < 8; subindex++) {
00676 float t1, t2, sum[16], diff[16];
00677
00678
00679 for (i = 0; i < s->subband_activity[chans]; i++)
00680 raXin[i] = samples_in[i][subindex];
00681 for (; i < 32; i++)
00682 raXin[i] = 0.0;
00683
00684
00685
00686 for (j = 0, k = 0; k < 16; k++) {
00687 t1 = 0.0;
00688 t2 = 0.0;
00689 for (i = 0; i < 16; i++, j++){
00690 t1 += (raXin[2 * i] + raXin[2 * i + 1]) * cos_mod[j];
00691 t2 += (raXin[2 * i] + raXin[2 * i - 1]) * cos_mod[j + 256];
00692 }
00693 sum[k] = t1 + t2;
00694 diff[k] = t1 - t2;
00695 }
00696
00697 j = 512;
00698
00699 for (k = 0; k < 16; k++)
00700 subband_fir_hist[k] = cos_mod[j++] * sum[k];
00701 for (k = 0; k < 16; k++)
00702 subband_fir_hist[32-k-1] = cos_mod[j++] * diff[k];
00703
00704
00705 for (k = 31, i = 0; i < 32; i++, k--)
00706 for (j = 0; j < 512; j += 64){
00707 subband_fir_hist2[i] += prCoeff[i+j] * ( subband_fir_hist[i+j] - subband_fir_hist[j+k]);
00708 subband_fir_hist2[i+32] += prCoeff[i+j+32]*(-subband_fir_hist[i+j] - subband_fir_hist[j+k]);
00709 }
00710
00711
00712 for (i = 0; i < 32; i++)
00713 samples_out[chindex++] = subband_fir_hist2[i] * scale + bias;
00714
00715
00716 memmove(&subband_fir_hist[32], &subband_fir_hist[0], (512 - 32) * sizeof(float));
00717 memmove(&subband_fir_hist2[0], &subband_fir_hist2[32], 32 * sizeof(float));
00718 memset(&subband_fir_hist2[32], 0, 32 * sizeof(float));
00719 }
00720 }
00721
00722 static void lfe_interpolation_fir(int decimation_select,
00723 int num_deci_sample, float *samples_in,
00724 float *samples_out, float scale,
00725 float bias)
00726 {
00727
00728
00729
00730
00731
00732
00733
00734
00735 int decifactor, k, j;
00736 const float *prCoeff;
00737
00738 int interp_index = 0;
00739 int deciindex;
00740
00741
00742 if (decimation_select == 1) {
00743 decifactor = 128;
00744 prCoeff = lfe_fir_128;
00745 } else {
00746 decifactor = 64;
00747 prCoeff = lfe_fir_64;
00748 }
00749
00750 for (deciindex = 0; deciindex < num_deci_sample; deciindex++) {
00751
00752 for (k = 0; k < decifactor; k++) {
00753 float rTmp = 0.0;
00754
00755 for (j = 0; j < 512 / decifactor; j++)
00756 rTmp += samples_in[deciindex - j] * prCoeff[k + j * decifactor];
00757 samples_out[interp_index++] = rTmp / scale + bias;
00758 }
00759 }
00760 }
00761
00762
00763 #define MIX_REAR1(samples, si1, rs, coef) \
00764 samples[i] += samples[si1] * coef[rs][0]; \
00765 samples[i+256] += samples[si1] * coef[rs][1];
00766
00767 #define MIX_REAR2(samples, si1, si2, rs, coef) \
00768 samples[i] += samples[si1] * coef[rs][0] + samples[si2] * coef[rs+1][0]; \
00769 samples[i+256] += samples[si1] * coef[rs][1] + samples[si2] * coef[rs+1][1];
00770
00771 #define MIX_FRONT3(samples, coef) \
00772 t = samples[i]; \
00773 samples[i] = t * coef[0][0] + samples[i+256] * coef[1][0] + samples[i+512] * coef[2][0]; \
00774 samples[i+256] = t * coef[0][1] + samples[i+256] * coef[1][1] + samples[i+512] * coef[2][1];
00775
00776 #define DOWNMIX_TO_STEREO(op1, op2) \
00777 for(i = 0; i < 256; i++){ \
00778 op1 \
00779 op2 \
00780 }
00781
00782 static void dca_downmix(float *samples, int srcfmt,
00783 int downmix_coef[DCA_PRIM_CHANNELS_MAX][2])
00784 {
00785 int i;
00786 float t;
00787 float coef[DCA_PRIM_CHANNELS_MAX][2];
00788
00789 for(i=0; i<DCA_PRIM_CHANNELS_MAX; i++) {
00790 coef[i][0] = dca_downmix_coeffs[downmix_coef[i][0]];
00791 coef[i][1] = dca_downmix_coeffs[downmix_coef[i][1]];
00792 }
00793
00794 switch (srcfmt) {
00795 case DCA_MONO:
00796 case DCA_CHANNEL:
00797 case DCA_STEREO_TOTAL:
00798 case DCA_STEREO_SUMDIFF:
00799 case DCA_4F2R:
00800 av_log(NULL, 0, "Not implemented!\n");
00801 break;
00802 case DCA_STEREO:
00803 break;
00804 case DCA_3F:
00805 DOWNMIX_TO_STEREO(MIX_FRONT3(samples, coef),);
00806 break;
00807 case DCA_2F1R:
00808 DOWNMIX_TO_STEREO(MIX_REAR1(samples, i + 512, 2, coef),);
00809 break;
00810 case DCA_3