title: AVFoundation positional audio not working on iOS device
body: <p>I'm trying to play positional audio in a Swift iOS app using <code>AVAudioEngine</code> and <code>AVAudioEnvironmentNode</code>. I can successfully play the audio fine and hear it spatialized, shifting between both outputs in stereo, but <strong>only in the simulator</strong>. When I run the same app on an iPhone, the audio plays but in both ears rather than panning when the source is moved around. Is there some special configuration I need to do, like manually handling the device audio output?</p>
  
  <p>I initialize the audio engine and player like so:</p>
  
  <pre class="lang-swift prettyprint-override"><code>let audioEngine = AVAudioEngine()
  let audioEnv = AVAudioEnvironmentNode()
  
  audioEngine.attach(audioEnv)
  audioEngine.connect(
      audioEnv,
      to: audioEngine.mainMixerNode,
      format: audioEnv.outputFormat(forBus: 0)
  )
  try audioEngine.start()
  
  let player = AVAudioPlayerNode()
  audioEngine.attach(player)
  audioEngine.connect(
      player,
      to: audioEnv,
      format: AVAudioFormat(standardFormatWithSampleRate: 44100, channels: 1)
  )
  
  player.scheduleFile(...)
  player.play()
  </code></pre>
  
  <p>My source files are mono channel <code>.wav</code>.</p>
  
  <p>At some point in the future, I change the position of the player:</p>
  
  <pre class="lang-swift prettyprint-override"><code>player.position = AVAudio3DPoint(x: 5, y: 0, z: 0)
  </code></pre>
  
  <p>This should play only (or mostly) in one ear. When run in the iOS simulator, it does exactly what I expect. However, on an actual device it just plays evenly in both ears no matter what <code>player.position</code> is set to. I suspect it has to do with the configuration of <code>audioEngine</code>.</p>
  
  <p>Thoughts?</p>