问题
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