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.h"
42 #include "libavutil/mem_internal.h"
43 #include "libavutil/thread.h"
44 #include "libavutil/tx.h"
45 
46 #include "avcodec.h"
47 #include "bswapdsp.h"
48 #include "codec_internal.h"
49 #include "decode.h"
50 #include "get_bits.h"
51 #include "sinewin.h"
52 
53 #include "imcdata.h"
54 
55 #define IMC_BLOCK_SIZE 64
56 #define IMC_FRAME_ID 0x21
57 #define BANDS 32
58 #define COEFFS 256
59 
60 typedef struct IMCChannel {
61  float old_floor[BANDS];
62  float flcoeffs1[BANDS];
63  float flcoeffs2[BANDS];
64  float flcoeffs3[BANDS];
65  float flcoeffs4[BANDS];
66  float flcoeffs5[BANDS];
67  float flcoeffs6[BANDS];
69 
70  int bandWidthT[BANDS]; ///< codewords per band
71  int bitsBandT[BANDS]; ///< how many bits per codeword in band
72  int CWlengthT[COEFFS]; ///< how many bits in each codeword
74  int bandFlagsBuf[BANDS]; ///< flags for each band
75  int sumLenArr[BANDS]; ///< bits for all coeffs in band
76  int skipFlagRaw[BANDS]; ///< skip flags are stored in raw form or not
77  int skipFlagBits[BANDS]; ///< bits used to code skip flags
78  int skipFlagCount[BANDS]; ///< skipped coefficients per band
79  int skipFlags[COEFFS]; ///< skip coefficient decoding or not
80  int codewords[COEFFS]; ///< raw codewords read from bitstream
81 
83  DECLARE_ALIGNED(32, float, prev_win)[128];
84 } IMCChannel;
85 
86 typedef struct IMCContext {
88 
89  /** MDCT tables */
91 
92  float sqrt_tab[30];
94 
99  float *out_samples;
100  DECLARE_ALIGNED(32, float, temp)[256];
101 
103 
104  int8_t cyclTab[32], cyclTab2[32];
105  float weights1[31], weights2[31];
106 
108 } IMCContext;
109 
110 static const VLCElem *huffman_vlc[4][4];
111 
112 #define IMC_VLC_BITS 9
113 #define VLC_TABLES_SIZE 9512
114 
116 
117 static inline double freq2bark(double freq)
118 {
119  return 3.5 * atan((freq / 7500.0) * (freq / 7500.0)) + 13.0 * atan(freq * 0.00076);
120 }
121 
122 static av_cold void iac_generate_tabs(IMCContext *q, int sampling_rate)
123 {
124  double freqmin[32], freqmid[32], freqmax[32];
125  double scale = sampling_rate / (256.0 * 2.0 * 2.0);
126  double nyquist_freq = sampling_rate * 0.5;
127  double freq, bark, prev_bark = 0, tf, tb;
128  int i, j;
129 
130  for (i = 0; i < 32; i++) {
131  freq = (band_tab[i] + band_tab[i + 1] - 1) * scale;
132  bark = freq2bark(freq);
133 
134  if (i > 0) {
135  tb = bark - prev_bark;
136  q->weights1[i - 1] = ff_exp10(-1.0 * tb);
137  q->weights2[i - 1] = ff_exp10(-2.7 * tb);
138  }
139  prev_bark = bark;
140 
141  freqmid[i] = freq;
142 
143  tf = freq;
144  while (tf < nyquist_freq) {
145  tf += 0.5;
146  tb = freq2bark(tf);
147  if (tb > bark + 0.5)
148  break;
149  }
150  freqmax[i] = tf;
151 
152  tf = freq;
153  while (tf > 0.0) {
154  tf -= 0.5;
155  tb = freq2bark(tf);
156  if (tb <= bark - 0.5)
157  break;
158  }
159  freqmin[i] = tf;
160  }
161 
162  for (i = 0; i < 32; i++) {
163  freq = freqmax[i];
164  for (j = 31; j > 0 && freq <= freqmid[j]; j--);
165  q->cyclTab[i] = j + 1;
166 
167  freq = freqmin[i];
168  for (j = 0; j < 32 && freq >= freqmid[j]; j++);
169  q->cyclTab2[i] = j - 1;
170  }
171 }
172 
173 static av_cold void imc_init_static(void)
174 {
176  /* initialize the VLC tables */
177  for (int i = 0; i < 4 ; i++) {
178  for (int j = 0; j < 4; j++) {
179  huffman_vlc[i][j] =
181  imc_huffman_lens[i][j], 1,
182  imc_huffman_syms[i][j], 1, 1,
183  0, 0);
184  }
185  }
186 }
187 
189 {
190  int i, j, ret;
191  IMCContext *q = avctx->priv_data;
192  static AVOnce init_static_once = AV_ONCE_INIT;
193  float scale = 1.0f / (16384);
194 
195  if (avctx->codec_id == AV_CODEC_ID_IAC && avctx->sample_rate > 96000) {
196  av_log(avctx, AV_LOG_ERROR,
197  "Strange sample rate of %i, file likely corrupt or "
198  "needing a new table derivation method.\n",
199  avctx->sample_rate);
200  return AVERROR_PATCHWELCOME;
201  }
202 
203  if (avctx->codec_id == AV_CODEC_ID_IMC) {
206  }
207 
208  if (avctx->ch_layout.nb_channels > 2) {
209  avpriv_request_sample(avctx, "Number of channels > 2");
210  return AVERROR_PATCHWELCOME;
211  }
212 
213  for (j = 0; j < avctx->ch_layout.nb_channels; j++) {
214  q->chctx[j].decoder_reset = 1;
215 
216  for (i = 0; i < BANDS; i++)
217  q->chctx[j].old_floor[i] = 1.0;
218  }
219 
220  /* Build mdct window, a simple sine window normalized with sqrt(2) */
222  for (i = 0; i < COEFFS; i++)
223  q->mdct_sine_window[i] *= sqrt(2.0);
224 
225  /* Generate a square root table */
226  for (i = 0; i < 30; i++)
227  q->sqrt_tab[i] = sqrt(i);
228 
229  if (avctx->codec_id == AV_CODEC_ID_IAC) {
230  iac_generate_tabs(q, avctx->sample_rate);
231  } else {
232  memcpy(q->cyclTab, cyclTab, sizeof(cyclTab));
233  memcpy(q->cyclTab2, cyclTab2, sizeof(cyclTab2));
234  memcpy(q->weights1, imc_weights1, sizeof(imc_weights1));
235  memcpy(q->weights2, imc_weights2, sizeof(imc_weights2));
236  }
237 
239  if (!q->fdsp)
240  return AVERROR(ENOMEM);
241 
242  ret = av_tx_init(&q->mdct, &q->mdct_fn, AV_TX_FLOAT_MDCT, 1, COEFFS, &scale, 0);
243  if (ret < 0)
244  return ret;
245 
246  ff_bswapdsp_init(&q->bdsp);
247 
249 
250  ff_thread_once(&init_static_once, imc_init_static);
251 
252  return 0;
253 }
254 
255 static void imc_calculate_coeffs(IMCContext *q, float *flcoeffs1,
256  float *flcoeffs2, int *bandWidthT,
257  float *flcoeffs3, float *flcoeffs5)
258 {
259  float workT1[BANDS];
260  float workT2[BANDS];
261  float workT3[BANDS];
262  float snr_limit = 1.e-30;
263  float accum = 0.0;
264  int i, cnt2;
265 
266  for (i = 0; i < BANDS; i++) {
267  flcoeffs5[i] = workT2[i] = 0.0;
268  if (bandWidthT[i]) {
269  workT1[i] = flcoeffs1[i] * flcoeffs1[i];
270  flcoeffs3[i] = 2.0 * flcoeffs2[i];
271  } else {
272  workT1[i] = 0.0;
273  flcoeffs3[i] = -30000.0;
274  }
275  workT3[i] = bandWidthT[i] * workT1[i] * 0.01;
276  if (workT3[i] <= snr_limit)
277  workT3[i] = 0.0;
278  }
279 
280  for (i = 0; i < BANDS; i++) {
281  for (cnt2 = i; cnt2 < q->cyclTab[i]; cnt2++)
282  flcoeffs5[cnt2] = flcoeffs5[cnt2] + workT3[i];
283  workT2[cnt2 - 1] = workT2[cnt2 - 1] + workT3[i];
284  }
285 
286  for (i = 1; i < BANDS; i++) {
287  accum = (workT2[i - 1] + accum) * q->weights1[i - 1];
288  flcoeffs5[i] += accum;
289  }
290 
291  for (i = 0; i < BANDS; i++)
292  workT2[i] = 0.0;
293 
294  for (i = 0; i < BANDS; i++) {
295  for (cnt2 = i - 1; cnt2 > q->cyclTab2[i]; cnt2--)
296  flcoeffs5[cnt2] += workT3[i];
297  workT2[cnt2+1] += workT3[i];
298  }
299 
300  accum = 0.0;
301 
302  for (i = BANDS-2; i >= 0; i--) {
303  accum = (workT2[i+1] + accum) * q->weights2[i];
304  flcoeffs5[i] += accum;
305  // there is missing code here, but it seems to never be triggered
306  }
307 }
308 
309 
310 static void imc_read_level_coeffs(IMCContext *q, int stream_format_code,
311  int *levlCoeffs)
312 {
313  int i;
314  int start = 0;
315  const uint8_t *cb_sel;
316  int s = stream_format_code >> 1;
317  const VLCElem * const *const hufftab = huffman_vlc[s];
318 
319  cb_sel = imc_cb_select[s];
320 
321  if (stream_format_code & 4)
322  start = 1;
323  if (start)
324  levlCoeffs[0] = get_bits(&q->gb, 7);
325  for (i = start; i < BANDS; i++) {
326  levlCoeffs[i] = get_vlc2(&q->gb, hufftab[cb_sel[i]],
327  IMC_VLC_BITS, 2);
328  if (levlCoeffs[i] == 17)
329  levlCoeffs[i] += get_bits(&q->gb, 4);
330  }
331 }
332 
333 static void imc_read_level_coeffs_raw(IMCContext *q, int stream_format_code,
334  int *levlCoeffs)
335 {
336  int i;
337 
338  q->coef0_pos = get_bits(&q->gb, 5);
339  levlCoeffs[0] = get_bits(&q->gb, 7);
340  for (i = 1; i < BANDS; i++)
341  levlCoeffs[i] = get_bits(&q->gb, 4);
342 }
343 
344 static void imc_decode_level_coefficients(IMCContext *q, int *levlCoeffBuf,
345  float *flcoeffs1, float *flcoeffs2)
346 {
347  int i, level;
348  float tmp, tmp2;
349  // maybe some frequency division thingy
350 
351  flcoeffs1[0] = 20000.0 / exp2 (levlCoeffBuf[0] * 0.18945); // 0.18945 = log2(10) * 0.05703125
352  flcoeffs2[0] = log2f(flcoeffs1[0]);
353  tmp = flcoeffs1[0];
354  tmp2 = flcoeffs2[0];
355 
356  for (i = 1; i < BANDS; i++) {
357  level = levlCoeffBuf[i];
358  if (level == 16) {
359  flcoeffs1[i] = 1.0;
360  flcoeffs2[i] = 0.0;
361  } else {
362  if (level < 17)
363  level -= 7;
364  else if (level <= 24)
365  level -= 32;
366  else
367  level -= 16;
368 
369  tmp *= imc_exp_tab[15 + level];
370  tmp2 += 0.83048 * level; // 0.83048 = log2(10) * 0.25
371  flcoeffs1[i] = tmp;
372  flcoeffs2[i] = tmp2;
373  }
374  }
375 }
376 
377 
378 static void imc_decode_level_coefficients2(IMCContext *q, int *levlCoeffBuf,
379  float *old_floor, float *flcoeffs1,
380  float *flcoeffs2)
381 {
382  int i;
383  /* FIXME maybe flag_buf = noise coding and flcoeffs1 = new scale factors
384  * and flcoeffs2 old scale factors
385  * might be incomplete due to a missing table that is in the binary code
386  */
387  for (i = 0; i < BANDS; i++) {
388  flcoeffs1[i] = 0;
389  if (levlCoeffBuf[i] < 16) {
390  flcoeffs1[i] = imc_exp_tab2[levlCoeffBuf[i]] * old_floor[i];
391  flcoeffs2[i] = (levlCoeffBuf[i] - 7) * 0.83048 + flcoeffs2[i]; // 0.83048 = log2(10) * 0.25
392  } else {
393  flcoeffs1[i] = old_floor[i];
394  }
395  }
396 }
397 
398 static void imc_decode_level_coefficients_raw(IMCContext *q, int *levlCoeffBuf,
399  float *flcoeffs1, float *flcoeffs2)
400 {
401  int i, level, pos;
402  float tmp, tmp2;
403 
404  pos = q->coef0_pos;
405  flcoeffs1[pos] = 20000.0 / pow (2, levlCoeffBuf[0] * 0.18945); // 0.18945 = log2(10) * 0.05703125
406  flcoeffs2[pos] = log2f(flcoeffs1[pos]);
407  tmp = flcoeffs1[pos];
408  tmp2 = flcoeffs2[pos];
409 
410  levlCoeffBuf++;
411  for (i = 0; i < BANDS; i++) {
412  if (i == pos)
413  continue;
414  level = *levlCoeffBuf++;
415  flcoeffs1[i] = tmp * powf(10.0, -level * 0.4375); //todo tab
416  flcoeffs2[i] = tmp2 - 1.4533435415 * level; // 1.4533435415 = log2(10) * 0.4375
417  }
418 }
419 
420 /**
421  * Perform bit allocation depending on bits available
422  */
423 static int bit_allocation(IMCContext *q, IMCChannel *chctx,
424  int stream_format_code, int freebits, int flag)
425 {
426  int i, j;
427  const float limit = -1.e20;
428  float highest = 0.0;
429  int indx;
430  int t1 = 0;
431  int t2 = 1;
432  float summa = 0.0;
433  int iacc = 0;
434  int summer = 0;
435  int rres, cwlen;
436  float lowest = 1.e10;
437  int low_indx = 0;
438  float workT[32];
439  int flg;
440  int found_indx = 0;
441 
442  for (i = 0; i < BANDS; i++)
443  highest = FFMAX(highest, chctx->flcoeffs1[i]);
444 
445  for (i = 0; i < BANDS - 1; i++) {
446  if (chctx->flcoeffs5[i] <= 0) {
447  av_log(q->avctx, AV_LOG_ERROR, "flcoeffs5 %f invalid\n", chctx->flcoeffs5[i]);
448  return AVERROR_INVALIDDATA;
449  }
450  chctx->flcoeffs4[i] = chctx->flcoeffs3[i] - log2f(chctx->flcoeffs5[i]);
451  }
452  chctx->flcoeffs4[BANDS - 1] = limit;
453 
454  highest = highest * 0.25;
455 
456  for (i = 0; i < BANDS; i++) {
457  indx = -1;
458  if ((band_tab[i + 1] - band_tab[i]) == chctx->bandWidthT[i])
459  indx = 0;
460 
461  if ((band_tab[i + 1] - band_tab[i]) > chctx->bandWidthT[i])
462  indx = 1;
463 
464  if (((band_tab[i + 1] - band_tab[i]) / 2) >= chctx->bandWidthT[i])
465  indx = 2;
466 
467  if (indx == -1)
468  return AVERROR_INVALIDDATA;
469 
470  chctx->flcoeffs4[i] += xTab[(indx * 2 + (chctx->flcoeffs1[i] < highest)) * 2 + flag];
471  }
472 
473  if (stream_format_code & 0x2) {
474  chctx->flcoeffs4[0] = limit;
475  chctx->flcoeffs4[1] = limit;
476  chctx->flcoeffs4[2] = limit;
477  chctx->flcoeffs4[3] = limit;
478  }
479 
480  for (i = (stream_format_code & 0x2) ? 4 : 0; i < BANDS - 1; i++) {
481  iacc += chctx->bandWidthT[i];
482  summa += chctx->bandWidthT[i] * chctx->flcoeffs4[i];
483  }
484 
485  if (!iacc)
486  return AVERROR_INVALIDDATA;
487 
488  chctx->bandWidthT[BANDS - 1] = 0;
489  summa = (summa * 0.5 - freebits) / iacc;
490 
491 
492  for (i = 0; i < BANDS / 2; i++) {
493  rres = summer - freebits;
494  if ((rres >= -8) && (rres <= 8))
495  break;
496 
497  summer = 0;
498  iacc = 0;
499 
500  for (j = (stream_format_code & 0x2) ? 4 : 0; j < BANDS; j++) {
501  cwlen = av_clipf(((chctx->flcoeffs4[j] * 0.5) - summa + 0.5), 0, 6);
502 
503  chctx->bitsBandT[j] = cwlen;
504  summer += chctx->bandWidthT[j] * cwlen;
505 
506  if (cwlen > 0)
507  iacc += chctx->bandWidthT[j];
508  }
509 
510  flg = t2;
511  t2 = 1;
512  if (freebits < summer)
513  t2 = -1;
514  if (i == 0)
515  flg = t2;
516  if (flg != t2)
517  t1++;
518 
519  summa = (float)(summer - freebits) / ((t1 + 1) * iacc) + summa;
520  }
521 
522  for (i = (stream_format_code & 0x2) ? 4 : 0; i < BANDS; i++) {
523  for (j = band_tab[i]; j < band_tab[i + 1]; j++)
524  chctx->CWlengthT[j] = chctx->bitsBandT[i];
525  }
526 
527  if (freebits > summer) {
528  for (i = 0; i < BANDS; i++) {
529  workT[i] = (chctx->bitsBandT[i] == 6) ? -1.e20
530  : (chctx->bitsBandT[i] * -2 + chctx->flcoeffs4[i] - 0.415);
531  }
532 
533  highest = 0.0;
534 
535  do {
536  if (highest <= -1.e20)
537  break;
538 
539  found_indx = 0;
540  highest = -1.e20;
541 
542  for (i = 0; i < BANDS; i++) {
543  if (workT[i] > highest) {
544  highest = workT[i];
545  found_indx = i;
546  }
547  }
548 
549  if (highest > -1.e20) {
550  workT[found_indx] -= 2.0;
551  if (++chctx->bitsBandT[found_indx] == 6)
552  workT[found_indx] = -1.e20;
553 
554  for (j = band_tab[found_indx]; j < band_tab[found_indx + 1] && (freebits > summer); j++) {
555  chctx->CWlengthT[j]++;
556  summer++;
557  }
558  }
559  } while (freebits > summer);
560  }
561  if (freebits < summer) {
562  for (i = 0; i < BANDS; i++) {
563  workT[i] = chctx->bitsBandT[i] ? (chctx->bitsBandT[i] * -2 + chctx->flcoeffs4[i] + 1.585)
564  : 1.e20;
565  }
566  if (stream_format_code & 0x2) {
567  workT[0] = 1.e20;
568  workT[1] = 1.e20;
569  workT[2] = 1.e20;
570  workT[3] = 1.e20;
571  }
572  while (freebits < summer) {
573  lowest = 1.e10;
574  low_indx = 0;
575  for (i = 0; i < BANDS; i++) {
576  if (workT[i] < lowest) {
577  lowest = workT[i];
578  low_indx = i;
579  }
580  }
581  // if (lowest >= 1.e10)
582  // break;
583  workT[low_indx] = lowest + 2.0;
584 
585  if (!--chctx->bitsBandT[low_indx])
586  workT[low_indx] = 1.e20;
587 
588  for (j = band_tab[low_indx]; j < band_tab[low_indx+1] && (freebits < summer); j++) {
589  if (chctx->CWlengthT[j] > 0) {
590  chctx->CWlengthT[j]--;
591  summer--;
592  }
593  }
594  }
595  }
596  return 0;
597 }
598 
599 static void imc_get_skip_coeff(IMCContext *q, IMCChannel *chctx)
600 {
601  int i, j;
602 
603  memset(chctx->skipFlagBits, 0, sizeof(chctx->skipFlagBits));
604  memset(chctx->skipFlagCount, 0, sizeof(chctx->skipFlagCount));
605  for (i = 0; i < BANDS; i++) {
606  if (!chctx->bandFlagsBuf[i] || !chctx->bandWidthT[i])
607  continue;
608 
609  if (!chctx->skipFlagRaw[i]) {
610  chctx->skipFlagBits[i] = band_tab[i + 1] - band_tab[i];
611 
612  for (j = band_tab[i]; j < band_tab[i + 1]; j++) {
613  chctx->skipFlags[j] = get_bits1(&q->gb);
614  if (chctx->skipFlags[j])
615  chctx->skipFlagCount[i]++;
616  }
617  } else {
618  for (j = band_tab[i]; j < band_tab[i + 1] - 1; j += 2) {
619  if (!get_bits1(&q->gb)) { // 0
620  chctx->skipFlagBits[i]++;
621  chctx->skipFlags[j] = 1;
622  chctx->skipFlags[j + 1] = 1;
623  chctx->skipFlagCount[i] += 2;
624  } else {
625  if (get_bits1(&q->gb)) { // 11
626  chctx->skipFlagBits[i] += 2;
627  chctx->skipFlags[j] = 0;
628  chctx->skipFlags[j + 1] = 1;
629  chctx->skipFlagCount[i]++;
630  } else {
631  chctx->skipFlagBits[i] += 3;
632  chctx->skipFlags[j + 1] = 0;
633  if (!get_bits1(&q->gb)) { // 100
634  chctx->skipFlags[j] = 1;
635  chctx->skipFlagCount[i]++;
636  } else { // 101
637  chctx->skipFlags[j] = 0;
638  }
639  }
640  }
641  }
642 
643  if (j < band_tab[i + 1]) {
644  chctx->skipFlagBits[i]++;
645  if ((chctx->skipFlags[j] = get_bits1(&q->gb)))
646  chctx->skipFlagCount[i]++;
647  }
648  }
649  }
650 }
651 
652 /**
653  * Increase highest' band coefficient sizes as some bits won't be used
654  */
656  int summer)
657 {
658  float workT[32];
659  int corrected = 0;
660  int i, j;
661  float highest = 0;
662  int found_indx = 0;
663 
664  for (i = 0; i < BANDS; i++) {
665  workT[i] = (chctx->bitsBandT[i] == 6) ? -1.e20
666  : (chctx->bitsBandT[i] * -2 + chctx->flcoeffs4[i] - 0.415);
667  }
668 
669  while (corrected < summer) {
670  if (highest <= -1.e20)
671  break;
672 
673  highest = -1.e20;
674 
675  for (i = 0; i < BANDS; i++) {
676  if (workT[i] > highest) {
677  highest = workT[i];
678  found_indx = i;
679  }
680  }
681 
682  if (highest > -1.e20) {
683  workT[found_indx] -= 2.0;
684  if (++(chctx->bitsBandT[found_indx]) == 6)
685  workT[found_indx] = -1.e20;
686 
687  for (j = band_tab[found_indx]; j < band_tab[found_indx+1] && (corrected < summer); j++) {
688  if (!chctx->skipFlags[j] && (chctx->CWlengthT[j] < 6)) {
689  chctx->CWlengthT[j]++;
690  corrected++;
691  }
692  }
693  }
694  }
695 }
696 
698  int stream_format_code)
699 {
700  int i, j;
701  int middle_value, cw_len, max_size;
702  const float *quantizer;
703 
704  for (i = 0; i < BANDS; i++) {
705  for (j = band_tab[i]; j < band_tab[i + 1]; j++) {
706  chctx->CWdecoded[j] = 0;
707  cw_len = chctx->CWlengthT[j];
708 
709  if (cw_len <= 0 || chctx->skipFlags[j])
710  continue;
711 
712  max_size = 1 << cw_len;
713  middle_value = max_size >> 1;
714 
715  if (chctx->codewords[j] >= max_size || chctx->codewords[j] < 0)
716  return AVERROR_INVALIDDATA;
717 
718  if (cw_len >= 4) {
719  quantizer = imc_quantizer2[(stream_format_code & 2) >> 1];
720  if (chctx->codewords[j] >= middle_value)
721  chctx->CWdecoded[j] = quantizer[chctx->codewords[j] - 8] * chctx->flcoeffs6[i];
722  else
723  chctx->CWdecoded[j] = -quantizer[max_size - chctx->codewords[j] - 8 - 1] * chctx->flcoeffs6[i];
724  }else{
725  quantizer = imc_quantizer1[((stream_format_code & 2) >> 1) | (chctx->bandFlagsBuf[i] << 1)];
726  if (chctx->codewords[j] >= middle_value)
727  chctx->CWdecoded[j] = quantizer[chctx->codewords[j] - 1] * chctx->flcoeffs6[i];
728  else
729  chctx->CWdecoded[j] = -quantizer[max_size - 2 - chctx->codewords[j]] * chctx->flcoeffs6[i];
730  }
731  }
732  }
733  return 0;
734 }
735 
736 
737 static void imc_get_coeffs(AVCodecContext *avctx,
738  IMCContext *q, IMCChannel *chctx)
739 {
740  int i, j, cw_len, cw;
741 
742  for (i = 0; i < BANDS; i++) {
743  if (!chctx->sumLenArr[i])
744  continue;
745  if (chctx->bandFlagsBuf[i] || chctx->bandWidthT[i]) {
746  for (j = band_tab[i]; j < band_tab[i + 1]; j++) {
747  cw_len = chctx->CWlengthT[j];
748  cw = 0;
749 
750  if (cw_len && (!chctx->bandFlagsBuf[i] || !chctx->skipFlags[j])) {
751  if (get_bits_count(&q->gb) + cw_len > 512) {
752  av_log(avctx, AV_LOG_WARNING,
753  "Potential problem on band %i, coefficient %i"
754  ": cw_len=%i\n", i, j, cw_len);
755  } else
756  cw = get_bits(&q->gb, cw_len);
757  }
758 
759  chctx->codewords[j] = cw;
760  }
761  }
762  }
763 }
764 
766 {
767  int i, j;
768  int summer;
769 
770  for (i = 0; i < BANDS; i++) {
771  chctx->sumLenArr[i] = 0;
772  chctx->skipFlagRaw[i] = 0;
773  for (j = band_tab[i]; j < band_tab[i + 1]; j++)
774  chctx->sumLenArr[i] += chctx->CWlengthT[j];
775  if (chctx->bandFlagsBuf[i])
776  if (((int)((band_tab[i + 1] - band_tab[i]) * 1.5) > chctx->sumLenArr[i]) && (chctx->sumLenArr[i] > 0))
777  chctx->skipFlagRaw[i] = 1;
778  }
779 
780  imc_get_skip_coeff(q, chctx);
781 
782  for (i = 0; i < BANDS; i++) {
783  chctx->flcoeffs6[i] = chctx->flcoeffs1[i];
784  /* band has flag set and at least one coded coefficient */
785  if (chctx->bandFlagsBuf[i] && (band_tab[i + 1] - band_tab[i]) != chctx->skipFlagCount[i]) {
786  chctx->flcoeffs6[i] *= q->sqrt_tab[ band_tab[i + 1] - band_tab[i]] /
787  q->sqrt_tab[(band_tab[i + 1] - band_tab[i] - chctx->skipFlagCount[i])];
788  }
789  }
790 
791  /* calculate bits left, bits needed and adjust bit allocation */
792  summer = 0;
793 
794  for (i = 0; i < BANDS; i++) {
795  if (chctx->bandFlagsBuf[i]) {
796  for (j = band_tab[i]; j < band_tab[i + 1]; j++) {
797  if (chctx->skipFlags[j]) {
798  summer += chctx->CWlengthT[j];
799  chctx->CWlengthT[j] = 0;
800  }
801  }
802  summer -= chctx->skipFlagBits[i];
803  }
804  }
805  imc_adjust_bit_allocation(q, chctx, summer);
806 }
807 
808 static int imc_decode_block(AVCodecContext *avctx, IMCContext *q, int ch)
809 {
810  int stream_format_code;
811  int imc_hdr, i, j, ret;
812  int flag;
813  int bits;
814  int bitscount;
815  IMCChannel *chctx = q->chctx + ch;
816 
817 
818  /* Check the frame header */
819  imc_hdr = get_bits(&q->gb, 9);
820  if (imc_hdr & 0x18) {
821  av_log(avctx, AV_LOG_ERROR, "frame header check failed!\n");
822  av_log(avctx, AV_LOG_ERROR, "got %X.\n", imc_hdr);
823  return AVERROR_INVALIDDATA;
824  }
825  stream_format_code = get_bits(&q->gb, 3);
826 
827  if (stream_format_code & 0x04)
828  chctx->decoder_reset = 1;
829 
830  if (chctx->decoder_reset) {
831  for (i = 0; i < BANDS; i++)
832  chctx->old_floor[i] = 1.0;
833  for (i = 0; i < COEFFS; i++)
834  chctx->CWdecoded[i] = 0;
835  chctx->decoder_reset = 0;
836  }
837 
838  flag = get_bits1(&q->gb);
839  if (stream_format_code & 0x1)
840  imc_read_level_coeffs_raw(q, stream_format_code, chctx->levlCoeffBuf);
841  else
842  imc_read_level_coeffs(q, stream_format_code, chctx->levlCoeffBuf);
843 
844  if (stream_format_code & 0x1)
846  chctx->flcoeffs1, chctx->flcoeffs2);
847  else if (stream_format_code & 0x4)
849  chctx->flcoeffs1, chctx->flcoeffs2);
850  else
852  chctx->flcoeffs1, chctx->flcoeffs2);
853 
854  for(i=0; i<BANDS; i++) {
855  if(chctx->flcoeffs1[i] > INT_MAX) {
856  av_log(avctx, AV_LOG_ERROR, "scalefactor out of range\n");
857  return AVERROR_INVALIDDATA;
858  }
859  }
860 
861  memcpy(chctx->old_floor, chctx->flcoeffs1, 32 * sizeof(float));
862 
863  if (stream_format_code & 0x1) {
864  for (i = 0; i < BANDS; i++) {
865  chctx->bandWidthT[i] = band_tab[i + 1] - band_tab[i];
866  chctx->bandFlagsBuf[i] = 0;
867  chctx->flcoeffs3[i] = chctx->flcoeffs2[i] * 2;
868  chctx->flcoeffs5[i] = 1.0;
869  }
870  } else {
871  for (i = 0; i < BANDS; i++) {
872  if (chctx->levlCoeffBuf[i] == 16) {
873  chctx->bandWidthT[i] = 0;
874  } else
875  chctx->bandWidthT[i] = band_tab[i + 1] - band_tab[i];
876  }
877 
878  memset(chctx->bandFlagsBuf, 0, BANDS * sizeof(int));
879  for (i = 0; i < BANDS - 1; i++)
880  if (chctx->bandWidthT[i])
881  chctx->bandFlagsBuf[i] = get_bits1(&q->gb);
882 
883  imc_calculate_coeffs(q, chctx->flcoeffs1, chctx->flcoeffs2,
884  chctx->bandWidthT, chctx->flcoeffs3,
885  chctx->flcoeffs5);
886  }
887 
888  bitscount = 0;
889  /* first 4 bands will be assigned 5 bits per coefficient */
890  if (stream_format_code & 0x2) {
891  bitscount += 15;
892 
893  chctx->bitsBandT[0] = 5;
894  chctx->CWlengthT[0] = 5;
895  chctx->CWlengthT[1] = 5;
896  chctx->CWlengthT[2] = 5;
897  for (i = 1; i < 4; i++) {
898  if (stream_format_code & 0x1)
899  bits = 5;
900  else
901  bits = (chctx->levlCoeffBuf[i] == 16) ? 0 : 5;
902  chctx->bitsBandT[i] = bits;
903  for (j = band_tab[i]; j < band_tab[i + 1]; j++) {
904  chctx->CWlengthT[j] = bits;
905  bitscount += bits;
906  }
907  }
908  }
909  if (avctx->codec_id == AV_CODEC_ID_IAC) {
910  bitscount += !!chctx->bandWidthT[BANDS - 1];
911  if (!(stream_format_code & 0x2))
912  bitscount += 16;
913  }
914 
915  if ((ret = bit_allocation(q, chctx, stream_format_code,
916  512 - bitscount - get_bits_count(&q->gb),
917  flag)) < 0) {
918  av_log(avctx, AV_LOG_ERROR, "Bit allocations failed\n");
919  chctx->decoder_reset = 1;
920  return ret;
921  }
922 
923  if (stream_format_code & 0x1) {
924  for (i = 0; i < BANDS; i++)
925  chctx->skipFlags[i] = 0;
926  } else {
927  imc_refine_bit_allocation(q, chctx);
928  }
929 
930  for (i = 0; i < BANDS; i++) {
931  chctx->sumLenArr[i] = 0;
932 
933  for (j = band_tab[i]; j < band_tab[i + 1]; j++)
934  if (!chctx->skipFlags[j])
935  chctx->sumLenArr[i] += chctx->CWlengthT[j];
936  }
937 
938  memset(chctx->codewords, 0, sizeof(chctx->codewords));
939 
940  imc_get_coeffs(avctx, q, chctx);
941 
942  if (inverse_quant_coeff(q, chctx, stream_format_code) < 0) {
943  av_log(avctx, AV_LOG_ERROR, "Inverse quantization of coefficients failed\n");
944  chctx->decoder_reset = 1;
945  return AVERROR_INVALIDDATA;
946  }
947 
948  memset(chctx->skipFlags, 0, sizeof(chctx->skipFlags));
949 
950  q->mdct_fn(q->mdct, q->temp, chctx->CWdecoded, sizeof(float));
951  q->fdsp->vector_fmul_window(q->out_samples, chctx->prev_win, q->temp,
952  q->mdct_sine_window, 128);
953  memcpy(chctx->prev_win, q->temp + 128, sizeof(float)*128);
954 
955  return 0;
956 }
957 
959  int *got_frame_ptr, AVPacket *avpkt)
960 {
961  const uint8_t *buf = avpkt->data;
962  int buf_size = avpkt->size;
963  int ret, i;
964 
965  IMCContext *q = avctx->priv_data;
966 
968 
969  q->avctx = avctx;
970 
971  if (buf_size < IMC_BLOCK_SIZE * avctx->ch_layout.nb_channels) {
972  av_log(avctx, AV_LOG_ERROR, "frame too small!\n");
973  return AVERROR_INVALIDDATA;
974  }
975 
976  /* get output buffer */
977  frame->nb_samples = COEFFS;
978  if ((ret = ff_get_buffer(avctx, frame, 0)) < 0)
979  return ret;
980 
981  for (i = 0; i < avctx->ch_layout.nb_channels; i++) {
982  q->out_samples = (float *)frame->extended_data[i];
983 
984  q->bdsp.bswap16_buf(buf16, (const uint16_t *) buf, IMC_BLOCK_SIZE / 2);
985 
986  init_get_bits(&q->gb, (const uint8_t*)buf16, IMC_BLOCK_SIZE * 8);
987 
988  buf += IMC_BLOCK_SIZE;
989 
990  if ((ret = imc_decode_block(avctx, q, i)) < 0)
991  return ret;
992  }
993 
994  if (avctx->ch_layout.nb_channels == 2) {
995  q->fdsp->butterflies_float((float *)frame->extended_data[0],
996  (float *)frame->extended_data[1], COEFFS);
997  }
998 
999  *got_frame_ptr = 1;
1000 
1001  return IMC_BLOCK_SIZE * avctx->ch_layout.nb_channels;
1002 }
1003 
1005 {
1006  IMCContext *q = avctx->priv_data;
1007 
1008  av_free(q->fdsp);
1009  av_tx_uninit(&q->mdct);
1010 
1011  return 0;
1012 }
1013 
1014 static av_cold void flush(AVCodecContext *avctx)
1015 {
1016  IMCContext *q = avctx->priv_data;
1017 
1018  q->chctx[0].decoder_reset =
1019  q->chctx[1].decoder_reset = 1;
1020 }
1021 
1022 #if CONFIG_IMC_DECODER
1023 const FFCodec ff_imc_decoder = {
1024  .p.name = "imc",
1025  CODEC_LONG_NAME("IMC (Intel Music Coder)"),
1026  .p.type = AVMEDIA_TYPE_AUDIO,
1027  .p.id = AV_CODEC_ID_IMC,
1028  .priv_data_size = sizeof(IMCContext),
1029  .init = imc_decode_init,
1030  .close = imc_decode_close,
1032  .flush = flush,
1033  .p.capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_CHANNEL_CONF,
1034  .p.sample_fmts = (const enum AVSampleFormat[]) { AV_SAMPLE_FMT_FLTP,
1036  .caps_internal = FF_CODEC_CAP_INIT_CLEANUP,
1037 };
1038 #endif
1039 #if CONFIG_IAC_DECODER
1040 const FFCodec ff_iac_decoder = {
1041  .p.name = "iac",
1042  CODEC_LONG_NAME("IAC (Indeo Audio Coder)"),
1043  .p.type = AVMEDIA_TYPE_AUDIO,
1044  .p.id = AV_CODEC_ID_IAC,
1045  .priv_data_size = sizeof(IMCContext),
1046  .init = imc_decode_init,
1047  .close = imc_decode_close,
1049  .flush = flush,
1050  .p.capabilities = AV_CODEC_CAP_DR1,
1051  .p.sample_fmts = (const enum AVSampleFormat[]) { AV_SAMPLE_FMT_FLTP,
1053  .caps_internal = FF_CODEC_CAP_INIT_CLEANUP,
1054 };
1055 #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:104
level
uint8_t level
Definition: svq3.c:205
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:1014
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:72
mem_internal.h
IMCContext::coef0_pos
int coef0_pos
Definition: imc.c:102
imc_exp_tab
static const float imc_exp_tab[32]
Definition: imcdata.h:87
IMCChannel::flcoeffs3
float flcoeffs3[BANDS]
Definition: imc.c:64
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:98
log2f
#define log2f(x)
Definition: libm.h:409
thread.h
IMCChannel::skipFlagCount
int skipFlagCount[BANDS]
skipped coefficients per band
Definition: imc.c:78
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:68
IMCContext::cyclTab
int8_t cyclTab[32]
Definition: imc.c:104
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:374
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:122
AVPacket::data
uint8_t * data
Definition: packet.h:524
IMCContext::fdsp
AVFloatDSPContext * fdsp
Definition: imc.c:95
COEFFS
#define COEFFS
Definition: imc.c:58
FFCodec
Definition: codec_internal.h:126
IMCChannel::old_floor
float old_floor[BANDS]
Definition: imc.c:61
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:83
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:255
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:903
imc_read_level_coeffs_raw
static void imc_read_level_coeffs_raw(IMCContext *q, int stream_format_code, int *levlCoeffs)
Definition: imc.c:333
vlc_tables
static VLCElem vlc_tables[VLC_TABLES_SIZE]
Definition: imc.c:115
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:310
IMCChannel::flcoeffs4
float flcoeffs4[BANDS]
Definition: imc.c:65
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:130
IMCChannel::skipFlagRaw
int skipFlagRaw[BANDS]
skip flags are stored in raw form or not
Definition: imc.c:76
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:173
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:92
IMC_BLOCK_SIZE
#define IMC_BLOCK_SIZE
Definition: imc.c:55
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:212
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:1004
FF_CODEC_DECODE_CB
#define FF_CODEC_DECODE_CB(func)
Definition: codec_internal.h:286
s
#define s(width, name)
Definition: cbs_vp9.c:198
IMCChannel
Definition: imc.c:60
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:599
IMCChannel::flcoeffs5
float flcoeffs5[BANDS]
Definition: imc.c:66
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:271
AVCodecContext::codec_id
enum AVCodecID codec_id
Definition: avcodec.h:455
IMCChannel::bandFlagsBuf
int bandFlagsBuf[BANDS]
flags for each band
Definition: imc.c:74
imc_decode_level_coefficients2
static void imc_decode_level_coefficients2(IMCContext *q, int *levlCoeffBuf, float *old_floor, float *flcoeffs1, float *flcoeffs2)
Definition: imc.c:378
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:96
IMCChannel::flcoeffs6
float flcoeffs6[BANDS]
Definition: imc.c:67
get_bits1
static unsigned int get_bits1(GetBitContext *s)
Definition: get_bits.h:388
IMCContext::temp
float temp[256]
Definition: imc.c:100
band_tab
static const uint16_t band_tab[33]
Definition: imcdata.h:29
IMCContext::weights1
float weights1[31]
Definition: imc.c:105
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:70
imc_decode_level_coefficients_raw
static void imc_decode_level_coefficients_raw(IMCContext *q, int *levlCoeffBuf, float *flcoeffs1, float *flcoeffs2)
Definition: imc.c:398
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:113
ff_get_buffer
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
Definition: decode.c:1575
init
int(* init)(AVBSFContext *ctx)
Definition: dts2pts.c:366
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:525
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:110
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:958
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:295
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:466
imc_refine_bit_allocation
static void imc_refine_bit_allocation(IMCContext *q, IMCChannel *chctx)
Definition: imc.c:765
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:256
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:423
internal.h
inverse_quant_coeff
static int inverse_quant_coeff(IMCContext *q, IMCChannel *chctx, int stream_format_code)
Definition: imc.c:697
IMCChannel::bitsBandT
int bitsBandT[BANDS]
how many bits per codeword in band
Definition: imc.c:71
BANDS
#define BANDS
Definition: imc.c:57
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
state
static struct @416 state
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:188
IMCChannel::levlCoeffBuf
int levlCoeffBuf[BANDS]
Definition: imc.c:73
IMCContext
Definition: imc.c:86
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
frame
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several the filter must be ready for frames arriving randomly on any input any filter with several inputs will most likely require some kind of queuing mechanism It is perfectly acceptable to have a limited queue and to drop frames when the inputs are too unbalanced request_frame For filters that do not use the this method is called when a frame is wanted on an output For a it should directly call filter_frame on the corresponding output For a if there are queued frames already one of these frames should be pushed If the filter should request a frame on one of its repeatedly until at least one frame has been pushed Return or at least make progress towards producing a frame
Definition: filter_design.txt:264
imc_huffman_sizes
static const uint8_t imc_huffman_sizes[4]
Definition: imcdata.h:111
pos
unsigned int pos
Definition: spdifenc.c:414
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:99
IMC_VLC_BITS
#define IMC_VLC_BITS
Definition: imc.c:112
channel_layout.h
t2
#define t2
Definition: regdef.h:30
IMCChannel::skipFlagBits
int skipFlagBits[BANDS]
bits used to code skip flags
Definition: imc.c:77
IMCContext::weights2
float weights2[31]
Definition: imc.c:105
IMCContext::avctx
AVCodecContext * avctx
Definition: imc.c:107
IMCChannel::flcoeffs2
float flcoeffs2[BANDS]
Definition: imc.c:63
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:433
imcdata.h
tf
#define tf
Definition: regdef.h:73
ffmath.h
IMCChannel::skipFlags
int skipFlags[COEFFS]
skip coefficient decoding or not
Definition: imc.c:79
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:87
imc_decode_block
static int imc_decode_block(AVCodecContext *avctx, IMCContext *q, int ch)
Definition: imc.c:808
mem.h
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
scale
static void scale(int *out, const int *in, const int w, const int h, const int shift)
Definition: intra.c:291
VLC_INIT_STATE
#define VLC_INIT_STATE(_table)
Definition: vlc.h:217
AVPacket
This structure stores compressed data.
Definition: packet.h:501
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:344
freq2bark
static double freq2bark(double freq)
Definition: imc.c:117
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
IMCContext::mdct
AVTXContext * mdct
Definition: imc.c:97
IMCContext::mdct_sine_window
float mdct_sine_window[COEFFS]
MDCT tables.
Definition: imc.c:90
AVERROR_INVALIDDATA
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:61
IMCContext::gb
GetBitContext gb
Definition: imc.c:93
BswapDSPContext
Definition: bswapdsp.h:24
IMCChannel::decoder_reset
int decoder_reset
Definition: imc.c:82
imc_get_coeffs
static void imc_get_coeffs(AVCodecContext *avctx, IMCContext *q, IMCChannel *chctx)
Definition: imc.c:737
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:655
IMCChannel::flcoeffs1
float flcoeffs1[BANDS]
Definition: imc.c:62
tx.h
IMCChannel::codewords
int codewords[COEFFS]
raw codewords read from bitstream
Definition: imc.c:80
IMCChannel::sumLenArr
int sumLenArr[BANDS]
bits for all coeffs in band
Definition: imc.c:75