Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var engine = AVAudioEngine()
- var environmentMixer = AVAudioEnvironmentNode()
- func initSound() {
- let player = AVAudioPlayerNode()
- let url = NSBundle.mainBundle().URLForResource("sound", withExtension: "wav")!
- let f = try! AVAudioFile(forReading: url)
- engine.attachNode(environmentMixer)
- let format = AVAudioFormat(standardFormatWithSampleRate: engine.outputNode.outputFormatForBus(0).sampleRate, channels: 2)
- engine.connect(environmentMixer, to: engine.outputNode, format: format)
- engine.attachNode(player)
- engine.connect(player, to: environmentMixer, format: f.processingFormat)
- environmentMixer.renderingAlgorithm = AVAudio3DMixingRenderingAlgorithmHRTF
- player.scheduleFile(f, atTime: nil, completionHandler: {print("done")})
- player.position = AVAudio3DPoint (x: 0.5, y: 0.25, z: 0)
- engine.prepare()
- do {
- try engine.start()
- player.play()
- } catch {}
- }
Advertisement
Add Comment
Please, Sign In to add comment