Metronome Filter Sample
|Microsoft DirectShow 9.0|
This sample filter shows how to implement a reference clock. The filter uses your default microphone input to listen for audio spikes (such as clicks, hand claps, or coughs), which it uses to determine a clock rate.
This sample is included with the Windows SDK. It is located under the following path: [SDK Root]\Samples\Multimedia\DirectShow\Filters\Metronome.
After building the filter, copy the filter DLL (Metronom.ax) to your Windows system directory. Run the Metronom.reg file to register the DLL.
To use the filter:
- Build a filter graph in GraphEdit that renders a video stream.
- Delete any rendered audio streams.
- Add the Metronome filter to the graph. It appears in the DirectShow Filters category.
- Run the graph. The video will begin playing at normal speed.
- Clap your hands or use a metronome to set a new speed.
This filter works only for video. The audio renderer is not capable of synchronizing to radically different clock rates.
If you clap 92 times per minute (once every ~652 ms), the video will play at the normal rate. You can change this default by changing the value of the constant BPM in Metronom.cpp.
If you stop clapping for a period of time and then start clapping again, you must start again at approximately the same speed, or the filter will ignore it. Also, the video playback rate is limited by the CPU speed. If you exceed the limit for any length of time, the filter will stop responding to rate changes. If this happens, stop the graph and restart.
If you implement your own clock, the most important rules is that reference clocks must not go backward. That is, they must never report a time value less than the previous time value.