Let's say I play a stereo WAV file with 317,520,000 samples, which theoretically is 1 hour. Assuming that interruptions in playback will not be interrupted, will there be a file playback in exactly one hour or will there be any slight variations in playback speed, so that it will be slightly larger or slightly less (by several milliseconds) than by one hour?
I am trying to synchronize the animation with audio, and I am using System.Diagnostics.Stopwatch to save frames corresponding to the sound. But if the playback speed of WAV audio in Windows may vary slightly over time, the sound will go out of sync with the animation controlled by the stopwatch.
This leads to a second question: it seems that a Stopwatch - while very narrow and precise for short durations - works a little fast. On my laptop, a Stopwatch run for exactly 24 hours (measured by the time of a computer system and a real stopwatch) shows the elapsed time of 24 hours plus about 5 seconds (not milliseconds).
Is this a known issue with Stopwatch ? (A related question will be βAm I crazy?β, But you can try it for yourself.) Given its use as a diagnostic tool, I see where such a mismatch will only be displayed when measuring long durations for which most people will use what something other than Stopwatch .
If I'm really lucky, then Stopwatch and sound playback are controlled by the same basic mechanism and, thus, will remain in sync with each other for several days in a row. Is any chance right?
Update . I just did the math, and if Stopwatch drifts for 5 seconds in 24 hours, it means that it will drift for 10 milliseconds in 172 seconds. Thus, after 3 minutes, the animation will noticeably not synchronize.
I experiment periodically (every 10 seconds or so) starts the timer again from the waveOutWrite callback, but this does not work, because then the whole next set of timer events is compensated by whatever callback error happened. Sucks for me.
Musigenesis
source share