annotate osdep/timer-win.c @ 10125:252428ac7978

Added support for AAC.
author mosu
date Sat, 17 May 2003 20:53:12 +0000
parents 2d703cd325ee
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
9765
2d703cd325ee high precision timer for windows patch by Frodo <csharprules at hotmail.com>
faust3
parents:
diff changeset
1 #include <stdio.h>
2d703cd325ee high precision timer for windows patch by Frodo <csharprules at hotmail.com>
faust3
parents:
diff changeset
2 #include <stdlib.h>
2d703cd325ee high precision timer for windows patch by Frodo <csharprules at hotmail.com>
faust3
parents:
diff changeset
3 #include <windows.h>
2d703cd325ee high precision timer for windows patch by Frodo <csharprules at hotmail.com>
faust3
parents:
diff changeset
4 #include <mmsystem.h>
2d703cd325ee high precision timer for windows patch by Frodo <csharprules at hotmail.com>
faust3
parents:
diff changeset
5 #include <sys/time.h>
2d703cd325ee high precision timer for windows patch by Frodo <csharprules at hotmail.com>
faust3
parents:
diff changeset
6
2d703cd325ee high precision timer for windows patch by Frodo <csharprules at hotmail.com>
faust3
parents:
diff changeset
7 static LARGE_INTEGER qwTimerFrequency;
2d703cd325ee high precision timer for windows patch by Frodo <csharprules at hotmail.com>
faust3
parents:
diff changeset
8 static LARGE_INTEGER qwTimerStart;
2d703cd325ee high precision timer for windows patch by Frodo <csharprules at hotmail.com>
faust3
parents:
diff changeset
9 static LARGE_INTEGER m_lStartTime;
2d703cd325ee high precision timer for windows patch by Frodo <csharprules at hotmail.com>
faust3
parents:
diff changeset
10 static float m_fuSecsPerTick;
2d703cd325ee high precision timer for windows patch by Frodo <csharprules at hotmail.com>
faust3
parents:
diff changeset
11 static unsigned long RelativeTime = 0;
2d703cd325ee high precision timer for windows patch by Frodo <csharprules at hotmail.com>
faust3
parents:
diff changeset
12
2d703cd325ee high precision timer for windows patch by Frodo <csharprules at hotmail.com>
faust3
parents:
diff changeset
13 int usec_sleep(int usec_delay)
2d703cd325ee high precision timer for windows patch by Frodo <csharprules at hotmail.com>
faust3
parents:
diff changeset
14 {
2d703cd325ee high precision timer for windows patch by Frodo <csharprules at hotmail.com>
faust3
parents:
diff changeset
15 LARGE_INTEGER qwStartTicks, qwCurrTicks;
2d703cd325ee high precision timer for windows patch by Frodo <csharprules at hotmail.com>
faust3
parents:
diff changeset
16 double dResult;
2d703cd325ee high precision timer for windows patch by Frodo <csharprules at hotmail.com>
faust3
parents:
diff changeset
17 long lTick;
2d703cd325ee high precision timer for windows patch by Frodo <csharprules at hotmail.com>
faust3
parents:
diff changeset
18 double fuSecDelay = ((float) usec_delay) / 1000000.0;
2d703cd325ee high precision timer for windows patch by Frodo <csharprules at hotmail.com>
faust3
parents:
diff changeset
19
2d703cd325ee high precision timer for windows patch by Frodo <csharprules at hotmail.com>
faust3
parents:
diff changeset
20 QueryPerformanceCounter(&qwStartTicks);
2d703cd325ee high precision timer for windows patch by Frodo <csharprules at hotmail.com>
faust3
parents:
diff changeset
21 do {
2d703cd325ee high precision timer for windows patch by Frodo <csharprules at hotmail.com>
faust3
parents:
diff changeset
22 QueryPerformanceCounter(&qwCurrTicks);
2d703cd325ee high precision timer for windows patch by Frodo <csharprules at hotmail.com>
faust3
parents:
diff changeset
23 dResult =
2d703cd325ee high precision timer for windows patch by Frodo <csharprules at hotmail.com>
faust3
parents:
diff changeset
24 ((double) (qwCurrTicks.QuadPart - qwStartTicks.QuadPart)) /
2d703cd325ee high precision timer for windows patch by Frodo <csharprules at hotmail.com>
faust3
parents:
diff changeset
25 ((double) (qwTimerFrequency.QuadPart));
2d703cd325ee high precision timer for windows patch by Frodo <csharprules at hotmail.com>
faust3
parents:
diff changeset
26 } while (dResult < fuSecDelay);
2d703cd325ee high precision timer for windows patch by Frodo <csharprules at hotmail.com>
faust3
parents:
diff changeset
27 }
2d703cd325ee high precision timer for windows patch by Frodo <csharprules at hotmail.com>
faust3
parents:
diff changeset
28
2d703cd325ee high precision timer for windows patch by Frodo <csharprules at hotmail.com>
faust3
parents:
diff changeset
29 // Returns current time in microseconds
2d703cd325ee high precision timer for windows patch by Frodo <csharprules at hotmail.com>
faust3
parents:
diff changeset
30 unsigned long GetTimer()
2d703cd325ee high precision timer for windows patch by Frodo <csharprules at hotmail.com>
faust3
parents:
diff changeset
31 {
2d703cd325ee high precision timer for windows patch by Frodo <csharprules at hotmail.com>
faust3
parents:
diff changeset
32 LARGE_INTEGER qwTime;
2d703cd325ee high precision timer for windows patch by Frodo <csharprules at hotmail.com>
faust3
parents:
diff changeset
33 FLOAT fTime;
2d703cd325ee high precision timer for windows patch by Frodo <csharprules at hotmail.com>
faust3
parents:
diff changeset
34 UINT64 uiQuadPart;
2d703cd325ee high precision timer for windows patch by Frodo <csharprules at hotmail.com>
faust3
parents:
diff changeset
35
2d703cd325ee high precision timer for windows patch by Frodo <csharprules at hotmail.com>
faust3
parents:
diff changeset
36 QueryPerformanceCounter(&qwTime);
2d703cd325ee high precision timer for windows patch by Frodo <csharprules at hotmail.com>
faust3
parents:
diff changeset
37 qwTime.QuadPart -= m_lStartTime.QuadPart;
2d703cd325ee high precision timer for windows patch by Frodo <csharprules at hotmail.com>
faust3
parents:
diff changeset
38 uiQuadPart = (UINT64) qwTime.QuadPart;
2d703cd325ee high precision timer for windows patch by Frodo <csharprules at hotmail.com>
faust3
parents:
diff changeset
39 uiQuadPart /= ((UINT64) 10); // prevent overflow after 4294.1 secs, now overflows after 42941 secs
2d703cd325ee high precision timer for windows patch by Frodo <csharprules at hotmail.com>
faust3
parents:
diff changeset
40 fTime = ((FLOAT) (uiQuadPart)) / m_fuSecsPerTick;
2d703cd325ee high precision timer for windows patch by Frodo <csharprules at hotmail.com>
faust3
parents:
diff changeset
41 return (unsigned long) fTime;
2d703cd325ee high precision timer for windows patch by Frodo <csharprules at hotmail.com>
faust3
parents:
diff changeset
42 }
2d703cd325ee high precision timer for windows patch by Frodo <csharprules at hotmail.com>
faust3
parents:
diff changeset
43
2d703cd325ee high precision timer for windows patch by Frodo <csharprules at hotmail.com>
faust3
parents:
diff changeset
44 // Returns current time in microseconds
2d703cd325ee high precision timer for windows patch by Frodo <csharprules at hotmail.com>
faust3
parents:
diff changeset
45 float GetRelativeTime()
2d703cd325ee high precision timer for windows patch by Frodo <csharprules at hotmail.com>
faust3
parents:
diff changeset
46 {
2d703cd325ee high precision timer for windows patch by Frodo <csharprules at hotmail.com>
faust3
parents:
diff changeset
47 unsigned long t, r;
2d703cd325ee high precision timer for windows patch by Frodo <csharprules at hotmail.com>
faust3
parents:
diff changeset
48
2d703cd325ee high precision timer for windows patch by Frodo <csharprules at hotmail.com>
faust3
parents:
diff changeset
49 t = GetTimer();
2d703cd325ee high precision timer for windows patch by Frodo <csharprules at hotmail.com>
faust3
parents:
diff changeset
50 r = t - RelativeTime;
2d703cd325ee high precision timer for windows patch by Frodo <csharprules at hotmail.com>
faust3
parents:
diff changeset
51 RelativeTime = t;
2d703cd325ee high precision timer for windows patch by Frodo <csharprules at hotmail.com>
faust3
parents:
diff changeset
52 return (float) r *0.000001F;
2d703cd325ee high precision timer for windows patch by Frodo <csharprules at hotmail.com>
faust3
parents:
diff changeset
53 }
2d703cd325ee high precision timer for windows patch by Frodo <csharprules at hotmail.com>
faust3
parents:
diff changeset
54
2d703cd325ee high precision timer for windows patch by Frodo <csharprules at hotmail.com>
faust3
parents:
diff changeset
55 // Returns current time in milliseconds
2d703cd325ee high precision timer for windows patch by Frodo <csharprules at hotmail.com>
faust3
parents:
diff changeset
56 unsigned int GetTimerMS()
2d703cd325ee high precision timer for windows patch by Frodo <csharprules at hotmail.com>
faust3
parents:
diff changeset
57 {
2d703cd325ee high precision timer for windows patch by Frodo <csharprules at hotmail.com>
faust3
parents:
diff changeset
58 return GetTimer() / 1000;
2d703cd325ee high precision timer for windows patch by Frodo <csharprules at hotmail.com>
faust3
parents:
diff changeset
59 }
2d703cd325ee high precision timer for windows patch by Frodo <csharprules at hotmail.com>
faust3
parents:
diff changeset
60
2d703cd325ee high precision timer for windows patch by Frodo <csharprules at hotmail.com>
faust3
parents:
diff changeset
61 void InitTimer()
2d703cd325ee high precision timer for windows patch by Frodo <csharprules at hotmail.com>
faust3
parents:
diff changeset
62 {
2d703cd325ee high precision timer for windows patch by Frodo <csharprules at hotmail.com>
faust3
parents:
diff changeset
63 FLOAT t;
2d703cd325ee high precision timer for windows patch by Frodo <csharprules at hotmail.com>
faust3
parents:
diff changeset
64
2d703cd325ee high precision timer for windows patch by Frodo <csharprules at hotmail.com>
faust3
parents:
diff changeset
65 QueryPerformanceFrequency(&qwTimerFrequency); // ticks/sec
2d703cd325ee high precision timer for windows patch by Frodo <csharprules at hotmail.com>
faust3
parents:
diff changeset
66 m_fuSecsPerTick = (FLOAT) (((FLOAT) (qwTimerFrequency.QuadPart)) / 1000.0); // tics/msec
2d703cd325ee high precision timer for windows patch by Frodo <csharprules at hotmail.com>
faust3
parents:
diff changeset
67 m_fuSecsPerTick = (FLOAT) (m_fuSecsPerTick / 1000.0); // ticks/usec
2d703cd325ee high precision timer for windows patch by Frodo <csharprules at hotmail.com>
faust3
parents:
diff changeset
68 m_fuSecsPerTick /= 10.0;
2d703cd325ee high precision timer for windows patch by Frodo <csharprules at hotmail.com>
faust3
parents:
diff changeset
69 QueryPerformanceCounter(&m_lStartTime);
2d703cd325ee high precision timer for windows patch by Frodo <csharprules at hotmail.com>
faust3
parents:
diff changeset
70 t = GetRelativeTime();
2d703cd325ee high precision timer for windows patch by Frodo <csharprules at hotmail.com>
faust3
parents:
diff changeset
71 }