ios - 停止后,AVAudioEngine连接AVAudioUnitSampler,然后再次启动崩溃

标签 ios objective-c++

帮助,AVAudioEngine附加并连接AVAudioUnitSampler可以正常播放。但是在调用AVAudioEngine并再次启动后,播放时崩溃。
我的代码像:

    self.engine=[[AVAudioEngine alloc] init];
    self.sampler= [AVAudioUnitSampler new];
    NSError *error=nil;

    NSURL soundfontFileURL = [[NSURL alloc] initFileURLWithPath:[[NSBundle mainBundle] pathForResource:@"test" ofType:@"sf2"]];

    [_sampler loadSoundBankInstrumentAtURL:soundfontFileURL program:0 bankMSB:0x79 bankLSB:0 error:&error];
    [self.engine attachNode:_sampler];
    [self.engine connect:_sampler to:[self.engine outputNode] format:nil];


    if([self.engine startAndReturnError:&error]){

            NSLog(@"start ok ");
    }else{

      NSLog(@"start err: %@",error);
    }

    //play at here is ok.
    //[_sampler startNote:60 withVelocity:100 onChannel:0];
    [self.engine stop];

    if([self.engine startAndReturnError:&error]){

            NSLog(@"start ok ");
    }else{

      NSLog(@"start err: %@",error);
    }

   //after stop and start again,play crash AudioStreamerImpl::sIOWorkerProcess (17)
   [_sampler startNote:60 withVelocity:100 onChannel:0];


崩溃信息:
libEmbeddedSystemAUs.dylib`DLSSample::GetMoreFrames:
AudioStreamerImpl::sIOWorkerProcess(17):EXC_BAD_ACCESS(代码= 1,地址= 0x701c943f1a0)

最佳答案

我的应用程序中存在这样的问题已有几个月了。
经过一些测试,在启动引擎和弹奏音符之间重新加载SoundFont时,似乎没有出现崩溃。

    engine.stop()
    do {
        try engine.start()
        reloadSoundFont() // remove this, and there will be the crash with GetMoreFrames()
    } catch {
        print("Could not start engine: " + error.localizedDescription)
    }

    self.sampler.startNote(60, withVelocity: 100, onChannel: 0)

    delay(1.0) {
        self.sampler.stopNote(60, onChannel: 0)
    }

关于ios - 停止后,AVAudioEngine连接AVAudioUnitSampler,然后再次启动崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59402729/

相关文章:

ios - Mac Catalyst中的弃用警告,但仅在Objective-C中,而不在Swift中

c++ - objective-c 方法中的 std::vector

c++ - 在 Objective-C 代码中使用带有 C++ 实例变量的 Objective-C++ 类

objective-c - Objective-C++ 中的字符串

iphone - 查找所有 .nib 并从路径中提取资源

iphone - 无法在 ios 中创建 sqlite3 数据库

objective-c - objective-c - 局部静态变量初始化线程安全吗?

ios - 从 C++ 类继承 NSObject

ios - 无法将自定义颜色设置为导航栏项目 iOS Swift

ios - UITableView 部分标题与 64 位 iPad 上的行重叠。在 32 位上工作正常