2016-11-12 18 views
3

AVAudioUnitをインスタンス化する方法はこれですので:AVAudioUnitをサブクラス化するにはどうすればいいですか?

[AVAudioUnit instantiateWithComponentDescription:componentDescription options:0 completionHandler:^(__kindof AVAudioUnit * _Nullable audioUnit, NSError * _Nullable error) { 
    }]; 

は、どのように私はAVAudioUnitをサブクラス化することが出来るのですか?私はこれを試してみました:

[MySubclassOfAVAudioUnit instantiateWithComponentDescription:componentDescription options:0 completionHandler:^(__kindof AVAudioUnit * _Nullable audioUnit, NSError * _Nullable error) { 
    }]; 

しかし、ブロックに返されaudioUnitMySubclassOfAVAudioUnitタイプAVAudioUnitのままですとNOT。


毎のリズムFistmanの応答、私はAppleのサンプルコードで私のカスタムAUAudioUnitサブクラスを登録しています:

componentDescription.componentType = kAudioUnitType_Effect; 
componentDescription.componentSubType = 0x666c7472; /*'fltr'*/ 
componentDescription.componentManufacturer = 0x44656d6f; /*'Demo'*/ 
componentDescription.componentFlags = 0; 
componentDescription.componentFlagsMask = 0; 

私は私のAVAudioUnitサブクラスはいつも私のAUAudioUnitを使用します。

+0

私の答えが間違っていたことに気付きました。あなたは 'AUAudioUnit'をサブクラス化して正しいタイプの' AVAudioUnit'サブクラスにラップさせることができます。私の更新された答えを見てください。 –

答えて

3

instantiateWithComponentDescription:completionHandler:から返さAVAudioUnitインスタンスは、通常、サブクラス(AVAudioUnitEffect、 AVAudioUnitGenerator、AVAudioUnitMIDIInstrument、又はAVAudioUnitTimeEffect)からなり、コンポーネントの種類に応じ を選択しました。

UPDATE 私はこの間違って持って - あなたは、関連するビルトインAVFoundation AVAudioUnitサブクラス(例えばAVAudioUnitEffect、など)に包まれた、あなただけのAUAudioUnitをインスタンス化することができ、あなた自身のAVAudioUnitサブクラスをインスタンス化することはできません。

次のコードでは、インスタンス化するAUAudioUnitのサブクラス、MyAUAudioUnitが発生します。

#import <AVFoundation/AVFoundation.h> 

@interface MyAUAudioUnit : AUAudioUnit { 

} 
@end 

@implementation MyAUAudioUnit 
    // implement it here 
@end 

// later 
- (void)instantiateMyAUAudioUnitWrappedInAVAudioUnit { 
    // register it (need only be done once) 
    AudioComponentDescription desc; 
    desc.componentType = kAudioUnitType_Effect; 
    desc.componentSubType = 0x666c7472; /*'fltr'*/ 
    desc.componentManufacturer = 0x44656d6f; /*'Demo'*/ 
    desc.componentFlags = 0; 
    desc.componentFlagsMask = 0; 

    [AUAudioUnit registerSubclass:MyAUAudioUnit.class asComponentDescription:desc name:@"MyAU" version:1]; 

    // Instantiate as many times as you like: 
    [AVAudioUnit instantiateWithComponentDescription:desc options:0 completionHandler:^(AVAudioUnit * audioUnit, NSError *error) { 
     NSLog(@"AVAudioUnit: %@, error: %@", audioUnit, error); 
    }]; 
} 

WRONG BIT

だからあなたAVAudioUnitサブクラスをインスタンス持っている、あなたが最初にAUAudioUnitに登録する必要があります方法:

+[AUAudioUnit registerSubclass:asComponentDescription:name:version:]

this devforum threadにコードスニペットといくつかの可能性があります。

+0

迅速な対応に感謝します。私は正確にその手順に従ったが、instantiateWithComponentDescriptionは決して私のサブクラスのインスタンスを返すことはありません。ディスカッションスレッドは、残念ながらこの問題に対処していないようです。私は質問にもう少し詳細を追加します。 – user1021430

+0

'registerSubclass'の呼び出し方法を表示できますか?あなたの 'AUAudioUnit'サブクラスのいくつかを表示するかもしれませんか? –

+0

OPがこれを理解したかどうかを知りたいのはちょっと不思議です。私はまったく同じ問題を抱えています。 – GWRodriguez

関連する問題