Intermittent crash on soundInputPtr in ofxiPhoneSoundStream.m

Sometimes I get an EXC_BAD_ACCESS in the soundStream init code on my iPhone app. The offending line is in recordingCallback:

		if(soundInputPtr!=NULL) soundInputPtr->audioIn(tempBuffer, ioData->mBuffers[i].mDataByteSize/2, 1);  

My sound setup code:

ofSoundStreamSetup(0, 1, this, 44100, SAMPLES_PER_BUFFER, 4);  
  UInt32 audioRouteOverride = 0;     
  AudioSessionSetProperty ('ovrd', sizeof (audioRouteOverride), &audioRouteOverride);  

(The app uses no output and one channel of input— the “zero outputs” and override code are all trying to turn off echoing sound to the internal speaker, which has been an issue)

Strangely, the error happens only occasionally. Since it’s in the app launch cycle I can’t think of anything nondeterministic that might be happening. Anyone seen this or have an idea of what might be going on?

Note: the offending line was

if(OFSAptr!=NULL) OFSAptr->audioReceived(tempBuffer, ioData->mBuffers[i].mDataByteSize/2, 1);  

in pre-007.

And, it seems to be due to me calling ofSoundStreamSetup(0, 1. …) . One input = bad? Two inputs, good.

can you post a simple example w/ code that causes the crash? audio is running a separate thread, and it could be that you are doing something that is crashing based on threading. (ie, two threads manipulating the same data). Thread errors are timing related, and can vary from time to time depending on how things are being run, etc.

Hi Zach–

I solved it by checking the pointers at the start and end of the audio buffer before passing them to a pitch analysis function. I think audioIn was being called sometimes before the buffer was full of samples, and so the pointer to the end of the buffer was null:

void testApp::audioIn (float * input, int bufferSize, int nChannels){  
  if (input) {  
      for (int i = 0; i < bufferSize; i++) {  
      left[i] = input[i];  
    if (&left[0] && &left[bufferSize]) {  
      // PITCH  
      AA.input(&left[0], &left[bufferSize]);  
      Tone const * tone = AA.findTone();  
      if (tone) {  
           // ...  
    } // end boundary checking on buffer  
  } // end if (input)  

(But, P.S. Are there resources for learning about threads and thread-safety that you’d recommend? So far anything threaded is kind of a black box to me)

ickydog, threading came up recently and i posted some thoughts on what i understand. there is some great input from arturo + zach too

Sweet, thanks! Will check it out now.