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