SigTimer class public functions

SigTimer
~SigTimer
adjustPeriod
clockCycles
expired
getCpuSpeed
getPeriod
getPeriodCount
getTempo
getTicksPerSecond
getTime
getTimeInSeconds
getTimeInTicks
measureCpuSpeed
reset
setCpuSpeed
setPeriod
setPeriodCount
setTempo
setTicksPerSecond
start
sync
update

typedefs for int64bits:
  • in UNIX with Gnu C:
  • typedef long long int int64bits;
  • in Microsoft Windows:
  • typedef LONGLONG int64bits;


    SigTimer(void);
    Sets the ticks per second to 1000. Period is set to 1000.0 ticks. Takes 1/4 of a second to measure the CPU speed if very first instantiation of class in program.

    SigTimer(int aSpeed);
    Sets the CPU speed to aSpeed. Sets the ticks per second to 1000, and the period to 1000.0.

    SigTimer(SigTimer& aTimer);
    No description available.

    ~SigTimer();
    Does nothing

    void adjustPeriod(double periodDelta);
    No description available.

    int expired(void) const;
    Returns the number of periods which have expired (occured) since the timer was last reset or updated.

    double getPeriod(void) const;
    Returns the period length in terms of ticks per second. The period is used to count larger units of tickes. The expired function returns the number of periods which have occurred since the last reset or an update.

    double getPeriodCount(void) const;
    Returns the period count in terms of the number of periods since the starting position of the period pointer. This function is similar to the expired function which returns the number of periods which have occurred since the last reset or an update as a floating-point fractional period count.

    double getTempo(void) const;
    No description available.

    int getTicksPerSecond(void) const;
    Returns the number of ticks per second for the timer. The default is 1000 ticks per second, which is measurement in terms of milliseconds.

    int getTime(void) const;
    Equivalent to calling getTimeInTicks.

    double getTimeInSeconds(void) const;
    Returns the time in seconds since the last reset or update. The cpuSpeed must be correct for the time values to be accurate.

    int getTimeInTicks(void) const;
    Returns the time in ticks since the last reset. By default, returns the time in milliseconds. See the setTicksPerSecond function. Calls the clockCycles function for determining time. For absolute time accuracy, the value of cpuSpeed needs be properly set.

    void reset(void);
    Resets the timer to 0 ticks.

    void setPeriod(double aPeriod);
    Sets the period which is used for counting in the expired() function.

    void setTempo(double beatsPerMinute);
    Sets the period which is used for counting in the expired() function. Tempo is specified in beats per minute.

    void setPeriodCount(double aCount);
    No description available.

    void setTicksPerSecond(int aTickRate);
    Sets the number of ticks produced per second. If reset function is not called, then there will be a discontinuity in getTime values before and after the call to the setTicksPerSecond function because time in seconds since a reset will be used to calculate the number of ticks. If the default of 1000 ticks per second is used, the timer must be reset after 24.9 days of continuous running (assuming 200 MHz CPU clock rate). If ticks per second were 1,000,000, i.e., one microsecond resolution, then the maximum time before reset would be shortened to 36 minutes for a 200 MHz CPU.

    void start(void);
    Does the same thing as the reset function.

    void sync(SigTimer& aTimer);
    Synchronizes time zero in the timer with the specified input aTimer. The ticksPerSecond are left unchanged in both timers and must be equivalent to give identical timings with getTime function.

    void update(void);
    Increments the timer offset by one period.

    void update(int periodCount);
    Increments the timer offset by peroidCount periods.

    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);
    Returns the CPU speed of the computer which was previously set by the user or was measured automatically to an accuracy of about 5%.

    static int measureCpuSpeed(int quantize = 0);
    Returns the number of clock cycles in one second. Accuracy is approximately +/- 5%.

    static void setCpuSpeed(int aSpeed);
    Sets the CPU speed used to calculate time in the getTimeTicks and getTimeSeconds functions. You can also vary the CPU speed to cause the getTime function to output different units of time, but the setTicksPerSecond function is a more appropriate place to do such a thing. Warning: if you set the cpu speed of one Timer object, it will affect all other Timer objects.

    static int64bits clockCycles(void);
    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.

    Helper functions

    The following non-class functions are useful for uniform behaviour between various operating systems:
    void millisleep(int milliseconds);
    void millisleep(float milliseconds);