[FFmpeg-devel] make ff_qcelp_lspf2lpc more general
Kenan Gillet
kenan.gillet
Wed Feb 25 22:11:04 CET 2009
On Feb 25, 2009, at 12:48 PM, Reynaldo H. Verdejo Pinochet wrote:
> Hello Kenan, sorry for taking this long to reply to your mail.
>
> Kenan Gillet wrote:
>> the patch split the specific code for QCELP back into qcelpdec.c.
>> It allows to reuse the code in the amr-nb SOC decoder.
>
> Patch is OK but it doesn't apply cleanly anymore. You have an small
> lsf/lspf typo here though:
>
> Index: libavcodec/qcelpdec.c
> ===================================================================
> - --- libavcodec/qcelpdec.c (revision 16645)
> +++ libavcodec/qcelpdec.c (working copy)
> @@ -79,7 +79,7 @@
> *
> * TIA/EIA/IS-733 2.4.3.3.5
> */
> - -void ff_qcelp_lspf2lpc(const float *lspf, float *lpc);
> +void ff_qcelp_lspf2lpc(const double *lsf, float *lpc);
>
> Anyway, I'm attaching an updated patch I should be commiting
> tomorrow.
>
> Bests
> - --
> Reynaldo
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.9 (GNU/Linux)
>
> iEYEARECAAYFAkmlroYACgkQwY4HfzEURSouzQCdEjMVbUd+M6ljIT2iZ+wjVs38
> dfEAn1Q3xO9SF8G1PEmZucOIdy2mPKcP
> =IbSU
> -----END PGP SIGNATURE-----
> Index: libavcodec/qcelp_lsp.c
> ===================================================================
> --- libavcodec/qcelp_lsp.c (revision 17591)
> +++ libavcodec/qcelp_lsp.c (working copy)
> @@ -30,15 +30,6 @@
> #include "libavutil/mathematics.h"
>
> /**
> - * initial coefficient to perform bandwidth expansion on LPC
> - *
> - * @note: 0.9883 looks like an approximation of 253/256.
> - *
> - * TIA/EIA/IS-733 2.4.3.3.6 6
> - */
> -#define QCELP_BANDWITH_EXPANSION_COEFF 0.9883
> -
> -/**
> * 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.
> @@ -48,16 +39,16 @@
> *
> * TIA/EIA/IS-733 2.4.3.3.5-1/2
> */
> -static void lsp2polyf(const float *lspf, double *f, int
> lp_half_order)
> +static void lsp2polyf(const double *lspf, double *f, int
> lp_half_order)
> {
> int i, j;
>
> f[0] = 1.0;
> - f[1] = -2 * cos(M_PI * lspf[0]);
> + f[1] = -2 * lspf[0];
> lspf -= 2;
> for(i=2; i<=lp_half_order; i++)
> {
> - double val = -2 * cos(M_PI * lspf[2*i]);
> + double val = -2 * lspf[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];
> @@ -66,22 +57,17 @@
> }
>
> /**
> - * Reconstructs LPC coefficients from the line spectral pair
> frequencies
> - * and performs bandwidth expansion.
> + * Reconstructs LPC coefficients from the line spectral pair
> frequencies.
> *
> * @param lspf line spectral pair frequencies
> * @param lpc linear predictive coding coefficients
> *
> - * @note: bandwith_expansion_coeff could be precalculated into a
> table
> - * but it seems to be slower on x86
> - *
> * TIA/EIA/IS-733 2.4.3.3.5
> */
> -void ff_qcelp_lspf2lpc(const float *lspf, float *lpc)
> +void ff_qcelp_lspf2lpc(const double *lspf, float *lpc)
> {
> double pa[6], qa[6];
> int i;
> - double bandwith_expansion_coeff =
> QCELP_BANDWITH_EXPANSION_COEFF * 0.5;
>
> lsp2polyf(lspf, pa, 5);
> lsp2polyf(lspf + 1, qa, 5);
> @@ -91,12 +77,7 @@
> double paf = pa[i+1] + pa[i];
> double qaf = qa[i+1] - qa[i];
>
> - lpc[i ] = paf + qaf;
> - lpc[9-i] = paf - qaf;
> + lpc[i ] = 0.5*(paf+qaf);
> + lpc[9-i] = 0.5*(paf-qaf);
> }
> - for (i=0; i<10; i++)
> - {
> - lpc[i] *= bandwith_expansion_coeff;
> - bandwith_expansion_coeff *= QCELP_BANDWITH_EXPANSION_COEFF;
> - }
> }
> Index: libavcodec/qcelpdata.h
> ===================================================================
> --- libavcodec/qcelpdata.h (revision 17591)
> +++ libavcodec/qcelpdata.h (working copy)
> @@ -550,4 +550,13 @@
> */
> #define QCELP_LSP_OCTAVE_PREDICTOR 29.0/32
>
> +/**
> + * initial coefficient to perform bandwidth expansion on LPC
> + *
> + * @note: 0.9883 looks like an approximation of 253/256.
> + *
> + * TIA/EIA/IS-733 2.4.3.3.6 6
> + */
> +#define QCELP_BANDWITH_EXPANSION_COEFF 0.9883
> +
> #endif /* AVCODEC_QCELPDATA_H */
> Index: libavcodec/qcelpdec.c
> ===================================================================
> --- libavcodec/qcelpdec.c (revision 17591)
> +++ libavcodec/qcelpdec.c (working copy)
> @@ -79,7 +79,7 @@
> *
> * TIA/EIA/IS-733 2.4.3.3.5
> */
> -void ff_qcelp_lspf2lpc(const float *lspf, float *lpc);
> +void ff_qcelp_lspf2lpc(const double *lspf, float *lpc);
>
> static void weighted_vector_sumf(float *out, const float *in_a,
> const float *in_b, float
> weight_coeff_a,
> @@ -585,6 +585,36 @@
> }
>
> /**
> + * Reconstructs LPC coefficients from the line spectral pair
> frequencies
> + * and performs bandwidth expansion.
> + *
> + * @param lspf line spectral pair frequencies
> + * @param lpc linear predictive coding coefficients
> + *
> + * @note: bandwith_expansion_coeff could be precalculated into a
> table
> + * but it seems to be slower on x86
> + *
> + * TIA/EIA/IS-733 2.4.3.3.5
> + */
> +void lspf2lpc(const float *lspf, float *lpc)
> +{
> + double lsf[10];
> + double bandwith_expansion_coeff = -
> QCELP_BANDWITH_EXPANSION_COEFF;
should be now
double bandwith_expansion_coeff = QCELP_BANDWITH_EXPANSION_COEFF;
after r17562
I did not have time to test it yet,
could you hold the commit until i double check it until later today?
thanks
Kenan
More information about the ffmpeg-devel
mailing list