
Untitled
By: a guest on
May 7th, 2012 | syntax:
None | size: 1.97 KB | hits: 12 | expires: Never
void AudioInputCallback(
void *inUserData,
AudioQueueRef inAQ,
AudioQueueBufferRef inBuffer,
const AudioTimeStamp *inStartTime,
UInt32 inNumberPacketDescriptions,
const AudioStreamPacketDescription *inPacketDescs)
{
RecordState* recordState = (RecordState*)inUserData;
if(!recordState->recording)
{
printf("Not recording, returning\n");
}
//if(inNumberPacketDescriptions == 0 && recordState->dataFormat.mBytesPerPacket != 0)
//{
// inNumberPacketDescriptions = inBuffer->mAudioDataByteSize / recordState->dataFormat.mBytesPerPacket;
//}
// NSLog("Writing buffer %d\n", recordState->currentPacket);
OSStatus status = AudioFileWritePackets(recordState->audioFile, // audio file we are writing too
false, // dont want to cache the data
inBuffer->mAudioDataByteSize, // The number of bytes of audio data being written
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.
recordState->currentPacket, // The packet index for the placement of the first provided packet.
&inNumberPacketDescriptions, // On input, a pointer to the number of packets to write. On output, a pointer to the number of packets actually written.
inBuffer->mAudioData); // A pointer to user-allocated memory containing the new audio data to write to the audio data file.
if(status == 0)
{
recordState->currentPacket += inBuffer->mAudioDataByteSize;
//i < inBuffer->mAudioDataByteSize
for(int i = 0; i<inBuffer->mAudioDataByteSize; i++){
if(i % 44100 == 0)
{
NSLog(@"\t Volume Level: %i ", ((UInt16*)(inBuffer->mAudioData))[i] );
}
}
}
AudioQueueEnqueueBuffer(recordState->queue, inBuffer, 0, NULL);
}