FFmpeg
speexdec.c
Go to the documentation of this file.
1 /*
2  * Copyright 2002-2008 Xiph.org Foundation
3  * Copyright 2002-2008 Jean-Marc Valin
4  * Copyright 2005-2007 Analog Devices Inc.
5  * Copyright 2005-2008 Commonwealth Scientific and Industrial Research Organisation (CSIRO)
6  * Copyright 1993, 2002, 2006 David Rowe
7  * Copyright 2003 EpicGames
8  * Copyright 1992-1994 Jutta Degener, Carsten Bormann
9 
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13 
14  * - Redistributions of source code must retain the above copyright
15  * notice, this list of conditions and the following disclaimer.
16 
17  * - Redistributions in binary form must reproduce the above copyright
18  * notice, this list of conditions and the following disclaimer in the
19  * documentation and/or other materials provided with the distribution.
20 
21  * - Neither the name of the Xiph.org Foundation nor the names of its
22  * contributors may be used to endorse or promote products derived from
23  * this software without specific prior written permission.
24 
25  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
28  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR
29  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36  *
37  * This file is part of FFmpeg.
38  *
39  * FFmpeg is free software; you can redistribute it and/or
40  * modify it under the terms of the GNU Lesser General Public
41  * License as published by the Free Software Foundation; either
42  * version 2.1 of the License, or (at your option) any later version.
43  *
44  * FFmpeg is distributed in the hope that it will be useful,
45  * but WITHOUT ANY WARRANTY; without even the implied warranty of
46  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
47  * Lesser General Public License for more details.
48  *
49  * You should have received a copy of the GNU Lesser General Public
50  * License along with FFmpeg; if not, write to the Free Software
51  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
52  */
53 
54 #include "libavutil/avassert.h"
55 #include "libavutil/avstring.h"
56 #include "libavutil/float_dsp.h"
57 #include "avcodec.h"
58 #include "bytestream.h"
59 #include "codec_internal.h"
60 #include "decode.h"
61 #include "get_bits.h"
62 #include "speexdata.h"
63 
64 #define SPEEX_NB_MODES 3
65 #define SPEEX_INBAND_STEREO 9
66 
67 #define QMF_ORDER 64
68 #define NB_ORDER 10
69 #define NB_FRAME_SIZE 160
70 #define NB_SUBMODES 9
71 #define NB_SUBMODE_BITS 4
72 #define SB_SUBMODE_BITS 3
73 
74 #define NB_SUBFRAME_SIZE 40
75 #define NB_NB_SUBFRAMES 4
76 #define NB_PITCH_START 17
77 #define NB_PITCH_END 144
78 
79 #define NB_DEC_BUFFER (NB_FRAME_SIZE + 2 * NB_PITCH_END + NB_SUBFRAME_SIZE + 12)
80 
81 #define SPEEX_MEMSET(dst, c, n) (memset((dst), (c), (n) * sizeof(*(dst))))
82 #define SPEEX_COPY(dst, src, n) (memcpy((dst), (src), (n) * sizeof(*(dst))))
83 
84 #define LSP_LINEAR(i) (.25f * (i) + .25f)
85 #define LSP_LINEAR_HIGH(i) (.3125f * (i) + .75f)
86 #define LSP_DIV_256(x) (0.00390625f * (x))
87 #define LSP_DIV_512(x) (0.001953125f * (x))
88 #define LSP_DIV_1024(x) (0.0009765625f * (x))
89 
90 typedef struct LtpParams {
91  const int8_t *gain_cdbk;
92  int gain_bits;
94 } LtpParam;
95 
96 static const LtpParam ltp_params_vlbr = { gain_cdbk_lbr, 5, 0 };
97 static const LtpParam ltp_params_lbr = { gain_cdbk_lbr, 5, 7 };
98 static const LtpParam ltp_params_med = { gain_cdbk_lbr, 5, 7 };
99 static const LtpParam ltp_params_nb = { gain_cdbk_nb, 7, 7 };
100 
101 typedef struct SplitCodebookParams {
104  const signed char *shape_cb;
108 
109 static const SplitCodebookParams split_cb_nb_ulbr = { 20, 2, exc_20_32_table, 5, 0 };
110 static const SplitCodebookParams split_cb_nb_vlbr = { 10, 4, exc_10_16_table, 4, 0 };
111 static const SplitCodebookParams split_cb_nb_lbr = { 10, 4, exc_10_32_table, 5, 0 };
112 static const SplitCodebookParams split_cb_nb_med = { 8, 5, exc_8_128_table, 7, 0 };
113 static const SplitCodebookParams split_cb_nb = { 5, 8, exc_5_64_table, 6, 0 };
114 static const SplitCodebookParams split_cb_sb = { 5, 8, exc_5_256_table, 8, 0 };
115 static const SplitCodebookParams split_cb_high = { 8, 5, hexc_table, 7, 1 };
117 
118 /** Quantizes LSPs */
119 typedef void (*lsp_quant_func)(float *, float *, int, GetBitContext *);
120 
121 /** Decodes quantized LSPs */
122 typedef void (*lsp_unquant_func)(float *, int, GetBitContext *);
123 
124 /** Long-term predictor quantization */
125 typedef int (*ltp_quant_func)(float *, float *, float *,
126  float *, float *, float *,
127  const void *, int, int, float, int, int,
128  GetBitContext *, char *, float *,
129  float *, int, int, int, float *);
130 
131 /** Long-term un-quantize */
132 typedef void (*ltp_unquant_func)(float *, float *, int, int,
133  float, const void *, int, int *,
134  float *, GetBitContext *, int, int,
135  float, int);
136 
137 /** Innovation quantization function */
138 typedef void (*innovation_quant_func)(float *, float *,
139  float *, float *, const void *,
140  int, int, float *, float *,
141  GetBitContext *, char *, int, int);
142 
143 /** Innovation unquantization function */
144 typedef void (*innovation_unquant_func)(float *, const void *, int,
145  GetBitContext *, uint32_t *);
146 
147 typedef struct SpeexSubmode {
148  int lbr_pitch; /**< Set to -1 for "normal" modes, otherwise encode pitch using
149  a global pitch and allowing a +- lbr_pitch variation (for
150  low not-rates)*/
151  int forced_pitch_gain; /**< Use the same (forced) pitch gain for all
152  sub-frames */
153  int have_subframe_gain; /**< Number of bits to use as sub-frame innovation
154  gain */
155  int double_codebook; /**< Apply innovation quantization twice for higher
156  quality (and higher bit-rate)*/
157  lsp_unquant_func lsp_unquant; /**< LSP unquantization function */
158 
159  ltp_unquant_func ltp_unquant; /**< Long-term predictor (pitch) un-quantizer */
160  const void *LtpParam; /**< Pitch parameters (options) */
161 
162  innovation_unquant_func innovation_unquant; /**< Innovation un-quantization */
163  const void *innovation_params; /**< Innovation quantization parameters*/
164 
165  float comb_gain; /**< Gain of enhancer comb filter */
166 } SpeexSubmode;
167 
168 typedef struct SpeexMode {
169  int modeID; /**< ID of the mode */
170  int (*decode)(AVCodecContext *avctx, void *dec, GetBitContext *gb, float *out);
171  int frame_size; /**< Size of frames used for decoding */
172  int subframe_size; /**< Size of sub-frames used for decoding */
173  int lpc_size; /**< Order of LPC filter */
174  float folding_gain; /**< Folding gain */
175  const SpeexSubmode *submodes[NB_SUBMODES]; /**< Sub-mode data for the mode */
176  int default_submode; /**< Default sub-mode to use when decoding */
177 } SpeexMode;
178 
179 typedef struct DecoderState {
180  const SpeexMode *mode;
181  int modeID; /**< ID of the decoder mode */
182  int first; /**< Is first frame */
183  int full_frame_size; /**< Length of full-band frames */
184  int is_wideband; /**< If wideband is present */
185  int count_lost; /**< Was the last frame lost? */
186  int frame_size; /**< Length of high-band frames */
187  int subframe_size; /**< Length of high-band sub-frames */
188  int nb_subframes; /**< Number of high-band sub-frames */
189  int lpc_size; /**< Order of high-band LPC analysis */
190  float last_ol_gain; /**< Open-loop gain for previous frame */
191  float *innov_save; /**< If non-NULL, innovation is copied here */
192 
193  /* This is used in packet loss concealment */
194  int last_pitch; /**< Pitch of last correctly decoded frame */
195  float last_pitch_gain; /**< Pitch gain of last correctly decoded frame */
196  uint32_t seed; /**< Seed used for random number generation */
197 
199  const SpeexSubmode *const *submodes; /**< Sub-mode data */
200  int submodeID; /**< Activated sub-mode */
201  int lpc_enh_enabled; /**< 1 when LPC enhancer is on, 0 otherwise */
202 
203  /* Vocoder data */
204  float voc_m1;
205  float voc_m2;
206  float voc_mean;
208 
210  int highpass_enabled; /**< Is the input filter enabled */
211 
212  float *exc; /**< Start of excitation frame */
213  float mem_hp[2]; /**< High-pass filter memory */
214  float exc_buf[NB_DEC_BUFFER]; /**< Excitation buffer */
215  float old_qlsp[NB_ORDER]; /**< Quantized LSPs for previous frame */
216  float interp_qlpc[NB_ORDER]; /**< Interpolated quantized LPCs */
217  float mem_sp[NB_ORDER]; /**< Filter memory for synthesis signal */
220  float pi_gain[NB_NB_SUBFRAMES]; /**< Gain of LPC filter at theta=pi (fe/2) */
221  float exc_rms[NB_NB_SUBFRAMES]; /**< RMS of excitation per subframe */
222 } DecoderState;
223 
224 /* Default handler for user callbacks: skip it */
225 static int speex_default_user_handler(GetBitContext *gb, void *state, void *data)
226 {
227  const int req_size = get_bits(gb, 4);
228  skip_bits_long(gb, 5 + 8 * req_size);
229  return 0;
230 }
231 
232 typedef struct StereoState {
233  float balance; /**< Left/right balance info */
234  float e_ratio; /**< Ratio of energies: E(left+right)/[E(left)+E(right)] */
235  float smooth_left; /**< Smoothed left channel gain */
236  float smooth_right; /**< Smoothed right channel gain */
237 } StereoState;
238 
239 typedef struct SpeexContext {
240  AVClass *class;
242 
243  int32_t version_id; /**< Version for Speex (for checking compatibility) */
244  int32_t rate; /**< Sampling rate used */
245  int32_t mode; /**< Mode used (0 for narrowband, 1 for wideband) */
246  int32_t bitstream_version; /**< Version ID of the bit-stream */
247  int32_t nb_channels; /**< Number of channels decoded */
248  int32_t bitrate; /**< Bit-rate used */
249  int32_t frame_size; /**< Size of frames */
250  int32_t vbr; /**< 1 for a VBR decoding, 0 otherwise */
251  int32_t frames_per_packet; /**< Number of frames stored per Ogg packet */
252  int32_t extra_headers; /**< Number of additional headers after the comments */
253 
254  int pkt_size;
255 
258 
260 } SpeexContext;
261 
262 static void lsp_unquant_lbr(float *lsp, int order, GetBitContext *gb)
263 {
264  int id;
265 
266  for (int i = 0; i < order; i++)
267  lsp[i] = LSP_LINEAR(i);
268 
269  id = get_bits(gb, 6);
270  for (int i = 0; i < 10; i++)
271  lsp[i] += LSP_DIV_256(cdbk_nb[id * 10 + i]);
272 
273  id = get_bits(gb, 6);
274  for (int i = 0; i < 5; i++)
275  lsp[i] += LSP_DIV_512(cdbk_nb_low1[id * 5 + i]);
276 
277  id = get_bits(gb, 6);
278  for (int i = 0; i < 5; i++)
279  lsp[i + 5] += LSP_DIV_512(cdbk_nb_high1[id * 5 + i]);
280 }
281 
282 static void forced_pitch_unquant(float *exc, float *exc_out, int start, int end,
283  float pitch_coef, const void *par, int nsf,
284  int *pitch_val, float *gain_val, GetBitContext *gb, int count_lost,
285  int subframe_offset, float last_pitch_gain, int cdbk_offset)
286 {
287  av_assert0(!isnan(pitch_coef));
288  pitch_coef = fminf(pitch_coef, .99f);
289  for (int i = 0; i < nsf; i++) {
290  exc_out[i] = exc[i - start] * pitch_coef;
291  exc[i] = exc_out[i];
292  }
293  pitch_val[0] = start;
294  gain_val[0] = gain_val[2] = 0.f;
295  gain_val[1] = pitch_coef;
296 }
297 
298 static inline float speex_rand(float std, uint32_t *seed)
299 {
300  const uint32_t jflone = 0x3f800000;
301  const uint32_t jflmsk = 0x007fffff;
302  float fran;
303  uint32_t ran;
304  seed[0] = 1664525 * seed[0] + 1013904223;
305  ran = jflone | (jflmsk & seed[0]);
306  fran = av_int2float(ran);
307  fran -= 1.5f;
308  fran *= std;
309  return fran;
310 }
311 
312 static void noise_codebook_unquant(float *exc, const void *par, int nsf,
313  GetBitContext *gb, uint32_t *seed)
314 {
315  for (int i = 0; i < nsf; i++)
316  exc[i] = speex_rand(1.f, seed);
317 }
318 
319 static void split_cb_shape_sign_unquant(float *exc, const void *par, int nsf,
320  GetBitContext *gb, uint32_t *seed)
321 {
322  int subvect_size, nb_subvect, have_sign, shape_bits;
323  const SplitCodebookParams *params;
324  const signed char *shape_cb;
325  int signs[10], ind[10];
326 
327  params = par;
328  subvect_size = params->subvect_size;
329  nb_subvect = params->nb_subvect;
330 
331  shape_cb = params->shape_cb;
332  have_sign = params->have_sign;
333  shape_bits = params->shape_bits;
334 
335  /* Decode codewords and gains */
336  for (int i = 0; i < nb_subvect; i++) {
337  signs[i] = have_sign ? get_bits1(gb) : 0;
338  ind[i] = get_bitsz(gb, shape_bits);
339  }
340  /* Compute decoded excitation */
341  for (int i = 0; i < nb_subvect; i++) {
342  const float s = signs[i] ? -1.f : 1.f;
343 
344  for (int j = 0; j < subvect_size; j++)
345  exc[subvect_size * i + j] += s * 0.03125f * shape_cb[ind[i] * subvect_size + j];
346  }
347 }
348 
349 #define SUBMODE(x) st->submodes[st->submodeID]->x
350 
351 #define gain_3tap_to_1tap(g) (FFABS(g[1]) + (g[0] > 0.f ? g[0] : -.5f * g[0]) + (g[2] > 0.f ? g[2] : -.5f * g[2]))
352 
353 static void
354 pitch_unquant_3tap(float *exc, float *exc_out, int start, int end, float pitch_coef,
355  const void *par, int nsf, int *pitch_val, float *gain_val, GetBitContext *gb,
356  int count_lost, int subframe_offset, float last_pitch_gain, int cdbk_offset)
357 {
358  int pitch, gain_index, gain_cdbk_size;
359  const int8_t *gain_cdbk;
360  const LtpParam *params;
361  float gain[3];
362 
363  params = (const LtpParam *)par;
364  gain_cdbk_size = 1 << params->gain_bits;
365  gain_cdbk = params->gain_cdbk + 4 * gain_cdbk_size * cdbk_offset;
366 
367  pitch = get_bitsz(gb, params->pitch_bits);
368  pitch += start;
369  gain_index = get_bitsz(gb, params->gain_bits);
370  gain[0] = 0.015625f * gain_cdbk[gain_index * 4] + .5f;
371  gain[1] = 0.015625f * gain_cdbk[gain_index * 4 + 1] + .5f;
372  gain[2] = 0.015625f * gain_cdbk[gain_index * 4 + 2] + .5f;
373 
374  if (count_lost && pitch > subframe_offset) {
375  float tmp = count_lost < 4 ? last_pitch_gain : 0.5f * last_pitch_gain;
376  float gain_sum;
377 
378  tmp = fminf(tmp, .95f);
379  gain_sum = gain_3tap_to_1tap(gain);
380 
381  if (gain_sum > tmp && gain_sum > 0.f) {
382  float fact = tmp / gain_sum;
383  for (int i = 0; i < 3; i++)
384  gain[i] *= fact;
385  }
386  }
387 
388  pitch_val[0] = pitch;
389  gain_val[0] = gain[0];
390  gain_val[1] = gain[1];
391  gain_val[2] = gain[2];
392  SPEEX_MEMSET(exc_out, 0, nsf);
393 
394  for (int i = 0; i < 3; i++) {
395  int tmp1, tmp3;
396  int pp = pitch + 1 - i;
397  tmp1 = nsf;
398  if (tmp1 > pp)
399  tmp1 = pp;
400  for (int j = 0; j < tmp1; j++)
401  exc_out[j] += gain[2 - i] * exc[j - pp];
402  tmp3 = nsf;
403  if (tmp3 > pp + pitch)
404  tmp3 = pp + pitch;
405  for (int j = tmp1; j < tmp3; j++)
406  exc_out[j] += gain[2 - i] * exc[j - pp - pitch];
407  }
408 }
409 
410 static void lsp_unquant_nb(float *lsp, int order, GetBitContext *gb)
411 {
412  int id;
413 
414  for (int i = 0; i < order; i++)
415  lsp[i] = LSP_LINEAR(i);
416 
417  id = get_bits(gb, 6);
418  for (int i = 0; i < 10; i++)
419  lsp[i] += LSP_DIV_256(cdbk_nb[id * 10 + i]);
420 
421  id = get_bits(gb, 6);
422  for (int i = 0; i < 5; i++)
423  lsp[i] += LSP_DIV_512(cdbk_nb_low1[id * 5 + i]);
424 
425  id = get_bits(gb, 6);
426  for (int i = 0; i < 5; i++)
427  lsp[i] += LSP_DIV_1024(cdbk_nb_low2[id * 5 + i]);
428 
429  id = get_bits(gb, 6);
430  for (int i = 0; i < 5; i++)
431  lsp[i + 5] += LSP_DIV_512(cdbk_nb_high1[id * 5 + i]);
432 
433  id = get_bits(gb, 6);
434  for (int i = 0; i < 5; i++)
435  lsp[i + 5] += LSP_DIV_1024(cdbk_nb_high2[id * 5 + i]);
436 }
437 
438 static void lsp_unquant_high(float *lsp, int order, GetBitContext *gb)
439 {
440  int id;
441 
442  for (int i = 0; i < order; i++)
443  lsp[i] = LSP_LINEAR_HIGH(i);
444 
445  id = get_bits(gb, 6);
446  for (int i = 0; i < order; i++)
447  lsp[i] += LSP_DIV_256(high_lsp_cdbk[id * order + i]);
448 
449  id = get_bits(gb, 6);
450  for (int i = 0; i < order; i++)
451  lsp[i] += LSP_DIV_512(high_lsp_cdbk2[id * order + i]);
452 }
453 
454 /* 2150 bps "vocoder-like" mode for comfort noise */
455 static const SpeexSubmode nb_submode1 = {
458 };
459 
460 /* 5.95 kbps very low bit-rate mode */
461 static const SpeexSubmode nb_submode2 = {
464 };
465 
466 /* 8 kbps low bit-rate mode */
467 static const SpeexSubmode nb_submode3 = {
470 };
471 
472 /* 11 kbps medium bit-rate mode */
473 static const SpeexSubmode nb_submode4 = {
476 };
477 
478 /* 15 kbps high bit-rate mode */
479 static const SpeexSubmode nb_submode5 = {
482 };
483 
484 /* 18.2 high bit-rate mode */
485 static const SpeexSubmode nb_submode6 = {
488 };
489 
490 /* 24.6 kbps high bit-rate mode */
491 static const SpeexSubmode nb_submode7 = {
494 };
495 
496 /* 3.95 kbps very low bit-rate mode */
497 static const SpeexSubmode nb_submode8 = {
500 };
501 
502 static const SpeexSubmode wb_submode1 = {
503  0, 0, 1, 0, lsp_unquant_high, NULL, NULL,
504  NULL, NULL, -1.f
505 };
506 
507 static const SpeexSubmode wb_submode2 = {
508  0, 0, 1, 0, lsp_unquant_high, NULL, NULL,
510 };
511 
512 static const SpeexSubmode wb_submode3 = {
513  0, 0, 1, 0, lsp_unquant_high, NULL, NULL,
515 };
516 
517 static const SpeexSubmode wb_submode4 = {
518  0, 0, 1, 1, lsp_unquant_high, NULL, NULL,
520 };
521 
522 static int nb_decode(AVCodecContext *, void *, GetBitContext *, float *);
523 static int sb_decode(AVCodecContext *, void *, GetBitContext *, float *);
524 
526  {
527  .modeID = 0,
528  .decode = nb_decode,
529  .frame_size = NB_FRAME_SIZE,
530  .subframe_size = NB_SUBFRAME_SIZE,
531  .lpc_size = NB_ORDER,
532  .submodes = {
535  },
536  .default_submode = 5,
537  },
538  {
539  .modeID = 1,
540  .decode = sb_decode,
541  .frame_size = NB_FRAME_SIZE,
542  .subframe_size = NB_SUBFRAME_SIZE,
543  .lpc_size = 8,
544  .folding_gain = 0.9f,
545  .submodes = {
547  },
548  .default_submode = 3,
549  },
550  {
551  .modeID = 2,
552  .decode = sb_decode,
553  .frame_size = 320,
554  .subframe_size = 80,
555  .lpc_size = 8,
556  .folding_gain = 0.7f,
557  .submodes = {
558  NULL, &wb_submode1
559  },
560  .default_submode = 1,
561  },
562 };
563 
564 static float compute_rms(const float *x, int len)
565 {
566  float sum = 0.f;
567 
568  for (int i = 0; i < len; i++)
569  sum += x[i] * x[i];
570 
571  av_assert0(len > 0);
572  return sqrtf(.1f + sum / len);
573 }
574 
575 static void bw_lpc(float gamma, const float *lpc_in,
576  float *lpc_out, int order)
577 {
578  float tmp = gamma;
579 
580  for (int i = 0; i < order; i++) {
581  lpc_out[i] = tmp * lpc_in[i];
582  tmp *= gamma;
583  }
584 }
585 
586 static void iir_mem(const float *x, const float *den,
587  float *y, int N, int ord, float *mem)
588 {
589  for (int i = 0; i < N; i++) {
590  float yi = x[i] + mem[0];
591  float nyi = -yi;
592  for (int j = 0; j < ord - 1; j++)
593  mem[j] = mem[j + 1] + den[j] * nyi;
594  mem[ord - 1] = den[ord - 1] * nyi;
595  y[i] = yi;
596  }
597 }
598 
599 static void highpass(const float *x, float *y, int len, float *mem, int wide)
600 {
601  static const float Pcoef[2][3] = {{ 1.00000f, -1.92683f, 0.93071f }, { 1.00000f, -1.97226f, 0.97332f } };
602  static const float Zcoef[2][3] = {{ 0.96446f, -1.92879f, 0.96446f }, { 0.98645f, -1.97277f, 0.98645f } };
603  const float *den, *num;
604 
605  den = Pcoef[wide];
606  num = Zcoef[wide];
607  for (int i = 0; i < len; i++) {
608  float yi = num[0] * x[i] + mem[0];
609  mem[0] = mem[1] + num[1] * x[i] + -den[1] * yi;
610  mem[1] = num[2] * x[i] + -den[2] * yi;
611  y[i] = yi;
612  }
613 }
614 
615 #define median3(a, b, c) \
616  ((a) < (b) ? ((b) < (c) ? (b) : ((a) < (c) ? (c) : (a))) \
617  : ((c) < (b) ? (b) : ((c) < (a) ? (c) : (a))))
618 
619 static int speex_std_stereo(GetBitContext *gb, void *state, void *data)
620 {
621  StereoState *stereo = data;
622  float sign = get_bits1(gb) ? -1.f : 1.f;
623 
624  stereo->balance = exp(sign * .25f * get_bits(gb, 5));
625  stereo->e_ratio = e_ratio_quant[get_bits(gb, 2)];
626 
627  return 0;
628 }
629 
630 static int speex_inband_handler(GetBitContext *gb, void *state, StereoState *stereo)
631 {
632  int id = get_bits(gb, 4);
633 
634  if (id == SPEEX_INBAND_STEREO) {
635  return speex_std_stereo(gb, state, stereo);
636  } else {
637  int adv;
638 
639  if (id < 2)
640  adv = 1;
641  else if (id < 8)
642  adv = 4;
643  else if (id < 10)
644  adv = 8;
645  else if (id < 12)
646  adv = 16;
647  else if (id < 14)
648  adv = 32;
649  else
650  adv = 64;
651  skip_bits_long(gb, adv);
652  }
653  return 0;
654 }
655 
656 static void sanitize_values(float *vec, float min_val, float max_val, int len)
657 {
658  for (int i = 0; i < len; i++) {
659  if (!isnormal(vec[i]) || fabsf(vec[i]) < 1e-8f)
660  vec[i] = 0.f;
661  else
662  vec[i] = av_clipf(vec[i], min_val, max_val);
663  }
664 }
665 
666 static void signal_mul(const float *x, float *y, float scale, int len)
667 {
668  for (int i = 0; i < len; i++)
669  y[i] = scale * x[i];
670 }
671 
672 static float inner_prod(const float *x, const float *y, int len)
673 {
674  float sum = 0.f;
675 
676  for (int i = 0; i < len; i += 8) {
677  float part = 0.f;
678  part += x[i + 0] * y[i + 0];
679  part += x[i + 1] * y[i + 1];
680  part += x[i + 2] * y[i + 2];
681  part += x[i + 3] * y[i + 3];
682  part += x[i + 4] * y[i + 4];
683  part += x[i + 5] * y[i + 5];
684  part += x[i + 6] * y[i + 6];
685  part += x[i + 7] * y[i + 7];
686  sum += part;
687  }
688 
689  return sum;
690 }
691 
692 static int interp_pitch(const float *exc, float *interp, int pitch, int len)
693 {
694  float corr[4][7], maxcorr;
695  int maxi, maxj;
696 
697  for (int i = 0; i < 7; i++)
698  corr[0][i] = inner_prod(exc, exc - pitch - 3 + i, len);
699  for (int i = 0; i < 3; i++) {
700  for (int j = 0; j < 7; j++) {
701  int i1, i2;
702  float tmp = 0.f;
703 
704  i1 = 3 - j;
705  if (i1 < 0)
706  i1 = 0;
707  i2 = 10 - j;
708  if (i2 > 7)
709  i2 = 7;
710  for (int k = i1; k < i2; k++)
711  tmp += shift_filt[i][k] * corr[0][j + k - 3];
712  corr[i + 1][j] = tmp;
713  }
714  }
715  maxi = maxj = 0;
716  maxcorr = corr[0][0];
717  for (int i = 0; i < 4; i++) {
718  for (int j = 0; j < 7; j++) {
719  if (corr[i][j] > maxcorr) {
720  maxcorr = corr[i][j];
721  maxi = i;
722  maxj = j;
723  }
724  }
725  }
726  for (int i = 0; i < len; i++) {
727  float tmp = 0.f;
728  if (maxi > 0.f) {
729  for (int k = 0; k < 7; k++)
730  tmp += exc[i - (pitch - maxj + 3) + k - 3] * shift_filt[maxi - 1][k];
731  } else {
732  tmp = exc[i - (pitch - maxj + 3)];
733  }
734  interp[i] = tmp;
735  }
736  return pitch - maxj + 3;
737 }
738 
739 static void multicomb(const float *exc, float *new_exc, float *ak, int p, int nsf,
740  int pitch, int max_pitch, float comb_gain)
741 {
742  float old_ener, new_ener;
743  float iexc0_mag, iexc1_mag, exc_mag;
744  float iexc[4 * NB_SUBFRAME_SIZE];
745  float corr0, corr1, gain0, gain1;
746  float pgain1, pgain2;
747  float c1, c2, g1, g2;
748  float ngain, gg1, gg2;
749  int corr_pitch = pitch;
750 
751  interp_pitch(exc, iexc, corr_pitch, 80);
752  if (corr_pitch > max_pitch)
753  interp_pitch(exc, iexc + nsf, 2 * corr_pitch, 80);
754  else
755  interp_pitch(exc, iexc + nsf, -corr_pitch, 80);
756 
757  iexc0_mag = sqrtf(1000.f + inner_prod(iexc, iexc, nsf));
758  iexc1_mag = sqrtf(1000.f + inner_prod(iexc + nsf, iexc + nsf, nsf));
759  exc_mag = sqrtf(1.f + inner_prod(exc, exc, nsf));
760  corr0 = inner_prod(iexc, exc, nsf);
761  corr1 = inner_prod(iexc + nsf, exc, nsf);
762  if (corr0 > iexc0_mag * exc_mag)
763  pgain1 = 1.f;
764  else
765  pgain1 = (corr0 / exc_mag) / iexc0_mag;
766  if (corr1 > iexc1_mag * exc_mag)
767  pgain2 = 1.f;
768  else
769  pgain2 = (corr1 / exc_mag) / iexc1_mag;
770  gg1 = exc_mag / iexc0_mag;
771  gg2 = exc_mag / iexc1_mag;
772  if (comb_gain > 0.f) {
773  c1 = .4f * comb_gain + .07f;
774  c2 = .5f + 1.72f * (c1 - .07f);
775  } else {
776  c1 = c2 = 0.f;
777  }
778  g1 = 1.f - c2 * pgain1 * pgain1;
779  g2 = 1.f - c2 * pgain2 * pgain2;
780  g1 = fmaxf(g1, c1);
781  g2 = fmaxf(g2, c1);
782  g1 = c1 / g1;
783  g2 = c1 / g2;
784 
785  if (corr_pitch > max_pitch) {
786  gain0 = .7f * g1 * gg1;
787  gain1 = .3f * g2 * gg2;
788  } else {
789  gain0 = .6f * g1 * gg1;
790  gain1 = .6f * g2 * gg2;
791  }
792  for (int i = 0; i < nsf; i++)
793  new_exc[i] = exc[i] + (gain0 * iexc[i]) + (gain1 * iexc[i + nsf]);
794  new_ener = compute_rms(new_exc, nsf);
795  old_ener = compute_rms(exc, nsf);
796 
797  old_ener = fmaxf(old_ener, 1.f);
798  new_ener = fmaxf(new_ener, 1.f);
799  old_ener = fminf(old_ener, new_ener);
800  ngain = old_ener / new_ener;
801 
802  for (int i = 0; i < nsf; i++)
803  new_exc[i] *= ngain;
804 }
805 
806 static void lsp_interpolate(const float *old_lsp, const float *new_lsp,
807  float *lsp, int len, int subframe,
808  int nb_subframes, float margin)
809 {
810  const float tmp = (1.f + subframe) / nb_subframes;
811 
812  for (int i = 0; i < len; i++) {
813  lsp[i] = (1.f - tmp) * old_lsp[i] + tmp * new_lsp[i];
814  lsp[i] = av_clipf(lsp[i], margin, M_PI - margin);
815  }
816  for (int i = 1; i < len - 1; i++) {
817  lsp[i] = fmaxf(lsp[i], lsp[i - 1] + margin);
818  if (lsp[i] > lsp[i + 1] - margin)
819  lsp[i] = .5f * (lsp[i] + lsp[i + 1] - margin);
820  }
821 }
822 
823 static void lsp_to_lpc(const float *freq, float *ak, int lpcrdr)
824 {
825  float xout1, xout2, xin1, xin2;
826  float *pw, *n0;
827  float Wp[4 * NB_ORDER + 2] = { 0 };
828  float x_freq[NB_ORDER];
829  const int m = lpcrdr >> 1;
830 
831  pw = Wp;
832 
833  xin1 = xin2 = 1.f;
834 
835  for (int i = 0; i < lpcrdr; i++)
836  x_freq[i] = -cosf(freq[i]);
837 
838  /* reconstruct P(z) and Q(z) by cascading second order
839  * polynomials in form 1 - 2xz(-1) +z(-2), where x is the
840  * LSP coefficient
841  */
842  for (int j = 0; j <= lpcrdr; j++) {
843  int i2 = 0;
844  for (int i = 0; i < m; i++, i2 += 2) {
845  n0 = pw + (i * 4);
846  xout1 = xin1 + 2.f * x_freq[i2 ] * n0[0] + n0[1];
847  xout2 = xin2 + 2.f * x_freq[i2 + 1] * n0[2] + n0[3];
848  n0[1] = n0[0];
849  n0[3] = n0[2];
850  n0[0] = xin1;
851  n0[2] = xin2;
852  xin1 = xout1;
853  xin2 = xout2;
854  }
855  xout1 = xin1 + n0[4];
856  xout2 = xin2 - n0[5];
857  if (j > 0)
858  ak[j - 1] = (xout1 + xout2) * 0.5f;
859  n0[4] = xin1;
860  n0[5] = xin2;
861 
862  xin1 = 0.f;
863  xin2 = 0.f;
864  }
865 }
866 
867 static int nb_decode(AVCodecContext *avctx, void *ptr_st,
868  GetBitContext *gb, float *out)
869 {
870  DecoderState *st = ptr_st;
871  float ol_gain = 0, ol_pitch_coef = 0, best_pitch_gain = 0, pitch_average = 0;
872  int m, pitch, wideband, ol_pitch = 0, best_pitch = 40;
873  SpeexContext *s = avctx->priv_data;
874  float innov[NB_SUBFRAME_SIZE];
875  float exc32[NB_SUBFRAME_SIZE];
876  float interp_qlsp[NB_ORDER];
877  float qlsp[NB_ORDER];
878  float ak[NB_ORDER];
879  float pitch_gain[3] = { 0 };
880 
881  st->exc = st->exc_buf + 2 * NB_PITCH_END + NB_SUBFRAME_SIZE + 6;
882 
883  if (st->encode_submode) {
884  do { /* Search for next narrowband block (handle requests, skip wideband blocks) */
885  if (get_bits_left(gb) < 5)
886  return AVERROR_INVALIDDATA;
887  wideband = get_bits1(gb);
888  if (wideband) /* Skip wideband block (for compatibility) */ {
889  int submode, advance;
890 
891  submode = get_bits(gb, SB_SUBMODE_BITS);
892  advance = wb_skip_table[submode];
893  advance -= SB_SUBMODE_BITS + 1;
894  if (advance < 0)
895  return AVERROR_INVALIDDATA;
896  skip_bits_long(gb, advance);
897 
898  if (get_bits_left(gb) < 5)
899  return AVERROR_INVALIDDATA;
900  wideband = get_bits1(gb);
901  if (wideband) {
902  submode = get_bits(gb, SB_SUBMODE_BITS);
903  advance = wb_skip_table[submode];
904  advance -= SB_SUBMODE_BITS + 1;
905  if (advance < 0)
906  return AVERROR_INVALIDDATA;
907  skip_bits_long(gb, advance);
908  wideband = get_bits1(gb);
909  if (wideband) {
910  av_log(avctx, AV_LOG_ERROR, "more than two wideband layers found\n");
911  return AVERROR_INVALIDDATA;
912  }
913  }
914  }
915  if (get_bits_left(gb) < 4)
916  return AVERROR_INVALIDDATA;
917  m = get_bits(gb, 4);
918  if (m == 15) /* We found a terminator */ {
919  return AVERROR_INVALIDDATA;
920  } else if (m == 14) /* Speex in-band request */ {
921  int ret = speex_inband_handler(gb, st, &s->stereo);
922  if (ret)
923  return ret;
924  } else if (m == 13) /* User in-band request */ {
925  int ret = speex_default_user_handler(gb, st, NULL);
926  if (ret)
927  return ret;
928  } else if (m > 8) /* Invalid mode */ {
929  return AVERROR_INVALIDDATA;
930  }
931  } while (m > 8);
932 
933  st->submodeID = m; /* Get the sub-mode that was used */
934  }
935 
936  /* Shift all buffers by one frame */
937  memmove(st->exc_buf, st->exc_buf + NB_FRAME_SIZE, (2 * NB_PITCH_END + NB_SUBFRAME_SIZE + 12) * sizeof(float));
938 
939  /* If null mode (no transmission), just set a couple things to zero */
940  if (st->submodes[st->submodeID] == NULL) {
941  float lpc[NB_ORDER];
942  float innov_gain = 0.f;
943 
944  bw_lpc(0.93f, st->interp_qlpc, lpc, NB_ORDER);
945  innov_gain = compute_rms(st->exc, NB_FRAME_SIZE);
946  for (int i = 0; i < NB_FRAME_SIZE; i++)
947  st->exc[i] = speex_rand(innov_gain, &st->seed);
948 
949  /* Final signal synthesis from excitation */
950  iir_mem(st->exc, lpc, out, NB_FRAME_SIZE, NB_ORDER, st->mem_sp);
951  st->count_lost = 0;
952 
953  return 0;
954  }
955 
956  /* Unquantize LSPs */
957  SUBMODE(lsp_unquant)(qlsp, NB_ORDER, gb);
958 
959  /* Damp memory if a frame was lost and the LSP changed too much */
960  if (st->count_lost) {
961  float fact, lsp_dist = 0;
962 
963  for (int i = 0; i < NB_ORDER; i++)
964  lsp_dist = lsp_dist + FFABS(st->old_qlsp[i] - qlsp[i]);
965  fact = .6f * exp(-.2f * lsp_dist);
966  for (int i = 0; i < NB_ORDER; i++)
967  st->mem_sp[i] = fact * st->mem_sp[i];
968  }
969 
970  /* Handle first frame and lost-packet case */
971  if (st->first || st->count_lost)
972  memcpy(st->old_qlsp, qlsp, sizeof(st->old_qlsp));
973 
974  /* Get open-loop pitch estimation for low bit-rate pitch coding */
975  if (SUBMODE(lbr_pitch) != -1)
976  ol_pitch = NB_PITCH_START + get_bits(gb, 7);
977 
978  if (SUBMODE(forced_pitch_gain))
979  ol_pitch_coef = 0.066667f * get_bits(gb, 4);
980 
981  /* Get global excitation gain */
982  ol_gain = expf(get_bits(gb, 5) / 3.5f);
983 
984  if (st->submodeID == 1)
985  st->dtx_enabled = get_bits(gb, 4) == 15;
986 
987  if (st->submodeID > 1)
988  st->dtx_enabled = 0;
989 
990  for (int sub = 0; sub < NB_NB_SUBFRAMES; sub++) { /* Loop on subframes */
991  float *exc, *innov_save = NULL, tmp, ener;
992  int pit_min, pit_max, offset, q_energy;
993 
994  offset = NB_SUBFRAME_SIZE * sub; /* Offset relative to start of frame */
995  exc = st->exc + offset; /* Excitation */
996  if (st->innov_save) /* Original signal */
997  innov_save = st->innov_save + offset;
998 
999  SPEEX_MEMSET(exc, 0, NB_SUBFRAME_SIZE); /* Reset excitation */
1000 
1001  /* Adaptive codebook contribution */
1002  av_assert0(SUBMODE(ltp_unquant));
1003  /* Handle pitch constraints if any */
1004  if (SUBMODE(lbr_pitch) != -1) {
1005  int margin = SUBMODE(lbr_pitch);
1006 
1007  if (margin) {
1008  pit_min = ol_pitch - margin + 1;
1009  pit_min = FFMAX(pit_min, NB_PITCH_START);
1010  pit_max = ol_pitch + margin;
1011  pit_max = FFMIN(pit_max, NB_PITCH_START);
1012  } else {
1013  pit_min = pit_max = ol_pitch;
1014  }
1015  } else {
1016  pit_min = NB_PITCH_START;
1017  pit_max = NB_PITCH_END;
1018  }
1019 
1020  SUBMODE(ltp_unquant)(exc, exc32, pit_min, pit_max, ol_pitch_coef, SUBMODE(LtpParam),
1021  NB_SUBFRAME_SIZE, &pitch, pitch_gain, gb, st->count_lost, offset,
1022  st->last_pitch_gain, 0);
1023 
1024  sanitize_values(exc32, -32000, 32000, NB_SUBFRAME_SIZE);
1025 
1026  tmp = gain_3tap_to_1tap(pitch_gain);
1027 
1028  pitch_average += tmp;
1029  if ((tmp > best_pitch_gain &&
1030  FFABS(2 * best_pitch - pitch) >= 3 &&
1031  FFABS(3 * best_pitch - pitch) >= 4 &&
1032  FFABS(4 * best_pitch - pitch) >= 5) ||
1033  (tmp > .6f * best_pitch_gain &&
1034  (FFABS(best_pitch - 2 * pitch) < 3 ||
1035  FFABS(best_pitch - 3 * pitch) < 4 ||
1036  FFABS(best_pitch - 4 * pitch) < 5)) ||
1037  ((.67f * tmp) > best_pitch_gain &&
1038  (FFABS(2 * best_pitch - pitch) < 3 ||
1039  FFABS(3 * best_pitch - pitch) < 4 ||
1040  FFABS(4 * best_pitch - pitch) < 5))) {
1041  best_pitch = pitch;
1042  if (tmp > best_pitch_gain)
1043  best_pitch_gain = tmp;
1044  }
1045 
1046  memset(innov, 0, sizeof(innov));
1047 
1048  /* Decode sub-frame gain correction */
1049  if (SUBMODE(have_subframe_gain) == 3) {
1050  q_energy = get_bits(gb, 3);
1051  ener = exc_gain_quant_scal3[q_energy] * ol_gain;
1052  } else if (SUBMODE(have_subframe_gain) == 1) {
1053  q_energy = get_bits1(gb);
1054  ener = exc_gain_quant_scal1[q_energy] * ol_gain;
1055  } else {
1056  ener = ol_gain;
1057  }
1058 
1059  av_assert0(SUBMODE(innovation_unquant));
1060  /* Fixed codebook contribution */
1061  SUBMODE(innovation_unquant)(innov, SUBMODE(innovation_params), NB_SUBFRAME_SIZE, gb, &st->seed);
1062  /* De-normalize innovation and update excitation */
1063 
1064  signal_mul(innov, innov, ener, NB_SUBFRAME_SIZE);
1065 
1066  /* Decode second codebook (only for some modes) */
1067  if (SUBMODE(double_codebook)) {
1068  float innov2[NB_SUBFRAME_SIZE] = { 0 };
1069 
1070  SUBMODE(innovation_unquant)(innov2, SUBMODE(innovation_params), NB_SUBFRAME_SIZE, gb, &st->seed);
1071  signal_mul(innov2, innov2, 0.454545f * ener, NB_SUBFRAME_SIZE);
1072  for (int i = 0; i < NB_SUBFRAME_SIZE; i++)
1073  innov[i] += innov2[i];
1074  }
1075  for (int i = 0; i < NB_SUBFRAME_SIZE; i++)
1076  exc[i] = exc32[i] + innov[i];
1077  if (innov_save)
1078  memcpy(innov_save, innov, sizeof(innov));
1079 
1080  /* Vocoder mode */
1081  if (st->submodeID == 1) {
1082  float g = ol_pitch_coef;
1083 
1084  g = av_clipf(1.5f * (g - .2f), 0.f, 1.f);
1085 
1086  SPEEX_MEMSET(exc, 0, NB_SUBFRAME_SIZE);
1087  while (st->voc_offset < NB_SUBFRAME_SIZE) {
1088  if (st->voc_offset >= 0)
1089  exc[st->voc_offset] = sqrtf(2.f * ol_pitch) * (g * ol_gain);
1090  st->voc_offset += ol_pitch;
1091  }
1093 
1094  for (int i = 0; i < NB_SUBFRAME_SIZE; i++) {
1095  float exci = exc[i];
1096  exc[i] = (.7f * exc[i] + .3f * st->voc_m1) + ((1.f - .85f * g) * innov[i]) - .15f * g * st->voc_m2;
1097  st->voc_m1 = exci;
1098  st->voc_m2 = innov[i];
1099  st->voc_mean = .8f * st->voc_mean + .2f * exc[i];
1100  exc[i] -= st->voc_mean;
1101  }
1102  }
1103  }
1104 
1105  if (st->lpc_enh_enabled && SUBMODE(comb_gain) > 0 && !st->count_lost) {
1107  2 * NB_SUBFRAME_SIZE, best_pitch, 40, SUBMODE(comb_gain));
1109  st->interp_qlpc, NB_ORDER, 2 * NB_SUBFRAME_SIZE, best_pitch, 40,
1110  SUBMODE(comb_gain));
1111  } else {
1113  }
1114 
1115  /* If the last packet was lost, re-scale the excitation to obtain the same
1116  * energy as encoded in ol_gain */
1117  if (st->count_lost) {
1118  float exc_ener, gain;
1119 
1120  exc_ener = compute_rms(st->exc, NB_FRAME_SIZE);
1121  av_assert0(exc_ener + 1.f > 0.f);
1122  gain = fminf(ol_gain / (exc_ener + 1.f), 2.f);
1123  for (int i = 0; i < NB_FRAME_SIZE; i++) {
1124  st->exc[i] *= gain;
1125  out[i] = st->exc[i - NB_SUBFRAME_SIZE];
1126  }
1127  }
1128 
1129  for (int sub = 0; sub < NB_NB_SUBFRAMES; sub++) { /* Loop on subframes */
1130  const int offset = NB_SUBFRAME_SIZE * sub; /* Offset relative to start of frame */
1131  float pi_g = 1.f, *sp = out + offset; /* Original signal */
1132 
1133  lsp_interpolate(st->old_qlsp, qlsp, interp_qlsp, NB_ORDER, sub, NB_NB_SUBFRAMES, 0.002f);
1134  lsp_to_lpc(interp_qlsp, ak, NB_ORDER); /* Compute interpolated LPCs (unquantized) */
1135 
1136  for (int i = 0; i < NB_ORDER; i += 2) /* Compute analysis filter at w=pi */
1137  pi_g += ak[i + 1] - ak[i];
1138  st->pi_gain[sub] = pi_g;
1139  st->exc_rms[sub] = compute_rms(st->exc + offset, NB_SUBFRAME_SIZE);
1140 
1142 
1143  memcpy(st->interp_qlpc, ak, sizeof(st->interp_qlpc));
1144  }
1145 
1146  if (st->highpass_enabled)
1148 
1149  /* Store the LSPs for interpolation in the next frame */
1150  memcpy(st->old_qlsp, qlsp, sizeof(st->old_qlsp));
1151 
1152  st->count_lost = 0;
1153  st->last_pitch = best_pitch;
1154  st->last_pitch_gain = .25f * pitch_average;
1155  st->last_ol_gain = ol_gain;
1156  st->first = 0;
1157 
1158  return 0;
1159 }
1160 
1161 static void qmf_synth(const float *x1, const float *x2, const float *a, float *y, int N, int M, float *mem1, float *mem2)
1162 {
1163  const int M2 = M >> 1, N2 = N >> 1;
1164  float xx1[352], xx2[352];
1165 
1166  for (int i = 0; i < N2; i++)
1167  xx1[i] = x1[N2-1-i];
1168  for (int i = 0; i < M2; i++)
1169  xx1[N2+i] = mem1[2*i+1];
1170  for (int i = 0; i < N2; i++)
1171  xx2[i] = x2[N2-1-i];
1172  for (int i = 0; i < M2; i++)
1173  xx2[N2+i] = mem2[2*i+1];
1174 
1175  for (int i = 0; i < N2; i += 2) {
1176  float y0, y1, y2, y3;
1177  float x10, x20;
1178 
1179  y0 = y1 = y2 = y3 = 0.f;
1180  x10 = xx1[N2-2-i];
1181  x20 = xx2[N2-2-i];
1182 
1183  for (int j = 0; j < M2; j += 2) {
1184  float x11, x21;
1185  float a0, a1;
1186 
1187  a0 = a[2*j];
1188  a1 = a[2*j+1];
1189  x11 = xx1[N2-1+j-i];
1190  x21 = xx2[N2-1+j-i];
1191 
1192  y0 += a0 * (x11-x21);
1193  y1 += a1 * (x11+x21);
1194  y2 += a0 * (x10-x20);
1195  y3 += a1 * (x10+x20);
1196  a0 = a[2*j+2];
1197  a1 = a[2*j+3];
1198  x10 = xx1[N2+j-i];
1199  x20 = xx2[N2+j-i];
1200 
1201  y0 += a0 * (x10-x20);
1202  y1 += a1 * (x10+x20);
1203  y2 += a0 * (x11-x21);
1204  y3 += a1 * (x11+x21);
1205  }
1206  y[2 * i ] = 2.f * y0;
1207  y[2 * i+1] = 2.f * y1;
1208  y[2 * i+2] = 2.f * y2;
1209  y[2 * i+3] = 2.f * y3;
1210  }
1211 
1212  for (int i = 0; i < M2; i++)
1213  mem1[2*i+1] = xx1[i];
1214  for (int i = 0; i < M2; i++)
1215  mem2[2*i+1] = xx2[i];
1216 }
1217 
1218 static int sb_decode(AVCodecContext *avctx, void *ptr_st,
1219  GetBitContext *gb, float *out)
1220 {
1221  SpeexContext *s = avctx->priv_data;
1222  DecoderState *st = ptr_st;
1223  float low_pi_gain[NB_NB_SUBFRAMES];
1224  float low_exc_rms[NB_NB_SUBFRAMES];
1225  float interp_qlsp[NB_ORDER];
1226  int ret, wideband;
1227  float *low_innov_alias;
1228  float qlsp[NB_ORDER];
1229  float ak[NB_ORDER];
1230  const SpeexMode *mode;
1231 
1232  mode = st->mode;
1233 
1234  if (st->modeID > 0) {
1235  low_innov_alias = out + st->frame_size;
1236  s->st[st->modeID - 1].innov_save = low_innov_alias;
1237  ret = speex_modes[st->modeID - 1].decode(avctx, &s->st[st->modeID - 1], gb, out);
1238  if (ret < 0)
1239  return ret;
1240  }
1241 
1242  if (st->encode_submode) { /* Check "wideband bit" */
1243  if (get_bits_left(gb) > 0)
1244  wideband = show_bits1(gb);
1245  else
1246  wideband = 0;
1247  if (wideband) { /* Regular wideband frame, read the submode */
1248  wideband = get_bits1(gb);
1249  st->submodeID = get_bits(gb, SB_SUBMODE_BITS);
1250  } else { /* Was a narrowband frame, set "null submode" */
1251  st->submodeID = 0;
1252  }
1253  if (st->submodeID != 0 && st->submodes[st->submodeID] == NULL)
1254  return AVERROR_INVALIDDATA;
1255  }
1256 
1257  /* If null mode (no transmission), just set a couple things to zero */
1258  if (st->submodes[st->submodeID] == NULL) {
1259  for (int i = 0; i < st->frame_size; i++)
1260  out[st->frame_size + i] = 1e-15f;
1261 
1262  st->first = 1;
1263 
1264  /* Final signal synthesis from excitation */
1265  iir_mem(out + st->frame_size, st->interp_qlpc, out + st->frame_size, st->frame_size, st->lpc_size, st->mem_sp);
1266 
1267  qmf_synth(out, out + st->frame_size, h0, out, st->full_frame_size, QMF_ORDER, st->g0_mem, st->g1_mem);
1268 
1269  return 0;
1270  }
1271 
1272  memcpy(low_pi_gain, s->st[st->modeID - 1].pi_gain, sizeof(low_pi_gain));
1273  memcpy(low_exc_rms, s->st[st->modeID - 1].exc_rms, sizeof(low_exc_rms));
1274 
1275  SUBMODE(lsp_unquant)(qlsp, st->lpc_size, gb);
1276 
1277  if (st->first)
1278  memcpy(st->old_qlsp, qlsp, sizeof(st->old_qlsp));
1279 
1280  for (int sub = 0; sub < st->nb_subframes; sub++) {
1281  float filter_ratio, el, rl, rh;
1282  float *innov_save = NULL, *sp;
1283  float exc[80];
1284  int offset;
1285 
1286  offset = st->subframe_size * sub;
1287  sp = out + st->frame_size + offset;
1288  /* Pointer for saving innovation */
1289  if (st->innov_save) {
1290  innov_save = st->innov_save + 2 * offset;
1291  SPEEX_MEMSET(innov_save, 0, 2 * st->subframe_size);
1292  }
1293 
1294  av_assert0(st->nb_subframes > 0);
1295  lsp_interpolate(st->old_qlsp, qlsp, interp_qlsp, st->lpc_size, sub, st->nb_subframes, 0.05f);
1296  lsp_to_lpc(interp_qlsp, ak, st->lpc_size);
1297 
1298  /* Calculate reponse ratio between the low and high filter in the middle
1299  of the band (4000 Hz) */
1300  st->pi_gain[sub] = 1.f;
1301  rh = 1.f;
1302  for (int i = 0; i < st->lpc_size; i += 2) {
1303  rh += ak[i + 1] - ak[i];
1304  st->pi_gain[sub] += ak[i] + ak[i + 1];
1305  }
1306 
1307  rl = low_pi_gain[sub];
1308  filter_ratio = (rl + .01f) / (rh + .01f);
1309 
1310  SPEEX_MEMSET(exc, 0, st->subframe_size);
1311  if (!SUBMODE(innovation_unquant)) {
1312  const int x = get_bits(gb, 5);
1313  const float g = expf(.125f * (x - 10)) / filter_ratio;
1314 
1315  for (int i = 0; i < st->subframe_size; i += 2) {
1316  exc[i ] = mode->folding_gain * low_innov_alias[offset + i ] * g;
1317  exc[i + 1] = -mode->folding_gain * low_innov_alias[offset + i + 1] * g;
1318  }
1319  } else {
1320  float gc, scale;
1321 
1322  el = low_exc_rms[sub];
1323  gc = 0.87360f * gc_quant_bound[get_bits(gb, 4)];
1324 
1325  if (st->subframe_size == 80)
1326  gc *= M_SQRT2;
1327 
1328  scale = (gc * el) / filter_ratio;
1329  SUBMODE(innovation_unquant)
1330  (exc, SUBMODE(innovation_params), st->subframe_size,
1331  gb, &st->seed);
1332 
1333  signal_mul(exc, exc, scale, st->subframe_size);
1334  if (SUBMODE(double_codebook)) {
1335  float innov2[80];
1336 
1337  SPEEX_MEMSET(innov2, 0, st->subframe_size);
1338  SUBMODE(innovation_unquant)(innov2, SUBMODE(innovation_params), st->subframe_size, gb, &st->seed);
1339  signal_mul(innov2, innov2, 0.4f * scale, st->subframe_size);
1340  for (int i = 0; i < st->subframe_size; i++)
1341  exc[i] += innov2[i];
1342  }
1343  }
1344 
1345  if (st->innov_save) {
1346  for (int i = 0; i < st->subframe_size; i++)
1347  innov_save[2 * i] = exc[i];
1348  }
1349 
1350  iir_mem(st->exc_buf, st->interp_qlpc, sp, st->subframe_size, st->lpc_size, st->mem_sp);
1351  memcpy(st->exc_buf, exc, sizeof(exc));
1352  memcpy(st->interp_qlpc, ak, sizeof(st->interp_qlpc));
1353  st->exc_rms[sub] = compute_rms(st->exc_buf, st->subframe_size);
1354  }
1355 
1356  qmf_synth(out, out + st->frame_size, h0, out, st->full_frame_size, QMF_ORDER, st->g0_mem, st->g1_mem);
1357  memcpy(st->old_qlsp, qlsp, sizeof(st->old_qlsp));
1358 
1359  st->first = 0;
1360 
1361  return 0;
1362 }
1363 
1365 {
1366  st->mode = mode;
1367  st->modeID = mode->modeID;
1368 
1369  st->first = 1;
1370  st->encode_submode = 1;
1371  st->is_wideband = st->modeID > 0;
1372  st->innov_save = NULL;
1373 
1374  st->submodes = mode->submodes;
1375  st->submodeID = mode->default_submode;
1376  st->subframe_size = mode->subframe_size;
1377  st->lpc_size = mode->lpc_size;
1378  st->full_frame_size = (1 + (st->modeID > 0)) * mode->frame_size;
1379  st->nb_subframes = mode->frame_size / mode->subframe_size;
1380  st->frame_size = mode->frame_size;
1381 
1382  st->lpc_enh_enabled = 1;
1383 
1384  st->last_pitch = 40;
1385  st->count_lost = 0;
1386  st->seed = 1000;
1387  st->last_ol_gain = 0;
1388 
1389  st->voc_m1 = st->voc_m2 = st->voc_mean = 0;
1390  st->voc_offset = 0;
1391  st->dtx_enabled = 0;
1392  st->highpass_enabled = mode->modeID == 0;
1393 
1394  return 0;
1395 }
1396 
1398  const uint8_t *extradata, int extradata_size)
1399 {
1400  SpeexContext *s = avctx->priv_data;
1401  const uint8_t *buf = av_strnstr(extradata, "Speex ", extradata_size);
1402 
1403  if (!buf)
1404  return AVERROR_INVALIDDATA;
1405 
1406  buf += 28;
1407 
1408  s->version_id = bytestream_get_le32(&buf);
1409  buf += 4;
1410  s->rate = bytestream_get_le32(&buf);
1411  if (s->rate <= 0)
1412  return AVERROR_INVALIDDATA;
1413  s->mode = bytestream_get_le32(&buf);
1414  if (s->mode < 0 || s->mode >= SPEEX_NB_MODES)
1415  return AVERROR_INVALIDDATA;
1416  s->bitstream_version = bytestream_get_le32(&buf);
1417  if (s->bitstream_version != 4)
1418  return AVERROR_INVALIDDATA;
1419  s->nb_channels = bytestream_get_le32(&buf);
1420  if (s->nb_channels <= 0 || s->nb_channels > 2)
1421  return AVERROR_INVALIDDATA;
1422  s->bitrate = bytestream_get_le32(&buf);
1423  s->frame_size = bytestream_get_le32(&buf);
1424  if (s->frame_size < NB_FRAME_SIZE << (s->mode > 0) ||
1425  s->frame_size > INT32_MAX >> (s->mode > 0))
1426  return AVERROR_INVALIDDATA;
1427  s->frame_size <<= (s->mode > 0);
1428  s->vbr = bytestream_get_le32(&buf);
1429  s->frames_per_packet = bytestream_get_le32(&buf);
1430  if (s->frames_per_packet <= 0 ||
1431  s->frames_per_packet > 64 ||
1432  s->frames_per_packet >= INT32_MAX / s->nb_channels / s->frame_size)
1433  return AVERROR_INVALIDDATA;
1434  s->extra_headers = bytestream_get_le32(&buf);
1435 
1436  return 0;
1437 }
1438 
1440 {
1441  SpeexContext *s = avctx->priv_data;
1442  int ret;
1443 
1444  s->fdsp = avpriv_float_dsp_alloc(0);
1445  if (!s->fdsp)
1446  return AVERROR(ENOMEM);
1447 
1448  if (avctx->extradata && avctx->extradata_size >= 80) {
1449  ret = parse_speex_extradata(avctx, avctx->extradata, avctx->extradata_size);
1450  if (ret < 0)
1451  return ret;
1452  } else {
1453  s->rate = avctx->sample_rate;
1454  if (s->rate <= 0)
1455  return AVERROR_INVALIDDATA;
1456 
1457  s->nb_channels = avctx->ch_layout.nb_channels;
1458  if (s->nb_channels <= 0 || s->nb_channels > 2)
1459  return AVERROR_INVALIDDATA;
1460 
1461  switch (s->rate) {
1462  case 8000: s->mode = 0; break;
1463  case 16000: s->mode = 1; break;
1464  case 32000: s->mode = 2; break;
1465  default: s->mode = 2;
1466  }
1467 
1468  s->frames_per_packet = 64;
1469  s->frame_size = NB_FRAME_SIZE << s->mode;
1470  }
1471 
1472  if (avctx->codec_tag == MKTAG('S', 'P', 'X', 'N')) {
1473  int quality;
1474 
1475  if (!avctx->extradata || avctx->extradata && avctx->extradata_size < 47) {
1476  av_log(avctx, AV_LOG_ERROR, "Missing or invalid extradata.\n");
1477  return AVERROR_INVALIDDATA;
1478  }
1479 
1480  quality = avctx->extradata[37];
1481  if (quality > 10) {
1482  av_log(avctx, AV_LOG_ERROR, "Unsupported quality mode %d.\n", quality);
1483  return AVERROR_PATCHWELCOME;
1484  }
1485 
1486  s->pkt_size = ((const uint8_t[]){ 5, 10, 15, 20, 20, 28, 28, 38, 38, 46, 62 })[quality];
1487 
1488  s->mode = 0;
1489  s->nb_channels = 1;
1490  s->rate = avctx->sample_rate;
1491  if (s->rate <= 0)
1492  return AVERROR_INVALIDDATA;
1493  s->frames_per_packet = 1;
1494  s->frame_size = NB_FRAME_SIZE;
1495  }
1496 
1497  if (s->bitrate > 0)
1498  avctx->bit_rate = s->bitrate;
1501  avctx->ch_layout.nb_channels = s->nb_channels;
1502  avctx->sample_rate = s->rate;
1503  avctx->sample_fmt = AV_SAMPLE_FMT_FLT;
1504 
1505  for (int m = 0; m <= s->mode; m++) {
1506  ret = decoder_init(s, &s->st[m], &speex_modes[m]);
1507  if (ret < 0)
1508  return ret;
1509  }
1510 
1511  s->stereo.balance = 1.f;
1512  s->stereo.e_ratio = .5f;
1513  s->stereo.smooth_left = 1.f;
1514  s->stereo.smooth_right = 1.f;
1515 
1516  return 0;
1517 }
1518 
1519 static void speex_decode_stereo(float *data, int frame_size, StereoState *stereo)
1520 {
1521  float balance, e_left, e_right, e_ratio;
1522 
1523  balance = stereo->balance;
1524  e_ratio = stereo->e_ratio;
1525 
1526  /* These two are Q14, with max value just below 2. */
1527  e_right = 1.f / sqrtf(e_ratio * (1.f + balance));
1528  e_left = sqrtf(balance) * e_right;
1529 
1530  for (int i = frame_size - 1; i >= 0; i--) {
1531  float tmp = data[i];
1532  stereo->smooth_left = stereo->smooth_left * 0.98f + e_left * 0.02f;
1533  stereo->smooth_right = stereo->smooth_right * 0.98f + e_right * 0.02f;
1534  data[2 * i ] = stereo->smooth_left * tmp;
1535  data[2 * i + 1] = stereo->smooth_right * tmp;
1536  }
1537 }
1538 
1540  int *got_frame_ptr, AVPacket *avpkt)
1541 {
1542  SpeexContext *s = avctx->priv_data;
1543  int frames_per_packet = s->frames_per_packet;
1544  const float scale = 1.f / 32768.f;
1545  int buf_size = avpkt->size;
1546  float *dst;
1547  int ret;
1548 
1549  if (s->pkt_size && avpkt->size == 62)
1550  buf_size = s->pkt_size;
1551  if ((ret = init_get_bits8(&s->gb, avpkt->data, buf_size)) < 0)
1552  return ret;
1553 
1554  frame->nb_samples = FFALIGN(s->frame_size * frames_per_packet, 4);
1555  if ((ret = ff_get_buffer(avctx, frame, 0)) < 0)
1556  return ret;
1557 
1558  dst = (float *)frame->extended_data[0];
1559  for (int i = 0; i < frames_per_packet; i++) {
1560  ret = speex_modes[s->mode].decode(avctx, &s->st[s->mode], &s->gb, dst + i * s->frame_size);
1561  if (ret < 0)
1562  return ret;
1563  if (avctx->ch_layout.nb_channels == 2)
1564  speex_decode_stereo(dst + i * s->frame_size, s->frame_size, &s->stereo);
1565  if (get_bits_left(&s->gb) < 5 ||
1566  show_bits(&s->gb, 5) == 15) {
1567  frames_per_packet = i + 1;
1568  break;
1569  }
1570  }
1571 
1572  dst = (float *)frame->extended_data[0];
1573  s->fdsp->vector_fmul_scalar(dst, dst, scale, frame->nb_samples * frame->ch_layout.nb_channels);
1574  frame->nb_samples = s->frame_size * frames_per_packet;
1575 
1576  *got_frame_ptr = 1;
1577 
1578  return (get_bits_count(&s->gb) + 7) >> 3;
1579 }
1580 
1582 {
1583  SpeexContext *s = avctx->priv_data;
1584  av_freep(&s->fdsp);
1585  return 0;
1586 }
1587 
1589  .p.name = "speex",
1590  CODEC_LONG_NAME("Speex"),
1591  .p.type = AVMEDIA_TYPE_AUDIO,
1592  .p.id = AV_CODEC_ID_SPEEX,
1593  .init = speex_decode_init,
1595  .close = speex_decode_close,
1596  .p.capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_CHANNEL_CONF,
1597  .priv_data_size = sizeof(SpeexContext),
1598  .caps_internal = FF_CODEC_CAP_INIT_CLEANUP,
1599 };
M
#define M(a, b)
Definition: vp3dsp.c:48
LtpParams::pitch_bits
int pitch_bits
Definition: speexdec.c:93
DecoderState::submodeID
int submodeID
Activated sub-mode.
Definition: speexdec.c:200
split_cb_high
static const SplitCodebookParams split_cb_high
Definition: speexdec.c:115
SB_SUBMODE_BITS
#define SB_SUBMODE_BITS
Definition: speexdec.c:72
nb_submode4
static const SpeexSubmode nb_submode4
Definition: speexdec.c:473
skip_bits_long
static void skip_bits_long(GetBitContext *s, int n)
Skips the specified number of bits.
Definition: get_bits.h:278
DecoderState::seed
uint32_t seed
Seed used for random number generation.
Definition: speexdec.c:196
h0
static const float h0[64]
Definition: speexdata.h:741
SpeexSubmode::have_subframe_gain
int have_subframe_gain
Number of bits to use as sub-frame innovation gain.
Definition: speexdec.c:153
SplitCodebookParams::shape_bits
int shape_bits
Definition: speexdec.c:105
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
show_bits1
static unsigned int show_bits1(GetBitContext *s)
Definition: get_bits.h:408
QMF_ORDER
#define QMF_ORDER
Definition: speexdec.c:67
get_bits_left
static int get_bits_left(GetBitContext *gb)
Definition: get_bits.h:694
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
wb_submode2
static const SpeexSubmode wb_submode2
Definition: speexdec.c:507
hexc_10_32_table
static const int8_t hexc_10_32_table[320]
Definition: speexdata.h:694
nb_submode3
static const SpeexSubmode nb_submode3
Definition: speexdec.c:467
DecoderState::count_lost
int count_lost
Was the last frame lost?
Definition: speexdec.c:185
exc_gain_quant_scal1
static const float exc_gain_quant_scal1[2]
Definition: speexdata.h:778
out
FILE * out
Definition: movenc.c:54
speexdata.h
SpeexContext::vbr
int32_t vbr
1 for a VBR decoding, 0 otherwise
Definition: speexdec.c:250
AVCodecContext::sample_rate
int sample_rate
samples per second
Definition: avcodec.h:1068
DecoderState::exc_buf
float exc_buf[NB_DEC_BUFFER]
Excitation buffer.
Definition: speexdec.c:214
DecoderState::highpass_enabled
int highpass_enabled
Is the input filter enabled.
Definition: speexdec.c:210
DecoderState::dtx_enabled
int dtx_enabled
Definition: speexdec.c:209
DecoderState::mode
const SpeexMode * mode
Definition: speexdec.c:180
hexc_table
static const int8_t hexc_table[1024]
Definition: speexdata.h:612
ltp_quant_func
int(* ltp_quant_func)(float *, float *, float *, float *, float *, float *, const void *, int, int, float, int, int, GetBitContext *, char *, float *, float *, int, int, int, float *)
Long-term predictor quantization.
Definition: speexdec.c:125
DecoderState::mem_hp
float mem_hp[2]
High-pass filter memory.
Definition: speexdec.c:213
DecoderState::voc_m1
float voc_m1
Definition: speexdec.c:204
get_bits_count
static int get_bits_count(const GetBitContext *s)
Definition: get_bits.h:266
exc_8_128_table
static const int8_t exc_8_128_table[1024]
Definition: speexdata.h:295
LSP_DIV_1024
#define LSP_DIV_1024(x)
Definition: speexdec.c:88
SpeexContext::version_id
int32_t version_id
Version for Speex (for checking compatibility)
Definition: speexdec.c:243
cdbk_nb_high1
static const int8_t cdbk_nb_high1[320]
Definition: speexdata.h:562
SpeexMode::modeID
int modeID
ID of the mode.
Definition: speexdec.c:169
DecoderState::lpc_enh_enabled
int lpc_enh_enabled
1 when LPC enhancer is on, 0 otherwise
Definition: speexdec.c:201
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:340
tmp
static uint8_t tmp[11]
Definition: aes_ctr.c:28
AVPacket::data
uint8_t * data
Definition: packet.h:522
LtpParams
Definition: speexdec.c:90
data
const char data[16]
Definition: mxf.c:148
DecoderState::exc
float * exc
Start of excitation frame.
Definition: speexdec.c:212
expf
#define expf(x)
Definition: libm.h:283
FFCodec
Definition: codec_internal.h:127
LSP_DIV_512
#define LSP_DIV_512(x)
Definition: speexdec.c:87
AVChannelLayout::order
enum AVChannelOrder order
Channel order used in this layout.
Definition: channel_layout.h:318
FFMAX
#define FFMAX(a, b)
Definition: macros.h:47
N2
#define N2
Definition: vf_pp7.c:72
SpeexMode::lpc_size
int lpc_size
Order of LPC filter.
Definition: speexdec.c:173
c1
static const uint64_t c1
Definition: murmur3.c:52
nb_submode8
static const SpeexSubmode nb_submode8
Definition: speexdec.c:497
AVChannelLayout::nb_channels
int nb_channels
Number of channels in this layout.
Definition: channel_layout.h:323
SpeexSubmode::double_codebook
int double_codebook
Apply innovation quantization twice for higher quality (and higher bit-rate)
Definition: speexdec.c:155
speex_inband_handler
static int speex_inband_handler(GetBitContext *gb, void *state, StereoState *stereo)
Definition: speexdec.c:630
DecoderState::first
int first
Is first frame
Definition: speexdec.c:182
gain_3tap_to_1tap
#define gain_3tap_to_1tap(g)
Definition: speexdec.c:351
quality
trying all byte sequences megabyte in length and selecting the best looking sequence will yield cases to try But a word about quality
Definition: rate_distortion.txt:12
wb_submode4
static const SpeexSubmode wb_submode4
Definition: speexdec.c:517
SpeexSubmode
Definition: speexdec.c:147
SpeexMode::subframe_size
int subframe_size
Size of sub-frames used for decoding.
Definition: speexdec.c:172
SpeexSubmode::LtpParam
const void * LtpParam
Pitch parameters (options)
Definition: speexdec.c:160
LSP_DIV_256
#define LSP_DIV_256(x)
Definition: speexdec.c:86
SpeexContext::pkt_size
int pkt_size
Definition: speexdec.c:254
SpeexContext::nb_channels
int32_t nb_channels
Number of channels decoded.
Definition: speexdec.c:247
get_bits
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
Definition: get_bits.h:335
FFCodec::p
AVCodec p
The public AVCodec.
Definition: codec_internal.h:131
exc_5_256_table
static const int8_t exc_5_256_table[1280]
Definition: speexdata.h:137
AV_CODEC_ID_SPEEX
@ AV_CODEC_ID_SPEEX
Definition: codec_id.h:478
LSP_LINEAR_HIGH
#define LSP_LINEAR_HIGH(i)
Definition: speexdec.c:85
cosf
#define cosf(x)
Definition: libm.h:78
interp
interp
Definition: vf_curves.c:61
AVCodecContext::ch_layout
AVChannelLayout ch_layout
Audio channel layout.
Definition: avcodec.h:2111
speex_default_user_handler
static int speex_default_user_handler(GetBitContext *gb, void *state, void *data)
Definition: speexdec.c:225
av_int2float
static av_always_inline float av_int2float(uint32_t i)
Reinterpret a 32-bit integer as a float.
Definition: intfloat.h:40
state
static struct @377 state
SpeexSubmode::ltp_unquant
ltp_unquant_func ltp_unquant
Long-term predictor (pitch) un-quantizer.
Definition: speexdec.c:159
GetBitContext
Definition: get_bits.h:108
innovation_quant_func
void(* innovation_quant_func)(float *, float *, float *, float *, const void *, int, int, float *, float *, GetBitContext *, char *, int, int)
Innovation quantization function.
Definition: speexdec.c:138
DecoderState
Definition: speexdec.c:179
AVFrame::ch_layout
AVChannelLayout ch_layout
Channel layout of the audio data.
Definition: frame.h:802
split_cb_nb_lbr
static const SplitCodebookParams split_cb_nb_lbr
Definition: speexdec.c:111
DecoderState::nb_subframes
int nb_subframes
Number of high-band sub-frames.
Definition: speexdec.c:188
fabsf
static __device__ float fabsf(float a)
Definition: cuda_runtime.h:181
wb_submode3
static const SpeexSubmode wb_submode3
Definition: speexdec.c:512
SpeexContext::bitrate
int32_t bitrate
Bit-rate used.
Definition: speexdec.c:248
e_ratio_quant
static const float e_ratio_quant[4]
Definition: speexdata.h:766
ff_speex_decoder
const FFCodec ff_speex_decoder
Definition: speexdec.c:1588
a1
#define a1
Definition: regdef.h:47
split_cb_nb_ulbr
static const SplitCodebookParams split_cb_nb_ulbr
Definition: speexdec.c:109
NB_PITCH_START
#define NB_PITCH_START
Definition: speexdec.c:76
avassert.h
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
init_get_bits8
static int init_get_bits8(GetBitContext *s, const uint8_t *buffer, int byte_size)
Initialize GetBitContext.
Definition: get_bits.h:545
StereoState::balance
float balance
Left/right balance info.
Definition: speexdec.c:233
lsp_interpolate
static void lsp_interpolate(const float *old_lsp, const float *new_lsp, float *lsp, int len, int subframe, int nb_subframes, float margin)
Definition: speexdec.c:806
float
float
Definition: af_crystalizer.c:121
AVCodecContext::extradata_size
int extradata_size
Definition: avcodec.h:547
FF_CODEC_DECODE_CB
#define FF_CODEC_DECODE_CB(func)
Definition: codec_internal.h:306
s
#define s(width, name)
Definition: cbs_vp9.c:198
split_cb_sb
static const SplitCodebookParams split_cb_sb
Definition: speexdec.c:114
nb_decode
static int nb_decode(AVCodecContext *, void *, GetBitContext *, float *)
Definition: speexdec.c:867
g
const char * g
Definition: vf_curves.c:127
frame_size
int frame_size
Definition: mxfenc.c:2422
speex_std_stereo
static int speex_std_stereo(GetBitContext *gb, void *state, void *data)
Definition: speexdec.c:619
AVMEDIA_TYPE_AUDIO
@ AVMEDIA_TYPE_AUDIO
Definition: avutil.h:202
AV_CHANNEL_ORDER_UNSPEC
@ AV_CHANNEL_ORDER_UNSPEC
Only the channel count is specified, without any further information about the channel order.
Definition: channel_layout.h:112
gain_cdbk_lbr
static const int8_t gain_cdbk_lbr[128]
Definition: speexdata.h:406
fminf
float fminf(float, float)
NB_SUBFRAME_SIZE
#define NB_SUBFRAME_SIZE
Definition: speexdec.c:74
av_assert0
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:40
nb_submode7
static const SpeexSubmode nb_submode7
Definition: speexdec.c:491
decode.h
speex_rand
static float speex_rand(float std, uint32_t *seed)
Definition: speexdec.c:298
get_bits.h
cdbk_nb_low2
static const int8_t cdbk_nb_low2[320]
Definition: speexdata.h:537
speex_modes
static const SpeexMode speex_modes[SPEEX_NB_MODES]
Definition: speexdec.c:525
DecoderState::encode_submode
int encode_submode
Definition: speexdec.c:198
NB_FRAME_SIZE
#define NB_FRAME_SIZE
Definition: speexdec.c:69
StereoState
Definition: speexdec.c:232
DecoderState::modeID
int modeID
ID of the decoder mode.
Definition: speexdec.c:181
CODEC_LONG_NAME
#define CODEC_LONG_NAME(str)
Definition: codec_internal.h:272
frame
static AVFrame * frame
Definition: demux_decode.c:54
SUBMODE
#define SUBMODE(x)
Definition: speexdec.c:349
nb_submode6
static const SpeexSubmode nb_submode6
Definition: speexdec.c:485
SpeexSubmode::innovation_unquant
innovation_unquant_func innovation_unquant
Innovation un-quantization.
Definition: speexdec.c:162
FFABS
#define FFABS(a)
Absolute value, Note, INT_MIN / INT64_MIN result in undefined behavior as they are not representable ...
Definition: common.h:72
DecoderState::mem_sp
float mem_sp[NB_ORDER]
Filter memory for synthesis signal.
Definition: speexdec.c:217
SPEEX_MEMSET
#define SPEEX_MEMSET(dst, c, n)
Definition: speexdec.c:81
lsp_to_lpc
static void lsp_to_lpc(const float *freq, float *ak, int lpcrdr)
Definition: speexdec.c:823
speex_decode_frame
static int speex_decode_frame(AVCodecContext *avctx, AVFrame *frame, int *got_frame_ptr, AVPacket *avpkt)
Definition: speexdec.c:1539
nb_submode1
static const SpeexSubmode nb_submode1
Definition: speexdec.c:455
AVClass
Describe the class of an AVClass context structure.
Definition: log.h:66
NULL
#define NULL
Definition: coverity.c:32
SpeexContext::frames_per_packet
int32_t frames_per_packet
Number of frames stored per Ogg packet.
Definition: speexdec.c:251
NB_SUBMODES
#define NB_SUBMODES
Definition: speexdec.c:70
AVERROR_PATCHWELCOME
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
Definition: error.h:64
DecoderState::lpc_size
int lpc_size
Order of high-band LPC analysis.
Definition: speexdec.c:189
isnan
#define isnan(x)
Definition: libm.h:340
SpeexMode::default_submode
int default_submode
Default sub-mode to use when decoding.
Definition: speexdec.c:176
AVCodecContext::bit_rate
int64_t bit_rate
the average bitrate
Definition: avcodec.h:495
get_bits1
static unsigned int get_bits1(GetBitContext *s)
Definition: get_bits.h:388
DecoderState::exc_rms
float exc_rms[NB_NB_SUBFRAMES]
RMS of excitation per subframe.
Definition: speexdec.c:221
split_cb_nb
static const SplitCodebookParams split_cb_nb
Definition: speexdec.c:113
sqrtf
static __device__ float sqrtf(float a)
Definition: cuda_runtime.h:184
SpeexContext::bitstream_version
int32_t bitstream_version
Version ID of the bit-stream.
Definition: speexdec.c:246
LtpParams::gain_bits
int gain_bits
Definition: speexdec.c:92
exc_10_32_table
static const int8_t exc_10_32_table[320]
Definition: speexdata.h:367
av_clipf
av_clipf
Definition: af_crystalizer.c:121
SpeexContext::extra_headers
int32_t extra_headers
Number of additional headers after the comments.
Definition: speexdec.c:252
ltp_params_nb
static const LtpParam ltp_params_nb
Definition: speexdec.c:99
exp
int8_t exp
Definition: eval.c:74
seed
static unsigned int seed
Definition: videogen.c:78
wb_skip_table
static const uint16_t wb_skip_table[8]
Definition: speexdata.h:765
DecoderState::voc_offset
int voc_offset
Definition: speexdec.c:207
float_dsp.h
SpeexSubmode::comb_gain
float comb_gain
Gain of enhancer comb filter.
Definition: speexdec.c:165
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
f
f
Definition: af_crystalizer.c:121
ff_get_buffer
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
Definition: decode.c:1618
AV_CODEC_CAP_DR1
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
Definition: codec.h:52
AVPacket::size
int size
Definition: packet.h:523
scale
static void scale(int *out, const int *in, const int w, const int h, const int shift)
Definition: vvc_intra.c:292
LtpParams::gain_cdbk
const int8_t * gain_cdbk
Definition: speexdec.c:91
lsp_unquant_nb
static void lsp_unquant_nb(float *lsp, int order, GetBitContext *gb)
Definition: speexdec.c:410
exc_5_64_table
static const int8_t exc_5_64_table[320]
Definition: speexdata.h:232
codec_internal.h
SpeexContext::fdsp
AVFloatDSPContext * fdsp
Definition: speexdec.c:259
ltp_params_lbr
static const LtpParam ltp_params_lbr
Definition: speexdec.c:97
ltp_params_med
static const LtpParam ltp_params_med
Definition: speexdec.c:98
sanitize_values
static void sanitize_values(float *vec, float min_val, float max_val, int len)
Definition: speexdec.c:656
SpeexMode::folding_gain
float folding_gain
Folding gain.
Definition: speexdec.c:174
for
for(k=2;k<=8;++k)
Definition: h264pred_template.c:425
ltp_unquant_func
void(* ltp_unquant_func)(float *, float *, int, int, float, const void *, int, int *, float *, GetBitContext *, int, int, float, int)
Long-term un-quantize.
Definition: speexdec.c:132
sp
#define sp
Definition: regdef.h:63
NB_PITCH_END
#define NB_PITCH_END
Definition: speexdec.c:77
fmaxf
float fmaxf(float, float)
AVCodecContext::sample_fmt
enum AVSampleFormat sample_fmt
audio sample format
Definition: avcodec.h:1084
DecoderState::submodes
const SpeexSubmode *const * submodes
Sub-mode data.
Definition: speexdec.c:199
LSP_LINEAR
#define LSP_LINEAR(i)
Definition: speexdec.c:84
signal_mul
static void signal_mul(const float *x, float *y, float scale, int len)
Definition: speexdec.c:666
DecoderState::old_qlsp
float old_qlsp[NB_ORDER]
Quantized LSPs for previous frame.
Definition: speexdec.c:215
DecoderState::frame_size
int frame_size
Length of high-band frames.
Definition: speexdec.c:186
SpeexContext
Definition: speexdec.c:239
AVFloatDSPContext
Definition: float_dsp.h:24
noise_codebook_unquant
static void noise_codebook_unquant(float *exc, const void *par, int nsf, GetBitContext *gb, uint32_t *seed)
Definition: speexdec.c:312
pitch_unquant_3tap
static void pitch_unquant_3tap(float *exc, float *exc_out, int start, int end, float pitch_coef, const void *par, int nsf, int *pitch_val, float *gain_val, GetBitContext *gb, int count_lost, int subframe_offset, float last_pitch_gain, int cdbk_offset)
Definition: speexdec.c:354
gain_cdbk_nb
static const int8_t gain_cdbk_nb[512]
Definition: speexdata.h:257
a
The reader does not expect b to be semantically here and if the code is changed by maybe adding a a division or other the signedness will almost certainly be mistaken To avoid this confusion a new type was SUINT is the C unsigned type but it holds a signed int to use the same example SUINT a
Definition: undefined.txt:41
SpeexMode::frame_size
int frame_size
Size of frames used for decoding.
Definition: speexdec.c:171
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
cdbk_nb_high2
static const int8_t cdbk_nb_high2[320]
Definition: speexdata.h:587
N
#define N
Definition: af_mcompand.c:53
fact
static double fact(double i)
Definition: af_aiir.c:943
a0
#define a0
Definition: regdef.h:46
SPEEX_COPY
#define SPEEX_COPY(dst, src, n)
Definition: speexdec.c:82
M_PI
#define M_PI
Definition: mathematics.h:67
DecoderState::subframe_size
int subframe_size
Length of high-band sub-frames.
Definition: speexdec.c:187
SpeexSubmode::innovation_params
const void * innovation_params
Innovation quantization parameters.
Definition: speexdec.c:163
ran
static uint32_t ran(void)
Definition: trasher.c:28
exc_20_32_table
static const int8_t exc_20_32_table[640]
Definition: speexdata.h:417
shift_filt
static const float shift_filt[3][7]
Definition: speexdata.h:719
multicomb
static void multicomb(const float *exc, float *new_exc, float *ak, int p, int nsf, int pitch, int max_pitch, float comb_gain)
Definition: speexdec.c:739
SplitCodebookParams::shape_cb
const signed char * shape_cb
Definition: speexdec.c:104
AVFrame::nb_samples
int nb_samples
number of audio samples (per channel) described by this frame
Definition: frame.h:420
lsp_quant_func
void(* lsp_quant_func)(float *, float *, int, GetBitContext *)
Quantizes LSPs.
Definition: speexdec.c:119
lsp_unquant_lbr
static void lsp_unquant_lbr(float *lsp, int order, GetBitContext *gb)
Definition: speexdec.c:262
split_cb_nb_med
static const SplitCodebookParams split_cb_nb_med
Definition: speexdec.c:112
forced_pitch_unquant
static void forced_pitch_unquant(float *exc, float *exc_out, int start, int end, float pitch_coef, const void *par, int nsf, int *pitch_val, float *gain_val, GetBitContext *gb, int count_lost, int subframe_offset, float last_pitch_gain, int cdbk_offset)
Definition: speexdec.c:282
nb_submode5
static const SpeexSubmode nb_submode5
Definition: speexdec.c:479
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:255
AVCodecContext::extradata
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
Definition: avcodec.h:546
show_bits
static unsigned int show_bits(GetBitContext *s, int n)
Show 1-25 bits.
Definition: get_bits.h:371
DecoderState::interp_qlpc
float interp_qlpc[NB_ORDER]
Interpolated quantized LPCs.
Definition: speexdec.c:216
AVFrame::extended_data
uint8_t ** extended_data
pointers to the data planes/channels.
Definition: frame.h:401
lsp_unquant_func
void(* lsp_unquant_func)(float *, int, GetBitContext *)
Decodes quantized LSPs.
Definition: speexdec.c:122
iir_mem
static void iir_mem(const float *x, const float *den, float *y, int N, int ord, float *mem)
Definition: speexdec.c:586
DecoderState::full_frame_size
int full_frame_size
Length of full-band frames.
Definition: speexdec.c:183
FFMIN
#define FFMIN(a, b)
Definition: macros.h:49
AVCodec::name
const char * name
Name of the codec implementation.
Definition: codec.h:194
DecoderState::voc_m2
float voc_m2
Definition: speexdec.c:205
len
int len
Definition: vorbis_enc_data.h:426
inner_prod
static float inner_prod(const float *x, const float *y, int len)
Definition: speexdec.c:672
cdbk_nb
static const int8_t cdbk_nb[640]
Definition: speexdata.h:463
avcodec.h
decoder_init
static int decoder_init(SpeexContext *s, DecoderState *st, const SpeexMode *mode)
Definition: speexdec.c:1364
SPEEX_INBAND_STEREO
#define SPEEX_INBAND_STEREO
Definition: speexdec.c:65
SpeexContext::gb
GetBitContext gb
Definition: speexdec.c:241
parse_speex_extradata
static int parse_speex_extradata(AVCodecContext *avctx, const uint8_t *extradata, int extradata_size)
Definition: speexdec.c:1397
ret
ret
Definition: filter_design.txt:187
SplitCodebookParams::subvect_size
int subvect_size
Definition: speexdec.c:102
SpeexSubmode::lsp_unquant
lsp_unquant_func lsp_unquant
LSP unquantization function.
Definition: speexdec.c:157
split_cb_nb_vlbr
static const SplitCodebookParams split_cb_nb_vlbr
Definition: speexdec.c:110
SpeexMode::decode
int(* decode)(AVCodecContext *avctx, void *dec, GetBitContext *gb, float *out)
Definition: speexdec.c:170
av_strnstr
char * av_strnstr(const char *haystack, const char *needle, size_t hay_length)
Locate the first occurrence of the string needle in the string haystack where not more than hay_lengt...
Definition: avstring.c:71
StereoState::smooth_right
float smooth_right
Smoothed right channel gain.
Definition: speexdec.c:236
id
enum AVCodecID id
Definition: dts2pts.c:364
gc_quant_bound
static const float gc_quant_bound[16]
Definition: speexdata.h:760
DecoderState::last_pitch
int last_pitch
Pitch of last correctly decoded frame.
Definition: speexdec.c:194
StereoState::smooth_left
float smooth_left
Smoothed left channel gain.
Definition: speexdec.c:235
AVCodecContext
main external API structure.
Definition: avcodec.h:445
c2
static const uint64_t c2
Definition: murmur3.c:53
SpeexMode::submodes
const SpeexSubmode * submodes[NB_SUBMODES]
Sub-mode data for the mode.
Definition: speexdec.c:175
DecoderState::last_ol_gain
float last_ol_gain
Open-loop gain for previous frame.
Definition: speexdec.c:190
cdbk_nb_low1
static const int8_t cdbk_nb_low1[320]
Definition: speexdata.h:512
mode
mode
Definition: ebur128.h:83
DecoderState::voc_mean
float voc_mean
Definition: speexdec.c:206
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:662
NB_NB_SUBFRAMES
#define NB_NB_SUBFRAMES
Definition: speexdec.c:75
DecoderState::is_wideband
int is_wideband
If wideband is present.
Definition: speexdec.c:184
speex_decode_close
static av_cold int speex_decode_close(AVCodecContext *avctx)
Definition: speexdec.c:1581
SpeexContext::stereo
StereoState stereo
Definition: speexdec.c:256
DecoderState::g0_mem
float g0_mem[QMF_ORDER]
Definition: speexdec.c:218
get_bitsz
static av_always_inline int get_bitsz(GetBitContext *s, int n)
Read 0-25 bits.
Definition: get_bits.h:351
high_lsp_cdbk2
static const int8_t high_lsp_cdbk2[512]
Definition: speexdata.h:99
SpeexContext::mode
int32_t mode
Mode used (0 for narrowband, 1 for wideband)
Definition: speexdec.c:245
M_SQRT2
#define M_SQRT2
Definition: mathematics.h:109
SpeexContext::st
DecoderState st[SPEEX_NB_MODES]
Definition: speexdec.c:257
nb_submode2
static const SpeexSubmode nb_submode2
Definition: speexdec.c:461
ltp_params_vlbr
static const LtpParam ltp_params_vlbr
Definition: speexdec.c:96
SpeexSubmode::forced_pitch_gain
int forced_pitch_gain
Use the same (forced) pitch gain for all sub-frames.
Definition: speexdec.c:151
AVCodecContext::codec_tag
unsigned int codec_tag
fourcc (LSB first, so "ABCD" -> ('D'<<24) + ('C'<<16) + ('B'<<8) + 'A').
Definition: avcodec.h:470
wb_submode1
static const SpeexSubmode wb_submode1
Definition: speexdec.c:502
FFALIGN
#define FFALIGN(x, a)
Definition: macros.h:78
highpass
static void highpass(const float *x, float *y, int len, float *mem, int wide)
Definition: speexdec.c:599
NB_ORDER
#define NB_ORDER
Definition: speexdec.c:68
AVPacket
This structure stores compressed data.
Definition: packet.h:499
AVCodecContext::priv_data
void * priv_data
Definition: avcodec.h:472
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:34
avpriv_float_dsp_alloc
av_cold AVFloatDSPContext * avpriv_float_dsp_alloc(int bit_exact)
Allocate a float DSP context.
Definition: float_dsp.c:135
DecoderState::g1_mem
float g1_mem[QMF_ORDER]
Definition: speexdec.c:219
speex_decode_stereo
static void speex_decode_stereo(float *data, int frame_size, StereoState *stereo)
Definition: speexdec.c:1519
int32_t
int32_t
Definition: audioconvert.c:56
bytestream.h
innovation_unquant_func
void(* innovation_unquant_func)(float *, const void *, int, GetBitContext *, uint32_t *)
Innovation unquantization function.
Definition: speexdec.c:144
SpeexSubmode::lbr_pitch
int lbr_pitch
Set to -1 for "normal" modes, otherwise encode pitch using a global pitch and allowing a +- lbr_pitch...
Definition: speexdec.c:148
speex_decode_init
static av_cold int speex_decode_init(AVCodecContext *avctx)
Definition: speexdec.c:1439
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
SpeexContext::frame_size
int32_t frame_size
Size of frames.
Definition: speexdec.c:249
lsp_unquant_high
static void lsp_unquant_high(float *lsp, int order, GetBitContext *gb)
Definition: speexdec.c:438
AVERROR_INVALIDDATA
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:61
exc_10_16_table
static const int8_t exc_10_16_table[160]
Definition: speexdata.h:392
qmf_synth
static void qmf_synth(const float *x1, const float *x2, const float *a, float *y, int N, int M, float *mem1, float *mem2)
Definition: speexdec.c:1161
exc_gain_quant_scal3
static const float exc_gain_quant_scal3[8]
Definition: speexdata.h:774
MKTAG
#define MKTAG(a, b, c, d)
Definition: macros.h:55
DecoderState::last_pitch_gain
float last_pitch_gain
Pitch gain of last correctly decoded frame.
Definition: speexdec.c:195
avstring.h
split_cb_high_lbr
static const SplitCodebookParams split_cb_high_lbr
Definition: speexdec.c:116
SplitCodebookParams
Definition: speexdec.c:101
SplitCodebookParams::have_sign
int have_sign
Definition: speexdec.c:106
int
int
Definition: ffmpeg_filter.c:424
DecoderState::pi_gain
float pi_gain[NB_NB_SUBFRAMES]
Gain of LPC filter at theta=pi (fe/2)
Definition: speexdec.c:220
SpeexContext::rate
int32_t rate
Sampling rate used.
Definition: speexdec.c:244
bw_lpc
static void bw_lpc(float gamma, const float *lpc_in, float *lpc_out, int order)
Definition: speexdec.c:575
interp_pitch
static int interp_pitch(const float *exc, float *interp, int pitch, int len)
Definition: speexdec.c:692
AV_SAMPLE_FMT_FLT
@ AV_SAMPLE_FMT_FLT
float
Definition: samplefmt.h:60
compute_rms
static float compute_rms(const float *x, int len)
Definition: speexdec.c:564
NB_DEC_BUFFER
#define NB_DEC_BUFFER
Definition: speexdec.c:79
sb_decode
static int sb_decode(AVCodecContext *, void *, GetBitContext *, float *)
Definition: speexdec.c:1218
DecoderState::innov_save
float * innov_save
If non-NULL, innovation is copied here.
Definition: speexdec.c:191
SplitCodebookParams::nb_subvect
int nb_subvect
Definition: speexdec.c:103
StereoState::e_ratio
float e_ratio
Ratio of energies: E(left+right)/[E(left)+E(right)]
Definition: speexdec.c:234
SpeexMode
Definition: speexdec.c:168
split_cb_shape_sign_unquant
static void split_cb_shape_sign_unquant(float *exc, const void *par, int nsf, GetBitContext *gb, uint32_t *seed)
Definition: speexdec.c:319
high_lsp_cdbk
static const int8_t high_lsp_cdbk[512]
Definition: speexdata.h:59
SPEEX_NB_MODES
#define SPEEX_NB_MODES
Definition: speexdec.c:64