Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 7th, 2012  |  syntax: None  |  size: 1.97 KB  |  hits: 12  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. void AudioInputCallback(
  2.                                                 void *inUserData,
  3.                                                 AudioQueueRef inAQ,
  4.                                                 AudioQueueBufferRef inBuffer,
  5.                                                 const AudioTimeStamp *inStartTime,
  6.                                                 UInt32 inNumberPacketDescriptions,
  7.                                                 const AudioStreamPacketDescription *inPacketDescs)
  8. {
  9.         RecordState* recordState = (RecordState*)inUserData;
  10.     if(!recordState->recording)
  11.     {
  12.         printf("Not recording, returning\n");
  13.     }
  14.        
  15.     //if(inNumberPacketDescriptions == 0 && recordState->dataFormat.mBytesPerPacket != 0)
  16.     //{
  17.     //    inNumberPacketDescriptions = inBuffer->mAudioDataByteSize / recordState->dataFormat.mBytesPerPacket;
  18.     //}
  19.        
  20.    // NSLog("Writing buffer %d\n", recordState->currentPacket);
  21.     OSStatus status = AudioFileWritePackets(recordState->audioFile,                     // audio file we are writing too
  22.                                                                                         false,                                                  // dont want to cache the data
  23.                                                                                         inBuffer->mAudioDataByteSize,   // The number of bytes of audio data being written
  24.                                                                                         inPacketDescs,                                  // A pointer to an array of packet descriptions for the audio data. Not all formats require packet descriptions. If no packet descriptions are required, for instance, if you are writing CBR data, pass NULL.
  25.                                                                                         recordState->currentPacket,             // The packet index for the placement of the first provided packet.
  26.                                                                                         &inNumberPacketDescriptions,    // On input, a pointer to the number of packets to write. On output, a pointer to the number of packets actually written.
  27.                                                                                         inBuffer->mAudioData);                  // A pointer to user-allocated memory containing the new audio data to write to the audio data file.
  28.     if(status == 0)
  29.     {
  30.         recordState->currentPacket += inBuffer->mAudioDataByteSize;
  31.  
  32.                
  33.                 //i < inBuffer->mAudioDataByteSize
  34.                
  35.                 for(int i = 0; i<inBuffer->mAudioDataByteSize; i++){
  36.                        
  37.                         if(i % 44100 == 0)
  38.                         {
  39.                                 NSLog(@"\t Volume Level: %i ", ((UInt16*)(inBuffer->mAudioData))[i] );
  40.                         }
  41.                 }
  42.                
  43.     }
  44.        
  45.     AudioQueueEnqueueBuffer(recordState->queue, inBuffer, 0, NULL);
  46. }