mikebrady / shairport-sync

AirPlay and AirPlay 2 audio player
Other
7.3k stars 574 forks source link

How to specify subdevice & use hardware mixer? #20

Closed k-lange closed 9 years ago

k-lange commented 9 years ago

I have a Creative XFi that has several outputs:

$ aplay -l | grep card
card 0: XFi [Creative X-Fi], device 0: ctxfi [Front/WaveIn]
card 0: XFi [Creative X-Fi], device 1: ctxfi [Surround]
card 0: XFi [Creative X-Fi], device 2: ctxfi [Center/LFE]
card 0: XFi [Creative X-Fi], device 3: ctxfi [Side]
card 0: XFi [Creative X-Fi], device 4: ctxfi [IEC958 Non-audio]

With the original shairport I could specify what output to use like so:

shairport -a bathroom -- -d hw:XFi,0
shairport -a kitchen -p 5001 -- -d hw:XFi,1

This also works with shairport-sync, unless I try to specify a mixer:

$ shairport-sync -a kitchen -- -d hw:XFi,1 -t hardware -c Surround
ALSA lib conf.c:4578:(parse_args) Unknown parameter 1
ALSA lib conf.c:4711:(snd_config_expand) Parse arguments error: No such file or directory
ALSA lib control.c:953:(snd_ctl_open_noupdate) Invalid CTL hw:XFi,1
Failed to attach mixer

Is there any way to make this work? Otherwise it works really well, the sync-feature is awesome, thanks a lot!

mikebrady commented 9 years ago

Is it possible that the command line parser is complaining about the comma embedded in hw:XFi,1? (I changed the code that parses the command line – basically I wanted to use a standard library (popt) that, ironically, offers more error checking.) Could you try using quotes, e.g.

shairport-sync -a kitchen -- -d 'hw:XFi,1' -t hardware -c Surround

This is easy to check, and the result would be interesting. If this fixed the problem, it would mean that the interpretation of hw:XFi,0 was probably different to what you expect, and was simply taken as hw:XFi.

k-lange commented 9 years ago

Thanks, I thought it could be something like that, but unfortunately I get the same result:

$ shairport-sync -a kitchen -- -d 'hw:XFi,1' -t hardware -c Surround
ALSA lib conf.c:4578:(parse_args) Unknown parameter 1
ALSA lib conf.c:4711:(snd_config_expand) Parse arguments error: No such file or directory
ALSA lib control.c:953:(snd_ctl_open_noupdate) Invalid CTL hw:XFi,1
Failed to attach mixer
mikebrady commented 9 years ago

Thanks for trying. I'll have to see if I can borrow one from somewhere. Is it the "SOUND BLASTER X-FI SURROUND 5.1 PRO" USB Card?

k-lange commented 9 years ago

No, it's the PCI-Version, not sure which model exactly. But I don't think it's related to the sound card. Same happens when I specify -- -d 'hw:CODEC,0' -t hardware -c PCM to get my USB sound card, although the 0 is of course not needed here. Maybe it's because you're using the device identifier to find the mixer, and the mixer is present on the card (hw:CODEC) but not on the device (hw:CODEC,0) ?

mikebrady commented 9 years ago

You're right on both counts – I can generate a similar issue with a card I have, and it is an issue of card vs. device.

I think I have an explanation and a fix, which I will document, I promise. By way of an excuse, I haven't come across the issue before because I haven't exercised that part of the ALSA back end. The problem is not with the command line or anything like that – your intuition is absolutely correct.

The core of the issue is the meaning of the -d option. When you write something like -d hw:0 you are specifying a sound card as an output device; the default output device on the card will be chosen. When you specify something like -d hw:0,0 you are specifying a specific device on a card as the output device. Fair enough. However, by default, it is assumed that the mixer you then describe with the -t and -c options is associated with whatever you specified with the -d option. Normally that's okay; typically you specify a card with -d, and the chances are that the mixer is associated with the card as a whole (that's always been the case for me). But if you specify a device with -d, the chances that the mixer is associated specifically with that device is remote – hence, I believe, the issue you reported.

It turns out that there is another option, the -m option, in the ALSA back end which is listed when you execute shairport-sync -h but is not in the documentation (yet). The option is for stating explicitly where the mixer is. By using the -m option you can specify that the mixer is somewhere specific, e.g. on the card. That means you can specify the exact output device with -d and separately specify the mixer to be used with -m.

So, if you try something like this on your USB sound card: -- -d 'hw:CODEC,0' -m 'hw:CODEC' -t hardware -c PCM it should work – it works for me. Then, analogously with the XFi.

If this is right, I'll try to fix the documentation over the next few days, so let me know, please!

k-lange commented 9 years ago

It works! Sorry, I didn't read through the help output careful enough, I guess documenting it would be a good idea. Thanks a lot for the detailed answers!

mikebrady commented 9 years ago

Excellent! Actually, the fault is mine for not documenting it properly.