Re: Input callback timestamp reset and current sample time
Re: Input callback timestamp reset and current sample time
- Subject: Re: Input callback timestamp reset and current sample time
- From: <email@hidden>
- Date: Thu, 29 Sep 2005 15:37:41 -0700
> It sounds like you have things somewhat confused. The time stamps the
> HAL passes to an IOProc are generated with the same code that does
> the translations in AudioDeviceTranslateTime() and calculates the
> current time in AudioDeviceGetCurrentTime(). So, they are all
> internally coherent and provide the same figures. It is not possible
> for them to disagree.
It's quite likely that I'm just confused about the way CoreAudio
works. I'm very new to it (last week was the first time I've ever
looked at CoreAudio). Here's an example of the input callback:
static OSStatus
MyAudioCallBack(
void * inRefCon,
AudioUnitRenderActionFlags inActionFlags,
const AudioTimeStamp * inTimeStamp,
UInt32 inBusNumber,
AudioBuffer * ioData )
{
OSStatus err;
UInt32 size;
AudioDeviceID deviceID;
AudioTimeStamp deviceTime;
AudioTimeStamp currentTime;
size = sizeof( deviceID );
err = AudioUnitGetProperty( context->outputUnit,
kAudioOutputUnitProperty_CurrentDevice,
kAudioUnitScope_Global, 0, &deviceID, &size );
check_noerr( err ); // note: noErr is returned
deviceTime.mFlags = kAudioTimeStampSampleTimeValid;
err = AudioDeviceTranslateTime( deviceID, inTimeStamp, &deviceTime );
check_noerr( err ); // note: noErr is returned
err = AudioDeviceGetCurrentTime( deviceID, ¤tTime );
check_noerr( err ); // note: noErr is returned
printf( "Input Time: %f\n", inTimeStamp->mSampleTime );
printf( "Device Time: %f\n", deviceTime.mSampleTime );
printf( "Current Time: %f\n", currentTime.mSampleTime );
...
}
This initially returns timestamps that are what I would expect and
things work fine:
Input Time: 196608.000000
Device Time: 196608.000000
Current Time: 200836.000000 (expected difference since it takes some time
to get the current device time)
But, if I plug in headphones while playing, I start to get numbers like these:
Input Time: 2046190.000000
Device Time: 2046190.000000
Current Time: 59343.000000
The device appears to restarts it timestamps to zero, but
AudioDeviceTranslateTime is still returning the AUHAL's time. The
problem is that now when I call AudioDeviceGetCurrentTime outside of
the callback (to see what sample is currently being played), I get
this new restarted timeline instead of the converted time from the
input callback.
> Now I know you're confused because the input time stamps are always
> in the past.
Here's an example of where I see the input timestamp in the future:
static OSStatus
MyAudioCallBack(
void * inRefCon,
AudioUnitRenderActionFlags inActionFlags,
const AudioTimeStamp * inTimeStamp,
UInt32 inBusNumber,
AudioBuffer * ioData )
{
UInt64 hostTime;
hostTime = AudioGetCurrentHostTime();
printf( "Input Time: %llu\n", inTimeStamp->mHostTime );
printf( "Host Time: %llu\n", hostTime );
...
}
This prints:
Input Time: 482979140557
Host Time: 482976032634
482979140557 - 482976032634 = 3107923 @ 33331840 Hz = ~4111 samples
(similar delta on each subsequent callback).
If I change kAudioDevicePropertyBufferFrameSize from 4096 to 2048, I
see mHostTime is about 2063 samples ahead (buffer size + ~340
microseconds of delay in getting the current time). This is what lead
me to believe that the input timestamp is about one buffer's worth of
time ahead of the current host time.
_______________________________________________
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