[FFmpeg-devel] [PATCH] Common ACELP code & G.729 [2/7] - pitch lag decoding

Michael Niedermayer michaelni
Thu Jun 26 17:17:41 CEST 2008


On Wed, Jun 25, 2008 at 07:33:07PM +0700, Vladimir Voroshilov wrote:
> 2008/6/25 Diego Biurrun <diego at biurrun.de>:
> > On Wed, Jun 25, 2008 at 11:10:13AM +0700, Vladimir Voroshilov wrote:
> 
> [...]
> 
> >> --- /dev/null
> >> +++ b/libavcodec/acelp_pitch_delay.h
> >> @@ -0,0 +1,232 @@
> >> +
> >> +#ifndef FFMPEG_ACELP_PITCH_LAG_H
> >> +#define FFMPEG_ACELP_PITCH_LAG_H
> >
> > You forgot to update the multiple inclusion guard after the rename.
> 
> [...]
> 
> >> +#endif // FFMPEG_ACELP_PITCH_LAG_H
> >
> > Rename.
> 
> Fixed.
[...]
> +void ff_acelp_update_past_gain_erasure(int16_t *quant_energy, int log2_ma_pred_order)
> +{
> +    int avg_gain=quant_energy[(1 << log2_ma_pred_order) - 1]; // (5.10)
> +    int i;
> +
> +    for(i=(1 << log2_ma_pred_order) - 1; i>0; i--)
> +    {
> +        avg_gain       += quant_energy[i-1];
> +        quant_energy[i] = quant_energy[i-1];
> +    }
> +    quant_energy[0] = FFMAX(avg_gain >> log2_ma_pred_order, -10240) - 4096; // -10 and -4 in (5.10)
> +}
> +
> +void ff_acelp_update_past_gain(int16_t* quant_energy, int gain_corr_factor, int ma_pred_order)
> +{
> +    int i;
> +
> +    for(i=ma_pred_order-1; i>0; i--)
> +        quant_energy[i] = quant_energy[i-1];
> +
> +    quant_energy[0] = (24660 * ((ff_log2(gain_corr_factor) >> 2) - (13 << 13))) >> 15;
> +}

ff_acelp_update_past_gain(int16_t* quant_energy, int gain_corr_factor, int log2_ma_pred_order, int erasure)
{
    int avg_gain=quant_energy[(1 << log2_ma_pred_order) - 1]; // (5.10)
    int i;

    for(i=(1 << log2_ma_pred_order) - 1; i>0; i--){
        avg_gain       += quant_energy[i-1];
        quant_energy[i] = quant_energy[i-1];
    }
    if(erasure)
        quant_energy[0] = FFMAX(avg_gain >> log2_ma_pred_order, -10240) - 4096; // -10 and -4 in (5.10)
    else
        quant_energy[0] = (6165 * ((ff_log2(gain_corr_factor) >> 2) - (13 << 13)))>>13
}


> +
> +int16_t ff_acelp_decode_gain_code(
> +    int gain_corr_factor,
> +    const int16_t* fc_v,
> +    int mr_energy,
> +    const int16_t* quant_energy,
> +    const int16_t* ma_prediction_coeff,
> +    int subframe_size,
> +    int ma_pred_order)
> +{
> +    int i;
> +    int energy;
> +    int innov_energy;
> +#ifdef G729_BITEXACT
> +    int exp;
> +#endif
> +
> +    energy = mr_energy << 10;
> +
> +    for(i=0; i<ma_pred_order; i++)
> +        energy += quant_energy[i] * ma_prediction_coeff[i];
> +
> +    innov_energy = sum_of_squares(fc_v, subframe_size, 0, 0);
> +#ifdef G729_BITEXACT
> +    energy +=  MULL(ff_log2(innov_energy), -24660) << 10;     
> +
> +    energy = (5439 * (energy >> 15)) >> 8;           // (0.15) = (0.15) * (7.23)

> +    exp = (energy >> 15);                            // integer part (exponent)
> +    
> +    energy = ((ff_exp2(energy & 0x7fff) + 16) >> 5); // only fraction part of (0.15) and rounding
> +
> +    energy *= gain_corr_factor >> 1;
> +    return bidir_sal(energy, exp - 25);              // energy*2^14 in (3.12) -> energy*2^exp in (14.1)

return bidir_sal(
                    ((ff_exp2(energy & 0x7fff) + 16) >> 5) * (gain_corr_factor >> 1),
                    (energy >> 15) - 25
                );

or any other solution that avoids the second ifdef above

[...]
-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

I wish the Xiph folks would stop pretending they've got something they
do not.  Somehow I fear this will remain a wish. -- M?ns Rullg?rd
-------------- 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/20080626/4af7dd33/attachment.pgp>



More information about the ffmpeg-devel mailing list