audioqueue audiotimestamp
audioqueue audiotimestamp
- Subject: audioqueue audiotimestamp
- From: Robert Carroll <email@hidden>
- Date: Sun, 1 Aug 2010 15:55:19 -0400
HI,
I'm having trouble getting my audioqueues to play back with timing
derived from audiotimestamps.
For simple testing purposes I have three audioqueues that need to play
either simultaneously, or at predetermined time intervals. The final
application needs considerably more complex timing options.
The buffer callback for the queues is:
-(void)audioQueue: (AudioQueueRef)inAQ processBuffer:
(AudioQueueBufferRef)inCompleteAQBuffer
{
if (mDone)
return;
UInt32 numBytes;
UInt32 nPackets = mNumPacketsToRead;
BOOL isDiscontinuous;
AudioTimeStamp outTimeStamp;
OSStatus err = AudioFileReadPackets(mAudioFile, false, &numBytes,
mPacketDescs, mPacketIndex, &nPackets, inCompleteAQBuffer->mAudioData);
if (err != noErr)
NSLog(@"Couldn't read into buffer");
if (nPackets > 0)
{
inCompleteAQBuffer->mAudioDataByteSize = numBytes;
err = AudioQueueEnqueueBufferWithParameters(inAQ,
inCompleteAQBuffer, (mPacketDescs ? nPackets : 0), mPacketDescs, 0, 0,
0, NULL, &aTimeStamp, NULL);
NSLog(@"buffercallback starttime is: %llu", aTimeStamp.mHostTime);
if (err != noErr)
NSLog(@"Couldn't enqueue buffer");
err = AudioQueueGetCurrentTime (inAQ, NULL, &outTimeStamp,
isDiscontinuous);
if (err != noErr)
NSLog(@"Couldn't get Current time");
UInt64 cTime = outTimeStamp.mHostTime;
//NSLog(@"buffercallback Currenttime is: %llu",
outTimeStamp.mHostTime);
NSLog(@"buffercallback Currenttime is: %llu", cTime);
mPacketIndex += nPackets;
//NSLog(@"The mPacketIndex is: %d", mPacketIndex);
}
else
{
UInt32 state = NO,
size = sizeof(UInt32);
OSStatus err = AudioQueueGetProperty(mQueue,
kAudioQueueProperty_IsRunning, &state, &size);
if (state)
{
err = AudioQueueStop(mQueue, false);
if (err != noErr)
NSLog(@"Couldn't stop queue");
}
mDone = true;
//[[NSNotificationCenter defaultCenter] postNotificationName:
@"playbackQueueStopped" object: self];
[self release]; /
}
}
The hostTime is obtained by getting an audioTimeStamp in the
applicationController object and then either handing that time
directly to the AudioQueueEnqueueBufferWithParameters call, or
calculating a series of later start times and then passing them to the
call.
NSLogging the requested starttimes verifies that the expected values
are being passed correctly, but calling AudioQueueGetCurrentTime and
logging the hostTime
retreives completely unrelated numbers. For example:
2010-08-01 15:33:41.119 Intervallogic[9127:10b] audioPlayerOne
requested starttime is: 160454591168220
2010-08-01 15:33:41.600 Intervallogic[9127:10b] buffercallback
starttime is: 160454591168220
2010-08-01 15:33:41.601 Intervallogic[9127:10b] buffercallback
Currenttime is: 5847924391114064
Shouldn't the hosttime be close to the same?
Any suggestions would be appreciated.
thanks,
Robert Carroll
RSM Records
Toronto
http://www.rsmrecords.com
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Coreaudio-api mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden