4

Is it possible to play different audio, for example audio from video file to my HDMI and audio from music player to 3,5 jack in the same time?

4

It is possible for the Pi to source multiple different audio outputs. The sound output via HDMI is digital whereas the 3.5 mm jack is a PWM based analogue output. They're different from each other and alsa is perfectly capable to handle multiple outputs (see here). Different software tools (or multiple instances of the same) should then be able to output different sound files to those cards.

In this case, an exemplary setup could be:

  1. kodi outputs A/V to HDMI
  2. mpd or mopidy output sound stream to the analog jack

The information on the web is slightly inconsistent, some claim that both support multiple instances running other say they don't.


related: Is it possible to have multiple audio outputs going to different speakers at the same time?

  • This is one thing that pulseaudio does make slightly more easy - with the right configuration and permissions those two different audio "sinks" don't even have to be on the same Host - I have one PC as a Media Server and sometimes route the audio to the speakers on the another PC that is on my Desktop. The same should be true for RPis as well... – SlySven Dec 31 '15 at 3:06
  • @SlySven, yes pulse-audio is something that also comes to mind (here and at a few other questions). If you have experience please share... – Ghanima Dec 31 '15 at 8:56
  • I'm not an authority on it! What I didn't say about that setup of playing the audio on a different host was that I tried to get the same sound from both server and client simultaneously - I think PA has a system to keep multiple sinks "in sync" by tweaking the sample rate of one of them - but for me this meant that one of the outputs went haywire either speeding up or slowing down until the clock rate couldn't be handled by the hardware. Trouble is the documentation (like with the author's other project systemd) was not what you might call completely clear IMHO and I gave up on it. – SlySven Dec 31 '15 at 18:57
  • Is there any kind of howto for this? What I want to achieve is exactly the example you gave: Kodi with AV on HDMI and MPD with audio on the analogue jack. – tremby Jan 9 '17 at 6:36
0

It turns out this is really easy. You just have to tell each program which audio device to use.

You can see the available devices with aplay -l. On my Pi 3, it tells me the following:

**** List of PLAYBACK Hardware Devices ****
card 0: ALSA [bcm2835 ALSA], device 0: bcm2835 ALSA [bcm2835 ALSA]
  Subdevices: 7/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

I don't know what all those subdevices are, but the important part to notice is that card 0 device 0 says at the end [bcm2835 ALSA] and then card 0 device 1 says [bcm2835 IEC958/HDMI]. In other words, they're both card 0, and device 0 is the analogue output while device 1 is HDMI.

I left the Raspberry Pi audio setting on "auto" (0). I also left my Kodi settings alone (though I wonder if there may be some edge cases where it might output to the wrong device so it may be worth setting the device explicitly). Then I configured MPD to use the analogue device. That looks like this:

audio_output {
    type "alsa"
    name "Raspberry Pi analogue output"
    device "hw:0:0"
}

I now have MPD's output coming through the analogue output and Kodi's through HDMI. They can both output simultaneously.

I'm running OSMC, in case it's relevant.

  • As of some time in the last week I can no longer get this working. I assume some update broke things, and am trying to figure it out. – tremby Oct 3 '17 at 23:32
  • And since then it started working again. No idea... – tremby Nov 3 '17 at 21:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.