Sample rate switcher for CamillaDSP

The only issue that I run into (in versions 2.2 and 2.2.1) is that the samplerate set in the CamillaDSP configuration file must match the first song that I play.
Note that camilladsp-setrate updates the samplerate in camilladsp configuration only if the alsa control detects a sample rate change event.
In my setup at boot the alsa control always detects a sample rate change to 768 KHz so, when the audio capture starts, a rate change to the correct sample rate is triggered and camilladsp configuration is updated correctly. This way everything works fine also at reboot regardless of the sample rate initially configured in the the camilladsp configuration file.
Hard to figure out what happens in your setup. Log files could give me useful information.
 
Last edited:
  • Like
Reactions: TerryForsythe
I realised that at boot the alsa control for the capture device (i.e. the USB gadget) always detects a sample rate change to the maximum supported sample rate, i.e. the maximum sample rate set during the gadget initialization.
Now I wonder if this happens in my setup only or if this is the expected behaviour of the usb gadget driver. If this were the case, the problem I pointed out in post #142 could easily be solved.
 
Note that camilladsp-setrate updates the samplerate in camilladsp configuration only if the alsa control detects a sample rate change event.
In my setup at boot the alsa control always detects a sample rate change to 768 KHz so, when the audio capture starts, a rate change to the correct sample rate is triggered and camilladsp configuration is updated correctly. This way everything works fine also at reboot regardless of the sample rate initially configured in the the camilladsp configuration file.
Hard to figure out what happens in your setup. Log files could give me useful information.
Thank you! I have not experienced this issue since my last post. If it happens again I will capture the log file.
 
  • Like
Reactions: mevang
Hi @TerryForsythe, looks like you were lucky and got the Wiim Ultra together with Camilla DSP on Raspi up and running properly with camilladsp-setrate - that's really amazing! I have exactly the same setup like you. My CamillaDSP works and I followed the camilladsp-setrate tutorial on github until point 7. Unfortunately then I get stuck, I don't understand how to configure and start camilladsp-setrate in order to make it work with CamillaDSP. Is there any chance you could help me to get it up and running? Did you create any special config file, that you could share with me? Unfortunately I'm new to linux, so I have to look up every single command 🙂. Your help and feedback would be greatly appreciated!

Another question: Did you also use a USB-C Y-splitter cable in order to be able to connect the Wiim to the Raspi USB-C port, while also powering it from a USB-C power supply. If I connect the Wiim Ultra directly to the USB-C Raspi port, it boots up and instantly turns off with the red status LED, as the power provided by the Wiim isn't enough. Is there any better option than using a USB-C Y-splitter cable?
 
I don't understand how to configure and start camilladsp-setrate in order to make it work with CamillaDSP.
Exactly how far have you come?

1) Check that the camilladsp-setrate service is active:
sudo systemctl status camilladsp-setrate

2) Check that the USB Gadget is up and running as a capture device:
arecord -l

3) Check that your DAC is available as a valid playback device:
aplay -l

4) Check that the camilladsp configuration file specifies the USB Gadget as capture device and your DAC as playback device.

Is there any better option than using a USB-C Y-splitter cable?
I use this small splitter board:
https://it.aliexpress.com/item/1005...t_main.25.32d236967iCMsr&gatewayAdapt=glo2ita
 
Hi @mevang, thanks a lot for your reply and help!

My status:
  • Wiim Ultra successfully connected via USB-C splitter (power supply on one of the outlets)
  • Wiim is recognising the Raspi as Linux DAC: Linux 6.6.28+rpt-rpi-2712
  • CamillaDSP works perfectly with a fixed samplerate (currently 48 khz)
  • I followed the camilladsp-setrate Github tutorial https://github.com/marcoevang/camilladsp-setrate until point 7. After that, I tried a few of the commands with the given flags, but usually got error messages and nothing changed.

Here are the replies, I receive based on your commands:

1) Check that the camilladsp-setrate service is active:
sudo systemctl status camilladsp-setrate

×
camilladsp-setrate.service - Automatic Sample Rate Changer Daemon for Camilla>


Loaded: loaded (/etc/systemd/system/camilladsp-setrate.service; enabled; p>


Active: failed (Result: exit-code) since Sat 2024-10-05 12:04:05 CEST; 1h >


Process: 1200 ExecStartPre=sleep 0.5 (code=exited, status=217/USER)


CPU: 0





Oct 05 12:04:05 raspberrypi systemd[1]: camilladsp-setrate.service: Scheduled r>


Oct 05 12:04:05 raspberrypi systemd[1]: Stopped camilladsp-setrate.service - Au>


Oct 05 12:04:05 raspberrypi systemd[1]: camilladsp-setrate.service: Start reque>


Oct 05 12:04:05 raspberrypi systemd[1]: camilladsp-setrate.service: Failed with>


Oct 05 12:04:05 raspberrypi systemd[1]: Failed to start camilladsp-setrate.serv>


lines 1-11/11 (END)




2) Check that the USB Gadget is up and running as a capture device:
arecord -l



** List of CAPTURE Hardware Devices **


card 2: UAC2Gadget [UAC2_Gadget], device 0: UAC2 PCM [UAC2 PCM]


Subdevices: 0/1


Subdevice #0: subdevice #0


card 3: Loopback [Loopback], device 0: Loopback PCM [Loopback PCM]


Subdevices: 8/8


Subdevice #0: subdevice #0


Subdevice #1: subdevice #1


Subdevice #2: subdevice #2


Subdevice #3: subdevice #3


Subdevice #4: subdevice #4


Subdevice #5: subdevice #5


Subdevice #6: subdevice #6


Subdevice #7: subdevice #7


card 3: Loopback [Loopback], device 1: Loopback PCM [Loopback PCM]


Subdevices: 8/8


Subdevice #0: subdevice #0


Subdevice #1: subdevice #1


Subdevice #2: subdevice #2


Subdevice #3: subdevice #3


Subdevice #4: subdevice #4


Subdevice #5: subdevice #5


Subdevice #6: subdevice #6


Subdevice #7: subdevice #7


card 5: Device [USB PnP Audio Device], device 0: USB Audio [USB Audio]


Subdevices: 1/1


Subdevice #0: subdevice #0



3) Check that your DAC is available as a valid playback device:
aplay -l



** List of PLAYBACK Hardware Devices **


card 0: vc4hdmi0 [vc4-hdmi-0], device 0: MAI PCM i2s-hifi-0 [MAI PCM i2s-hifi-0]


Subdevices: 1/1


Subdevice #0: subdevice #0


card 1: vc4hdmi1 [vc4-hdmi-1], device 0: MAI PCM i2s-hifi-0 [MAI PCM i2s-hifi-0]


Subdevices: 1/1


Subdevice #0: subdevice #0


card 3: Loopback [Loopback], device 0: Loopback PCM [Loopback PCM]


Subdevices: 8/8


Subdevice #0: subdevice #0


Subdevice #1: subdevice #1


Subdevice #2: subdevice #2


Subdevice #3: subdevice #3


Subdevice #4: subdevice #4


Subdevice #5: subdevice #5


Subdevice #6: subdevice #6


Subdevice #7: subdevice #7


card 3: Loopback [Loopback], device 1: Loopback PCM [Loopback PCM]


Subdevices: 8/8


Subdevice #0: subdevice #0


Subdevice #1: subdevice #1


Subdevice #2: subdevice #2


Subdevice #3: subdevice #3


Subdevice #4: subdevice #4


Subdevice #5: subdevice #5


Subdevice #6: subdevice #6


Subdevice #7: subdevice #7


card 4: sndrpihifiberry [snd_rpi_hifiberry_dac8x], device 0: HifiBerry DAC8x HiFi pcm5102a-hifi-0 [HifiBerry DAC8x HiFi pcm5102a-hifi-0]


Subdevices: 0/1


Subdevice #0: subdevice #0




4) Check that the camilladsp configuration file specifies the USB Gadget as capture device and your DAC as playback device.

-> How do I do this? Which file is this?


I don’t understand everything, but looking at the outputs of these commands, it seems like the camilladsp-setrate.service is in-anctive and also it seems like the Wiim Ultra isn’t properly configured as the playback device in camilladsp-setrate.


Any idea, how this can be fixed/configured the right way?

Any help is highly appreciated - thank you! 🙂
 
Here are the replies, I receive based on your commands:

1) Check that the camilladsp-setrate service is active:
sudo systemctl status camilladsp-setrate
The output of that command shows that the camilladsp-setrate service exits with error.

Process: 1200 ExecStartPre=sleep 0.5 (code=exited, status=217/USER)
Try removing the 'ExercStartPre' line from the unit file (.service file).

Please also post your camilladsp-setrate.service file.

Finally, please use the '--syslog' command flag, set logging level to '--loglevel=notice' and then check the logfile produced by camilladsp-setrate:
sudo journalctl | grep camilladsp-setrate
 
Last edited:
  • Thank You
Reactions: Airharder
4) Check that the camilladsp configuration file specifies the USB Gadget as capture device and your DAC as playback device.

-> How do I do this? Which file is this?
I mean the .yml file containing the configuration of camilladsp.
The "devices:" section in that file shall contain the specification of the capture device and of the playback device, something like this:
...
devices:
...
capture:
type: Alsa
device: "hw:UAC2Gadget"
...
playback:
type: Alsa
device: "hw:sndrpihifiberry"
...

I strongly recommend you to study in depth the camilladsp README.md page:
https://github.com/HEnquist/camilladsp
 
it seems like the Wiim Ultra isn’t properly configured as the playback device in camilladsp-setrate.
In camilladsp-setrate you only have to specify the capture device. If you omit that specification, the default value is ‘hw:UAC2Gadget’, which is the correct one.
The playback device must be specified in the camilladsp configuration file as shown in the example in my previous post.
 
  • Thank You
Reactions: Airharder
Process: 1200 ExecStartPre=sleep 0.5 (code=exited, status=217/USER)
UPDATE:
The exit code 217 indicates the user did not exist at the time the service tried to start.
In the .service file you must indicate the user who will launch the service. For example, if you use Raspberry Pi OS, you could edit the .service file as follows:
...
User=pi
Group=pi
...

(see camilladsp-setrate home page, point 2. in the "Installing" section)
 
  • Thank You
Reactions: Airharder
As of the systemd unit files - it's always good to make the softwares running manually in terminals first, checking their output and logs. Only after everything is configured properly and works OK it makes sense to set up the startup scripts to make everything run automatically.
 
  • Like
Reactions: mevang
Hi @TerryForsythe, looks like you were lucky and got the Wiim Ultra together with Camilla DSP on Raspi up and running properly with camilladsp-setrate - that's really amazing! I have exactly the same setup like you. My CamillaDSP works and I followed the camilladsp-setrate tutorial on github until point 7. Unfortunately then I get stuck, I don't understand how to configure and start camilladsp-setrate in order to make it work with CamillaDSP. Is there any chance you could help me to get it up and running? Did you create any special config file, that you could share with me? Unfortunately I'm new to linux, so I have to look up every single command 🙂. Your help and feedback would be greatly appreciated!

Another question: Did you also use a USB-C Y-splitter cable in order to be able to connect the Wiim to the Raspi USB-C port, while also powering it from a USB-C power supply. If I connect the Wiim Ultra directly to the USB-C Raspi port, it boots up and instantly turns off with the red status LED, as the power provided by the Wiim isn't enough. Is there any better option than using a USB-C Y-splitter cable?
I just saw your post. For installation I followed the installation instructions. At first I had a lot of issues trying to get it to work with SPDIF input. Once I got the WiiM Ultra, and on my Pi switched to USB Gadget mode and enabled loopback, it worked. I did increase the multiplier for the MAX_PAYLOAD_SIZE parameter in the setrate.h file.

I do use a USB-C Y-splitter cable, and it works well. I use this one:

https://a.co/d/6qQIX6C
 
  • Like
Reactions: Airharder
The output of that command shows that the camilladsp-setrate service exits with error.


Try removing the 'ExercStartPre' line from the unit file (.service file).

Please also post your camilladsp-setrate.service file.

Finally, please use the '--syslog' command flag, set logging level to '--loglevel=notice' and then check the logfile produced by camilladsp-setrate:
sudo journalctl | grep camilladsp-setrate
Sorry for my late reply. I was on some other things in the last days. Thanks a lot for getting back to me! I still hope to be able to make this work with the forum help 🙂. I definitely had an error in the User=xxx Group=xxx, it still showed "dietpi". Now I managed to correct that (now it shows "airharder", which is my correct user name). By now it seems like the rate adjust sometimes works sometimes not. Meaning it changes from 48 Khz to 44.1 Khz...if I then go back to the 48 Khz track it's stuck on the 44.1 Khz setting.

This is what I see now, when I open "camilladsp-setrate.service" with nano:

GNU nano 7.2 camilladsp-setrate.service
[Unit]
Description=Automatic Sample Rate Changer Daemon for CamillaDSP
After=camilladsp.service

[Service]
(ExecStartPre=sleep 0.5) -> I removed this line now!***
ExecStart=/usr/local/bin/camilladsp-setrate --loglevel=err --syslog
Restart=always
RestartSec=1
StandardOutput=journal
StandardError=journal
SyslogIdentifier=camilladsp-setrate
CPUSchedulingPolicy=fifo
CPUSchedulingPriority=10
User=airharder
Group=airharder

[Install]
WantedBy=camilladsp.service

Now going back through your initial prompt suggestions:

1) Check that the camilladsp-setrate service is active:
sudo systemctl status camilladsp-setrate


camilladsp-setrate.service - Automatic Sample Rate Changer Daemon for Camilla>
Loaded: loaded (/etc/systemd/system/camilladsp-setrate.service; enabled; p>
Active: active (running) since Thu 2024-10-17 21:26:31 CEST; 10min ago
Process: 1263 ExecStartPre=sleep 0.5 (code=exited, status=0/SUCCESS)
Main PID: 1284 (camilladsp-setr)
Tasks: 1 (limit: 9252)
CPU: 32ms
CGroup: /system.slice/camilladsp-setrate.service
└─1284 /usr/local/bin/camilladsp-setrate --loglevel=err --syslog
Oct 17 21:26:31 raspberrypi systemd[1]: Starting camilladsp-setrate.service - A>
Oct 17 21:26:31 raspberrypi systemd[1]: Started camilladsp-setrate.service - Au>

2) Check that the USB Gadget is up and running as a capture device:
arecord -l

** List of CAPTURE Hardware Devices **
card 2: UAC2Gadget [UAC2_Gadget], device 0: UAC2 PCM [UAC2 PCM]
Subdevices: 0/1
Subdevice #0: subdevice #0
card 3: Loopback [Loopback], device 0: Loopback PCM [Loopback PCM]
Subdevices: 8/8
Subdevice #0: subdevice #0
Subdevice #1: subdevice #1
Subdevice #2: subdevice #2
Subdevice #3: subdevice #3
Subdevice #4: subdevice #4
Subdevice #5: subdevice #5
Subdevice #6: subdevice #6
Subdevice #7: subdevice #7
card 3: Loopback [Loopback], device 1: Loopback PCM [Loopback PCM]
Subdevices: 8/8
Subdevice #0: subdevice #0
Subdevice #1: subdevice #1
Subdevice #2: subdevice #2
Subdevice #3: subdevice #3
Subdevice #4: subdevice #4
Subdevice #5: subdevice #5
Subdevice #6: subdevice #6
Subdevice #7: subdevice #7

3) Check that your DAC is available as a valid playback device:
aplay -l
airharder@raspberrypi
:~ $ aplay -l
aplay: invalid option -- '?'
Try `aplay --help' for more information.

--> I think something happened here, I've received a different message before

Please find two screenshots of my CamillaDSP device settings attached.

Capture device: plughw:CARD=UAC2Gadget,DEV=0
Playback device: plughw:CARD=sndrpihifiberry,DEV=0

Would be amazing if you could help me further based on these infos 🙂
 

Attachments

  • Bildschirmfoto 2024-10-17 um 21.50.49.png
    Bildschirmfoto 2024-10-17 um 21.50.49.png
    256.6 KB · Views: 48
  • Bildschirmfoto 2024-10-17 um 21.51.06.png
    Bildschirmfoto 2024-10-17 um 21.51.06.png
    243.7 KB · Views: 47
The output of that command shows that the camilladsp-setrate service exits with error.


Try removing the 'ExercStartPre' line from the unit file (.service file).

Please also post your camilladsp-setrate.service file.

Finally, please use the '--syslog' command flag, set logging level to '--loglevel=notice' and then check the logfile produced by camilladsp-setrate:
sudo journalctl | grep camilladsp-setrate
I don't know how to apply this "Finally, please use the '--syslog' command flag, set logging level to '--loglevel=notice'"

Here is the result I get from sudo journalctl | grep camilladsp-setrate

airharder@raspberrypi:~ $ sudo journalctl | grep camilladsp-setrate
Oct 01 18:30:05 raspberrypi sudo[2802]: airharder : TTY=pts/0 ; PWD=/home/airharder/camilladsp-setrate ; USER=root ; COMMAND=/usr/bin/cp ./bin/camilladsp-setrate /usr/local/bin
Oct 01 18:30:19 raspberrypi sudo[2805]: airharder : TTY=pts/0 ; PWD=/home/airharder/camilladsp-setrate ; USER=root ; COMMAND=/usr/bin/cp camilladsp-setrate.service /etc/systemd/system
Oct 01 18:30:19 raspberrypi sudo[2808]: airharder : TTY=pts/0 ; PWD=/home/airharder/camilladsp-setrate ; USER=root ; COMMAND=/usr/bin/systemctl enable camilladsp-setrate
Oct 01 18:31:48 raspberrypi sudo[2894]: airharder : TTY=pts/0 ; PWD=/home/airharder/camilladsp-setrate ; USER=root ; COMMAND=/usr/sbin/usermod -a airharder -G audio
Oct 01 18:51:33 raspberrypi systemd[1]: Starting camilladsp-setrate.service - Automatic Sample Rate Changer Daemon for CamillaDSP...
Oct 01 18:51:33 raspberrypi (sleep)[1157]: camilladsp-setrate.service: Failed to determine user credentials: No such process
Oct 01 18:51:33 raspberrypi (sleep)[1157]: camilladsp-setrate.service: Failed at step USER spawning sleep: No such process
Oct 01 18:51:33 raspberrypi systemd[1]: camilladsp-setrate.service: Control process exited, code=exited, status=217/USER
Oct 01 18:51:33 raspberrypi systemd[1]: camilladsp-setrate.service: Failed with result 'exit-code'.

I run CamillaDSP on Raspberry PI OS. Does this mean I need to change the camilladsp-setrate.service to

User=pi
Group=pi

?
 
@Airharder
I recommed you to do what @phofman suggested in post #174:
First check that camilladsp-setrate works as expected. To this end please open a terminal session and run camilladsp-setrate manually with the following command:
/usr/local/bin/camilladsp-setrate --loglevel=notice

The output of this command should indicate that the process initialization completed with success. After that the process will wait for a sample rate change.
Any changes in the sample rate and actions resulting therefrom should be notified in the output, as well as possible errors and warnings.

Once you got a fully working camilladsp-setrate process, come back to this thread and together we will fix possible issues with services.

IMPORTANT NOTE:
If you do not specify the capture device on the command line, it defaults to "hw:UAC2Gadget". If you do want to use the "plughw" device type, you must add the device specification on the command line as follows:
/usr/local/bin/camilladsp-setrate --loglevel=notice --device=plughw:UAC2Gadget
 
  • Thank You
Reactions: Airharder
.if I then go back to the 48 Khz track it's stuck on the 44.1 Khz setting.
If you have not already done so, please enable the ‘Rate adjust’ parameter, otherwise you may experience a buffer underrun (refer to camilladsp homepage for further information).
You can do this from the camillagui web interface by setting ‘enable_rate_adjust’ to ‘yes’ and clicking on 'Apply to DSP'. Or, even better, enter the following line in the ‘devices’ section of the camilladsp configuration file
enable_rate_adjust: true
 
  • Thank You
Reactions: Airharder