I thought I'd share my recipe for overlaying music playing on pCP
machines with audio jingles. This is a simplified version of a working
setup with multiple emitters, multiple sounds, multiple players.
It uses multicast over UDP to let many devices receive the order to do
something (generally: play a sound.) Each device can elect to execute or
discard the order, according to its local configuration. So you can
arbitrary link one event from one device to one receiver to one output.
What gets sent via multicast is a simple ASCII string, not audio itself.
In the case of pCP players they select a local wav file corresponding to
the string, but non-audio receivers are possible too. The payload is
extremely small so network load is minimal.
Local processing is fast enough to ensure the delay between sending
(pressing a button) and executing (hearing a sound) feels ok. I've
elected to let socat do the multicast magic, as it is ported to many
platforms.
When multiple audio receivers play a jingle, there is no sync mechanism
but in effect with pCP you get all receivers to play at the same
instant.
The system works as long as there is one emitter and one receiver active
on the network, so it's independent from LMS. To overlay an incoming
audio jingle over possibly playing music, I've determined a double ramp
works best: music volume goes down gradually while the jingle volume
goes up gradually, and back.
With the JustBoom amp HAT I've used -and all i2s devices?- there is no
hardware mixer so a software mixer is defined with ALSA with 2 sources
and 2 volume controls.
The script that manipulates volume controls is very basic, it works with
jingles that are 4 or 5 seconds long. YMMV.
This is how to play a jingle on pCP 3.22 (normal kernel version) with an
add-on amp on a Pi 3 wired via ethernet:
- *Setup pCP via the web interface*, at
http://:
- -Install the socat extension.- Select Main Page, Beta (bottom of
page), then Extensions. On that new page, make sure you're using the
Official piCore repository (default), then in "Available extensions
in the Official piCore repository" select socat.tcz and press Load.
- -Select your add-on DAC or amp.- Select Squeezelite Settings,
then pick your add-on model under "Choose Audio output". Click Save.
Reboot if needed, come back here, click Audio card control, and
disable the onboard soundcard.
- -Setup Squeezelite to use an ALSA audio mixer.- Select
Squeezelite Settings, then in field "Output setting" enter the value
"music" (without quotes). Press Save. If you restart Squeezelite as
prompted it will now fail, that's ok.
- -Set pCP to run a script at boot.- Select Tweaks, then under
"User commands", enter user command "/home/tc/gong.sh" (no quotes)
and press Save.
- *Locate a wav jingle file* and copy it under the name "action1.wav"
to pCP, e.g. "scp jingle.wav
tc@:~/action1.wav". The setup is known to
work with audio files ~ 4-5 secs. in duration, format "Signed 16 bit
Little Endian, Rate 44100 Hz, Mono"
- *Customize pCP via the shell*, at ssh
tc@:
- -Replace the stock /etc/asound.conf- file with this:
Code:
## Onboard audio disabled in /boot/config.txt
## Otherwise volume sliders that use "control.card X"
## could attach to the wrong card at boot in pCP 3.2.0.
##
## Alsaequal removed from this file. Some issues controlling
## softvols with equal in pCP 3.2.0. Add it back if you want.
##
## Make sure hardware volume control "Digital" is set to
## a safe value, you probably don't want a jingle to play
## at full power by accident
##
## A) Devices available to applications
##
# Squeezelite is set to use this device
# This softvol allows to ramp down-up music when an application
# plays another sound.
# Nominal state is: 100%
pcm.music {
type softvol
slave.pcm plug:dmixer
control.name musicvol
control.card 0
}
# Same story here: ramp up-down sounds sent by other applications
# Nominal state is: 0%
pcm.gong {
type softvol
slave.pcm plug:dmixer
control.name gongvol
control.card 0
}
## B) Audio output device. Here: Justboom amp HAT
##
# Shared access to our audio card
pcm.dmixer {
type dmix
ipc_key 1234
ipc_key_add_uid true # Needed ?
ipc_perm 0666
slave {
pcm "hw:CARD=sndrpijustboomd,DEV=0"
}
}
# Whatever ctl magic thing
ctl.dmixer {
type hw
card 0
}
#EOF
E.g. from the shell session on pCP, run "cp /etc/asound.conf
~/asound.conf.orig", then copy the code above, run "cat >
/etc/asound.conf", paste clipboard contents in the window, and hit