01-30-2020, 05:55 PM
Hi Tim
I know very little about ALSA, what I know is just from trying to duplicate a stream!
The loopback is handled by the snd_aloop driver.
There are three configuration files in the mpd_oled issue, but it is worth reviewing all of them
My Moode config: https://github.com/antiprism/mpd_oled/is...-567146826
In my Moode /etc/mpd.conf file, mpd is outputing to "hw:0,0". I don't know how to overload "hw:0,0" (I am not sure if it can be done) but I can overload "hw", and this is what the configuration file does. It means that whenever Moode/mpd writes to hw:X or hw:X,Y the overload will be used and a copy sent to the loopback device. It may have consequences, because it is used whenever "hw" is used.
Sergey's Volumio config: https://github.com/antiprism/mpd_oled/is...-536098398
I think when Volumio uses hardware volume it outputs to the "default" ALSA device. This can be overriden. However, the original output device is not known, and so needs to be specified, in this case "hw:IQaudIODAC,0"
My Volumio config: https://github.com/antiprism/mpd_oled/is...-423255641
Using Volomio software volume the system set up an alsa config file with pcm.softvolume that called pcm.softvol. I changed pcm.softvolume to call my duplication config plugin, which then called the origional pcm.softvol.
I think the last approach is the way to go. When Moode wants to play something it would always play it to the same named ALSA plugin, e.g. "playerout". When Moode configures a device, it wouldn't refer to a "hw" name directly, but configure it in a plugin, say "deviceout". Then, in a global configuration file "deviceout" is a slave of "playerout", so anything that plays to "playerout" is heard on the "deviceout" device.
Now, if anybody wants to do anything with the audio before it is played they can override "playerout" and have "deviceout" as a slave, and the processed audio will go to the configured device.
I'll give an example. On Ubuntu I have created a global ALSA config /etc/asoundrc
I can now play some audio to the "playerout" device and it comes out of my speakers
If I want to duplicate the audio, I can simply write an .asoundrc file to override "playerout", and send the audio to be played on to "deviceout" and I don't need to know the hardware device name
I can now play audio as before, with the sound coming out the speakers
In a separate terminal I can now show a spectrum analyser for the audio with cava by creating a config file conf.txt
And running cava with this configuration
For Moode you could probably specify a Moode-only config file in /usr/share/alsa/alsa.conf, then the user overrides could be put in /etc/asound.conf as now. Moode could create some duplicate streams in the UI with the same kind of configuration override, playerout -> moode processing/duplicates -> moodeout -> user processing/duplicates -> deviceout (the user would override moodeout in this chain). But even if Moode doesn't provide anything in the UI, the ALSA config file for creating duplicates is now much easier to write and should be robust over different audio configurations.
Adrian.
I know very little about ALSA, what I know is just from trying to duplicate a stream!
The loopback is handled by the snd_aloop driver.
There are three configuration files in the mpd_oled issue, but it is worth reviewing all of them
My Moode config: https://github.com/antiprism/mpd_oled/is...-567146826
In my Moode /etc/mpd.conf file, mpd is outputing to "hw:0,0". I don't know how to overload "hw:0,0" (I am not sure if it can be done) but I can overload "hw", and this is what the configuration file does. It means that whenever Moode/mpd writes to hw:X or hw:X,Y the overload will be used and a copy sent to the loopback device. It may have consequences, because it is used whenever "hw" is used.
Sergey's Volumio config: https://github.com/antiprism/mpd_oled/is...-536098398
I think when Volumio uses hardware volume it outputs to the "default" ALSA device. This can be overriden. However, the original output device is not known, and so needs to be specified, in this case "hw:IQaudIODAC,0"
My Volumio config: https://github.com/antiprism/mpd_oled/is...-423255641
Using Volomio software volume the system set up an alsa config file with pcm.softvolume that called pcm.softvol. I changed pcm.softvolume to call my duplication config plugin, which then called the origional pcm.softvol.
I think the last approach is the way to go. When Moode wants to play something it would always play it to the same named ALSA plugin, e.g. "playerout". When Moode configures a device, it wouldn't refer to a "hw" name directly, but configure it in a plugin, say "deviceout". Then, in a global configuration file "deviceout" is a slave of "playerout", so anything that plays to "playerout" is heard on the "deviceout" device.
Now, if anybody wants to do anything with the audio before it is played they can override "playerout" and have "deviceout" as a slave, and the processed audio will go to the configured device.
I'll give an example. On Ubuntu I have created a global ALSA config /etc/asoundrc
Code:
pcm.playerout {
type plug
slave.pcm "deviceout"
}
pcm.deviceout {
type plug
slave.pcm "hw:1"
}
I can now play some audio to the "playerout" device and it comes out of my speakers
Code:
aplay -D playerout tmp.wav
If I want to duplicate the audio, I can simply write an .asoundrc file to override "playerout", and send the audio to be played on to "deviceout" and I don't need to know the hardware device name
Code:
pcm.!playerout {
type plug
slave.pcm {
type multi
slaves {
a { channels 2 pcm "deviceout" } # the real device
b { channels 2 pcm "plughw:Loopback,0" } # the loopback driver
}
bindings {
0 { slave a channel 0 }
1 { slave a channel 1 }
2 { slave b channel 0 }
3 { slave b channel 1 }
}
}
ttable [
[ 1 0 1 0 ] # left -> a.left, b.left
[ 0 1 0 1 ] # right -> a.right, b.right
]
}
I can now play audio as before, with the sound coming out the speakers
Code:
aplay -D playerout tmp.wav
In a separate terminal I can now show a spectrum analyser for the audio with cava by creating a config file conf.txt
Code:
[input]
method = alsa
source = hw:Loopback,1
And running cava with this configuration
Code:
cava -p conf.txt
For Moode you could probably specify a Moode-only config file in /usr/share/alsa/alsa.conf, then the user overrides could be put in /etc/asound.conf as now. Moode could create some duplicate streams in the UI with the same kind of configuration override, playerout -> moode processing/duplicates -> moodeout -> user processing/duplicates -> deviceout (the user would override moodeout in this chain). But even if Moode doesn't provide anything in the UI, the ALSA config file for creating duplicates is now much easier to write and should be robust over different audio configurations.
Adrian.