14

Is it possible to pan sound to either the top or bottom speaker on the iPhone 7 and newer models? I don't have one of these phones, but my understanding is that iOS mixes stereo sound and plays it back from both speakers when the phone is in portrait mode. I know it routes left and right channels to their respective speakers in landscape, but I can't find documentation about the behavior in portrait mode.

Is it possible to limit playback to just one speaker or the other, or to pan between top and bottom? My library cannot operate with the destructive interference of both speakers playing at the same time.

jscs
  • 63,694
  • 13
  • 151
  • 195
Brian Armstrong
  • 326
  • 2
  • 14
  • 1
    Did you try by setting player.pan? – Forte Zhu Feb 05 '18 at 09:53
  • 1
    Can the OP or @CatsLoveJazz run this gist https://gist.github.com/rfistman/1c63315d6634112eac8b1f7dc9dffe64 on an iPhone 7 (ideally without headphones) and report back the results? adapted from https://stackoverflow.com/questions/15643516/list-available-output-audio-target-avaudiosession – Rhythmic Fistman Apr 26 '18 at 09:46
  • Checkout AVAudioSession class, I don't think you can do that. This is available under accessibility settings for override by end users. What you can do is toggle between speakers and earphone. Though you can check this gist - https://gist.github.com/rfistman/1c63315d6634112eac8b1f7dc9dffe64 – mdeora May 02 '18 at 15:27
  • 1
    Did you try setting AvAudioPlayers' pan property? -1 or 1. – Emre Önder May 08 '18 at 06:38
  • In light of this [Q&A on Reddit](https://www.reddit.com/r/apple/comments/5434ma/iphone_7_stereo_speakers_will_adjust_lr_based_on/) you will probably want [your GitHub code](https://github.com/brian-armstrong/speaker-tester?files=1) to consider UIDeviceOrientation so you can flip your left and right as you turn your phone, even with a 'portrait only' APP. I think you're interfacing at too high a level in the API to get such fine grained control (you're asking 'play this' and it does, in accordance with the volume control and accessibility features - IE: you can't override system settings). – Rob May 13 '18 at 17:55

1 Answers1

2

It turns out my question was misguided. It's hard to get credible information when you can't test on the device yourself.

On iPhone 7 and newer, the stereo channels are actually routed to the individual speakers, even though there is no stereo separation. The left channel routes to the bottom speaker, and the right channel routes to the top/headset speaker. Using the pan attribute can also accomplish the same thing.

Finally, there's one more option with channel assignments. Using AVAudioSession.sharedInstance.currentRoute.outputs, the two speakers combined show up as a single output (outputs[0]). Inside this output are two channels, outputs[0].channels[0] and outputs[0].channels[1]. Mapping to either of these with channel assignments works as well, with the first channel mapping to the bottom speaker and the second to the top.

Any of these methods works fine as a way to route sound output to the new stereo speakers, even when the phone is in portrait orientation.

For anyone who wants to try on their own device, I put together a test application that tests out the various approaches https://github.com/brian-armstrong/speaker-tester

Brian Armstrong
  • 326
  • 2
  • 14