title: Passing AudioQueueBufferRef data to FFT function!
body: <p>I am trying to compute the frequency of a given sound process through the microphone on the iphone.</p>
  
  <p>I've read all the post about FFT (including all apple code examples e.g aurioTouch,SpeakHere), but not solution to this problem.</p>
  
  <p>I'm using AudioQueue, but how do I to pass the raw data "AudioQueueBufferRef" from the AudioQueue callback function (MyInputBufferHandler) inBuffer->mAudioData . To the Actual FFT "DSPSplitComplex" datatype, so I can compute it. All this using the Accelerate framework.</p>
  
  <pre><code>// AudioQueue callback function, called when an input buffers has been filled.
  void AQRecorder::MyInputBufferHandler(  void      *                             inUserData,
                                       AudioQueueRef                      inAQ,
                                      AudioQueueBufferRef                 inBuffer,
                                      const AudioTimeStamp *              inStartTime,
                                      UInt32                              inNumPackets,
                                      const AudioStreamPacketDescription* inPacketDesc)
  {
  
   for(int i=0; i&lt;inNumPackets; i++) {
              printf("%d ",((int*)inBuffer-&gt;mAudioData)[i]);  
   }      
  }
  </code></pre>
  
  <p>The FFT function. </p>
  
  <pre><code>RealFFTUsageAndTiming(){
  
  COMPLEX_SPLIT   A; //DSPSplitComplex datatype 
  FFTSetup        setupReal;  
  uint32_t        log2n;  
  uint32_t        n, nOver2;  
  int32_t         stride; 
  uint32_t        i;  
  float          *originalReal, *obtainedReal;    
  float           scale;
  
  /* Set the size of FFT. */  
  log2n = N;  
  n = 1 &lt;&lt; log2n; 
  stride = 1; 
  nOver2 = n / 2;     
  
  /* Allocate memory for the input operands and check its availability,    
   * use the vector version to get 16-byte alignment. */
  
  A.realp = (float *) malloc(nOver2 * sizeof(float)); 
  A.imagp = (float *) malloc(nOver2 * sizeof(float)); 
  originalReal = (float *) malloc(n * sizeof(float)); 
  obtainedReal = (float *) malloc(n * sizeof(float));
  
  //How do I pass the data from AudioQueue callback to function?
  vDSP_fft_zrip(setupReal, &amp;A, stride, log2n, FFT_FORWARD);
  
  vDSP_fft_zrip(setupReal, &amp;A, stride, log2n, FFT_INVERSE);
  }
  </code></pre>
  
  <p>I haven't find anywhere on how to do this. Please help!</p>