KevinBrewster
KevinBrewster

Reputation: 31

AVAudioMixerNode pan or AVAudioUnitSampler stereoPan properties not working to change left/right balance of sound output for AVAudioEngine

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

Answers (2)

sven7
sven7

Reputation: 748

According to Apple Developer Forum the range of stereopan is -100 to 100.

Upvotes: 1

Johan Velthuis
Johan Velthuis

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

Related Questions