Re: Polling Callback, Threads [Attn: Michael Thornburgh]
Re: Polling Callback, Threads [Attn: Michael Thornburgh]
- Subject: Re: Polling Callback, Threads [Attn: Michael Thornburgh]
- From: Daniel Todd Currie <email@hidden>
- Date: Thu, 11 Dec 2003 16:21:51 -0800
So I've been working with MTCircularQueue for a couple hours now and I
have implemented the queue read as such:
- (void)runBufferDrain
{
unsigned byteCount = 1024 * sizeof(Float32);
Float32 *dspBuffer = malloc(byteCount);
while(1)
{
NSAutoreleasePool *drainPool = [[NSAutoreleasePool alloc] init];
[aQueue readBytesTo:dspBuffer length:byteCount];
NSData *floatDataObject = [NSData dataWithBytes:dspBuffer
length:byteCount];
[audioDelegate
performSelectorOnMainThread:@selector(processAudioBuffer:)
withObject:floatDataObject waitUntilDone:NO];
[drainPool release];
}
}
I have it running entirely in it's own thread, so the while loop should
not be significantly held up at any point.
The problem is that it is taking twice as long as it should to collect
the buffer. 512 samples / 44100 samples per second should be capturing
a buffer every 11.61 milliseconds. However, the while condition is
looping every 23 milliseconds. When I was sending the buffer out
directly from the callback using performSelectorOnMainThread, it was
indeed sending about every 11 milliseconds. My CoreAudio callback is
as follows (part of the Recorder class):
OSStatus recordIOProc(AudioDeviceID inDevice, const AudioTimeStamp*
inNow, const AudioBufferList* inInputData, const AudioTimeStamp*
inInputTime, AudioBufferList* outOutputData, const AudioTimeStamp*
inOutputTime, void* inClientData)
{
Recorder *client = (Recorder *)inClientData;
unsigned frameCount = (inInputData->mBuffers[0].mDataByteSize /
inInputData->mBuffers[0].mNumberChannels) / sizeof(Float32);
[client->aQueue writeBytesWithoutBlockingFrom:client->tempBuffer
length:(frameCount * sizeof(Float32))];
return kAudioHardwareNoError;
}
_______________________________________________
coreaudio-api mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/coreaudio-api
Do not post admin requests to the list. They will be ignored.