Skip to content

Commit

Permalink
Merge pull request #1379 from stream-labs/feature/channel-map-validation
Browse files Browse the repository at this point in the history
Validate audio channel map before applying
  • Loading branch information
shogo4405 authored Feb 16, 2024
2 parents 338b260 + 5b3018e commit 44770d6
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion Sources/IO/IOAudioResampler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ struct IOAudioResamplerSettings {
if converter.downmix != downmix {
converter.downmix = downmix
}
if let channelMap {
if let channelMap = validatedChannelMap(converter) {
converter.channelMap = channelMap
} else {
switch converter.outputFormat.channelCount {
Expand All @@ -60,6 +60,18 @@ struct IOAudioResamplerSettings {
interleaved: inputFormat.isInterleaved
)
}

private func validatedChannelMap(_ converter: AVAudioConverter) -> [NSNumber]? {
guard let channelMap, channelMap.count == converter.outputFormat.channelCount else {
return nil
}
for inputChannel in channelMap {
if inputChannel.intValue >= converter.inputFormat.channelCount {
return nil
}
}
return channelMap
}
}

final class IOAudioResampler<T: IOAudioResamplerDelegate> {
Expand Down

0 comments on commit 44770d6

Please sign in to comment.