AVAudioEngine 在停止后连接 AVAudioUnitSampler 并再次启动崩溃
AVAudioEngine connect AVAudioUnitSampler after stop and start again crash
help, AVAudioEngine attach and connect a AVAudioUnitSampler play is ok.but 在调用 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)
}
help, AVAudioEngine attach and connect a AVAudioUnitSampler play is ok.but 在调用 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)
}