From ceac394c2133d44e81db2eb633ff54a9ad6ce7c5 Mon Sep 17 00:00:00 2001 From: Hans-Christoph Steiner Date: Thu, 10 Nov 2005 05:52:11 +0000 Subject: This commit was generated by cvs2svn to compensate for changes in r3865, which included commits to RCS files with non-trunk default branches. svn path=/trunk/extensions/gripd/; revision=3866 --- src/midiio/include/SigTimer.h | 104 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 104 insertions(+) create mode 100644 src/midiio/include/SigTimer.h (limited to 'src/midiio/include/SigTimer.h') diff --git a/src/midiio/include/SigTimer.h b/src/midiio/include/SigTimer.h new file mode 100644 index 0000000..e93345c --- /dev/null +++ b/src/midiio/include/SigTimer.h @@ -0,0 +1,104 @@ +// +// Programmer: Craig Stuart Sapp +// Thanks to: Erik Neuenschwander +// for Windows 95 assembly code for Pentium clock cycles. +// Ozgur Izmirli +// for concept of periodic timer. +// Creation Date: Mon Oct 13 11:34:57 GMT-0800 1997 +// Last Modified: Tue Feb 10 21:05:19 GMT-0800 1998 +// Last Modified: Sat Sep 19 15:56:48 PDT 1998 +// Last Modified: Mon Feb 22 04:44:25 PST 1999 +// Last Modified: Sun Nov 28 12:39:39 PST 1999 (added adjustPeriod()) +// Filename: .../sig/code/control/SigTimer/SigTimer.h +// Web Address: http://www-ccrma.stanford.edu/~craig/improv/include/SigTimer.h +// Syntax: C++ +// +// Description: This class can only be used on Motorola Pentinum 75 Mhz +// chips or better because the timing information is +// extracted from the clock cycle count from a register +// on the CPU itself. This class will estimate the +// speed of the computer, but it would be better if there +// was a way of finding out the speed from some function. +// This class is used primarily for timing of MIDI input +// and output at a millisecond resolution. +// +// Interesting: http://www.datasilicon.nl/I786/timer_1.htm +// + +#ifndef _SIGTIMER_H_INCLUDED +#define _SIGTIMER_H_INCLUDED + + +#ifdef VISUAL + #include + typedef LONGLONG int64bits; +#else + typedef long long int int64bits; + #include /* for millisleep function */ +#endif + + +class SigTimer { + public: + SigTimer (void); + SigTimer (int aSpeed); + SigTimer (SigTimer& aTimer); + ~SigTimer (); + + void adjustPeriod (double periodDelta); + int expired (void) const; + double getPeriod (void) const; + double getPeriodCount (void) const; + double getTempo (void) const; + int getTicksPerSecond (void) const; + int getTime (void) const; + double getTimeInSeconds (void) const; + int getTimeInTicks (void) const; + void reset (void); + void setPeriod (double aPeriod); + void setTempo (double beatsPerMinute); + void setPeriodCount (double aCount); + void setTicksPerSecond (int aTickRate); + void start (void); + void sync (SigTimer& aTimer); + void update (void); + void update (int periodCount); + + // The following functions are semi-private. They do not have + // anything to do with timing themselves, but are a by-product + // of the timer implementation. They are useful, so they have + // been left public; however, they should be used judiciously. + static int getCpuSpeed (void); + static int measureCpuSpeed (int quantize = 0); + static void setCpuSpeed (int aSpeed); + + // the following function is hardware specific to Intel Pentium + // computers with a processor speed of at least 75 MHz. + // This function is the only non-portable function in this + // class, but everything else is based on it. + static int64bits clockCycles (void); + + protected: + static int64bits globalOffset; + static int cpuSpeed; + + int64bits offset; + int ticksPerSecond; + double period; + + // protected functions + double getFactor (void) const; + +}; + + +// The following function is mostly for Linux: +void millisleep(int milliseconds); +void millisleep(float milliseconds); + + +#endif /* _SIGTIMER_H_INCLUDED */ + + + +// md5sum: 601fa3caae4e3bacc4e6fb87f545c86b - SigTimer.h =css= 20030102 -- cgit v1.2.1