mikebrady / shairport-sync

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

Selecting analogue out on Raspberry Pi (OSMC) [Solved] #423

Closed ashtonaut closed 7 years ago

ashtonaut commented 7 years ago

Hi, I'm trying to get shairport-sync working on my Raspberry Pi 3 running OSMC (based on Debian Jessie - www.osmc.tv). Fantastic package by the way - it's just what I am looking for and I can't wait to get it working.

I managed to find the shairport-sync package in Jessie backports and installed it using apt-get with no problem. The server starts and runs fine and I can select it from iOS as an AirPlay target.

My issue is that the AirPlay audio comes through HDMI to the TV, not through the analogue audio jack as I would prefer. I'm struggling with the config file changes I need to get audio coming out of the analogue output and not HDMI (I know nothing about audio on Linux...).

The alsa section in my config file looks like this (I don't need synchronised audio):

alsa =
{
  output_device = "hw:0";
  mixer_control_name = "PCM";
  disable_synchronization = "yes";
};

The output from aplay -l on my system looks like this:

**** List of PLAYBACK Hardware Devices ****
card 0: ALSA [bcm2835 ALSA], device 0: bcm2835 ALSA [bcm2835 ALSA]
  Subdevices: 8/8
  Subdevice #0: subdevice #0
  Subdevice #1: subdevice #1
  Subdevice #2: subdevice #2
  Subdevice #3: subdevice #3
  Subdevice #4: subdevice #4
  Subdevice #5: subdevice #5
  Subdevice #6: subdevice #6
  Subdevice #7: subdevice #7
card 0: ALSA [bcm2835 ALSA], device 1: bcm2835 ALSA [bcm2835 IEC958/HDMI]
  Subdevices: 1/1
  Subdevice #0: subdevice #0

Any suggestions for what my alsa settings should be to get audio out of the analogue jack and not HDMI?

Thanks in advance!

mikebrady commented 7 years ago

Thanks for the post. It might be worth checking this: https://www.raspberrypi.org/documentation/configuration/audio-config.md.

Otherwise, I think that the card has two devices, device 0 and device 1. Thus, the headphone jack is hw:0,0 and the HDMI port is hw:0,1. So, you could specify the output device as hw:0,0 or hw:0,1. Then you have to work out where the mixer is – it might be associated with the card, in which case it'll be at hw:0, or it might be associated with a device, in which case hw:0,0 or hw:0,1 as appropriate.

ashtonaut commented 7 years ago

Thanks for the response, and apologies for what are probably basic questions - I am discovering audio on Linux is a bit complicated...

So it sounds like my output device should be hw:0,0. I'm now struggling with how to work out where the mixer is.

If I don't specify a mixer, the service starts with no error and I can connect to the AirPlay receiver, but I get no audio out of the analogue output.

If I specify the mixer as hw:0, hw:0,0, hw:0,1 or PCM, I get an error when starting the service along the lines of "could not connect to mixer".

The output from amixer -L is:

null
    Discard all samples (playback) or generate zero samples (capture)
default:CARD=ALSA
    bcm2835 ALSA, bcm2835 ALSA
    Default Audio Device
sysdefault:CARD=ALSA
    bcm2835 ALSA, bcm2835 ALSA
    Default Audio Device
dmix:CARD=ALSA,DEV=0
    bcm2835 ALSA, bcm2835 ALSA
    Direct sample mixing device
dmix:CARD=ALSA,DEV=1
    bcm2835 ALSA, bcm2835 IEC958/HDMI
    Direct sample mixing device
dsnoop:CARD=ALSA,DEV=0
    bcm2835 ALSA, bcm2835 ALSA
    Direct sample snooping device
dsnoop:CARD=ALSA,DEV=1
    bcm2835 ALSA, bcm2835 IEC958/HDMI
    Direct sample snooping device
hw:CARD=ALSA,DEV=0
    bcm2835 ALSA, bcm2835 ALSA
    Direct hardware device without any conversions
hw:CARD=ALSA,DEV=1
    bcm2835 ALSA, bcm2835 IEC958/HDMI
    Direct hardware device without any conversions
plughw:CARD=ALSA,DEV=0
    bcm2835 ALSA, bcm2835 ALSA
    Hardware device with all software conversions
plughw:CARD=ALSA,DEV=1
    bcm2835 ALSA, bcm2835 IEC958/HDMI
    Hardware device with all software conversions

I assume that the line dmix:CARD=ALSA,DEV=0 is relevant here, but I'm not sure what the allowable formats are for specifying the mixer in the config file.

Any further tips for identifying the correct mixer to use? Thanks again for your help.

Edit: Quick update. Regardless of whether I select hw:0,0 or hw:0,1 as the output device (with a mixer not specified in the config file), I get AirPlay sound on HDMI, but not on analogue.

mikebrady commented 7 years ago

Thanks for the update. I know it sounds weird, but if you unplug the HDMI device (maybe you can't in your system) does sound "revert" to the 3.5mm jack – the "analogue" output?

Failing that, could you use the information in the link to "force" output to the analogue port?

ashtonaut commented 7 years ago

My suspicion is that the way OSMC is configured by default may be messing with things somehow. I know that the analogue out is 'working', because I can hear sound from this output when I set the audio output within Kodi to be HDMI + analogue and play something (from Kodi). I have raised a query with the OSMC team and I'll see what comes of that.

I will do some playing about with amixer to see if I can see how things are configured at present, and if I can force audio to analogue out using this command.

Part of my issue is that I don't want to mess up the default OSMC audio path through HDMI, as I use the Pi as a media center - ideally I only want shairport-sync audio coming out the analogue output. Perhaps shairport-sync's ability to run commands before and after playback might help if I need to manually switch the audio output when using AirPlay only.

I'll report back once I've tried a few more troubleshooting steps. Your assistance is most appreciated - I'll write a how-to for OSMC assuming I can get this working...

mikebrady commented 7 years ago

Okay, thanks.

ashtonaut commented 7 years ago

Fixed and working! Running amixer cset numid=3 1 before playback, and amixer cset numid=3 0 after playback does exactly what I need it to. I will post a link to an OSMC how-to for future reference when I get a chance to write it up. Thanks again for your help!

ashtonaut commented 7 years ago

For future reference, I've written up a how-to for my situation here

mikebrady commented 7 years ago

Super.