I played around with the alsa_cdsp plugin (
https://github.com/scripple/alsa_cdsp) this weekend and can share a basic configuration that works with the Ultralite Mk5. For those unaware the alsa_cdsp plugin establishes an ALSA device called camilladsp that you can specify as the playback device for software players like squeezelite and shairport-sync. The advantage of using the alsa_cdsp plugin is that it can dynamically switch the sample rate and format of CamillaDSP based on the file you are playing.
This is not meant to be an exhaustive tutorial and it is important to read all of the notes / caveats on the GitHub, also many of things in my base tutorial won't work with the plugin (cannot use camilladsp.service, oled.py doesn't work, cannot switch configurations in the GUI, etc). Personally I don't think it is worth the effort to pursue the alsa_cdsp plugin over the approach described in this tutorial as without further refinement it has numerous usability issues.
Here are instructions for installing the plugin.
Code:
sudo apt install libasound2-dev
git clone https://github.com/scripple/alsa_cdsp
cd alsa_cdsp
make
sudo make install
Make an asound.conf if you do not have one already.
Code:
sudo nano /etc/asound.conf
There are multiple approaches to using the alsa_cdsp plugin, the example asound.conf shown below uses the config_in approach.
Code:
# This declares an ALSA device that you can specify to playback programs.
# You can use any name you wish that ALSA supports not just camilladsp.
# To use it you specify it to alsa like "aplay -D camilladsp"
pcm.camilladsp {
# type cdsp must be present - it declares to use this plugin.
# The type is NOT a variable name you can choose.
# You can however create multiple type cdsp plugins with different names
# if you want to specify different parameters selected by specifying a
# different ALSA device.
type cdsp
#######################################################################
#######################################################################
# Required parameters.
# The parameters in this section must be specified as a valid set.
#######################################################################
#######################################################################
# cpath specifies the absolute path to the CamillaDSP executable.
# CamillaDSP must have executable permission for any user that runs an
# audio program that uses this plugin.
cpath "/home/michael6/camilladsp/camilladsp"
# config_out is the absolute path that will be passed to CamillaDSP as
# the YAML config file argument. The file must be readable by any user
# that runs an audio program that uses this plugin. If the config_in
# or config_cmd options are chosen (see below) it must also be writable
# by those users.
config_out "/home/michael6/camilladsp/configs/config_out.yml"
#######################################################################
# Parameter Passing Options
#
# There are three mutually exclusive ways to send the updated hw_params
# and extra_samples to CamillaDSP. One and only one method must be
# specified. The three methods are config_in, config_cmd, and
# config_cdsp.
#######################################################################
# config_in is an absolute path to a YAML template the plugin will read
# and pass along to CamillaDSP after making simple token substitutions.
# It must be readable by any user that runs an audio program that uses
# this plugin.
config_in "/home/michael6/camilladsp/configs/config_in.yml"
# config_in processing does a simple search and replace of four tokens
# representing format, channels, sample rate, and extra samples
# replacing the tokens with the appropriate parameters. The following
# entries show the default tokens. They can be changed to custom
# tokens by uncommenting the lines below and replacing the default
# tokens with the desired tokens wrapped in quotes.
#format_token "$format$"
#samplerate_token "$samplerate$"
#channels_token "$channels$"
#extrasamples_token "$extrasamples$"
# config_cmd is the absolute path to a command that will be called
# whenever the hw_params change with arguments "format rate channels".
# It should create the YAML file CamillaDSP will load and place it in
# the location specified by the config_out parameter.
# Note that the extra_samples parameters specified below are NOT
# passed in any way to this command.
#config_cmd "/path/to/more_complex_yaml_creator"
# config_cdsp says to use the new CamillaDSP internal substitutions.
# When config_cdsp is set to an integer != 0 the hw_params and
# extra samples are passed to CamillaDSP on the command line as
# -f format -r samplerate -n channels -e extra_samples
#config_cdsp 1
#######################################################################
# End Parameter Passing Options
#######################################################################
#######################################################################
# Capability Enumeration
#
# The plugin will announce the hw_params it supports based on the
# following settings. Channels and sample rates must be specified.
# The plugin will automatically enumerate all the formats that
# CamillaDSP supports.
#######################################################################
# Channels can be specified as a single value like this.
channels 2
# Or a range like this. (Uncomment the lines.)
#min_channels 1
#max_channels 2
# But only one method can be used.
# Sample rates can be configured as a specific list like this.
# (Up to 100 entries.)
rates = [
44100
48000
88200
96000
176400
192000
# 352800
# 384000
]
# Or as a range like this. (Uncomment the lines.)
#min_rate 44100
#max_rate 384000
# Note that if you use a range like this ALSA will accept ANYTHING in
# that range. Even something odd like 45873. If you aren't using
# CamillaDSP's resampler and don't have a very unusual DAC you are
# probably better off with the list format above.
#######################################################################
# End Capability Enumeration
#######################################################################
#######################################################################
#######################################################################
# End Required Parameters
#######################################################################
#######################################################################
#######################################################################
#######################################################################
# Optional Parameters
#######################################################################
#######################################################################
# If you wish to specify additional arguments to CamillaDSP you can
# specify them using the cargs array. Numeric arguments must be quoted
# in strings or the plugin will fail to load. You should not specify
# the hw_params arguments here as the plugin will take care of that as
# they change.
cargs [
-p "1234"
-a "0.0.0.0"
-g-40
-o /home/michael6/camilladsp/camilladsp.log
-v
]
# Extra samples can be provided in a rate scaling way for the two most
# common audio base rates. This is under the assumption your filters
# will be N times as long at N times the base rate. Any of the
# following three values can be set or excluded in any combination.
# If no valid extra_samples parameter is set for a given sample rate
# the extra_samples token replacement will not occur in config_in mode
# and the -e argument will not be issued in config_cdsp mode.
# All extra_samples arguments must be integers >= 0.
# extra_samples is used when the sample rate is not an integer multiple
# of 44100 or 48000 or when the corresponding rate matching
# extra_samples option is not set.
#
# If using config_cdsp this is the only version of extra_samples
# that should be specified as CamillaDSP does its own sample rate
# based scaling of the extra samples.
extra_samples 0
# extra_samples_44100 is used when the sample rate is an integer
# multiple of 44100. In this case {extrasamples} will be replaced with
# {samplerate/44100 * extra_samples_44100}.
extra_samples_44100 8192
# extra_samples_48000 is used when the sample rate is an integer
# multiple of 48000. In this case {extrasamples} will be replaced with
# {samplerate/48000 * extra_samples_48000}.
extra_samples_48000 8916
# An option not directly related to camilladsp. A command to run when
# the plugin is first created. (Meaning when a playback program opens
# the audio device.) Use it for whatever you want. Set gpio pins on a
# raspberry pi to turn on your amp for example.
##start_cmd "/path/to/start_command"
}
You specify a configuration file called config_in which can have dynamic values for channels, format, sample rate and extra samples. The plugin will then create a configuration file called config_out based on the specific values of the file you are playing and load CamillaDSP with the config_out configuration. It will do this every time one of these values changes.
In order for this to work you need to update the cpath, config_in and config_out values in asound.conf to reflect your camillaDSP path and where you store your configuration files. For reference this example uses a hostname of raspberrypi6 and a username of michael6.
You also need to create a config_in.yml file at the location you specify.
Code:
nano ~/camilladsp/configs/config_in.yml
Below is an example config_in.yml for an Ultralite Mk5. A few things of note, I needed to use plughw:UltraLiteMk5 as my playback device and specify 10 channels in order for the plugin to work with all sample rates. The reason for this is the Ultralite Mk5 has different output channel counts depending on sample rate and unless you use plughw it expects the exact number of channels. If I would have used a higher number of channels (say 22 output channels for 44.1/48 kHz) the configuration would fail at higher sample rates.
This example also shows how you can specify FIR filters for different sample rates by appending the sample rate at the end of the file name and using the $samplerate$ flag when specifying the filter name in CamillaDSP. Of course this requires you to generate specific FIR filters for every sample rate you want to use. As you can see below I created FIR filters in rephase for 44.1, 48, 88.2, 96, 176.4 and 192 kHz.
You also need to update the configuration files for your software players to use a playback device called camilladsp.
For squeezelite:
Code:
sudo nano /etc/default/squeezelite
Note that all resampling has been implemented from this configuration.
Code:
# Defaults for squeezelite initscript
# sourced by /etc/init.d/squeezelite
# installed at /etc/default/squeezelite by the maintainer scripts
# The name for the squeezelite player:
SL_NAME="$(hostname -s)"
# ALSA output device:
# Squeezebox server (Logitech Media Server):
# Uncomment the next line if you want to point squeezelite at the IP address of
# your squeezebox server. This is usually unnecessary as the server is
# automatically discovered.
#SB_SERVER_IP="192.168.x.y"
# Additional options to pass to squeezelite:
# Please do not include -z to make squeezelite daemonise itself.
SB_EXTRA_ARGS="-W -C 5"
SL_SOUNDCARD="camilladsp"
For shairport-sync:
Code:
sudo nano /etc/shairport-sync.conf
Change alsa output_device to "camilladsp".
Also, you need to change the username in the shairport-sync.service to allow shairport-sync to start camilladsp.
Code:
sudo nano /lib/systemd/system/shairport-sync.service
Change your username from shairport-sync to whatever your username is, in my case michael6.
Code:
[Unit]
Description=Shairport Sync - AirPlay Audio Receiver
After=sound.target
Requires=avahi-daemon.service
After=avahi-daemon.service
Wants=network-online.target
After=network.target network-online.target
[Service]
ExecStart=/usr/local/bin/shairport-sync --log-to-syslog
User=michael6
Group=shairport-sync
[Install]
WantedBy=multi-user.target
At this point restart your RPi and you should be good to go.
Overall it seems to work well with a few issues. The Ultralite Mk5 takes a few seconds to switch so you won't hear the first few seconds of a song after a switch. Because the plugin restarts CamillaDSP there are also issues with using CamillaDSP volume control. I added "-g-40" to my asound.conf so that CamillaDSP always restarts at -40 dB but if you don't include this it will restart at -0 dB and you will be in for a nasty surprise. Either way the change in volume when changing a song is annoying.
I am not adding this approach to the tutorial and do not plan on helping folks troubleshoot using this approach but hopeful this post points people in the right direction if they are interested in pursuing the plugin.
Good luck!
Michael