FFmpeg
imc.c
Go to the documentation of this file.
1 /*
2  * IMC compatible decoder
3  * Copyright (c) 2002-2004 Maxim Poliakovski
4  * Copyright (c) 2006 Benjamin Larsson
5  * Copyright (c) 2006 Konstantin Shishkov
6  *
7  * This file is part of FFmpeg.
8  *
9  * FFmpeg is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public
11  * License as published by the Free Software Foundation; either
12  * version 2.1 of the License, or (at your option) any later version.
13  *
14  * FFmpeg is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with FFmpeg; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22  */
23 
24 /**
25  * @file
26  * IMC - Intel Music Coder
27  * A mdct based codec using a 256 points large transform
28  * divided into 32 bands with some mix of scale factors.
29  * Only mono is supported.
30  */
31 
32 #include "config_components.h"
33 
34 #include <math.h>
35 #include <stddef.h>
36 
38 #include "libavutil/ffmath.h"
39 #include "libavutil/float_dsp.h"
40 #include "libavutil/internal.h"
41 #include "libavutil/mem_internal.h"
42 #include "libavutil/thread.h"
43 #include "libavutil/tx.h"
44 
45 #include "avcodec.h"
46 #include "bswapdsp.h"
47 #include "codec_internal.h"
48 #include "decode.h"
49 #include "get_bits.h"
50 #include "sinewin.h"
51 
52 #include "imcdata.h"
53 
54 #define IMC_BLOCK_SIZE 64
55 #define IMC_FRAME_ID 0x21
56 #define BANDS 32
57 #define COEFFS 256
58 
59 typedef struct IMCChannel {
60  float old_floor[BANDS];
61  float flcoeffs1[BANDS];
62  float flcoeffs2[BANDS];
63  float flcoeffs3[BANDS];
64  float flcoeffs4[BANDS];
65  float flcoeffs5[BANDS];
66  float flcoeffs6[BANDS];
68 
69  int bandWidthT[BANDS]; ///< codewords per band
70  int bitsBandT[BANDS]; ///< how many bits per codeword in band
71  int CWlengthT[COEFFS]; ///< how many bits in each codeword
73  int bandFlagsBuf[BANDS]; ///< flags for each band
74  int sumLenArr[BANDS]; ///< bits for all coeffs in band
75  int skipFlagRaw[BANDS]; ///< skip flags are stored in raw form or not
76  int skipFlagBits[BANDS]; ///< bits used to code skip flags
77  int skipFlagCount[BANDS]; ///< skipped coefficients per band
78  int skipFlags[COEFFS]; ///< skip coefficient decoding or not
79  int codewords[COEFFS]; ///< raw codewords read from bitstream
80 
82  DECLARE_ALIGNED(32, float, prev_win)[128];
83 } IMCChannel;
84 
85 typedef struct IMCContext {
87 
88  /** MDCT tables */
90 
91  float sqrt_tab[30];
93 
98  float *out_samples;
99  DECLARE_ALIGNED(32, float, temp)[256];
100 
102 
103  int8_t cyclTab[32], cyclTab2[32];
104  float weights1[31], weights2[31];
105 
107 } IMCContext;
108 
109 static const VLCElem *huffman_vlc[4][4];
110 
111 #define IMC_VLC_BITS 9
112 #define VLC_TABLES_SIZE 9512
113 
115 
116 static inline double freq2bark(double freq)
117 {
118  return 3.5 * atan((freq / 7500.0) * (freq / 7500.0)) + 13.0 * atan(freq * 0.00076);
119 }
120 
121 static av_cold void iac_generate_tabs(IMCContext *q, int sampling_rate)
122 {
123  double freqmin[32], freqmid[32], freqmax[32];
124  double scale = sampling_rate / (256.0 * 2.0 * 2.0);
125  double nyquist_freq = sampling_rate * 0.5;
126  double freq, bark, prev_bark = 0, tf, tb;
127  int i, j;
128 
129  for (i = 0; i < 32; i++) {
130  freq = (band_tab[i] + band_tab[i + 1] - 1) * scale;
131  bark = freq2bark(freq);
132 
133  if (i > 0) {
134  tb = bark - prev_bark;
135  q->weights1[i - 1] = ff_exp10(-1.0 * tb);
136  q->weights2[i - 1] = ff_exp10(-2.7 * tb);
137  }
138  prev_bark = bark;
139 
140  freqmid[i] = freq;
141 
142  tf = freq;
143  while (tf < nyquist_freq) {
144  tf += 0.5;
145  tb = freq2bark(tf);
146  if (tb > bark + 0.5)
147  break;
148  }
149  freqmax[i] = tf;
150 
151  tf = freq;
152  while (tf > 0.0) {
153  tf -= 0.5;
154  tb = freq2bark(tf);
155  if (tb <= bark - 0.5)
156  break;
157  }
158  freqmin[i] = tf;
159  }
160 
161  for (i = 0; i < 32; i++) {
162  freq = freqmax[i];
163  for (j = 31; j > 0 && freq <= freqmid[j]; j--);
164  q->cyclTab[i] = j + 1;
165 
166  freq = freqmin[i];
167  for (j = 0; j < 32 && freq >= freqmid[j]; j++);
168  q->cyclTab2[i] = j - 1;
169  }
170 }
171 
172 static av_cold void imc_init_static(void)
173 {
175  /* initialize the VLC tables */
176  for (int i = 0; i < 4 ; i++) {
177  for (int j = 0; j < 4; j++) {
178  huffman_vlc[i][j] =
180  imc_huffman_lens[i][j], 1,
181  imc_huffman_syms[i][j], 1, 1,
182  0, 0);
183  }
184  }
185 }
186 
188 {
189  int i, j, ret;
190  IMCContext *q = avctx->priv_data;
191  static AVOnce init_static_once = AV_ONCE_INIT;
192  float scale = 1.0f / (16384);
193 
194  if (avctx->codec_id == AV_CODEC_ID_IAC && avctx->sample_rate > 96000) {
195  av_log(avctx, AV_LOG_ERROR,
196  "Strange sample rate of %i, file likely corrupt or "
197  "needing a new table derivation method.\n",
198  avctx->sample_rate);
199  return AVERROR_PATCHWELCOME;
200  }
201 
202  if (avctx->codec_id == AV_CODEC_ID_IMC) {
205  }
206 
207  if (avctx->ch_layout.nb_channels > 2) {
208  avpriv_request_sample(avctx, "Number of channels > 2");
209  return AVERROR_PATCHWELCOME;
210  }
211 
212  for (j = 0; j < avctx->ch_layout.nb_channels; j++) {
213  q->chctx[j].decoder_reset = 1;
214 
215  for (i = 0; i < BANDS; i++)
216  q->chctx[j].old_floor[i] = 1.0;
217  }
218 
219  /* Build mdct window, a simple sine window normalized with sqrt(2) */
221  for (i = 0; i < COEFFS; i++)
222  q->mdct_sine_window[i] *= sqrt(2.0);
223 
224  /* Generate a square root table */
225  for (i = 0; i < 30; i++)
226  q->sqrt_tab[i] = sqrt(i);
227 
228  if (avctx->codec_id == AV_CODEC_ID_IAC) {
229  iac_generate_tabs(q, avctx->sample_rate);
230  } else {
231  memcpy(q->cyclTab, cyclTab, sizeof(cyclTab));
232  memcpy(q->cyclTab2, cyclTab2, sizeof(cyclTab2));
233  memcpy(q->weights1, imc_weights1, sizeof(imc_weights1));
234  memcpy(q->weights2, imc_weights2, sizeof(imc_weights2));
235  }
236 
238  if (!q->fdsp)
239  return AVERROR(ENOMEM);
240 
241  ret = av_tx_init(&q->mdct, &q->mdct_fn, AV_TX_FLOAT_MDCT, 1, COEFFS, &scale, 0);
242  if (ret < 0)
243  return ret;
244 
245  ff_bswapdsp_init(&q->bdsp);
246 
248 
249  ff_thread_once(&init_static_once, imc_init_static);
250 
251  return 0;
252 }
253 
254 static void imc_calculate_coeffs(IMCContext *q, float *flcoeffs1,
255  float *flcoeffs2, int *bandWidthT,
256  float *flcoeffs3, float *flcoeffs5)
257 {
258  float workT1[BANDS];
259  float workT2[BANDS];
260  float workT3[BANDS];
261  float snr_limit = 1.e-30;
262  float accum = 0.0;
263  int i, cnt2;
264 
265  for (i = 0; i < BANDS; i++) {
266  flcoeffs5[i] = workT2[i] = 0.0;
267  if (bandWidthT[i]) {
268  workT1[i] = flcoeffs1[i] * flcoeffs1[i];
269  flcoeffs3[i] = 2.0 * flcoeffs2[i];
270  } else {
271  workT1[i] = 0.0;
272  flcoeffs3[i] = -30000.0;
273  }
274  workT3[i] = bandWidthT[i] * workT1[i] * 0.01;
275  if (workT3[i] <= snr_limit)
276  workT3[i] = 0.0;
277  }
278 
279  for (i = 0; i < BANDS; i++) {
280  for (cnt2 = i; cnt2 < q->cyclTab[i]; cnt2++)
281  flcoeffs5[cnt2] = flcoeffs5[cnt2] + workT3[i];
282  workT2[cnt2 - 1] = workT2[cnt2 - 1] + workT3[i];
283  }
284 
285  for (i = 1; i < BANDS; i++) {
286  accum = (workT2[i - 1] + accum) * q->weights1[i - 1];
287  flcoeffs5[i] += accum;
288  }
289 
290  for (i = 0; i < BANDS; i++)
291  workT2[i] = 0.0;
292 
293  for (i = 0; i < BANDS; i++) {
294  for (cnt2 = i - 1; cnt2 > q->cyclTab2[i]; cnt2--)
295  flcoeffs5[cnt2] += workT3[i];
296  workT2[cnt2+1] += workT3[i];
297  }
298 
299  accum = 0.0;
300 
301  for (i = BANDS-2; i >= 0; i--) {
302  accum = (workT2[i+1] + accum) * q->weights2[i];
303  flcoeffs5[i] += accum;
304  // there is missing code here, but it seems to never be triggered
305  }
306 }
307 
308 
309 static void imc_read_level_coeffs(IMCContext *q, int stream_format_code,
310  int *levlCoeffs)
311 {
312  int i;
313  int start = 0;
314  const uint8_t *cb_sel;
315  int s = stream_format_code >> 1;
316  const VLCElem * const *const hufftab = huffman_vlc[s];
317 
318  cb_sel = imc_cb_select[s];
319 
320  if (stream_format_code & 4)
321  start = 1;
322  if (start)
323  levlCoeffs[0] = get_bits(&q->gb, 7);
324  for (i = start; i < BANDS; i++) {
325  levlCoeffs[i] = get_vlc2(&q->gb, hufftab[cb_sel[i]],
326  IMC_VLC_BITS, 2);
327  if (levlCoeffs[i] == 17)
328  levlCoeffs[i] += get_bits(&q->gb, 4);
329  }
330 }
331 
332 static void imc_read_level_coeffs_raw(IMCContext *q, int stream_format_code,
333  int *levlCoeffs)
334 {
335  int i;
336 
337  q->coef0_pos = get_bits(&q->gb, 5);
338  levlCoeffs[0] = get_bits(&q->gb, 7);
339  for (i = 1; i < BANDS; i++)
340  levlCoeffs[i] = get_bits(&q->gb, 4);
341 }
342 
343 static void imc_decode_level_coefficients(IMCContext *q, int *levlCoeffBuf,
344  float *flcoeffs1, float *flcoeffs2)
345 {
346  int i, level;
347  float tmp, tmp2;
348  // maybe some frequency division thingy
349 
350  flcoeffs1[0] = 20000.0 / exp2 (levlCoeffBuf[0] * 0.18945); // 0.18945 = log2(10) * 0.05703125
351  flcoeffs2[0] = log2f(flcoeffs1[0]);
352  tmp = flcoeffs1[0];
353  tmp2 = flcoeffs2[0];
354 
355  for (i = 1; i < BANDS; i++) {
356  level = levlCoeffBuf[i];
357  if (level == 16) {
358  flcoeffs1[i] = 1.0;
359  flcoeffs2[i] = 0.0;
360  } else {
361  if (level < 17)
362  level -= 7;
363  else if (level <= 24)
364  level -= 32;
365  else
366  level -= 16;
367 
368  tmp *= imc_exp_tab[15 + level];
369  tmp2 += 0.83048 * level; // 0.83048 = log2(10) * 0.25
370  flcoeffs1[i] = tmp;
371  flcoeffs2[i] = tmp2;
372  }
373  }
374 }
375 
376 
377 static void imc_decode_level_coefficients2(IMCContext *q, int *levlCoeffBuf,
378  float *old_floor, float *flcoeffs1,
379  float *flcoeffs2)
380 {
381  int i;
382  /* FIXME maybe flag_buf = noise coding and flcoeffs1 = new scale factors
383  * and flcoeffs2 old scale factors
384  * might be incomplete due to a missing table that is in the binary code
385  */
386  for (i = 0; i < BANDS; i++) {
387  flcoeffs1[i] = 0;
388  if (levlCoeffBuf[i] < 16) {
389  flcoeffs1[i] = imc_exp_tab2[levlCoeffBuf[i]] * old_floor[i];
390  flcoeffs2[i] = (levlCoeffBuf[i] - 7) * 0.83048 + flcoeffs2[i]; // 0.83048 = log2(10) * 0.25
391  } else {
392  flcoeffs1[i] = old_floor[i];
393  }
394  }
395 }
396 
397 static void imc_decode_level_coefficients_raw(IMCContext *q, int *levlCoeffBuf,
398  float *flcoeffs1, float *flcoeffs2)
399 {
400  int i, level, pos;
401  float tmp, tmp2;
402 
403  pos = q->coef0_pos;
404  flcoeffs1[pos] = 20000.0 / pow (2, levlCoeffBuf[0] * 0.18945); // 0.18945 = log2(10) * 0.05703125
405  flcoeffs2[pos] = log2f(flcoeffs1[pos]);
406  tmp = flcoeffs1[pos];
407  tmp2 = flcoeffs2[pos];
408 
409  levlCoeffBuf++;
410  for (i = 0; i < BANDS; i++) {
411  if (i == pos)
412  continue;
413  level = *levlCoeffBuf++;
414  flcoeffs1[i] = tmp * powf(10.0, -level * 0.4375); //todo tab
415  flcoeffs2[i] = tmp2 - 1.4533435415 * level; // 1.4533435415 = log2(10) * 0.4375
416  }
417 }
418 
419 /**
420  * Perform bit allocation depending on bits available
421  */
422 static int bit_allocation(IMCContext *q, IMCChannel *chctx,
423  int stream_format_code, int freebits, int flag)
424 {
425  int i, j;
426  const float limit = -1.e20;
427  float highest = 0.0;
428  int indx;
429  int t1 = 0;
430  int t2 = 1;
431  float summa = 0.0;
432  int iacc = 0;
433  int summer = 0;
434  int rres, cwlen;
435  float lowest = 1.e10;
436  int low_indx = 0;
437  float workT[32];
438  int flg;
439  int found_indx = 0;
440 
441  for (i = 0; i < BANDS; i++)
442  highest = FFMAX(highest, chctx->flcoeffs1[i]);
443 
444  for (i = 0; i < BANDS - 1; i++) {
445  if (chctx->flcoeffs5[i] <= 0) {
446  av_log(q->avctx, AV_LOG_ERROR, "flcoeffs5 %f invalid\n", chctx->flcoeffs5[i]);
447  return AVERROR_INVALIDDATA;
448  }
449  chctx->flcoeffs4[i] = chctx->flcoeffs3[i] - log2f(chctx->flcoeffs5[i]);
450  }
451  chctx->flcoeffs4[BANDS - 1] = limit;
452 
453  highest = highest * 0.25;
454 
455  for (i = 0; i < BANDS; i++) {
456  indx = -1;
457  if ((band_tab[i + 1] - band_tab[i]) == chctx->bandWidthT[i])
458  indx = 0;
459 
460  if ((band_tab[i + 1] - band_tab[i]) > chctx->bandWidthT[i])
461  indx = 1;
462 
463  if (((band_tab[i + 1] - band_tab[i]) / 2) >= chctx->bandWidthT[i])
464  indx = 2;
465 
466  if (indx == -1)
467  return AVERROR_INVALIDDATA;
468 
469  chctx->flcoeffs4[i] += xTab[(indx * 2 + (chctx->flcoeffs1[i] < highest)) * 2 + flag];
470  }
471 
472  if (stream_format_code & 0x2) {
473  chctx->flcoeffs4[0] = limit;
474  chctx->flcoeffs4[1] = limit;
475  chctx->flcoeffs4[2] = limit;
476  chctx->flcoeffs4[3] = limit;
477  }
478 
479  for (i = (stream_format_code & 0x2) ? 4 : 0; i < BANDS - 1; i++) {
480  iacc += chctx->bandWidthT[i];
481  summa += chctx->bandWidthT[i] * chctx->flcoeffs4[i];
482  }
483 
484  if (!iacc)
485  return AVERROR_INVALIDDATA;
486 
487  chctx->bandWidthT[BANDS - 1] = 0;
488  summa = (summa * 0.5 - freebits) / iacc;
489 
490 
491  for (i = 0; i < BANDS / 2; i++) {
492  rres = summer - freebits;
493  if ((rres >= -8) && (rres <= 8))
494  break;
495 
496  summer = 0;
497  iacc = 0;
498 
499  for (j = (stream_format_code & 0x2) ? 4 : 0; j < BANDS; j++) {
500  cwlen = av_clipf(((chctx->flcoeffs4[j] * 0.5) - summa + 0.5), 0, 6);
501 
502  chctx->bitsBandT[j] = cwlen;
503  summer += chctx->bandWidthT[j] * cwlen;
504 
505  if (cwlen > 0)
506  iacc += chctx->bandWidthT[j];
507  }
508 
509  flg = t2;
510  t2 = 1;
511  if (freebits < summer)
512  t2 = -1;
513  if (i == 0)
514  flg = t2;
515  if (flg != t2)
516  t1++;
517 
518  summa = (float)(summer - freebits) / ((t1 + 1) * iacc) + summa;
519  }
520 
521  for (i = (stream_format_code & 0x2) ? 4 : 0; i < BANDS; i++) {
522  for (j = band_tab[i]; j < band_tab[i + 1]; j++)
523  chctx->CWlengthT[j] = chctx->bitsBandT[i];
524  }
525 
526  if (freebits > summer) {
527  for (i = 0; i < BANDS; i++) {
528  workT[i] = (chctx->bitsBandT[i] == 6) ? -1.e20
529  : (chctx->bitsBandT[i] * -2 + chctx->flcoeffs4[i] - 0.415);
530  }
531 
532  highest = 0.0;
533 
534  do {
535  if (highest <= -1.e20)
536  break;
537 
538  found_indx = 0;
539  highest = -1.e20;
540 
541  for (i = 0; i < BANDS; i++) {
542  if (workT[i] > highest) {
543  highest = workT[i];
544  found_indx = i;
545  }
546  }
547 
548  if (highest > -1.e20) {
549  workT[found_indx] -= 2.0;
550  if (++chctx->bitsBandT[found_indx] == 6)
551  workT[found_indx] = -1.e20;
552 
553  for (j = band_tab[found_indx]; j < band_tab[found_indx + 1] && (freebits > summer); j++) {
554  chctx->CWlengthT[j]++;
555  summer++;
556  }
557  }
558  } while (freebits > summer);
559  }
560  if (freebits < summer) {
561  for (i = 0; i < BANDS; i++) {
562  workT[i] = chctx->bitsBandT[i] ? (chctx->bitsBandT[i] * -2 + chctx->flcoeffs4[i] + 1.585)
563  : 1.e20;
564  }
565  if (stream_format_code & 0x2) {
566  workT[0] = 1.e20;
567  workT[1] = 1.e20;
568  workT[2] = 1.e20;
569  workT[3] = 1.e20;
570  }
571  while (freebits < summer) {
572  lowest = 1.e10;
573  low_indx = 0;
574  for (i = 0; i < BANDS; i++) {
575  if (workT[i] < lowest) {
576  lowest = workT[i];
577  low_indx = i;
578  }
579  }
580  // if (lowest >= 1.e10)
581  // break;
582  workT[low_indx] = lowest + 2.0;
583 
584  if (!--chctx->bitsBandT[low_indx])
585  workT[low_indx] = 1.e20;
586 
587  for (j = band_tab[low_indx]; j < band_tab[low_indx+1] && (freebits < summer); j++) {
588  if (chctx->CWlengthT[j] > 0) {
589  chctx->CWlengthT[j]--;
590  summer--;
591  }
592  }
593  }
594  }
595  return 0;
596 }
597 
598 static void imc_get_skip_coeff(IMCContext *q, IMCChannel *chctx)
599 {
600  int i, j;
601 
602  memset(chctx->skipFlagBits, 0, sizeof(chctx->skipFlagBits));
603  memset(chctx->skipFlagCount, 0, sizeof(chctx->skipFlagCount));
604  for (i = 0; i < BANDS; i++) {
605  if (!chctx->bandFlagsBuf[i] || !chctx->bandWidthT[i])
606  continue;
607 
608  if (!chctx->skipFlagRaw[i]) {
609  chctx->skipFlagBits[i] = band_tab[i + 1] - band_tab[i];
610 
611  for (j = band_tab[i]; j < band_tab[i + 1]; j++) {
612  chctx->skipFlags[j] = get_bits1(&q->gb);
613  if (chctx->skipFlags[j])
614  chctx->skipFlagCount[i]++;
615  }
616  } else {
617  for (j = band_tab[i]; j < band_tab[i + 1] - 1; j += 2) {
618  if (!get_bits1(&q->gb)) { // 0
619  chctx->skipFlagBits[i]++;
620  chctx->skipFlags[j] = 1;
621  chctx->skipFlags[j + 1] = 1;
622  chctx->skipFlagCount[i] += 2;
623  } else {
624  if (get_bits1(&q->gb)) { // 11
625  chctx->skipFlagBits[i] += 2;
626  chctx->skipFlags[j] = 0;
627  chctx->skipFlags[j + 1] = 1;
628  chctx->skipFlagCount[i]++;
629  } else {
630  chctx->skipFlagBits[i] += 3;
631  chctx->skipFlags[j + 1] = 0;
632  if (!get_bits1(&q->gb)) { // 100
633  chctx->skipFlags[j] = 1;
634  chctx->skipFlagCount[i]++;
635  } else { // 101
636  chctx->skipFlags[j] = 0;
637  }
638  }
639  }
640  }
641 
642  if (j < band_tab[i + 1]) {
643  chctx->skipFlagBits[i]++;
644  if ((chctx->skipFlags[j] = get_bits1(&q->gb)))
645  chctx->skipFlagCount[i]++;
646  }
647  }
648  }
649 }
650 
651 /**
652  * Increase highest' band coefficient sizes as some bits won't be used
653  */
655  int summer)
656 {
657  float workT[32];
658  int corrected = 0;
659  int i, j;
660  float highest = 0;
661  int found_indx = 0;
662 
663  for (i = 0; i < BANDS; i++) {
664  workT[i] = (chctx->bitsBandT[i] == 6) ? -1.e20
665  : (chctx->bitsBandT[i] * -2 + chctx->flcoeffs4[i] - 0.415);
666  }
667 
668  while (corrected < summer) {
669  if (highest <= -1.e20)
670  break;
671 
672  highest = -1.e20;
673 
674  for (i = 0; i < BANDS; i++) {
675  if (workT[i] > highest) {
676  highest = workT[i];
677  found_indx = i;
678  }
679  }
680 
681  if (highest > -1.e20) {
682  workT[found_indx] -= 2.0;
683  if (++(chctx->bitsBandT[found_indx]) == 6)
684  workT[found_indx] = -1.e20;
685 
686  for (j = band_tab[found_indx]; j < band_tab[found_indx+1] && (corrected < summer); j++) {
687  if (!chctx->skipFlags[j] && (chctx->CWlengthT[j] < 6)) {
688  chctx->CWlengthT[j]++;
689  corrected++;
690  }
691  }
692  }
693  }
694 }
695 
697  int stream_format_code)
698 {
699  int i, j;
700  int middle_value, cw_len, max_size;
701  const float *quantizer;
702 
703  for (i = 0; i < BANDS; i++) {
704  for (j = band_tab[i]; j < band_tab[i + 1]; j++) {
705  chctx->CWdecoded[j] = 0;
706  cw_len = chctx->CWlengthT[j];
707 
708  if (cw_len <= 0 || chctx->skipFlags[j])
709  continue;
710 
711  max_size = 1 << cw_len;
712  middle_value = max_size >> 1;
713 
714  if (chctx->codewords[j] >= max_size || chctx->codewords[j] < 0)
715  return AVERROR_INVALIDDATA;
716 
717  if (cw_len >= 4) {
718  quantizer = imc_quantizer2[(stream_format_code & 2) >> 1];
719  if (chctx->codewords[j] >= middle_value)
720  chctx->CWdecoded[j] = quantizer[chctx->codewords[j] - 8] * chctx->flcoeffs6[i];
721  else
722  chctx->CWdecoded[j] = -quantizer[max_size - chctx->codewords[j] - 8 - 1] * chctx->flcoeffs6[i];
723  }else{
724  quantizer = imc_quantizer1[((stream_format_code & 2) >> 1) | (chctx->bandFlagsBuf[i] << 1)];
725  if (chctx->codewords[j] >= middle_value)
726  chctx->CWdecoded[j] = quantizer[chctx->codewords[j] - 1] * chctx->flcoeffs6[i];
727  else
728  chctx->CWdecoded[j] = -quantizer[max_size - 2 - chctx->codewords[j]] * chctx->flcoeffs6[i];
729  }
730  }
731  }
732  return 0;
733 }
734 
735 
736 static void imc_get_coeffs(AVCodecContext *avctx,
737  IMCContext *q, IMCChannel *chctx)
738 {
739  int i, j, cw_len, cw;
740 
741  for (i = 0; i < BANDS; i++) {
742  if (!chctx->sumLenArr[i])
743  continue;
744  if (chctx->bandFlagsBuf[i] || chctx->bandWidthT[i]) {
745  for (j = band_tab[i]; j < band_tab[i + 1]; j++) {
746  cw_len = chctx->CWlengthT[j];
747  cw = 0;
748 
749  if (cw_len && (!chctx->bandFlagsBuf[i] || !chctx->skipFlags[j])) {
750  if (get_bits_count(&q->gb) + cw_len > 512) {
751  av_log(avctx, AV_LOG_WARNING,
752  "Potential problem on band %i, coefficient %i"
753  ": cw_len=%i\n", i, j, cw_len);
754  } else
755  cw = get_bits(&q->gb, cw_len);
756  }
757 
758  chctx->codewords[j] = cw;
759  }
760  }
761  }
762 }
763 
765 {
766  int i, j;
767  int summer;
768 
769  for (i = 0; i < BANDS; i++) {
770  chctx->sumLenArr[i] = 0;
771  chctx->skipFlagRaw[i] = 0;
772  for (j = band_tab[i]; j < band_tab[i + 1]; j++)
773  chctx->sumLenArr[i] += chctx->CWlengthT[j];
774  if (chctx->bandFlagsBuf[i])
775  if (((int)((band_tab[i + 1] - band_tab[i]) * 1.5) > chctx->sumLenArr[i]) && (chctx->sumLenArr[i] > 0))
776  chctx->skipFlagRaw[i] = 1;
777  }
778 
779  imc_get_skip_coeff(q, chctx);
780 
781  for (i = 0; i < BANDS; i++) {
782  chctx->flcoeffs6[i] = chctx->flcoeffs1[i];
783  /* band has flag set and at least one coded coefficient */
784  if (chctx->bandFlagsBuf[i] && (band_tab[i + 1] - band_tab[i]) != chctx->skipFlagCount[i]) {
785  chctx->flcoeffs6[i] *= q->sqrt_tab[ band_tab[i + 1] - band_tab[i]] /
786  q->sqrt_tab[(band_tab[i + 1] - band_tab[i] - chctx->skipFlagCount[i])];
787  }
788  }
789 
790  /* calculate bits left, bits needed and adjust bit allocation */
791  summer = 0;
792 
793  for (i = 0; i < BANDS; i++) {
794  if (chctx->bandFlagsBuf[i]) {
795  for (j = band_tab[i]; j < band_tab[i + 1]; j++) {
796  if (chctx->skipFlags[j]) {
797  summer += chctx->CWlengthT[j];
798  chctx->CWlengthT[j] = 0;
799  }
800  }
801  summer -= chctx->skipFlagBits[i];
802  }
803  }
804  imc_adjust_bit_allocation(q, chctx, summer);
805 }
806 
807 static int imc_decode_block(AVCodecContext *avctx, IMCContext *q, int ch)
808 {
809  int stream_format_code;
810  int imc_hdr, i, j, ret;
811  int flag;
812  int bits;
813  int bitscount;
814  IMCChannel *chctx = q->chctx + ch;
815 
816 
817  /* Check the frame header */
818  imc_hdr = get_bits(&q->gb, 9);
819  if (imc_hdr & 0x18) {
820  av_log(avctx, AV_LOG_ERROR, "frame header check failed!\n");
821  av_log(avctx, AV_LOG_ERROR, "got %X.\n", imc_hdr);
822  return AVERROR_INVALIDDATA;
823  }
824  stream_format_code = get_bits(&q->gb, 3);
825 
826  if (stream_format_code & 0x04)
827  chctx->decoder_reset = 1;
828 
829  if (chctx->decoder_reset) {
830  for (i = 0; i < BANDS; i++)
831  chctx->old_floor[i] = 1.0;
832  for (i = 0; i < COEFFS; i++)
833  chctx->CWdecoded[i] = 0;
834  chctx->decoder_reset = 0;
835  }
836 
837  flag = get_bits1(&q->gb);
838  if (stream_format_code & 0x1)
839  imc_read_level_coeffs_raw(q, stream_format_code, chctx->levlCoeffBuf);
840  else
841  imc_read_level_coeffs(q, stream_format_code, chctx->levlCoeffBuf);
842 
843  if (stream_format_code & 0x1)
845  chctx->flcoeffs1, chctx->flcoeffs2);
846  else if (stream_format_code & 0x4)
848  chctx->flcoeffs1, chctx->flcoeffs2);
849  else
851  chctx->flcoeffs1, chctx->flcoeffs2);
852 
853  for(i=0; i<BANDS; i++) {
854  if(chctx->flcoeffs1[i] > INT_MAX) {
855  av_log(avctx, AV_LOG_ERROR, "scalefactor out of range\n");
856  return AVERROR_INVALIDDATA;
857  }
858  }
859 
860  memcpy(chctx->old_floor, chctx->flcoeffs1, 32 * sizeof(float));
861 
862  if (stream_format_code & 0x1) {
863  for (i = 0; i < BANDS; i++) {
864  chctx->bandWidthT[i] = band_tab[i + 1] - band_tab[i];
865  chctx->bandFlagsBuf[i] = 0;
866  chctx->flcoeffs3[i] = chctx->flcoeffs2[i] * 2;
867  chctx->flcoeffs5[i] = 1.0;
868  }
869  } else {
870  for (i = 0; i < BANDS; i++) {
871  if (chctx->levlCoeffBuf[i] == 16) {
872  chctx->bandWidthT[i] = 0;
873  } else
874  chctx->bandWidthT[i] = band_tab[i + 1] - band_tab[i];
875  }
876 
877  memset(chctx->bandFlagsBuf, 0, BANDS * sizeof(int));
878  for (i = 0; i < BANDS - 1; i++)
879  if (chctx->bandWidthT[i])
880  chctx->bandFlagsBuf[i] = get_bits1(&q->gb);
881 
882  imc_calculate_coeffs(q, chctx->flcoeffs1, chctx->flcoeffs2,
883  chctx->bandWidthT, chctx->flcoeffs3,
884  chctx->flcoeffs5);
885  }
886 
887  bitscount = 0;
888  /* first 4 bands will be assigned 5 bits per coefficient */
889  if (stream_format_code & 0x2) {
890  bitscount += 15;
891 
892  chctx->bitsBandT[0] = 5;
893  chctx->CWlengthT[0] = 5;
894  chctx->CWlengthT[1] = 5;
895  chctx->CWlengthT[2] = 5;
896  for (i = 1; i < 4; i++) {
897  if (stream_format_code & 0x1)
898  bits = 5;
899  else
900  bits = (chctx->levlCoeffBuf[i] == 16) ? 0 : 5;
901  chctx->bitsBandT[i] = bits;
902  for (j = band_tab[i]; j < band_tab[i + 1]; j++) {
903  chctx->CWlengthT[j] = bits;
904  bitscount += bits;
905  }
906  }
907  }
908  if (avctx->codec_id == AV_CODEC_ID_IAC) {
909  bitscount += !!chctx->bandWidthT[BANDS - 1];
910  if (!(stream_format_code & 0x2))
911  bitscount += 16;
912  }
913 
914  if ((ret = bit_allocation(q, chctx, stream_format_code,
915  512 - bitscount - get_bits_count(&q->gb),
916  flag)) < 0) {
917  av_log(avctx, AV_LOG_ERROR, "Bit allocations failed\n");
918  chctx->decoder_reset = 1;
919  return ret;
920  }
921 
922  if (stream_format_code & 0x1) {
923  for (i = 0; i < BANDS; i++)
924  chctx->skipFlags[i] = 0;
925  } else {
926  imc_refine_bit_allocation(q, chctx);
927  }
928 
929  for (i = 0; i < BANDS; i++) {
930  chctx->sumLenArr[i] = 0;
931 
932  for (j = band_tab[i]; j < band_tab[i + 1]; j++)
933  if (!chctx->skipFlags[j])
934  chctx->sumLenArr[i] += chctx->CWlengthT[j];
935  }
936 
937  memset(chctx->codewords, 0, sizeof(chctx->codewords));
938 
939  imc_get_coeffs(avctx, q, chctx);
940 
941  if (inverse_quant_coeff(q, chctx, stream_format_code) < 0) {
942  av_log(avctx, AV_LOG_ERROR, "Inverse quantization of coefficients failed\n");
943  chctx->decoder_reset = 1;
944  return AVERROR_INVALIDDATA;
945  }
946 
947  memset(chctx->skipFlags, 0, sizeof(chctx->skipFlags));
948 
949  q->mdct_fn(q->mdct, q->temp, chctx->CWdecoded, sizeof(float));
950  q->fdsp->vector_fmul_window(q->out_samples, chctx->prev_win, q->temp,
951  q->mdct_sine_window, 128);
952  memcpy(chctx->prev_win, q->temp + 128, sizeof(float)*128);
953 
954  return 0;
955 }
956 
958  int *got_frame_ptr, AVPacket *avpkt)
959 {
960  const uint8_t *buf = avpkt->data;
961  int buf_size = avpkt->size;
962  int ret, i;
963 
964  IMCContext *q = avctx->priv_data;
965 
967 
968  q->avctx = avctx;
969 
970  if (buf_size < IMC_BLOCK_SIZE * avctx->ch_layout.nb_channels) {
971  av_log(avctx, AV_LOG_ERROR, "frame too small!\n");
972  return AVERROR_INVALIDDATA;
973  }
974 
975  /* get output buffer */
977  if ((ret = ff_get_buffer(avctx, frame, 0)) < 0)
978  return ret;
979 
980  for (i = 0; i < avctx->ch_layout.nb_channels; i++) {
981  q->out_samples = (float *)frame->extended_data[i];
982 
983  q->bdsp.bswap16_buf(buf16, (const uint16_t *) buf, IMC_BLOCK_SIZE / 2);
984 
985  init_get_bits(&q->gb, (const uint8_t*)buf16, IMC_BLOCK_SIZE * 8);
986 
987  buf += IMC_BLOCK_SIZE;
988 
989  if ((ret = imc_decode_block(avctx, q, i)) < 0)
990  return ret;
991  }
992 
993  if (avctx->ch_layout.nb_channels == 2) {
994  q->fdsp->butterflies_float((float *)frame->extended_data[0],
995  (float *)frame->extended_data[1], COEFFS);
996  }
997 
998  *got_frame_ptr = 1;
999 
1000  return IMC_BLOCK_SIZE * avctx->ch_layout.nb_channels;
1001 }
1002 
1004 {
1005  IMCContext *q = avctx->priv_data;
1006 
1007  av_free(q->fdsp);
1008  av_tx_uninit(&q->mdct);
1009 
1010  return 0;
1011 }
1012 
1013 static av_cold void flush(AVCodecContext *avctx)
1014 {
1015  IMCContext *q = avctx->priv_data;
1016 
1017  q->chctx[0].decoder_reset =
1018  q->chctx[1].decoder_reset = 1;
1019 }
1020 
1021 #if CONFIG_IMC_DECODER
1022 const FFCodec ff_imc_decoder = {
1023  .p.name = "imc",
1024  CODEC_LONG_NAME("IMC (Intel Music Coder)"),
1025  .p.type = AVMEDIA_TYPE_AUDIO,
1026  .p.id = AV_CODEC_ID_IMC,
1027  .priv_data_size = sizeof(IMCContext),
1028  .init = imc_decode_init,
1029  .close = imc_decode_close,
1031  .flush = flush,
1032  .p.capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_CHANNEL_CONF,
1033  .p.sample_fmts = (const enum AVSampleFormat[]) { AV_SAMPLE_FMT_FLTP,
1035  .caps_internal = FF_CODEC_CAP_INIT_CLEANUP,
1036 };
1037 #endif
1038 #if CONFIG_IAC_DECODER
1039 const FFCodec ff_iac_decoder = {
1040  .p.name = "iac",
1041  CODEC_LONG_NAME("IAC (Indeo Audio Coder)"),
1042  .p.type = AVMEDIA_TYPE_AUDIO,
1043  .p.id = AV_CODEC_ID_IAC,
1044  .priv_data_size = sizeof(IMCContext),
1045  .init = imc_decode_init,
1046  .close = imc_decode_close,
1048  .flush = flush,
1049  .p.capabilities = AV_CODEC_CAP_DR1,
1050  .p.sample_fmts = (const enum AVSampleFormat[]) { AV_SAMPLE_FMT_FLTP,
1052  .caps_internal = FF_CODEC_CAP_INIT_CLEANUP,
1053 };
1054 #endif
ff_iac_decoder
const FFCodec ff_iac_decoder
bswapdsp.h
AV_SAMPLE_FMT_FLTP
@ AV_SAMPLE_FMT_FLTP
float, planar
Definition: samplefmt.h:66
AV_LOG_WARNING
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:186
ff_exp10
static av_always_inline double ff_exp10(double x)
Compute 10^x for floating point values.
Definition: ffmath.h:42
IMCContext::cyclTab2
int8_t cyclTab2[32]
Definition: imc.c:103
level
uint8_t level
Definition: svq3.c:204
FF_CODEC_CAP_INIT_CLEANUP
#define FF_CODEC_CAP_INIT_CLEANUP
The codec allows calling the close function for deallocation even if the init function returned a fai...
Definition: codec_internal.h:42
flush
static av_cold void flush(AVCodecContext *avctx)
Definition: imc.c:1013
AVERROR
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
AVFloatDSPContext::butterflies_float
void(* butterflies_float)(float *restrict v1, float *restrict v2, int len)
Calculate the sum and difference of two vectors of floats.
Definition: float_dsp.h:162
IMCChannel::CWlengthT
int CWlengthT[COEFFS]
how many bits in each codeword
Definition: imc.c:71
mem_internal.h
IMCContext::coef0_pos
int coef0_pos
Definition: imc.c:101
imc_exp_tab
static const float imc_exp_tab[32]
Definition: imcdata.h:87
IMCChannel::flcoeffs3
float flcoeffs3[BANDS]
Definition: imc.c:63
AVCodecContext::sample_rate
int sample_rate
samples per second
Definition: avcodec.h:1050
imc_huffman_lens
static const uint8_t imc_huffman_lens[4][4][18]
Definition: imcdata.h:115
IMCContext::mdct_fn
av_tx_fn mdct_fn
Definition: imc.c:97
log2f
#define log2f(x)
Definition: libm.h:409
thread.h
IMCChannel::skipFlagCount
int skipFlagCount[BANDS]
skipped coefficients per band
Definition: imc.c:77
AVTXContext
Definition: tx_priv.h:235
get_bits_count
static int get_bits_count(const GetBitContext *s)
Definition: get_bits.h:266
imc_quantizer2
static const float imc_quantizer2[2][56]
Definition: imcdata.h:66
IMCChannel::CWdecoded
float CWdecoded[COEFFS]
Definition: imc.c:67
IMCContext::cyclTab
int8_t cyclTab[32]
Definition: imc.c:103
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:344
tmp
static uint8_t tmp[11]
Definition: aes_ctr.c:28
iac_generate_tabs
static av_cold void iac_generate_tabs(IMCContext *q, int sampling_rate)
Definition: imc.c:121
AVPacket::data
uint8_t * data
Definition: packet.h:522
IMCContext::fdsp
AVFloatDSPContext * fdsp
Definition: imc.c:94
COEFFS
#define COEFFS
Definition: imc.c:57
FFCodec
Definition: codec_internal.h:127
IMCChannel::old_floor
float old_floor[BANDS]
Definition: imc.c:60
t1
#define t1
Definition: regdef.h:29
FFMAX
#define FFMAX(a, b)
Definition: macros.h:47
AV_CODEC_ID_IMC
@ AV_CODEC_ID_IMC
Definition: codec_id.h:467
IMCChannel::prev_win
float prev_win[128]
Definition: imc.c:82
AVChannelLayout::nb_channels
int nb_channels
Number of channels in this layout.
Definition: channel_layout.h:313
init_get_bits
static int init_get_bits(GetBitContext *s, const uint8_t *buffer, int bit_size)
Initialize GetBitContext.
Definition: get_bits.h:514
imc_calculate_coeffs
static void imc_calculate_coeffs(IMCContext *q, float *flcoeffs1, float *flcoeffs2, int *bandWidthT, float *flcoeffs3, float *flcoeffs5)
Definition: imc.c:254
av_tx_init
av_cold int av_tx_init(AVTXContext **ctx, av_tx_fn *tx, enum AVTXType type, int inv, int len, const void *scale, uint64_t flags)
Initialize a transform context with the given configuration (i)MDCTs with an odd length are currently...
Definition: tx.c:902
imc_read_level_coeffs_raw
static void imc_read_level_coeffs_raw(IMCContext *q, int stream_format_code, int *levlCoeffs)
Definition: imc.c:332
vlc_tables
static VLCElem vlc_tables[VLC_TABLES_SIZE]
Definition: imc.c:114
imc_exp_tab2
static const float *const imc_exp_tab2
Definition: imcdata.h:97
imc_read_level_coeffs
static void imc_read_level_coeffs(IMCContext *q, int stream_format_code, int *levlCoeffs)
Definition: imc.c:309
IMCChannel::flcoeffs4
float flcoeffs4[BANDS]
Definition: imc.c:64
get_bits
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
Definition: get_bits.h:335
FFCodec::p
AVCodec p
The public AVCodec.
Definition: codec_internal.h:131
IMCChannel::skipFlagRaw
int skipFlagRaw[BANDS]
skip flags are stored in raw form or not
Definition: imc.c:75
cyclTab
static const int8_t cyclTab[32]
Definition: imcdata.h:36
AVCodecContext::ch_layout
AVChannelLayout ch_layout
Audio channel layout.
Definition: avcodec.h:1065
imc_init_static
static av_cold void imc_init_static(void)
Definition: imc.c:172
GetBitContext
Definition: get_bits.h:108
imc_weights2
static const float imc_weights2[31]
Definition: imcdata.h:53
AVCodecContext::flags
int flags
AV_CODEC_FLAG_*.
Definition: avcodec.h:502
IMCContext::sqrt_tab
float sqrt_tab[30]
Definition: imc.c:91
IMC_BLOCK_SIZE
#define IMC_BLOCK_SIZE
Definition: imc.c:54
ff_thread_once
static int ff_thread_once(char *control, void(*routine)(void))
Definition: thread.h:205
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:180
av_cold
#define av_cold
Definition: attributes.h:90
av_tx_fn
void(* av_tx_fn)(AVTXContext *s, void *out, void *in, ptrdiff_t stride)
Function pointer to a function to perform the transform.
Definition: tx.h:151
VLCInitState
For static VLCs, the number of bits can often be hardcoded at each get_vlc2() callsite.
Definition: vlc.h:209
float
float
Definition: af_crystalizer.c:121
AV_TX_FLOAT_MDCT
@ AV_TX_FLOAT_MDCT
Standard MDCT with a sample data type of float, double or int32_t, respecively.
Definition: tx.h:68
imc_decode_close
static av_cold int imc_decode_close(AVCodecContext *avctx)
Definition: imc.c:1003
FF_CODEC_DECODE_CB
#define FF_CODEC_DECODE_CB(func)
Definition: codec_internal.h:287
s
#define s(width, name)
Definition: cbs_vp9.c:198
IMCChannel
Definition: imc.c:59
AVMEDIA_TYPE_AUDIO
@ AVMEDIA_TYPE_AUDIO
Definition: avutil.h:202
bits
uint8_t bits
Definition: vp3data.h:128
LOCAL_ALIGNED_16
#define LOCAL_ALIGNED_16(t, v,...)
Definition: mem_internal.h:150
imc_weights1
static const float imc_weights1[31]
Definition: imcdata.h:47
imc_get_skip_coeff
static void imc_get_skip_coeff(IMCContext *q, IMCChannel *chctx)
Definition: imc.c:598
IMCChannel::flcoeffs5
float flcoeffs5[BANDS]
Definition: imc.c:65
decode.h
get_bits.h
BswapDSPContext::bswap16_buf
void(* bswap16_buf)(uint16_t *dst, const uint16_t *src, int len)
Definition: bswapdsp.h:26
CODEC_LONG_NAME
#define CODEC_LONG_NAME(str)
Definition: codec_internal.h:272
frame
static AVFrame * frame
Definition: demux_decode.c:54
AVCodecContext::codec_id
enum AVCodecID codec_id
Definition: avcodec.h:455
IMCChannel::bandFlagsBuf
int bandFlagsBuf[BANDS]
flags for each band
Definition: imc.c:73
imc_decode_level_coefficients2
static void imc_decode_level_coefficients2(IMCContext *q, int *levlCoeffBuf, float *old_floor, float *flcoeffs1, float *flcoeffs2)
Definition: imc.c:377
if
if(ret)
Definition: filter_design.txt:179
AV_ONCE_INIT
#define AV_ONCE_INIT
Definition: thread.h:203
ff_bswapdsp_init
av_cold void ff_bswapdsp_init(BswapDSPContext *c)
Definition: bswapdsp.c:49
AVERROR_PATCHWELCOME
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
Definition: error.h:64
IMCContext::bdsp
BswapDSPContext bdsp
Definition: imc.c:95
IMCChannel::flcoeffs6
float flcoeffs6[BANDS]
Definition: imc.c:66
get_bits1
static unsigned int get_bits1(GetBitContext *s)
Definition: get_bits.h:388
IMCContext::temp
float temp[256]
Definition: imc.c:99
band_tab
static const uint16_t band_tab[33]
Definition: imcdata.h:29
state
static struct @385 state
IMCContext::weights1
float weights1[31]
Definition: imc.c:104
av_clipf
av_clipf
Definition: af_crystalizer.c:121
get_vlc2
static av_always_inline int get_vlc2(GetBitContext *s, const VLCElem *table, int bits, int max_depth)
Parse a vlc code.
Definition: get_bits.h:652
AVOnce
#define AVOnce
Definition: thread.h:202
cyclTab2
static const int8_t cyclTab2[32]
Definition: imcdata.h:42
float_dsp.h
AV_CODEC_CAP_CHANNEL_CONF
#define AV_CODEC_CAP_CHANNEL_CONF
Codec should fill in channel configuration and samplerate instead of container.
Definition: codec.h:106
IMCChannel::bandWidthT
int bandWidthT[BANDS]
codewords per band
Definition: imc.c:69
imc_decode_level_coefficients_raw
static void imc_decode_level_coefficients_raw(IMCContext *q, int *levlCoeffBuf, float *flcoeffs1, float *flcoeffs2)
Definition: imc.c:397
imc_huffman_syms
static const uint8_t imc_huffman_syms[4][4][18]
Definition: imcdata.h:142
VLC_TABLES_SIZE
#define VLC_TABLES_SIZE
Definition: imc.c:112
ff_get_buffer
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
Definition: decode.c:1569
init
int(* init)(AVBSFContext *ctx)
Definition: dts2pts.c:365
AV_CODEC_CAP_DR1
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
Definition: codec.h:52
AVPacket::size
int size
Definition: packet.h:523
scale
static void scale(int *out, const int *in, const int w, const int h, const int shift)
Definition: vvc_intra.c:291
powf
#define powf(x, y)
Definition: libm.h:50
AVChannelLayout
An AVChannelLayout holds information about the channel layout of audio data.
Definition: channel_layout.h:303
codec_internal.h
DECLARE_ALIGNED
#define DECLARE_ALIGNED(n, t, v)
Definition: mem_internal.h:109
huffman_vlc
static const VLCElem * huffman_vlc[4][4]
Definition: imc.c:109
for
for(k=2;k<=8;++k)
Definition: h264pred_template.c:425
AVCodecContext::sample_fmt
enum AVSampleFormat sample_fmt
audio sample format
Definition: avcodec.h:1057
AV_SAMPLE_FMT_NONE
@ AV_SAMPLE_FMT_NONE
Definition: samplefmt.h:56
VLCElem
Definition: vlc.h:32
imc_quantizer1
static const float imc_quantizer1[4][8]
Definition: imcdata.h:59
AVFloatDSPContext
Definition: float_dsp.h:22
sinewin.h
imc_decode_frame
static int imc_decode_frame(AVCodecContext *avctx, AVFrame *frame, int *got_frame_ptr, AVPacket *avpkt)
Definition: imc.c:957
av_tx_uninit
av_cold void av_tx_uninit(AVTXContext **ctx)
Frees a context and sets *ctx to NULL, does nothing when *ctx == NULL.
Definition: tx.c:294
ff_sine_window_init
void ff_sine_window_init(float *window, int n)
Generate a sine window.
Definition: sinewin_tablegen.h:59
flag
#define flag(name)
Definition: cbs_av1.c:474
AVFrame::nb_samples
int nb_samples
number of audio samples (per channel) described by this frame
Definition: frame.h:424
imc_refine_bit_allocation
static void imc_refine_bit_allocation(IMCContext *q, IMCChannel *chctx)
Definition: imc.c:764
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:255
bit_allocation
static int bit_allocation(IMCContext *q, IMCChannel *chctx, int stream_format_code, int freebits, int flag)
Perform bit allocation depending on bits available.
Definition: imc.c:422
internal.h
inverse_quant_coeff
static int inverse_quant_coeff(IMCContext *q, IMCChannel *chctx, int stream_format_code)
Definition: imc.c:696
AVFrame::extended_data
uint8_t ** extended_data
pointers to the data planes/channels.
Definition: frame.h:405
IMCChannel::bitsBandT
int bitsBandT[BANDS]
how many bits per codeword in band
Definition: imc.c:70
BANDS
#define BANDS
Definition: imc.c:56
xTab
static const float xTab[14]
Definition: imcdata.h:84
AVSampleFormat
AVSampleFormat
Audio sample formats.
Definition: samplefmt.h:55
exp2
#define exp2(x)
Definition: libm.h:288
tb
#define tb
Definition: regdef.h:68
AVCodec::name
const char * name
Name of the codec implementation.
Definition: codec.h:194
imc_decode_init
static av_cold int imc_decode_init(AVCodecContext *avctx)
Definition: imc.c:187
IMCChannel::levlCoeffBuf
int levlCoeffBuf[BANDS]
Definition: imc.c:72
IMCContext
Definition: imc.c:85
avcodec.h
limit
static double limit(double x)
Definition: vf_pseudocolor.c:142
AV_CODEC_ID_IAC
@ AV_CODEC_ID_IAC
Definition: codec_id.h:498
ret
ret
Definition: filter_design.txt:187
imc_huffman_sizes
static const uint8_t imc_huffman_sizes[4]
Definition: imcdata.h:111
pos
unsigned int pos
Definition: spdifenc.c:413
AV_INPUT_BUFFER_PADDING_SIZE
#define AV_INPUT_BUFFER_PADDING_SIZE
Definition: defs.h:40
AVCodecContext
main external API structure.
Definition: avcodec.h:445
IMCContext::out_samples
float * out_samples
Definition: imc.c:98
IMC_VLC_BITS
#define IMC_VLC_BITS
Definition: imc.c:111
channel_layout.h
t2
#define t2
Definition: regdef.h:30
IMCChannel::skipFlagBits
int skipFlagBits[BANDS]
bits used to code skip flags
Definition: imc.c:76
IMCContext::weights2
float weights2[31]
Definition: imc.c:104
IMCContext::avctx
AVCodecContext * avctx
Definition: imc.c:106
IMCChannel::flcoeffs2
float flcoeffs2[BANDS]
Definition: imc.c:62
av_channel_layout_uninit
void av_channel_layout_uninit(AVChannelLayout *channel_layout)
Free any allocated data in the channel layout and reset the channel count to 0.
Definition: channel_layout.c:432
imcdata.h
tf
#define tf
Definition: regdef.h:73
ffmath.h
IMCChannel::skipFlags
int skipFlags[COEFFS]
skip coefficient decoding or not
Definition: imc.c:78
ff_imc_decoder
const FFCodec ff_imc_decoder
ff_vlc_init_tables_from_lengths
const av_cold VLCElem * ff_vlc_init_tables_from_lengths(VLCInitState *state, int nb_bits, int nb_codes, const int8_t *lens, int lens_wrap, const void *symbols, int symbols_wrap, int symbols_size, int offset, int flags)
Definition: vlc.c:366
IMCContext::chctx
IMCChannel chctx[2]
Definition: imc.c:86
imc_decode_block
static int imc_decode_block(AVCodecContext *avctx, IMCContext *q, int ch)
Definition: imc.c:807
AV_CODEC_FLAG_BITEXACT
#define AV_CODEC_FLAG_BITEXACT
Use only bitexact stuff (except (I)DCT).
Definition: avcodec.h:342
avpriv_request_sample
#define avpriv_request_sample(...)
Definition: tableprint_vlc.h:36
AVFloatDSPContext::vector_fmul_window
void(* vector_fmul_window)(float *dst, const float *src0, const float *src1, const float *win, int len)
Overlap/add with window function.
Definition: float_dsp.h:117
AV_CHANNEL_LAYOUT_MONO
#define AV_CHANNEL_LAYOUT_MONO
Definition: channel_layout.h:378
av_free
#define av_free(p)
Definition: tableprint_vlc.h:33
VLC_INIT_STATE
#define VLC_INIT_STATE(_table)
Definition: vlc.h:214
AVPacket
This structure stores compressed data.
Definition: packet.h:499
AVCodecContext::priv_data
void * priv_data
Definition: avcodec.h:472
avpriv_float_dsp_alloc
av_cold AVFloatDSPContext * avpriv_float_dsp_alloc(int bit_exact)
Allocate a float DSP context.
Definition: float_dsp.c:135
imc_cb_select
static const uint8_t imc_cb_select[4][32]
Definition: imcdata.h:100
imc_decode_level_coefficients
static void imc_decode_level_coefficients(IMCContext *q, int *levlCoeffBuf, float *flcoeffs1, float *flcoeffs2)
Definition: imc.c:343
freq2bark
static double freq2bark(double freq)
Definition: imc.c:116
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
IMCContext::mdct
AVTXContext * mdct
Definition: imc.c:96
IMCContext::mdct_sine_window
float mdct_sine_window[COEFFS]
MDCT tables.
Definition: imc.c:89
AVERROR_INVALIDDATA
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:61
IMCContext::gb
GetBitContext gb
Definition: imc.c:92
BswapDSPContext
Definition: bswapdsp.h:24
IMCChannel::decoder_reset
int decoder_reset
Definition: imc.c:81
imc_get_coeffs
static void imc_get_coeffs(AVCodecContext *avctx, IMCContext *q, IMCChannel *chctx)
Definition: imc.c:736
imc_adjust_bit_allocation
static void imc_adjust_bit_allocation(IMCContext *q, IMCChannel *chctx, int summer)
Increase highest' band coefficient sizes as some bits won't be used.
Definition: imc.c:654
IMCChannel::flcoeffs1
float flcoeffs1[BANDS]
Definition: imc.c:61
tx.h
IMCChannel::codewords
int codewords[COEFFS]
raw codewords read from bitstream
Definition: imc.c:79
IMCChannel::sumLenArr
int sumLenArr[BANDS]
bits for all coeffs in band
Definition: imc.c:74