[FFmpeg-devel] [PATCH] Common ACELP code & G.729 [4/7] - G.729 core

Michael Niedermayer michaelni
Tue Sep 2 13:59:10 CEST 2008


On Wed, Aug 27, 2008 at 03:10:48AM +0700, Vladimir Voroshilov wrote:
> 2008/8/26 Michael Niedermayer <michaelni at gmx.at>:
> > On Sat, Aug 23, 2008 at 08:42:02PM +0700, Vladimir Voroshilov wrote:
> >> Updated after recent changes in SVN
> 
> 
> >> +    int16_t gain_pitch;         ///< (1.14) pitch gain of previous subframe (3.8) [SHARP_MIN ... SHARP_MAX]
> > [...]
> >> +    int16_t pitch_sharp;        ///< pitch sharpening of the previous frame
> >
> > these 2 variables are redundant, one can be removed
> 
> fixed
> 
> >> +        if(ctx->frame_erasure)
> >> +        {
> >> +            ctx->gain_pitch = FFMIN((29491 * ctx->gain_pitch) >> 15, 29491); // 0.9 (0.15)
> >
> >> +            ctx->gain_code  = (8028 * ctx->gain_code) >> 13; // 0.98 in (2.13)
> >
> > 2007 >> 11
> 
> fixed
[...]
> +typedef struct
> +{
> +    G729_formats format;        ///< format index from formats array
> +    int subframe_size;          ///< number of samples produced from one subframe
> +    int frame_erasure;          ///< frame erasure detected during decoding
> +    int bad_pitch;              ///< parity check failed
> +
> +    /// past excitation signal buffer
> +    int16_t exc_base[2*MAX_SUBFRAME_SIZE+PITCH_DELAY_MAX+INTERPOL_LEN];
> +
> +    int16_t* exc;               ///< start of past excitation data in buffer
> +    int pitch_delay_int_prev;   ///< integer part of previous subframe's pitch delay (4.1.3)
> +    int16_t lq_prev[MA_NP][10]; ///< (2.13) LSP quantizer output (3.2.4)
> +    int16_t lsp_prev[10];       ///< (0.15) LSP coefficients from previous frame (3.2.5)
> +    int16_t lsf_prev[10];       ///< (2.13) LSF coefficients from previous frame
> +    int16_t quant_energy[4];    ///< (5.10) past quantized energy

> +    int16_t gain_pitch;         ///< (1.14) pitch gain of previous subframe (3.8) [SHARP_MIN ... SHARP_MAX]

what is the "[SHARP_MIN ... SHARP_MAX]" supposed to mean?


[...]
> +static const G729_format_description formats[] =
> +{
> +  {8000, 10, 160, 5, 1, GC_1ST_IDX_BITS_8K,  GC_2ND_IDX_BITS_8K,  4, 13, 0xf892c,},
> +// Note: may not work
> +  {4400, 11, 176, 5, 1, GC_1ST_IDX_BITS_8K,  GC_2ND_IDX_BITS_8K,  4, 17, 0xf966b,},
> +};

The parts that are equal between both do not need to be in the struct.


[...]
> +/**
> + * \brief Calculate parity bit (3.7.2 of G.729).
> + * \param ac_index_1st adaptive codebook index for first subframe
> + *
> + * \return parity bit
> + */
> +static inline int g729_get_parity(uint8_t ac_index_1st)
> +{
> +    /* Parity is calculated on six most significant bits of P1. */


/**
 * Get parity bit of bit 2..7.
 */


> +   return (0x6996966996696996ULL >> (ac_index_1st >> 2)) & 1;
> +}

ok


[...]
> +        /*
> +          This filter enhances harmonic components of the fixed-codebook vector to
> +          improve the quality of the reconstructed speech.
> +         
> +                     / fc_v[i],                                    i < pitch_delay

traling whitespace


> +          fc_v[i] = <
> +                     \ fc_v[i] + gain_pitch * fc_v[i-pitch_delay], i >= pitch_delay
> +        */


> +        ff_acelp_weighted_vector_sum(
> +                fc + pitch_delay_int[i],
> +                fc + pitch_delay_int[i],
> +                fc,
> +                1 << 14,
> +                av_clip(ctx->gain_pitch, SHARP_MIN, SHARP_MAX),
> +                0,
> +                14,
> +                ctx->subframe_size - pitch_delay_int[i]);

ok


> +
> +        if(ctx->frame_erasure)
> +        {

> +            ctx->gain_pitch = FFMIN((29491 * ctx->gain_pitch) >> 15, 29491); // 0.9 (0.15)

(FFMIN(ctx->gain_pitch, 1<<15)*29491)>>15


> +            ctx->gain_code  = (2007 * ctx->gain_code) >> 11;                 // 0.98 in (0.11)
> +
> +            ff_acelp_update_past_gain(ctx->quant_energy, 0, 2, ctx->frame_erasure);
> +        }
> +        else
> +        {
> +            int gain_corr_factor;        // (2.13)
> +


> +            ctx->gain_pitch  = cb_gain_1st_8k[parm->gc_1st_index[i]][0] +
> +                               cb_gain_2nd_8k[parm->gc_2nd_index[i]][0];
> +            gain_corr_factor = cb_gain_1st_8k[parm->gc_1st_index[i]][1] +
> +                               cb_gain_2nd_8k[parm->gc_2nd_index[i]][1];

ok


> +
> +            /* Decode the fixed-codebook gain. */
> +            ctx->gain_code = ff_acelp_decode_gain_code(
> +                    gain_corr_factor,
> +                    fc,
> +                    formats[ctx->format].mr_energy,
> +                    ctx->quant_energy,
> +                    ma_prediction_coeff,
> +                    ctx->subframe_size,
> +                    4);
> +            ff_acelp_update_past_gain(ctx->quant_energy, gain_corr_factor, 2, ctx->frame_erasure);
> +        }

ff_acelp_update_past_gain can be factored out of the if/else


> +
> +        /* Routine requires rounding to lowest. */
> +        ff_acelp_interpolate(
> +                ctx->exc + i*ctx->subframe_size,
> +                ctx->exc + i*ctx->subframe_size - pitch_delay_3x/3,
> +                ff_acelp_interp_filter,
> +                6,
> +                (pitch_delay_3x%3)<<1,
> +                10,
> +                ctx->subframe_size);
> +


> +        ff_acelp_weighted_vector_sum(
> +                ctx->exc + i * ctx->subframe_size,
> +                ctx->exc + i * ctx->subframe_size,
> +                fc,
> +                (!voicing && ctx->frame_erasure) ? 0 : ctx->gain_pitch,
> +                ( voicing && ctx->frame_erasure) ? 0 : ctx->gain_code,
> +                1<<13,
> +                14,
> +                ctx->subframe_size);

ok


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

I count him braver who overcomes his desires than him who conquers his
enemies for the hardest victory is over self. -- 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/20080902/12519191/attachment.pgp>



More information about the ffmpeg-devel mailing list