annotate qcelp_lsp.c @ 8240:d3d0d9cc0e50 libavcodec

Commit last ok'ed parts of QCELP decoder and enable it. patch by Kenan Gillet, kenan.gillet gmail com
author vitor
date Tue, 02 Dec 2008 16:48:05 +0000
parents
children b41482ad0ef5
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
8240
d3d0d9cc0e50 Commit last ok'ed parts of QCELP decoder and enable it.
vitor
parents:
diff changeset
1 /*
d3d0d9cc0e50 Commit last ok'ed parts of QCELP decoder and enable it.
vitor
parents:
diff changeset
2 * QCELP decoder
d3d0d9cc0e50 Commit last ok'ed parts of QCELP decoder and enable it.
vitor
parents:
diff changeset
3 * Copyright (c) 2007 Reynaldo H. Verdejo Pinochet
d3d0d9cc0e50 Commit last ok'ed parts of QCELP decoder and enable it.
vitor
parents:
diff changeset
4 *
d3d0d9cc0e50 Commit last ok'ed parts of QCELP decoder and enable it.
vitor
parents:
diff changeset
5 * This file is part of FFmpeg.
d3d0d9cc0e50 Commit last ok'ed parts of QCELP decoder and enable it.
vitor
parents:
diff changeset
6 *
d3d0d9cc0e50 Commit last ok'ed parts of QCELP decoder and enable it.
vitor
parents:
diff changeset
7 * FFmpeg is free software; you can redistribute it and/or
d3d0d9cc0e50 Commit last ok'ed parts of QCELP decoder and enable it.
vitor
parents:
diff changeset
8 * modify it under the terms of the GNU Lesser General Public
d3d0d9cc0e50 Commit last ok'ed parts of QCELP decoder and enable it.
vitor
parents:
diff changeset
9 * License as published by the Free Software Foundation; either
d3d0d9cc0e50 Commit last ok'ed parts of QCELP decoder and enable it.
vitor
parents:
diff changeset
10 * version 2.1 of the License, or (at your option) any later version.
d3d0d9cc0e50 Commit last ok'ed parts of QCELP decoder and enable it.
vitor
parents:
diff changeset
11 *
d3d0d9cc0e50 Commit last ok'ed parts of QCELP decoder and enable it.
vitor
parents:
diff changeset
12 * FFmpeg is distributed in the hope that it will be useful,
d3d0d9cc0e50 Commit last ok'ed parts of QCELP decoder and enable it.
vitor
parents:
diff changeset
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
d3d0d9cc0e50 Commit last ok'ed parts of QCELP decoder and enable it.
vitor
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
d3d0d9cc0e50 Commit last ok'ed parts of QCELP decoder and enable it.
vitor
parents:
diff changeset
15 * Lesser General Public License for more details.
d3d0d9cc0e50 Commit last ok'ed parts of QCELP decoder and enable it.
vitor
parents:
diff changeset
16 *
d3d0d9cc0e50 Commit last ok'ed parts of QCELP decoder and enable it.
vitor
parents:
diff changeset
17 * You should have received a copy of the GNU Lesser General Public
d3d0d9cc0e50 Commit last ok'ed parts of QCELP decoder and enable it.
vitor
parents:
diff changeset
18 * License along with FFmpeg; if not, write to the Free Software
d3d0d9cc0e50 Commit last ok'ed parts of QCELP decoder and enable it.
vitor
parents:
diff changeset
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
d3d0d9cc0e50 Commit last ok'ed parts of QCELP decoder and enable it.
vitor
parents:
diff changeset
20 */
d3d0d9cc0e50 Commit last ok'ed parts of QCELP decoder and enable it.
vitor
parents:
diff changeset
21
d3d0d9cc0e50 Commit last ok'ed parts of QCELP decoder and enable it.
vitor
parents:
diff changeset
22 /**
d3d0d9cc0e50 Commit last ok'ed parts of QCELP decoder and enable it.
vitor
parents:
diff changeset
23 * @file qcelp_lsp.c
d3d0d9cc0e50 Commit last ok'ed parts of QCELP decoder and enable it.
vitor
parents:
diff changeset
24 * QCELP decoder
d3d0d9cc0e50 Commit last ok'ed parts of QCELP decoder and enable it.
vitor
parents:
diff changeset
25 * @author Reynaldo H. Verdejo Pinochet
d3d0d9cc0e50 Commit last ok'ed parts of QCELP decoder and enable it.
vitor
parents:
diff changeset
26 */
d3d0d9cc0e50 Commit last ok'ed parts of QCELP decoder and enable it.
vitor
parents:
diff changeset
27
d3d0d9cc0e50 Commit last ok'ed parts of QCELP decoder and enable it.
vitor
parents:
diff changeset
28 #include "libavutil/mathematics.h"
d3d0d9cc0e50 Commit last ok'ed parts of QCELP decoder and enable it.
vitor
parents:
diff changeset
29
d3d0d9cc0e50 Commit last ok'ed parts of QCELP decoder and enable it.
vitor
parents:
diff changeset
30 /**
d3d0d9cc0e50 Commit last ok'ed parts of QCELP decoder and enable it.
vitor
parents:
diff changeset
31 * initial coefficient to perform bandwidth expansion on LPC
d3d0d9cc0e50 Commit last ok'ed parts of QCELP decoder and enable it.
vitor
parents:
diff changeset
32 *
d3d0d9cc0e50 Commit last ok'ed parts of QCELP decoder and enable it.
vitor
parents:
diff changeset
33 * @note: 0.9883 looks like an approximation of 253/256.
d3d0d9cc0e50 Commit last ok'ed parts of QCELP decoder and enable it.
vitor
parents:
diff changeset
34 *
d3d0d9cc0e50 Commit last ok'ed parts of QCELP decoder and enable it.
vitor
parents:
diff changeset
35 * TIA/EIA/IS-733 2.4.3.3.6 6
d3d0d9cc0e50 Commit last ok'ed parts of QCELP decoder and enable it.
vitor
parents:
diff changeset
36 */
d3d0d9cc0e50 Commit last ok'ed parts of QCELP decoder and enable it.
vitor
parents:
diff changeset
37 #define QCELP_BANDWITH_EXPANSION_COEFF 0.9883
d3d0d9cc0e50 Commit last ok'ed parts of QCELP decoder and enable it.
vitor
parents:
diff changeset
38
d3d0d9cc0e50 Commit last ok'ed parts of QCELP decoder and enable it.
vitor
parents:
diff changeset
39 /**
d3d0d9cc0e50 Commit last ok'ed parts of QCELP decoder and enable it.
vitor
parents:
diff changeset
40 * Computes the Pa / (1 + z(-1)) or Qa / (1 - z(-1)) coefficients
d3d0d9cc0e50 Commit last ok'ed parts of QCELP decoder and enable it.
vitor
parents:
diff changeset
41 * needed for LSP to LPC conversion.
d3d0d9cc0e50 Commit last ok'ed parts of QCELP decoder and enable it.
vitor
parents:
diff changeset
42 * We only need to calculate the 6 first elements of the polynomial.
d3d0d9cc0e50 Commit last ok'ed parts of QCELP decoder and enable it.
vitor
parents:
diff changeset
43 *
d3d0d9cc0e50 Commit last ok'ed parts of QCELP decoder and enable it.
vitor
parents:
diff changeset
44 * @param lspf line spectral pair frequencies
d3d0d9cc0e50 Commit last ok'ed parts of QCELP decoder and enable it.
vitor
parents:
diff changeset
45 * @param f [out] polynomial input/output as a vector
d3d0d9cc0e50 Commit last ok'ed parts of QCELP decoder and enable it.
vitor
parents:
diff changeset
46 *
d3d0d9cc0e50 Commit last ok'ed parts of QCELP decoder and enable it.
vitor
parents:
diff changeset
47 * TIA/EIA/IS-733 2.4.3.3.5-1/2
d3d0d9cc0e50 Commit last ok'ed parts of QCELP decoder and enable it.
vitor
parents:
diff changeset
48 */
d3d0d9cc0e50 Commit last ok'ed parts of QCELP decoder and enable it.
vitor
parents:
diff changeset
49 static void lsp2polyf(const float *lspf, double *f, int lp_half_order)
d3d0d9cc0e50 Commit last ok'ed parts of QCELP decoder and enable it.
vitor
parents:
diff changeset
50 {
d3d0d9cc0e50 Commit last ok'ed parts of QCELP decoder and enable it.
vitor
parents:
diff changeset
51 int i, j;
d3d0d9cc0e50 Commit last ok'ed parts of QCELP decoder and enable it.
vitor
parents:
diff changeset
52
d3d0d9cc0e50 Commit last ok'ed parts of QCELP decoder and enable it.
vitor
parents:
diff changeset
53 f[0] = 1.0;
d3d0d9cc0e50 Commit last ok'ed parts of QCELP decoder and enable it.
vitor
parents:
diff changeset
54 f[1] = -2 * cos(M_PI * lspf[0]);
d3d0d9cc0e50 Commit last ok'ed parts of QCELP decoder and enable it.
vitor
parents:
diff changeset
55 lspf -= 2;
d3d0d9cc0e50 Commit last ok'ed parts of QCELP decoder and enable it.
vitor
parents:
diff changeset
56 for(i=2; i<=lp_half_order; i++)
d3d0d9cc0e50 Commit last ok'ed parts of QCELP decoder and enable it.
vitor
parents:
diff changeset
57 {
d3d0d9cc0e50 Commit last ok'ed parts of QCELP decoder and enable it.
vitor
parents:
diff changeset
58 double val = -2 * cos(M_PI * lspf[2*i]);
d3d0d9cc0e50 Commit last ok'ed parts of QCELP decoder and enable it.
vitor
parents:
diff changeset
59 f[i] = val * f[i-1] + 2*f[i-2];
d3d0d9cc0e50 Commit last ok'ed parts of QCELP decoder and enable it.
vitor
parents:
diff changeset
60 for(j=i-1; j>1; j--)
d3d0d9cc0e50 Commit last ok'ed parts of QCELP decoder and enable it.
vitor
parents:
diff changeset
61 f[j] += f[j-1] * val + f[j-2];
d3d0d9cc0e50 Commit last ok'ed parts of QCELP decoder and enable it.
vitor
parents:
diff changeset
62 f[1] += val;
d3d0d9cc0e50 Commit last ok'ed parts of QCELP decoder and enable it.
vitor
parents:
diff changeset
63 }
d3d0d9cc0e50 Commit last ok'ed parts of QCELP decoder and enable it.
vitor
parents:
diff changeset
64 }
d3d0d9cc0e50 Commit last ok'ed parts of QCELP decoder and enable it.
vitor
parents:
diff changeset
65
d3d0d9cc0e50 Commit last ok'ed parts of QCELP decoder and enable it.
vitor
parents:
diff changeset
66 /**
d3d0d9cc0e50 Commit last ok'ed parts of QCELP decoder and enable it.
vitor
parents:
diff changeset
67 * Reconstructs LPC coefficients from the line spectral pair frequencies
d3d0d9cc0e50 Commit last ok'ed parts of QCELP decoder and enable it.
vitor
parents:
diff changeset
68 * and performs bandwidth expansion.
d3d0d9cc0e50 Commit last ok'ed parts of QCELP decoder and enable it.
vitor
parents:
diff changeset
69 *
d3d0d9cc0e50 Commit last ok'ed parts of QCELP decoder and enable it.
vitor
parents:
diff changeset
70 * @param lspf line spectral pair frequencies
d3d0d9cc0e50 Commit last ok'ed parts of QCELP decoder and enable it.
vitor
parents:
diff changeset
71 * @param lpc linear predictive coding coefficients
d3d0d9cc0e50 Commit last ok'ed parts of QCELP decoder and enable it.
vitor
parents:
diff changeset
72 *
d3d0d9cc0e50 Commit last ok'ed parts of QCELP decoder and enable it.
vitor
parents:
diff changeset
73 * @note: bandwith_expansion_coeff could be precalculated into a table
d3d0d9cc0e50 Commit last ok'ed parts of QCELP decoder and enable it.
vitor
parents:
diff changeset
74 * but it seems to be slower on x86
d3d0d9cc0e50 Commit last ok'ed parts of QCELP decoder and enable it.
vitor
parents:
diff changeset
75 *
d3d0d9cc0e50 Commit last ok'ed parts of QCELP decoder and enable it.
vitor
parents:
diff changeset
76 * TIA/EIA/IS-733 2.4.3.3.5
d3d0d9cc0e50 Commit last ok'ed parts of QCELP decoder and enable it.
vitor
parents:
diff changeset
77 */
d3d0d9cc0e50 Commit last ok'ed parts of QCELP decoder and enable it.
vitor
parents:
diff changeset
78 void ff_qcelp_lspf2lpc(const float *lspf, float *lpc)
d3d0d9cc0e50 Commit last ok'ed parts of QCELP decoder and enable it.
vitor
parents:
diff changeset
79 {
d3d0d9cc0e50 Commit last ok'ed parts of QCELP decoder and enable it.
vitor
parents:
diff changeset
80 double pa[6], qa[6];
d3d0d9cc0e50 Commit last ok'ed parts of QCELP decoder and enable it.
vitor
parents:
diff changeset
81 int i;
d3d0d9cc0e50 Commit last ok'ed parts of QCELP decoder and enable it.
vitor
parents:
diff changeset
82 double bandwith_expansion_coeff = -QCELP_BANDWITH_EXPANSION_COEFF * 0.5;
d3d0d9cc0e50 Commit last ok'ed parts of QCELP decoder and enable it.
vitor
parents:
diff changeset
83
d3d0d9cc0e50 Commit last ok'ed parts of QCELP decoder and enable it.
vitor
parents:
diff changeset
84 lsp2polyf(lspf, pa, 5);
d3d0d9cc0e50 Commit last ok'ed parts of QCELP decoder and enable it.
vitor
parents:
diff changeset
85 lsp2polyf(lspf + 1, qa, 5);
d3d0d9cc0e50 Commit last ok'ed parts of QCELP decoder and enable it.
vitor
parents:
diff changeset
86
d3d0d9cc0e50 Commit last ok'ed parts of QCELP decoder and enable it.
vitor
parents:
diff changeset
87 for (i=4; i>=0; i--)
d3d0d9cc0e50 Commit last ok'ed parts of QCELP decoder and enable it.
vitor
parents:
diff changeset
88 {
d3d0d9cc0e50 Commit last ok'ed parts of QCELP decoder and enable it.
vitor
parents:
diff changeset
89 double paf = pa[i+1] + pa[i];
d3d0d9cc0e50 Commit last ok'ed parts of QCELP decoder and enable it.
vitor
parents:
diff changeset
90 double qaf = qa[i+1] - qa[i];
d3d0d9cc0e50 Commit last ok'ed parts of QCELP decoder and enable it.
vitor
parents:
diff changeset
91
d3d0d9cc0e50 Commit last ok'ed parts of QCELP decoder and enable it.
vitor
parents:
diff changeset
92 lpc[i ] = paf + qaf;
d3d0d9cc0e50 Commit last ok'ed parts of QCELP decoder and enable it.
vitor
parents:
diff changeset
93 lpc[9-i] = paf - qaf;
d3d0d9cc0e50 Commit last ok'ed parts of QCELP decoder and enable it.
vitor
parents:
diff changeset
94 }
d3d0d9cc0e50 Commit last ok'ed parts of QCELP decoder and enable it.
vitor
parents:
diff changeset
95 for (i=0; i<10; i++)
d3d0d9cc0e50 Commit last ok'ed parts of QCELP decoder and enable it.
vitor
parents:
diff changeset
96 {
d3d0d9cc0e50 Commit last ok'ed parts of QCELP decoder and enable it.
vitor
parents:
diff changeset
97 lpc[i] *= bandwith_expansion_coeff;
d3d0d9cc0e50 Commit last ok'ed parts of QCELP decoder and enable it.
vitor
parents:
diff changeset
98 bandwith_expansion_coeff *= QCELP_BANDWITH_EXPANSION_COEFF;
d3d0d9cc0e50 Commit last ok'ed parts of QCELP decoder and enable it.
vitor
parents:
diff changeset
99 }
d3d0d9cc0e50 Commit last ok'ed parts of QCELP decoder and enable it.
vitor
parents:
diff changeset
100 }