35 #define MAX_CHANNELS 6
36 #define DCA_MAX_FRAME_SIZE 16384
37 #define DCA_HEADER_SIZE 13
38 #define DCA_LFE_SAMPLES 8
40 #define DCAENC_SUBBANDS 32
42 #define SUBSUBFRAMES 2
43 #define SUBBAND_SAMPLES (SUBFRAMES * SUBSUBFRAMES * 8)
87 static double hom(
double f)
91 return -3.64 * pow(f1, -0.8)
92 + 6.8 * exp(-0.6 * (f1 - 3.4) * (f1 - 3.4))
93 - 6.0 * exp(-0.15 * (f1 - 8.7) * (f1 - 8.7))
94 - 0.0006 * (f1 * f1) * (f1 * f1);
99 double h = (f -
fc[i]) /
erb[i];
103 return 20 * log10(h);
110 int i, min_frame_bits;
121 "encoder will guess the layout, but it "
122 "might be incorrect.\n");
139 for (i = 0; i < 9; i++) {
167 for (i = 0; i < 2048; i++) {
173 for (i = 0; i < 256; i++) {
178 for (i = 0; i < 512; i++) {
183 for (i = 0; i < 9; i++) {
184 for (j = 0; j <
AUBANDS; j++) {
185 for (k = 0; k < 256; k++) {
193 for (i = 0; i < 256; i++) {
194 double add = 1 + pow(10, -0.01 * i);
197 for (j = 0; j < 8; j++) {
199 for (i = 0; i < 512; i++) {
201 accum += reconst * cos(2 *
M_PI * (i + 0.5 - 256) * (j + 0.5) / 512);
205 for (j = 0; j < 8; j++) {
207 for (i = 0; i < 512; i++) {
209 accum += reconst * cos(2 *
M_PI * (i + 0.5 - 256) * (j + 0.5) / 512);
224 return cos_t(x - 512);
234 int64_t
r = (int64_t)a * b + 0x80000000ULL;
240 int ch, subs, i, k, j;
247 for (i = 0; i < 512; i++)
256 for (i = 0; i < 64; i++)
259 for (k = 0, i = hist_start, j = 0;
260 i < 512; k = (k + 1) & 63, i++, j++)
262 for (i = 0; i < hist_start; k = (k + 1) & 63, i++, j++)
265 for (k = 16; k < 32; k++)
266 accum[k] = accum[k] - accum[31 - k];
267 for (k = 32; k < 48; k++)
268 accum[k] = accum[k] + accum[95 - k];
270 for (band = 0; band < 32; band++) {
272 for (i = 16; i < 48; i++) {
273 int s = (2 * band + 1) * (2 * (i + 16) + 1);
277 c->
subband[subs][
band][ch] = ((band + 1) & 2) ? -resp : resp;
281 for (i = 0; i < 32; i++)
282 hist[i + hist_start] = input[(subs * 32 + i) * c->
channels + ch];
283 hist_start = (hist_start + 32) & 511;
296 for (i = 0; i < 512; i++)
303 for (i = hist_start, j = 0; i < 512; i++, j++)
305 for (i = 0; i < hist_start; i++, j++)
311 for (i = 0; i < 64; i++)
312 hist[i + hist_start] = input[(lfes * 64 + i) * c->
channels + c->
channels - 1];
314 hist_start = (hist_start + 64) & 511;
329 for (i = 0; i < 256; i++) {
331 rin[i].
re =
mul32(in[2 * i], 0x3fffffff - (
cos_t(8 * i + 2) >> 1));
332 rin[i].
im =
mul32(in[2 * i + 1], 0x3fffffff - (
cos_t(8 * i + 6) >> 1));
335 for (i = 0; i < 256; i++) {
342 for (j = 256, l = 1; j != 1; j >>= 1, l <<= 1) {
343 for (k = 0; k < 256; k += j) {
344 for (i = k; i < k + j / 2; i++) {
348 sum.
re = buf[i].
re + buf[i + j / 2].
re;
349 sum.
im = buf[i].
im + buf[i + j / 2].
im;
351 diff.
re = buf[i].
re - buf[i + j / 2].
re;
352 diff.
im = buf[i].
im - buf[i + j / 2].
im;
365 for (i = 0; i < 256; i++) {
372 for (i = 0; i < 256; i++) {
376 o1.
re = rout[i].
re - rout[255 - i].
re;
377 o1.
im = rout[i].
im + rout[255 - i].
im;
379 o2.
re = rout[i].
im - rout[255 - i].
im;
380 o2.
im = -rout[i].
re - rout[255 - i].
re;
397 for (i = 1024; i > 0; i >>= 1) {
427 for (j = 0; j < 256; j++) {
429 out_cb_unnorm[j] = -2047;
432 for (i = 0; i <
AUBANDS; i++) {
434 for (j = 0; j < 256; j++)
435 denom =
add_cb(denom, power[j] +
auf[samplerate_index][i][j]);
436 for (j = 0; j < 256; j++)
437 out_cb_unnorm[j] =
add_cb(out_cb_unnorm[j],
438 -denom +
auf[samplerate_index][i][j]);
441 for (j = 0; j < 256; j++)
442 out_cb[j] =
add_cb(out_cb[j], -out_cb_unnorm[j] - ca_cb - cs_cb);
455 for (f = 0; f < 4; f++)
456 walk(c, 0, 0, f, 0, -2047, channel, arg);
458 for (f = 0; f < 8; f++)
459 walk(c, band, band - 1, 8 * band - 4 + f,
470 for (f = 0; f < 4; f++)
471 walk(c, 31, 31, 256 - 4 + f, 0, -2047, channel, arg);
473 for (f = 0; f < 8; f++)
474 walk(c, band, band + 1, 8 * band + 4 + f,
491 int i, k,
band, ch, ssf;
494 for (i = 0; i < 256; i++)
500 for (i = 0, k = 128 + 256 * ssf; k < 512; i++, k++)
502 for (k -= 512; i < 512; i++, k++)
503 data[i] = input[k * c->
channels + ch];
506 for (i = 0; i < 256; i++) {
515 for (band = 0; band < 32; band++) {
526 for (band = 0; band < 32; band++)
551 #define USED_1ABITS 1
552 #define USED_NABITS 2
553 #define USED_26ABITS 4
565 for (band = 0; band < 32; band++) {
568 if (snr_cb >= 1312) {
571 }
else if (snr_cb >= 222) {
574 }
else if (snr_cb >= 0) {
584 for (band = 0; band < 32; band++)
618 for (down =
snr_fudge >> 1; down; down >>= 1) {
634 for (k = 0; k < 512; k++)
635 for (ch = 0; ch < c->
channels; ch++)
644 value = value >> quant.
e;
651 int our_nscale, try_remove;
660 for (try_remove = 64; try_remove > 0; try_remove >>= 1) {
667 our_nscale -= try_remove;
670 if (our_nscale >= 125)
684 for (band = 0; band < 32; band++)
688 &c->
quant[band][ch]);
699 for (band = 0; band < 32; band++)
789 static const int bitlen[11] = { 0, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3 };
790 static const int thr[11] = { 0, 1, 3, 3, 3, 3, 7, 7, 7, 7, 7 };
825 for (i = 1; i < 11; i++)
835 if (c->
abits[band][ch] <= 7) {
837 for (i = 0; i < 8; i += 4) {
839 for (j = 3; j >= 0; j--) {
848 for (i = 0; i < 8; i++) {