Re: iPhone OS 3.0 and AudioQueueStart
Re: iPhone OS 3.0 and AudioQueueStart
- Subject: Re: iPhone OS 3.0 and AudioQueueStart
- From: bill luoma <email@hidden>
- Date: Wed, 24 Jun 2009 16:57:18 -0700
Hi Nunzio,
I've noticed the same behavior in 3.0 GM.
I filed a bug on iphone OS beta 4 and 5.
Bug ID# 6879952.
One way I've found around this problem
is to call AudioQueueStart(q, NULL);
then prime the buffers by manually invoking the callback.
On the first prime, create a timestamp
and set mFlags = kAudioTimeStampSampleTimeValid,
and convert your future mach_absolute_time to sample time
then pass that timestamp in to
AudioQueueEnqueueBuffersWithParameters.
It seems to have more latency than the simple method that works in 2.x.
The way I convert future host time to future sample time
is with a call to AudioQueueGetCurrentTime and then some math
that Bill and Doug posted a while back on syncing two audio queues.
- (OSStatus)hostTime:(UInt64)hostTime toQueueSampleTime:(AudioTimeStamp*)tsIn
{
AudioTimeStamp t1 = {0};
int i = 0;
OSStatus err = -1;
do {
err = AudioQueueGetCurrentTime(audioQueue, NULL, &t1, NULL);
} while (err && i++ < MAX_HOST_TO_QUEUE_LOOP);
if (err || t1.mSampleTime > 100000.0) {
[self hostTime:hostTime toSampleTime:tsIn];
}
else {
if (t1.mHostTime > hostTime)
{
tsIn->mSampleTime = t1.mSampleTime;
}
else
{
tsIn->mSampleTime = t1.mSampleTime +
(((hostTime - t1.mHostTime) / timeUtils.hostFrequency *
AudioFormat.mSampleRate) * t1.mRateScalar);
}
tsIn->mFlags = kAudioTimeStampSampleTimeValid;
}
return err;
}
The call to AudioQueueGetCurrentTime is prone to error, especially in
the simulator, when called right after AudioQueueStart, or so I've
found, so I call it a few times if it fails.
I've probably got the math a bit wrong (not exactly sure how to factor
in the rate scalar) ((help)). But I'm able to sync with it. To my ear
tho, it's not as accurate as calling AudioQueueStart with a timestamp
on 2.x.
What I haven't tried yet on 3.0 is just passing in the future host
time with mFlags = kAudioTimeStampHostTimeValid to
AudioQueueEnqueueBuffersWithParameters.
Bill Luoma
>Message: 9
>Date: Wed, 24 Jun 2009 11:00:02 +0200
>From: Nunzio <email@hidden>
>Subject: iPhone OS 3.0 and AudioQueueStart
>To: email@hidden
>Message-ID: <email@hidden>
>Content-Type: text/plain; charset=US-ASCII; format=flowed; delsp=yes
>
>Hello,
>
>I noticed that in the final release of iPhone OS 3.0, AudioQueueStart
>on a playback queue continues to ignore the audiotimestamp passed to
>it. I thought that this was a bug in the beta version of the OS, but
>even in the final it's still there. Is there a solution to this? My
>app works fine in 2.2, but not in 3.0, and everything is done as the
>documentation states. Does the audiotimestamp have to be set
>differently in OS 3.0?
>Thanks,
>Nunzio
_______________________________________________
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