I'm quite new to AudioKit so forgive me in advance. What I'm trying to do is an app that applies a chains of audio effects. Let's say I have a file audio (or the mic or both):
The thread is in this line:
engine.output = stereoOutputMixer
Here the init of the class I wrote:
var audioFilePlayer: AudioPlayer?
class AudioProcessor: ObservableObject {
var engine: AudioEngine
var mic: AudioEngine.InputNode!
var mixer: Mixer
var equalizer1: Equalizer
var equalizer2: Equalizer
var amplitudeTap: AmplitudeTap?
var threshold: Float = 40.0
var equalizer1Mixer: Mixer
var equalizer2Mixer: Mixer
var leftPanner: Panner
var rightPanner: Panner
var leftPannerMixer: Mixer
var rightPannerMixer: Mixer
var stereoOutputMixer: Mixer
var delay1: Delay
var delay2: Delay
var highPassFilter: HighPassFilter
var lowPassFilter: LowPassFilter
var leftVolumeMixer: Mixer
var rightVolumeMixer: Mixer
var micMixer: Mixer
var fileMixer: Mixer
var leftOutputPanner: Panner
var rightOutputPanner: Panner
var isAboveThreshold: Bool = false
var preferences: UserPreferences
init(preferences: UserPreferences = UserPreferences()) {
// First, initialize all properties
self.preferences = preferences
self.engine = AudioEngine()
self.mixer = Mixer()
// Initialize equalizers with default frequencies
let frequencies: [Double] = [125, 250, 500, 750, 1000, 1500, 2000, 3000, 4000, 6000, 8000]
self.equalizer1 = Equalizer(engine: engine, input: mixer, frequencies: frequencies)
self.equalizer2 = Equalizer(engine: engine, input: mixer, frequencies: frequencies)
self.delay1 = Delay(equalizer1.output)
self.delay1.time = preferences.delay1Time
self.delay2 = Delay(equalizer2.output)
self.delay2.time = preferences.delay2Time
self.threshold = preferences.threshold // Initialize threshold
self.highPassFilter = HighPassFilter(mixer, cutoffFrequency: preferences.highPassFilterFrequency, resonance: 1)
self.lowPassFilter = LowPassFilter(mixer, cutoffFrequency: preferences.lowPassFilterFrequency, resonance: 1)
self.leftPanner = Panner(mixer, pan: -1)
self.rightPanner = Panner(mixer, pan: 1)
self.leftOutputPanner = Panner(equalizer1.output, pan: -1)
self.rightOutputPanner = Panner(equalizer2.output, pan: 1)
self.leftVolumeMixer = Mixer()
self.rightVolumeMixer = Mixer()
self.stereoOutputMixer = Mixer()
self.micMixer = Mixer()
self.fileMixer = Mixer()
self.isAboveThreshold = false
self.amplitudeTap = nil
// Now that all properties are initialized, call methods to set up the audio chain
// Initialize mixers for each equalizer
equalizer1Mixer = Mixer()
equalizer2Mixer = Mixer()
// Initialize panners and their mixers
leftPannerMixer = Mixer()
rightPannerMixer = Mixer()
setupDelays()
setupFilters()
setupPanners()
setupVolumeControlMixers()
setupMicAndFileMixers()
applyEqualizerGains(preferences: preferences)
setVolumeBalance(leftVolume: preferences.balanceVolumeLeft, rightVolume: preferences.balanceVolumeRight)
setMicPlaybackBalance(micVolume: preferences.micGain, playbackVolume: preferences.playbackVolume)
if preferences.micEnabled {
setupMicrophone()
}
startEngine()
setupInitialAudioChain()
setupAmplitudeMonitoring()
checkAmplitudeAndApplyDelays()
applyDelaysAndSwitchEqualizers()
engine.output = stereoOutputMixer
}
You are calling startEngine()
which presumably contains engine.start()
before setting the engine's output. i.e engine.output = stereoOutputMixer
Also make sure that you have added the inputs to the stereoOutputMixer
. Use engine.connectionTreeDescription
to view the engine's output tree.