Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Code snippets showing how to get ambisonic playback working, however head rotation doesn't work.
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()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment