HEnquist / camilladsp

A flexible cross-platform IIR and FIR engine for crossovers, room correction etc.
https://henquist.github.io/
GNU General Public License v3.0
505 stars 48 forks source link

Segfault on certain config using CoreAudio with USB hardware audio interface #318

Closed SamuelSwartzberg closed 4 months ago

SamuelSwartzberg commented 5 months ago

Describe the bug

When reading from a certain config (see below), camilladsp segfaults immediately due to a null pointer.

To Reproduce

camilladsp /path/to/config.yml

System info

Configuration

devices:
  samplerate: 192000
  chunksize: 4096
  enable_rate_adjust: true
  capture:
    type: CoreAudio
    channels: 2
    device: 'UMC202HD 192k'
  playback:
    type: CoreAudio
    channels: 2
    device: 'BlackHole 2ch'
mixers:
  map_left_to_both:
    description: Mix left channel to both channels
    channels:
      in: 2
      out: 2
    mapping:
      - dest: 0
        sources:
          - channel: 0
            gain: 0
            inverted: false
      - dest: 1
        sources:
          - channel: 0
            gain: 0
            inverted: false
pipeline:
  - type: Mixer
    name: map_left_to_both

Logs

2024-02-04 12:43:26.981124 INFO [src/bin.rs:683] CamillaDSP version 2.0.1
2024-02-04 12:43:26.981205 INFO [src/bin.rs:684] Running on macos, aarch64
2024-02-04 12:43:26.981223 DEBUG [src/bin.rs:728] Loaded state: None
2024-02-04 12:43:26.981227 DEBUG [src/bin.rs:738] Using default initial volume
2024-02-04 12:43:26.981229 DEBUG [src/bin.rs:755] Using default initial mute
2024-02-04 12:43:26.981231 DEBUG [src/bin.rs:765] Initial mute: [false, false, false, false, false]
2024-02-04 12:43:26.981233 DEBUG [src/bin.rs:766] Initial volume: [0.0, 0.0, 0.0, 0.0, 0.0]
2024-02-04 12:43:26.981238 DEBUG [src/bin.rs:768] Read config file Some("/Users/sam/gtr/mac-audio-video-kit/pipelines/stereo_routing.yml")
2024-02-04 12:43:26.981585 DEBUG [src/bin.rs:808] Config is valid
2024-02-04 12:43:26.981650 DEBUG [src/bin.rs:994] Wait for config
2024-02-04 12:43:26.981655 DEBUG [src/bin.rs:1010] Waiting to receive a command
2024-02-04 12:43:26.981659 DEBUG [src/bin.rs:1013] Config change command received
2024-02-04 12:43:26.981661 DEBUG [src/bin.rs:999] New config is available and there are no queued commands, continuing
2024-02-04 12:43:26.981663 DEBUG [src/bin.rs:1036] Config ready, start processing
2024-02-04 12:43:26.981748 DEBUG [src/bin.rs:157] Using channels [true, false]
2024-02-04 12:43:26.981736 DEBUG [src/filters.rs:488] Build new pipeline
2024-02-04 12:43:26.981910 DEBUG [src/processing.rs:19] build filters, waiting to start processing loop
2024-02-04 12:43:26.981779 DEBUG [src/coreaudiodevice.rs:361] Using a playback channel capacity of 3 chunks.
2024-02-04 12:43:26.981857 DEBUG [src/coreaudiodevice.rs:628] Using a capture channel capacity of 65 buffers.
2024-02-04 12:43:27.054975 DEBUG [src/coreaudiodevice.rs:255] Available capture devices: ["联想thinkplus-TH30", "联想thinkplus-TH20", "UMC202HD 192k", "BlackHole 16ch", "BlackHole 2ch"]
2024-02-04 12:43:27.075670 DEBUG [src/coreaudiodevice.rs:244] Opened CoreAudio playback device Some("BlackHole 2ch")
2024-02-04 12:43:27.075804 DEBUG [src/coreaudiodevice.rs:469] Playback device ready and waiting
2024-02-04 12:43:27.075813 DEBUG [src/bin.rs:265] Playback thread ready to start
2024-02-04 12:43:27.077194 DEBUG [src/coreaudiodevice.rs:312] Set capture stream format
2024-02-04 12:43:27.082240 DEBUG [src/coreaudiodevice.rs:326] Opened CoreAudio capture device Some("UMC202HD 192k")
2024-02-04 12:43:27.082633 DEBUG [src/coreaudiodevice.rs:1090] Capture device has 1 clock sources
Segmentation fault: 11

lldb output for good measure

Process 13268 stopped
* thread #7, name = 'CoreaudioCapture', stop reason = EXC_BAD_ACCESS (code=1, address=0x0)
    frame #0: 0x0000000183ef2dc4 libsystem_platform.dylib`_platform_strlen + 4
libsystem_platform.dylib`:
->  0x183ef2dc4 <+4>:  ldr    q0, [x1]
    0x183ef2dc8 <+8>:  adr    x3, #-0xc8                ; ___lldb_unnamed_symbol282
    0x183ef2dcc <+12>: ldr    q2, [x3], #0x10
    0x183ef2dd0 <+16>: and    x2, x0, #0xf
Target 0: (camilladsp) stopped.
(lldb) bt
* thread #7, name = 'CoreaudioCapture', stop reason = EXC_BAD_ACCESS (code=1, address=0x0)
  * frame #0: 0x0000000183ef2dc4 libsystem_platform.dylib`_platform_strlen + 4
    frame #1: 0x00000001002237b0 camilladsp`_$LT$camillalib..coreaudiodevice..CoreaudioCaptureDevice$u20$as$u20$camillalib..audiodevice..CaptureDevice$GT$::start::_$u7b$$u7b$closure$u7d$$u7d$::h8371dc9239dc31dd + 6408
    frame #2: 0x0000000100173638 camilladsp`std::sys_common::backtrace::__rust_begin_short_backtrace::h68896ed6e2785d26 + 12
    frame #3: 0x0000000100183d78 camilladsp`core::ops::function::FnOnce::call_once$u7b$$u7b$vtable.shim$u7d$$u7d$::ha60263269f35c6cd + 256
    frame #4: 0x0000000100318c08 camilladsp`std::sys::unix::thread::Thread::new::thread_start::h9b6324e2391e6ebb + 48
    frame #5: 0x0000000183ec6034 libsystem_pthread.dylib`_pthread_start + 136

Note

While I do write code frequently, audio processing is a new field for me, with which I am not very familiar. This config file was my attempt to migrate my Element config over to try and understand the basics of camilladsp. So I can't exclude I'm just doing something pretty stupid that'd be obvious to anyone in the field.

HEnquist commented 5 months ago

Thanks! I managed to reproduce this with a Motu M4. The problems happens when trying to read the names of the capture device clock sources. The call to CoreAudio should return a pointer to a string. But for some reason, for some device, it returns a null pointer. This fixes it by adding a check before trying to access the string: https://github.com/HEnquist/camilladsp/pull/319 I'll release a 2.0.2 asap, just need to figure out why building on linux decided to stop working.

SamuelSwartzberg commented 5 months ago

Great! Thanks for the quick turnaround :D

HEnquist commented 4 months ago

fixed in release 2.0.2

SamuelSwartzberg commented 4 months ago

Just upgraded and it works! :D Thanks!