AVAudioSinkNode with non-default, but still device-native sample rates

喜夏-厌秋 提交于 2020-04-17 07:17:09

问题


I've configured AVAudioSinkNode attached to AVAudioEngine's inputNode like so:

let sinkNode = AVAudioSinkNode() { (timestamp, frames, audioBufferList) -> OSStatus in
    print("SINK: \(timestamp.pointee.mHostTime) - \(frames) - \(audioBufferList.pointee.mNumberBuffers)")
    return noErr
}

audioEngine.attach(sinkNode)
audioEngine.connect(audioEngine.inputNode, to: sinkNode, format: nil)
audioEngine.prepare()

do {
    try audioEngine.start()
    print("AudioEngine started.")
} catch {
    print("AudioEngine did not start!")
}

I've separately configured it to use the "Built-in Microphone" device (which I am sure it does use).

If I set sample rate 44100 for the mic (using "Audio MIDI Setup" app provided by Apple on all Macs), everything works as expected:

AudioEngine started.
SINK: 692312319180567 - 512 - 2
SINK: 692312348024104 - 512 - 2
SINK: 692312359634082 - 512 - 2
SINK: 692312371244059 - 512 - 2
SINK: 692312382854036 - 512 - 2
...

However, if I use "Audio MIDI Setup" app (provided by Apple on all Macs), and change the mic's sample rate to anything other than 44100 (say 48000), then the sink node doesn't seem to do anything (doesn't print anything).

Of course, originally I was trying to modify the mic's sample rate programmatically. But later on I discovered that the same happens when I just change the device sample rate via the standard "Audio MIDI Setup" app. Therefore, the code I have for setting the sample rate is unnecessary to post here.

Does anyone know if AVAudioSinkNode has allowed sample rate hard-coded into it?

I cannot find any other explanation...

来源:https://stackoverflow.com/questions/60837320/avaudiosinknode-with-non-default-but-still-device-native-sample-rates

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!