我正在使用 objective-c 制作一个8步鼓音序器。但是我将脚踢,军鼓和帽子样本加载到了缓冲区中,但是,当模拟器运行并且按下开关来切换脚鼓时,我得到了可怕的EXC_BAD_ACCESS错误,并且程序退出。
放入断点后,调试窗口将提示缓冲区中没有任何内容。但据我所知,它们在这里加载:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// laod the audio files into memory buffers
_kickBuffer = [PAEBuffer bufferNamed:@"TMD 09 KICK.aif"];
_snareBuffer = [PAEBuffer bufferNamed:@"TMD 09 SN 1.aif"];
_hihatBuffer = [PAEBuffer bufferNamed:@"TMD 09 CHH.aif"];
// initialise the host
_host = [PAEAudioHost audioHostWithNumOutputs:2];
// create some channel strips to play the audio
const int numVoices = 16;
NSMutableArray* channelStrips = [[NSMutableArray alloc] initWithCapacity:numVoices];
for (int i = 0; i < numVoices; ++i)
{
PAEChannelStrip* channelStrip = [PAEChannelStrip channelStripWithNumChannels:2];
[channelStrips addObject:channelStrip];
}
错误出现在此功能中
-(void)playBuffer:(PAEBuffer*)buffer
{
PAEBufferPlayer* player = [PAEBufferPlayer bufferPlayerWithBuffer:buffer];
player.loop = NO;
PAEChannelStrip* channelStrip = _channelStrips[_nextVoice];
channelStrip.input = player;
// we allocated voices in a round robin fashion, reallocating the oldest voices first
_nextVoice++;
if (_nextVoice >= _channelStrips.count)
_nextVoice = 0;
}
我是这门语言的新手,对不起,如果我还没有说清楚的话。谢谢您的任何帮助。
(编辑)添加了setStep函数
// the step has changed
-(void)setStep:(int)step
{
if (step < 0 || step >= NUMSTEPS)
return;
_step = step;
// decide which buffers to play on this step
if (_kickSteps[step])
[self playBuffer:_kickBuffer];
if (_snareSteps[step])
[self playBuffer:_snareBuffer];
if (_hihatSteps[step])
[self playBuffer:_hihatBuffer];
}
最佳答案
音频样本位于项目的build文件夹中,但不在Xcode的“支持文件文件夹”中。问题解决了。
关于ios - iOS鼓音序器-缓冲区问题(错误访问),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36651383/