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

Vladimir Voroshilov voroshil
Sun May 11 16:42:26 CEST 2008


2008/5/10 Michael Niedermayer <michaelni at gmx.at>:
> On Fri, May 09, 2008 at 01:31:02PM +0700, Vladimir Voroshilov wrote:
>> Michael Niedermayer wrote:
>> > On Fri, May 02, 2008 at 06:36:34PM +0700, Vladimir Voroshilov wrote:

[...]

>> +int ff_acelp_decode_lag3_2nd_8_4_bits(
>> +        int ac_index,
>> +        int pitch_lag_min)
>> +{
>> +    ac_index &= 0xf;
>> +
>> +    if(ac_index < 4)
>> +        return 3*(ac_index + pitch_lag_min) + 1;
>> +    else if(ac_index < 12)
>> +        return 3*pitch_lag_min + ac_index + 7;
>> +    else
>> +        return 3*(ac_index + pitch_lag_min) - 17;
>> +}
>
> if ac_index is 4 bits as the doxy says, then the & 0xf should not be needed

ok

>> +void ff_acelp_update_past_gain_erasure(int16_t *quant_energy, int ma_pred_order)
>> +{
>> +    int avg_gain=quant_energy[ma_pred_order-1]; // (5.10)
>> +    int i;
>> +
>> +    /* 4.4.3. Equation 95 of G.729 */
>> +    for(i=ma_pred_order-1; i>0; i--)
>> +    {
>> +        avg_gain       += quant_energy[i-1];
>> +        quant_energy[i] = quant_energy[i-1];
>> +    }
>> +av_log(NULL, AV_LOG_ERROR, "%d %d %d\n", ma_pred_order, (avg_gain>>2), (avg_gain/ma_pred_order));
>
>> +    quant_energy[0] = FFMAX((avg_gain / ma_pred_order) - 4096, -14336); // -14 in (5.10)
>> +//    quant_energy[0] = FFMAX((avg_gain >> 2) - 4096, -14336); // -14 in (5.10)
>
> why the commented out line?

Bitexact code. In attached patch it is enclosed into #ifdef

> and
> quant_energy[0] = FFMAX(avg_gain / ma_pred_order, -10240) - 4096;
> looks nicer to me

ok

>> +void ff_acelp_update_past_gain(int16_t* quant_energy, int gain_corr_factor, int ma_pred_order)
>> +{
>> +    int i;
>> +
>
>> +    // shift prediction energy vector
>> +    for(i=ma_pred_order-1; i>0; i--)
>> +        quant_energy[i] = quant_energy[i-1];
>
> duplicate of above

hm. I don't see any advantage of separating one memmove
into standalone routine (perhaps i should convert those two line
 into memove), because it can not reuse one of two those
routines from another without reduntant calculations.

[...]

>> +    energy =  MULL(ff_log2(energy),       -24660);
>
>> +    energy += MULL(ff_log2(subframe_size), 24660);
>> +    energy += 0x9c888; // 24660 * 26
>> +    energy += mean_energy;
>> +
>> +#ifdef G729_BITEXACT
>> +    /*
>> +       Reference code uses a constant instead of the two previous lines.
>> +       That value (due to 2^6 rounding) differs by 2 from code above.
>> +       Subtracting 2 from energy makes the result be bit-equal with
>> +       the reference code.
>> +    */
>> +    energy -= 2;
>> +#endif
>
> wouldnt it be easier to just pass the sum of these as argument?

ok. moved to g729dec.c with comment.

[...]

>> +    /*
>> +      The following code will calculate energy*2^14 instead of energy*2^exp
>> +      due to the recent change of the ineger part of energy_int.
>> +      This is done to avoid overflow. Result fits into 16 bit.
>> +    */
>> +    exp = (energy >> 15);             // integer part (exponent)
>> +    // Only fraction part of (0.15) and rounding
>
>> +    energy = ((ff_exp2(energy & 0x7fff) + 16) >> 5) & 0x7fff;
>
> is the second & 0x7fff needed?

no, removed.

>
>
>> +
>> +    // apply correction
>> +    energy *= gain_corr_factor >> 1; // energy*2^14 in (3.12)
>> +
>
>> +    // energy*2^14 in (3.12) -> energy*2^exp in (14.1)
>> +    if(exp > 25)
>> +        energy <<= exp - 25;
>> +    else
>> +        energy >>= 25 - exp;
>
> seperate function

done.


-- 
Regards,
Vladimir Voroshilov mailto:voroshil at gmail.com
JID: voroshil at gmail.com, voroshil at jabber.ru
ICQ: 95587719
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 02_acelp_lag49.diff
Type: text/x-diff
Size: 13767 bytes
Desc: not available
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20080511/dec80b3e/attachment.diff>



More information about the ffmpeg-devel mailing list