51 #define IMC_BLOCK_SIZE 64
52 #define IMC_FRAME_ID 0x21
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];
274 float *flcoeffs2,
int *bandWidthT,
275 float *flcoeffs3,
float *flcoeffs5)
280 float snr_limit = 1.e-30;
284 for (i = 0; i <
BANDS; i++) {
285 flcoeffs5[i] = workT2[i] = 0.0;
287 workT1[i] = flcoeffs1[i] * flcoeffs1[i];
288 flcoeffs3[i] = 2.0 * flcoeffs2[i];
291 flcoeffs3[i] = -30000.0;
293 workT3[i] = bandWidthT[i] * workT1[i] * 0.01;
294 if (workT3[i] <= snr_limit)
298 for (i = 0; i <
BANDS; i++) {
299 for (cnt2 = i; cnt2 < q->
cyclTab[i]; cnt2++)
300 flcoeffs5[cnt2] = flcoeffs5[cnt2] + workT3[i];
301 workT2[cnt2 - 1] = workT2[cnt2 - 1] + workT3[i];
304 for (i = 1; i <
BANDS; i++) {
305 accum = (workT2[i - 1] + accum) * q->
weights1[i - 1];
306 flcoeffs5[i] += accum;
309 for (i = 0; i <
BANDS; i++)
312 for (i = 0; i <
BANDS; i++) {
313 for (cnt2 = i - 1; cnt2 > q->
cyclTab2[i]; cnt2--)
314 flcoeffs5[cnt2] += workT3[i];
315 workT2[cnt2+1] += workT3[i];
320 for (i = BANDS-2; i >= 0; i--) {
321 accum = (workT2[i+1] + accum) * q->
weights2[i];
322 flcoeffs5[i] += accum;
337 s = stream_format_code >> 1;
338 hufftab[0] = &huffman_vlc[
s][0];
339 hufftab[1] = &huffman_vlc[
s][1];
340 hufftab[2] = &huffman_vlc[
s][2];
341 hufftab[3] = &huffman_vlc[
s][3];
344 if (stream_format_code & 4)
348 for (i = start; i <
BANDS; i++) {
350 hufftab[cb_sel[i]]->
bits, 2);
351 if (levlCoeffs[i] == 17)
363 for (i = 1; i <
BANDS; i++)
368 float *flcoeffs1,
float *flcoeffs2)
374 flcoeffs1[0] = 20000.0 /
exp2 (levlCoeffBuf[0] * 0.18945);
375 flcoeffs2[0] =
log2f(flcoeffs1[0]);
379 for (i = 1; i <
BANDS; i++) {
380 level = levlCoeffBuf[i];
387 else if (level <= 24)
393 tmp2 += 0.83048 *
level;
402 float *old_floor,
float *flcoeffs1,
410 for (i = 0; i <
BANDS; i++) {
412 if (levlCoeffBuf[i] < 16) {
413 flcoeffs1[i] =
imc_exp_tab2[levlCoeffBuf[i]] * old_floor[i];
414 flcoeffs2[i] = (levlCoeffBuf[i] - 7) * 0.83048 + flcoeffs2[i];
416 flcoeffs1[i] = old_floor[i];
422 float *flcoeffs1,
float *flcoeffs2)
428 flcoeffs1[pos] = 20000.0 / pow (2, levlCoeffBuf[0] * 0.18945);
429 flcoeffs2[pos] =
log2f(flcoeffs1[0]);
430 tmp = flcoeffs1[pos];
431 tmp2 = flcoeffs2[pos];
434 for (i = 0; i <
BANDS; i++) {
437 level = *levlCoeffBuf++;
438 flcoeffs1[i] = tmp *
powf(10.0, -level * 0.4375);
439 flcoeffs2[i] = tmp2 - 1.4533435415 *
level;
447 int stream_format_code,
int freebits,
int flag)
450 const float limit = -1.e20;
459 float lowest = 1.e10;
465 for (i = 0; i <
BANDS; i++)
468 for (i = 0; i < BANDS - 1; i++) {
477 highest = highest * 0.25;
479 for (i = 0; i <
BANDS; i++) {
496 if (stream_format_code & 0x2) {
503 for (i = (stream_format_code & 0x2) ? 4 : 0; i < BANDS - 1; i++) {
512 summa = (summa * 0.5 - freebits) / iacc;
515 for (i = 0; i < BANDS / 2; i++) {
516 rres = summer - freebits;
517 if ((rres >= -8) && (rres <= 8))
523 for (j = (stream_format_code & 0x2) ? 4 : 0; j <
BANDS; j++) {
524 cwlen = av_clipf(((chctx->
flcoeffs4[j] * 0.5) - summa + 0.5), 0, 6);
535 if (freebits < summer)
542 summa = (float)(summer - freebits) / ((t1 + 1) * iacc) + summa;
545 for (i = (stream_format_code & 0x2) ? 4 : 0; i <
BANDS; i++) {
550 if (freebits > summer) {
551 for (i = 0; i <
BANDS; i++) {
552 workT[i] = (chctx->
bitsBandT[i] == 6) ? -1.e20
559 if (highest <= -1.e20)
565 for (i = 0; i <
BANDS; i++) {
566 if (workT[i] > highest) {
572 if (highest > -1.e20) {
573 workT[found_indx] -= 2.0;
575 workT[found_indx] = -1.e20;
577 for (j =
band_tab[found_indx]; j < band_tab[found_indx + 1] && (freebits > summer); j++) {
582 }
while (freebits > summer);
584 if (freebits < summer) {
585 for (i = 0; i <
BANDS; i++) {
589 if (stream_format_code & 0x2) {
595 while (freebits < summer) {
598 for (i = 0; i <
BANDS; i++) {
599 if (workT[i] < lowest) {
606 workT[low_indx] = lowest + 2.0;
609 workT[low_indx] = 1.e20;
611 for (j =
band_tab[low_indx]; j <
band_tab[low_indx+1] && (freebits < summer); j++) {
628 for (i = 0; i <
BANDS; i++) {
635 for (j = band_tab[i]; j < band_tab[i + 1]; j++) {
666 if (j < band_tab[i + 1]) {
687 for (i = 0; i <
BANDS; i++) {
688 workT[i] = (chctx->
bitsBandT[i] == 6) ? -1.e20
692 while (corrected < summer) {
693 if (highest <= -1.e20)
698 for (i = 0; i <
BANDS; i++) {
699 if (workT[i] > highest) {
705 if (highest > -1.e20) {
706 workT[found_indx] -= 2.0;
707 if (++(chctx->
bitsBandT[found_indx]) == 6)
708 workT[found_indx] = -1.e20;
710 for (j =
band_tab[found_indx]; j <
band_tab[found_indx+1] && (corrected < summer); j++) {
728 for (i = 0; i <
COEFFS / 2; i++) {
740 for (i = 0; i <
COEFFS / 2; i++) {
754 int stream_format_code)
757 int middle_value, cw_len, max_size;
758 const float *quantizer;
760 for (i = 0; i <
BANDS; i++) {
765 if (cw_len <= 0 || chctx->skipFlags[j])
768 max_size = 1 << cw_len;
769 middle_value = max_size >> 1;
796 int i, j, cw_len, cw;
798 for (i = 0; i <
BANDS; i++) {
809 "Potential problem on band %i, coefficient %i"
810 ": cw_len=%i\n", i, j, cw_len);
826 for (i = 0; i <
BANDS; i++) {
832 if ((((band_tab[i + 1] - band_tab[i]) * 1.5) > chctx->
sumLenArr[i]) && (chctx->
sumLenArr[i] > 0))
838 for (i = 0; i <
BANDS; i++) {
850 for (i = 0; i <
BANDS; i++) {
867 int stream_format_code;
868 int imc_hdr, i, j,
ret;
871 int counter, bitscount;
877 if (imc_hdr & 0x18) {
884 if (stream_format_code & 0x04)
888 for (i = 0; i <
BANDS; i++)
896 if (stream_format_code & 0x1)
901 if (stream_format_code & 0x1)
904 else if (stream_format_code & 0x4)
911 for(i=0; i<
BANDS; i++) {
921 if (stream_format_code & 0x1) {
922 for (i = 0; i <
BANDS; i++) {
929 for (i = 0; i <
BANDS; i++) {
938 for (i = 0; i < BANDS - 1; i++)
949 if (stream_format_code & 0x2) {
956 for (i = 1; i < 4; i++) {
957 if (stream_format_code & 0x1)
970 if (!(stream_format_code & 0x2))
982 if (stream_format_code & 0x1) {
983 for (i = 0; i <
BANDS; i++)
989 for (i = 0; i <
BANDS; i++) {
1015 int *got_frame_ptr,
AVPacket *avpkt)
1019 int buf_size = avpkt->
size;
1026 if (buf_size < IMC_BLOCK_SIZE * avctx->channels) {
1036 for (i = 0; i < avctx->
channels; i++) {
1077 #if CONFIG_IMC_DECODER
1093 #if CONFIG_IAC_DECODER