2016-05-13 5 views
0

kAudioUnitType_MusicEffect AUをAVAudioEngineグラフに使用したいと思います。kAudioUnitType_MusicEffect as AVAudioUnit

[AVAudioUnitMIDIInstrument instantiateWithComponentDescription:desc options:kAudioComponentInstantiation_LoadInProcess completionHandler: 

が、それは普通のAVAudioUnitをyeildsので、MIDIセレクタ(のような - [AVAudioUnit sendMIDIEvent:data1:data2:]:)が認識されていない。だから私は、呼び出そう。 AVAudioUnitMIDIInstrument instantiateWithComponentDescriptionkAudioUnitType_MusicDeviceとしか動作していないようです。

これを行う方法はありますか? (注:OS X 10.11)

答えて

0

サブクラスを作成し、そのinitからinstantiateWithComponentDescriptionを呼び出します。

Goryの詳細とgithubのプロジェクトこのblog post

http://www.rockhoppertech.com/blog/multi-timbral-avaudiounitmidiinstrument/#avfoundation

にこれはスウィフトとkAudioUnitSubType_MIDISynthを使用していますが、あなたはそれを行う方法を見ることができます。

+0

サブクラス化がどのように役立つかわかりません。 'instantiateWithComponentDescription'を呼び出す必要があります。これは' kAudioUnitType_MusicEffect'では動作しません。 'kAudioUnitType_MusicDevice'に切り替えると、オーディオ入力に接続しようとするとアサーションエラーが発生します。 – Taylor

0

これは機能します。それはサブクラスです。エンジンに追加し、信号を経路指定します。

class MyAVAudioUnitDistortionEffect: AVAudioUnitEffect { 

override init() { 
    var description     = AudioComponentDescription() 
    description.componentType   = kAudioUnitType_Effect 
    description.componentSubType  = kAudioUnitSubType_Distortion 
    description.componentManufacturer = kAudioUnitManufacturer_Apple 
    description.componentFlags  = 0 
    description.componentFlagsMask = 0 
    super.init(audioComponentDescription: description) 
} 

func setFinalMix(finalMix:Float) { 

    let status = AudioUnitSetParameter(
     self.audioUnit, 
     AudioUnitPropertyID(kDistortionParam_FinalMix), 
     AudioUnitScope(kAudioUnitScope_Global), 
     0, 
     finalMix, 
     0) 

    if status != noErr { 
     print("error \(status)") 
    } 
}