6

I'm writing my first audio app for Mac, which loads an external audio unit and uses it to play sound through an instance of AVAudioEngine, and I've been seeing this warning:

WARNING: 140: This application, or a library it uses, is using the deprecated Carbon Component Manager for hosting Audio Units. Support for this will be removed in a future release. Also, this makes the host incompatible with version 3 audio units. Please transition to the API's in AudioComponent.h.

I've already transitioned from using AVAudioUnitComponents to AudioComponents (now accessed via this api) which I expected would solve this issue, but I'm still seeing this warning when I call start() on my engine.

Any ideas what's going wrong here? As far as I can tell, I'm no longer using deprecated APIs. Is it possible that AVAudioEngine is using deprecated APIs under the hood?

Here's a snippet from the code I'm working with. I'm calling selectInstrument with a description I've retrieved using the AudioComponents API.

public func selectInstrument(withDescription description: AudioComponentDescription, callback: @escaping SelectInstrumentCallback) {
    AVAudioUnit.instantiate(with: description, options: []) { avAudioUnit, error in
        guard let unit = avAudioUnit else {
            callback(nil)
            return
        }

        self.disconnectCurrent()
        self.connect(unit: unit)

        unit.auAudioUnit.requestViewController { viewController in
            callback(viewController)
        }
    }
}

private func disconnectCurrent() {
    guard let current = currentInstrument else { return }
    self.engine.disconnectNodeInput(engine.mainMixerNode)
    self.engine.detach(current)
    self.currentInstrument = nil
    self.engine.stop()
}

private func connect(unit: AVAudioUnit) {
    let hardwareFormat = self.engine.outputNode.outputFormat(forBus: 0)
    self.engine.connect(self.engine.mainMixerNode, to: self.engine.outputNode, format: hardwareFormat)
    self.engine.attach(unit)
    do {
        try ExceptionCatcher.catchException {
            let stereoFormat = AVAudioFormat(standardFormatWithSampleRate: hardwareFormat.sampleRate, channels: 2)
            self.engine.connect(unit, to: self.engine.mainMixerNode, format: stereoFormat)
        }
    } catch {
        let monoFormat = AVAudioFormat(standardFormatWithSampleRate: hardwareFormat.sampleRate, channels: 1)
        self.engine.connect(unit, to: self.engine.mainMixerNode, format: monoFormat)
    }

    unit.auAudioUnit.contextName = "Running in AU host demo app"
    self.currentInstrument = unit

    do {
        // Carbon Component Manager warning issued here:
        try self.engine.start()
    } catch {
        print("Failed to start engine")
    }
}

Thanks for your help!

flatpickles
  • 2,198
  • 2
  • 15
  • 21

0 Answers0