Add Pieter Palmers FreeBob driver.
[jack2.git] / common / JackTime.c
blobdbbf6063208517e3e74a7645c1a2791137c1d104
1 /*
2 Copyright (C) 2001-2003 Paul Davis
3 Copyright (C) 2004-2006 Grame
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 #include "JackTime.h"
22 #include "JackError.h"
24 #ifdef __APPLE__
26 double __jack_time_ratio;
28 /* This should only be called ONCE per process. */
29 void InitTime()
31 JackLog("InitTime\n");
32 mach_timebase_info_data_t info;
33 mach_timebase_info(&info);
34 __jack_time_ratio = ((float)info.numer / info.denom) / 1000;
37 #endif
39 #ifdef WIN32
41 EXPORT LARGE_INTEGER _jack_freq;
43 void InitTime()
45 QueryPerformanceFrequency(&_jack_freq);
46 JackLog("InitTime freq = %ld %ld\n", _jack_freq.HighPart, _jack_freq.LowPart);
47 _jack_freq.QuadPart = _jack_freq.QuadPart / 1000000; // by usec
50 jack_time_t GetMicroSeconds(void)
52 LARGE_INTEGER t1;
53 QueryPerformanceCounter (&t1);
54 return (jack_time_t)(((double)t1.QuadPart)/((double)_jack_freq.QuadPart));
57 // TODO
58 #endif
60 #ifdef linux
62 #ifdef GETCYCLE_TIME
64 #include <stdio.h>
65 jack_time_t GetMhz(void)
67 FILE *f = fopen("/proc/cpuinfo", "r");
68 if (f == 0)
70 perror("can't open /proc/cpuinfo\n");
71 exit(1);
74 for ( ; ; )
76 jack_time_t mhz;
77 int ret;
78 char buf[1000];
80 if (fgets(buf, sizeof(buf), f) == NULL) {
81 jack_error ("FATAL: cannot locate cpu MHz in "
82 "/proc/cpuinfo\n");
83 exit(1);
86 #if defined(__powerpc__)
87 ret = sscanf(buf, "clock\t: %" SCNu64 "MHz", &mhz);
88 #elif defined( __i386__ ) || defined (__hppa__) || defined (__ia64__) || \
89 defined(__x86_64__)
90 ret = sscanf(buf, "cpu MHz : %" SCNu64, &mhz);
91 #elif defined( __sparc__ )
92 ret = sscanf(buf, "Cpu0Bogo : %" SCNu64, &mhz);
93 #elif defined( __mc68000__ )
94 ret = sscanf(buf, "Clocking: %" SCNu64, &mhz);
95 #elif defined( __s390__ )
96 ret = sscanf(buf, "bogomips per cpu: %" SCNu64, &mhz);
97 #else /* MIPS, ARM, alpha */
98 ret = sscanf(buf, "BogoMIPS : %" SCNu64, &mhz);
99 #endif
100 if (ret == 1)
102 fclose(f);
103 return (jack_time_t)mhz;
108 jack_time_t __jack_cpu_mhz;
110 void InitTime()
112 __jack_cpu_mhz = GetMhz();
115 #else
116 void InitTime()
119 #endif
121 #endif