Michael Niedermayer <[email protected]> added the comment:
On Fri, Jun 26, 2009 at 02:14:33PM +0000, Yoshihisa Uchida wrote:
>
> Yoshihisa Uchida <[email protected]> added the comment:
>
> In regard to IMA ADPCM, because there was the same problem as Yamaha ADPCM, it
> corrected.
>
> My patch updates.
>
> changes:
> - IMA ADPCM decode/encode logic correct.
> - adpcm_compress_trellis() corrects.
> - regression test results update.
>
> _____________________________________________________
> FFmpeg issue tracker <[email protected]>
> <https://roundup.ffmpeg.org/roundup/ffmpeg/issue1223>
> _____________________________________________________
> libavcodec/adpcm.c | 89
> +++++++++++++++++++++++++++++++-----------
> tests/rotozoom.regression.ref | 24 +++++------
> tests/vsynth.regression.ref | 24 +++++------
> 3 files changed, 91 insertions(+), 46 deletions(-)
> 188ca71076d2e1a36840c6300c69cc94af8d97b1
> ffmpeg_yamaha_adpcm_decode_encode_2.patch
> diff --git a/libavcodec/adpcm.c b/libavcodec/adpcm.c
> old mode 100644
> new mode 100755
> index e670aa9..04a8e59
> --- a/libavcodec/adpcm.c
> +++ b/libavcodec/adpcm.c
> @@ -121,11 +121,6 @@ static const int yamaha_indexscale[] = {
> 230, 230, 230, 230, 307, 409, 512, 614
> };
>
> -static const int yamaha_difflookup[] = {
> - 1, 3, 5, 7, 9, 11, 13, 15,
> - -1, -3, -5, -7, -9, -11, -13, -15
> -};
> -
> /* end of tables */
>
> typedef struct ADPCMChannelStatus {
> @@ -207,12 +202,58 @@ static av_cold int adpcm_encode_close(AVCodecContext
> *avctx)
> return 0;
> }
>
> +static inline int get_adpcm_ima_nibble(int predictor, int step, short
> sample, int *delta)
> +{
> + int bit = 4;
> + int diff;
> + int nibble = 0;
> +
> + if (delta)
> + *delta = 0;
> + diff = abs(sample - predictor);
> + do {
> + if (diff >= step) {
> + if (delta)
> + *delta += step;
> + diff -= step;
> + nibble += bit;
> + }
> + step >>= 1;
> + bit >>= 1;
> + } while(bit);
> + if (delta)
> + *delta += step;
> +
> + if (sample < predictor)
> + {
> + if (delta)
> + *delta = -(*delta);
> + nibble += 8;
> + }
> +
> + return nibble;
> +}
I think the previous code was better
this is too slow and i dont see why it would be better
> +
> +static inline int get_adpcm_ima_delta(int step, int nibble)
> +{
> + int delta;
> +
> + delta = step >> 3;
> + if (nibble & 4) delta += step;
> + if (nibble & 2) delta += (step >> 1);
> + if (nibble & 1) delta += (step >> 2);
this can be done with a LUT
[...9
> @@ -708,10 +747,16 @@ static inline short
> adpcm_ima_expand_nibble(ADPCMChannelStatus *c, char nibble,
>
> sign = nibble & 8;
> delta = nibble & 7;
> - /* perform direct multiplication instead of series of jumps proposed by
> - * the reference ADPCM implementation since modern CPUs can do the mults
> - * quickly enough */
> - diff = ((2 * delta + 1) * step) >> shift;
> + /* Note:
> + * some delta and delta
> + * Several delta and step, the following formula cannot obtain the value
> of correct "diff".
> + * diff = ((2 * delta + 1) * step) >> shift
> + */
> + diff = step >> shift;
> + if (delta & 4) diff += (step >> (shift - 3));
> + if (delta & 2) diff += (step >> (shift - 2));
> + if (delta & 1) diff += (step >> (shift - 1));
> +
> predictor = c->predictor;
> if (sign) predictor -= diff;
> else predictor += diff;
duplicate
[...]
--
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
When you are offended at any man's fault, turn to yourself and study your
own failings. Then you will forget your anger. -- Epictetus
_____________________________________________________
FFmpeg issue tracker <[email protected]>
<https://roundup.ffmpeg.org/roundup/ffmpeg/issue1223>
_____________________________________________________