[FFmpeg-devel] [PATCH] Common ACELP code & G.729 [1/7] - filters

Michael Niedermayer michaelni
Sat May 3 14:23:13 CEST 2008


On Sat, May 03, 2008 at 03:24:54PM +0700, Vladimir Voroshilov wrote:
> Michael Niedermayer wrote: 
[...]
> +void ff_acelp_convolve_circ(
> +        int16_t* fc_out,
> +        const int16_t* fc_in,
> +        const int16_t* filter,
> +        int subframe_size)
> +{
> +    int i, k;
> +
> +    memset(fc_out, 0, subframe_size * sizeof(int16_t));
> +
> +    /* Since there are few pulses over all subframe (i.e. almost all
> +       fc_in[i] are zero, in case of G.729D it is only two non-zero
> +       samples of total 40), it is faster to swap two loops and process
> +       non-zero samples only. This will reduce number of multiplications
> +       from 40*40 to 2*40 for G.729D */

doesnt ff_acelp_fc_enchance_harmonics() increase the number of non 0
elements above 2 ?


> +    for(i=0; i<subframe_size; i++)
> +    {
> +        if(fc_in[i])
> +        {
> +            for(k=0; k<i; k++)
> +                fc_out[k] += (fc_in[i] * filter[subframe_size + k - i]) >> 15;
> +
> +            for(k=i; k<subframe_size; k++)
> +                fc_out[k] += (fc_in[i] * filter[k - i]) >> 15;
> +        }
> +    }
> +}
> +
> +int ff_acelp_lp_synthesis_filter(
> +        int16_t *out,
> +        const int16_t* filter_coeffs,
> +        const int16_t* in,
> +        int buffer_length,
> +        int filter_length,
> +        int stop_on_overflow)
> +{
> +    int i,n;

> +    int sum;
> +
> +    for(n=0; n<buffer_length; n++)
> +    {
> +        sum = 0x800;

declaration and initializatio can be merged


[...]
> +void ff_acelp_weighted_filter(
> +        int16_t *out,
> +        const int16_t* in,
> +        const int16_t *weight_pow,
> +        int filter_length)
> +{
> +    int n;
> +    for(n=0; n<filter_length; n++)
> +    {
> +        /* (3.12) = (0.15) * (3.12) with rounding */
> +        out[n] = (in[n] * weight_pow[n] + 0x4000) >> 15;
> +    }

{} are superflous, and the comment would be more readable at the right


> +}
> +
> +void ff_acelp_high_pass_filter(
> +        int16_t* out,
> +        int16_t* hpf_z,
> +        int* hpf_f,
> +        const int16_t* in,
> +        int length)
> +{
> +    int i;
> +
> +    for(i=0; i<length; i++)
> +    {
> +        memmove(hpf_z + 1, hpf_z, 2 * sizeof(hpf_z[0]));
> +        hpf_z[0] = in[i];
> +        /* (14.13) = (13.13) * (1.13) */
> +        hpf_f[0] =  MULL(hpf_f[1], 15836);
> +        /* (13.13) = (13.13) * (0.13) */
> +        hpf_f[0] += MULL(hpf_f[2], -7667);
> +        /* (14.13) = (0.13) * (14.0) */
> +        hpf_f[0] += 7699 * (hpf_z[0] - 2*hpf_z[1] + hpf_z[2]);
> +
> +        /* Multiplication by 2 with rounding can cause short type
> +           overflow, thus clipping is required. */
> +
> +        /* (15.0) = 2 * (13.13) = (14.13) */
> +        out[i] = av_clip_int16((hpf_f[0] + 0x800) >> 12);

Please put the comments to the right of the code and vertically aligned, this
is very hard to read with them intermingled with the code.


[...]
> +/**
> + * \brief Calculates coefficients of weighted A(z/weight) filter
> + * \param out [out] resulted weighted A(z/weight)
> + *                  filter (-0x8000 <= (3.12) < 0x8000)
> + * \param in source filter (-0x8000 <= (3.12) < 0x8000)
> + * \param weight_pow array containing weight^i (-0x8000 <= (0.15) < 0x8000)
> + * \param filter_length filter length (11 for 10th order LP filter)
> + *

> + * out[i]=weight^i*in[i] , i=0..9

this does no longer match what the function does.


> + */
> +void ff_acelp_weighted_filter(
> +        int16_t *out,
> +        const int16_t* in,
> +        const int16_t *weight_pow,
> +        int filter_length);

> +
> +/**
> + * \brief high-pass filtering and upscaling (4.2.5 of G.729)

just G729 ? or is it also used by others?


> + * \param out [out] output buffer for filtered speech data
> + * \param hpf_z [in/out] filter data from previous frames
> + * \param hpf_f [in/out] past filtered data from previous
> + *                       frames (-0x20000000 <= (14.13) < 0x20000000)
> + * \param in speech data to process
> + * \param length input data size
> + *
> + * Filter has cut-off frequency 100Hz

the exact filter equation would also be nice ...

[...]
-- 
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/20080503/6963fa2a/attachment.pgp>



More information about the ffmpeg-devel mailing list