man*_*an1 5 macos avfoundation audiounit ios avaudioengine
我正在为Mac编写我的第一个音频应用程序,它加载外部音频单元并使用它通过AVAudioEngine实例播放声音,我一直看到这个警告:
警告:140:此应用程序或其使用的库正在使用已弃用的Carbon Component Manager来托管Audio Units.将来的版本中将删除对此的支持.此外,这使主机与版本3音频单元不兼容.请转到AudioComponent.h中的API.
我已经从使用AVAudioUnitComponents转换到AudioComponents(现在通过这个api访问),我希望能解决这个问题,但是当我调用start()我的引擎时,我仍然会看到这个警告.
任何想法在这里出了什么问题?据我所知,我不再使用已弃用的API.AVAudioEngine是否有可能在引擎盖下使用已弃用的API?
这是我正在使用的代码的片段.我正在调用selectInstrument我使用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")
}
}
Run Code Online (Sandbox Code Playgroud)
谢谢你的帮助!
| 归档时间: |
|
| 查看次数: |
199 次 |
| 最近记录: |