-
-
Notifications
You must be signed in to change notification settings - Fork 626
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1420 from shogo4405/feature/IOSingleAudioMixer
Add an ON/OFF switch for the multi-track audio mixing feature.
- Loading branch information
Showing
7 changed files
with
125 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import AVFoundation | ||
import Foundation | ||
|
||
final class IOAudioMixerConvertibleBySingleTrack: IOAudioMixerConvertible { | ||
var delegate: (any IOAudioMixerDelegate)? | ||
var inputFormat: AVAudioFormat? | ||
var settings: IOAudioMixerSettings = .init() | ||
|
||
private lazy var resampler: IOAudioResampler<IOAudioMixerConvertibleBySingleTrack> = { | ||
var resampler = IOAudioResampler<IOAudioMixerConvertibleBySingleTrack>() | ||
resampler.delegate = self | ||
return resampler | ||
}() | ||
|
||
func append(_ buffer: CMSampleBuffer, track: UInt8) { | ||
guard settings.mainTrack == track else { | ||
return | ||
} | ||
resampler.append(buffer) | ||
} | ||
|
||
func append(_ buffer: AVAudioPCMBuffer, when: AVAudioTime, track: UInt8) { | ||
guard settings.mainTrack == track else { | ||
return | ||
} | ||
resampler.append(buffer, when: when) | ||
} | ||
} | ||
|
||
extension IOAudioMixerConvertibleBySingleTrack: IOAudioResamplerDelegate { | ||
// MARK: IOAudioResamplerDelegate | ||
func resampler(_ resampler: IOAudioResampler<IOAudioMixerConvertibleBySingleTrack>, didOutput audioFormat: AVAudioFormat) { | ||
delegate?.audioMixer(self, didOutput: audioFormat) | ||
} | ||
|
||
func resampler(_ resampler: IOAudioResampler<IOAudioMixerConvertibleBySingleTrack>, didOutput audioPCMBuffer: AVAudioPCMBuffer, when: AVAudioTime) { | ||
delegate?.audioMixer(self, didOutput: audioPCMBuffer, when: when) | ||
} | ||
|
||
func resampler(_ resampler: IOAudioResampler<IOAudioMixerConvertibleBySingleTrack>, errorOccurred error: IOAudioUnitError) { | ||
delegate?.audioMixer(self, errorOccurred: error) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import Foundation | ||
|
||
/// The util object to get feature flag info. | ||
public enum FeatureUtil { | ||
/// A structure that defines the name of a feature. | ||
public struct Name: RawRepresentable, ExpressibleByStringLiteral { | ||
// swiftlint:disable:next nesting | ||
public typealias RawValue = String | ||
// swiftlint:disable:next nesting | ||
public typealias StringLiteralType = String | ||
|
||
/// This is a feature to mix multiple audio tracks. For example, it is possible to mix .appAudio and .micAudio from ReplayKit. | ||
public static let multiTrackMixing: Name = "multiTrackMixing" | ||
|
||
/// The raw type value. | ||
public let rawValue: String | ||
|
||
/// Create a feature name by rawValue. | ||
public init(rawValue: String) { | ||
self.rawValue = rawValue | ||
} | ||
|
||
/// Create a feature name by stringLiteral. | ||
public init(stringLiteral value: String) { | ||
self.rawValue = value | ||
} | ||
} | ||
|
||
private static var flags: [String: Bool] = [:] | ||
|
||
/// Whether or not a flag is enabled. | ||
public static func isEnabled(feature: Name) -> Bool { | ||
return flags[feature.rawValue] ?? false | ||
} | ||
|
||
/// Setter for a feature flag. | ||
public static func setEnabled( | ||
feature: Name, | ||
isEnabled: Bool | ||
) { | ||
flags[feature.rawValue] = isEnabled | ||
} | ||
} |