[FFmpeg-devel] [PATCH] G.729 Frame erasure support for LSF decoding
Vladimir Voroshilov
voroshil
Thu Jun 25 13:55:38 CEST 2009
2009/6/25 Michael Niedermayer <michaelni at gmx.at>:
> On Thu, Jun 25, 2009 at 06:20:53PM +0700, Vladimir Voroshilov wrote:
>> 2009/6/25 Michael Niedermayer <michaelni at gmx.at>:
> [...]
>> >> diff --git ffmpeg-r19260/libavcodec/g729data.h ffmpeg-r19260_v171/libavcodec/g729data.h
>> >> index 1d64553..02d0b93 100644
>> >> --- ffmpeg-r19260/libavcodec/g729data.h
>> >> +++ ffmpeg-r19260_v171/libavcodec/g729data.h
>> >> @@ -268,6 +268,11 @@ static const int16_t cb_ma_predictor_sum[2][10] = { /* (0.15) */
>> >> ? ?{14585, 18333, 19772, 17344, 16426, 16459, 15155, 15220, 16043, 15708}
>> >> ?};
>> >>
>> >> +static const int16_t cb_ma_predictor_sum_inv[2][10] = { /* (3.12) */
>> >> + ?{17210, 15888, 16357, 16183, 16516, 15833, 15888, 15421, 14840, 15597},
>> >> + ?{ 9202, ?7320, ?6788, ?7738, ?8170, ?8154, ?8856, ?8818, ?8366, ?8544}
>> >> +};
>> >> +
>> >> ?/**
>> >> ? * initial LSP coefficients belongs to virtual frame preceding ?the
>> >> ? * first frame of the stream
>> >
>> >> diff --git ffmpeg-r19260/libavcodec/g729dec.c ffmpeg-r19260_v171/libavcodec/g729dec.c
>> >> index 628aee0..baf8a08 100644
>> >> --- ffmpeg-r19260/libavcodec/g729dec.c
>> >> +++ ffmpeg-r19260_v171/libavcodec/g729dec.c
>> >> @@ -88,6 +88,8 @@ typedef struct {
>> >> ? ? ?int16_t lsfq[10]; ? ? ? ? ? ///< (2.13) quantized LSF coefficients from previous frame
>> >> ? ? ?int16_t lsp_buf[2][10]; ? ? ///< (0.15) LSP coefficients (previous and current frames) (3.2.5)
>> >> ? ? ?int16_t *lsp[2]; ? ? ? ? ? ?///< pointers to lsp_buf
>> >> +
>> >> + ? ?int ma_predictor; ? ? ? ? ? ///< switched MA predictor of LSP quantizer
>> >> ?} ?G729Context;
>> >>
>> >> ?static const G729FormatDescription format_g729_8k = {
>> >
>> > this change looks unneeded
>>
>> It does.
>>
>> I have to keep MA predictor from last good frame.
>> It is used for past quantizer output computation.
>
> if it is used and represents the previous, prev or previous should be in its
> name
Ok. Will add to avoid confusing.
>
>
>>
>> >
>> >
>> >> @@ -155,13 +157,26 @@ static void lsf_decode(int16_t* lsfq, int16_t* past_quantizer_outputs[MA_NP + 1]
>> >> ? ? ? ? ?lsfq[i] = sum >> 15;
>> >> ? ? ?}
>> >>
>> >> - ? ?/* Rotate past_quantizer_outputs. */
>> >> - ? ?memmove(past_quantizer_outputs + 1, past_quantizer_outputs, MA_NP * sizeof(int16_t*));
>> >> - ? ?past_quantizer_outputs[0] = quantizer_output;
>> >> -
>> >> ? ? ?ff_acelp_reorder_lsf(lsfq, LSFQ_DIFF_MIN, LSFQ_MIN, LSFQ_MAX, 10);
>> >> ?}
>> >>
>
>> >> +static void lsf_restore_from_previous(int16_t* lsfq,
>> >> + ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?int16_t* past_quantizer_outputs[MA_NP + 1],
>> >> + ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?int ma_predictor_prev)
>> >> +{
>> >> + ? ?int16_t* quantizer_output = past_quantizer_outputs[MA_NP];
>> >> + ? ?int i,k;
>> >> +
>> >> + ? ?for (i = 0; i < 10; i++) {
>> >> + ? ? ? ?int tmp = lsfq[i] << 15;
>> >> +
>> >> + ? ? ? ?for (k = 0; k < MA_NP; k++)
>> >> + ? ? ? ? ? ?tmp -= past_quantizer_outputs[k][i] * cb_ma_predictor[ma_predictor_prev][k][i];
>> >> +
>> >> + ? ? ? ?quantizer_output[i] = ((tmp >> 15) * cb_ma_predictor_sum_inv[ma_predictor_prev][i]) >> 12;
>> >> + ? ?}
>> >> +}
>> >
>> > this code still is practically the same as lsf_decode()
>>
>> It does opposite calculation.
>> Then lsf_decode calculates LSF from MA predictor and past_quantizer_output.
>> lsdf_restore_from_previous calculated past_quantizer output from last
>> LSF and _last
>> good_ MA predictor. Merging them together will not make understanding
>> things better, imho.
>
> if the code restores a value that was previously known, simply storing that
> value in the context seems a cleaner choice
> if not the word "restore" does not belong into this anywhere
The values were not known. They _can be computed_ from already known values.
For regular frame quantizer output is computed using MA predictor and
two stage vector of quantizer.
For erased frame MA predictor and LSF from previous frame are used
(vector of quantized is ignored).
this is because i can't use the same formula and thus can't just reuse
any of previously computed
past_quantizer_output values.
>
>
> [...]
> --
> Michael ? ? GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
>
> Observe your enemies, for they first find out your faults. -- Antisthenes
>
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.9 (GNU/Linux)
>
> iD8DBQFKQ2M6YR7HhwQLD6sRAiYKAJwKNZhFJTAfFKA3LLTjzuLfZGAnNwCePdO1
> /cCXLqCawfdcCzmeQ34dSR8=
> =VNUz
> -----END PGP SIGNATURE-----
>
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel at mplayerhq.hu
> https://lists.mplayerhq.hu/mailman/listinfo/ffmpeg-devel
>
--
Regards,
Vladimir Voroshilov mailto:voroshil at gmail.com
JID: voroshil at gmail.com, voroshil at jabber.ru
ICQ: 95587719
More information about the ffmpeg-devel
mailing list