author | mickeyl <mickeyl> | 2003-09-27 11:29:26 (UTC) |
---|---|---|
committer | mickeyl <mickeyl> | 2003-09-27 11:29:26 (UTC) |
commit | 651b6c612db4e809c506973996f2580c4158ac3a (patch) (unidiff) | |
tree | 8c8edc86e4b206dd4542a6b556ad1a319d6698ab /inputmethods/dasher/FrameRate.h | |
parent | d1a11b45e805fe7771ea05944757d767c3c4c8ea (diff) | |
download | opie-651b6c612db4e809c506973996f2580c4158ac3a.zip opie-651b6c612db4e809c506973996f2580c4158ac3a.tar.gz opie-651b6c612db4e809c506973996f2580c4158ac3a.tar.bz2 |
merge dasher which has been introduced in BRANCH first (wtf?) into HEAD
Diffstat (limited to 'inputmethods/dasher/FrameRate.h') (more/less context) (ignore whitespace changes)
-rw-r--r-- | inputmethods/dasher/FrameRate.h | 112 |
1 files changed, 112 insertions, 0 deletions
diff --git a/inputmethods/dasher/FrameRate.h b/inputmethods/dasher/FrameRate.h new file mode 100644 index 0000000..2f86b03 --- a/dev/null +++ b/inputmethods/dasher/FrameRate.h | |||
@@ -0,0 +1,112 @@ | |||
1 | // FrameRate.h | ||
2 | // | ||
3 | ///////////////////////////////////////////////////////////////////////////// | ||
4 | // | ||
5 | // Copyright (c) 2002 David Ward | ||
6 | // | ||
7 | ///////////////////////////////////////////////////////////////////////////// | ||
8 | |||
9 | #ifndef __FrameRate_h__ | ||
10 | #define __FrameRate_h__ | ||
11 | |||
12 | #include "MSVC_Unannoy.h" | ||
13 | |||
14 | // keeps track of framerate | ||
15 | // computes the Steps parameter | ||
16 | // computes RXmax - which controls the maximum rate of zooming in | ||
17 | |||
18 | const double LN2= log(2); | ||
19 | |||
20 | class CFrameRate { | ||
21 | public: | ||
22 | CFrameRate() ; | ||
23 | ~CFrameRate() {}; | ||
24 | const double Rxmax() const {return m_dRXmax;} | ||
25 | const int Steps() const {return m_iSteps;} | ||
26 | const double Framerate() const {return m_dFr;} | ||
27 | void Reset(unsigned long Time); | ||
28 | void NewFrame(unsigned long Time); | ||
29 | |||
30 | // TODO: These two shouldn't be the same thing: | ||
31 | void SetBitrate(double TargetRate); | ||
32 | void SetMaxBitrate(double MaxRate); | ||
33 | private: | ||
34 | double m_dFr; | ||
35 | double m_dMaxbitrate; // the maximum rate of entering information | ||
36 | double m_dRXmax; // the maximum zoomin per frame | ||
37 | int m_iFrames,m_iTime,m_iTime2,m_iSamples; | ||
38 | int m_iSteps; // the 'Steps' parameter. See djw thesis. | ||
39 | }; | ||
40 | |||
41 | inline CFrameRate::CFrameRate() { | ||
42 | |||
43 | // maxbitrate should be user-defined and/or adaptive. Currently it is not. | ||
44 | #if defined(_WIN32_WCE) | ||
45 | m_dMaxbitrate=5; | ||
46 | #else | ||
47 | m_dMaxbitrate=5.5; | ||
48 | #endif | ||
49 | |||
50 | m_dRXmax=2; // only a transient effect | ||
51 | m_iFrames=0; | ||
52 | m_iSamples=1; | ||
53 | |||
54 | // we dont know the framerate yet - play it safe by setting it high | ||
55 | m_dFr=1<<5; | ||
56 | |||
57 | // start off very slow until we have sampled framerate adequately | ||
58 | m_iSteps=2000; | ||
59 | m_iTime=0; // Hmmm, User must reset framerate before starting. | ||
60 | } | ||
61 | |||
62 | inline void CFrameRate::NewFrame(unsigned long Time) | ||
63 | // compute framerate if we have sampled enough frames | ||
64 | { | ||
65 | |||
66 | m_iFrames++; | ||
67 | |||
68 | if (m_iFrames==m_iSamples) { | ||
69 | m_iTime2=Time; | ||
70 | if (m_iTime2-m_iTime < 50) | ||
71 | m_iSamples++; // increase sample size | ||
72 | else if (m_iTime2-m_iTime > 80) { | ||
73 | m_iSamples--; | ||
74 | if (m_iSamples <2) | ||
75 | m_iSamples=2; | ||
76 | } | ||
77 | if (m_iTime2-m_iTime) { | ||
78 | m_dFr=m_iFrames*1000.0/(m_iTime2-m_iTime); | ||
79 | m_iTime=m_iTime2; | ||
80 | m_iFrames=0; | ||
81 | |||
82 | } | ||
83 | m_dRXmax=exp(m_dMaxbitrate*LN2/m_dFr); | ||
84 | m_iSteps=m_iSteps/2+(int)(-log(0.2)*m_dFr/LN2/m_dMaxbitrate)/2; | ||
85 | //dchar debug[256]; | ||
86 | // _stprintf(debug,TEXT("fr %f Steps %d samples %d time2 %d rxmax %f\n"),fr,Steps,samples,time2,RXmax); | ||
87 | //OutputDebugString(debug); | ||
88 | |||
89 | } | ||
90 | } | ||
91 | |||
92 | inline void CFrameRate::Reset(unsigned long Time) | ||
93 | { | ||
94 | m_iFrames=0; | ||
95 | m_iTime=Time; | ||
96 | } | ||
97 | |||
98 | |||
99 | inline void CFrameRate::SetBitrate(double TargetRate) | ||
100 | { | ||
101 | m_dMaxbitrate = TargetRate; | ||
102 | } | ||
103 | |||
104 | |||
105 | inline void CFrameRate::SetMaxBitrate(double MaxRate) | ||
106 | { | ||
107 | m_dMaxbitrate = MaxRate; | ||
108 | } | ||
109 | |||
110 | |||
111 | |||
112 | #endif /* #ifndef __FrameRate_h__ */ | ||