miniaudio icon indicating copy to clipboard operation
miniaudio copied to clipboard

jack: only open as many channels as requested, option to not autoconnect to default device

Open digitalsignalperson opened this issue 1 year ago • 2 comments

Current behavior:

My default device has 8 channels. If I request 2 channels it creates a jack device with 8 outputs and auto-connect them all.

Desired behavior:

  • Request 2 channels, get 2 channels
  • Request 32 channels, get 32 (regardless if the default device has less)
  • Ability to enable or disable autoconnecting to the default device

Details

With this config

    ma_device_config deviceConfig = ma_device_config_init(ma_device_type_playback);
    deviceConfig.playback.format = ma_format_f32;
    deviceConfig.playback.channels = 2;
    deviceConfig.sampleRate = 48000.0f;

The result is: image

Proposed solution

Number of channels

  • Since in device config the .playback.channels is ignored for jack, then I suggest if it is default 0 to use the number of channels in the default device.
  • If .playback.channels is non-zero, then in ma_device_init__jack() simply create as many channels with (ma_jack_port_register_proc)() instead of basing it off the default device specs.

Autoconnect

  • in the context config add a .jack.autoconnect setting
  • in ma_device_start__jack() don't do calls to (ma_jack_connect_proc)() if .jack.autoconnect is false

digitalsignalperson avatar May 23 '24 21:05 digitalsignalperson

Thanks. I don't have a whole lot of experience with jack, but everything you mentioned here makes sense. I'm actually surprised it's not already doing the channel count thing. Just on the autoconnect thing, if jack.autoconnect is false, I wouldn't do any jack_connect() at all? Does that not need to be called at some point in order for audio to actually work?

mackron avatar May 23 '24 22:05 mackron

@mackron correct, I have it working without calling jack_connect() at all. See #852

digitalsignalperson avatar May 24 '24 01:05 digitalsignalperson

Sorry for leaving this one hanging. I finally got around to doing another pass on the JACK backend. I've pushed some changes to the dev-0.12 branch which should address all of the issues you pointed out. Unfortunately this branch has breaking API changes and is not quite ready for general use so I don't recommend you immediately switch over just yet, but I thought I'd drop a message here to let you know that these changes will be making it in eventually.

I decided to make the noAutoConnect thing part of the device config rather than the context config.

I will go ahead and close your PR.

mackron avatar Jul 18 '25 06:07 mackron

Cool. Any idea, when can we expect this to land in a release?

SpotlightKid avatar Sep 15 '25 22:09 SpotlightKid

With 0.12, probably sometime next year.

mackron avatar Sep 15 '25 23:09 mackron