I am also attempting to get ambisonic audio playback working with AVFoundation / AVFAudio with the AVAudioEngine through an AVAudioEnvironmentNode. I believe I have gotten a .WAV PCM Ambisonics B_Format (4 Channel) audio file playing back properly as shown in the code below. However, rotating the listeners head via listenerAngularOrientation.yaw doesn't affect the ambisonic audio rotation.
private let AmbiPlayerNode = AVAudioPlayerNode()
func playAmbiAudio(){
guard let AmbiFileURL = Bundle.main.url(forResource: "crowdAmbiOut", withExtension: "wav")
else{
print("read ambi failed")
return
}
let file = try! AVAudioFile(forReading: AmbiFileURL)
let layout = AVAudioChannelLayout(layoutTag: kAudioChannelLayoutTag_Ambisonic_B_Format)
let format = AVAudioFormat(commonFormat: .pcmFormatFloat32, sampleRate: 44100, interleaved: false, channelLayout: (layout)!)
guard let buffer = AVAudioPCMBuffer(pcmFormat: format, frameCapacity: UInt32(file.length)) else
{
print("buffer failed")
return
}
try! file.read(into: buffer)
engine.attach(AmbiPlayerNode)
engine.connect(AmbiPlayerNode, to: environment, format: file.processingFormat)
AmbiPlayerNode.scheduleBuffer(buffer, at: nil, options: .loops, completionHandler: nil)
AmbiPlayerNode.sourceMode = .ambienceBed
AmbiPlayerNode.play()
}
Post
Replies
Boosts
Views
Activity
I haven't mastered the Apple Developer forums formatting. Here is a more readable link.