[alsa-devel] wrong channel mapping in a52 plugin

Tom Yan tom.ty89 at gmail.com
Sun Jan 10 23:58:36 CET 2016


[ I was wrong about ONE thing, the ALSA pulse plugin doesn't report
any channel map. What speaker-test used is just the ALSA fallback,
that's why 4 is "Center" instead of "Front Center". ]

Let me clarify again. The a52 plugin does NOT output the file with
incorrect channel order, it's probably also fine that it expects the
input to be in ALSA order and remaps it to general 5.1 order when
encoding. The thing that's wrong is it REPORTS itself as a plugin that
expect input to be in general 5.1 order while it ACTUALLY expects ALSA
order. Apparently someone mistakenly thought that it should report the
order it OUTPUT but it really should NOT. It's like a a crossover
cable reporting itself as a straight-through cable.

mpv does a great job in reporting everything:

[tom at localhost ~]$ mpv -v --audio-channels=6 -ao
alsa:device=[hw:PCH,0] Downloads/www_lynnemusic_com_surround_test.ac3
...
[ao] Trying audio driver 'alsa'
[ao/alsa] Setting option 'device' = 'hw:PCH,0' (flags = 0)
[ao/alsa] requested format: 48000 Hz, 5.1 channels, floatp
[ao/alsa] using ALSA version: 1.1.0
[ao/alsa] opening device 'hw:PCH,0'
[ao/alsa] trying format float
[ao/alsa] trying format double
[ao/alsa] trying format s32
[ao/alsa] Channel layouts:
[ao/alsa]  - stereo
[ao/alsa]  - quad
[ao/alsa]  - 5.1(alsa)
[ao/alsa]  - 7.1(alsa)
[ao/alsa] result: 5.1(alsa)
[ao/alsa] trying to set ALSA channel map: FL FR RL RR FC LFE
[ao/alsa] channel map reported by ALSA: FL FR RL RR FC LFE
[ao/alsa] which we understand as: 5.1(alsa)
[ao/alsa] using the ALSA channel map.
[ao/alsa] which is what we requested.
[ao/alsa] hw pausing supported: yes
[ao/alsa] buffersize: 12000 samples
[ao/alsa] period size: 750 samples
[ao/alsa] device buffer: 12000 samples.
[ao/alsa] using soft-buffer of 12000 samples.
[cplayer] AO: [alsa] 48000Hz 5.1(alsa) (5.1) 6ch s32
...

[tom at localhost ~]$ mpv -v -ao alsa:device=[hw:PCH,1]
Downloads/www_lynnemusic_com_surround_test.ac3
...
[ao] Trying audio driver 'alsa'
[ao/alsa] Setting option 'device' = 'hw:PCH,1' (flags = 0)
[ao/alsa] requested format: 48000 Hz, 5.1(side) channels, floatp
[ao/alsa] using ALSA version: 1.1.0
[ao/alsa] opening device 'hw:PCH,1'
[ao/alsa] trying format float
[ao/alsa] trying format double
[ao/alsa] trying format s32
[ao/alsa] Channel layouts:
[ao/alsa]  - stereo
[ao/alsa] result: stereo
[ao/alsa] trying to set ALSA channel map: FL FR
[ao/alsa] channel map reported by ALSA: FL FR
[ao/alsa] which we understand as: stereo
[ao/alsa] using the ALSA channel map.
[ao/alsa] which is what we requested.
[ao/alsa] hw pausing supported: yes
[ao/alsa] buffersize: 12000 samples
[ao/alsa] period size: 750 samples
[ao/alsa] device buffer: 12000 samples.
[ao/alsa] using soft-buffer of 12000 samples.
[cplayer] AO: [alsa] 48000Hz stereo 2ch s32
...

[tom at localhost ~]$ mpv -v --audio-channels=6 -ao alsa:device=[pulse]
Downloads/www_lynnemusic_com_surround_test.ac3
...
[ao/alsa] Setting option 'device' = 'pulse' (flags = 0)
[ao/alsa] requested format: 48000 Hz, 5.1 channels, floatp
[ao/alsa] using ALSA version: 1.1.0
[ao/alsa] opening device 'pulse'
[ao/alsa] trying format float
[ao/alsa] hw pausing supported: yes
[ao/alsa] buffersize: 12000 samples
[ao/alsa] period size: 750 samples
[ao/alsa] device buffer: 12000 samples.
[ao/alsa] using soft-buffer of 12000 samples.
[cplayer] AO: [alsa] 48000Hz stereo 2ch float
...

[tom at localhost ~]$ mpv -v --audio-channels=6 -ao
alsa:device=[a52:PCH]:non-interleaved
Downloads/www_lynnemusic_com_surround_test.ac3
...
[ao] Trying audio driver 'alsa'
[ao/alsa] Setting option 'device' = 'a52:PCH' (flags = 0)
[ao/alsa] Setting option 'non-interleaved' = '' (flags = 0)
[ao/alsa] requested format: 48000 Hz, 5.1 channels, floatp
[ao/alsa] using ALSA version: 1.1.0
[ao/alsa] opening device 'a52:PCH'
[ao/alsa] trying format floatp
[ao/alsa] trying format doublep
[ao/alsa] trying format s32p
[ao/alsa] trying format s16p
[ao/alsa] Channel layouts:
[ao/alsa]  - stereo
[ao/alsa]  - quad
[ao/alsa]  - 5.1
[ao/alsa] result: 5.1
[ao/alsa] trying to set ALSA channel map: FL FR FC LFE RL RR
[ao/alsa] channel map reported by ALSA: FL FR FC LFE RL RR
[ao/alsa] which we understand as: 5.1
[ao/alsa] using the ALSA channel map.
[ao/alsa] which is what we requested.
[ao/alsa] hw pausing supported: no
[ao/alsa] buffersize: 12288 samples
[ao/alsa] period size: 1536 samples
[ao/alsa] device buffer: 12288 samples.
[ao/alsa] using soft-buffer of 12288 samples.
[cplayer] AO: [alsa] 48000Hz 5.1 6ch s16p
...

On 10 January 2016 at 01:22, Tom Yan <tom.ty89 at gmail.com> wrote:
> I think I found out what exactly is wrong in the a52 plugin.
>
>
> So I had this .asoundrc:
>
> pcm.myhw {
>     type hw
>     card PCH
>     device 0
> }
>
> pcm.mya52 {
>     type a52
>     card PCH
> }
>
>
> pcm.hwfile {
>     type file
>     slave {
>         pcm myhw
>     }
>     file myhw.wav
>     format wav
> }
>
> pcm.a52file {
>     type file
>     slave {
>         pcm mya52
>     }
>     file mya52.wav
>     format wav
> }
>
> and ran the following:
>
>
> [tom at localhost ~]$ speaker-test -D hwfile -c 6 -l 1
>
> speaker-test 1.1.0
>
> Playback device is hwfile
> Stream parameters are 48000Hz, S16_LE, 6 channels
> Using 16 octaves of pink noise
> Rate set to 48000Hz (requested 48000Hz)
> Buffer size range from 22 to 349525
> Period size range from 11 to 174762
> Using max buffer size 349524
> Periods = 4
> was set period_size = 87381
> was set buffer_size = 349524
>  0 - Front Left
>  4 - Front Center
>  1 - Front Right
>  3 - Rear Right
>  2 - Rear Left
>  5 - LFE
> Time per period = 10.961529
> [tom at localhost ~]$ speaker-test -D plug:a52file -c 6 -l 1
>
> speaker-test 1.1.0
>
> Playback device is plug:a52file
> Stream parameters are 48000Hz, S16_LE, 6 channels
> Using 16 octaves of pink noise
> Rate set to 48000Hz (requested 48000Hz)
> Buffer size range from 3072 to 1047552
> Period size range from 1536 to 1536
> Using max buffer size 1047552
> Periods = 4
> was set period_size = 1536
> was set buffer_size = 1047552
>  0 - Front Left
>  2 - Front Center
>  1 - Front Right
>  5 - Rear Right
>  4 - Rear Left
>  3 - LFE
> Time per period = 6.376158
>
> As you can see, the a52 plugin expose/report itself as something that
> consider the input it takes should be in general 5.1 mapping order
> (fl-fr-fc-lfe-bl-br) instead of "ALSA order" (fl-fr-bl-br-fc-lfe),
> while it actually consider the input has ALSA order and remap the
> channels when get it encoded (because ac3 should have the general
> order).
>
> Same thing happens in mpv:
>
> [tom at localhost ~]$ mpv --audio-channels=help | grep 5.1
>     5.1              (fl-fr-fc-lfe-bl-br)
>     5.1(alsa)        (fl-fr-bl-br-fc-lfe)
>     5.1(side)        (fl-fr-fc-lfe-sl-sr)
> [tom at localhost ~]$ ffprobe
> Downloads/www_lynnemusic_com_surround_test.ac3 |& grep 5.1
>     Stream #0:0: Audio: ac3, 48000 Hz, 5.1(side), fltp, 448 kb/s
> [tom at localhost ~]$ mpv -ao alsa:device=[hwfile]:non-interleaved
> --audio-channels=6 Downloads/www_lynnemusic_com_surround_test.ac3
> Playing: Downloads/www_lynnemusic_com_surround_test.ac3
> [ffmpeg/demuxer] ac3: Estimating duration from bitrate, this may be inaccurate
>  (+) Audio --aid=1 (ac3)
> AO: [alsa] 48000Hz 5.1(alsa) (5.1) 6ch s32
> A: 00:00:09 / 00:00:09 (97%)
>
>
> Exiting... (End of file)
> [tom at localhost ~]$ mpv -ao alsa:device=[a52file]:non-interleaved
> --audio-channels=6 Downloads/www_lynnemusic_com_surround_test.ac3
> Playing: Downloads/www_lynnemusic_com_surround_test.ac3
> [ffmpeg/demuxer] ac3: Estimating duration from bitrate, this may be inaccurate
>  (+) Audio --aid=1 (ac3)
> AO: [alsa] 48000Hz 5.1 6ch s16p
> A: 00:00:09 / 00:00:09 (97%)
>
>
> Exiting... (End of file)
>
> [ see 5.1 vs 5.1(alsa) in the AO: lines; the input is 5.1(side), which
> has basically the same order as 5.1 ]
>
> I've also done the same test with mplayer. As oppose to what
> speaker-test / mpv does, it does a channel remap ANYWAY (at least for
> -ao alsa). I compared all the output wav files captured by the "type
> file" pcm wrappers to confirm these.
>
> Another example is the ALSA pulse plugin:
>
> [tom at localhost ~]$ speaker-test -D pulse -c 6 -l 1
>
> speaker-test 1.1.0
>
> Playback device is pulse
> Stream parameters are 48000Hz, S16_LE, 6 channels
> Using 16 octaves of pink noise
> Rate set to 48000Hz (requested 48000Hz)
> Buffer size range from 32 to 349525
> Period size range from 10 to 116509
> Using max buffer size 349524
> Periods = 4
> was set period_size = 87381
> was set buffer_size = 349524
>  0 - Front Left
>  4 - Center
>  1 - Front Right
>  3 - Rear Right
>  2 - Rear Left
>  5 - LFE
> Time per period = 10.976481
>
> As you can see, it reports that it takes ALSA order. That's exactly
> what a52 plugin should do too.
>
> On 9 January 2016 at 02:59, Tom Yan <tom.ty89 at gmail.com> wrote:
>> I am using alsa-lib/alsa-utils/alsa-plugins 1.1.0 and ffmpeg 2.8.4 and
>> in Arch Linux.
>>
>> So I ran `speaker-test -D wav -c 6 -l 1` with the following .asoundrc:
>>
>> pcm.file {
>>     type file
>>     file st.ac3
>> }
>>
>> pcm.a52 {
>>     type plug
>>     slave {
>>         pcm {
>>             type a52
>>             slavepcm file
>>         }
>>     }
>> }
>>
>> pcm.wav {
>>     type file
>>     slave {
>>         pcm a52
>>     }
>>     file st.wav
>>     format wav
>> }
>>
>> [tom at localhost ~]$ speaker-test -D wav -c 6 -l 1
>>
>> speaker-test 1.1.0
>>
>> Playback device is wav
>> Stream parameters are 48000Hz, S16_LE, 6 channels
>> Using 16 octaves of pink noise
>> Rate set to 48000Hz (requested 48000Hz)
>> Buffer size range from 3072 to 206157312
>> Period size range from 1536 to 1536
>> Using max buffer size 206157312
>> Periods = 4
>> was set period_size = 1536
>> was set buffer_size = 206157312
>>  0 - Front Left
>>  2 - Front Center
>>  1 - Front Right
>>  5 - Rear Right
>>  4 - Rear Left
>>  3 - LFE
>> Time per period = 0.203625
>>
>> Then, I encode "st.wav" manually with `ffmpeg -i st.wav ff.ac3`.
>>
>> This shows a comparison between the wav file written directly from the
>> speaker-test directly (st.wav) and the ac3 file I encode with a manual
>> ffmpeg command (ff.ac3):
>> https://ptpb.pw/5XJR.png
>> As you can see, everything is preserved but the LFE is made LFE.
>>
>> And this shows a comparision between the the ac3 file from ffmpeg and
>> the one written from the output of a52 plugin:
>> https://ptpb.pw/YaKg.png
>> If you compare carefully, you can see that Front Center and Rear Left
>> is swapped, LFE and Rear Right is also swapped.
>>
>> Here is a pair of ac3 samples that shows the problem clearly (a lady
>> will be telling the channels one by one):
>> Original: https://ptpb.pw/9XdC.ac3
>> ALSA a52 plugin re-encoded from mpv output: https://ptpb.pw/SQ_7.ac3


More information about the Alsa-devel mailing list