Re: AudioDevice playback time information?
Re: AudioDevice playback time information?
- Subject: Re: AudioDevice playback time information?
- From: Jeff Moore <email@hidden>
- Date: Fri, 23 May 2008 11:12:49 -0700
I'm not sure I understand the question. Getting the current time in
milliseconds, in what time frame? Since the device started? Since your
IOProc started? I can't remember what waveOutGetPosition uses for a
time frame, so I don't know what equivalent mechanism to refer you to.
Maybe you should explain a bit about what you are trying to do,
because this code doesn't make a whole lot of sense to me.
On May 23, 2008, at 7:38 AM, Vyacheslav Karamov wrote:
Is this code correct?
It assumes a lot.
static Float64 GetSampleRate()
{
UInt32 dataSize = sizeof(AudioStreamBasicDescription);
AudioStreamBasicDescription dataFormat;
BOOL err = AudioDeviceGetProperty(_s_info.device, 0, NO,
kAudioDevicePropertyStreamFormat, &dataSize, &dataFormat);
if (err) return 0;
return dataFormat.mSampleRate;
}
This is incorrect. It assumes that the device has an output stream.
Further, getting the stream format this way is essentially deprecated.
You should be getting it from the stream object itself.
But that's really beside the point since you should just use
kAudioDevicePropertyNominalSampleRate to get the sample rate directly.
//-----------------------------------------------------------------------
UInt64 SndGetCurrentPosition()
{
if (_s_info.is_playing != YES)
{
return 1;
}
AudioTimeStamp timeStamp;
OSStatus err = AudioDeviceGetCurrentTime( _s_info.device,
&timeStamp );
if (err)
return 2;
Float64 sampleRate = GetSampleRate();
if ( sampleRate < FLT_EPSILON )
{
return 0;
}
return timeStamp.mSampleTime * 1000 / sampleRate;
}
This will translate the sample time to a number of milliseconds as
judged against the nominal sample rate. I'm not sure what you would do
with that number. You certainly can't do any sort of real
synchronization with it as it won't match up with reality given that
it is rare to find a piece of hardware that really runs at it's
nominal sample rate. So, this number will differ from the true
position of the audio by the cumulative error of the device's true
sample rate vs. it's nominal rate.
In other words, this will be fine for very short durations, but it
will drift further and further out of synch the longer you run.
Vyacheslav Karamov пишет:
Hi All!
How to obtain correct Audio Device playback time information in
milliseconds?
I have found AudioDeviceGetCurrentTime() function, but I don't
understand how can I use it to retrieve current playback time.
P.S. In Windows its very easy
// Get playback position in milliseconds
DWORD CWinPlayer::GetPlaybackPositionMS()
{
MMTIME mm;
mm.wType = TIME_MS;
::waveOutGetPosition(m_hPlayDevice, &mm, sizeof(mm));
return mm.u.ms;
}
_______________________________________________
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
--
Jeff Moore
Core Audio
Apple
_______________________________________________
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