Sunday, May 13, 2018

Panning sound between top and bottom speaker on iPhone 7

Leave a Comment

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.

2 Answers

Answers 1

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.

Answers 2

It apperes that you can add https://developer.apple.com/documentation/audiounit to your app to manipulate sounds.

This page has some more information. https://developer.apple.com/documentation/audiounit/audio_unit_properties

If You Enjoyed This, Take 5 Seconds To Share It

0 comments:

Post a Comment