Go to the documentation of this file.
   64 #define SPEEX_NB_MODES 3 
   65 #define SPEEX_INBAND_STEREO 9 
   69 #define NB_FRAME_SIZE 160 
   71 #define NB_SUBMODE_BITS 4 
   72 #define SB_SUBMODE_BITS 3 
   74 #define NB_SUBFRAME_SIZE 40 
   75 #define NB_NB_SUBFRAMES 4 
   76 #define NB_PITCH_START 17 
   77 #define NB_PITCH_END 144 
   79 #define NB_DEC_BUFFER (NB_FRAME_SIZE + 2 * NB_PITCH_END + NB_SUBFRAME_SIZE + 12) 
   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)))) 
   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)) 
  126     float *, 
float *, 
float *,
 
  139     float *, 
float *, 
const void *,
 
  140     int, 
int, 
float *, 
float *,
 
  227     const int req_size = 
get_bits(gb, 4);
 
  266     for (
int i = 0; 
i < order; 
i++)
 
  270     for (
int i = 0; 
i < 10; 
i++)
 
  274     for (
int i = 0; 
i < 5; 
i++)
 
  278     for (
int i = 0; 
i < 5; 
i++)
 
  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)
 
  288     pitch_coef = 
fminf(pitch_coef, .99
f);
 
  289     for (
int i = 0; 
i < nsf; 
i++) {
 
  290         exc_out[
i] = exc[
i - start] * pitch_coef;
 
  293     pitch_val[0] = start;
 
  294     gain_val[0] = gain_val[2] = 0.f;
 
  295     gain_val[1] = pitch_coef;
 
  300     const uint32_t jflone = 0x3f800000;
 
  301     const uint32_t jflmsk = 0x007fffff;
 
  304     seed[0] = 1664525 * 
seed[0] + 1013904223;
 
  305     ran = jflone | (jflmsk & 
seed[0]);
 
  315     for (
int i = 0; 
i < nsf; 
i++)
 
  322     int subvect_size, nb_subvect, have_sign, shape_bits;
 
  324     const signed char *shape_cb;
 
  325     int signs[10], ind[10];
 
  336     for (
int i = 0; 
i < nb_subvect; 
i++) {
 
  341     for (
int i = 0; 
i < nb_subvect; 
i++) {
 
  342         const float s = signs[
i] ? -1.f : 1.f;
 
  344         for (
int j = 0; j < subvect_size; j++)
 
  345             exc[subvect_size * 
i + j] += 
s * 0.03125
f * shape_cb[ind[
i] * subvect_size + j];
 
  349 #define SUBMODE(x) st->submodes[st->submodeID]->x 
  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])) 
  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)
 
  358     int pitch, gain_index, gain_cdbk_size;
 
  359     const int8_t *gain_cdbk;
 
  360     const LtpParam *params;
 
  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;
 
  367     pitch = 
get_bitsz(gb, params->pitch_bits);
 
  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;
 
  374     if (count_lost && pitch > subframe_offset) {
 
  375         float tmp = count_lost < 4 ? last_pitch_gain : 0.5f * last_pitch_gain;
 
  381         if (gain_sum > 
tmp && gain_sum > 0.
f) {
 
  383             for (
int i = 0; 
i < 3; 
i++)
 
  388     pitch_val[0] = pitch;
 
  389     gain_val[0] = gain[0];
 
  390     gain_val[1] = gain[1];
 
  391     gain_val[2] = gain[2];
 
  394     for (
int i = 0; 
i < 3; 
i++) {
 
  396         int pp = pitch + 1 - 
i;
 
  400         for (
int j = 0; j < tmp1; j++)
 
  401             exc_out[j] += gain[2 - 
i] * exc[j - pp];
 
  403         if (tmp3 > pp + pitch)
 
  405         for (
int j = tmp1; j < tmp3; j++)
 
  406             exc_out[j] += gain[2 - 
i] * exc[j - pp - pitch];
 
  414     for (
int i = 0; 
i < order; 
i++)
 
  418     for (
int i = 0; 
i < 10; 
i++)
 
  422     for (
int i = 0; 
i < 5; 
i++)
 
  426     for (
int i = 0; 
i < 5; 
i++)
 
  430     for (
int i = 0; 
i < 5; 
i++)
 
  434     for (
int i = 0; 
i < 5; 
i++)
 
  442     for (
int i = 0; 
i < order; 
i++)
 
  446     for (
int i = 0; 
i < order; 
i++)
 
  450     for (
int i = 0; 
i < order; 
i++)
 
  536         .default_submode = 5,
 
  544         .folding_gain = 0.9f,
 
  548         .default_submode = 3,
 
  556         .folding_gain = 0.7f,
 
  560         .default_submode = 1,
 
  568     for (
int i = 0; 
i < 
len; 
i++)
 
  575 static void bw_lpc(
float gamma, 
const float *lpc_in,
 
  576                    float *lpc_out, 
int order)
 
  580     for (
int i = 0; 
i < order; 
i++) {
 
  581         lpc_out[
i] = 
tmp * lpc_in[
i];
 
  586 static void iir_mem(
const float *x, 
const float *den,
 
  587     float *y, 
int N, 
int ord, 
float *mem)
 
  589     for (
int i = 0; 
i < 
N; 
i++) {
 
  590         float yi = x[
i] + mem[0];
 
  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;
 
  599 static void highpass(
const float *x, 
float *y, 
int len, 
float *mem, 
int wide)
 
  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;
 
  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;
 
  615 #define median3(a, b, c)                                     \ 
  616     ((a) < (b) ? ((b) < (c) ? (b) : ((a) < (c) ? (c) : (a))) \ 
  617                : ((c) < (b) ? (b) : ((c) < (a) ? (c) : (a)))) 
  658     for (
int i = 0; 
i < 
len; 
i++) {
 
  659         if (!isnormal(vec[
i]) || 
fabsf(vec[
i]) < 1e-8
f)
 
  668     for (
int i = 0; 
i < 
len; 
i++)
 
  676     for (
int i = 0; 
i < 
len; 
i += 8) {
 
  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];
 
  694     float corr[4][7], maxcorr;
 
  697     for (
int i = 0; 
i < 7; 
i++)
 
  699     for (
int i = 0; 
i < 3; 
i++) {
 
  700         for (
int j = 0; j < 7; j++) {
 
  710             for (
int k = i1; k < i2; k++)
 
  712             corr[
i + 1][j] = 
tmp;
 
  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];
 
  726     for (
int i = 0; 
i < 
len; 
i++) {
 
  729             for (
int k = 0; k < 7; k++)
 
  730                 tmp += exc[
i - (pitch - maxj + 3) + k - 3] * 
shift_filt[maxi - 1][k];
 
  732             tmp = exc[
i - (pitch - maxj + 3)];
 
  736     return pitch - maxj + 3;
 
  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)
 
  742     float old_ener, new_ener;
 
  743     float iexc0_mag, iexc1_mag, exc_mag;
 
  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;
 
  752     if (corr_pitch > max_pitch)
 
  762     if (corr0 > iexc0_mag * exc_mag)
 
  765         pgain1 = (corr0 / exc_mag) / iexc0_mag;
 
  766     if (corr1 > iexc1_mag * exc_mag)
 
  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);
 
  778     g1 = 1.f - 
c2 * pgain1 * pgain1;
 
  779     g2 = 1.f - 
c2 * pgain2 * pgain2;
 
  785     if (corr_pitch > max_pitch) {
 
  786         gain0 = .7f * g1 * gg1;
 
  787         gain1 = .3f * g2 * gg2;
 
  789         gain0 = .6f * g1 * gg1;
 
  790         gain1 = .6f * g2 * gg2;
 
  792     for (
int i = 0; 
i < nsf; 
i++)
 
  793         new_exc[
i] = exc[
i] + (gain0 * iexc[
i]) + (gain1 * iexc[
i + nsf]);
 
  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;
 
  802     for (
int i = 0; 
i < nsf; 
i++)
 
  807                             float *lsp, 
int len, 
int subframe,
 
  808                             int nb_subframes, 
float margin)
 
  810     const float tmp = (1.f + subframe) / nb_subframes;
 
  812     for (
int i = 0; 
i < 
len; 
i++) {
 
  813         lsp[
i] = (1.f - 
tmp) * old_lsp[
i] + 
tmp * new_lsp[
i];
 
  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);
 
  823 static void lsp_to_lpc(
const float *freq, 
float *ak, 
int lpcrdr)
 
  825     float xout1, xout2, xin1, xin2;
 
  829     const int m = lpcrdr >> 1;
 
  835     for (
int i = 0; 
i < lpcrdr; 
i++)
 
  836         x_freq[
i] = -
cosf(freq[
i]);
 
  842     for (
int j = 0; j <= lpcrdr; j++) {
 
  844         for (
int i = 0; 
i < m; 
i++, i2 += 2) {
 
  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];
 
  855         xout1 = xin1 + n0[4];
 
  856         xout2 = xin2 - n0[5];
 
  858             ak[j - 1] = (xout1 + xout2) * 0.5
f;
 
  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;
 
  879     float pitch_gain[3] = { 0 };
 
  889                 int submode, advance;
 
  920             } 
else if (m == 14)  {
 
  924             } 
else if (m == 13)  {
 
  942         float innov_gain = 0.f;
 
  961         float fact, lsp_dist = 0;
 
  978     if (
SUBMODE(forced_pitch_gain))
 
  979         ol_pitch_coef = 0.066667f * 
get_bits(gb, 4);
 
  991         float *exc, *innov_save = 
NULL, 
tmp, ener;
 
  992         int pit_min, pit_max, 
offset, q_energy;
 
 1004         if (
SUBMODE(lbr_pitch) != -1) {
 
 1005             int margin = 
SUBMODE(lbr_pitch);
 
 1008                 pit_min = ol_pitch - margin + 1;
 
 1010                 pit_max = ol_pitch + margin;
 
 1013                 pit_min = pit_max = ol_pitch;
 
 1020         SUBMODE(ltp_unquant)(exc, exc32, pit_min, pit_max, ol_pitch_coef, 
SUBMODE(LtpParam),
 
 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 > .6
f * 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             ((.67
f * 
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))) {
 
 1042             if (
tmp > best_pitch_gain)
 
 1043                 best_pitch_gain = 
tmp;
 
 1046         memset(innov, 0, 
sizeof(innov));
 
 1049         if (
SUBMODE(have_subframe_gain) == 3) {
 
 1052         } 
else if (
SUBMODE(have_subframe_gain) == 1) {
 
 1067         if (
SUBMODE(double_codebook)) {
 
 1073                 innov[
i] += innov2[
i];
 
 1076             exc[
i] = exc32[
i] + innov[
i];
 
 1078             memcpy(innov_save, innov, 
sizeof(innov));
 
 1082             float g = ol_pitch_coef;
 
 1095                 float exci = exc[
i];
 
 1096                 exc[
i] = (.7f * exc[
i] + .3f * st->
voc_m1) + ((1.
f - .85
f * 
g) * innov[
i]) - .15
f * 
g * st->
voc_m2;
 
 1118         float exc_ener, gain;
 
 1122         gain = 
fminf(ol_gain / (exc_ener + 1.
f), 2.
f);
 
 1137             pi_g += ak[
i + 1] - ak[
i];
 
 1161 static void qmf_synth(
const float *x1, 
const float *x2, 
const float *
a, 
float *y, 
int N, 
int M, 
float *mem1, 
float *mem2)
 
 1163     const int M2 = 
M >> 1, 
N2 = 
N >> 1;
 
 1164     float xx1[352], xx2[352];
 
 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];
 
 1175     for (
int i = 0; 
i < 
N2; 
i += 2) {
 
 1176         float y0, y1, y2, y3;
 
 1179         y0 = y1 = y2 = y3 = 0.f;
 
 1183         for (
int j = 0; j < M2; j += 2) {
 
 1189             x11 = xx1[
N2-1+j-
i];
 
 1190             x21 = xx2[
N2-1+j-
i];
 
 1192             y0 += 
a0 * (x11-x21);
 
 1193             y1 += 
a1 * (x11+x21);
 
 1194             y2 += 
a0 * (x10-x20);
 
 1195             y3 += 
a1 * (x10+x20);
 
 1201             y0 += 
a0 * (x10-x20);
 
 1202             y1 += 
a1 * (x10+x20);
 
 1203             y2 += 
a0 * (x11-x21);
 
 1204             y3 += 
a1 * (x11+x21);
 
 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;
 
 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];
 
 1227     float *low_innov_alias;
 
 1236         s->st[st->
modeID - 1].innov_save = low_innov_alias;
 
 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));
 
 1281         float filter_ratio, el, rl, rh;
 
 1282         float *innov_save = 
NULL, *
sp;
 
 1303             rh += ak[
i + 1] - ak[
i];
 
 1307         rl = low_pi_gain[sub];
 
 1308         filter_ratio = (rl + .01f) / (rh + .01
f);
 
 1311         if (!
SUBMODE(innovation_unquant)) {
 
 1313             const float g = 
expf(.125
f * (x - 10)) / filter_ratio;
 
 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;
 
 1322             el = low_exc_rms[sub];
 
 1328             scale = (gc * el) / filter_ratio;
 
 1334             if (
SUBMODE(double_codebook)) {
 
 1341                     exc[
i] += innov2[
i];
 
 1347                 innov_save[2 * 
i] = exc[
i];
 
 1351         memcpy(st->
exc_buf, exc, 
sizeof(exc));
 
 1398     const uint8_t *extradata, 
int extradata_size)
 
 1401     const uint8_t *buf = 
av_strnstr(extradata, 
"Speex   ", extradata_size);
 
 1408     s->version_id = bytestream_get_le32(&buf);
 
 1410     s->rate = bytestream_get_le32(&buf);
 
 1413     s->mode = bytestream_get_le32(&buf);
 
 1416     s->bitstream_version = bytestream_get_le32(&buf);
 
 1417     if (
s->bitstream_version != 4)
 
 1419     s->nb_channels = bytestream_get_le32(&buf);
 
 1420     if (
s->nb_channels <= 0 || 
s->nb_channels > 2)
 
 1422     s->bitrate = bytestream_get_le32(&buf);
 
 1423     s->frame_size = bytestream_get_le32(&buf);
 
 1425         s->frame_size >     INT32_MAX >> (
s->mode > 0))
 
 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)
 
 1434     s->extra_headers = bytestream_get_le32(&buf);
 
 1458         if (
s->nb_channels <= 0 || 
s->nb_channels > 2)
 
 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;
 
 1468         s->frames_per_packet = 64;
 
 1486         s->pkt_size = ((
const uint8_t[]){ 5, 10, 15, 20, 20, 28, 28, 38, 38, 46, 62 })[
quality];
 
 1493         s->frames_per_packet = 1;
 
 1505     for (
int m = 0; m <= 
s->mode; m++) {
 
 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;
 
 1521     float balance, e_left, e_right, e_ratio;
 
 1527     e_right = 1.f / 
sqrtf(e_ratio * (1.
f + balance));
 
 1528     e_left = 
sqrtf(balance) * e_right;
 
 1540                               int *got_frame_ptr, 
AVPacket *avpkt)
 
 1543     int frames_per_packet = 
s->frames_per_packet;
 
 1544     const float scale = 1.f / 32768.f;
 
 1545     int buf_size = avpkt->
size;
 
 1549     if (
s->pkt_size && avpkt->
size == 62)
 
 1550         buf_size = 
s->pkt_size;
 
 1559     for (
int i = 0; 
i < frames_per_packet; 
i++) {
 
 1567             frames_per_packet = 
i + 1;
 
  
int submodeID
Activated sub-mode.
 
static const SplitCodebookParams split_cb_high
 
static const SpeexSubmode nb_submode4
 
static void skip_bits_long(GetBitContext *s, int n)
Skips the specified number of bits.
 
uint32_t seed
Seed used for random number generation.
 
static const float h0[64]
 
int have_subframe_gain
Number of bits to use as sub-frame innovation gain.
 
#define FF_CODEC_CAP_INIT_CLEANUP
The codec allows calling the close function for deallocation even if the init function returned a fai...
 
static unsigned int show_bits1(GetBitContext *s)
 
static int get_bits_left(GetBitContext *gb)
 
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
 
static const SpeexSubmode wb_submode2
 
static const int8_t hexc_10_32_table[320]
 
static const SpeexSubmode nb_submode3
 
int count_lost
Was the last frame lost?
 
static const float exc_gain_quant_scal1[2]
 
int32_t vbr
1 for a VBR decoding, 0 otherwise
 
int sample_rate
samples per second
 
float exc_buf[NB_DEC_BUFFER]
Excitation buffer.
 
int highpass_enabled
Is the input filter enabled.
 
static const int8_t hexc_table[1024]
 
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.
 
float mem_hp[2]
High-pass filter memory.
 
static int get_bits_count(const GetBitContext *s)
 
static const int8_t exc_8_128_table[1024]
 
int32_t version_id
Version for Speex (for checking compatibility)
 
static const int8_t cdbk_nb_high1[320]
 
int modeID
ID of the mode.
 
int lpc_enh_enabled
1 when LPC enhancer is on, 0 otherwise
 
This structure describes decoded (raw) audio or video data.
 
float * exc
Start of excitation frame.
 
enum AVChannelOrder order
Channel order used in this layout.
 
int lpc_size
Order of LPC filter.
 
static const SpeexSubmode nb_submode8
 
int nb_channels
Number of channels in this layout.
 
int double_codebook
Apply innovation quantization twice for higher quality (and higher bit-rate)
 
static int speex_inband_handler(GetBitContext *gb, void *state, StereoState *stereo)
 
#define gain_3tap_to_1tap(g)
 
trying all byte sequences megabyte in length and selecting the best looking sequence will yield cases to try But a word about quality
 
static const SpeexSubmode wb_submode4
 
int subframe_size
Size of sub-frames used for decoding.
 
const void * LtpParam
Pitch parameters (options)
 
int32_t nb_channels
Number of channels decoded.
 
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
 
AVCodec p
The public AVCodec.
 
static const int8_t exc_5_256_table[1280]
 
#define LSP_LINEAR_HIGH(i)
 
AVChannelLayout ch_layout
Audio channel layout.
 
static int speex_default_user_handler(GetBitContext *gb, void *state, void *data)
 
static av_always_inline float av_int2float(uint32_t i)
Reinterpret a 32-bit integer as a float.
 
ltp_unquant_func ltp_unquant
Long-term predictor (pitch) un-quantizer.
 
void(* innovation_quant_func)(float *, float *, float *, float *, const void *, int, int, float *, float *, GetBitContext *, char *, int, int)
Innovation quantization function.
 
AVChannelLayout ch_layout
Channel layout of the audio data.
 
static const SplitCodebookParams split_cb_nb_lbr
 
int nb_subframes
Number of high-band sub-frames.
 
static __device__ float fabsf(float a)
 
static const SpeexSubmode wb_submode3
 
int32_t bitrate
Bit-rate used.
 
static const float e_ratio_quant[4]
 
const FFCodec ff_speex_decoder
 
static const SplitCodebookParams split_cb_nb_ulbr
 
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
 
static int init_get_bits8(GetBitContext *s, const uint8_t *buffer, int byte_size)
Initialize GetBitContext.
 
float balance
Left/right balance info.
 
static void lsp_interpolate(const float *old_lsp, const float *new_lsp, float *lsp, int len, int subframe, int nb_subframes, float margin)
 
#define FF_CODEC_DECODE_CB(func)
 
static const SplitCodebookParams split_cb_sb
 
static int nb_decode(AVCodecContext *, void *, GetBitContext *, float *)
 
static int speex_std_stereo(GetBitContext *gb, void *state, void *data)
 
@ AV_CHANNEL_ORDER_UNSPEC
Only the channel count is specified, without any further information about the channel order.
 
static const int8_t gain_cdbk_lbr[128]
 
float fminf(float, float)
 
#define av_assert0(cond)
assert() equivalent, that is always enabled.
 
static const SpeexSubmode nb_submode7
 
static float speex_rand(float std, uint32_t *seed)
 
static const int8_t cdbk_nb_low2[320]
 
static const SpeexMode speex_modes[SPEEX_NB_MODES]
 
int modeID
ID of the decoder mode.
 
#define CODEC_LONG_NAME(str)
 
static const SpeexSubmode nb_submode6
 
innovation_unquant_func innovation_unquant
Innovation un-quantization.
 
#define FFABS(a)
Absolute value, Note, INT_MIN / INT64_MIN result in undefined behavior as they are not representable ...
 
float mem_sp[NB_ORDER]
Filter memory for synthesis signal.
 
#define SPEEX_MEMSET(dst, c, n)
 
static void lsp_to_lpc(const float *freq, float *ak, int lpcrdr)
 
static int speex_decode_frame(AVCodecContext *avctx, AVFrame *frame, int *got_frame_ptr, AVPacket *avpkt)
 
static const SpeexSubmode nb_submode1
 
Describe the class of an AVClass context structure.
 
int32_t frames_per_packet
Number of frames stored per Ogg packet.
 
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
 
int lpc_size
Order of high-band LPC analysis.
 
int default_submode
Default sub-mode to use when decoding.
 
int64_t bit_rate
the average bitrate
 
static unsigned int get_bits1(GetBitContext *s)
 
float exc_rms[NB_NB_SUBFRAMES]
RMS of excitation per subframe.
 
static const SplitCodebookParams split_cb_nb
 
static __device__ float sqrtf(float a)
 
int32_t bitstream_version
Version ID of the bit-stream.
 
static const int8_t exc_10_32_table[320]
 
int32_t extra_headers
Number of additional headers after the comments.
 
static const LtpParam ltp_params_nb
 
static const uint16_t wb_skip_table[8]
 
float comb_gain
Gain of enhancer comb filter.
 
#define AV_CODEC_CAP_CHANNEL_CONF
Codec should fill in channel configuration and samplerate instead of container.
 
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
 
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
 
static void scale(int *out, const int *in, const int w, const int h, const int shift)
 
static void lsp_unquant_nb(float *lsp, int order, GetBitContext *gb)
 
static const int8_t exc_5_64_table[320]
 
static const LtpParam ltp_params_lbr
 
static const LtpParam ltp_params_med
 
static void sanitize_values(float *vec, float min_val, float max_val, int len)
 
float folding_gain
Folding gain.
 
void(* ltp_unquant_func)(float *, float *, int, int, float, const void *, int, int *, float *, GetBitContext *, int, int, float, int)
Long-term un-quantize.
 
float fmaxf(float, float)
 
enum AVSampleFormat sample_fmt
audio sample format
 
const SpeexSubmode *const * submodes
Sub-mode data.
 
static void signal_mul(const float *x, float *y, float scale, int len)
 
float old_qlsp[NB_ORDER]
Quantized LSPs for previous frame.
 
int frame_size
Length of high-band frames.
 
static void noise_codebook_unquant(float *exc, const void *par, int nsf, GetBitContext *gb, uint32_t *seed)
 
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)
 
static const int8_t gain_cdbk_nb[512]
 
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
 
int frame_size
Size of frames used for decoding.
 
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
 
static const int8_t cdbk_nb_high2[320]
 
static double fact(double i)
 
#define SPEEX_COPY(dst, src, n)
 
int subframe_size
Length of high-band sub-frames.
 
const void * innovation_params
Innovation quantization parameters.
 
static uint32_t ran(void)
 
static const int8_t exc_20_32_table[640]
 
static const float shift_filt[3][7]
 
static void multicomb(const float *exc, float *new_exc, float *ak, int p, int nsf, int pitch, int max_pitch, float comb_gain)
 
const signed char * shape_cb
 
int nb_samples
number of audio samples (per channel) described by this frame
 
void(* lsp_quant_func)(float *, float *, int, GetBitContext *)
Quantizes LSPs.
 
static void lsp_unquant_lbr(float *lsp, int order, GetBitContext *gb)
 
static const SplitCodebookParams split_cb_nb_med
 
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)
 
static const SpeexSubmode nb_submode5
 
#define i(width, name, range_min, range_max)
 
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
 
static unsigned int show_bits(GetBitContext *s, int n)
Show 1-25 bits.
 
float interp_qlpc[NB_ORDER]
Interpolated quantized LPCs.
 
uint8_t ** extended_data
pointers to the data planes/channels.
 
void(* lsp_unquant_func)(float *, int, GetBitContext *)
Decodes quantized LSPs.
 
static void iir_mem(const float *x, const float *den, float *y, int N, int ord, float *mem)
 
int full_frame_size
Length of full-band frames.
 
const char * name
Name of the codec implementation.
 
static float inner_prod(const float *x, const float *y, int len)
 
static const int8_t cdbk_nb[640]
 
static int decoder_init(SpeexContext *s, DecoderState *st, const SpeexMode *mode)
 
#define SPEEX_INBAND_STEREO
 
static int parse_speex_extradata(AVCodecContext *avctx, const uint8_t *extradata, int extradata_size)
 
lsp_unquant_func lsp_unquant
LSP unquantization function.
 
static const SplitCodebookParams split_cb_nb_vlbr
 
int(* decode)(AVCodecContext *avctx, void *dec, GetBitContext *gb, float *out)
 
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...
 
float smooth_right
Smoothed right channel gain.
 
static const float gc_quant_bound[16]
 
int last_pitch
Pitch of last correctly decoded frame.
 
float smooth_left
Smoothed left channel gain.
 
main external API structure.
 
const SpeexSubmode * submodes[NB_SUBMODES]
Sub-mode data for the mode.
 
float last_ol_gain
Open-loop gain for previous frame.
 
static const int8_t cdbk_nb_low1[320]
 
void av_channel_layout_uninit(AVChannelLayout *channel_layout)
Free any allocated data in the channel layout and reset the channel count to 0.
 
int is_wideband
If wideband is present.
 
static av_cold int speex_decode_close(AVCodecContext *avctx)
 
static av_always_inline int get_bitsz(GetBitContext *s, int n)
Read 0-25 bits.
 
static const int8_t high_lsp_cdbk2[512]
 
int32_t mode
Mode used (0 for narrowband, 1 for wideband)
 
DecoderState st[SPEEX_NB_MODES]
 
static const SpeexSubmode nb_submode2
 
static const LtpParam ltp_params_vlbr
 
int forced_pitch_gain
Use the same (forced) pitch gain for all sub-frames.
 
unsigned int codec_tag
fourcc (LSB first, so "ABCD" -> ('D'<<24) + ('C'<<16) + ('B'<<8) + 'A').
 
static const SpeexSubmode wb_submode1
 
static void highpass(const float *x, float *y, int len, float *mem, int wide)
 
This structure stores compressed data.
 
av_cold AVFloatDSPContext * avpriv_float_dsp_alloc(int bit_exact)
Allocate a float DSP context.
 
static void speex_decode_stereo(float *data, int frame_size, StereoState *stereo)
 
void(* innovation_unquant_func)(float *, const void *, int, GetBitContext *, uint32_t *)
Innovation unquantization function.
 
int lbr_pitch
Set to -1 for "normal" modes, otherwise encode pitch using a global pitch and allowing a +- lbr_pitch...
 
static av_cold int speex_decode_init(AVCodecContext *avctx)
 
int32_t frame_size
Size of frames.
 
static void lsp_unquant_high(float *lsp, int order, GetBitContext *gb)
 
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
 
static const int8_t exc_10_16_table[160]
 
static void qmf_synth(const float *x1, const float *x2, const float *a, float *y, int N, int M, float *mem1, float *mem2)
 
static const float exc_gain_quant_scal3[8]
 
#define MKTAG(a, b, c, d)
 
float last_pitch_gain
Pitch gain of last correctly decoded frame.
 
static const SplitCodebookParams split_cb_high_lbr
 
float pi_gain[NB_NB_SUBFRAMES]
Gain of LPC filter at theta=pi (fe/2)
 
int32_t rate
Sampling rate used.
 
static void bw_lpc(float gamma, const float *lpc_in, float *lpc_out, int order)
 
static int interp_pitch(const float *exc, float *interp, int pitch, int len)
 
static float compute_rms(const float *x, int len)
 
static int sb_decode(AVCodecContext *, void *, GetBitContext *, float *)
 
float * innov_save
If non-NULL, innovation is copied here.
 
float e_ratio
Ratio of energies: E(left+right)/[E(left)+E(right)]
 
static void split_cb_shape_sign_unquant(float *exc, const void *par, int nsf, GetBitContext *gb, uint32_t *seed)
 
static const int8_t high_lsp_cdbk[512]