gpt4 book ai didi

objective-c - 将 AVAudioUnitEffect 与 AVAudioEngine 连接时遇到问题

转载 作者:行者123 更新时间:2023-12-02 17:09:24 27 4
gpt4 key购买 nike

我一直在研究 AVAudioEngine,但在集成 AVAudioUnitEffect 类时遇到了问题。例如,使用 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]'"

我根据 WWDC 的“AVAudioEngine 实践” session 中的一些示例对此进行建模。我知道我可能遗漏了一些明显的东西,但无法弄清楚......

最佳答案

在链接它们之前,您忘记将 AvAudioUnitDelay 对象附加到 AvAudioEngine 节点;)

这是工作代码:

- (IBAction)playMusic:(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 attachNode:delay];

[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];
}

关于objective-c - 将 AVAudioUnitEffect 与 AVAudioEngine 连接时遇到问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24443863/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com