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

Axel Holzinger aholzinger
Wed Oct 31 21:18:46 CET 2007


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.

Shifting right is perfectly right (if you want to divide by 2). There is no -? with shorts. The most negative number has the same (okay not exactly, off by one) energy as the most positive value. If you want to reduce energy (and that's what he had in mind I guess) shifting right is perfect.

But I recommend to just clip, meanig check, if the value is smaller than SHORT_MIN tie it to SHORT_MIN and if it's greater than SHORT_MAX tie it to SHORT_MAX.

> > > > +        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..

Not really, just listen to a AC3 DVB-S radio signal. Most of the content is stereo, but the radio stations don't switch formats from take to take (you would have a constant resyncing of your receiver at take boundaries, annoying), but they do route the stereo signal to front left and front right. If they have a real 5.1 take, they send it to all channels.

On a digital mixing console it's the same, there is no division by the number of channels you have, it's just summing up all channels. The operator has to reduce gain of the inputs, if the sum is going into overload. The console will just do correct clipping to prevent a numerical overflow, what would lead to a distortion with maximum energy.

Just my 0.02?
Axel

> Rich
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel at mplayerhq.hu
> http://lists.mplayerhq.hu/mailman/listinfo/ffmpeg-devel





More information about the ffmpeg-devel mailing list