[FFmpeg-devel] [PATCH] Common ACELP code & G.729 [4/7] - G.729 core
Michael Niedermayer
michaelni
Wed Sep 17 04:27:51 CEST 2008
On Sun, Sep 07, 2008 at 07:26:46PM +0700, Vladimir Voroshilov wrote:
> 2008/9/4 Vladimir Voroshilov <voroshil at gmail.com>:
> > 2008/9/3 Michael Niedermayer <michaelni at gmx.at>:
> >> On Wed, Sep 03, 2008 at 12:51:30AM +0700, Vladimir Voroshilov wrote:
> >> [...]
> >>> >> +
> >>> >> + /* 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
> >>>
> >>> Splitting was done especially for moving gain_corr_factor variable
> >>> inside "if" statement.
> >>> Otherwise one of the following is required to avoid compiler warning:
> >>>
> >>> 1. "=0" before loop.
> >>> 2. "=0" inside loop in frame erasure case
> >>
> >> i think it fits best inside the if() to complement the other in else
> >
> > Hopefully i understood you correctly. Those peace of code looks enough clean.
> >
> >>
> >>
> >>>
> >>> In both cases those fact that this variable is not used between loop
> >>> iterations is unclear
> >>> So i preferred to split the call to routine and explicitly pass zero
> >>> in frame erasure case cases.
> >>>
> >>>
> >>> P.S. How should i apply ok'ed chunks (since they are not standalone
> >>> parts of code)?
> >>
> >>> As in your reply, without any routine headers, if/else statements/parenthesis ?
> >>
> >> yes, the file isnt compiled yet
> >
> > Ok.
> >
> > Updated patch is attached.
> > 1. removed all postfilter-related code from it (as long as build
> > environment) - will be posted later
> > as separate patches.
> > 2. duplicated entries in format table removed.
> >
>
> Seems i forgot to post updated patch
> after made changes in svn.
[...]
> +#include "g729.h"
> +#include "lsp.h"
> +#include "acelp_math.h"
> +#include "acelp_filters.h"
> +#include "acelp_pitch_delay.h"
> +#include "acelp_vectors.h"
> +#include "g729data.h"
> +
> /**
> * minimum quantized LSF value (3.2.4)
> * 0.005 in Q13
ok
[...]
> +typedef struct
> +{
> + int sample_rate;
> + uint8_t packed_frame_size; ///< input frame size(in bytes)
> + uint8_t unpacked_frame_size;///< output frame size (in bytes)
> + uint8_t fc_indexes_bits; ///< size (in bits) of fixed-codebook index entry
> +
> + /// mr_energy = mean_energy + 10 * log10(2^26 * subframe_size) in (7.13)
> + int mr_energy;
> +} G729_format_description;
ok
[...]
> +static const G729_format_description formats[] =
> +{
> + {8000, 10, 160, 13, 0xf892c,},
> +// Note: may not work
> + {4400, 11, 176, 17, 0xf966b,},
> +};
Is the last parameter really best specified in hex?
[...]
> +/**
> + * \brief Decode LSP coefficients from L0-L3 (3.2.4).
> + * \param lsfq [out] (2.13) decoded LSP coefficients
> + * \param lq_prev [in/out] (2.13) quantized LSF coefficients from previous frames
> + * \param lsf_prev [in/out] (2.13) LSF coefficients from previous frame
> + * \param ma_predictor switched MA predictor of LSP quantizer
> + * \param vq_1st first stage vector of quantizer
> + * \param vq_2nd_low second stage lower vector of LSP quantizer
> + * \param vq_2nd_high second stage higher vector of LSP quantizer
> + */
> +static void g729_lsf_decode(
> + int16_t* lsfq,
> + int16_t lq_prev[MA_NP][10],
> + int16_t* lsf_prev,
> + int16_t ma_predictor,
> + int16_t vq_1st,
> + int16_t vq_2nd_low,
> + int16_t vq_2nd_high)
> +{
> + int i,j,k;
> + static const uint8_t min_distance[2]={10, 5}; //(2.13)
> + int16_t lq[10]; //(2.13)
what does "lq" stand for?
[...]
> + g729_lq_rotate(lq_prev, lq);
> +
> + ff_acelp_reorder_lsf(lsfq, LSFQ_DIFF_MIN, LSFQ_MIN, LSFQ_MAX, 10);
> +}
> +
> +/**
> + * \brief Restore LSP parameters using previous frame data.
> + * \param lsfq [out] (2.13) decoded LSF coefficients
> + * \param lq_prev [in/out] (2.13) quantized LSF coefficients from previous frames
> + * \param ma_predictor_prev MA predictor from previous frame
> + * \param lsf_prev (2.13) LSF coefficients from previous frame
> + */
> +static void g729_lsf_restore_from_previous(
> + int16_t* lsfq,
> + int16_t lq_prev[MA_NP][10],
> + int ma_predictor_prev,
> + const int16_t* lsf_prev)
> +{
> + int16_t lq[10];
> + int i,k,tmp;
> +
> + for(i=0; i<10; i++)
> + lsfq[i] = lsf_prev[i];
memcpy()
> +
> + for(i=0; i<10; i++)
> + {
> + tmp = lsfq[i] << 15;
> +
> + for(k=0; k<MA_NP; k++)
> + tmp -= lq_prev[k][i] * cb_ma_predictor[ma_predictor_prev][k][i];
> +
> + lq[i] = ((tmp >> 15) * cb_ma_predictor_sum_inv[ma_predictor_prev][i]) >> 12;
the cb_ma_predictor_sum_inv table is unneeded division by cb_ma_predictor_sum
can be used
also the code looks a little odd, its subtracting here but adding above ...
> + }
> +
> + g729_lq_rotate(lq_prev, lq);
> +}
g729_lq_rotate() can be factorized out of these 2 functions that are only
called by if/else
[...]
> + if(avctx->channels != 1)
> + {
> + av_log(avctx, AV_LOG_ERROR, "Only mono sound is supported (requested channels: %d).\n", avctx->channels);
> + return AVERROR_NOFMT;
> + }
ok
[...]
> @@ -89,11 +483,42 @@ static inline int g729_get_parity(uint8_t value)
> 14,
> ctx->subframe_size - pitch_delay_int[i]);
>
> + if(ctx->frame_erasure)
> + {
> + ctx->gain_pitch = (29491 * ctx->gain_pitch) >> 15; // 0.9 (0.15)
> + ctx->gain_code = (2007 * ctx->gain_code) >> 11; // 0.98 in (0.11)
> +
> + gain_corr_factor = 0;
> + }
> + else
> + {
> ctx->gain_pitch = cb_gain_1st_8k[parm->gc_1st_index[i]][0] +
> cb_gain_2nd_8k[parm->gc_2nd_index[i]][0];
ok
[...]
> +static int ff_g729_decode_frame(AVCodecContext *avctx,
static functions do not need a ff prefix
> + void *data, int *data_size,
> + const uint8_t *buf, int buf_size)
> +{
> + G729_parameters parm;
> + G729_Context *ctx=avctx->priv_data;
> + int packed_frame_size = formats[ctx->format].packed_frame_size;
> + int unpacked_frame_size = formats[ctx->format].unpacked_frame_size;
vertical align
> + int frame_erasure;
> +
> + if (buf_size<packed_frame_size)
> + {
> + av_log(avctx, AV_LOG_ERROR, "Error processing packet: packet size too small\n");
> + return AVERROR(EIO);
> + }
> + if (*data_size<unpacked_frame_size)
> + {
> + av_log(avctx, AV_LOG_ERROR, "Error processing packet: output buffer too small\n");
> + return AVERROR(EIO);
> + }
ok
[...]
--
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
Let us carefully observe those good qualities wherein our enemies excel us
and endeavor to excel them, by avoiding what is faulty, and imitating what
is excellent in them. -- Plutarch
-------------- 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/20080917/09e3526f/attachment.pgp>
More information about the ffmpeg-devel
mailing list