[FFmpeg-devel] make ff_qcelp_lspf2lpc more general
Kenan Gillet
kenan.gillet
Thu Feb 26 01:56:46 CET 2009
On Feb 25, 2009, at 12:48 PM, Reynaldo H. Verdejo Pinochet wrote:
> [...]
>
> 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)
was thinking of renaming it ff_celp_lspf2lpc since it is not anymore
related to only qcelp.
>
> {
> 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;
i tested it and u definitely need to drop the negative sign
double bandwith_expansion_coeff = QCELP_BANDWITH_EXPANSION_COEFF;
>
> + int i;
> +
> + for (i=0; i<10; i++)
> + lsf[i] = cos(M_PI * lspf[i]);
> +
> + ff_qcelp_lspf2lpc(lsf, lpc);
> +
> + for (i=0; i<10; i++)
> + {
> + lpc[i] *= bandwith_expansion_coeff;
> + bandwith_expansion_coeff *= QCELP_BANDWITH_EXPANSION_COEFF;
> + }
> +}
> +
> +/**
> * Interpolates LSP frequencies and computes LPC coefficients
> * for a given bitrate & pitch subframe.
> *
> @@ -612,12 +642,12 @@
> {
> weighted_vector_sumf(interpolated_lspf, curr_lspf, q-
> >prev_lspf,
> weight, 1.0 - weight, 10);
> - ff_qcelp_lspf2lpc(interpolated_lspf, lpc);
> + lspf2lpc(interpolated_lspf, lpc);
> }else if(q->bitrate >= RATE_QUARTER ||
> (q->bitrate == I_F_Q && !subframe_num))
> - ff_qcelp_lspf2lpc(curr_lspf, lpc);
> + lspf2lpc(curr_lspf, lpc);
> else if(q->bitrate == SILENCE && !subframe_num)
> - ff_qcelp_lspf2lpc(q->prev_lspf, lpc);
> + lspf2lpc(q->prev_lspf, lpc);
> }
>
> static qcelp_packet_rate buf_size2bitrate(const int buf_size)
on another note, it would be nice to split the commit into:
- splitting ff_qcelp_lspf2lpc into ff_qcelp_lspf2lpc(QCELP specific) +
ff_celp_lspf2lpc(any CELP)
like in [1]
- moving the QCELP specific code to qcelpdec.c and qcelpdata.h
what do you think?
Kenan
[1] http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/2009-February/063583.html
More information about the ffmpeg-devel
mailing list