Reputation: 31
I have the following code, which plays a single midi note, but I want to be able to adjust the balance/pan so that it only plays out of the left speaker or the right speaker or perhaps some combination. I thought changing "sampler.stereoPan" or perhaps "engine.mainMixerNode.pan" would do the trick but it seems to have no effect. Any ideas what I'm doing wrong?
engine = AVAudioEngine()
sampler = AVAudioUnitSampler()
sampler.stereoPan = -1.0 // doesn't work
//engine.mainMixerNode.pan = -1.0 // doesn't work
engine.attachNode(sampler)
engine.connect(sampler, to: engine.mainMixerNode, format: engine.mainMixerNode.outputFormatForBus(0))
var error: NSError?
engine.startAndReturnError(&error)
sampler.startNote(65, withVelocity: 64, onChannel: 1)
Upvotes: 3
Views: 1172
Reputation: 748
According to Apple Developer Forum the range of stereopan
is -100 to 100.
Upvotes: 1
Reputation: 320
You should set the pan of any node after it has been connected, the pan settings are defaulted again at the engine.connect method.
Upvotes: 1