• WANTED: Happy members who like to discuss audio and other topics related to our interest. Desire to learn and share knowledge of science required. 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!

RPi4 + CamillaDSP Tutorial

OP
M

mdsimon2

Major Contributor
Forum Donor
Joined
Oct 20, 2020
Messages
2,515
Likes
3,378
Location
Detroit, MI
Hello, would the focusrite 4i4 be a good alternative to the motu m4? I would get the m4 but the volume knob doesn't control 2 of the outputs, which is unfortunate. I'm looking at the specs for the 4i4 and it says the line inputs 3 and 4 are fixed gain. Does that mean it is similar to the Motu m4?

4i4 manual says that the knob only controls outputs 1-2.

However, please note that only LINE OUTPUTS 1 and 2 are affected in level by the the large front panel MONITOR volume control. Also please note that Outputs 3 and 4 are also used to feed the front panel headphone output.

If you do not use the knob you can use CamillaDSP to do volume control on all outputs, this is what I do on my Ultralite Mk5 setup and it works great.

If you want a knob the Focusrite 18i20 has a knob that can control all analog outputs and is not terribly more expensive than the M4, although the analog quality is quite a bit lower.

Michael
 

artmis

New Member
Joined
Jul 13, 2022
Messages
4
Likes
1
Ah too bad, thanks for looking into it. The journey continues for a good 4 channel dac. I really wanted to use the the volume knob. Doing it through camilla would actually be fine, but I would prefer more convenience.

Also thank you for creating this tutorial, it's ignited a desire to use room correction from audiolense.
 

phofman

Addicted to Fun and Learning
Joined
Apr 13, 2021
Messages
503
Likes
328
At first I tried to do 96 kHz, 512 chunk size and no resampling however without resampling I would often get a capture error saying I was providing an invalid argument. It always worked with BalancedAsync resampling enabled.

That's interesting, do you have any details of the error message, in order to locate it in CDSP sources? That would suggest MOTU uses different clock for capture and playback which is highly unlikely. Does MOTU run with proper USB async mode? E.g. if implicit feedback was ignored by the driver, duplex would not run synchronously.
I had anticipated that the relative delay might shift during a given session as I would see buffer levels changing but in practice no delay shifting was observed on the output which was very nice.
When both sides run continuously without breaks/xruns, they keep the latency constant (apart of slowly growing relative shift caused by potentially different clocks, if the case). The output buffer level (i.e. what CDSP reports) is changing because the buffer receives data in chunks and consumes them continuously by the soundcard. Also the relative time of reading the buffer level (at AudioMsg arrival from the Processing thread) to the time of filling the buffer (period-elapsed when the chunk is written to the buffer - the rise of the saw) with the chunk varies, further contributing to the variance. I have a patch which uses a "virtual" buffer level adjusted for relative difference of time chunks spend from their creation on capture side to their delivery to the playback thread (AudioMsg arrival). I have not had time to test the patch yet but I hope it will smooth the buffer level minus target level diffs a bit.

index.php
 
OP
M

mdsimon2

Major Contributor
Forum Donor
Joined
Oct 20, 2020
Messages
2,515
Likes
3,378
Location
Detroit, MI
That's interesting, do you have any details of the error message, in order to locate it in CDSP sources? That would suggest MOTU uses different clock for capture and playback which is highly unlikely. Does MOTU run with proper USB async mode? E.g. if implicit feedback was ignored by the driver, duplex would not run synchronously.

Here is the log without resampling.

Code:
2022-07-21 13:15:10.844586 INFO  [src/bin.rs:711] CamillaDSP version 1.0.0
2022-07-21 13:15:10.844723 INFO  [src/bin.rs:712] Running on linux, aarch64
2022-07-21 13:15:10.844867 DEBUG [src/bin.rs:754] Read config file Some("/home/michael6/camilladsp/active_config.yml")
2022-07-21 13:15:10.845899 DEBUG [src/bin.rs:773] Config is valid
2022-07-21 13:15:10.846043 DEBUG [src/socketserver.rs:260] Start websocket server on 127.0.0.1:1234
2022-07-21 13:15:10.846350 DEBUG [src/bin.rs:857] Wait for config
2022-07-21 13:15:10.846452 DEBUG [src/bin.rs:890] Config ready
2022-07-21 13:15:10.846885 DEBUG [src/filters.rs:450] Build new pipeline
2022-07-21 13:15:10.846892 DEBUG [src/bin.rs:213] Using channels [true, true, false, false]
2022-07-21 13:15:10.847040 DEBUG [src/alsadevice.rs:903] Buffer frames 1024
2022-07-21 13:15:10.847044 DEBUG [src/filters.rs:355] Build from config
2022-07-21 13:15:10.847153 DEBUG [src/filters.rs:355] Build from config
2022-07-21 13:15:10.847264 DEBUG [src/filters.rs:355] Build from config
2022-07-21 13:15:10.847361 DEBUG [src/filters.rs:355] Build from config
2022-07-21 13:15:10.847472 DEBUG [src/processing.rs:19] build filters, waiting to start processing loop
2022-07-21 13:15:10.850052 DEBUG [src/alsadevice.rs:406] Playback: supported channels, min: 4, max: 4, list: [4]
2022-07-21 13:15:10.850052 DEBUG [src/alsadevice.rs:406] Capture: supported channels, min: 4, max: 4, list: [4]
2022-07-21 13:15:10.850175 DEBUG [src/alsadevice.rs:407] Capture: setting channels to 4
2022-07-21 13:15:10.850179 DEBUG [src/alsadevice.rs:407] Playback: setting channels to 4
2022-07-21 13:15:10.850391 DEBUG [src/alsadevice.rs:411] Capture: supported samplerates: Discrete([44100, 48000, 88200, 96000, 176400, 192000])
2022-07-21 13:15:10.850394 DEBUG [src/alsadevice.rs:411] Playback: supported samplerates: Discrete([44100, 48000, 88200, 96000, 176400, 192000])
2022-07-21 13:15:10.850493 DEBUG [src/alsadevice.rs:412] Capture: setting rate to 96000
2022-07-21 13:15:10.850508 DEBUG [src/alsadevice.rs:412] Playback: setting rate to 96000
2022-07-21 13:15:10.850614 DEBUG [src/alsadevice.rs:416] Capture: supported sample formats: [S32LE]
2022-07-21 13:15:10.850620 DEBUG [src/alsadevice.rs:416] Playback: supported sample formats: [S32LE]
2022-07-21 13:15:10.850715 DEBUG [src/alsadevice.rs:417] Capture: setting format to S32LE
2022-07-21 13:15:10.850722 DEBUG [src/alsadevice.rs:417] Playback: setting format to S32LE
2022-07-21 13:15:10.858578 ERROR [src/bin.rs:362] Capture error: ALSA function 'snd_pcm_hw_params' failed with error 'EINVAL: Invalid argument'
2022-07-21 13:15:10.858608 DEBUG [src/alsadevice.rs:448] Opening audio device "hw:M4" with parameters: HwParams { channels: Ok(4), rate: "Ok(96000) Hz", format: Ok(S32LE), access: Ok(RWInterleaved), period_size: "Ok(128) frames", buffer_size: "Ok(1024) frames" }, SwParams(avail_min: Ok(512) frames, start_threshold: Ok(384) frames, stop_threshold: Ok(1024) frames)
2022-07-21 13:15:10.858734 DEBUG [src/bin.rs:364] Error while starting, release barrier
2022-07-21 13:15:10.858738 DEBUG [src/alsadevice.rs:453] Audio device "hw:M4" successfully opened
2022-07-21 13:15:10.858883 DEBUG [src/bin.rs:367] Wait for playback thread to exit..
2022-07-21 13:15:10.858892 DEBUG [src/alsadevice.rs:850] Starting playback loop
2022-07-21 13:15:10.858897 DEBUG [src/processing.rs:21] Processing loop starts now!
2022-07-21 13:15:10.858999 ERROR [src/processing.rs:50] Message channel error: receiving on a closed channel
2022-07-21 13:15:10.869721 DEBUG [src/bin.rs:915] Restarting with new config
2022-07-21 13:15:10.869836 DEBUG [src/bin.rs:857] Wait for config
2022-07-21 13:15:10.869945 DEBUG [src/bin.rs:860] No config and not in wait mode, exiting!

Here is the log with resampling.

Code:
2022-07-21 13:20:55.577483 INFO  [src/bin.rs:711] CamillaDSP version 1.0.0
2022-07-21 13:20:55.577631 INFO  [src/bin.rs:712] Running on linux, aarch64
2022-07-21 13:20:55.577788 DEBUG [src/bin.rs:754] Read config file Some("/home/michael6/camilladsp/active_config.yml")
2022-07-21 13:20:55.578984 DEBUG [src/bin.rs:773] Config is valid
2022-07-21 13:20:55.579151 DEBUG [src/socketserver.rs:260] Start websocket server on 127.0.0.1:1234
2022-07-21 13:20:55.579475 DEBUG [src/bin.rs:857] Wait for config
2022-07-21 13:20:55.579594 DEBUG [src/bin.rs:890] Config ready
2022-07-21 13:20:55.580091 DEBUG [src/filters.rs:450] Build new pipeline
2022-07-21 13:20:55.580086 DEBUG [src/bin.rs:213] Using channels [true, true, false, false]
2022-07-21 13:20:55.580213 WARN  [src/audiodevice.rs:451] Needless 1:1 sample rate conversion active. Not needed since enable_rate_adjust=False
2022-07-21 13:20:55.580250 DEBUG [src/filters.rs:355] Build from config
2022-07-21 13:20:55.580349 DEBUG [src/alsadevice.rs:903] Buffer frames 1024
2022-07-21 13:20:55.580352 DEBUG [src/filters.rs:355] Build from config
2022-07-21 13:20:55.580493 DEBUG [src/filters.rs:355] Build from config
2022-07-21 13:20:55.580606 DEBUG [src/filters.rs:355] Build from config
2022-07-21 13:20:55.580717 DEBUG [src/processing.rs:19] build filters, waiting to start processing loop
2022-07-21 13:20:55.580866 DEBUG [src/alsadevice.rs:918] Creating resampler
2022-07-21 13:20:55.580991 DEBUG [src/audiodevice.rs:418] Creating asynchronous resampler with parameters: InterpolationParameters { sinc_len: 128, f_cutoff: 0.92591465, oversampling_factor: 1024, interpolation: Linear, window: Blackman2 }
2022-07-21 13:20:55.583472 DEBUG [src/alsadevice.rs:406] Playback: supported channels, min: 4, max: 4, list: [4]
2022-07-21 13:20:55.583610 DEBUG [src/alsadevice.rs:407] Playback: setting channels to 4
2022-07-21 13:20:55.583835 DEBUG [src/alsadevice.rs:411] Playback: supported samplerates: Discrete([44100, 48000, 88200, 96000, 176400, 192000])
2022-07-21 13:20:55.583957 DEBUG [src/alsadevice.rs:412] Playback: setting rate to 96000
2022-07-21 13:20:55.584088 DEBUG [src/alsadevice.rs:416] Playback: supported sample formats: [S32LE]
2022-07-21 13:20:55.584189 DEBUG [src/alsadevice.rs:417] Playback: setting format to S32LE
2022-07-21 13:20:55.587161 DEBUG [src/alsadevice.rs:448] Opening audio device "hw:M4" with parameters: HwParams { channels: Ok(4), rate: "Ok(96000) Hz", format: Ok(S32LE), access: Ok(RWInterleaved), period_size: "Ok(128) frames", buffer_size: "Ok(1024) frames" }, SwParams(avail_min: Ok(512) frames, start_threshold: Ok(384) frames, stop_threshold: Ok(1024) frames)
2022-07-21 13:20:55.587425 DEBUG [src/alsadevice.rs:453] Audio device "hw:M4" successfully opened
2022-07-21 13:20:55.587590 DEBUG [src/bin.rs:323] Playback thread ready to start
2022-07-21 13:20:55.621233 DEBUG [src/alsadevice.rs:406] Capture: supported channels, min: 4, max: 4, list: [4]
2022-07-21 13:20:55.621398 DEBUG [src/alsadevice.rs:407] Capture: setting channels to 4
2022-07-21 13:20:55.621508 DEBUG [src/alsadevice.rs:411] Capture: supported samplerates: Discrete([96000])
2022-07-21 13:20:55.621610 DEBUG [src/alsadevice.rs:412] Capture: setting rate to 96000
2022-07-21 13:20:55.621721 DEBUG [src/alsadevice.rs:416] Capture: supported sample formats: [S32LE]
2022-07-21 13:20:55.621820 DEBUG [src/alsadevice.rs:417] Capture: setting format to S32LE
2022-07-21 13:20:55.622107 DEBUG [src/alsadevice.rs:448] Opening audio device "hw:M4" with parameters: HwParams { channels: Ok(4), rate: "Ok(96000) Hz", format: Ok(S32LE), access: Ok(RWInterleaved), period_size: "Ok(128) frames", buffer_size: "Ok(1024) frames" }, SwParams(avail_min: Ok(512) frames, start_threshold: Ok(0) frames, stop_threshold: Ok(1024) frames)
2022-07-21 13:20:55.622251 DEBUG [src/alsadevice.rs:453] Audio device "hw:M4" successfully opened
2022-07-21 13:20:55.622416 DEBUG [src/bin.rs:333] Capture thread ready to start
2022-07-21 13:20:55.622526 DEBUG [src/bin.rs:336] Both capture and playback ready, release barrier
2022-07-21 13:20:55.622646 DEBUG [src/bin.rs:338] Supervisor loop starts now!
2022-07-21 13:20:55.622672 DEBUG [src/alsadevice.rs:944] Starting captureloop
2022-07-21 13:20:55.622689 DEBUG [src/processing.rs:21] Processing loop starts now!
2022-07-21 13:20:55.622822 DEBUG [src/alsadevice.rs:850] Starting playback loop
2022-07-21 13:20:55.623062 DEBUG [src/alsadevice.rs:244] Starting capture from state: SND_PCM_STATE_PREPARED, Ready to start
2022-07-21 13:20:55.630550 INFO  [src/alsadevice.rs:156] Starting playback from Prepared state

And lsusb -v dump just for fun.

Code:
Bus 001 Device 006: ID 07fd:0008 Mark of the Unicorn M Series
Couldn't open device, some information will be missing
Device Descriptor:
  bLength                18
  bDescriptorType         1
  bcdUSB               2.00
  bDeviceClass          239 Miscellaneous Device
  bDeviceSubClass         2 
  bDeviceProtocol         1 Interface Association
  bMaxPacketSize0        64
  idVendor           0x07fd Mark of the Unicorn
  idProduct          0x0008 M Series
  bcdDevice            1.02
  iManufacturer           1 MOTU
  iProduct                3 M4
  iSerial                 2 M40000058933
  bNumConfigurations      1
  Configuration Descriptor:
    bLength                 9
    bDescriptorType         2
    wTotalLength       0x0147
    bNumInterfaces          6
    bConfigurationValue     1
    iConfiguration          0 
    bmAttributes         0x80
      (Bus Powered)
    MaxPower              500mA
    Interface Association:
      bLength                 8
      bDescriptorType        11
      bFirstInterface         0
      bInterfaceCount         3
      bFunctionClass          1 Audio
      bFunctionSubClass       0 
      bFunctionProtocol      32 
      iFunction               0 
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        0
      bAlternateSetting       0
      bNumEndpoints           1
      bInterfaceClass         1 Audio
      bInterfaceSubClass      1 Control Device
      bInterfaceProtocol     32 
      iInterface              3 
      AudioControl Interface Descriptor:
        bLength                 9
        bDescriptorType        36
        bDescriptorSubtype      1 (HEADER)
        bcdADC               2.00
        bCategory               8
        wTotalLength       0x0053
        bmControls           0x00
      AudioControl Interface Descriptor:
        bLength                 8
        bDescriptorType        36
        bDescriptorSubtype     10 (CLOCK_SOURCE)
        bClockID                1
        bmAttributes            3 Internal programmable clock 
        bmControls           0x07
          Clock Frequency Control (read/write)
          Clock Validity Control (read-only)
        bAssocTerminal          0
        iClockSource            9 
      AudioControl Interface Descriptor:
        bLength                 8
        bDescriptorType        36
        bDescriptorSubtype     11 (CLOCK_SELECTOR)
        bClockID                4
        bNrInPins               1
        baCSourceID(0)          1
        bmControls           0x03
          Clock Selector Control (read/write)
        iClockSelector          8 
      AudioControl Interface Descriptor:
        bLength                17
        bDescriptorType        36
        bDescriptorSubtype      2 (INPUT_TERMINAL)
        bTerminalID            42
        wTerminalType      0x0101 USB Streaming
        bAssocTerminal          0
        bCSourceID              4
        bNrChannels             4
        bmChannelConfig    0x00000000
        iChannelNames          12 
        bmControls         0x0000
        iTerminal               6 
      AudioControl Interface Descriptor:
        bLength                12
        bDescriptorType        36
        bDescriptorSubtype      3 (OUTPUT_TERMINAL)
        bTerminalID            20
        wTerminalType      0x0301 Speaker
        bAssocTerminal          0
        bSourceID              42
        bCSourceID              4
        bmControls         0x0000
        iTerminal               0 
      AudioControl Interface Descriptor:
        bLength                17
        bDescriptorType        36
        bDescriptorSubtype      2 (INPUT_TERMINAL)
        bTerminalID            41
        wTerminalType      0x0201 Microphone
        bAssocTerminal          0
        bCSourceID              4
        bNrChannels             4
        bmChannelConfig    0x00000000
        iChannelNames          16 
        bmControls         0x0000
        iTerminal               0 
      AudioControl Interface Descriptor:
        bLength                12
        bDescriptorType        36
        bDescriptorSubtype      3 (OUTPUT_TERMINAL)
        bTerminalID            22
        wTerminalType      0x0101 USB Streaming
        bAssocTerminal          0
        bSourceID              41
        bCSourceID              4
        bmControls         0x0000
        iTerminal               7 
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x83  EP 3 IN
        bmAttributes            3
          Transfer Type            Interrupt
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0006  1x 6 bytes
        bInterval               1
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        1
      bAlternateSetting       0
      bNumEndpoints           0
      bInterfaceClass         1 Audio
      bInterfaceSubClass      2 Streaming
      bInterfaceProtocol     32 
      iInterface              4 
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        1
      bAlternateSetting       1
      bNumEndpoints           1
      bInterfaceClass         1 Audio
      bInterfaceSubClass      2 Streaming
      bInterfaceProtocol     32 
      iInterface              4 
      AudioStreaming Interface Descriptor:
        bLength                16
        bDescriptorType        36
        bDescriptorSubtype      1 (AS_GENERAL)
        bTerminalLink          42
        bmControls           0x00
        bFormatType             1
        bmFormats          0x00000001
          PCM
        bNrChannels             4
        bmChannelConfig    0x00000000
        iChannelNames          12 
      AudioStreaming Interface Descriptor:
        bLength                 6
        bDescriptorType        36
        bDescriptorSubtype      2 (FORMAT_TYPE)
        bFormatType             1 (FORMAT_TYPE_I)
        bSubslotSize            4
        bBitResolution         24
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x01  EP 1 OUT
        bmAttributes            5
          Transfer Type            Isochronous
          Synch Type               Asynchronous
          Usage Type               Data
        wMaxPacketSize     0x0190  1x 400 bytes
        bInterval               1
        AudioStreaming Endpoint Descriptor:
          bLength                 8
          bDescriptorType        37
          bDescriptorSubtype      1 (EP_GENERAL)
          bmAttributes         0x00
          bmControls           0x00
          bLockDelayUnits         2 Decoded PCM samples
          wLockDelay         0x0008
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        2
      bAlternateSetting       0
      bNumEndpoints           0
      bInterfaceClass         1 Audio
      bInterfaceSubClass      2 Streaming
      bInterfaceProtocol     32 
      iInterface              5 
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        2
      bAlternateSetting       1
      bNumEndpoints           1
      bInterfaceClass         1 Audio
      bInterfaceSubClass      2 Streaming
      bInterfaceProtocol     32 
      iInterface              5 
      AudioStreaming Interface Descriptor:
        bLength                16
        bDescriptorType        36
        bDescriptorSubtype      1 (AS_GENERAL)
        bTerminalLink          22
        bmControls           0x00
        bFormatType             1
        bmFormats          0x00000001
          PCM
        bNrChannels             4
        bmChannelConfig    0x00000000
        iChannelNames          16 
      AudioStreaming Interface Descriptor:
        bLength                 6
        bDescriptorType        36
        bDescriptorSubtype      2 (FORMAT_TYPE)
        bFormatType             1 (FORMAT_TYPE_I)
        bSubslotSize            4
        bBitResolution         24
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x81  EP 1 IN
        bmAttributes           37
          Transfer Type            Isochronous
          Synch Type               Asynchronous
          Usage Type               Implicit feedback Data
        wMaxPacketSize     0x0190  1x 400 bytes
        bInterval               1
        AudioStreaming Endpoint Descriptor:
          bLength                 8
          bDescriptorType        37
          bDescriptorSubtype      1 (EP_GENERAL)
          bmAttributes         0x00
          bmControls           0x00
          bLockDelayUnits         2 Decoded PCM samples
          wLockDelay         0x0008
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        3
      bAlternateSetting       0
      bNumEndpoints           0
      bInterfaceClass         1 Audio
      bInterfaceSubClass      1 Control Device
      bInterfaceProtocol      0 
      iInterface              0 
      AudioControl Interface Descriptor:
        bLength                 9
        bDescriptorType        36
        bDescriptorSubtype      1 (HEADER)
        bcdADC               1.00
        wTotalLength       0x0009
        bInCollection           1
        baInterfaceNr(0)        1
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        4
      bAlternateSetting       0
      bNumEndpoints           2
      bInterfaceClass         1 Audio
      bInterfaceSubClass      3 MIDI Streaming
      bInterfaceProtocol      0 
      iInterface              0 
      MIDIStreaming Interface Descriptor:
        bLength                 7
        bDescriptorType        36
        bDescriptorSubtype      1 (HEADER)
        bcdADC               1.00
        wTotalLength       0x0041
      MIDIStreaming Interface Descriptor:
        bLength                 6
        bDescriptorType        36
        bDescriptorSubtype      2 (MIDI_IN_JACK)
        bJackType               1 Embedded
        bJackID                 1
        iJack                   0 
      MIDIStreaming Interface Descriptor:
        bLength                 6
        bDescriptorType        36
        bDescriptorSubtype      2 (MIDI_IN_JACK)
        bJackType               2 External
        bJackID                 2
        iJack                  11 
      MIDIStreaming Interface Descriptor:
        bLength                 9
        bDescriptorType        36
        bDescriptorSubtype      3 (MIDI_OUT_JACK)
        bJackType               1 Embedded
        bJackID                 3
        bNrInputPins            1
        baSourceID( 0)          2
        BaSourcePin( 0)         1
        iJack                   0 
      MIDIStreaming Interface Descriptor:
        bLength                 9
        bDescriptorType        36
        bDescriptorSubtype      3 (MIDI_OUT_JACK)
        bJackType               2 External
        bJackID                 4
        bNrInputPins            1
        baSourceID( 0)          1
        BaSourcePin( 0)         1
        iJack                  10 
      Endpoint Descriptor:
        bLength                 9
        bDescriptorType         5
        bEndpointAddress     0x02  EP 2 OUT
        bmAttributes            2
          Transfer Type            Bulk
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0200  1x 512 bytes
        bInterval               0
        bRefresh                0
        bSynchAddress           0
        MIDIStreaming Endpoint Descriptor:
          bLength                 5
          bDescriptorType        37
          bDescriptorSubtype      1 (GENERAL)
          bNumEmbMIDIJack         1
          baAssocJackID( 0)       1
      Endpoint Descriptor:
        bLength                 9
        bDescriptorType         5
        bEndpointAddress     0x82  EP 2 IN
        bmAttributes            2
          Transfer Type            Bulk
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0200  1x 512 bytes
        bInterval               0
        bRefresh                0
        bSynchAddress           0
        MIDIStreaming Endpoint Descriptor:
          bLength                 5
          bDescriptorType        37
          bDescriptorSubtype      1 (GENERAL)
          bNumEmbMIDIJack         1
          baAssocJackID( 0)       3
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        5
      bAlternateSetting       0
      bNumEndpoints           0
      bInterfaceClass       255 Vendor Specific Class
      bInterfaceSubClass      4 
      bInterfaceProtocol      1 
      iInterface              0

When both sides run continuously without breaks/xruns, they keep the latency constant (apart of slowly growing relative shift caused by potentially different clocks, if the case). The output buffer level (i.e. what CDSP reports) is changing because the buffer receives data in chunks and consumes them continuously by the soundcard. Also the relative time of reading the buffer level (at AudioMsg arrival from the Processing thread) to the time of filling the buffer (period-elapsed when the chunk is written to the buffer - the rise of the saw) with the chunk varies, further contributing to the variance.

Thank you for the explanation, I always wondered how this worked.

Michael
 

phofman

Addicted to Fun and Learning
Joined
Apr 13, 2021
Messages
503
Likes
328
Thanks, the usb dump shows that input defines implicit feedback and there is no explicit feedback endpoint. What does the proc stream0 say about the feedback considered by the driver while capturing/playing? Thanks
 
OP
M

mdsimon2

Major Contributor
Forum Donor
Joined
Oct 20, 2020
Messages
2,515
Likes
3,378
Location
Detroit, MI
Here is stream0.

Code:
michael6@raspberrypi6:~$ cat /proc/asound/M4/stream0
MOTU M4 at usb-0000:01:00.0-1.4, high speed : USB Audio

Playback:
  Status: Running
    Interface = 1
    Altset = 1
    Packet Size = 288
    Momentary freq = 96000 Hz (0xc.0000)
  Interface 1
    Altset 1
    Format: S32_LE
    Channels: 4
    Endpoint: 0x01 (1 OUT) (ASYNC)
    Rates: 44100, 48000, 88200, 96000, 176400, 192000
    Data packet interval: 125 us
    Bits: 24
    Channel map: FL FR FC LFE
    Sync Endpoint: 0x81 (1 IN)
    Sync EP Interface: 2
    Sync EP Altset: 1
    Implicit Feedback Mode: Yes

Capture:
  Status: Running
    Interface = 2
    Altset = 1
    Packet Size = 288
    Momentary freq = 96000 Hz (0xc.0000)
  Interface 2
    Altset 1
    Format: S32_LE
    Channels: 4
    Endpoint: 0x81 (1 IN) (ASYNC)
    Rates: 44100, 48000, 88200, 96000, 176400, 192000
    Data packet interval: 125 us
    Bits: 24
    Channel map: FL FR FC LFE

This is a complete guess but does the order of operations have anything to do with this? I noticed that with resampling enabled the playback device is opened first by CamillaDSP but it seems like without resampling the capture device is opened first.

Thinking back I also remember when I was first trying out the MOTU Ultralite Mk5 I had a similar issue where I needed to enable resampling when using the TOSLINK input even the the interface clock was set to TOSLINK. I never understood why but now I am wondering if it is the same issue.

Michael
 

HenrikEnquist

Member
Joined
Jul 1, 2021
Messages
82
Likes
110
It may be the order! When resampling is enabled, then the capture thread first creates the resampler before it opens the capture device. That takes a little while, so the it doesn't start opening the capture device until the playback device is already opened.
Could you try adding a little sleep in the capture thread, before it opens the device?
 

HenrikEnquist

Member
Joined
Jul 1, 2021
Messages
82
Likes
110

phofman

Addicted to Fun and Learning
Joined
Apr 13, 2021
Messages
503
Likes
328
Right, that error has nothing to do with the feedback or diverting capture/playback rate (the implicit feedback seems to be detected correctly by the driver). It looks like some lock contention in the driver when trying to install hw params to both devices at close moments, even with the hw params having same rate and sample size.
 
OP
M

mdsimon2

Major Contributor
Forum Donor
Joined
Oct 20, 2020
Messages
2,515
Likes
3,378
Location
Detroit, MI
Add this:
let delay = Duration::from_millis(100); thread::sleep(delay);

Insert it before open_pcm() here:

Thanks!

That did it, now can use analog inputs of M4 without resampling. Also checked the Ultralite Mk5 and it fixed my TOSLINK issues and can use the TOSLINK input without resampling.

Code:
2022-07-21 16:09:39.778564 INFO  [src/bin.rs:711] CamillaDSP version 1.0.0
2022-07-21 16:09:39.778738 INFO  [src/bin.rs:712] Running on linux, aarch64
2022-07-21 16:09:39.778934 DEBUG [src/bin.rs:754] Read config file Some("/home/michael6/camilladsp/active_config.yml")
2022-07-21 16:09:39.780886 DEBUG [src/bin.rs:773] Config is valid
2022-07-21 16:09:39.781025 DEBUG [src/socketserver.rs:260] Start websocket server on 127.0.0.1:1234
2022-07-21 16:09:39.781368 DEBUG [src/bin.rs:857] Wait for config
2022-07-21 16:09:39.781480 DEBUG [src/bin.rs:890] Config ready
2022-07-21 16:09:39.781972 DEBUG [src/filters.rs:450] Build new pipeline
2022-07-21 16:09:39.781972 DEBUG [src/bin.rs:213] Using channels [false, false, false, false, false, false, false, false, false, false, false, false, true, true, false, false]
2022-07-21 16:09:39.782154 DEBUG [src/alsadevice.rs:903] Buffer frames 1024
2022-07-21 16:09:39.782165 DEBUG [src/filters.rs:355] Build from config
2022-07-21 16:09:39.782272 DEBUG [src/filters.rs:355] Build from config
2022-07-21 16:09:39.782383 DEBUG [src/filters.rs:355] Build from config
2022-07-21 16:09:39.782520 DEBUG [src/filters.rs:355] Build from config
2022-07-21 16:09:39.782629 DEBUG [src/filters.rs:355] Build from config
2022-07-21 16:09:39.782742 DEBUG [src/filters.rs:355] Build from config
2022-07-21 16:09:39.782848 DEBUG [src/filters.rs:355] Build from config
2022-07-21 16:09:39.782955 DEBUG [src/filters.rs:355] Build from config
2022-07-21 16:09:39.783064 DEBUG [src/filters.rs:355] Build from config
2022-07-21 16:09:39.783169 DEBUG [src/filters.rs:355] Build from config
2022-07-21 16:09:39.783271 DEBUG [src/filters.rs:355] Build from config
2022-07-21 16:09:39.783372 DEBUG [src/filters.rs:355] Build from config
2022-07-21 16:09:39.783474 DEBUG [src/filters.rs:355] Build from config
2022-07-21 16:09:39.783575 DEBUG [src/filters.rs:355] Build from config
2022-07-21 16:09:39.783680 DEBUG [src/filters.rs:355] Build from config
2022-07-21 16:09:39.783787 DEBUG [src/filters.rs:355] Build from config
2022-07-21 16:09:39.783919 DEBUG [src/processing.rs:19] build filters, waiting to start processing loop
2022-07-21 16:09:39.785494 DEBUG [src/alsadevice.rs:406] Playback: supported channels, min: 10, max: 22, list: [10, 18, 22]
2022-07-21 16:09:39.785644 DEBUG [src/alsadevice.rs:407] Playback: setting channels to 18
2022-07-21 16:09:39.785836 DEBUG [src/alsadevice.rs:411] Playback: supported samplerates: Discrete([88200, 96000])
2022-07-21 16:09:39.785966 DEBUG [src/alsadevice.rs:412] Playback: setting rate to 96000
2022-07-21 16:09:39.786110 DEBUG [src/alsadevice.rs:416] Playback: supported sample formats: [S24LE3]
2022-07-21 16:09:39.786225 DEBUG [src/alsadevice.rs:417] Playback: setting format to S24LE3
2022-07-21 16:09:39.791250 DEBUG [src/alsadevice.rs:448] Opening audio device "hw:UltraLitemk5" with parameters: HwParams { channels: Ok(18), rate: "Ok(96000) Hz", format: Ok(S243LE), access: Ok(RWInterleaved), period_size: "Ok(128) frames", buffer_size: "Ok(1024) frames" }, SwParams(avail_min: Ok(512) frames, start_threshold: Ok(384) frames, stop_threshold: Ok(1024) frames)
2022-07-21 16:09:39.791433 DEBUG [src/alsadevice.rs:453] Audio device "hw:UltraLitemk5" successfully opened
2022-07-21 16:09:39.791590 DEBUG [src/bin.rs:323] Playback thread ready to start
2022-07-21 16:09:39.883473 DEBUG [src/alsadevice.rs:406] Capture: supported channels, min: 16, max: 16, list: [16]
2022-07-21 16:09:39.883613 DEBUG [src/alsadevice.rs:407] Capture: setting channels to 16
2022-07-21 16:09:39.883720 DEBUG [src/alsadevice.rs:411] Capture: supported samplerates: Discrete([96000])
2022-07-21 16:09:39.883819 DEBUG [src/alsadevice.rs:412] Capture: setting rate to 96000
2022-07-21 16:09:39.883924 DEBUG [src/alsadevice.rs:416] Capture: supported sample formats: [S24LE3]
2022-07-21 16:09:39.884022 DEBUG [src/alsadevice.rs:417] Capture: setting format to S24LE3
2022-07-21 16:09:39.884299 DEBUG [src/alsadevice.rs:448] Opening audio device "hw:UltraLitemk5" with parameters: HwParams { channels: Ok(16), rate: "Ok(96000) Hz", format: Ok(S243LE), access: Ok(RWInterleaved), period_size: "Ok(128) frames", buffer_size: "Ok(1024) frames" }, SwParams(avail_min: Ok(512) frames, start_threshold: Ok(0) frames, stop_threshold: Ok(1024) frames)
2022-07-21 16:09:39.884436 DEBUG [src/alsadevice.rs:453] Audio device "hw:UltraLitemk5" successfully opened
2022-07-21 16:09:39.884591 DEBUG [src/bin.rs:333] Capture thread ready to start
2022-07-21 16:09:39.884694 DEBUG [src/bin.rs:336] Both capture and playback ready, release barrier
2022-07-21 16:09:39.884814 DEBUG [src/bin.rs:338] Supervisor loop starts now!
2022-07-21 16:09:39.884837 DEBUG [src/alsadevice.rs:948] Starting captureloop
2022-07-21 16:09:39.884912 DEBUG [src/processing.rs:21] Processing loop starts now!
2022-07-21 16:09:39.884922 DEBUG [src/alsadevice.rs:850] Starting playback loop
2022-07-21 16:09:39.885295 DEBUG [src/alsadevice.rs:244] Starting capture from state: SND_PCM_STATE_PREPARED, Ready to start
2022-07-21 16:09:39.891988 INFO  [src/alsadevice.rs:156] Starting playback from Prepared state

Michael
 
Last edited:

phofman

Addicted to Fun and Learning
Joined
Apr 13, 2021
Messages
503
Likes
328
So the order does not matter, just the concurrency does. It really looks like something the driver should be taking care of.
 

chuckt62

Active Member
Editor
Joined
Apr 6, 2022
Messages
142
Likes
123
Location
Tejas
@mdsimon2, can you add the steps for updating to the latest version, to the end of Part 2 of this tutorial?
 
OP
M

mdsimon2

Major Contributor
Forum Donor
Joined
Oct 20, 2020
Messages
2,515
Likes
3,378
Location
Detroit, MI

Jeromeof

Addicted to Fun and Learning
Forum Donor
Joined
Jul 25, 2021
Messages
627
Likes
997
Location
Ireland
Anyone know of a pre-built made an pre-installed image(s) for a RPI4 with all this setup done? Thinking of the basic setup + airplay, bluetooth, squeezelite and now maybe adding PlexAmp. I know there are some images like Volumio or MoodeAudio but they are more about setting up RPI as a streamer, while I like the idea just having a RPI4 as a high quality Audio DSP 'endpoint' for other systems to stream too?
 
Top Bottom