PortAudio / portaudio

PortAudio is a cross-platform, open-source C language library for real-time audio input and output.
Other
1.43k stars 296 forks source link

CoreAudio - device parameters not changing to match stream bit depth even with paMacCoreChangeDeviceParameters #824

Open TDW89 opened 1 year ago

TDW89 commented 1 year ago

Describe the bug

paMacCoreChangeDeviceParameters and paMacCoreFailIfConversionRequired not functioning as expected with regard to stream bit depth.

To Reproduce

Steps to reproduce the behavior.

  1. connect a usb audio device that supports multiple bit depths (in our case 16-bit int and 24-bit int) and sample rates.
  2. Select format 16-bit Integer 44.1kHz in Audio Midi Settings
  3. use port audio to start a 24-bit Integer 48kHz stream with the flags
    • paMacCoreChangeDeviceParameters
    • paMacCoreFailIfConversionRequired
  4. observe the format in Audio Midi Settings or monitor with USB analyser if available.

Expected behavior

The format should change to 24-bit 48kHz

Actual behavior

The format instead only changes sample rate to 16-bit 48kHz, or alternatively fail due to the paMacCoreFailIfConversionRequired flag but the preferred behaviour would be to change device parameters since it is a supported format.

Desktop:

Additional context

We are testing a device that supports both 16-bit and 24-bit PCM streams, at a variety of bit rates, by sending it known values and checking that those values are reaching the DAC. On macOS we have run into an issue where the host is selecting eg. 44.1kHz 16-bit causing a 44.1kHz 24-bit test stream to lose 8 bits of resolution. If the correct bit depth is selected in Audio Midi Settings, then the issue resolves itself but interacting with the gui is less than ideal for remote testing.

RossBencina commented 1 year ago

the preferred behaviour would be to change device parameters since it is a supported format.

I agree. I think we'd accept a patch that did that.

Have you looked into the PortAudio code? Do you think this is an omission, an error in the PA code, or perhaps an issue with CoreAudio not actually changing the bit depth as requested?

philburk commented 1 year ago

I wonder whether PortAudio is doing 24 to 16-bit conversion itself, or is PortAudio passing 24-bit audio to CoreAudio and then CoreAudio converts to 16-bit.