Re: SampleTime
Re: SampleTime
- Subject: Re: SampleTime
- From: Jeff Moore <email@hidden>
- Date: Thu, 13 Dec 2001 11:25:07 -0800
on 12/13/01 8:04 AM, Jim Dolan <email@hidden> wrote:
>
Could someone please give me a good description of how an AudioTimeStamp is
>
used.
At the moment, the HAL will only return you the sample time and the host
time in the time stamp. They represent the _same_ point in time, but use two
different ways of measuring that point.
AudioDeviceGetCurrentTime() will return the time stamp that represents where
the device currently is in time. It is the same sort of value you get from
the inNow parameter to your IOProc.
Because you are sharing the device with other folks on the system, you
cannot and should not depend in any way on the absolute values in the time
stamps. Instead, you should take an "anchor" point and call it your local
zero point. From there you use relative offsets from that anchor point to
measure things.
BTW, the current implementation of the HAL will never give you a 0 value for
the sample time. It starts it's own internal counters off at a different
value that makes it's math a little more efficient. And even if it did start
with 0, you would never see it since it will be covered by the start up
overhead of the IOThread (which is just a normal thread until it gets into
it's work loop).
>
If I ask the device for the current time before I start it will give me some
>
large number for mSampleTime.
This is illegal! In my test code, AudioDeviceGetCurrentTime() returns an
error unless the device is already running. I quote from the header
documentation in <CoreAudio/AudioHardware.h>:
//==========================================================================
// Time Management
//
// Note that time operations are only valid while the device in question
// is running. Otherwise, a kAudioHardwareNotRunningError will be returned.
//==========================================================================
Most likely the value you are getting back is garbage since the HAL won't
write to the time stamp struct you pass in unless the device is running (as
defined by kAudioDevicePropertyDeviceIsRunning).
>
I call AudioDeviceStart and before the first IOProc I get a completely
>
different number - something close to zero.
Your code is flat out wrong. So you are getting the expected results.
--
Jeff Moore
Core Audio
Apple