[FFmpeg-devel] [PATCH] Common ACELP routines (3/3) - LPC decoding routines
Michael Niedermayer
michaelni
Wed Apr 23 02:38:00 CEST 2008
On Tue, Apr 22, 2008 at 01:21:24AM +0700, Vladimir Voroshilov wrote:
> Hi, All
>
> This patch contains several routines related to LP filter coefficients
> decoding (not all, but those which
> looks like AMR's).
[...]
> diff --git a/libavcodec/acelp_lpc.c b/libavcodec/acelp_lpc.c
> new file mode 100644
> index 0000000..65b870d
> --- /dev/null
> +++ b/libavcodec/acelp_lpc.c
lsp.c
[...]
> +void ff_acelp_reorder_lsf(int16_t* lsfq, int16_t lsfq_min_distance, int16_t lsfq_min, int16_t lsfq_max)
> +{
> + int i;
> +
> + lsfq[0] = FFMAX(lsfq[0], lsfq_min); //Is warning required ?
> +
> + for(i=0;i<9; i++)
> + lsfq[i+1] = FFMAX(lsfq[i+1], lsfq[i] + lsfq_min_distance);
simplification stolen from soc/amrnbdec.c:
for(i=0; i<10; i++){
lsf[i] = FFMAX(lsf[i], lsf_min);
lsf_min = lsf[i] + min_distance;
}
also id make lsfq_min_distance and lsfq_min/max int
ahh, and reorder_lsf() in soc/amrnbdec.c is buggy (uninitalized var)
> +
> + lsfq[9] = FFMIN(lsfq[9], lsfq_max);//Is warning required ?
> +}
> +
> +/**
> + * \brief Convert LSF to LSP
> + * \param lsf (Q13) LSF coefficients (0 <= lsf < PI)
ff_acelp_cos() behaves like PI=0x8000 or so IIRC so above is not really
correct
> + * \param lsp [out] (Q15) LSP coefficients (-1 <= lsp < 1)
> + *
> + * \remark It is safe to pass the same array in lsf and lsp parameters
> + */
> +void ff_acelp_lsf2lsp(const int16_t *lsf, int16_t *lsp, int16_t factor)
i slightly prefer that the written to argument is left (lsp, lsf, factor)
same for the other functions (this of course is minor nitpicking ...)
[...]
> +/**
> + * \brief decodes polynomial coefficients from LSP
> + * \param lsp (Q15) LSP coefficients
> + * \param f [out] (Q24) decoded polynomial coefficients
> + */
> +void ff_acelp_lsp2poly(const int16_t* lsp, int* f)
is this function used from outside this file? if not it could be static
> +{
> + int i, j;
> +
> + f[0] = 0x1000000; // 1.0 in Q24
> + f[1] = -lsp[0] << 10; // *2 and Q15 -> Q24
> +
> + for(i=2; i<=5; i++)
> + {
> + f[i] = f[i-2];
> +
> + for(j=i; j>1; j--)
> + f[j] -= (mul_24_15(f[j-1]>>1, lsp[2*i-2])<<2) - f[j-2];
why the >>1 ? our 64bit multiply wont overflow.
> +
> + f[1] -= lsp[2*i-2] << 10;
> + }
> +}
> +
> +/**
> + * \brief LSP to LP conversion (3.2.6)
> + * \param lsp (Q15) LSP coefficients
> + * \param lp [out] (Q12) decoded LP coefficients
> + */
> +void ff_acelp_lsp2lpc(const int16_t* lsp, int16_t* lp)
> +{
> + int i;
> + int f1[6]; // Q24
> + int f2[6]; // Q24
> +
> + ff_acelp_lsp2poly(lsp, f1);
> + ff_acelp_lsp2poly(lsp+1, f2);
> +
> + /* 3.2.6, Equations 25 and 26*/
3.2.6 of g729 ...
[...]
> +/**
> + * \brief Interpolate LSP for the first subframe and convert LSP -> LP for both subframes (3.2.5 and 3.2.6)
> + * \param (Q15) lsp_2nd LSP coefficients of the second subframe
> + * \param (Q15) lsp_prev past LSP coefficients
> + * \param lp_1st [out] (Q12) decoded LP coefficients for 1st subframe
> + * \param lp_2nd [out] (Q12) decoded LP coefficients for second subframe
> + */
> +void ff_acelp_lp_decode(const int16_t* lsp_2nd, const int16_t* lsp_prev, int16_t* lp_1st, int16_t* lp_2nd)
> +{
> + int16_t lsp_1st[10]; // Q15
> + int i;
> +
> + /* LSP values for first subframe (3.2.5, Equation 24)*/
> + for(i=0;i<10;i++)
> + lsp_1st[i] = (lsp_2nd[i] >> 1) + (lsp_prev[i] >> 1);
(a+b)>>1
[...]
--
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
The worst form of inequality is to try to make unequal things equal.
-- Aristotle
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20080423/c181e13d/attachment.pgp>
More information about the ffmpeg-devel
mailing list