FFmpeg
twinvq.c
Go to the documentation of this file.
1 /*
2  * TwinVQ decoder
3  * Copyright (c) 2009 Vitor Sessak
4  *
5  * This file is part of FFmpeg.
6  *
7  * FFmpeg is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * FFmpeg is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with FFmpeg; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21 
22 #include <math.h>
23 #include <stdint.h>
24 
26 #include "libavutil/float_dsp.h"
27 #include "avcodec.h"
28 #include "decode.h"
29 #include "lsp.h"
30 #include "metasound_twinvq_data.h"
31 #include "sinewin.h"
32 #include "twinvq.h"
33 
34 /**
35  * Evaluate a single LPC amplitude spectrum envelope coefficient from the line
36  * spectrum pairs.
37  *
38  * @param lsp a vector of the cosine of the LSP values
39  * @param cos_val cos(PI*i/N) where i is the index of the LPC amplitude
40  * @param order the order of the LSP (and the size of the *lsp buffer). Must
41  * be a multiple of four.
42  * @return the LPC value
43  *
44  * @todo reuse code from Vorbis decoder: vorbis_floor0_decode
45  */
46 static float eval_lpc_spectrum(const float *lsp, float cos_val, int order)
47 {
48  int j;
49  float p = 0.5f;
50  float q = 0.5f;
51  float two_cos_w = 2.0f * cos_val;
52 
53  for (j = 0; j + 1 < order; j += 2 * 2) {
54  // Unroll the loop once since order is a multiple of four
55  q *= lsp[j] - two_cos_w;
56  p *= lsp[j + 1] - two_cos_w;
57 
58  q *= lsp[j + 2] - two_cos_w;
59  p *= lsp[j + 3] - two_cos_w;
60  }
61 
62  p *= p * (2.0f - two_cos_w);
63  q *= q * (2.0f + two_cos_w);
64 
65  return 0.5 / (p + q);
66 }
67 
68 /**
69  * Evaluate the LPC amplitude spectrum envelope from the line spectrum pairs.
70  */
71 static void eval_lpcenv(TwinVQContext *tctx, const float *cos_vals, float *lpc)
72 {
73  int i;
74  const TwinVQModeTab *mtab = tctx->mtab;
75  int size_s = mtab->size / mtab->fmode[TWINVQ_FT_SHORT].sub;
76 
77  for (i = 0; i < size_s / 2; i++) {
78  float cos_i = tctx->cos_tabs[0][i];
79  lpc[i] = eval_lpc_spectrum(cos_vals, cos_i, mtab->n_lsp);
80  lpc[size_s - i - 1] = eval_lpc_spectrum(cos_vals, -cos_i, mtab->n_lsp);
81  }
82 }
83 
84 static void interpolate(float *out, float v1, float v2, int size)
85 {
86  int i;
87  float step = (v1 - v2) / (size + 1);
88 
89  for (i = 0; i < size; i++) {
90  v2 += step;
91  out[i] = v2;
92  }
93 }
94 
95 static inline float get_cos(int idx, int part, const float *cos_tab, int size)
96 {
97  return part ? -cos_tab[size - idx - 1]
98  : cos_tab[idx];
99 }
100 
101 /**
102  * Evaluate the LPC amplitude spectrum envelope from the line spectrum pairs.
103  * Probably for speed reasons, the coefficients are evaluated as
104  * siiiibiiiisiiiibiiiisiiiibiiiisiiiibiiiis ...
105  * where s is an evaluated value, i is a value interpolated from the others
106  * and b might be either calculated or interpolated, depending on an
107  * unexplained condition.
108  *
109  * @param step the size of a block "siiiibiiii"
110  * @param in the cosine of the LSP data
111  * @param part is 0 for 0...PI (positive cosine values) and 1 for PI...2PI
112  * (negative cosine values)
113  * @param size the size of the whole output
114  */
115 static inline void eval_lpcenv_or_interp(TwinVQContext *tctx,
116  enum TwinVQFrameType ftype,
117  float *out, const float *in,
118  int size, int step, int part)
119 {
120  int i;
121  const TwinVQModeTab *mtab = tctx->mtab;
122  const float *cos_tab = tctx->cos_tabs[ftype];
123 
124  // Fill the 's'
125  for (i = 0; i < size; i += step)
126  out[i] =
128  get_cos(i, part, cos_tab, size),
129  mtab->n_lsp);
130 
131  // Fill the 'iiiibiiii'
132  for (i = step; i <= size - 2 * step; i += step) {
133  if (out[i + step] + out[i - step] > 1.95 * out[i] ||
134  out[i + step] >= out[i - step]) {
135  interpolate(out + i - step + 1, out[i], out[i - step], step - 1);
136  } else {
137  out[i - step / 2] =
139  get_cos(i - step / 2, part, cos_tab, size),
140  mtab->n_lsp);
141  interpolate(out + i - step + 1, out[i - step / 2],
142  out[i - step], step / 2 - 1);
143  interpolate(out + i - step / 2 + 1, out[i],
144  out[i - step / 2], step / 2 - 1);
145  }
146  }
147 
148  interpolate(out + size - 2 * step + 1, out[size - step],
149  out[size - 2 * step], step - 1);
150 }
151 
153  const float *buf, float *lpc,
154  int size, int step)
155 {
156  eval_lpcenv_or_interp(tctx, ftype, lpc, buf, size / 2, step, 0);
157  eval_lpcenv_or_interp(tctx, ftype, lpc + size / 2, buf, size / 2,
158  2 * step, 1);
159 
160  interpolate(lpc + size / 2 - step + 1, lpc[size / 2],
161  lpc[size / 2 - step], step);
162 
163  twinvq_memset_float(lpc + size - 2 * step + 1, lpc[size - 2 * step],
164  2 * step - 1);
165 }
166 
167 /**
168  * Inverse quantization. Read CB coefficients for cb1 and cb2 from the
169  * bitstream, sum the corresponding vectors and write the result to *out
170  * after permutation.
171  */
172 static void dequant(TwinVQContext *tctx, const uint8_t *cb_bits, float *out,
173  enum TwinVQFrameType ftype,
174  const int16_t *cb0, const int16_t *cb1, int cb_len)
175 {
176  int pos = 0;
177  int i, j;
178 
179  for (i = 0; i < tctx->n_div[ftype]; i++) {
180  int tmp0, tmp1;
181  int sign0 = 1;
182  int sign1 = 1;
183  const int16_t *tab0, *tab1;
184  int length = tctx->length[ftype][i >= tctx->length_change[ftype]];
185  int bitstream_second_part = (i >= tctx->bits_main_spec_change[ftype]);
186 
187  int bits = tctx->bits_main_spec[0][ftype][bitstream_second_part];
188  tmp0 = *cb_bits++;
189  if (bits == 7) {
190  if (tmp0 & 0x40)
191  sign0 = -1;
192  tmp0 &= 0x3F;
193  }
194 
195  bits = tctx->bits_main_spec[1][ftype][bitstream_second_part];
196  tmp1 = *cb_bits++;
197  if (bits == 7) {
198  if (tmp1 & 0x40)
199  sign1 = -1;
200  tmp1 &= 0x3F;
201  }
202 
203  tab0 = cb0 + tmp0 * cb_len;
204  tab1 = cb1 + tmp1 * cb_len;
205 
206  for (j = 0; j < length; j++)
207  out[tctx->permut[ftype][pos + j]] = sign0 * tab0[j] +
208  sign1 * tab1[j];
209 
210  pos += length;
211  }
212 }
213 
214 static void dec_gain(TwinVQContext *tctx,
215  enum TwinVQFrameType ftype, float *out)
216 {
217  const TwinVQModeTab *mtab = tctx->mtab;
218  const TwinVQFrameData *bits = &tctx->bits[tctx->cur_frame];
219  int i, j;
220  int channels = tctx->avctx->ch_layout.nb_channels;
221  int sub = mtab->fmode[ftype].sub;
222  float step = TWINVQ_AMP_MAX / ((1 << TWINVQ_GAIN_BITS) - 1);
223  float sub_step = TWINVQ_SUB_AMP_MAX / ((1 << TWINVQ_SUB_GAIN_BITS) - 1);
224 
225  if (ftype == TWINVQ_FT_LONG) {
226  for (i = 0; i < channels; i++)
227  out[i] = (1.0 / (1 << 13)) *
228  twinvq_mulawinv(step * 0.5 + step * bits->gain_bits[i],
230  } else {
231  for (i = 0; i < channels; i++) {
232  float val = (1.0 / (1 << 23)) *
233  twinvq_mulawinv(step * 0.5 + step * bits->gain_bits[i],
235 
236  for (j = 0; j < sub; j++)
237  out[i * sub + j] =
238  val * twinvq_mulawinv(sub_step * 0.5 +
239  sub_step * bits->sub_gain_bits[i * sub + j],
241  }
242  }
243 }
244 
245 /**
246  * Rearrange the LSP coefficients so that they have a minimum distance of
247  * min_dist. This function does it exactly as described in section of 3.2.4
248  * of the G.729 specification (but interestingly is different from what the
249  * reference decoder actually does).
250  */
251 static void rearrange_lsp(int order, float *lsp, float min_dist)
252 {
253  int i;
254  float min_dist2 = min_dist * 0.5;
255  for (i = 1; i < order; i++)
256  if (lsp[i] - lsp[i - 1] < min_dist) {
257  float avg = (lsp[i] + lsp[i - 1]) * 0.5;
258 
259  lsp[i - 1] = avg - min_dist2;
260  lsp[i] = avg + min_dist2;
261  }
262 }
263 
264 static void decode_lsp(TwinVQContext *tctx, int lpc_idx1, uint8_t *lpc_idx2,
265  int lpc_hist_idx, float *lsp, float *hist)
266 {
267  const TwinVQModeTab *mtab = tctx->mtab;
268  int i, j;
269 
270  const float *cb = mtab->lspcodebook;
271  const float *cb2 = cb + (1 << mtab->lsp_bit1) * mtab->n_lsp;
272  const float *cb3 = cb2 + (1 << mtab->lsp_bit2) * mtab->n_lsp;
273 
274  const int8_t funny_rounding[4] = {
275  -2,
276  mtab->lsp_split == 4 ? -2 : 1,
277  mtab->lsp_split == 4 ? -2 : 1,
278  0
279  };
280 
281  j = 0;
282  for (i = 0; i < mtab->lsp_split; i++) {
283  int chunk_end = ((i + 1) * mtab->n_lsp + funny_rounding[i]) /
284  mtab->lsp_split;
285  for (; j < chunk_end; j++)
286  lsp[j] = cb[lpc_idx1 * mtab->n_lsp + j] +
287  cb2[lpc_idx2[i] * mtab->n_lsp + j];
288  }
289 
290  rearrange_lsp(mtab->n_lsp, lsp, 0.0001);
291 
292  for (i = 0; i < mtab->n_lsp; i++) {
293  float tmp1 = 1.0 - cb3[lpc_hist_idx * mtab->n_lsp + i];
294  float tmp2 = hist[i] * cb3[lpc_hist_idx * mtab->n_lsp + i];
295  hist[i] = lsp[i];
296  lsp[i] = lsp[i] * tmp1 + tmp2;
297  }
298 
299  rearrange_lsp(mtab->n_lsp, lsp, 0.0001);
300  rearrange_lsp(mtab->n_lsp, lsp, 0.000095);
302 }
303 
304 static void dec_lpc_spectrum_inv(TwinVQContext *tctx, float *lsp,
305  enum TwinVQFrameType ftype, float *lpc)
306 {
307  int i;
308  int size = tctx->mtab->size / tctx->mtab->fmode[ftype].sub;
309 
310  for (i = 0; i < tctx->mtab->n_lsp; i++)
311  lsp[i] = 2 * cos(lsp[i]);
312 
313  switch (ftype) {
314  case TWINVQ_FT_LONG:
315  eval_lpcenv_2parts(tctx, ftype, lsp, lpc, size, 8);
316  break;
317  case TWINVQ_FT_MEDIUM:
318  eval_lpcenv_2parts(tctx, ftype, lsp, lpc, size, 2);
319  break;
320  case TWINVQ_FT_SHORT:
321  eval_lpcenv(tctx, lsp, lpc);
322  break;
323  }
324 }
325 
326 static const uint8_t wtype_to_wsize[] = { 0, 0, 2, 2, 2, 1, 0, 1, 1 };
327 
329  int wtype, float *in, float *prev, int ch)
330 {
331  AVTXContext *tx = tctx->tx[ftype];
332  av_tx_fn tx_fn = tctx->tx_fn[ftype];
333  const TwinVQModeTab *mtab = tctx->mtab;
334  int bsize = mtab->size / mtab->fmode[ftype].sub;
335  int size = mtab->size;
336  float *buf1 = tctx->tmp_buf;
337  int j, first_wsize, wsize; // Window size
338  float *out = tctx->curr_frame + 2 * ch * mtab->size;
339  float *out2 = out;
340  float *prev_buf;
341  int types_sizes[] = {
342  mtab->size / mtab->fmode[TWINVQ_FT_LONG].sub,
343  mtab->size / mtab->fmode[TWINVQ_FT_MEDIUM].sub,
344  mtab->size / (mtab->fmode[TWINVQ_FT_SHORT].sub * 2),
345  };
346 
347  wsize = types_sizes[wtype_to_wsize[wtype]];
348  first_wsize = wsize;
349  prev_buf = prev + (size - bsize) / 2;
350 
351  for (j = 0; j < mtab->fmode[ftype].sub; j++) {
352  int sub_wtype = ftype == TWINVQ_FT_MEDIUM ? 8 : wtype;
353 
354  if (!j && wtype == 4)
355  sub_wtype = 4;
356  else if (j == mtab->fmode[ftype].sub - 1 && wtype == 7)
357  sub_wtype = 7;
358 
359  wsize = types_sizes[wtype_to_wsize[sub_wtype]];
360 
361  tx_fn(tx, buf1 + bsize * j, in + bsize * j, sizeof(float));
362 
363  tctx->fdsp->vector_fmul_window(out2, prev_buf + (bsize - wsize) / 2,
364  buf1 + bsize * j,
365  ff_sine_windows[av_log2(wsize)],
366  wsize / 2);
367  out2 += wsize;
368 
369  memcpy(out2, buf1 + bsize * j + wsize / 2,
370  (bsize - wsize / 2) * sizeof(float));
371 
372  out2 += ftype == TWINVQ_FT_MEDIUM ? (bsize - wsize) / 2 : bsize - wsize;
373 
374  prev_buf = buf1 + bsize * j + bsize / 2;
375  }
376 
377  tctx->last_block_pos[ch] = (size + first_wsize) / 2;
378 }
379 
381  int wtype, float **out, int offset)
382 {
383  const TwinVQModeTab *mtab = tctx->mtab;
384  float *prev_buf = tctx->prev_frame + tctx->last_block_pos[0];
385  int channels = tctx->avctx->ch_layout.nb_channels;
386  int size1, size2, i;
387  float *out1, *out2;
388 
389  for (i = 0; i < channels; i++)
390  imdct_and_window(tctx, ftype, wtype,
391  tctx->spectrum + i * mtab->size,
392  prev_buf + 2 * i * mtab->size,
393  i);
394 
395  if (!out)
396  return;
397 
398  size2 = tctx->last_block_pos[0];
399  size1 = mtab->size - size2;
400 
401  out1 = &out[0][0] + offset;
402  memcpy(out1, prev_buf, size1 * sizeof(*out1));
403  memcpy(out1 + size1, tctx->curr_frame, size2 * sizeof(*out1));
404 
405  if (channels == 2) {
406  out2 = &out[1][0] + offset;
407  memcpy(out2, &prev_buf[2 * mtab->size],
408  size1 * sizeof(*out2));
409  memcpy(out2 + size1, &tctx->curr_frame[2 * mtab->size],
410  size2 * sizeof(*out2));
411  tctx->fdsp->butterflies_float(out1, out2, mtab->size);
412  }
413 }
414 
415 static void read_and_decode_spectrum(TwinVQContext *tctx, float *out,
416  enum TwinVQFrameType ftype)
417 {
418  const TwinVQModeTab *mtab = tctx->mtab;
419  TwinVQFrameData *bits = &tctx->bits[tctx->cur_frame];
420  int channels = tctx->avctx->ch_layout.nb_channels;
421  int sub = mtab->fmode[ftype].sub;
422  int block_size = mtab->size / sub;
424  float ppc_shape[TWINVQ_PPC_SHAPE_LEN_MAX * TWINVQ_CHANNELS_MAX * 4];
425 
426  int i, j;
427 
428  dequant(tctx, bits->main_coeffs, out, ftype,
429  mtab->fmode[ftype].cb0, mtab->fmode[ftype].cb1,
430  mtab->fmode[ftype].cb_len_read);
431 
432  dec_gain(tctx, ftype, gain);
433 
434  if (ftype == TWINVQ_FT_LONG) {
435  int cb_len_p = (tctx->n_div[3] + mtab->ppc_shape_len * channels - 1) /
436  tctx->n_div[3];
437  dequant(tctx, bits->ppc_coeffs, ppc_shape,
439  mtab->ppc_shape_cb + cb_len_p * TWINVQ_PPC_SHAPE_CB_SIZE,
440  cb_len_p);
441  }
442 
443  for (i = 0; i < channels; i++) {
444  float *chunk = out + mtab->size * i;
445  float lsp[TWINVQ_LSP_COEFS_MAX];
446 
447  for (j = 0; j < sub; j++) {
448  tctx->dec_bark_env(tctx, bits->bark1[i][j],
449  bits->bark_use_hist[i][j], i,
450  tctx->tmp_buf, gain[sub * i + j], ftype);
451 
452  tctx->fdsp->vector_fmul(chunk + block_size * j,
453  chunk + block_size * j,
454  tctx->tmp_buf, block_size);
455  }
456 
457  if (ftype == TWINVQ_FT_LONG)
458  tctx->decode_ppc(tctx, bits->p_coef[i], bits->g_coef[i],
459  ppc_shape + i * mtab->ppc_shape_len, chunk);
460 
461  decode_lsp(tctx, bits->lpc_idx1[i], bits->lpc_idx2[i],
462  bits->lpc_hist_idx[i], lsp, tctx->lsp_hist[i]);
463 
464  dec_lpc_spectrum_inv(tctx, lsp, ftype, tctx->tmp_buf);
465 
466  for (j = 0; j < mtab->fmode[ftype].sub; j++) {
467  tctx->fdsp->vector_fmul(chunk, chunk, tctx->tmp_buf, block_size);
468  chunk += block_size;
469  }
470  }
471 }
472 
477 };
478 
480  int *got_frame_ptr, AVPacket *avpkt)
481 {
482  const uint8_t *buf = avpkt->data;
483  int buf_size = avpkt->size;
484  TwinVQContext *tctx = avctx->priv_data;
485  const TwinVQModeTab *mtab = tctx->mtab;
486  float **out = NULL;
487  int ret;
488 
489  /* get output buffer */
490  if (tctx->discarded_packets >= 2) {
491  frame->nb_samples = mtab->size * tctx->frames_per_packet;
492  if ((ret = ff_get_buffer(avctx, frame, 0)) < 0)
493  return ret;
494  out = (float **)frame->extended_data;
495  }
496 
497  if (buf_size < avctx->block_align) {
498  av_log(avctx, AV_LOG_ERROR,
499  "Frame too small (%d bytes). Truncated file?\n", buf_size);
500  return AVERROR(EINVAL);
501  }
502 
503  if ((ret = tctx->read_bitstream(avctx, tctx, buf, buf_size)) < 0)
504  return ret;
505 
506  for (tctx->cur_frame = 0; tctx->cur_frame < tctx->frames_per_packet;
507  tctx->cur_frame++) {
509  tctx->bits[tctx->cur_frame].ftype);
510 
511  imdct_output(tctx, tctx->bits[tctx->cur_frame].ftype,
512  tctx->bits[tctx->cur_frame].window_type, out,
513  tctx->cur_frame * mtab->size);
514 
515  FFSWAP(float *, tctx->curr_frame, tctx->prev_frame);
516  }
517 
518  if (tctx->discarded_packets < 2) {
519  tctx->discarded_packets++;
520  *got_frame_ptr = 0;
521  return buf_size;
522  }
523 
524  *got_frame_ptr = 1;
525 
526  // VQF can deliver packets 1 byte greater than block align
527  if (buf_size == avctx->block_align + 1)
528  return buf_size;
529  return avctx->block_align;
530 }
531 
532 /**
533  * Init IMDCT and windowing tables
534  */
536 {
537  int i, j, ret;
538  const TwinVQModeTab *mtab = tctx->mtab;
539  int size_s = mtab->size / mtab->fmode[TWINVQ_FT_SHORT].sub;
540  int size_m = mtab->size / mtab->fmode[TWINVQ_FT_MEDIUM].sub;
541  int channels = tctx->avctx->ch_layout.nb_channels;
542  float norm = channels == 1 ? 2.0 : 1.0;
543  int table_size = 2 * mtab->size * channels;
544 
545  for (i = 0; i < 3; i++) {
546  int bsize = tctx->mtab->size / tctx->mtab->fmode[i].sub;
547  const float scale = -sqrt(norm / bsize) / (1 << 15);
548  if ((ret = av_tx_init(&tctx->tx[i], &tctx->tx_fn[i], AV_TX_FLOAT_MDCT,
549  1, bsize, &scale, 0)))
550  return ret;
551  }
552 
553  if (!FF_ALLOC_TYPED_ARRAY(tctx->tmp_buf, mtab->size) ||
554  !FF_ALLOC_TYPED_ARRAY(tctx->spectrum, table_size) ||
555  !FF_ALLOC_TYPED_ARRAY(tctx->curr_frame, table_size) ||
556  !FF_ALLOC_TYPED_ARRAY(tctx->prev_frame, table_size))
557  return AVERROR(ENOMEM);
558 
559  for (i = 0; i < 3; i++) {
560  int m = 4 * mtab->size / mtab->fmode[i].sub;
561  double freq = 2 * M_PI / m;
562  if (!FF_ALLOC_TYPED_ARRAY(tctx->cos_tabs[i], m / 4))
563  return AVERROR(ENOMEM);
564  for (j = 0; j <= m / 8; j++)
565  tctx->cos_tabs[i][j] = cos((2 * j + 1) * freq);
566  for (j = 1; j < m / 8; j++)
567  tctx->cos_tabs[i][m / 4 - j] = tctx->cos_tabs[i][j];
568  }
569 
571  ff_init_ff_sine_windows(av_log2(size_s / 2));
573 
574  return 0;
575 }
576 
577 /**
578  * Interpret the data as if it were a num_blocks x line_len[0] matrix and for
579  * each line do a cyclic permutation, i.e.
580  * abcdefghijklm -> defghijklmabc
581  * where the amount to be shifted is evaluated depending on the column.
582  */
583 static void permutate_in_line(int16_t *tab, int num_vect, int num_blocks,
584  int block_size,
585  const uint8_t line_len[2], int length_div,
586  enum TwinVQFrameType ftype)
587 {
588  int i, j;
589 
590  for (i = 0; i < line_len[0]; i++) {
591  int shift;
592 
593  if (num_blocks == 1 ||
594  (ftype == TWINVQ_FT_LONG && num_vect % num_blocks) ||
595  (ftype != TWINVQ_FT_LONG && num_vect & 1) ||
596  i == line_len[1]) {
597  shift = 0;
598  } else if (ftype == TWINVQ_FT_LONG) {
599  shift = i;
600  } else
601  shift = i * i;
602 
603  for (j = 0; j < num_vect && (j + num_vect * i < block_size * num_blocks); j++)
604  tab[i * num_vect + j] = i * num_vect + (j + shift) % num_vect;
605  }
606 }
607 
608 /**
609  * Interpret the input data as in the following table:
610  *
611  * @verbatim
612  *
613  * abcdefgh
614  * ijklmnop
615  * qrstuvw
616  * x123456
617  *
618  * @endverbatim
619  *
620  * and transpose it, giving the output
621  * aiqxbjr1cks2dlt3emu4fvn5gow6hp
622  */
623 static void transpose_perm(int16_t *out, int16_t *in, int num_vect,
624  const uint8_t line_len[2], int length_div)
625 {
626  int i, j;
627  int cont = 0;
628 
629  for (i = 0; i < num_vect; i++)
630  for (j = 0; j < line_len[i >= length_div]; j++)
631  out[cont++] = in[j * num_vect + i];
632 }
633 
634 static void linear_perm(int16_t *out, int16_t *in, int n_blocks, int size)
635 {
636  int block_size = size / n_blocks;
637  int i;
638 
639  for (i = 0; i < size; i++)
640  out[i] = block_size * (in[i] % n_blocks) + in[i] / n_blocks;
641 }
642 
644  enum TwinVQFrameType ftype)
645 {
646  int block_size, size;
647  const TwinVQModeTab *mtab = tctx->mtab;
648  int16_t *tmp_perm = (int16_t *)tctx->tmp_buf;
649 
650  if (ftype == TWINVQ_FT_PPC) {
651  size = tctx->avctx->ch_layout.nb_channels;
652  block_size = mtab->ppc_shape_len;
653  } else {
654  size = tctx->avctx->ch_layout.nb_channels * mtab->fmode[ftype].sub;
655  block_size = mtab->size / mtab->fmode[ftype].sub;
656  }
657 
658  permutate_in_line(tmp_perm, tctx->n_div[ftype], size,
659  block_size, tctx->length[ftype],
660  tctx->length_change[ftype], ftype);
661 
662  transpose_perm(tctx->permut[ftype], tmp_perm, tctx->n_div[ftype],
663  tctx->length[ftype], tctx->length_change[ftype]);
664 
665  linear_perm(tctx->permut[ftype], tctx->permut[ftype], size,
666  size * block_size);
667 }
668 
670 {
671  const TwinVQModeTab *mtab = tctx->mtab;
672  int n_ch = tctx->avctx->ch_layout.nb_channels;
673  int total_fr_bits = tctx->avctx->bit_rate * mtab->size /
674  tctx->avctx->sample_rate;
675 
676  int lsp_bits_per_block = n_ch * (mtab->lsp_bit0 + mtab->lsp_bit1 +
677  mtab->lsp_split * mtab->lsp_bit2);
678 
679  int ppc_bits = n_ch * (mtab->pgain_bit + mtab->ppc_shape_bit +
680  mtab->ppc_period_bit);
681 
682  int bsize_no_main_cb[3], bse_bits[3], i;
683  enum TwinVQFrameType frametype;
684 
685  for (i = 0; i < 3; i++)
686  // +1 for history usage switch
687  bse_bits[i] = n_ch *
688  (mtab->fmode[i].bark_n_coef *
689  mtab->fmode[i].bark_n_bit + 1);
690 
691  bsize_no_main_cb[2] = bse_bits[2] + lsp_bits_per_block + ppc_bits +
693 
694  for (i = 0; i < 2; i++)
695  bsize_no_main_cb[i] =
696  lsp_bits_per_block + n_ch * TWINVQ_GAIN_BITS +
698  mtab->fmode[i].sub * (bse_bits[i] + n_ch * TWINVQ_SUB_GAIN_BITS);
699 
700  if (tctx->codec == TWINVQ_CODEC_METASOUND && !tctx->is_6kbps) {
701  bsize_no_main_cb[1] += 2;
702  bsize_no_main_cb[2] += 2;
703  }
704 
705  // The remaining bits are all used for the main spectrum coefficients
706  for (i = 0; i < 4; i++) {
707  int bit_size, vect_size;
708  int rounded_up, rounded_down, num_rounded_down, num_rounded_up;
709  if (i == 3) {
710  bit_size = n_ch * mtab->ppc_shape_bit;
711  vect_size = n_ch * mtab->ppc_shape_len;
712  } else {
713  bit_size = total_fr_bits - bsize_no_main_cb[i];
714  vect_size = n_ch * mtab->size;
715  }
716 
717  tctx->n_div[i] = (bit_size + 13) / 14;
718 
719  rounded_up = (bit_size + tctx->n_div[i] - 1) /
720  tctx->n_div[i];
721  rounded_down = (bit_size) / tctx->n_div[i];
722  num_rounded_down = rounded_up * tctx->n_div[i] - bit_size;
723  num_rounded_up = tctx->n_div[i] - num_rounded_down;
724  tctx->bits_main_spec[0][i][0] = (rounded_up + 1) / 2;
725  tctx->bits_main_spec[1][i][0] = rounded_up / 2;
726  tctx->bits_main_spec[0][i][1] = (rounded_down + 1) / 2;
727  tctx->bits_main_spec[1][i][1] = rounded_down / 2;
728  tctx->bits_main_spec_change[i] = num_rounded_up;
729 
730  rounded_up = (vect_size + tctx->n_div[i] - 1) /
731  tctx->n_div[i];
732  rounded_down = (vect_size) / tctx->n_div[i];
733  num_rounded_down = rounded_up * tctx->n_div[i] - vect_size;
734  num_rounded_up = tctx->n_div[i] - num_rounded_down;
735  tctx->length[i][0] = rounded_up;
736  tctx->length[i][1] = rounded_down;
737  tctx->length_change[i] = num_rounded_up;
738  }
739 
740  for (frametype = TWINVQ_FT_SHORT; frametype <= TWINVQ_FT_PPC; frametype++)
741  construct_perm_table(tctx, frametype);
742 }
743 
745 {
746  TwinVQContext *tctx = avctx->priv_data;
747  int i;
748 
749  for (i = 0; i < 3; i++) {
750  av_tx_uninit(&tctx->tx[i]);
751  av_freep(&tctx->cos_tabs[i]);
752  }
753 
754  av_freep(&tctx->curr_frame);
755  av_freep(&tctx->spectrum);
756  av_freep(&tctx->prev_frame);
757  av_freep(&tctx->tmp_buf);
758  av_freep(&tctx->fdsp);
759 
760  return 0;
761 }
762 
764 {
765  int ret;
766  TwinVQContext *tctx = avctx->priv_data;
767  int64_t frames_per_packet;
768 
769  tctx->avctx = avctx;
771 
772  if (!avctx->block_align) {
773  avctx->block_align = tctx->frame_size + 7 >> 3;
774  }
775  frames_per_packet = avctx->block_align * 8LL / tctx->frame_size;
776  if (frames_per_packet <= 0) {
777  av_log(avctx, AV_LOG_ERROR, "Block align is %"PRId64" bits, expected %d\n",
778  avctx->block_align * (int64_t)8, tctx->frame_size);
779  return AVERROR_INVALIDDATA;
780  }
781  if (frames_per_packet > TWINVQ_MAX_FRAMES_PER_PACKET) {
782  av_log(avctx, AV_LOG_ERROR, "Too many frames per packet (%"PRId64")\n",
783  frames_per_packet);
784  return AVERROR_INVALIDDATA;
785  }
786  tctx->frames_per_packet = frames_per_packet;
787 
789  if (!tctx->fdsp)
790  return AVERROR(ENOMEM);
791  if ((ret = init_mdct_win(tctx))) {
792  av_log(avctx, AV_LOG_ERROR, "Error initializing MDCT\n");
793  return ret;
794  }
795  init_bitstream_params(tctx);
796 
797  twinvq_memset_float(tctx->bark_hist[0][0], 0.1,
798  FF_ARRAY_ELEMS(tctx->bark_hist));
799 
800  return 0;
801 }
TwinVQModeTab::lspcodebook
const float * lspcodebook
Definition: twinvq.h:116
AV_SAMPLE_FMT_FLTP
@ AV_SAMPLE_FMT_FLTP
float, planar
Definition: samplefmt.h:66
linear_perm
static void linear_perm(int16_t *out, int16_t *in, int n_blocks, int size)
Definition: twinvq.c:634
TWINVQ_SUB_AMP_MAX
#define TWINVQ_SUB_AMP_MAX
Definition: twinvq.h:48
TwinVQContext::mtab
const TwinVQModeTab * mtab
Definition: twinvq.h:143
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
ff_sine_windows
SINETABLE_CONST float *const ff_sine_windows[]
Definition: sinewin_tablegen.h:51
TwinVQFrameMode::sub
uint8_t sub
Number subblocks in each frame.
Definition: twinvq.h:67
out
FILE * out
Definition: movenc.c:54
AVCodecContext::sample_rate
int sample_rate
samples per second
Definition: avcodec.h:1034
TwinVQContext::bits_main_spec
uint8_t bits_main_spec[2][4][2]
bits for the main codebook
Definition: twinvq.h:155
cb
static double cb(void *priv, double x, double y)
Definition: vf_geq.c:239
dequant
static void dequant(TwinVQContext *tctx, const uint8_t *cb_bits, float *out, enum TwinVQFrameType ftype, const int16_t *cb0, const int16_t *cb1, int cb_len)
Inverse quantization.
Definition: twinvq.c:172
TWINVQ_AMP_MAX
#define TWINVQ_AMP_MAX
Definition: twinvq.h:51
sub
static float sub(float src0, float src1)
Definition: dnn_backend_native_layer_mathbinary.c:31
TwinVQContext::tmp_buf
float * tmp_buf
Definition: twinvq.h:168
decode_lsp
static void decode_lsp(TwinVQContext *tctx, int lpc_idx1, uint8_t *lpc_idx2, int lpc_hist_idx, float *lsp, float *hist)
Definition: twinvq.c:264
TwinVQContext::curr_frame
float * curr_frame
non-interleaved output
Definition: twinvq.h:160
AVTXContext
Definition: tx_priv.h:228
TWINVQ_GAIN_BITS
#define TWINVQ_GAIN_BITS
Definition: twinvq.h:50
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:330
step
trying all byte sequences megabyte in length and selecting the best looking sequence will yield cases to try But a word about which is also called distortion Distortion can be quantified by almost any quality measurement one chooses the sum of squared differences is used but more complex methods that consider psychovisual effects can be used as well It makes no difference in this discussion First step
Definition: rate_distortion.txt:58
TwinVQContext::bits
TwinVQFrameData bits[TWINVQ_MAX_FRAMES_PER_PACKET]
Definition: twinvq.h:171
AVPacket::data
uint8_t * data
Definition: packet.h:374
metasound_twinvq_data.h
TwinVQModeTab::ppc_shape_len
uint8_t ppc_shape_len
size of PPC shape CB
Definition: twinvq.h:130
TwinVQModeTab::lsp_bit1
uint8_t lsp_bit1
Definition: twinvq.h:120
ff_twinvq_decode_init
av_cold int ff_twinvq_decode_init(AVCodecContext *avctx)
Requires the caller to call ff_twinvq_decode_close() upon failure.
Definition: twinvq.c:763
TwinVQContext::permut
int16_t permut[4][4096]
Definition: twinvq.h:152
imdct_output
static void imdct_output(TwinVQContext *tctx, enum TwinVQFrameType ftype, int wtype, float **out, int offset)
Definition: twinvq.c:380
ff_sort_nearly_sorted_floats
void ff_sort_nearly_sorted_floats(float *vals, int len)
Sort values in ascending order.
Definition: lsp.c:239
TwinVQModeTab::pgain_bit
uint8_t pgain_bit
bits for PPC gain
Definition: twinvq.h:131
AVChannelLayout::nb_channels
int nb_channels
Number of channels in this layout.
Definition: channel_layout.h:311
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:883
TWINVQ_PPC_SHAPE_CB_SIZE
#define TWINVQ_PPC_SHAPE_CB_SIZE
Definition: twinvq.h:46
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
TwinVQFrameMode::cb0
const int16_t * cb0
main codebooks for spectrum data
Definition: twinvq.h:79
TwinVQContext::last_block_pos
int last_block_pos[2]
Definition: twinvq.h:162
TWINVQ_WINDOW_TYPE_BITS
#define TWINVQ_WINDOW_TYPE_BITS
Definition: twinvq.h:53
TwinVQFrameMode::cb1
const int16_t * cb1
Definition: twinvq.h:80
AVCodecContext::ch_layout
AVChannelLayout ch_layout
Audio channel layout.
Definition: avcodec.h:2054
TwinVQFrameMode::bark_n_coef
uint8_t bark_n_coef
number of BSE CB coefficients to read
Definition: twinvq.h:74
TwinVQFrameType
TwinVQFrameType
Definition: twinvq.h:39
AVCodecContext::flags
int flags
AV_CODEC_FLAG_*.
Definition: avcodec.h:506
val
static double val(void *priv, double ch)
Definition: aeval.c:77
FF_ALLOC_TYPED_ARRAY
#define FF_ALLOC_TYPED_ARRAY(p, nelem)
Definition: internal.h:96
scale
static av_always_inline float scale(float x, float s)
Definition: vf_v360.c:1389
TwinVQModeTab::size
uint16_t size
frame size in samples
Definition: twinvq.h:114
twinvq_mulawinv
static float twinvq_mulawinv(float y, float clip, float mu)
Definition: twinvq.h:200
tab1
const int16_t * tab1
Definition: mace.c:145
TwinVQContext::dec_bark_env
void(* dec_bark_env)(struct TwinVQContext *tctx, const uint8_t *in, int use_hist, int ch, float *out, float gain, enum TwinVQFrameType ftype)
Definition: twinvq.h:177
TwinVQContext::n_div
int n_div[4]
Definition: twinvq.h:157
TwinVQContext::decode_ppc
void(* decode_ppc)(struct TwinVQContext *tctx, int period_coef, int g_coef, const float *shape, float *speech)
Definition: twinvq.h:180
chunk_end
static int chunk_end(AVFormatContext *s, int flush)
Definition: webm_chunk.c:179
ftype
#define ftype
Definition: afir_template.c:45
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:180
TwinVQContext::fdsp
AVFloatDSPContext * fdsp
Definition: twinvq.h:139
wtype_to_wsize
static const uint8_t wtype_to_wsize[]
Definition: twinvq.c:326
FF_ARRAY_ELEMS
#define FF_ARRAY_ELEMS(a)
Definition: sinewin_tablegen.c:29
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:127
TwinVQContext::lsp_hist
float lsp_hist[2][20]
LSP coefficients of the last frame.
Definition: twinvq.h:148
TwinVQModeTab::ppc_shape_bit
uint8_t ppc_shape_bit
number of bits of the PPC shape CB coeffs
Definition: twinvq.h:129
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
rearrange_lsp
static void rearrange_lsp(int order, float *lsp, float min_dist)
Rearrange the LSP coefficients so that they have a minimum distance of min_dist.
Definition: twinvq.c:251
TWINVQ_LSP_COEFS_MAX
#define TWINVQ_LSP_COEFS_MAX
Definition: twinvq.h:55
TwinVQContext::codec
enum TwinVQCodec codec
Definition: twinvq.h:173
TwinVQContext::length_change
uint8_t length_change[4]
Definition: twinvq.h:154
bits
uint8_t bits
Definition: vp3data.h:128
TWINVQ_FT_MEDIUM
@ TWINVQ_FT_MEDIUM
Medium frame (divided in m<n sub-blocks)
Definition: twinvq.h:41
TwinVQModeTab
Parameters and tables that are different for every combination of bitrate/sample rate.
Definition: twinvq.h:111
channels
channels
Definition: aptx.h:31
decode.h
TwinVQModeTab::lsp_bit2
uint8_t lsp_bit2
Definition: twinvq.h:121
TWINVQ_MULAW_MU
#define TWINVQ_MULAW_MU
Definition: twinvq.h:49
twinvq_memset_float
static void twinvq_memset_float(float *buf, float val, int size)
Definition: twinvq.h:194
TwinVQContext::prev_frame
float * prev_frame
non-interleaved previous frame
Definition: twinvq.h:161
TWINVQ_FT_PPC
@ TWINVQ_FT_PPC
Periodic Peak Component (part of the long frame)
Definition: twinvq.h:43
eval_lpcenv
static void eval_lpcenv(TwinVQContext *tctx, const float *cos_vals, float *lpc)
Evaluate the LPC amplitude spectrum envelope from the line spectrum pairs.
Definition: twinvq.c:71
if
if(ret)
Definition: filter_design.txt:179
ff_twinvq_decode_close
av_cold int ff_twinvq_decode_close(AVCodecContext *avctx)
Definition: twinvq.c:744
TwinVQContext::length
uint8_t length[4][2]
main codebook stride
Definition: twinvq.h:153
NULL
#define NULL
Definition: coverity.c:32
AVCodecContext::bit_rate
int64_t bit_rate
the average bitrate
Definition: avcodec.h:476
get_cos
static float get_cos(int idx, int part, const float *cos_tab, int size)
Definition: twinvq.c:95
eval_lpc_spectrum
static float eval_lpc_spectrum(const float *lsp, float cos_val, int order)
Evaluate a single LPC amplitude spectrum envelope coefficient from the line spectrum pairs.
Definition: twinvq.c:46
ff_twinvq_decode_frame
int ff_twinvq_decode_frame(AVCodecContext *avctx, AVFrame *frame, int *got_frame_ptr, AVPacket *avpkt)
Definition: twinvq.c:479
TwinVQContext::is_6kbps
int is_6kbps
Definition: twinvq.h:145
transpose_perm
static void transpose_perm(int16_t *out, int16_t *in, int num_vect, const uint8_t line_len[2], int length_div)
Interpret the input data as in the following table:
Definition: twinvq.c:623
float_dsp.h
tab
static const uint8_t tab[16]
Definition: rka.c:668
TwinVQContext::avctx
AVCodecContext * avctx
Definition: twinvq.h:138
dec_lpc_spectrum_inv
static void dec_lpc_spectrum_inv(TwinVQContext *tctx, float *lsp, enum TwinVQFrameType ftype, float *lpc)
Definition: twinvq.c:304
TwinVQModeTab::lsp_bit0
uint8_t lsp_bit0
Definition: twinvq.h:119
read_and_decode_spectrum
static void read_and_decode_spectrum(TwinVQContext *tctx, float *out, enum TwinVQFrameType ftype)
Definition: twinvq.c:415
TWINVQ_FT_LONG
@ TWINVQ_FT_LONG
Long frame (single sub-block + PPC)
Definition: twinvq.h:42
ff_get_buffer
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
Definition: decode.c:1473
AVPacket::size
int size
Definition: packet.h:375
AVFloatDSPContext::vector_fmul
void(* vector_fmul)(float *dst, const float *src0, const float *src1, int len)
Calculate the entry wise product of two vectors of floats and store the result in a vector of floats.
Definition: float_dsp.h:38
shift
static int shift(int a, int b)
Definition: bonk.c:257
AVCodecContext::sample_fmt
enum AVSampleFormat sample_fmt
audio sample format
Definition: avcodec.h:1050
TwinVQFrameMode::bark_n_bit
uint8_t bark_n_bit
number of bits of the BSE coefs
Definition: twinvq.h:75
size
int size
Definition: twinvq_data.h:10344
TwinVQModeTab::ppc_period_bit
uint8_t ppc_period_bit
number of the bits for the PPC period value
Definition: twinvq.h:127
TwinVQContext::bits_main_spec_change
int bits_main_spec_change[4]
Definition: twinvq.h:156
TWINVQ_PPC_SHAPE_LEN_MAX
#define TWINVQ_PPC_SHAPE_LEN_MAX
Definition: twinvq.h:47
TWINVQ_CHANNELS_MAX
#define TWINVQ_CHANNELS_MAX
Definition: twinvq.h:57
TwinVQModeTab::ppc_shape_cb
const int16_t * ppc_shape_cb
PPC shape CB.
Definition: twinvq.h:124
avg
#define avg(a, b, c, d)
Definition: colorspacedsp_template.c:28
sinewin.h
init_bitstream_params
static av_cold void init_bitstream_params(TwinVQContext *tctx)
Definition: twinvq.c:669
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
init_mdct_win
static av_cold int init_mdct_win(TwinVQContext *tctx)
Init IMDCT and windowing tables.
Definition: twinvq.c:535
interpolate
static void interpolate(float *out, float v1, float v2, int size)
Definition: twinvq.c:84
M_PI
#define M_PI
Definition: mathematics.h:52
av_tx_uninit
av_cold void av_tx_uninit(AVTXContext **ctx)
Frees a context and sets *ctx to NULL, does nothing when *ctx == NULL.
Definition: tx.c:294
TwinVQContext::read_bitstream
int(* read_bitstream)(AVCodecContext *avctx, struct TwinVQContext *tctx, const uint8_t *buf, int buf_size)
Definition: twinvq.h:175
TWINVQ_SUB_GAIN_BITS
#define TWINVQ_SUB_GAIN_BITS
Definition: twinvq.h:52
TwinVQContext::discarded_packets
int discarded_packets
Definition: twinvq.h:163
TWINVQ_CODEC_METASOUND
@ TWINVQ_CODEC_METASOUND
Definition: twinvq.h:36
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:269
TwinVQContext::frame_size
int frame_size
Definition: twinvq.h:170
TwinVQContext::bark_hist
float bark_hist[3][2][40]
BSE coefficients of last frame.
Definition: twinvq.h:149
TwinVQFrameData
Definition: twinvq.h:86
TwinVQContext::cos_tabs
float * cos_tabs[3]
Definition: twinvq.h:165
permutate_in_line
static void permutate_in_line(int16_t *tab, int num_vect, int num_blocks, int block_size, const uint8_t line_len[2], int length_div, enum TwinVQFrameType ftype)
Interpret the data as if it were a num_blocks x line_len[0] matrix and for each line do a cyclic perm...
Definition: twinvq.c:583
avcodec.h
ret
ret
Definition: filter_design.txt:187
TwinVQContext::cur_frame
int cur_frame
Definition: twinvq.h:170
AVCodecContext::block_align
int block_align
number of bytes per packet if constant and known or 0 Used by some WAV based audio codecs.
Definition: avcodec.h:1083
FFSWAP
#define FFSWAP(type, a, b)
Definition: macros.h:52
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
lsp.h
TwinVQContext::tx_fn
av_tx_fn tx_fn[3]
Definition: twinvq.h:141
pos
unsigned int pos
Definition: spdifenc.c:413
TWINVQ_FT_SHORT
@ TWINVQ_FT_SHORT
Short frame (divided in n sub-blocks)
Definition: twinvq.h:40
twinvq.h
imdct_and_window
static void imdct_and_window(TwinVQContext *tctx, enum TwinVQFrameType ftype, int wtype, float *in, float *prev, int ch)
Definition: twinvq.c:328
AVCodecContext
main external API structure.
Definition: avcodec.h:426
construct_perm_table
static av_cold void construct_perm_table(TwinVQContext *tctx, enum TwinVQFrameType ftype)
Definition: twinvq.c:643
channel_layout.h
ff_init_ff_sine_windows
void ff_init_ff_sine_windows(int index)
initialize the specified entry of ff_sine_windows
Definition: sinewin_tablegen.h:101
TwinVQFrameMode::cb_len_read
uint8_t cb_len_read
number of spectrum coefficients to read
Definition: twinvq.h:83
TwinVQFrameData::ftype
enum TwinVQFrameType ftype
Definition: twinvq.h:88
eval_lpcenv_or_interp
static void eval_lpcenv_or_interp(TwinVQContext *tctx, enum TwinVQFrameType ftype, float *out, const float *in, int size, int step, int part)
Evaluate the LPC amplitude spectrum envelope from the line spectrum pairs.
Definition: twinvq.c:115
TwinVQContext::tx
AVTXContext * tx[3]
Definition: twinvq.h:140
TwinVQContext::frames_per_packet
int frames_per_packet
Definition: twinvq.h:170
AV_CODEC_FLAG_BITEXACT
#define AV_CODEC_FLAG_BITEXACT
Use only bitexact stuff (except (I)DCT).
Definition: avcodec.h:321
dec_gain
static void dec_gain(TwinVQContext *tctx, enum TwinVQFrameType ftype, float *out)
Definition: twinvq.c:214
eval_lpcenv_2parts
static void eval_lpcenv_2parts(TwinVQContext *tctx, enum TwinVQFrameType ftype, const float *buf, float *lpc, int size, int step)
Definition: twinvq.c:152
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:119
AVCodecContext::priv_data
void * priv_data
Definition: avcodec.h:453
AVPacket
This structure stores compressed data.
Definition: packet.h:351
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:34
TWINVQ_SUBBLOCKS_MAX
#define TWINVQ_SUBBLOCKS_MAX
Definition: twinvq.h:58
TwinVQContext::spectrum
float * spectrum
Definition: twinvq.h:159
avpriv_float_dsp_alloc
av_cold AVFloatDSPContext * avpriv_float_dsp_alloc(int bit_exact)
Allocate a float DSP context.
Definition: float_dsp.c:135
TwinVQFrameData::window_type
int window_type
Definition: twinvq.h:87
TWINVQ_MAX_FRAMES_PER_PACKET
#define TWINVQ_MAX_FRAMES_PER_PACKET
Definition: twinvq.h:61
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
TwinVQContext
Definition: twinvq.h:137
AVERROR_INVALIDDATA
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:61
cos_tab
static float cos_tab[256]
Definition: dca_lbr.c:121
av_log2
int av_log2(unsigned v)
Definition: intmath.c:26
TwinVQModeTab::lsp_split
uint8_t lsp_split
number of CB entries for the LSP decoding
Definition: twinvq.h:123
ff_twinvq_wtype_to_ftype_table
enum TwinVQFrameType ff_twinvq_wtype_to_ftype_table[]
Definition: twinvq.c:473
TwinVQModeTab::fmode
struct TwinVQFrameMode fmode[3]
frame type-dependent parameters
Definition: twinvq.h:112
TwinVQModeTab::n_lsp
uint8_t n_lsp
number of lsp coefficients
Definition: twinvq.h:115