[FFmpeg-devel] [PATCH] Support for reducing from 5.1 and 4.0 audio to stereo audio

Michael Niedermayer michaelni
Wed Oct 31 18:31:48 CET 2007


Hi

On Wed, Oct 31, 2007 at 12:26:37PM -0400, Rich Felker wrote:
> On Wed, Oct 31, 2007 at 04:38:57PM +0100, Axel Holzinger wrote:
> > > > +static void quad_to_stereo(short *output, short *input, int n)
> > > > +{
> > > > +    int i;
> > > > +    for(i=0; i<n; i++) {
> > > > +        output[0] = (input[0] + input[2]) >> 1;
> > > > +        output[1] = (input[1] + input[3]) >> 1;
> > > >   
> > > 
> > > shouldn't it be /2 instead of >>1 ?
> > 
> > It's ints, what is the difference?
> 
> The difference is what happens to negative values. However, I think
> rounding in the consistent direction (towards -?) is better than
> rounding towards 0. The latter could create artifacts; the former will
> only create DC bias which is inaudible.

well ...

input[0]=0, 0, 0, ...
input[1]=1, 1, 1, ...
input[2]=input[3]= 0, 1, 0, 1, 0, ...

the output would be
output[0]= 0,0,0,0, ...
output[1]= 0,1,0,1, ...

while not rounded it would be
output[0]= 0  , 0.5, 0  , 0.5, ...
output[1]= 0.5, 1.0, 0.5, 1.0, ...

as you can see the non DC signal VERY significantly changes amplitude and
does so even in a radically different way between the left and right channels

so no, neither /2 nor >>1 are ideal or would just create a DC bias
still IMHO >>1 is better than /2, its at least simpler

the most correct would be adding random +1 before >>1, maybe behind some
#ifdef AUDIOPHILE
but its likely overkill ...


> 
> > > > +        output += 2;
> > > > +        input += 4;
> > > > +    }
> > > > +}
> > > > +
> > > > +
> > > > +static void ac3_5p1_to_stereo(short *output, short *input, int n1)
> > 
> > The correct way to handle this is to follow the ITU matrix:
> > 
> > Lo = L + 0.7 * C + k * Ls
> > Ro = R + 0.7 * C + k * Rs with default k = 0.7
> > 
> > You see: No division! Instead you have to implement clipping.
> > 
> > Why no division?
> > 
> > Imagine, you have a 5.1 signal, but only L + R hold any signal. If you
> > divide, the stereo level will be decreased and you will loose dynamic.
> 
> This is correct, though. Channel reduction is _supposed_ to be a lossy
> operation. A stream with content only in the L/R channels is "less
> loud" than a stream with content on all 6 channels (when played on a
> real 5.1 system), and thus it should come across less loud when
> downmixed. If you really have 5.1 content where all but 2 of the
> channels are empty, you should be using a channel-dropping filter
> rather than downmixing anyway, but only an idiot would produce such
> content to begin with..

either way, /3 is not ok in a inner loop there are faster ways to achive the
same
and 0.7 is plain wrong, its sqrt(0.5) at least

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

No human being will ever know the Truth, for even if they happen to say it
by chance, they would not even known they had done so. -- Xenophanes
-------------- 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/20071031/27e2752a/attachment.pgp>



More information about the ffmpeg-devel mailing list