Code snippets showing how to get ambisonic playback working, however head rotation doesn't work.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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