Documentation Archive Developer
Search

ADC Home > Reference Library > Technical Q&As > QuickTime > Movie Creation >

Sequence Grabber - Ensuring the SG TimeBase is being driven by the Sound Clock.


Q: When using the Sequence Grabber to capture audio and video is there a way to make sure the time base used by the Video Channel is being driven by the Sound Clock? This doesn't appear to be the case by default.

A: Yes, this is not necessarily true by default.

NOTE:

While this behaviour is current as of QuickTime 6.4 it may change in a future version of QuickTime.

The Sequence Grabber creates a time base which is assigned the default clock (the Microseconds Clock), and this time base is passed to the Video Digitizer. The Sound Channel counts audio samples from the Sound Input Device and relies on the Video Digitizer to supply the matching timestamps. The time base used by the Sound Channel however is driven by the Sound Clock, and if these two clocks diverge you may get drift.

To minimize jitter or synchronization problems, the time base used by the Sequence Grabber can be assigned the Clock which is driving the Sound Channel's time base. Listing 1 demonstrates how an application can set this up.

IMPORTANT:

SGPrepare must be called before calling SGGetChannelTimeBase; otherwise, the Sound Channel's TimeBase will not be initialized.


Listing 1. Ensuring the sound clock is driving the SG TimeBase.

{
  TimeBase soundTimeBase = NULL, sgTimeBase = NULL;

  // get the TimeBase being used by the Sequence Grabber
  err = SGGetTimeBase(sg, &sgTimeBase);
  if(noErr == err) {
    // get the TimeBase being used by the Sound Channel
     err = SGGetChannelTimeBase(soundChannel, &soundTimeBase);
  }
  if ((noErr == err) && (NULL != soundTimeBase)) {
    // get the sound clock and assign it to the TimeBase being used by the
    // Sequence Grabber ensuring a single clock driving both the audio
    // and video TimeBase
    SetTimeBaseMasterClock(sgTimeBase,
                (Component)GetTimeBaseMasterClock(soundTimeBase), NULL);
  }
}


References:


[Oct 24, 2003]