Support for multi-channel audio streaming #1273
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
PR
Description & motivation
This change is providing an audio layout for the
AVAudioFormat
when number for channels of the input format is more than two.AVAudioFormat
recommends usinginit(streamDescription:channelLayout:)
:This PR adds a method to create a layout for non mono/stereo audio formats. It also limits maximum number of output audio channels to two in
AudioCodecSettings
. Lastly, it adds a method that creates a channel mapping and provides it to the audio converter.I tested this change with mono, stereo and 4 channel audio. Mono and stereo fall back to the previous behavior. It's possible to use channel layout as well. However, I decided to fall back to the previous implementation instead this one:
What didn't work at all is to use custom channel descriptions:
Code
Every call of
AVAudioChannelLayout(layout: &channelLayout)
generatesAVAudioChannelLayout
instance with random number of channels. I wasn't able to find any combination ofmChannelLabel
to create a stable result. Ring buffer and converter end up having different audio formats which leads to a crash:required condition is false: [impl->_inputBufferReceived.format isEqual: impl->_inputFormat]
.Examples of random channel layouts
All instances of
AVAudioChannelLayout
was provided with the sameAudioChannelLayout
.AVAudioChannelLayout
attempts to make a conversion as states in the doc. Somehow it creates random layout every time:Example 1:
Example 2:
Example 3:
More discussion in this issue: #1262
Type of change
Please delete options that are not relevant.