Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

jim93

macrumors newbie
Original poster
Jun 27, 2009
16
0
After playing with AVAudioPlayer I have decided to try to learn how use AudioQueue. I have figured out how to record and am trying to figure out how to push Audio data to an analysis class. I have written this callback to try to do this but I never get to the dump loop and the callback appears to not have access to the index and i variable in the for loop for some reason. Is it possible to dump this way?

Code:
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");
    }
	
	
	// kSampleRate*kSampleSize/8 = bytes of data per second
	double a = kSampleRate;int b = kSampleSize;
	int bSize = a*b/8;
	int secOfData = kSecondsUsed;
	int chunk = secOfData*bSize; 
	
	double in[chunk+1];

	
	if(recordState->dataCount == 0){
		printf("In Buffer Size is: %d\n", bSize);
	}
		
	if(recordState->dataCount > (chunk - 1)){
		DataDump *dump = new DataDump();
		dump->(in);
		double out = dump->doSomething();
		recordState->DoOut = out;
		recordState->dataCount = 0;
	}
    
	int i;
	int index;

	for (i = 0; i < bSize ; i+=2)
	{
		
		index = recordState->dataCount;		
		// Take data from Audio in and put into bit buffer
		char *buf = (char *) inBuffer->mAudioData;
		// Take into SInt16 
		SInt16 s = (buf[i] << 16) | (buf[i+1] << 8);
		// Normalize SInt16 to be between [-1,1]
		double t = ((double)s/32768)
		in[index+i] = t;
		in[i+1+index] = 0.0;

		recordState->dataCount =  index + 1;
	} 
	
    OSStatus status = AudioFileWritePackets(recordState->audioFile,
											false,
											inBuffer->mAudioDataByteSize,
											inPacketDescs,
											recordState->currentPacket,
											&inNumberPacketDescriptions,
											inBuffer->mAudioData);
    if(status == 0)
    {
        recordState->currentPacket += inNumberPacketDescriptions;
    }
	
    AudioQueueEnqueueBuffer(recordState->queue, inBuffer, 0, NULL);
}
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.