annotate sipr16k.c @ 12123:750962dae4c9 libavcodec

Change qmax/qmin limits to 63 instead of 51. VP8 supports quantizers up to 63.
author darkshikari
date Sat, 10 Jul 2010 06:34:57 +0000
parents 8b6f3d3b55cb
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
10891
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
1 /*
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
2 * SIPR decoder for the 16k mode
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
3 *
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
4 * Copyright (c) 2008 Vladimir Voroshilov
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
5 * Copyright (c) 2009 Vitor Sessak
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
6 *
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
7 * This file is part of FFmpeg.
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
8 *
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
9 * FFmpeg is free software; you can redistribute it and/or
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
10 * modify it under the terms of the GNU Lesser General Public
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
11 * License as published by the Free Software Foundation; either
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
12 * version 2.1 of the License, or (at your option) any later version.
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
13 *
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
14 * FFmpeg is distributed in the hope that it will be useful,
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
17 * Lesser General Public License for more details.
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
18 *
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
19 * You should have received a copy of the GNU Lesser General Public
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
20 * License along with FFmpeg; if not, write to the Free Software
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
22 */
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
23
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
24 #include <math.h>
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
25
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
26 #include "sipr.h"
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
27 #include "libavutil/mathematics.h"
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
28 #include "lsp.h"
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
29 #include "celp_math.h"
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
30 #include "acelp_vectors.h"
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
31 #include "acelp_pitch_delay.h"
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
32 #include "acelp_filters.h"
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
33 #include "celp_filters.h"
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
34
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
35 #include "sipr16kdata.h"
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
36
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
37 /**
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
38 * Convert an lsf vector into an lsp vector.
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
39 *
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
40 * @param lsf input lsf vector
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
41 * @param lsp output lsp vector
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
42 */
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
43 static void lsf2lsp(const float *lsf, double *lsp)
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
44 {
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
45 int i;
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
46
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
47 for (i = 0; i < LP_FILTER_ORDER_16k; i++)
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
48 lsp[i] = cosf(lsf[i]);
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
49 }
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
50
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
51 static void dequant(float *out, const int *idx, const float *cbs[])
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
52 {
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
53 int i;
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
54
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
55 for (i = 0; i < 4; i++)
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
56 memcpy(out + 3*i, cbs[i] + 3*idx[i], 3*sizeof(float));
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
57
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
58 memcpy(out + 12, cbs[4] + 4*idx[4], 4*sizeof(float));
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
59 }
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
60
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
61 static void lsf_decode_fp_16k(float* lsf_history, float* isp_new,
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
62 const int* parm, int ma_pred)
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
63 {
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
64 int i;
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
65 float isp_q[LP_FILTER_ORDER_16k];
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
66
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
67 dequant(isp_q, parm, lsf_codebooks_16k);
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
68
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
69 for (i = 0; i < LP_FILTER_ORDER_16k; i++) {
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
70 isp_new[i] = (1 - qu[ma_pred]) * isp_q[i]
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
71 + qu[ma_pred] * lsf_history[i]
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
72 + mean_lsf_16k[i];
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
73 }
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
74
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
75 memcpy(lsf_history, isp_q, LP_FILTER_ORDER_16k * sizeof(float));
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
76 }
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
77
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
78 static int dec_delay3_1st(int index)
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
79 {
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
80 if (index < 390) {
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
81 return index + 88;
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
82 } else
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
83 return 3 * index - 690;
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
84 }
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
85
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
86 static int dec_delay3_2nd(int index, int pit_min, int pit_max,
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
87 int pitch_lag_prev)
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
88 {
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
89 if (index < 62) {
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
90 int pitch_delay_min = av_clip(pitch_lag_prev - 10,
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
91 pit_min, pit_max - 19);
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
92 return 3 * pitch_delay_min + index - 2;
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
93 } else
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
94 return 3 * pitch_lag_prev;
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
95 }
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
96
11649
e4e4fce64e5d Make the Sipr16k postfilter function write data into the target/output buffer.
rbultje
parents: 10891
diff changeset
97 static void postfilter(float *out_data, float* synth, float* iir_mem,
e4e4fce64e5d Make the Sipr16k postfilter function write data into the target/output buffer.
rbultje
parents: 10891
diff changeset
98 float* filt_mem[2], float* mem_preemph)
10891
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
99 {
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
100 float buf[30 + LP_FILTER_ORDER_16k];
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
101 float *tmpbuf = buf + LP_FILTER_ORDER_16k;
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
102 float s;
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
103 int i;
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
104
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
105 for (i = 0; i < LP_FILTER_ORDER_16k; i++)
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
106 filt_mem[0][i] = iir_mem[i] * ff_pow_0_5[i];
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
107
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
108 memcpy(tmpbuf - LP_FILTER_ORDER_16k, mem_preemph,
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
109 LP_FILTER_ORDER_16k*sizeof(*buf));
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
110
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
111 ff_celp_lp_synthesis_filterf(tmpbuf, filt_mem[1], synth, 30,
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
112 LP_FILTER_ORDER_16k);
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
113
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
114 memcpy(synth - LP_FILTER_ORDER_16k, mem_preemph,
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
115 LP_FILTER_ORDER_16k * sizeof(*synth));
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
116
11649
e4e4fce64e5d Make the Sipr16k postfilter function write data into the target/output buffer.
rbultje
parents: 10891
diff changeset
117 ff_celp_lp_synthesis_filterf(synth, filt_mem[0], synth, 30,
10891
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
118 LP_FILTER_ORDER_16k);
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
119
11649
e4e4fce64e5d Make the Sipr16k postfilter function write data into the target/output buffer.
rbultje
parents: 10891
diff changeset
120 memcpy(out_data + 30 - LP_FILTER_ORDER_16k,
e4e4fce64e5d Make the Sipr16k postfilter function write data into the target/output buffer.
rbultje
parents: 10891
diff changeset
121 synth + 30 - LP_FILTER_ORDER_16k,
e4e4fce64e5d Make the Sipr16k postfilter function write data into the target/output buffer.
rbultje
parents: 10891
diff changeset
122 LP_FILTER_ORDER_16k * sizeof(*synth));
e4e4fce64e5d Make the Sipr16k postfilter function write data into the target/output buffer.
rbultje
parents: 10891
diff changeset
123
e4e4fce64e5d Make the Sipr16k postfilter function write data into the target/output buffer.
rbultje
parents: 10891
diff changeset
124 ff_celp_lp_synthesis_filterf(out_data + 30, filt_mem[0],
e4e4fce64e5d Make the Sipr16k postfilter function write data into the target/output buffer.
rbultje
parents: 10891
diff changeset
125 synth + 30, 2 * L_SUBFR_16k - 30,
e4e4fce64e5d Make the Sipr16k postfilter function write data into the target/output buffer.
rbultje
parents: 10891
diff changeset
126 LP_FILTER_ORDER_16k);
e4e4fce64e5d Make the Sipr16k postfilter function write data into the target/output buffer.
rbultje
parents: 10891
diff changeset
127
e4e4fce64e5d Make the Sipr16k postfilter function write data into the target/output buffer.
rbultje
parents: 10891
diff changeset
128
e4e4fce64e5d Make the Sipr16k postfilter function write data into the target/output buffer.
rbultje
parents: 10891
diff changeset
129 memcpy(mem_preemph, out_data + 2*L_SUBFR_16k - LP_FILTER_ORDER_16k,
10891
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
130 LP_FILTER_ORDER_16k * sizeof(*synth));
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
131
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
132 FFSWAP(float *, filt_mem[0], filt_mem[1]);
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
133 for (i = 0, s = 0; i < 30; i++, s += 1.0/30)
11649
e4e4fce64e5d Make the Sipr16k postfilter function write data into the target/output buffer.
rbultje
parents: 10891
diff changeset
134 out_data[i] = tmpbuf[i] + s * (synth[i] - tmpbuf[i]);
10891
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
135 }
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
136
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
137 /**
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
138 * Floating point version of ff_acelp_lp_decode().
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
139 */
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
140 static void acelp_lp_decodef(float *lp_1st, float *lp_2nd,
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
141 const double *lsp_2nd, const double *lsp_prev)
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
142 {
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
143 double lsp_1st[LP_FILTER_ORDER_16k];
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
144 int i;
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
145
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
146 /* LSP values for first subframe (3.2.5 of G.729, Equation 24) */
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
147 for (i = 0; i < LP_FILTER_ORDER_16k; i++)
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
148 lsp_1st[i] = (lsp_2nd[i] + lsp_prev[i]) * 0.5;
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
149
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
150 ff_acelp_lspd2lpc(lsp_1st, lp_1st, LP_FILTER_ORDER_16k >> 1);
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
151
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
152 /* LSP values for second subframe (3.2.5 of G.729) */
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
153 ff_acelp_lspd2lpc(lsp_2nd, lp_2nd, LP_FILTER_ORDER_16k >> 1);
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
154 }
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
155
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
156 /**
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
157 * Floating point version of ff_acelp_decode_gain_code().
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
158 */
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
159 static float acelp_decode_gain_codef(float gain_corr_factor, const float *fc_v,
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
160 float mr_energy, const float *quant_energy,
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
161 const float *ma_prediction_coeff,
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
162 int subframe_size, int ma_pred_order)
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
163 {
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
164 mr_energy +=
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
165 ff_dot_productf(quant_energy, ma_prediction_coeff, ma_pred_order);
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
166
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
167 mr_energy = gain_corr_factor * exp(M_LN10 / 20. * mr_energy) /
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
168 sqrt((0.01 + ff_dot_productf(fc_v, fc_v, subframe_size)));
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
169 return mr_energy;
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
170 }
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
171
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
172 #define DIVIDE_BY_3(x) ((x) * 10923 >> 15)
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
173
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
174 void ff_sipr_decode_frame_16k(SiprContext *ctx, SiprParameters *params,
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
175 float *out_data)
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
176 {
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
177 int frame_size = SUBFRAME_COUNT_16k * L_SUBFR_16k;
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
178 float *synth = ctx->synth_buf + LP_FILTER_ORDER_16k;
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
179 float lsf_new[LP_FILTER_ORDER_16k];
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
180 double lsp_new[LP_FILTER_ORDER_16k];
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
181 float Az[2][LP_FILTER_ORDER_16k];
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
182 float fixed_vector[L_SUBFR_16k];
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
183 float pitch_fac, gain_code;
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
184
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
185 int i;
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
186 int pitch_delay_3x;
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
187
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
188 float *excitation = ctx->excitation + 292;
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
189
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
190 lsf_decode_fp_16k(ctx->lsf_history, lsf_new, params->vq_indexes,
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
191 params->ma_pred_switch);
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
192
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
193 ff_set_min_dist_lsf(lsf_new, LSFQ_DIFF_MIN / 2, LP_FILTER_ORDER_16k);
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
194
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
195 lsf2lsp(lsf_new, lsp_new);
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
196
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
197 acelp_lp_decodef(Az[0], Az[1], lsp_new, ctx->lsp_history_16k);
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
198
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
199 memcpy(ctx->lsp_history_16k, lsp_new, LP_FILTER_ORDER_16k * sizeof(double));
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
200
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
201 memcpy(synth - LP_FILTER_ORDER_16k, ctx->synth,
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
202 LP_FILTER_ORDER_16k * sizeof(*synth));
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
203
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
204 for (i = 0; i < SUBFRAME_COUNT_16k; i++) {
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
205 int i_subfr = i * L_SUBFR_16k;
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
206 AMRFixed f;
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
207 float gain_corr_factor;
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
208 int pitch_delay_int;
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
209 int pitch_delay_frac;
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
210
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
211 if (!i) {
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
212 pitch_delay_3x = dec_delay3_1st(params->pitch_delay[i]);
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
213 } else
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
214 pitch_delay_3x = dec_delay3_2nd(params->pitch_delay[i],
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
215 PITCH_MIN, PITCH_MAX,
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
216 ctx->pitch_lag_prev);
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
217
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
218 pitch_fac = gain_pitch_cb_16k[params->gp_index[i]];
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
219 f.pitch_fac = FFMIN(pitch_fac, 1.0);
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
220 f.pitch_lag = DIVIDE_BY_3(pitch_delay_3x+1);
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
221 ctx->pitch_lag_prev = f.pitch_lag;
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
222
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
223 pitch_delay_int = DIVIDE_BY_3(pitch_delay_3x + 2);
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
224 pitch_delay_frac = pitch_delay_3x + 2 - 3*pitch_delay_int;
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
225
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
226 ff_acelp_interpolatef(&excitation[i_subfr],
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
227 &excitation[i_subfr] - pitch_delay_int + 1,
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
228 sinc_win, 3, pitch_delay_frac + 1,
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
229 LP_FILTER_ORDER, L_SUBFR_16k);
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
230
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
231
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
232 memset(fixed_vector, 0, sizeof(fixed_vector));
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
233
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
234 ff_decode_10_pulses_35bits(params->fc_indexes[i], &f,
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
235 ff_fc_4pulses_8bits_tracks_13, 5, 4);
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
236
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
237 ff_set_fixed_vector(fixed_vector, &f, 1.0, L_SUBFR_16k);
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
238
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
239 gain_corr_factor = gain_cb_16k[params->gc_index[i]];
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
240 gain_code = gain_corr_factor *
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
241 acelp_decode_gain_codef(sqrt(L_SUBFR_16k), fixed_vector,
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
242 19.0 - 15.0/(0.05*M_LN10/M_LN2),
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
243 pred_16k, ctx->energy_history,
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
244 L_SUBFR_16k, 2);
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
245
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
246 ctx->energy_history[1] = ctx->energy_history[0];
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
247 ctx->energy_history[0] = 20.0 * log10f(gain_corr_factor);
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
248
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
249 ff_weighted_vector_sumf(&excitation[i_subfr], &excitation[i_subfr],
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
250 fixed_vector, pitch_fac,
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
251 gain_code, L_SUBFR_16k);
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
252
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
253 ff_celp_lp_synthesis_filterf(synth + i_subfr, Az[i],
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
254 &excitation[i_subfr], L_SUBFR_16k,
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
255 LP_FILTER_ORDER_16k);
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
256
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
257 }
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
258 memcpy(ctx->synth, synth + frame_size - LP_FILTER_ORDER_16k,
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
259 LP_FILTER_ORDER_16k * sizeof(*synth));
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
260
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
261 memmove(ctx->excitation, ctx->excitation + 2 * L_SUBFR_16k,
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
262 (L_INTERPOL+PITCH_MAX) * sizeof(float));
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
263
11649
e4e4fce64e5d Make the Sipr16k postfilter function write data into the target/output buffer.
rbultje
parents: 10891
diff changeset
264 postfilter(out_data, synth, ctx->iir_mem, ctx->filt_mem, ctx->mem_preemph);
10891
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
265
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
266 memcpy(ctx->iir_mem, Az[1], LP_FILTER_ORDER_16k * sizeof(float));
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
267 }
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
268
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
269 void ff_sipr_init_16k(SiprContext *ctx)
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
270 {
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
271 int i;
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
272
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
273 for (i = 0; i < LP_FILTER_ORDER_16k; i++)
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
274 ctx->lsp_history_16k[i] = cos((i + 1) * M_PI/(LP_FILTER_ORDER_16k + 1));
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
275
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
276 ctx->filt_mem[0] = ctx->filt_buf[0];
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
277 ctx->filt_mem[1] = ctx->filt_buf[1];
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
278
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
279 ctx->pitch_lag_prev = 180;
ff7c1c90b6f5 SIPR16k decoder
vitor
parents:
diff changeset
280 }