annotate qcelp_lsp.c @ 9186:f7fda987b769 libavcodec

Fix typo in AOT_ER_AAC_ELD
author alexc
date Wed, 18 Mar 2009 14:14:56 +0000
parents 36a5caff8540
children 18dab2b47db7
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 /**
8718
e9d9d946f213 Use full internal pathname in doxygen @file directives.
diego
parents: 8258
diff changeset
23 * @file libavcodec/qcelp_lsp.c
8240
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
8258
b41482ad0ef5 COSMETICS, add missing remarks crediting Ben and Kenan
reynaldo
parents: 8240
diff changeset
26 * @remark FFmpeg merging spearheaded by Kenan Gillet
b41482ad0ef5 COSMETICS, add missing remarks crediting Ben and Kenan
reynaldo
parents: 8240
diff changeset
27 * @remark Development mentored by Benjamin Larson
8240
d3d0d9cc0e50 Commit last ok'ed parts of QCELP decoder and enable it.
vitor
parents:
diff changeset
28 */
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 #include "libavutil/mathematics.h"
d3d0d9cc0e50 Commit last ok'ed parts of QCELP decoder and enable it.
vitor
parents:
diff changeset
31
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 * 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
34 * needed for LSP to LPC conversion.
d3d0d9cc0e50 Commit last ok'ed parts of QCELP decoder and enable it.
vitor
parents:
diff changeset
35 * 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
36 *
d3d0d9cc0e50 Commit last ok'ed parts of QCELP decoder and enable it.
vitor
parents:
diff changeset
37 * @param lspf line spectral pair frequencies
d3d0d9cc0e50 Commit last ok'ed parts of QCELP decoder and enable it.
vitor
parents:
diff changeset
38 * @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
39 *
d3d0d9cc0e50 Commit last ok'ed parts of QCELP decoder and enable it.
vitor
parents:
diff changeset
40 * 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
41 */
9122
0613e9b5514c Part 1 of 2 of Kenan Gillet's 'make ff_qcelp_lspf2lpc
reynaldo
parents: 9017
diff changeset
42 static void lsp2polyf(const double *lspf, double *f, int lp_half_order)
8240
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 int i, j;
d3d0d9cc0e50 Commit last ok'ed parts of QCELP decoder and enable it.
vitor
parents:
diff changeset
45
d3d0d9cc0e50 Commit last ok'ed parts of QCELP decoder and enable it.
vitor
parents:
diff changeset
46 f[0] = 1.0;
9122
0613e9b5514c Part 1 of 2 of Kenan Gillet's 'make ff_qcelp_lspf2lpc
reynaldo
parents: 9017
diff changeset
47 f[1] = -2 * lspf[0];
8240
d3d0d9cc0e50 Commit last ok'ed parts of QCELP decoder and enable it.
vitor
parents:
diff changeset
48 lspf -= 2;
d3d0d9cc0e50 Commit last ok'ed parts of QCELP decoder and enable it.
vitor
parents:
diff changeset
49 for(i=2; i<=lp_half_order; i++)
d3d0d9cc0e50 Commit last ok'ed parts of QCELP decoder and enable it.
vitor
parents:
diff changeset
50 {
9122
0613e9b5514c Part 1 of 2 of Kenan Gillet's 'make ff_qcelp_lspf2lpc
reynaldo
parents: 9017
diff changeset
51 double val = -2 * lspf[2*i];
8240
d3d0d9cc0e50 Commit last ok'ed parts of QCELP decoder and enable it.
vitor
parents:
diff changeset
52 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
53 for(j=i-1; j>1; j--)
d3d0d9cc0e50 Commit last ok'ed parts of QCELP decoder and enable it.
vitor
parents:
diff changeset
54 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
55 f[1] += val;
d3d0d9cc0e50 Commit last ok'ed parts of QCELP decoder and enable it.
vitor
parents:
diff changeset
56 }
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
d3d0d9cc0e50 Commit last ok'ed parts of QCELP decoder and enable it.
vitor
parents:
diff changeset
59 /**
9122
0613e9b5514c Part 1 of 2 of Kenan Gillet's 'make ff_qcelp_lspf2lpc
reynaldo
parents: 9017
diff changeset
60 * Reconstructs LPC coefficients from the line spectral pair frequencies.
0613e9b5514c Part 1 of 2 of Kenan Gillet's 'make ff_qcelp_lspf2lpc
reynaldo
parents: 9017
diff changeset
61 *
0613e9b5514c Part 1 of 2 of Kenan Gillet's 'make ff_qcelp_lspf2lpc
reynaldo
parents: 9017
diff changeset
62 * @param lspf line spectral pair frequencies
0613e9b5514c Part 1 of 2 of Kenan Gillet's 'make ff_qcelp_lspf2lpc
reynaldo
parents: 9017
diff changeset
63 * @param lpc linear predictive coding coefficients
0613e9b5514c Part 1 of 2 of Kenan Gillet's 'make ff_qcelp_lspf2lpc
reynaldo
parents: 9017
diff changeset
64 */
0613e9b5514c Part 1 of 2 of Kenan Gillet's 'make ff_qcelp_lspf2lpc
reynaldo
parents: 9017
diff changeset
65 void ff_celp_lspf2lpc(const double *lspf, float *lpc)
0613e9b5514c Part 1 of 2 of Kenan Gillet's 'make ff_qcelp_lspf2lpc
reynaldo
parents: 9017
diff changeset
66 {
0613e9b5514c Part 1 of 2 of Kenan Gillet's 'make ff_qcelp_lspf2lpc
reynaldo
parents: 9017
diff changeset
67 double pa[6], qa[6];
0613e9b5514c Part 1 of 2 of Kenan Gillet's 'make ff_qcelp_lspf2lpc
reynaldo
parents: 9017
diff changeset
68 int i;
0613e9b5514c Part 1 of 2 of Kenan Gillet's 'make ff_qcelp_lspf2lpc
reynaldo
parents: 9017
diff changeset
69
0613e9b5514c Part 1 of 2 of Kenan Gillet's 'make ff_qcelp_lspf2lpc
reynaldo
parents: 9017
diff changeset
70 lsp2polyf(lspf, pa, 5);
0613e9b5514c Part 1 of 2 of Kenan Gillet's 'make ff_qcelp_lspf2lpc
reynaldo
parents: 9017
diff changeset
71 lsp2polyf(lspf + 1, qa, 5);
0613e9b5514c Part 1 of 2 of Kenan Gillet's 'make ff_qcelp_lspf2lpc
reynaldo
parents: 9017
diff changeset
72
0613e9b5514c Part 1 of 2 of Kenan Gillet's 'make ff_qcelp_lspf2lpc
reynaldo
parents: 9017
diff changeset
73 for (i=4; i>=0; i--)
0613e9b5514c Part 1 of 2 of Kenan Gillet's 'make ff_qcelp_lspf2lpc
reynaldo
parents: 9017
diff changeset
74 {
0613e9b5514c Part 1 of 2 of Kenan Gillet's 'make ff_qcelp_lspf2lpc
reynaldo
parents: 9017
diff changeset
75 double paf = pa[i+1] + pa[i];
0613e9b5514c Part 1 of 2 of Kenan Gillet's 'make ff_qcelp_lspf2lpc
reynaldo
parents: 9017
diff changeset
76 double qaf = qa[i+1] - qa[i];
0613e9b5514c Part 1 of 2 of Kenan Gillet's 'make ff_qcelp_lspf2lpc
reynaldo
parents: 9017
diff changeset
77
9123
36a5caff8540 Part 2 of 2 of Kenan Gillet's 'make ff_qcelp_lspf2lpc
reynaldo
parents: 9122
diff changeset
78 lpc[i ] = 0.5*(paf+qaf);
36a5caff8540 Part 2 of 2 of Kenan Gillet's 'make ff_qcelp_lspf2lpc
reynaldo
parents: 9122
diff changeset
79 lpc[9-i] = 0.5*(paf-qaf);
9122
0613e9b5514c Part 1 of 2 of Kenan Gillet's 'make ff_qcelp_lspf2lpc
reynaldo
parents: 9017
diff changeset
80 }
0613e9b5514c Part 1 of 2 of Kenan Gillet's 'make ff_qcelp_lspf2lpc
reynaldo
parents: 9017
diff changeset
81 }