[FFmpeg-devel] [PATCH] ALAC Encoder

Michael Niedermayer michaelni
Mon Aug 18 19:24:23 CEST 2008


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
with W=1,S=1  you get l-r, (r+l)>>1
with W=2,S=1  you get l-r, l


[...]
-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

It is dangerous to be right in matters on which the established authorities
are wrong. -- Voltaire
-------------- 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/20080818/0dadb149/attachment.pgp>



More information about the ffmpeg-devel mailing list