• Welcome to ASR. There are many reviews of audio hardware and expert members to help answer your questions. Click here to have your audio equipment measured for free!

RPi + CamillaDSP Tutorial

IMO CDSP chunksize is fixed, as configured.

IIUC the overall latency of alsa-device CDSP (under its control) is delay in the capture device (equal to chunk time) + time of first chunk spent in resampling& processing + playback target level time.

Of course playback devices do not have to start processing samples at the moment their alsa driver threshold is reached (set to zero by CDSP, i.e. the device may start consuming samples from the playback buffer right away the first chunk is copied to the playback buffer). Some do, some would wait for some more data to start, depending on their internal implementation. E.g. a USB-audio driver will wait until full USB packet of data gets collected before sending the packet over USB to the device. Packet size is controlled by the device, hence every device can have this different.

As @mdsimon2 notes at xruns this timing is ruined. But I believe this issue could be solved (with some limitations) if a feature designed to keep latency fixed were implemented and enabled in CDSP as each chunk carries its capture time and chunks can be dropped at the playback side to get back to the required latency.
If it’s possible to design a feature to fix latency, it’s then pretty much equivalent to a SHARC chip DSP except maybe larger latency?
 
I have generated .wav files in REW for FIR convolution filtering following this tutorial:


The steps are as follows:

1. Align left and right impulse responses at 0.
2. Align left and right SPL at 500 Hz with a 3 octave span.
3. Calculate level of the target curve (Harman curve) from an average of the left and right curves.
4. Divide frequency response traces by the target curve (A/B) to generate A over B traces.
5. Invert the A over B traces (1/A) to generate inverted traces.
6. Generate minimum phase versions of inverted traces.
7. Export the minimum phase versions as .wav files.

The .wav files are working, but the group delay looks terrible, and when the .wav files are active music sounds a little tinny:

KEF Conv File Group Delay.png


Does anybody know what is causing the group delay of the .wav files to be like this? I have tried generating the .wav files with 64k taps and with 256k taps, but have the same issue either way.

Any suggestions to improve the group delay?
 
Last edited:
If I run the command with CamillaDSP running, the command won't run. The output is: 'arecord: main:831: audio open error: Device or resource busy'
If the device is being used by camillaDSP, it cannot be used by arecord at the same time.
If I stop CamillaDSP then run the command, the output is: 'Recording WAVE '-' : Signed 32 bit Little Endian, Rate 44100 Hz, Stereo'
IMO there is more in the output, at least the hw params details requested by the --dump-hw-params parameter - that's the dump we are interested in.
When I then change the sample rate output by my WiiM to the MCHSTREAMER nothing is output in the terminal - the command appears to be still running.
That would suggest condition 1 is not satisfied - the device does not break the stream at samplerate change. You can easily check by measuring the output bitrate with pv:

arecord -D hw:YOUR_MCHSTREAMER_CARD -c 2 -r INCOMING_RATE -f INCOMING_FORMAT (e.g. S16_LE) --dump-hw-params | pv > /dev/null

The stream bitrate reported by pv should change when the SPDIF stream rate changes.

With CamillaDSP stopped, I'm not sure if there is anything else happening since I can't hear the music playing.
Right, linux audio has a number of diagnostics tools apart of just listening.
 
If it’s possible to design a feature to fix latency, it’s then pretty much equivalent to a SHARC chip DSP except maybe larger latency?
Basically yes, with incomparably more options (and larger latency).
 
Does anybody know what is causing the group delay of the .wav files to be like this? I have tried generating the .wav files with 64k taps and with 256k taps, but have the same issue either way.

Any suggestions to improve the group delay?
I would suggest to start a new thread on your REW issues. Alternatively the home forum of REW https://www.avnirvana.com/forums/official-rew-room-eq-wizard-support-forum.10/ is your best bet, Serkan (the author of that great video) is being active there.
 
sorry, I looked up and down and can't find that first post that you're referring to. Guess I don't know enough to know what to look for :). Would be nice, if you could send the corresponding link or the post number, etc.
The first several posts of this thread link Michael's resourceful tutorials.
 
Do you mean the sawtooth shape at higher frequencies? That's most likely a plot artifact. But please include the phase and magnitude curves as well.
Gain shown in CamillaDSP for .wav file:
Gain.png


Phase shown in CamillaDSP for .wav file:
Phase.png


SPL and phase shown in REW for minimum phase trace used to export to .wav file:
REW SPL Gain and Phase.jpg
 
Ok, this is a limitation in how filter steps are plotted. This plots the combined result for all filters in the step. Instead try plotting the individual filter, in the Filters tab. Then it uses some more tricks to unwrap the phase. Can you show that one? Then also include the impulse response trace.
 
Ok, this is a limitation in how filter steps are plotted. This plots the combined result for all filters in the step. Instead try plotting the individual filter, in the Filters tab. Then it uses some more tricks to unwrap the phase. Can you show that one? Then also include the impulse response trace.
That was the issue. Thank you, Henrik!

Here is what the group delay shows from the Filters tab:

Group Delay 2.png




The gain is pretty much the same as REW.

The phase is a little different than that showing in REW, though, most predominantly above 10 kHz. Below 10 kHz it follows the same general trend. Could it be due to the .wav file export process?

Phase 2.png
 
IMO there is more in the output, at least the hw params details requested by the --dump-hw-params parameter - that's the dump we are interested in.
My understanding is that when output parameters are are directed to /dev/null they are discarded, and thus nothing will show up in /dev/null. My /dev/null file remains empty, as I think it should.

I also tried directing the output to a test file. There is output, but it is not text, and thus is not human unreadable.

The stream bitrate reported by pv should change when the SPDIF stream rate changes.
The stream bitrate reported by pv did not change when I changed the sample rate in my WiiM. Thus, I concur that condition 1 is not satisfied.

Thank you for your suggestions!
 
The phase is a little different than that showing in REW, though, most predominantly above 10 kHz. Below 10 kHz it follows the same general trend. Could it be due to the .wav file export process?
The only difference is that the phase plots bend a little differently at the very top. This means that the two plots use a slightly different value for time zero (that they use to calculate the relative phase). The difference looks to be about half a sample. Nothing to care about, the two plots are the same in practice.
 
My understanding is that when output parameters are are directed to /dev/null they are discarded, and thus nothing will show up in /dev/null.
No, stdout with sample stream is redirected to /dev/null, the info texts are printed to stderr, i.e. will show up in the terminal. I do not think the terminal output was empty, or you called the command in a wrong way:


Code:
arecord --dump-hw-params > /dev/null
Recording WAVE 'stdin' : Signed 16 bit Little Endian, Rate 8000 Hz, Mono
HW Params of device "default":
--------------------
ACCESS:  RW_INTERLEAVED
FORMAT:  U8 S16_LE S16_BE S24_LE S24_BE S32_LE S32_BE FLOAT_LE FLOAT_BE MU_LAW A_LAW S24_3LE S24_3BE
SUBFORMAT:  STD
SAMPLE_BITS: [8 32]
FRAME_BITS: [8 1024]
CHANNELS: [1 32]
RATE: [1 384000]
PERIOD_TIME: (2 4294967295)
PERIOD_SIZE: [1 1398102)
PERIOD_BYTES: [128 1398102)
PERIODS: [3 1024]
BUFFER_TIME: (7 4294967295]
BUFFER_SIZE: [3 4194304]
BUFFER_BYTES: [384 4194304]
TICK_TIME: ALL
--------------------

My /dev/null file remains empty, as I think it should.
That's the purpose of the /dev/null device, e.g. https://www.digitalocean.com/community/tutorials/dev-null-in-linux

The stream bitrate reported by pv did not change when I changed the sample rate in my WiiM. Thus, I concur that condition 1 is not satisfied.
Think about it - if the SPDIF stream has a different samplerate, it's bitrate must change. Therefore the captured bitrate should also change, even if the change did not cause closing the stream. How is it possible the bitrate did not change, where do the missing/redundant data come from? Does your SPDIF transmitter really change the SPDIF stream rate, or does it perhaps keep constant rate and resample the track instead?
 
Therefore the captured bitrate should also change, even if the change did not cause closing the stream. How is it possible the bitrate did not change, where do the missing/redundant data come from?
It would be interesting to record to a file and look at the result. The result will be a raw (headerless) audio file. An audio editor like Audacity can import this. My guess is that it records garbage after the rate changes.
 
The result will be a raw (headerless) audio file.
The arecord output format can be specified with e.g. -t wav.
My guess is that it records garbage after the rate changes.
Typically the USB capture devices fill USB packets with whatever samples land in their incoming FIFO - FIFO input clocked by the recovered SPDIF clock, FIFO output by the USB bus clock. That's the async stream. The bitrate would be up to max packetsize reported at enumeration (but that one should be maximum for all reported samplerates, i.e. data at other valid samplerates should fit). All this can be quite easily checked by wireshark.

A simple way to exclude the theoretically potential max packet size issue is going down with the samplerate check - if packet size is large enough for 48kHz, it will be for 44.kHz too. I do not see where the extra data would come from.

I have played with externally-clocked I2S which is similar to SPDIF and the bitrate at arecord output does change. Unless of course something is resampling along the chain to a fixed rate.
 
@mdsimon2
nice meeting you and happy to hear that you're the guru here for these things . Which way would you recommend to get at least 3x I2S out from the Raspi5? I would then use 3x of Wm8805 i2s to coax spdif boards in order to get the coax SPDIF outs in order to drive my 6 channel DIY DAC. I want the Raspi5/CamillaDSP setup to offer SPDIF outs, in order to stay DAC agnostic.
Also which way would you recommend to get Tidal Connect up and running - any software solution, or stick to the Wiim Pro+ SPDIF out?

Instructions for multichannel I2S output on a RPi5 can be found here -> https://www.audiosciencereview.com/...ole-lot-easier-and-cheaper.48233/post-1861036. However, there is no need to compile the kernel (steps 1-5), simply install the latest version of Raspberry Pi OS Lite and follow the instructions below and then follow steps 6 and beyond.

1) Create a file called 8chi2s.dts.

Code:
nano 8chi2s.dts

2) Paste the following text in 8chi2s.dts.

Code:
//Device tree overlay for 8ch RP1
/dts-v1/;
/plugin/;

/ {
    fragment@0 {
        target = <&rp1_i2s0_18_21>;
        __overlay__ {
            pins = "gpio18", "gpio19", "gpio20", "gpio22", "gpio24", "gpio26", "gpio21", "gpio23", "gpio25",  "gpio27";
        };
    };

    fragment@1 {
        target = <&rp1_i2s1_18_21>;
        __overlay__ {
            pins = "gpio18", "gpio19", "gpio20", "gpio22", "gpio24", "gpio26", "gpio21", "gpio23", "gpio25",  "gpio27";
        };
    };
};

3) Compile 8chi2s.dts.

Code:
dtc -@ -H epapr -O dtb -o 8chi2s.dtbo -Wno-unit_address_vs_reg 8chi2s.dts

4) Copy compiled 8chi2s.dtbo to /boot/firmware/overlays.

Code:
sudo cp 8chi2s.dtbo /boot/firmware/overlays

One thing to watch out for with the WM8805 boards is that in my experience they require MCLK to function and the RPi does not provide this by default. @phofman has mentioned it should be possible to have MCLK output on one of the GPIO pins, but I haven't done it personally.

Another thing to watch out for is you will need to split MCLK, BLCK and LRCLK. Splitting MCLK is particularly tricky as it is usually 256 x Fs (so for 96 kHz this is 24.576 MHz), BCLK is also rather high frequency at 64 x Fs. The proper way to do this is with a clock buffer, but you may get away with soldering some very short splitter wiring. It may also be possible to have other GPIO pins output MCLK, BLCK and LRCLK but I am not sure.

I am not familiar with Tidal so I am of no help there.

If I was in your shoes, I would consider a miniDSP U-DIO8. It offers 8 channel digital input / output (either AES or SPDIF). It also has a ASRC which means you can have a variety of inputs with different sample rates and run CamillaDSP at a constant sample rate. You can use just as a USB to 8 channel digital output device or use it as an input and output device. It would eliminate all the complications with I2S and should just work.

Michael
 
Last edited:
arecord --dump-hw-params > /dev/null
The command 'arecord --dump-hw-params -f S32_LE > /dev/null' outputs the following:

Recording WAVE 'stdin' : Signed 32 bit Little Endian, Rate 8000 Hz, Mono
HW Params of device "default":
--------------------
ACCESS: MMAP_INTERLEAVED MMAP_NONINTERLEAVED MMAP_COMPLEX RW_INTERLEAVED RW_NONINTERLEAVED
FORMAT: S8 U8 S16_LE S16_BE U16_LE U16_BE S24_LE S24_BE U24_LE U24_BE S32_LE S32_BE U32_LE U32_BE FLOAT_LE FLOAT_BE FLOAT64_LE FLOAT64_BE MU_LAW A_LAW IMA_ADPCM S20_LE S20_BE U20_LE U20_BE S24_3LE S24_3BE U24_3LE U24_3BE S20_3LE S20_3BE U20_3LE U20_3BE S18_3LE S18_3BE U18_3LE U18_3BE
SUBFORMAT: STD
SAMPLE_BITS: [4 64]
FRAME_BITS: [4 640000]
CHANNELS: [1 10000]
RATE: [4000 4294967295)
PERIOD_TIME: (21333 21334)
PERIOD_SIZE: (85 91628833)
PERIOD_BYTES: (42 4294967295)
PERIODS: (0 17247242)
BUFFER_TIME: [1 4294967295]
BUFFER_SIZE: [170 1466015503]
BUFFER_BYTES: [85 4294967295]
TICK_TIME: ALL
--------------------

So, that seams to be working fine.


Think about it - if the SPDIF stream has a different samplerate, it's bitrate must change. Therefore the captured bitrate should also change, even if the change did not cause closing the stream. How is it possible the bitrate did not change, where do the missing/redundant data come from?

When I enter the following command:

arecord -D hw:TosLink -c 2 -r 44100 -f S32_LE - dump-hw-params | pv > /dev/null

The terminal outputs the following:

Recording WAVE '-' : Signed 32 bit Little Endian, Rate 44100 Hz, Stereo
13.1MiB 0:00:39 [ 344KiB/s] [

The total size and time parameters constantly increase, but the 344KiB/s rate stays at that 344KiB/s value, even when I change the WiiM's SPDIF Output Resolution from 44.1 kHz to 96 kHz or 192 kHz. My guess is that ALSA is not detecting the change, but I am not familiar with how ALSA handles such things.


Does your SPDIF transmitter really change the SPDIF stream rate, or does it perhaps keep constant rate and resample the track instead?

If I have CamillaDSP running, and I change WiiM's SPDIF Output Resolution, WiiM definitely is changing the stream rate - the music becomes garbled until I set the stream rate back to the original stream rate that was set when the CamillaDSP service started.

If I set WiiM SPDIF output to 192 kHz, it works fine so long as Tidal is streaming the song at that rate. If a next song comes on that is recorded at a lower resolution, then Tidal appears to be streaming it at a lower rate, and the song comes out garbled. If I set the WiiM to 44.1 kHz, it will automatically resample anything streamed higher than that down to 44.1 kHz.

Anyway, don't stress about it. Like I said, 24-bit, 44.1 kHz is working fine, and I can bypass the MCHSTREAMER input if I upgrade to the WiiM Ultra down the road.
 
When I enter the following command:

arecord -D hw:TosLink -c 2 -r 44100 -f S32_LE - dump-hw-params | pv > /dev/null

The terminal outputs the following:

Recording WAVE '-' : Signed 32 bit Little Endian, Rate 44100 Hz, Stereo
13.1MiB 0:00:39 [ 344KiB/s] [
If no hw params are listed, the --dump-hw-params parameter is not entered correctly. It would show important information about that Toslink card.

The total size and time parameters constantly increase, but the 344KiB/s rate stays at that 344KiB/s value, even when I change the WiiM's SPDIF Output Resolution from 44.1 kHz to 96 kHz or 192 kHz. My guess is that ALSA is not detecting the change, but I am not familiar with how ALSA handles such things.
Alsa just receives data sent by the USB device, for it the samplerate is just a number. Whatever gets received is passed to arecord. Apparently the device does not send anything faster/slower.
If I set WiiM SPDIF output to 192 kHz, it works fine so long as Tidal is streaming the song at that rate. If a next song comes on that is recorded at a lower resolution, then Tidal appears to be streaming it at a lower rate, and the song comes out garbled. If I set the WiiM to 44.1 kHz, it will automatically resample anything streamed higher than that down to 44.1 kHz.
If WiiM resamples automatically to a fixed frequency, then no need for tracking the incoming SPDIF rate, IIUC. That's what I have been saying - if the bitrate at arecord is constant, something must be resampling in the chain upstream.
 
If no hw params are listed, the --dump-hw-params parameter is not entered correctly.

EDIT. I found the issue. I had '- dump-hw-params'. It should be '--dump-hw-params'.

It now outputs the hw parameters. The rate still does not change when changing the output resolution in the WiiM.
 
Last edited:
Instructions for multichannel I2S output on a RPi5 can be found here -> https://www.audiosciencereview.com/...ole-lot-easier-and-cheaper.48233/post-1861036. However, there is no need to compile the kernel (steps 1-5), simply install the latest version of Raspberry Pi OS Lite and follow the instructions below and then follow steps 6 and beyond.

1) Create a file called 8chi2s.dts.

Code:
nano 8chi2s.dts

2) Paste the following text in 8chi2s.dts.

Code:
//Device tree overlay for 8ch RP1
/dts-v1/;
/plugin/;

/ {
    fragment@0 {
        target = <&rp1_i2s0_18_21>;
        __overlay__ {
            pins = "gpio18", "gpio19", "gpio20", "gpio22", "gpio24", "gpio26", "gpio21", "gpio23", "gpio25",  "gpio27";
        };
    };

    fragment@1 {
        target = <&rp1_i2s1_18_21>;
        __overlay__ {
            pins = "gpio18", "gpio19", "gpio20", "gpio22", "gpio24", "gpio26", "gpio21", "gpio23", "gpio25",  "gpio27";
        };
    };
};

3) Compile 8chi2s.dts.

Code:
dtc -@ -H epapr -O dtb -o 8chi2s.dtbo -Wno-unit_address_vs_reg 8chi2s.dts

4) Copy compiled 8chi2s.dtbo to /boot/firmware/overlays.

Code:
sudo cp 8chi2s.dtbo /boot/firmware/overlays

One thing to watch out for with the WM8805 boards is that in my experience they require MCLK to function and the RPi does not provide this by default. @phofman has mentioned it should be possible to have MCLK output on one of the GPIO pins, but I haven't done it personally.

Another thing to watch out for is you will need to split MCLK, BLCK and LRCLK. Splitting MCLK is particularly tricky as it is usually 256 x Fs (so for 96 kHz this is 24.576 MHz), BCLK is also rather high frequency at 64 x Fs. The proper way to do this is with a clock buffer, but you may get away with soldering some very short splitter wiring. It may also be possible to have other GPIO pins output MCLK, BLCK and LRCLK but I am not sure.

I am not familiar with Tidal so I am of no help there.

If I was in your shoes, I would consider a miniDSP U-DIO8. It offers 8 channel digital input / output (either AES or SPDIF). It also has a ASRC which means you can have a variety of inputs with different sample rates and run CamillaDSP at a constant sample rate. You can use just as a USB to 8 channel digital output device or use it as an input and output device. It would eliminate all the complications with I2S and should just work.

Michael
@mdsimon2 thanks a lot for your quick reply! If I would know and understand how to split MCLK, BLCK and LRCLK, I would really like the simple and cost effective way of using the generic Raspi5 I2S ins/outs. Is there any alternative to the WM8805 boards, that don't require MCLK to function?

Or @phofman, do you still see an easy way to for getting MCLK output on one of the GPIO pins and thus allow to use WM8805 I2S to SPDIF boards?

Thanks for the idea with miniDSP U-DIO8. I knew about it and have also considered it before. Unfortunately I find it too pricy and too bulky. If I would manage to get at least the SPDIF outs to work, I could even consider a new Wiim Ultra that apparently has USB output.

As an alternative to miniDSP U-DIO8, a MiniDSP nanoDIGI 2x8 should also work, right? It's just difficult to get one of these...I'll keep on searching, as this seems quite a nice package with regards to price, performance and size.

Or I go back to my initial idea to use DIYIHNK XMOS MULTICHANNEL for I2S outs. To my understanding this board, provides MCLK.
 
Last edited:
Back
Top Bottom