/[svn]/linuxsampler/trunk/src/common/RTMath.cpp
ViewVC logotype

Diff of /linuxsampler/trunk/src/common/RTMath.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 2941 by schoenebeck, Tue May 29 23:59:36 2007 UTC revision 2942 by schoenebeck, Wed Jul 13 15:51:06 2016 UTC
# Line 23  Line 23 
23    
24  #include "RTMath.h"  #include "RTMath.h"
25    
26    // for unsafeMicroSeconds() implementation
27    #if !defined(WIN32) && !defined(__APPLE__)
28    # include <time.h>
29    #endif
30    
31  static float CentsToFreqTable[CONFIG_MAX_PITCH * 1200 * 2 + 1]; // +-1200 cents per octave  static float CentsToFreqTable[CONFIG_MAX_PITCH * 1200 * 2 + 1]; // +-1200 cents per octave
32    
33  float* RTMathBase::pCentsToFreqTable(InitCentsToFreqTable());  float* RTMathBase::pCentsToFreqTable(InitCentsToFreqTable());
# Line 77  RTMathBase::time_stamp_t RTMathBase::Cre Line 82  RTMathBase::time_stamp_t RTMathBase::Cre
82      #endif      #endif
83  }  }
84    
85    RTMathBase::usecs_t RTMathBase::unsafeMicroSeconds(clock_source_t source) {
86        #if defined(WIN32)
87        LARGE_INTEGER t;
88        LARGE_INTEGER f;
89        QueryPerformanceCounter(&t);
90        if (!QueryPerformanceFrequency(&f)) return 0;
91        return usecs_t( double(t) / double(f) * 1000000.0 );
92        #elif defined(__APPLE__)
93        static mach_timebase_info_data_t tb;
94        double t = mach_absolute_time();
95        // if this method is run for the first time, get the internal time base
96        if (!tb.denom) mach_timebase_info(&tb); // get nanoseconds per tick
97        // convert from internal (abstract) time value to microseconds
98        return usecs_t( t * double(tb.numer) / double(tb.denom) / 1000.0 );
99        #else
100        timespec t;
101        clockid_t cid;
102        switch (source) {
103            case process_clock: cid = CLOCK_PROCESS_CPUTIME_ID; break;
104            case thread_clock:  cid = CLOCK_THREAD_CPUTIME_ID; break;
105            case real_clock:    cid = CLOCK_MONOTONIC; break;
106            default:            return 0;
107        }
108        clock_gettime(cid, &t);
109        return usecs_t( (double(t.tv_sec) * 1000000000.0 + double(t.tv_nsec)) / 1000.0 );
110        #endif
111    }
112    
113  /**  /**
114   * Will automatically be called once to initialize the 'Cents to frequency   * Will automatically be called once to initialize the 'Cents to frequency
115   * ratio' table.   * ratio' table.

Legend:
Removed from v.2941  
changed lines
  Added in v.2942

  ViewVC Help
Powered by ViewVC