annotate qcelp_lsp.c @ 8997:1c69c50d78f1 libavcodec

Parse NAL units in H264 parser. Patch by Ivan Schreter, schreter gmx net
author cehoyos
date Sat, 21 Feb 2009 19:56:50 +0000
parents e9d9d946f213
children 1e2c96617886
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 * initial coefficient to perform bandwidth expansion on LPC
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 * @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
36 *
d3d0d9cc0e50 Commit last ok'ed parts of QCELP decoder and enable it.
vitor
parents:
diff changeset
37 * 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
38 */
d3d0d9cc0e50 Commit last ok'ed parts of QCELP decoder and enable it.
vitor
parents:
diff changeset
39 #define QCELP_BANDWITH_EXPANSION_COEFF 0.9883
d3d0d9cc0e50 Commit last ok'ed parts of QCELP decoder and enable it.
vitor
parents:
diff changeset
40
d3d0d9cc0e50 Commit last ok'ed parts of QCELP decoder and enable it.
vitor
parents:
diff changeset
41 /**
d3d0d9cc0e50 Commit last ok'ed parts of QCELP decoder and enable it.
vitor
parents:
diff changeset
42 * 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
43 * needed for LSP to LPC conversion.
d3d0d9cc0e50 Commit last ok'ed parts of QCELP decoder and enable it.
vitor
parents:
diff changeset
44 * 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
45 *
d3d0d9cc0e50 Commit last ok'ed parts of QCELP decoder and enable it.
vitor
parents:
diff changeset
46 * @param lspf line spectral pair frequencies
d3d0d9cc0e50 Commit last ok'ed parts of QCELP decoder and enable it.
vitor
parents:
diff changeset
47 * @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
48 *
d3d0d9cc0e50 Commit last ok'ed parts of QCELP decoder and enable it.
vitor
parents:
diff changeset
49 * 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
50 */
d3d0d9cc0e50 Commit last ok'ed parts of QCELP decoder and enable it.
vitor
parents:
diff changeset
51 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
52 {
d3d0d9cc0e50 Commit last ok'ed parts of QCELP decoder and enable it.
vitor
parents:
diff changeset
53 int i, j;
d3d0d9cc0e50 Commit last ok'ed parts of QCELP decoder and enable it.
vitor
parents:
diff changeset
54
d3d0d9cc0e50 Commit last ok'ed parts of QCELP decoder and enable it.
vitor
parents:
diff changeset
55 f[0] = 1.0;
d3d0d9cc0e50 Commit last ok'ed parts of QCELP decoder and enable it.
vitor
parents:
diff changeset
56 f[1] = -2 * cos(M_PI * lspf[0]);
d3d0d9cc0e50 Commit last ok'ed parts of QCELP decoder and enable it.
vitor
parents:
diff changeset
57 lspf -= 2;
d3d0d9cc0e50 Commit last ok'ed parts of QCELP decoder and enable it.
vitor
parents:
diff changeset
58 for(i=2; i<=lp_half_order; i++)
d3d0d9cc0e50 Commit last ok'ed parts of QCELP decoder and enable it.
vitor
parents:
diff changeset
59 {
d3d0d9cc0e50 Commit last ok'ed parts of QCELP decoder and enable it.
vitor
parents:
diff changeset
60 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
61 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
62 for(j=i-1; j>1; j--)
d3d0d9cc0e50 Commit last ok'ed parts of QCELP decoder and enable it.
vitor
parents:
diff changeset
63 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
64 f[1] += val;
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
d3d0d9cc0e50 Commit last ok'ed parts of QCELP decoder and enable it.
vitor
parents:
diff changeset
68 /**
d3d0d9cc0e50 Commit last ok'ed parts of QCELP decoder and enable it.
vitor
parents:
diff changeset
69 * 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
70 * and performs bandwidth expansion.
d3d0d9cc0e50 Commit last ok'ed parts of QCELP decoder and enable it.
vitor
parents:
diff changeset
71 *
d3d0d9cc0e50 Commit last ok'ed parts of QCELP decoder and enable it.
vitor
parents:
diff changeset
72 * @param lspf line spectral pair frequencies
d3d0d9cc0e50 Commit last ok'ed parts of QCELP decoder and enable it.
vitor
parents:
diff changeset
73 * @param lpc linear predictive coding coefficients
d3d0d9cc0e50 Commit last ok'ed parts of QCELP decoder and enable it.
vitor
parents:
diff changeset
74 *
d3d0d9cc0e50 Commit last ok'ed parts of QCELP decoder and enable it.
vitor
parents:
diff changeset
75 * @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
76 * but it seems to be slower on x86
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 * 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
79 */
d3d0d9cc0e50 Commit last ok'ed parts of QCELP decoder and enable it.
vitor
parents:
diff changeset
80 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
81 {
d3d0d9cc0e50 Commit last ok'ed parts of QCELP decoder and enable it.
vitor
parents:
diff changeset
82 double pa[6], qa[6];
d3d0d9cc0e50 Commit last ok'ed parts of QCELP decoder and enable it.
vitor
parents:
diff changeset
83 int i;
d3d0d9cc0e50 Commit last ok'ed parts of QCELP decoder and enable it.
vitor
parents:
diff changeset
84 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
85
d3d0d9cc0e50 Commit last ok'ed parts of QCELP decoder and enable it.
vitor
parents:
diff changeset
86 lsp2polyf(lspf, pa, 5);
d3d0d9cc0e50 Commit last ok'ed parts of QCELP decoder and enable it.
vitor
parents:
diff changeset
87 lsp2polyf(lspf + 1, qa, 5);
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 for (i=4; i>=0; i--)
d3d0d9cc0e50 Commit last ok'ed parts of QCELP decoder and enable it.
vitor
parents:
diff changeset
90 {
d3d0d9cc0e50 Commit last ok'ed parts of QCELP decoder and enable it.
vitor
parents:
diff changeset
91 double paf = pa[i+1] + pa[i];
d3d0d9cc0e50 Commit last ok'ed parts of QCELP decoder and enable it.
vitor
parents:
diff changeset
92 double qaf = qa[i+1] - qa[i];
d3d0d9cc0e50 Commit last ok'ed parts of QCELP decoder and enable it.
vitor
parents:
diff changeset
93
d3d0d9cc0e50 Commit last ok'ed parts of QCELP decoder and enable it.
vitor
parents:
diff changeset
94 lpc[i ] = paf + qaf;
d3d0d9cc0e50 Commit last ok'ed parts of QCELP decoder and enable it.
vitor
parents:
diff changeset
95 lpc[9-i] = paf - qaf;
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 for (i=0; i<10; i++)
d3d0d9cc0e50 Commit last ok'ed parts of QCELP decoder and enable it.
vitor
parents:
diff changeset
98 {
d3d0d9cc0e50 Commit last ok'ed parts of QCELP decoder and enable it.
vitor
parents:
diff changeset
99 lpc[i] *= bandwith_expansion_coeff;
d3d0d9cc0e50 Commit last ok'ed parts of QCELP decoder and enable it.
vitor
parents:
diff changeset
100 bandwith_expansion_coeff *= QCELP_BANDWITH_EXPANSION_COEFF;
d3d0d9cc0e50 Commit last ok'ed parts of QCELP decoder and enable it.
vitor
parents:
diff changeset
101 }
d3d0d9cc0e50 Commit last ok'ed parts of QCELP decoder and enable it.
vitor
parents:
diff changeset
102 }