[pulseaudio-discuss] WIP/RFC: completely rewritten channel remixing

Alexander E. Patrakov patrakov at gmail.com
Sun Oct 14 02:39:54 UTC 2018


The current code in PulseAudio for channel remixing is quite complex, 
has a lot of ifs, and does not do the right thing. For example:

1) Given a "5.1 (Side)" sink input and "5.1" sink, it generates the rear 
channels as averages between Front and Side instead of just using Side.

2) The coefficients for downmixing rear channels from a 5.1 sink input 
to a stereo sink are very low. On compositions like "Lichtmond 2" it is 
quite annoying. AC3 specifies the -3 or -6 dB downmix level, which means 
dividing by 1.4 or by 2, not by 9.

3) The coefficient for downmixing Left channel into LFE (and thus the 
tonal balance) is different when playing stereo and 5.0 material on a 
5.1 sink.

I found that I can get rid of a lot of complexity, while reproducing 
most (all?) of the good decisions that the old code did, by using a 
simple notion of "channel azimuth" and "channel proximity", and 
reordering the algorithm so that it first tries to use all input 
channels and then to fill unused output channels.

Each input channel is routed to one (or, if the situation is too 
symmetrical, two) output channels that are nearest to its position. 
Then, each unused output channel is filled in from one (or, in 
symmetrical cases, two) input channels that are the closest ones to its 
position. That's it, no need to explicitly consider special cases of 
exactly matching channels or mono layout. The old code was so complex 
because it did not know the word "nearest".

While at it, I also tried to fix cases (2) and (3). The resulting patch 
is attached. Yes, it is unreadable, as it typically happens with big 
rewrites.

Here is an example channel matrix for 5.1(Side) -> Stereo remapping with 
the new patch:

        I00   I01   I02   I03   I04   I05
     +------------------------------------
O00 | 0,385 0,000 0,192 0,192 0,231 0,000
O01 | 0,000 0,385 0,192 0,192 0,000 0,231

Here is 5.1(Side) -> 5.1:

        I00   I01   I02   I03   I04   I05
     +------------------------------------
O00 | 1,000 0,000 0,000 0,000 0,000 0,000
O01 | 0,000 1,000 0,000 0,000 0,000 0,000
O02 | 0,000 0,000 0,000 0,000 1,000 0,000
O03 | 0,000 0,000 0,000 0,000 0,000 1,000
O04 | 0,000 0,000 1,000 0,000 0,000 0,000
O05 | 0,000 0,000 0,000 1,000 0,000 0,000

Here is Stereo -> 5.1, with fill-all-channels enabled and LFE remixing 
disabled:

        I00   I01
     +------------
O00 | 1,000 0,000
O01 | 0,000 1,000
O02 | 0,600 0,000
O03 | 0,000 0,600
O04 | 0,500 0,500
O05 | 0,000 0,000

The patch is definitely not baked enough, e.g. it attenuates too much 
when LFE remixing is going on with 5.1 or 7.1 input. Also, there might 
be bugs and corner cases that I haven't thought about. Testing and 
criticizing is welcome, inclusion in the official tree is probably not a 
good idea.

The patch is an alternative approach to what was solved by 
https://lists.freedesktop.org/archives/pulseaudio-discuss/2018-October/030559.html 
, do not try to apply both.

-- 
Alexander E. Patrakov
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-resampler-Completely-rewritten-channel-remapping.patch
Type: text/x-patch
Size: 32289 bytes
Desc: not available
URL: <https://lists.freedesktop.org/archives/pulseaudio-discuss/attachments/20181014/8651e87e/attachment-0001.bin>


More information about the pulseaudio-discuss mailing list