我正在使用目标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];
}
答案 0 :(得分:0)
音频样本位于项目的build文件夹中,但不在Xcode的“支持文件夹”中。问题解决了。