51 #define IMC_BLOCK_SIZE 64
52 #define IMC_FRAME_ID 0x21
107 float weights1[31], weights2[31];
112 #define VLC_TABLES_SIZE 9512
115 0, 640, 1156, 1732, 2308, 2852, 3396, 3924,
123 return 3.5 * atan((freq / 7500.0) * (freq / 7500.0)) + 13.0 * atan(freq * 0.00076);
128 double freqmin[32], freqmid[32], freqmax[32];
129 double scale = sampling_rate / (256.0 * 2.0 * 2.0);
130 double nyquist_freq = sampling_rate * 0.5;
131 double freq, bark, prev_bark = 0,
tf,
tb;
134 for (i = 0; i < 32; i++) {
139 tb = bark - prev_bark;
140 q->
weights1[i - 1] = pow(10.0, -1.0 * tb);
141 q->
weights2[i - 1] = pow(10.0, -2.7 * tb);
148 while (
tf < nyquist_freq) {
160 if (tb <= bark - 0.5)
166 for (i = 0; i < 32; i++) {
168 for (j = 31; j > 0 && freq <= freqmid[j]; j--);
172 for (j = 0; j < 32 && freq >= freqmid[j]; j++);
185 "Strange sample rate of %i, file likely corrupt or "
186 "needing a new table derivation method.\n",
199 for (j = 0; j < avctx->
channels; j++) {
202 for (i = 0; i <
BANDS; i++)
211 for (i = 0; i <
COEFFS; i++)
213 for (i = 0; i < COEFFS / 2; i++) {
214 q->
post_cos[i] = (1.0f / 32768) * cos(i / 256.0 *
M_PI);
215 q->
post_sin[i] = (1.0f / 32768) * sin(i / 256.0 *
M_PI);
217 r1 = sin((i * 4.0 + 1.0) / 1024.0 *
M_PI);
218 r2 = cos((i * 4.0 + 1.0) / 1024.0 *
M_PI);
222 q->
pre_coef2[i] = -(r1 - r2) * sqrt(2.0);
224 q->
pre_coef1[i] = -(r1 + r2) * sqrt(2.0);
231 for (i = 0; i < 30; i++)
235 for (i = 0; i < 4 ; i++) {
236 for (j = 0; j < 4; j++) {
238 huffman_vlc[i][j].
table_allocated = vlc_offsets[i * 4 + j + 1] - vlc_offsets[i * 4 + j];
268 float *flcoeffs2,
int *bandWidthT,
269 float *flcoeffs3,
float *flcoeffs5)
274 float snr_limit = 1.e-30;
278 for (i = 0; i <
BANDS; i++) {
279 flcoeffs5[i] = workT2[i] = 0.0;
281 workT1[i] = flcoeffs1[i] * flcoeffs1[i];
282 flcoeffs3[i] = 2.0 * flcoeffs2[i];
285 flcoeffs3[i] = -30000.0;
287 workT3[i] = bandWidthT[i] * workT1[i] * 0.01;
288 if (workT3[i] <= snr_limit)
292 for (i = 0; i <
BANDS; i++) {
293 for (cnt2 = i; cnt2 < q->
cyclTab[i]; cnt2++)
294 flcoeffs5[cnt2] = flcoeffs5[cnt2] + workT3[i];
295 workT2[cnt2 - 1] = workT2[cnt2 - 1] + workT3[i];
298 for (i = 1; i <
BANDS; i++) {
299 accum = (workT2[i - 1] + accum) * q->
weights1[i - 1];
300 flcoeffs5[i] += accum;
303 for (i = 0; i <
BANDS; i++)
306 for (i = 0; i <
BANDS; i++) {
307 for (cnt2 = i - 1; cnt2 > q->
cyclTab2[i]; cnt2--)
308 flcoeffs5[cnt2] += workT3[i];
309 workT2[cnt2+1] += workT3[i];
314 for (i = BANDS-2; i >= 0; i--) {
315 accum = (workT2[i+1] + accum) * q->
weights2[i];
316 flcoeffs5[i] += accum;
331 s = stream_format_code >> 1;
332 hufftab[0] = &huffman_vlc[
s][0];
333 hufftab[1] = &huffman_vlc[
s][1];
334 hufftab[2] = &huffman_vlc[
s][2];
335 hufftab[3] = &huffman_vlc[
s][3];
338 if (stream_format_code & 4)
342 for (i = start; i <
BANDS; i++) {
344 hufftab[cb_sel[i]]->
bits, 2);
345 if (levlCoeffs[i] == 17)
357 for (i = 1; i <
BANDS; i++)
362 float *flcoeffs1,
float *flcoeffs2)
368 flcoeffs1[0] = 20000.0 /
exp2 (levlCoeffBuf[0] * 0.18945);
369 flcoeffs2[0] =
log2f(flcoeffs1[0]);
373 for (i = 1; i <
BANDS; i++) {
374 level = levlCoeffBuf[i];
381 else if (level <= 24)
387 tmp2 += 0.83048 *
level;
396 float *old_floor,
float *flcoeffs1,
404 for (i = 0; i <
BANDS; i++) {
406 if (levlCoeffBuf[i] < 16) {
407 flcoeffs1[i] =
imc_exp_tab2[levlCoeffBuf[i]] * old_floor[i];
408 flcoeffs2[i] = (levlCoeffBuf[i] - 7) * 0.83048 + flcoeffs2[i];
410 flcoeffs1[i] = old_floor[i];
416 float *flcoeffs1,
float *flcoeffs2)
422 flcoeffs1[pos] = 20000.0 / pow (2, levlCoeffBuf[0] * 0.18945);
423 flcoeffs2[pos] =
log2f(flcoeffs1[0]);
424 tmp = flcoeffs1[pos];
425 tmp2 = flcoeffs2[pos];
428 for (i = 0; i <
BANDS; i++) {
431 level = *levlCoeffBuf++;
432 flcoeffs1[i] = tmp *
powf(10.0, -level * 0.4375);
433 flcoeffs2[i] = tmp2 - 1.4533435415 *
level;
441 int stream_format_code,
int freebits,
int flag)
444 const float limit = -1.e20;
453 float lowest = 1.e10;
459 for (i = 0; i <
BANDS; i++)
462 for (i = 0; i < BANDS - 1; i++) {
471 highest = highest * 0.25;
473 for (i = 0; i <
BANDS; i++) {
490 if (stream_format_code & 0x2) {
497 for (i = (stream_format_code & 0x2) ? 4 : 0; i < BANDS - 1; i++) {
506 summa = (summa * 0.5 - freebits) / iacc;
509 for (i = 0; i < BANDS / 2; i++) {
510 rres = summer - freebits;
511 if ((rres >= -8) && (rres <= 8))
517 for (j = (stream_format_code & 0x2) ? 4 : 0; j <
BANDS; j++) {
518 cwlen = av_clipf(((chctx->
flcoeffs4[j] * 0.5) - summa + 0.5), 0, 6);
529 if (freebits < summer)
536 summa = (float)(summer - freebits) / ((t1 + 1) * iacc) + summa;
539 for (i = (stream_format_code & 0x2) ? 4 : 0; i <
BANDS; i++) {
544 if (freebits > summer) {
545 for (i = 0; i <
BANDS; i++) {
546 workT[i] = (chctx->
bitsBandT[i] == 6) ? -1.e20
553 if (highest <= -1.e20)
559 for (i = 0; i <
BANDS; i++) {
560 if (workT[i] > highest) {
566 if (highest > -1.e20) {
567 workT[found_indx] -= 2.0;
569 workT[found_indx] = -1.e20;
571 for (j =
band_tab[found_indx]; j < band_tab[found_indx + 1] && (freebits > summer); j++) {
576 }
while (freebits > summer);
578 if (freebits < summer) {
579 for (i = 0; i <
BANDS; i++) {
583 if (stream_format_code & 0x2) {
589 while (freebits < summer) {
592 for (i = 0; i <
BANDS; i++) {
593 if (workT[i] < lowest) {
600 workT[low_indx] = lowest + 2.0;
603 workT[low_indx] = 1.e20;
605 for (j =
band_tab[low_indx]; j <
band_tab[low_indx+1] && (freebits < summer); j++) {
622 for (i = 0; i <
BANDS; i++) {
629 for (j = band_tab[i]; j < band_tab[i + 1]; j++) {
660 if (j < band_tab[i + 1]) {
681 for (i = 0; i <
BANDS; i++) {
682 workT[i] = (chctx->
bitsBandT[i] == 6) ? -1.e20
686 while (corrected < summer) {
687 if (highest <= -1.e20)
692 for (i = 0; i <
BANDS; i++) {
693 if (workT[i] > highest) {
699 if (highest > -1.e20) {
700 workT[found_indx] -= 2.0;
701 if (++(chctx->
bitsBandT[found_indx]) == 6)
702 workT[found_indx] = -1.e20;
704 for (j =
band_tab[found_indx]; j <
band_tab[found_indx+1] && (corrected < summer); j++) {
722 for (i = 0; i <
COEFFS / 2; i++) {
734 for (i = 0; i <
COEFFS / 2; i++) {
748 int stream_format_code)
751 int middle_value, cw_len, max_size;
752 const float *quantizer;
754 for (i = 0; i <
BANDS; i++) {
759 if (cw_len <= 0 || chctx->skipFlags[j])
762 max_size = 1 << cw_len;
763 middle_value = max_size >> 1;
789 int i, j, cw_len, cw;
791 for (i = 0; i <
BANDS; i++) {
800 av_dlog(NULL,
"Band %i coeff %i cw_len %i\n", i, j, cw_len);
819 for (i = 0; i <
BANDS; i++) {
825 if ((((band_tab[i + 1] - band_tab[i]) * 1.5) > chctx->
sumLenArr[i]) && (chctx->
sumLenArr[i] > 0))
831 for (i = 0; i <
BANDS; i++) {
843 for (i = 0; i <
BANDS; i++) {
860 int stream_format_code;
861 int imc_hdr, i, j,
ret;
864 int counter, bitscount;
870 if (imc_hdr & 0x18) {
877 if (stream_format_code & 0x04)
881 for (i = 0; i <
BANDS; i++)
889 if (stream_format_code & 0x1)
892 else if (stream_format_code & 0x1)
897 if (stream_format_code & 0x4)
904 for(i=0; i<
BANDS; i++) {
914 if (stream_format_code & 0x1) {
915 for (i = 0; i <
BANDS; i++) {
922 for (i = 0; i <
BANDS; i++) {
931 for (i = 0; i < BANDS - 1; i++)
942 if (stream_format_code & 0x2) {
949 for (i = 1; i < 4; i++) {
950 if (stream_format_code & 0x1)
963 if (!(stream_format_code & 0x2))
975 if (stream_format_code & 0x1) {
976 for (i = 0; i <
BANDS; i++)
982 for (i = 0; i <
BANDS; i++) {
1012 int *got_frame_ptr,
AVPacket *avpkt)
1016 int buf_size = avpkt->
size;
1023 if (buf_size < IMC_BLOCK_SIZE * avctx->channels) {
1033 for (i = 0; i < avctx->
channels; i++) {
1074 #if CONFIG_IMC_DECODER
1090 #if CONFIG_IAC_DECODER