I am trying to achieve a multi-room audio setup in my house using Raspberry Pis. How can I get VLC playing simultaneously out the local headphone port while also streaming it to other devices via trx?
Background:
I have found a fantastic package called trx which allows low-latency streaming using the Opus codec across the LAN: http://www.pogo.org.uk/~mark/trx/streaming-desktop-audio.html
I have managed to successfully get trx installed and working with the following:
sudo modprobe snd-aloop
Transmission side ~/.asoundrc
# TX device catches played audio from a player (e.g. VLC)
# point vlc to this device:
# cvlc --alsa-audio-device="tx" <file_or_stream>
pcm.tx {
type plug
slave.pcm {
type dmix
ipc_key 2867
slave {
pcm "hw:Loopback,0,0"
rate 48000
format S16_LE
channels 2
period_size 256
buffer_size 8192
}
}
}
# Hubcap ensures 48000Hz sample rate (Opus compatible)
pcm.hubcap {
type plug
slave {
pcm "hw:Loopback,1,0"
rate 48000
format S16_LE
}
}
Transmission side:
tx -d hubcap -m 64 -h 239.0.0.99 &
cvlc --alsa-audio-device="tx" {source_file_path_or_url}
Receiving side:
rx -m 64 -h 239.0.0.99
There are occasional buffer underruns which are easily fixed by changing the niceness of the tx processes to -10.
renice -n -10 {process_id}
The problem:
I would like to be able to play audio from VLC to the devices across the network listening to the multicast 239.0.0.99, and also from the transmission device's headphone / line-out socket.
I cannot figure out how to set up a plug, route and multi in ~/.asoundrc so that there is one ALSA device cvlc can play to, where the audio is fed to both local hw:1 (headphone socket) and plug:tx (input for audio to be transmitted via tx).
The ALSA asound configuration documentation is abysmal. I have tried the following addition to .asoundrc with no luck:
pcm.headphones_dmix {
type dmix
slave {
pcm "hw:Headphones"
}
}
pcm.localandtx {
type plug
slave {
format S16_LE
pcm {
type multi
slaves.tx.pcm "tx"
slaves.tx.channels 2
slaves.local.pcm "headphones_dmix"
slaves.local.channels 2
bindings.0.slave tx
bindings.0.channel 0
bindings.1.slave tx
bindings.1.channel 1
bindings.2.slave local
bindings.2.channel 0
bindings.3.slave local
bindings.3.channel 1
}
}
route_policy duplicate
ttable {
0.0 1
1.1 1
0.2 1
1.3 1
}
hint {
show on
description "Play both locally and via TX."
}
}
With the above:
vlc will happily play to the local headphones with --alsa-audio-device="hw:Headphones"
vlc will happily play to devices running rx with --alsa-audio-device="tx"
But, vlc won't play to either with --alsa-audio-device="localandtx"
. I want it to play to both. (I am aware of the additional latency when sending audio via trx).
The vlc errors are:
ALSA lib pcm_direct.c:2031:(snd1_pcm_direct_parse_open_conf) Unique IPC key is not defined
[015a4ac8] alsa audio output error: cannot open ALSA device "localandtx": Invalid argument
[015a4ac8] main audio output error: Audio output failed
[015a4ac8] main audio output error: The audio device "localandtx" could not be used: Invalid argument.
[015a4ac8] main audio output error: module not functional
[71b7a980] main decoder error: failed to create audio output
Is there any useful (sane) tool for debugging an ALSA asound config file?
How do I determine which .asoundrc argument in localandtx is "invalid"?
How can I achieve audio routing to both hw:Headphones and tx in ALSA without using PulseAudio?