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
566 stars 49 forks source link

ALSA support for MMAP_NONINTERLEAVED access method interfaces #364

Closed siraaris closed 1 month ago

siraaris commented 1 month ago

I've added an RME HDSPe MADI PCIe card to a Linux system, as an attempt to bridge to an AVB/MADI device (and RME M32 DA Pro) (due to a lack of Linux AVB support generally).

Running camilladsp (version 3 pre-release) results in an error -

2024-09-25 13:24:41.653631 ERROR [src/bin.rs:292] Playback error: ALSA function 'snd_pcm_hw_params_set_access' failed with error 'Invalid argument (22)'

Looking at the code, alsadevice.rs accesses the device as RWInterleaved, which this device does not support.

Line 388 (alsadevice.rs): hwp.set_access(Access::RWInterleaved)?;

Note that with the aplay utility:

aris@core:~/proj$ aplay -vvv -D hw:CARD=HDSPe24081377,DEV=0 -c32 -fS32_LE -r96000 Phoebe\ Bridgers\ -\ Punisher\ -\ 04\ Punisher.raw Playing raw data 'Phoebe Bridgers - Punisher - 04 Punisher.raw' : Signed 32 bit Little Endian, Rate 96000 Hz, Channels 32 aplay: set_params:1382: Access type not available

But with accessing with MMAP:

aris@core:~/proj$ aplay -M -vvv -D hw:CARD=HDSPe24081377,DEV=0 -c32 -fS32_LE -r96000 Phoebe\ Bridgers\ -\ Punisher\ -\ 04\ Punisher.raw Playing raw data 'Phoebe Bridgers - Punisher - 04 Punisher.raw' : Signed 32 bit Little Endian, Rate 96000 Hz, Channels 32 Hardware PCM card 1 'RME MADI_24081377' device 0 subdevice 0 Its setup is: stream : PLAYBACK access : MMAP_NONINTERLEAVED format : S32_LE subformat : STD channels : 32 rate : 96000 exact rate : 96000 (96000/1) msbits : 24 buffer_size : 8192 period_size : 4096 period_time : 42666 tstamp_mode : ENABLE tstamp_type : MONOTONIC period_step : 1 avail_min : 4096 period_event : 0 start_threshold : 8192 stop_threshold : 8192 silence_threshold: 0 silence_size : 0 boundary : 4611686018427387904 appl_ptr : 0 hw_ptr : 0

I suspect accessing the ALSA device should only try the methods supported by the card, but at the moment, RWInterleaved is the default?

HEnquist commented 1 month ago

Yes it uses RW_INTERLEAVED because it's by far the most common and nearly all devices support it. MMAP works quite differently from the RW modes and I don't plan to support it. You can always use a plug to get around that. That could perhaps be useful to suggest in the error message. Does the device support RW_NONINTERLEAVED?

siraaris commented 1 month ago

I guess fair enough. I started looking at conversions.rs where I think work would be needed?

siraaris commented 1 month ago

As far as I can tell it supports only MMAP_NONINTERLEAVED.

HEnquist commented 1 month ago

RWNONINTERLEAVED could be supported mostly by changes in conversions.rs, but the MMAP(NON)INTERLEAVED modes exchange data in a different way and need a lot of changes in alsadevice.rs as well.

siraaris commented 1 month ago

I've set up /etc/asound.conf to use plug, and playing to the device at 96k, 32ch.

I'm seeing the following - assume they are harmless?

2024-09-30 01:52:05.419867 DEBUG [src/alsadevice_utils.rs:406] Event from numid 1 2024-09-30 01:52:05.419879 DEBUG [src/alsadevice_utils.rs:542] Ignoring event from unknown numid 1

HEnquist commented 1 month ago

Yes those are harmless, just means that there was a change event from a control that camilladsp doesn't care about. You can list the controls with the amixer command to see that the control with numid 1 is.

siraaris commented 1 month ago

Think this one should close, the plughw ALSA device seems to work well.

siraaris commented 2 weeks ago

Just for completeness in case someone lands here in the future.

Another way is to use Jack as the playback device in CamillaDSP.