• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Host Time epoch
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Host Time epoch


  • Subject: Re: Host Time epoch
  • From: Steve Checkoway <email@hidden>
  • Date: Thu, 10 Feb 2005 12:38:19 -0800

On Feb 10, 2005, at 12:21 PM, John Iversen wrote:
Sorry, I'm not aware of this issue, but it's of interest to me, and is rather fundamental. Would you mind elaborating? What is the nature of the non-monotonicity--I can't imagine you mean actual reversals in the host time, I hope. Instead, do you mean that the rate of increase of the HostTime is variable, so it drifts away from 'real time'? How large is the effect in your experience?

Oh no. I mean non-monotonicity. Time does indeed move backward. I filed a bug report quite a while ago and I was told (eventually) that it was fixed in some later version of the OS.

To take a concrete example: Given that MIDITimeStamps are based on 'HostTime' (right?), are you saying that if midi events are received in at exactly 1 sec intervals the increases in Host time (as seen in the MIDITimeStamp of incoming packets) would not be identical (give or take some small margin of error)? If that's really the case, I don't see how any sequencer could possibly work reliably and not show tempo drift, so I may not be getting the drift of what you're talking about here.

I'm really no expert on this and I've never done anything with midi so I can't answer that.

Here's the code to duplicate the bug:

#include "CAAudioHardwareSystem.h"
#include "CAAudioHardwareDevice.h"
#include "CAAudioHardwareStream.h"
#include "CAStreamBasicDescription.h"
#include "CAException.h"

CAAudioHardwareDevice *OutputDevice;

OSStatus GetData(AudioDeviceID inDevice, const AudioTimeStamp *inNow,
const AudioBufferList *inInputData,
const AudioTimeStamp *inInputTime,
AudioBufferList *outOutputData,
const AudioTimeStamp *inOutputTime, void *inClientData)
{
AudioBuffer& buf = outOutputData->mBuffers[0];

memset( buf.mData, 0, buf.mDataByteSize );

return noErr;
}

OSStatus OverloadListener(AudioDeviceID inDevice, UInt32 inChannel,
Boolean isInput, AudioDevicePropertyID inPropertyID,
void *inData)
{
printf( "overload\n");
return noErr;
}

void start()
{
try
{
AudioDeviceID dID = CAAudioHardwareSystem::GetDefaultDevice(false, false);
OutputDevice = new CAAudioHardwareDevice(dID);
}
catch (const CAException& e)
{
throw "Couldn't create default output device.";
}

AudioStreamID sID;

sID = OutputDevice->GetStreamByIndex( kAudioDeviceSectionOutput, 0 );
CAAudioHardwareStream stream( sID );

try
{
OutputDevice->AddPropertyListener(kAudioPropertyWildcardChannel,
kAudioPropertyWildcardSection,
kAudioDeviceProcessorOverload,
OverloadListener, NULL);
} catch (const CAException& e)
{
printf("Could not install the overload listener.\n");
}

const CAStreamBasicDescription CanonicalFormat(44100.0, kAudioFormatLinearPCM,
8, 1, 8, 2, 32,
kAudioFormatFlagsNativeFloatPacked);

stream.SetCurrentIOProcFormat(CanonicalFormat);

try
{
OutputDevice->AddIOProc(GetData, NULL);
OutputDevice->StartIOProc(GetData);
}
catch(const CAException& e)
{
printf("Couldn't start the IOProc.\n");
}
}

int main(int argc, char* argv[])
{
start();

double last = 0;
while(1)
{
AudioTimeStamp time;

try
{
OutputDevice->GetCurrentTime(time);
if ((time.mFlags & kAudioTimeStampSampleTimeValid) !=
kAudioTimeStampSampleTimeValid)
{
puts("Time stamp not valid.");
}

if (time.mSampleTime < last)
printf("%f < %f\n", time.mSampleTime, last);
last = time.mSampleTime;
}
catch (const CAException& e)
{
unsigned error = e.GetError();
printf("err: '%4.4s'\n", (char *)&error);
}
}

return 0;
}


I compiled it (it was called bug.cpp) with:
$ g++ -framework CoreAudio bug.cpp -I /Developer/Examples/CoreAudio/PublicUtility /Developer/Examples/CoreAudio/PublicUtility/CAAudioHardware*.cpp /Developer/Examples/CoreAudio/PublicUtility/ CAStreamBasicDescription.cpp -framework CoreFoundation
$ ./a.out
err: 'stop'
71451259.000000 < 71451260.000000
71468667.000000 < 71468668.000000
71516284.000000 < 71532668.000000
71630972.000000 < 71647356.000000
71647356.000000 < 71663740.000000
71680124.000000 < 71696508.000000
71712892.000000 < 71729276.000000
71762044.000000 < 71778428.000000
71778428.000000 < 71794812.000000
71958652.000000 < 71975036.000000

There should not be any output except for maybe the err: 'stop' while it is still setting up but successive calls are producing times that are not monotonic.

- Steve

_______________________________________________
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
  • Follow-Ups:
    • Re: Host Time epoch
      • From: Herbie Robinson <email@hidden>
    • Re: Host Time epoch
      • From: Shawn Erickson <email@hidden>
References: 
 >Host Time epoch (From: Geoff Schmidt <email@hidden>)
 >Re: Host Time epoch (From: Jeff Moore <email@hidden>)
 >Re: Host Time epoch (From: Steve Checkoway <email@hidden>)
 >Re: Host Time epoch (From: John Iversen <email@hidden>)

  • Prev by Date: Re: Host Time epoch
  • Next by Date: Re: Host Time epoch
  • Previous by thread: Re: Host Time epoch
  • Next by thread: Re: Host Time epoch
  • Index(es):
    • Date
    • Thread