[FFmpeg-devel] [PATCH] Add a G.722 encoder

Martin Storsjö martin
Thu Sep 16 17:20:25 CEST 2010


On Thu, 16 Sep 2010, Michael Niedermayer wrote:

> On Thu, Sep 16, 2010 at 10:50:18AM +0300, Martin Storsj? wrote:
> > On Wed, 15 Sep 2010, Michael Niedermayer wrote:
> > 
> > > On Wed, Sep 15, 2010 at 05:42:39PM +0300, Martin Storsj? wrote:
> > > > 
> > > > I managed to do this, so I've got the following two versions:
> > > > 
> > > >     limit = limit + 1 << 10;
> > > >     while (limit > low_quant[i] * state->scale_factor)
> > > > 
> > > > 885 dezicycles in encode_low, 1047991 runs, 585 skips
> > > > 
> > > > and
> > > > 
> > > >     limit = limit + 1 << 10;
> > > >     limit = (limit + state->scale_factor - 1) / state->scale_factor;
> > > >     while (limit > low_quant[i])
> > > > 
> > > > 988 dezicycles in encode_low, 1047886 runs, 690 skips
> > > > 
> > > > So the former version is a bit faster, even if it does more 
> > > > multiplications.
> > > > 
> > > > Removing the i < 29 check with a sentinel works fine for normal samples, 
> > > > but the reference test vectors fail on this if using the former version, 
> > > > since the numeric range of 32 bit numbers isn't enough.
> > > > 
> > > > I.e., low_quant[i] * scale_factor mustn't overflow, so the the sentinel 
> > > > must be INT_MAX/max_scale_factor, which is (2^31-1)/4096, and limit << 10 
> > > > can be larger than this.
> > > 
> > > multiple sentinels should then work
> > 
> > Good idea, I was able to get this to work, too, in this form:
> > 
> >     limit = limit + 1 << 10;
> >     while (limit > low_quant[i] * state->scale_factor)
> >         i++;
> >     i = av_clip(i, 0, 29);
> > 
> > When the initial version took 919 dezicycles today, it went up to 948 when 
> > I changed the low_quant table to be int instead of int16_t (which is 
> > needed for the sentinels to fit), dropped to 914 when I removed the i < 29 
> > check from the loop, and increased to 922 when I added the av_clip at the 
> > end.
> > 
> > If I instead of the av_clip use an if (i > 29) i = 29; I got it down to 
> > 918, one dezicycle less than where I started.
> 
> that doesnt feel right
> can you show us some statistic on how often each of the 0..29 occurs on
> your test file / normal audio?

On my test file, which is a movie trailer with both speech and music, the 
distribution is like this:

66152 73807 84030 83795 77497 84602 75193 79712 72637 72394 63477 62738 
54695 51064 42842 39389 30935 27155 20366 17044 11724 9528 5710 4342 2408 
1560 745 442 165 201

And graphically: http://albin.abo.fi/~mstorsjo/low_code.pdf

So it quite heavily biased towards the lower values.

So, which one do you prefer, the one with multiple sentinels and clipping 
of the value after the loop, or simply with the condition inside the loop?

// Martin



More information about the ffmpeg-devel mailing list