49 #define IMC_BLOCK_SIZE 64
50 #define IMC_FRAME_ID 0x21
104 float weights1[31], weights2[31];
109 #define VLC_TABLES_SIZE 9512
112 0, 640, 1156, 1732, 2308, 2852, 3396, 3924,
120 return 3.5 * atan((freq / 7500.0) * (freq / 7500.0)) + 13.0 * atan(freq * 0.00076);
125 double freqmin[32], freqmid[32], freqmax[32];
126 double scale = sampling_rate / (256.0 * 2.0 * 2.0);
127 double nyquist_freq = sampling_rate * 0.5;
128 double freq, bark, prev_bark = 0, tf, tb;
131 for (i = 0; i < 32; i++) {
136 tb = bark - prev_bark;
137 q->
weights1[i - 1] = pow(10.0, -1.0 * tb);
138 q->
weights2[i - 1] = pow(10.0, -2.7 * tb);
145 while (tf < nyquist_freq) {
157 if (tb <= bark - 0.5)
163 for (i = 0; i < 32; i++) {
165 for (j = 31; j > 0 && freq <= freqmid[j]; j--);
169 for (j = 0; j < 32 && freq >= freqmid[j]; j++);
188 for (j = 0; j < avctx->
channels; j++) {
191 for (i = 0; i <
BANDS; i++)
200 for (i = 0; i <
COEFFS; i++)
202 for (i = 0; i < COEFFS / 2; i++) {
203 q->
post_cos[i] = (1.0f / 32768) * cos(i / 256.0 *
M_PI);
204 q->
post_sin[i] = (1.0f / 32768) * sin(i / 256.0 *
M_PI);
206 r1 = sin((i * 4.0 + 1.0) / 1024.0 *
M_PI);
207 r2 = cos((i * 4.0 + 1.0) / 1024.0 *
M_PI);
211 q->
pre_coef2[i] = -(r1 - r2) * sqrt(2.0);
213 q->
pre_coef1[i] = -(r1 + r2) * sqrt(2.0);
220 for (i = 0; i < 30; i++)
224 for (i = 0; i < 4 ; i++) {
225 for (j = 0; j < 4; j++) {
227 huffman_vlc[i][j].
table_allocated = vlc_offsets[i * 4 + j + 1] - vlc_offsets[i * 4 + j];
259 float *flcoeffs2,
int *bandWidthT,
260 float *flcoeffs3,
float *flcoeffs5)
265 float snr_limit = 1.e-30;
269 for (i = 0; i <
BANDS; i++) {
270 flcoeffs5[i] = workT2[i] = 0.0;
272 workT1[i] = flcoeffs1[i] * flcoeffs1[i];
273 flcoeffs3[i] = 2.0 * flcoeffs2[i];
276 flcoeffs3[i] = -30000.0;
278 workT3[i] = bandWidthT[i] * workT1[i] * 0.01;
279 if (workT3[i] <= snr_limit)
283 for (i = 0; i <
BANDS; i++) {
284 for (cnt2 = i; cnt2 < q->
cyclTab[i]; cnt2++)
285 flcoeffs5[cnt2] = flcoeffs5[cnt2] + workT3[i];
286 workT2[cnt2 - 1] = workT2[cnt2 - 1] + workT3[i];
289 for (i = 1; i <
BANDS; i++) {
290 accum = (workT2[i - 1] + accum) * q->
weights1[i - 1];
291 flcoeffs5[i] += accum;
294 for (i = 0; i <
BANDS; i++)
297 for (i = 0; i <
BANDS; i++) {
298 for (cnt2 = i - 1; cnt2 > q->
cyclTab2[i]; cnt2--)
299 flcoeffs5[cnt2] += workT3[i];
300 workT2[cnt2+1] += workT3[i];
305 for (i = BANDS-2; i >= 0; i--) {
306 accum = (workT2[i+1] + accum) * q->
weights2[i];
307 flcoeffs5[i] += accum;
322 s = stream_format_code >> 1;
323 hufftab[0] = &huffman_vlc[s][0];
324 hufftab[1] = &huffman_vlc[s][1];
325 hufftab[2] = &huffman_vlc[s][2];
326 hufftab[3] = &huffman_vlc[s][3];
329 if (stream_format_code & 4)
333 for (i = start; i <
BANDS; i++) {
335 hufftab[cb_sel[i]]->
bits, 2);
336 if (levlCoeffs[i] == 17)
342 float *flcoeffs1,
float *flcoeffs2)
348 flcoeffs1[0] = 20000.0 /
exp2 (levlCoeffBuf[0] * 0.18945);
349 flcoeffs2[0] =
log2f(flcoeffs1[0]);
353 for (i = 1; i <
BANDS; i++) {
354 level = levlCoeffBuf[i];
361 else if (level <= 24)
367 tmp2 += 0.83048 *
level;
376 float *old_floor,
float *flcoeffs1,
384 for (i = 0; i <
BANDS; i++) {
386 if (levlCoeffBuf[i] < 16) {
387 flcoeffs1[i] =
imc_exp_tab2[levlCoeffBuf[i]] * old_floor[i];
388 flcoeffs2[i] = (levlCoeffBuf[i] - 7) * 0.83048 + flcoeffs2[i];
390 flcoeffs1[i] = old_floor[i];
399 int stream_format_code,
int freebits,
int flag)
402 const float limit = -1.e20;
411 float lowest = 1.e10;
417 for (i = 0; i <
BANDS; i++)
420 for (i = 0; i < BANDS - 1; i++)
424 highest = highest * 0.25;
426 for (i = 0; i <
BANDS; i++) {
443 if (stream_format_code & 0x2) {
450 for (i = (stream_format_code & 0x2) ? 4 : 0; i < BANDS - 1; i++) {
455 summa = (summa * 0.5 - freebits) / iacc;
458 for (i = 0; i < BANDS / 2; i++) {
459 rres = summer - freebits;
460 if ((rres >= -8) && (rres <= 8))
466 for (j = (stream_format_code & 0x2) ? 4 : 0; j <
BANDS; j++) {
467 cwlen = av_clipf(((chctx->
flcoeffs4[j] * 0.5) - summa + 0.5), 0, 6);
478 if (freebits < summer)
485 summa = (float)(summer - freebits) / ((t1 + 1) * iacc) + summa;
488 for (i = (stream_format_code & 0x2) ? 4 : 0; i <
BANDS; i++) {
493 if (freebits > summer) {
494 for (i = 0; i <
BANDS; i++) {
495 workT[i] = (chctx->
bitsBandT[i] == 6) ? -1.e20
502 if (highest <= -1.e20)
508 for (i = 0; i <
BANDS; i++) {
509 if (workT[i] > highest) {
515 if (highest > -1.e20) {
516 workT[found_indx] -= 2.0;
518 workT[found_indx] = -1.e20;
520 for (j =
band_tab[found_indx]; j < band_tab[found_indx + 1] && (freebits > summer); j++) {
525 }
while (freebits > summer);
527 if (freebits < summer) {
528 for (i = 0; i <
BANDS; i++) {
532 if (stream_format_code & 0x2) {
538 while (freebits < summer) {
541 for (i = 0; i <
BANDS; i++) {
542 if (workT[i] < lowest) {
549 workT[low_indx] = lowest + 2.0;
552 workT[low_indx] = 1.e20;
554 for (j =
band_tab[low_indx]; j <
band_tab[low_indx+1] && (freebits < summer); j++) {
571 for (i = 0; i <
BANDS; i++) {
578 for (j = band_tab[i]; j < band_tab[i + 1]; j++) {
609 if (j < band_tab[i + 1]) {
630 for (i = 0; i <
BANDS; i++) {
631 workT[i] = (chctx->
bitsBandT[i] == 6) ? -1.e20
635 while (corrected < summer) {
636 if (highest <= -1.e20)
641 for (i = 0; i <
BANDS; i++) {
642 if (workT[i] > highest) {
648 if (highest > -1.e20) {
649 workT[found_indx] -= 2.0;
650 if (++(chctx->
bitsBandT[found_indx]) == 6)
651 workT[found_indx] = -1.e20;
653 for (j =
band_tab[found_indx]; j <
band_tab[found_indx+1] && (corrected < summer); j++) {
671 for (i = 0; i <
COEFFS / 2; i++) {
683 for (i = 0; i <
COEFFS / 2; i++) {
697 int stream_format_code)
700 int middle_value, cw_len, max_size;
701 const float *quantizer;
703 for (i = 0; i <
BANDS; i++) {
708 if (cw_len <= 0 || chctx->skipFlags[j])
711 max_size = 1 << cw_len;
712 middle_value = max_size >> 1;
738 int i, j, cw_len, cw;
740 for (i = 0; i <
BANDS; i++) {
749 av_dlog(
NULL,
"Band %i coeff %i cw_len %i\n", i, j, cw_len);
765 int stream_format_code;
766 int imc_hdr, i, j, ret;
769 int counter, bitscount;
775 if (imc_hdr & 0x18) {
782 if (stream_format_code & 1) {
788 if (stream_format_code & 0x04)
792 for (i = 0; i <
BANDS; i++)
802 if (stream_format_code & 0x4)
809 for(i=0; i<
BANDS; i++) {
819 for (i = 0; i <
BANDS; i++) {
827 for (i = 0; i < BANDS - 1; i++) {
836 if (stream_format_code & 0x2) {
843 for (i = 1; i < 4; i++) {
854 if (!(stream_format_code & 0x2))
866 for (i = 0; i <
BANDS; i++) {
872 if ((((band_tab[i + 1] - band_tab[i]) * 1.5) > chctx->
sumLenArr[i]) && (chctx->
sumLenArr[i] > 0))
878 for (i = 0; i <
BANDS; i++) {
890 for (i = 0; i <
BANDS; i++) {
904 for (i = 0; i <
BANDS; i++) {
934 int *got_frame_ptr,
AVPacket *avpkt)
937 int buf_size = avpkt->
size;
944 if (buf_size < IMC_BLOCK_SIZE * avctx->channels) {
956 for (i = 0; i < avctx->
channels; i++) {
998 #if CONFIG_IMC_DECODER
1014 #if CONFIG_IAC_DECODER