Note that there are some explanatory texts on larger screens.

plurals
  1. POHow accurately (in terms of time) does Windows play audio?
    primarykey
    data
    text
    <p>Let's say I play a stereo WAV file with 317,520,000 samples, which is <em>theoretically</em> 1 hour long. Assuming no interruptions of the playback, will the file finish playing in <em>exactly</em> one hour, or is there some occasional tiny variation in the playback speed such that it would be slightly more or slightly less (by some number of milliseconds) than one hour?</p> <p>I am trying to synchronize animation with audio, and I am using a <code>System.Diagnostics.Stopwatch</code> to keep the frames matching the audio. But if the playback speed of WAV audio in Windows can vary slightly over time, then the audio will drift out of sync with the Stopwatch-driven animation.</p> <p>Which leads to a second question: it appears that a <code>Stopwatch</code> - while highly granular and accurate for short durations - runs slightly fast. On my laptop, a <code>Stopwatch</code> run for exactly 24 hours (as measured by the computer's system time and a real stopwatch) shows an elapsed time of 24 hours <em>plus</em> about 5 seconds (not milliseconds).</p> <p>Is this a known problem with <code>Stopwatch</code>? (A related question would be "am I crazy?", but you can try it for yourself.) Given its usage as a diagnostics tool, I can see where a discrepancy like this would only show up when measuring long durations, for which most people would use something other than a <code>Stopwatch</code>.</p> <p>If I'm really lucky, then both <code>Stopwatch</code> and audio playback are driven by the same underlying mechanism, and thus will stay in sync with each other for days on end. Any chance this is true?</p> <p><strong>Update</strong>: I just did the math, and if <code>Stopwatch</code> drifts by 5 seconds over 24 hours, this means it will drift by 10 milliseconds after just 172 seconds. So in 3 minutes the animation will start being perceptably out of sync.</p> <p>I'm experimenting with periodically (every 10 seconds or so) re-starting the timer from the waveOutWrite callback, but this isn't working because then the whole next set of timer events is offset by whatever the inaccuracy of the callback happened to be. Sucks to be me.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload