diff options
author | Colin McQuillan <m.niloc@googlemail.com> | 2009-08-03 08:37:02 +0000 |
---|---|---|
committer | Robert Swain <robert.swain@gmail.com> | 2009-08-03 08:37:02 +0000 |
commit | 33ae681f5ca9fa9aae82081dd6a6edbe2509f983 (patch) | |
tree | 091f20de691a3115540d9c6582fb84de0d153b5b | |
parent | 1e1e02eacd948572108c78c15d5b3e3bcd94947c (diff) | |
download | ffmpeg-33ae681f5ca9fa9aae82081dd6a6edbe2509f983.tar.gz |
Expose QCELP's floating-point LSP-to-LPC function
qcelp_lsp exported a single function, ff_acelp_lspd2lpc, which was not
specific to qcelp. It can be kept with its fixed-point version
ff_acelp_lsp2lpc in lpc.c.
Patch by Colin McQuillan ( m.niloc googlemail com )
Originally committed as revision 19571 to svn://svn.ffmpeg.org/ffmpeg/trunk
-rw-r--r-- | libavcodec/Makefile | 2 | ||||
-rw-r--r-- | libavcodec/lsp.c | 46 | ||||
-rw-r--r-- | libavcodec/lsp.h | 10 | ||||
-rw-r--r-- | libavcodec/qcelp_lsp.c | 81 | ||||
-rw-r--r-- | libavcodec/qcelpdec.c | 8 |
5 files changed, 58 insertions, 89 deletions
diff --git a/libavcodec/Makefile b/libavcodec/Makefile index c549d20561..3ad54c0cf4 100644 --- a/libavcodec/Makefile +++ b/libavcodec/Makefile @@ -177,7 +177,7 @@ OBJS-$(CONFIG_PNG_ENCODER) += png.o pngenc.o OBJS-$(CONFIG_PPM_DECODER) += pnmenc.o pnm.o OBJS-$(CONFIG_PPM_ENCODER) += pnmenc.o OBJS-$(CONFIG_PTX_DECODER) += ptx.o -OBJS-$(CONFIG_QCELP_DECODER) += qcelpdec.o qcelp_lsp.o celp_math.o celp_filters.o acelp_vectors.o +OBJS-$(CONFIG_QCELP_DECODER) += qcelpdec.o lsp.o celp_math.o celp_filters.o acelp_vectors.o OBJS-$(CONFIG_QDM2_DECODER) += qdm2.o mpegaudiodec.o mpegaudiodecheader.o mpegaudio.o mpegaudiodata.o OBJS-$(CONFIG_QDRAW_DECODER) += qdrw.o OBJS-$(CONFIG_QPEG_DECODER) += qpeg.o diff --git a/libavcodec/lsp.c b/libavcodec/lsp.c index f57f621350..5b5fc1c50e 100644 --- a/libavcodec/lsp.c +++ b/libavcodec/lsp.c @@ -1,6 +1,7 @@ /* * LSP routines for ACELP-based codecs * + * Copyright (c) 2007 Reynaldo H. Verdejo Pinochet (QCELP decoder) * Copyright (c) 2008 Vladimir Voroshilov * * This file is part of FFmpeg. @@ -118,3 +119,48 @@ void ff_acelp_lp_decode(int16_t* lp_1st, int16_t* lp_2nd, const int16_t* lsp_2nd /* LSP values for second subframe (3.2.5 of G.729)*/ ff_acelp_lsp2lpc(lp_2nd, lsp_2nd, lp_order >> 1); } + +/** + * Computes the Pa / (1 + z(-1)) or Qa / (1 - z(-1)) coefficients + * needed for LSP to LPC conversion. + * We only need to calculate the 6 first elements of the polynomial. + * + * @param lsp line spectral pairs in cosine domain + * @param f [out] polynomial input/output as a vector + * + * TIA/EIA/IS-733 2.4.3.3.5-1/2 + */ +static void lsp2polyf(const double *lsp, double *f, int lp_half_order) +{ + int i, j; + + f[0] = 1.0; + f[1] = -2 * lsp[0]; + lsp -= 2; + for(i=2; i<=lp_half_order; i++) + { + double val = -2 * lsp[2*i]; + f[i] = val * f[i-1] + 2*f[i-2]; + for(j=i-1; j>1; j--) + f[j] += f[j-1] * val + f[j-2]; + f[1] += val; + } +} + +void ff_acelp_lspd2lpc(const double *lsp, float *lpc) +{ + double pa[6], qa[6]; + int i; + + lsp2polyf(lsp, pa, 5); + lsp2polyf(lsp + 1, qa, 5); + + for (i=4; i>=0; i--) + { + double paf = pa[i+1] + pa[i]; + double qaf = qa[i+1] - qa[i]; + + lpc[i ] = 0.5*(paf+qaf); + lpc[9-i] = 0.5*(paf-qaf); + } +} diff --git a/libavcodec/lsp.h b/libavcodec/lsp.h index 2337756406..0fa585016a 100644 --- a/libavcodec/lsp.h +++ b/libavcodec/lsp.h @@ -67,4 +67,14 @@ void ff_acelp_lsp2lpc(int16_t* lp, const int16_t* lsp, int lp_half_order); */ void ff_acelp_lp_decode(int16_t* lp_1st, int16_t* lp_2nd, const int16_t* lsp_2nd, const int16_t* lsp_prev, int lp_order); +/** + * Reconstructs LPC coefficients from the line spectral pair frequencies. + * + * @param lsp line spectral pairs in cosine domain + * @param lpc linear predictive coding coefficients + * + * TIA/EIA/IS-733 2.4.3.3.5 + */ +void ff_acelp_lspd2lpc(const double *lsp, float *lpc); + #endif /* AVCODEC_LSP_H */ diff --git a/libavcodec/qcelp_lsp.c b/libavcodec/qcelp_lsp.c deleted file mode 100644 index 6823ad8069..0000000000 --- a/libavcodec/qcelp_lsp.c +++ /dev/null @@ -1,81 +0,0 @@ -/* - * QCELP decoder - * Copyright (c) 2007 Reynaldo H. Verdejo Pinochet - * - * This file is part of FFmpeg. - * - * FFmpeg is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * FFmpeg is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with FFmpeg; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -/** - * @file libavcodec/qcelp_lsp.c - * QCELP decoder - * @author Reynaldo H. Verdejo Pinochet - * @remark FFmpeg merging spearheaded by Kenan Gillet - * @remark Development mentored by Benjamin Larson - */ - -#include "libavutil/mathematics.h" - -/** - * Computes the Pa / (1 + z(-1)) or Qa / (1 - z(-1)) coefficients - * needed for LSP to LPC conversion. - * We only need to calculate the 6 first elements of the polynomial. - * - * @param lsp line spectral pairs in cosine domain - * @param f [out] polynomial input/output as a vector - * - * TIA/EIA/IS-733 2.4.3.3.5-1/2 - */ -static void lsp2polyf(const double *lsp, double *f, int lp_half_order) -{ - int i, j; - - f[0] = 1.0; - f[1] = -2 * lsp[0]; - lsp -= 2; - for(i=2; i<=lp_half_order; i++) - { - double val = -2 * lsp[2*i]; - f[i] = val * f[i-1] + 2*f[i-2]; - for(j=i-1; j>1; j--) - f[j] += f[j-1] * val + f[j-2]; - f[1] += val; - } -} - -/** - * Reconstructs LPC coefficients from the line spectral pair frequencies. - * - * @param lsp line spectral pairs in cosine domain - * @param lpc linear predictive coding coefficients - */ -void ff_acelp_lspd2lpc(const double *lsp, float *lpc) -{ - double pa[6], qa[6]; - int i; - - lsp2polyf(lsp, pa, 5); - lsp2polyf(lsp + 1, qa, 5); - - for (i=4; i>=0; i--) - { - double paf = pa[i+1] + pa[i]; - double qaf = qa[i+1] - qa[i]; - - lpc[i ] = 0.5*(paf+qaf); - lpc[9-i] = 0.5*(paf-qaf); - } -} diff --git a/libavcodec/qcelpdec.c b/libavcodec/qcelpdec.c index 4ba42a1be1..0df30daf34 100644 --- a/libavcodec/qcelpdec.c +++ b/libavcodec/qcelpdec.c @@ -38,6 +38,7 @@ #include "celp_math.h" #include "celp_filters.h" #include "acelp_vectors.h" +#include "lsp.h" #undef NDEBUG #include <assert.h> @@ -76,13 +77,6 @@ typedef struct } QCELPContext; /** - * Reconstructs LPC coefficients from the line spectral pair frequencies. - * - * TIA/EIA/IS-733 2.4.3.3.5 - */ -void ff_acelp_lspd2lpc(const double *lsp, float *lpc); - -/** * Initialize the speech codec according to the specification. * * TIA/EIA/IS-733 2.4.9 |