[FFmpeg-devel] [PATCH] ALAC Encoder

Jai Menon realityman
Mon Aug 18 19:24:53 CEST 2008


Hi,

On Monday 18 Aug 2008 10:54:23 pm Michael Niedermayer wrote:
> On Mon, Aug 18, 2008 at 09:55:10PM +0530, Jai Menon wrote:
> > Hi,
> >
> > On Monday 18 Aug 2008 3:46:23 am Michael Niedermayer wrote:
> > > On Mon, Aug 18, 2008 at 02:38:24AM +0530, Jai Menon wrote:
> > > > Hi,
> > > >
> > > > On Sunday 17 Aug 2008 5:17:52 pm Michael Niedermayer wrote:
> > > > > On Sun, Aug 17, 2008 at 11:17:10AM +0530, Jai Menon wrote:
>
> [...]
>
> > > > +
> > > > +static void alac_stereo_decorrelation(AlacEncodeContext *s)
> > > > +{
> > > > +    int32_t *left = s->sample_buf[0], *right = s->sample_buf[1];
> > > > +    int i, mode, n = s->avctx->frame_size;
> > > > +
> > > > +    mode = estimate_stereo_mode(left, right, n);
> > > > +
> > > > +    if(mode == ALAC_CHMODE_LEFT_RIGHT) {
> > > > +        s->interlacing_leftweight = 0;
> > > > +        s->interlacing_shift = 0;
> > > > +        return;
> > > > +    }
> > > > +
> > > > +    if(mode == ALAC_CHMODE_LEFT_SIDE) {
> > > > +        for(i=0; i<n; i++) {
> > > > +            right[i] = left[i] - right[i];
> > > > +        }
> > > > +        s->interlacing_leftweight = 1;
> > > > +        s->interlacing_shift = 0;
> > > > +
> > > > +    } else {
> > > > +        int32_t tmp;
> > > > +        for(i=0; i<n; i++) {
> > > > +            tmp = left[i];
> > > > +            left[i] = (tmp + right[i]) >> 1;
> > > > +            right[i] = tmp - right[i];
> > > > +        }
> > > > +        s->interlacing_leftweight = 1;
> > > > +        s->interlacing_shift = 1;
> > > > +    }
> > >
> > > i think 1 mode is missing
> >
> > I left out the right-side mode because I really don't see how the decoder
> > could support it without accidentally swapping channels. Or am I missing
> > something?
>
> The decoder does:
>             cl -= (cr * W) >> S;
>             cr += cl;
>
>             l = cr;
>             r = cl;
> the encoder does:
>             l -= r;
>             r += (l * W) >> S;
>
>             cr = l;
>             cl = r;
>
> These hold true for all values of W and S
>
> with W=0,S=1  you get l-r, r

W=0 will skip the decorrelation code on the decoder side :-)

> with W=1,S=1  you get l-r, (r+l)>>1
> with W=2,S=1  you get l-r, l
>






Regards,

Jai Menon




More information about the ffmpeg-devel mailing list