Possible to have Analog and loopback audio?

I use OSMC to power a local radio station. I would also like to broadcast to Icecast. I have it working either way, but I need it to work both ways. Meaning I can change the audio device in settings to Analog and it goes to my FM transmitter, or I can choose the loopback I’ve made and it will work with EZstream. Is there a way to make it send audio to Analog and loopback? I’ve spent days now just to get this far and this is the last obstacle. Please help if you can.

You haven’t mentioned what OSMC device you’re using, which makes it difficult to answer your question.

ALSA loopback sinks will be automatically enumerated by AudioEngine and you should be able to select this.

Sorry, Pi3.
“ALSA loopback sinks will be automatically enumerated by AudioEngine and you should be able to select this.”
I apologize, I don’t know what that means. I followed this tutorial:

and it works great. I just need to be able to have audio on both the loopback as well as the analog output. I am able to choose either analog or loopback, not both.

Does Sonos support Bluetooth?
In that case, it may be better to follow the OSMC Bluetooth instructions.

Sam

Sorry, I haven’t been super clear. I don’t use Sonos. I created a loopback via the above link. It creates an output in OSMC

system/system/audio/audio output device/ALSO:Loopback(@:CARD=Loopback,DEV=0), Loopback PCM. That works perfectly if I just want to broadcast to Icecast, but it kills the analog audio. I need it to ALSO go to the analog audio output, which is how I send the signal to my FM transmitter. I could do this with a second Pi, but I would obviously much prefer to do it all on one device.

Here is the asoundrc

.asoundrc

pcm.multi {
type route;
slave.pcm {
type multi;
slaves.a.pcm “output”;
slaves.b.pcm “loopin”;
slaves.a.channels 2;
slaves.b.channels 2;
bindings.0.slave a;
bindings.0.channel 0;
bindings.1.slave a;
bindings.1.channel 1;
bindings.2.slave b;
bindings.2.channel 0;
bindings.3.slave b;
bindings.3.channel 1;
}

ttable.0.0 1;
ttable.1.1 1;
ttable.0.2 1;
ttable.1.3 1;

}

pcm.!default {
type plug
slave.pcm “multi”
}

pcm.output {
type hw
card Headset
}

pcm.loopin {
type plug
slave.pcm “hw:Loopback,0,0”
}

pcm.loopout {
type plug
slave.pcm “hw:Loopback,1,0”
}

And the command to run it is:
avconv -f alsa -i loopout -f mp3 - 2>/dev/null | sudo /usr/bin/ezstream -qvc /etc/ezstream.xml

I assume it is probably in one of those two, I just don’t know which.

Kodi doesn’t consult asoundrc IIRC.
This probably needs to be configured in /usr/share/alsa/cards or /etc/asound.conf.

Yes, but I don’t know how to do that. Is there a way to get audio through both the analog and loopback?

This is from the tutorial above:

"When OSMC is ready again, go to System -> Settings -> System -> Audio output and select Audio output device=ALSA: Loopback (loopin), Loopback PCM

This will stop the sound coming via the normal HDMI or analogue output."

Not to chase you away from OSMC, but I think for what you seem to be trying to do that using Raspbian or Mint Mate would be a better solution. IDJC (idjc.sourceforge.net) should work on a Pi3 (I tried it on a Pi2, and it mostly worked.) and is great DJ software.

Thank you. I am just so close. I just need to make the audio go through both outputs and I’m done. There has to be a way to do it.

Now I see your issue. You want dual audio output.

Unfortunately this is not trivial at this time.

Sam

That means it’s not possible? I assumed since it can be sent to both HDMI and analog, that it could be edited in a config file.

Audio’s not really my thing but what’s the problem with teeing the data stream? Something like

avconv -f alsa -i loopout -f mp3 - 2>/dev/null | tee <analogue sink> | sudo /usr/bin/ezstream -qvc /etc/ezstream.xml

bash: syntax error near unexpected token `|’

It was meant as pseudocode. But the syntax is correct:

echo hello | tee file1 | cat > file2

will write hello to file1 and file2.

hope you replaced the whole <> with the analogue sink, not haveing <>

Sorry guys. I’m trying to understand the commands I’m entering, but I don’t fully. This is the command that works for me. Can you help me with the actual command or help me to understand, so I can do it myself?

avconv -f alsa -i loopout -f mp3 - 2>/dev/null | sudo /usr/bin/ezstream -qvc /etc/ezstream.xml

What does it do, exactly?

Ezstream starts to broadcast to Icecast. I am trying to get audio going to both the analog output as well as the loopback, so it will broadcast to Icecast. The local FM station as well as internet radio.

Sorry it’s taken so long to get back. New Year and all that, plus I needed to get up to speed on ALSA loopback.

Here’s my understanding of what’s happening with ALSA loopback, at least on my Pi3:

1 You’ll send an audio stream to the loopback sink at hw:1,0.
2 The loopbck source hw:1,1 outputs the audio stream.
3 The original analogue audio sink at hw:0,0 is still available but isn’t being used.

The easiest way to access ALSA sinks and sources is to use aplay and arecord, respectively.

Caveat: It might be possible to get this to work using ALSA configuration alone but I’m no expert in this field – and judging by the quality of articles and posts on the Internet, I’m not alone. So the method I’m going to propose might not be ideal but it’s the best I can come up with, given my limited knowledge. I’m more of a *nix kinda dog, than an audio expert.

As mentioned previously, I’m proposing that you “tee” a copy of the hw:1,1 loopback source and send it to hw:0,0. Unfortunately, I can’t currently test it on a TV so you’ll need to experiement a bit at your end.

First, you need to create a Linux named pipe (“fifo”), then send data to hw:0,0 using aplay. Once data arrives in the pipe, it will play on the analogue output. This worked successfully in my tests.

mkfifo /home/osmc/alsapipe
aplay -D hw:0,0 < /home/osmc/alsapipe

Then in another SSH session, you need to read the audio source from hw:1,1 using arecord and tee a copy to /home/osmc/alsapipe.

arecord -D hw:1,1 | tee /home/osmc/alsapipe | ffmpeg -i pipe:0  -f mp3 - 2>/dev/null | sudo /usr/bin/ezstream -qvc /etc/ezstream.xml

(BTW, avconv is just a link to ffmpeg, so better to use its real name.)

This second part might be a bit trickier. If it just about works, we can try to clean it up a bit. If not, let me know what goes wrong.