ios - iOS鼓音序器-缓冲区问题(错误访问)

标签 ios objective-c audio

我正在使用 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/

相关文章:

ios - 如何在 iOS 8/9 中获取今日扩展的宽度

ios - 我可以为正常应用程序提供免费订阅 IAP 吗?

audio - 将多个音频文件合并为一个文件

python - 在 Python 3 中读取 MP3

ios - 错误消息 "Parse Issue Expected identified or ‘(‘ "

java - 更改来自类的事件上的按钮

ios - 使用序列化程序时更改 json 输出

iphone - 在 iphone 中扫描这么多次后,条形码阅读器 View 出现两次?

iphone - 线程中的 CADisplayLink

ios - ImageView 和 UIButton