2016-04-15 48 views
0

我正在使用目標C製作一個8步鼓音序器。我將kick,snare和帽子樣本加載到緩衝區中,但是,當模擬器運行並按下開關時切換一個踢鼓,我得到一個可怕的EXC_BAD_ACCESS錯誤,程序退出。iOS鼓音序器 - 緩衝區問題(訪問不良)

放入斷點後,調試窗口顯示緩衝區中沒有任何東西。但據我所知,他們在這裏裝:出現在此功能

-(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; 
} 

我是新來這個的langauge很抱歉,如果我還沒有做出明確的一切

- (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]; 
    } 

錯誤。任何幫助都非常appriciated,謝謝。

(編輯)新增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

緩衝區被傳遞給playBuffer:nil嗎? – JAL

+0

是的,在調試窗口中它說這個播放器\t PAEBufferPlayer * \t無\t 0x0000000000000000 – Neo

+0

你在哪裏調用'playBuffer'? – JAL

回答

0

音頻樣品在該項目的生成文件夾,但不是在Xcode中「支持文件夾」。問題解決了。