Possible to have Analog and loopback audio?

I’m no expert either, but I would be looking to do a similar thing in alsa, using the dsnoop plug-in which shares a single stream to more than one slave. (it says)

Well, if you can offer a working example, that would be excellent.

ALSA also provides a tee device but I couldn’t get it to work. Unfortunately, the Internet seems to be full of boilerplate “articles” on using ALSA tee that are just a copy/paste of the same info.

Thank you for taking the time to help me with this. Sorry it took me so long to get back. Happy New Year to you.
I followed your instructions and here are the results.

In the first SSH session I ran:
aplay -D hw:0,0 < /home/osmc/alsapipe

And then I opened a second SSH session and ran:
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

As soon as I ran the second command, the first session reports:
aplay: playback:2715: read error

And in the second, in an endless loop:
ezstream: Streaming from standard input
ezstream: No (more) data available on standard input

As you can guess, I’ve still a lot to learn about ALSA.

One thing I learned since last posting is that the order of the devices can change, so that loopback can be on “card” 0 and the analogue device on “card” 1. This issue can be sidestepped by using the device names shown when you run aplay -L, rather than their numbers. So the revised commands would be:

aplay -D hw:CARD=ALSA,DEV=0 < /home/osmc/alsapipe

and

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

(You won’t need to create /home/osmc/alsapipe each time.)

This might have caused your errors. If you run aplay -l you can see what card number has been allocated to the ALSA and Loopback cards.

All this depends on the sound being sent to CARD=Loopback,DEV=0.

I’m getting the same error on session 2:
ezstream: Streaming from standard input
ezstream: No (more) data available on standard input

But it doesn’t kill the first session now.

Here is the output of aplay -l:

**** List of PLAYBACK Hardware Devices ****
card 0: Loopback [Loopback], device 0: Loopback PCM [Loopback PCM]
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: Loopback [Loopback], device 1: Loopback PCM [Loopback PCM]
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 1: 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 1: ALSA [bcm2835 ALSA], device 1: bcm2835 ALSA [bcm2835 IEC958/HDMI]
Subdevices: 1/1
Subdevice #0: subdevice #0

Which is an improvement, for sure.

One step at a time…

arecord -D hw:CARD=Loopback,DEV=1 | tee /home/osmc/alsapipe | cat > /dev/null

Do you hear sound on the analogue output?

Of course, and thank you for helping.
I don’t hear audio on the analog port, no.

tee: /home/osmc/alsapipe: Permission denied
Recording WAVE ‘stdin’ : Unsigned 8 bit, Rate 8000 Hz, Mono
arecord: set_params:1233: Sample format non available
Available formats:

  • S32_LE

Try:

arecord -D hw:CARD=Loopback,DEV=1 -f S32_LE -r 44100 | tee /home/osmc/alsapipe | cat > /dev/null

I’m guessing the bitrate.

What does ls -l /home/ismc/alsapipe show? Are you running this as user osmc?

tee: /home/osmc/alsapipe: Permission denied
Recording WAVE ‘stdin’ : Signed 32 bit Little Endian, Rate 44100 Hz, Mono
arecord: set_params:1239: Channels count non available

ls -l /home/ismc/alsapipe returns:
ls: cannot access /home/ismc/alsapipe: No such file or directory

And yes, running osmc with sudo su

ls -l /home/osmc/alsapipe

prw-r–r-- 1 root root 0 Jan 3 08:44 /home/osmc/alsapipe

Aargh. Remove it and create it under osmc.

Ok, now it’s:
prw-r–r-- 1 osmc osmc 0 Jan 3 11:35 /home/osmc/alsapipe

1 Like

I’m getting:
Recording WAVE ‘stdin’ : Signed 32 bit Little Endian, Rate 44100 Hz, Mono
arecord: set_params:1239: Channels count non available

But it’s doing something. It’s not a prompt. Although I still don’t hear audio from analog.

If it’s being fed stereo, add -c 2 to the arecord command.

Where is Kodi sound being sent now? I have a feeling it might be going to the wrong place.

Forgive me if this is wrong, but I put -c at the beginning.
I ran:
arecord -D -c 2hw:CARD=Loopback,DEV=1 -f S32_LE -r 44100 | tee /home/osmc/alsapipe | cat > /dev/null

It returns:
ALSA lib pcm.c:2239:(snd_pcm_open_noupdate) Unknown PCM -c
arecord: main:722: audio open error: No such file or directory

And Kodi sound is being sent to the first loopback. output device=ALSA: Loopback (loopin), Loopback PCM
But there are 3 different loopbacks.

arecord -c 2 -D hw:CARD=Loopback,DEV=1 -f S32_LE -r 44100 etc...

Please list the loopback options.

Warning: rate is not accurate (requested = 44100Hz, got = 48000Hz)
please, try the plug plugin

The loopback options are:
ALSA: Default (Loopback Loopback PCM)
ALSA: Loopback (@:CARD=Loopback,DEV=0), Loopback PCM |
ALSA Loopback (surround21:CARD=Loopback,DEV=0), Loopback PCM |

I changed arecord -c 2 -D hw:CARD=Loopback,DEV=1 -f S32_LE -r 44100 etc…
to
arecord -c 2 -D hw:CARD=Loopback,DEV=1 -f S32_LE -r 48000 etc…

and no error now. But still no audio from analog.

I went through and tried arecord -c 2 -D hw:CARD=Loopback,DEV=1 -f S32_LE -r 44100 etc…
with all three looback devices in Kodi and the third one (ALSA Loopback (surround21:CARD=Loopback,DEV=0), Loopback PCM)
gave me the error again, but in reverse.
Warning: rate is not accurate (requested = 48000Hz, got = 44100Hz)

That’s not right. Either your .asoundrc is wrong or you haven’t restarted Kodi since you created it.

Edit: It should look something like this:

alsa-loopback

1 Like