本文介绍了无法通过AVAudioEngine连接AVAudioUnitEffect的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在闲逛AVAudioEngine,但在集成AVAudioUnitEffect类时遇到了麻烦.例如,使用AVAudioUnitDelay ...

I've been poking around with AVAudioEngine and I'm having trouble integrating AVAudioUnitEffect classes. For example, with AVAudioUnitDelay...

@implementation ViewController {
AVAudioEngine *engine;
AVAudioPlayerNode *player;
}

...

- (IBAction)playButtonHit:(id)sender {
if (!player){
    NSURL *bandsURL = [[NSBundle mainBundle] URLForResource:@"Bands With Managers" withExtension:@"mp3"];
    AVAudioFile *file = [[AVAudioFile alloc] initForReading:bandsURL error:nil];

    engine = [[AVAudioEngine alloc] init];
    player = [[AVAudioPlayerNode alloc] init];
    [engine attachNode:player];

    AVAudioUnitDelay *delay = [[AVAudioUnitDelay alloc] init];
    delay.wetDryMix = 50;

    [engine connect:player to:delay format:file.processingFormat];
    [engine connect:delay to:[engine outputNode] format:file.processingFormat];

    [player scheduleFile:file atTime:nil completionHandler:nil];
    [engine prepare];
    [engine startAndReturnError:nil];
}
[player play];  

}

调用该方法时,应用程序崩溃,并且出现以下错误:" * 由于未捕获的异常'com.apple.coreaudio.avfaudio',终止应用程序,原因:'所需条件为假: [_nodes containsObject:node1]&& [_nodes containsObject:node2]'"

When the method is called the app crashes and I get this error: "* Terminating app due to uncaught exception 'com.apple.coreaudio.avfaudio', reason: 'required condition is false: [_nodes containsObject: node1] && [_nodes containsObject: node2]'"

在WWDC的"AVAudioEngine in Practice"会议中的一些示例之后,我对此进行了建模.我知道我可能遗漏了一些明显的东西,但无法弄清楚....

I'm modeling this after some of the examples from the "AVAudioEngine in Practice" session from WWDC. I know there's probably something obvious I'm missing but can't figure it out....

推荐答案

这不是AVAudioUnitEffect的问题!我用该代码尝试过

It is not a problem of the AVAudioUnitEffect! I tried it with that code

NSError *err = nil;

self.engine = [[AVAudioEngine alloc] init];
AVAudioPlayerNode *player = [[AVAudioPlayerNode alloc] init];
[self.engine attachNode:player];

NSURL *fileURL = [[NSBundle mainBundle] URLForResource:@"sound" withExtension:@"m4a"];
AVAudioFile *file = [[AVAudioFile alloc] initForReading:fileURL error:&err];

AVAudioMixerNode *mainMixer = [self.engine mainMixerNode];
[self.engine connect:player to:mainMixer format:file.processingFormat];

[player scheduleFile:file atTime:nil completionHandler:nil];

[self.engine startAndReturnError:&err];

if (err != nil) {
    NSLog(@"An error occured");
}

[player play];

self.engine是由

@property (nonatomic, strong) AVAudioEngine *engine;

我认为这是AVAudioEngine中的一个错误,因为它会导致内存泄漏:它开始播放第一个样本,然后由于内存使用过多而崩溃(在我的16 kB m4a文件中超过300 MB ).

I think that is a bug in AVAudioEngine, because it causes a memory leak: It starts playing the first samples and then it crashes because of heavy memory usage (more than 300 MB in my case of a 16 kB m4a file).

更新2014年12月7日:苹果使用iOS 8 Seed 3(内部版本12A4318c)修复了此问题!

Update 12/07/2014: Apple fixed this issue with iOS 8 Seed 3 (Build 12A4318c)!

这篇关于无法通过AVAudioEngine连接AVAudioUnitEffect的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-19 02:12