Synthesizer Timing

The synthesizer works with two different systems of time:

  • Reference time

  • Sample time

Reference time is the absolute time (in master-clock units) at which a sequence of messages is to be played. In user-mode implementations, it is passed to the IDirectMusicSynth::PlayBuffer method when MIDI messages are fed to the synthesizer. The synthesizer, wave sink, and the rest of DirectMusic should all work under the same master clock, which is attached to the synthesizer by your implementation of the IDirectMusicSynth::SetMasterClock method and to the wave sink by IDirectMusicSynthSink::SetMasterClock.

Sample time is used to measure offsets into the synthesizer's output buffer. This buffer is filled with wave samples, so sample time is relative to the sampling rate. For example, at a sampling rate of 22.1 kHz, each second of time is equivalent to 22,100 samples or 44,200 bytes (in the case of a 16-bit mono format).

Because the playback of the wave sample buffer is likely to be controlled by a different timing crystal than the master clock, reference time and sample time tend to drift apart. The wave sink keeps them in step by implementing a phase-locked loop. This clock synchronization is described in Clock Synchronization.

This section also includes:

Synthesizer Latency

Time-Stamped Events