AVAudioOutputSettings not recognizing values I've set

Hello. I'm using AVFoundation to capture audio, and am setting the following audio settings for an AVCaptureAudioDataOutput:

audioOutput.audioSettings[AVLinearPCMBitDepthKey] = 16
audioOutput.audioSettings[AVLinearPCMIsFloatKey] = false

These seem fine as per the docs on the permitted values for these keys (and I know that AVAudioOutputSettings errors if you pass in bad values). My issue is that I get the following error from this code:
+[AVAudioOutputSettings audioOutputSettingsWithAudioSettingsDictionary:] If one of AVLinearPCMIsFloatKey and AVLinearPCMBitDepthKey is specified, both must be specified

This is confusing because I've set both of these values above. I get the same error even if I only set one of the two values. I've tried putting in different values for them but to no avail; it wants both values to be set, even though both are set. I haven't been able to find any source code to look deeper into this. Could anyone share any insight?

Did you try setting them at the same time?

var settings = audioOutput.audioSettings
settings[AVLinearPCMBitDepthKey] = 16
settings[AVLinearPCMIsFloatKey] = false
audioOutput.audioSettings = settings
1 Like

Ah, no, I just tried that and it worked, thank you.

1 Like