51 #define IMC_BLOCK_SIZE 64
52 #define IMC_FRAME_ID 0x21
105 float weights1[31], weights2[31];
110 #define VLC_TABLES_SIZE 9512
113 0, 640, 1156, 1732, 2308, 2852, 3396, 3924,
121 return 3.5 * atan((freq / 7500.0) * (freq / 7500.0)) + 13.0 * atan(freq * 0.00076);
126 double freqmin[32], freqmid[32], freqmax[32];
127 double scale = sampling_rate / (256.0 * 2.0 * 2.0);
128 double nyquist_freq = sampling_rate * 0.5;
129 double freq, bark, prev_bark = 0,
tf,
tb;
132 for (i = 0; i < 32; i++) {
137 tb = bark - prev_bark;
138 q->
weights1[i - 1] = pow(10.0, -1.0 * tb);
139 q->
weights2[i - 1] = pow(10.0, -2.7 * tb);
146 while (
tf < nyquist_freq) {
158 if (tb <= bark - 0.5)
164 for (i = 0; i < 32; i++) {
166 for (j = 31; j > 0 && freq <= freqmid[j]; j--);
170 for (j = 0; j < 32 && freq >= freqmid[j]; j++);
189 for (j = 0; j < avctx->
channels; j++) {
192 for (i = 0; i <
BANDS; i++)
201 for (i = 0; i <
COEFFS; i++)
203 for (i = 0; i < COEFFS / 2; i++) {
204 q->
post_cos[i] = (1.0f / 32768) * cos(i / 256.0 *
M_PI);
205 q->
post_sin[i] = (1.0f / 32768) * sin(i / 256.0 *
M_PI);
207 r1 = sin((i * 4.0 + 1.0) / 1024.0 *
M_PI);
208 r2 = cos((i * 4.0 + 1.0) / 1024.0 *
M_PI);
212 q->
pre_coef2[i] = -(r1 - r2) * sqrt(2.0);
214 q->
pre_coef1[i] = -(r1 + r2) * sqrt(2.0);
221 for (i = 0; i < 30; i++)
225 for (i = 0; i < 4 ; i++) {
226 for (j = 0; j < 4; j++) {
228 huffman_vlc[i][j].
table_allocated = vlc_offsets[i * 4 + j + 1] - vlc_offsets[i * 4 + j];
258 float *flcoeffs2,
int *bandWidthT,
259 float *flcoeffs3,
float *flcoeffs5)
264 float snr_limit = 1.e-30;
268 for (i = 0; i <
BANDS; i++) {
269 flcoeffs5[i] = workT2[i] = 0.0;
271 workT1[i] = flcoeffs1[i] * flcoeffs1[i];
272 flcoeffs3[i] = 2.0 * flcoeffs2[i];
275 flcoeffs3[i] = -30000.0;
277 workT3[i] = bandWidthT[i] * workT1[i] * 0.01;
278 if (workT3[i] <= snr_limit)
282 for (i = 0; i <
BANDS; i++) {
283 for (cnt2 = i; cnt2 < q->
cyclTab[i]; cnt2++)
284 flcoeffs5[cnt2] = flcoeffs5[cnt2] + workT3[i];
285 workT2[cnt2 - 1] = workT2[cnt2 - 1] + workT3[i];
288 for (i = 1; i <
BANDS; i++) {
289 accum = (workT2[i - 1] + accum) * q->
weights1[i - 1];
290 flcoeffs5[i] += accum;
293 for (i = 0; i <
BANDS; i++)
296 for (i = 0; i <
BANDS; i++) {
297 for (cnt2 = i - 1; cnt2 > q->
cyclTab2[i]; cnt2--)
298 flcoeffs5[cnt2] += workT3[i];
299 workT2[cnt2+1] += workT3[i];
304 for (i = BANDS-2; i >= 0; i--) {
305 accum = (workT2[i+1] + accum) * q->
weights2[i];
306 flcoeffs5[i] += accum;
321 s = stream_format_code >> 1;
322 hufftab[0] = &huffman_vlc[
s][0];
323 hufftab[1] = &huffman_vlc[
s][1];
324 hufftab[2] = &huffman_vlc[
s][2];
325 hufftab[3] = &huffman_vlc[
s][3];
328 if (stream_format_code & 4)
332 for (i = start; i <
BANDS; i++) {
334 hufftab[cb_sel[i]]->
bits, 2);
335 if (levlCoeffs[i] == 17)
341 float *flcoeffs1,
float *flcoeffs2)
347 flcoeffs1[0] = 20000.0 /
exp2 (levlCoeffBuf[0] * 0.18945);
348 flcoeffs2[0] =
log2f(flcoeffs1[0]);
352 for (i = 1; i <
BANDS; i++) {
353 level = levlCoeffBuf[i];
360 else if (level <= 24)
366 tmp2 += 0.83048 *
level;
375 float *old_floor,
float *flcoeffs1,
383 for (i = 0; i <
BANDS; i++) {
385 if (levlCoeffBuf[i] < 16) {
386 flcoeffs1[i] =
imc_exp_tab2[levlCoeffBuf[i]] * old_floor[i];
387 flcoeffs2[i] = (levlCoeffBuf[i] - 7) * 0.83048 + flcoeffs2[i];
389 flcoeffs1[i] = old_floor[i];
398 int stream_format_code,
int freebits,
int flag)
401 const float limit = -1.e20;
410 float lowest = 1.e10;
416 for (i = 0; i <
BANDS; i++)
419 for (i = 0; i < BANDS - 1; i++)
423 highest = highest * 0.25;
425 for (i = 0; i <
BANDS; i++) {
442 if (stream_format_code & 0x2) {
449 for (i = (stream_format_code & 0x2) ? 4 : 0; i < BANDS - 1; i++) {
458 summa = (summa * 0.5 - freebits) / iacc;
461 for (i = 0; i < BANDS / 2; i++) {
462 rres = summer - freebits;
463 if ((rres >= -8) && (rres <= 8))
469 for (j = (stream_format_code & 0x2) ? 4 : 0; j <
BANDS; j++) {
470 cwlen = av_clipf(((chctx->
flcoeffs4[j] * 0.5) - summa + 0.5), 0, 6);
481 if (freebits < summer)
488 summa = (float)(summer - freebits) / ((t1 + 1) * iacc) + summa;
491 for (i = (stream_format_code & 0x2) ? 4 : 0; i <
BANDS; i++) {
496 if (freebits > summer) {
497 for (i = 0; i <
BANDS; i++) {
498 workT[i] = (chctx->
bitsBandT[i] == 6) ? -1.e20
505 if (highest <= -1.e20)
511 for (i = 0; i <
BANDS; i++) {
512 if (workT[i] > highest) {
518 if (highest > -1.e20) {
519 workT[found_indx] -= 2.0;
521 workT[found_indx] = -1.e20;
523 for (j =
band_tab[found_indx]; j < band_tab[found_indx + 1] && (freebits > summer); j++) {
528 }
while (freebits > summer);
530 if (freebits < summer) {
531 for (i = 0; i <
BANDS; i++) {
535 if (stream_format_code & 0x2) {
541 while (freebits < summer) {
544 for (i = 0; i <
BANDS; i++) {
545 if (workT[i] < lowest) {
552 workT[low_indx] = lowest + 2.0;
555 workT[low_indx] = 1.e20;
557 for (j =
band_tab[low_indx]; j <
band_tab[low_indx+1] && (freebits < summer); j++) {
574 for (i = 0; i <
BANDS; i++) {
581 for (j = band_tab[i]; j < band_tab[i + 1]; j++) {
612 if (j < band_tab[i + 1]) {
633 for (i = 0; i <
BANDS; i++) {
634 workT[i] = (chctx->
bitsBandT[i] == 6) ? -1.e20
638 while (corrected < summer) {
639 if (highest <= -1.e20)
644 for (i = 0; i <
BANDS; i++) {
645 if (workT[i] > highest) {
651 if (highest > -1.e20) {
652 workT[found_indx] -= 2.0;
653 if (++(chctx->
bitsBandT[found_indx]) == 6)
654 workT[found_indx] = -1.e20;
656 for (j =
band_tab[found_indx]; j <
band_tab[found_indx+1] && (corrected < summer); j++) {
674 for (i = 0; i <
COEFFS / 2; i++) {
686 for (i = 0; i <
COEFFS / 2; i++) {
700 int stream_format_code)
703 int middle_value, cw_len, max_size;
704 const float *quantizer;
706 for (i = 0; i <
BANDS; i++) {
711 if (cw_len <= 0 || chctx->skipFlags[j])
714 max_size = 1 << cw_len;
715 middle_value = max_size >> 1;
741 int i, j, cw_len, cw;
743 for (i = 0; i <
BANDS; i++) {
752 av_dlog(NULL,
"Band %i coeff %i cw_len %i\n", i, j, cw_len);
768 int stream_format_code;
769 int imc_hdr, i, j,
ret;
772 int counter, bitscount;
778 if (imc_hdr & 0x18) {
785 if (stream_format_code & 1) {
790 if (stream_format_code & 0x04)
794 for (i = 0; i <
BANDS; i++)
804 if (stream_format_code & 0x4)
811 for(i=0; i<
BANDS; i++) {
821 for (i = 0; i <
BANDS; i++) {
829 for (i = 0; i < BANDS - 1; i++) {
838 if (stream_format_code & 0x2) {
845 for (i = 1; i < 4; i++) {
856 if (!(stream_format_code & 0x2))
868 for (i = 0; i <
BANDS; i++) {
874 if ((((band_tab[i + 1] - band_tab[i]) * 1.5) > chctx->
sumLenArr[i]) && (chctx->
sumLenArr[i] > 0))
880 for (i = 0; i <
BANDS; i++) {
892 for (i = 0; i <
BANDS; i++) {
906 for (i = 0; i <
BANDS; i++) {
936 int *got_frame_ptr,
AVPacket *avpkt)
940 int buf_size = avpkt->
size;
947 if (buf_size < IMC_BLOCK_SIZE * avctx->channels) {
957 for (i = 0; i < avctx->
channels; i++) {
998 #if CONFIG_IMC_DECODER
1014 #if CONFIG_IAC_DECODER