This project is a continuation of my previous RPi Zero 2 W Audio Gadget project.
The goal of this project is to use the RPi Zero 2 W as a fully functional DAC and DSP. This will be accomplished by using CamillaDSP as well as some other useful pieces of software to connect the USB capture device on the Pi to the Allo miniBOSS DAC. The DSP functionality of CamillaDSP will not really be covered, but the basic config provided with this guide can be expanded upon very easily to add filters, mixers, processing pipelines, and more. The basic config can also be adapted for use with other input/output devices.
This project also adds volume and mute controls that are adjusted from the USB host device. In this case, a Windows computer is used as the host, and the volume and mute on the RPi can be adjusted using the volume control and mute button in Windows.
There are a few assumptions that are made for this guide:
- You followed the previous guide and have a working g_audio device
- Your username is "pi": this can be changed, but you will need to change every instance of "pi" in the config files and.service files
- The port you want to use for the CamillaDSP websocket is "1234": This can also be easily changed by editing the various config files and start command for
camilladsp.serviceand the websocket port in
- You are running kernel 5.18-rc3 or greater on the RPi: Older kernels may work, but 5.18 includes improvements to the g_audio driver and, from my testing, works much better with Windows hosts than previous versions.
First, the Allo miniBOSS must be added as an overlay:
sudo nano /boot/config.txt
dtparam=audio parameter as follows to disable the onboard audio card:
Then add this line to the end of the file:
Now reboot your RPi and check that the DAC shows up:
aplay -l && arecord -l
The output should be similar to this:
You may have more or less devices depending on what audio devices are currently plugged in to you pi, but BossDAC (pcm512x-hifi-0) should be in the list of playback devices.Step 2: Reconfiguring g_audio
Now the UAC2 sound card needs to be reconfigured. The miniBOSS is a 384kHz/32-bit DAC so the USB capture device will be set as such. For simplicity, only use one sample rate. At the time of this writing, changing sample rates is not handled easily by CamillaDSP.
Create a new configuration file for g_audio to be read at boot.
sudo nano /etc/modprobe.d/g_audio.conf
then add the appropriate settings to the file:
options g_audio c_srate=384000 c_ssize=4 p_chmask=0 iProduct="RPi USB DAC"
c_srate- the capture sample rate in Hz
c_ssize- the size of a sample in bytes
p_chmask- setting the playback channel mask to 0 disables USB playback
iProduct- a string to describe the device
See my previous guide for more information on what each of these settings does. These can be used to further customize the USB audio device to meet your needs.
If you want to test that this worked properly, reboot and check the currently loaded settings with:
Step 3: Setting Up CamillaDSP
grep -H '' /sys/module/g_audio/parameters/*
First, install dependencies:
sudo apt install alsa-utils python3 python3-pip python3-websocket python3-aiohttp python3-jsonschema python3-numpy python3-matplotlib unzip git -y
Create the folder structure:
mkdir coeffs configs
NOTE: From this point forward, this guide assumes you are in the
Now add the CamillaDSP config file for this device:
wget https://raw.githubusercontent.com/Masonrf/RPi-Z2W-USB-Soundcard/main/camilladsp.yml -P configs
Make the log file:
Now download the latest version of CamillaDSP. This command depends on the architecture of the device it will be run on.
For 64-bit RPi:
For 32-bit RPi:
Extract the tarball:
tar -xvf camilladsp-linux-*.tar.gz
Now try to start up CamillaDSP:
./camilladsp -g-10 -p 1234 configs/camilladsp.yml
It should (hopefully) start up without any errors. You may get warnings about wait time outs if you do not have any audio playing from the host:
If you want to do some testing, but only want errors, change the start command to only show errors:
./camilladsp -g-10 -p 1234 configs/camilladsp.yml -l error
Now we can start CamillaDSP at boot as a service.
Download the service file and enable it at boot:
sudo wget https://raw.githubusercontent.com/Masonrf/RPi-Z2W-USB-Soundcard/main/camilladsp.service -P /lib/systemd/system
sudo systemctl enable camilladsp
Make sure you get the last line "Created symlink..."
Install pycamilladsp and its plotting functionality:
sudo git clone https://github.com/HEnquist/pycamilladsp
sudo pip3 install .
sudo git clone https://github.com/HEnquist/pycamilladsp-plot
sudo pip3 install .
unzip camillagui.zip -d camillagui
Next, we need to reconfigure camillagui:
active_config to the path for the camillaDSP device config:
Now add CamillaGUI as a service and enable at boot:
sudo wget https://raw.githubusercontent.com/Masonrf/RPi-Z2W-USB-Soundcard/main/camillagui.service -P /lib/systemd/system
sudo systemctl enable camillagui
Now reboot and go to
http://(your pi ip):5000/ in your browser
You should see a gui interface for CamillaDSP
If not, check that the services are active:
sudo systemctl status camilladsp.service
sudo systemctl status camillagui.service
If you run into any problems, shoot me a direct message on hackster.Step 5: Adding Host Volume Control/Mute
The final step is adding a python program to connect the USB volume and mute control signals sent from the host computer to CamillaDSP.
sudo apt install libasound2-dev
pip install pyalsaaudio
Download the python program and test it:
You should see values change as you change the host computer volume and mute selection. You should also be able to hear the changes while the python program is running and you have sound playing through the USB connection.
Now add this functionality as a service at boot:
sudo wget https://raw.githubusercontent.com/Masonrf/RPi-Z2W-USB-Soundcard/main/usb-control.service -P /lib/systemd/system
sudo systemctl enable usb-control
Finally, reboot for the changes to take effect.
You should now be able to mute and change the volume from your host computer!