Mercurial > hg > vamp-website
comparison code-doc/RealTime_8cpp-source.html @ 0:351c4ebce5f9 website
* Move website from vamp-website/trunk to plain website
author | cannam |
---|---|
date | Mon, 22 Sep 2008 13:01:46 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:351c4ebce5f9 |
---|---|
1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> | |
2 <html><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8"> | |
3 <title>VampPluginSDK: RealTime.cpp Source File</title> | |
4 <link href="doxygen.css" rel="stylesheet" type="text/css"> | |
5 <link href="tabs.css" rel="stylesheet" type="text/css"> | |
6 </head><body> | |
7 <!-- Generated by Doxygen 1.5.5 --> | |
8 <div class="navigation" id="top"> | |
9 <div class="tabs"> | |
10 <ul> | |
11 <li><a href="main.html"><span>Main Page</span></a></li> | |
12 <li><a href="namespaces.html"><span>Namespaces</span></a></li> | |
13 <li><a href="annotated.html"><span>Classes</span></a></li> | |
14 <li class="current"><a href="files.html"><span>Files</span></a></li> | |
15 <li><a href="dirs.html"><span>Directories</span></a></li> | |
16 </ul> | |
17 </div> | |
18 <div class="navpath"><a class="el" href="dir_5b77fce4b90561041d958141b45c7c55.html">vamp-sdk</a> | |
19 </div> | |
20 </div> | |
21 </div> | |
22 <h1>RealTime.cpp</h1><a href="RealTime_8cpp.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */</span> | |
23 <a name="l00002"></a>00002 | |
24 <a name="l00003"></a>00003 <span class="comment">/*</span> | |
25 <a name="l00004"></a>00004 <span class="comment"> Vamp</span> | |
26 <a name="l00005"></a>00005 <span class="comment"></span> | |
27 <a name="l00006"></a>00006 <span class="comment"> An API for audio analysis and feature extraction plugins.</span> | |
28 <a name="l00007"></a>00007 <span class="comment"></span> | |
29 <a name="l00008"></a>00008 <span class="comment"> Centre for Digital Music, Queen Mary, University of London.</span> | |
30 <a name="l00009"></a>00009 <span class="comment"> Copyright 2006 Chris Cannam.</span> | |
31 <a name="l00010"></a>00010 <span class="comment"> </span> | |
32 <a name="l00011"></a>00011 <span class="comment"> Permission is hereby granted, free of charge, to any person</span> | |
33 <a name="l00012"></a>00012 <span class="comment"> obtaining a copy of this software and associated documentation</span> | |
34 <a name="l00013"></a>00013 <span class="comment"> files (the "Software"), to deal in the Software without</span> | |
35 <a name="l00014"></a>00014 <span class="comment"> restriction, including without limitation the rights to use, copy,</span> | |
36 <a name="l00015"></a>00015 <span class="comment"> modify, merge, publish, distribute, sublicense, and/or sell copies</span> | |
37 <a name="l00016"></a>00016 <span class="comment"> of the Software, and to permit persons to whom the Software is</span> | |
38 <a name="l00017"></a>00017 <span class="comment"> furnished to do so, subject to the following conditions:</span> | |
39 <a name="l00018"></a>00018 <span class="comment"></span> | |
40 <a name="l00019"></a>00019 <span class="comment"> The above copyright notice and this permission notice shall be</span> | |
41 <a name="l00020"></a>00020 <span class="comment"> included in all copies or substantial portions of the Software.</span> | |
42 <a name="l00021"></a>00021 <span class="comment"></span> | |
43 <a name="l00022"></a>00022 <span class="comment"> THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,</span> | |
44 <a name="l00023"></a>00023 <span class="comment"> EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF</span> | |
45 <a name="l00024"></a>00024 <span class="comment"> MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND</span> | |
46 <a name="l00025"></a>00025 <span class="comment"> NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR</span> | |
47 <a name="l00026"></a>00026 <span class="comment"> ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF</span> | |
48 <a name="l00027"></a>00027 <span class="comment"> CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION</span> | |
49 <a name="l00028"></a>00028 <span class="comment"> WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.</span> | |
50 <a name="l00029"></a>00029 <span class="comment"></span> | |
51 <a name="l00030"></a>00030 <span class="comment"> Except as contained in this notice, the names of the Centre for</span> | |
52 <a name="l00031"></a>00031 <span class="comment"> Digital Music; Queen Mary, University of London; and Chris Cannam</span> | |
53 <a name="l00032"></a>00032 <span class="comment"> shall not be used in advertising or otherwise to promote the sale,</span> | |
54 <a name="l00033"></a>00033 <span class="comment"> use or other dealings in this Software without prior written</span> | |
55 <a name="l00034"></a>00034 <span class="comment"> authorization.</span> | |
56 <a name="l00035"></a>00035 <span class="comment">*/</span> | |
57 <a name="l00036"></a>00036 | |
58 <a name="l00037"></a>00037 <span class="comment">/*</span> | |
59 <a name="l00038"></a>00038 <span class="comment"> This is a modified version of a source file from the </span> | |
60 <a name="l00039"></a>00039 <span class="comment"> Rosegarden MIDI and audio sequencer and notation editor.</span> | |
61 <a name="l00040"></a>00040 <span class="comment"> This file copyright 2000-2006 Chris Cannam.</span> | |
62 <a name="l00041"></a>00041 <span class="comment"> Relicensed by the author as detailed above.</span> | |
63 <a name="l00042"></a>00042 <span class="comment">*/</span> | |
64 <a name="l00043"></a>00043 | |
65 <a name="l00044"></a>00044 <span class="preprocessor">#include <iostream></span> | |
66 <a name="l00045"></a>00045 | |
67 <a name="l00046"></a>00046 <span class="preprocessor">#if (__GNUC__ < 3)</span> | |
68 <a name="l00047"></a>00047 <span class="preprocessor"></span><span class="preprocessor">#include <strstream></span> | |
69 <a name="l00048"></a><a class="code" href="RealTime_8cpp.html#f265757a67f4d68101c17dbc0ce1294e">00048</a> <span class="preprocessor">#define stringstream strstream</span> | |
70 <a name="l00049"></a>00049 <span class="preprocessor"></span><span class="preprocessor">#else</span> | |
71 <a name="l00050"></a>00050 <span class="preprocessor"></span><span class="preprocessor">#include <sstream></span> | |
72 <a name="l00051"></a>00051 <span class="preprocessor">#endif</span> | |
73 <a name="l00052"></a>00052 <span class="preprocessor"></span> | |
74 <a name="l00053"></a>00053 <span class="keyword">using</span> std::cerr; | |
75 <a name="l00054"></a>00054 <span class="keyword">using</span> std::endl; | |
76 <a name="l00055"></a>00055 | |
77 <a name="l00056"></a>00056 <span class="preprocessor">#include "<a class="code" href="RealTime_8h.html">RealTime.h</a>"</span> | |
78 <a name="l00057"></a>00057 | |
79 <a name="l00058"></a>00058 <span class="preprocessor">#ifndef _WIN32</span> | |
80 <a name="l00059"></a>00059 <span class="preprocessor"></span><span class="preprocessor">#include <sys/time.h></span> | |
81 <a name="l00060"></a>00060 <span class="preprocessor">#endif</span> | |
82 <a name="l00061"></a>00061 <span class="preprocessor"></span> | |
83 <a name="l00062"></a>00062 <span class="keyword">namespace </span>Vamp { | |
84 <a name="l00063"></a>00063 | |
85 <a name="l00064"></a>00064 <span class="comment">// A RealTime consists of two ints that must be at least 32 bits each.</span> | |
86 <a name="l00065"></a>00065 <span class="comment">// A signed 32-bit int can store values exceeding +/- 2 billion. This</span> | |
87 <a name="l00066"></a>00066 <span class="comment">// means we can safely use our lower int for nanoseconds, as there are</span> | |
88 <a name="l00067"></a>00067 <span class="comment">// 1 billion nanoseconds in a second and we need to handle double that</span> | |
89 <a name="l00068"></a>00068 <span class="comment">// because of the implementations of addition etc that we use.</span> | |
90 <a name="l00069"></a>00069 <span class="comment">//</span> | |
91 <a name="l00070"></a>00070 <span class="comment">// The maximum valid RealTime on a 32-bit system is somewhere around</span> | |
92 <a name="l00071"></a>00071 <span class="comment">// 68 years: 999999999 nanoseconds longer than the classic Unix epoch.</span> | |
93 <a name="l00072"></a>00072 | |
94 <a name="l00073"></a><a class="code" href="RealTime_8cpp.html#f05eba65a3d4d0547dba7e69e440db2c">00073</a> <span class="preprocessor">#define ONE_BILLION 1000000000</span> | |
95 <a name="l00074"></a>00074 <span class="preprocessor"></span> | |
96 <a name="l00075"></a><a class="code" href="structVamp_1_1RealTime.html#75b2f0af2f9c49e649f8d30b452b049d">00075</a> <a class="code" href="structVamp_1_1RealTime.html#d703be11b7beb07af08ddf133aa2ae79">RealTime::RealTime</a>(<span class="keywordtype">int</span> s, <span class="keywordtype">int</span> n) : | |
97 <a name="l00076"></a>00076 sec(s), nsec(n) | |
98 <a name="l00077"></a>00077 { | |
99 <a name="l00078"></a>00078 <span class="keywordflow">if</span> (<a class="code" href="structVamp_1_1RealTime.html#b4d81983384a9f57ce064e6c343f2267">sec</a> == 0) { | |
100 <a name="l00079"></a>00079 <span class="keywordflow">while</span> (<a class="code" href="structVamp_1_1RealTime.html#2078835bef7bb92514a65b6051cfc6c8">nsec</a> <= -<a class="code" href="RealTime_8cpp.html#f05eba65a3d4d0547dba7e69e440db2c">ONE_BILLION</a>) { <a class="code" href="structVamp_1_1RealTime.html#2078835bef7bb92514a65b6051cfc6c8">nsec</a> += <a class="code" href="RealTime_8cpp.html#f05eba65a3d4d0547dba7e69e440db2c">ONE_BILLION</a>; --<a class="code" href="structVamp_1_1RealTime.html#b4d81983384a9f57ce064e6c343f2267">sec</a>; } | |
101 <a name="l00080"></a>00080 <span class="keywordflow">while</span> (<a class="code" href="structVamp_1_1RealTime.html#2078835bef7bb92514a65b6051cfc6c8">nsec</a> >= <a class="code" href="RealTime_8cpp.html#f05eba65a3d4d0547dba7e69e440db2c">ONE_BILLION</a>) { <a class="code" href="structVamp_1_1RealTime.html#2078835bef7bb92514a65b6051cfc6c8">nsec</a> -= <a class="code" href="RealTime_8cpp.html#f05eba65a3d4d0547dba7e69e440db2c">ONE_BILLION</a>; ++<a class="code" href="structVamp_1_1RealTime.html#b4d81983384a9f57ce064e6c343f2267">sec</a>; } | |
102 <a name="l00081"></a>00081 } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (<a class="code" href="structVamp_1_1RealTime.html#b4d81983384a9f57ce064e6c343f2267">sec</a> < 0) { | |
103 <a name="l00082"></a>00082 <span class="keywordflow">while</span> (<a class="code" href="structVamp_1_1RealTime.html#2078835bef7bb92514a65b6051cfc6c8">nsec</a> <= -<a class="code" href="RealTime_8cpp.html#f05eba65a3d4d0547dba7e69e440db2c">ONE_BILLION</a>) { <a class="code" href="structVamp_1_1RealTime.html#2078835bef7bb92514a65b6051cfc6c8">nsec</a> += <a class="code" href="RealTime_8cpp.html#f05eba65a3d4d0547dba7e69e440db2c">ONE_BILLION</a>; --<a class="code" href="structVamp_1_1RealTime.html#b4d81983384a9f57ce064e6c343f2267">sec</a>; } | |
104 <a name="l00083"></a>00083 <span class="keywordflow">while</span> (<a class="code" href="structVamp_1_1RealTime.html#2078835bef7bb92514a65b6051cfc6c8">nsec</a> > 0) { <a class="code" href="structVamp_1_1RealTime.html#2078835bef7bb92514a65b6051cfc6c8">nsec</a> -= <a class="code" href="RealTime_8cpp.html#f05eba65a3d4d0547dba7e69e440db2c">ONE_BILLION</a>; ++<a class="code" href="structVamp_1_1RealTime.html#b4d81983384a9f57ce064e6c343f2267">sec</a>; } | |
105 <a name="l00084"></a>00084 } <span class="keywordflow">else</span> { | |
106 <a name="l00085"></a>00085 <span class="keywordflow">while</span> (<a class="code" href="structVamp_1_1RealTime.html#2078835bef7bb92514a65b6051cfc6c8">nsec</a> >= <a class="code" href="RealTime_8cpp.html#f05eba65a3d4d0547dba7e69e440db2c">ONE_BILLION</a>) { <a class="code" href="structVamp_1_1RealTime.html#2078835bef7bb92514a65b6051cfc6c8">nsec</a> -= <a class="code" href="RealTime_8cpp.html#f05eba65a3d4d0547dba7e69e440db2c">ONE_BILLION</a>; ++<a class="code" href="structVamp_1_1RealTime.html#b4d81983384a9f57ce064e6c343f2267">sec</a>; } | |
107 <a name="l00086"></a>00086 <span class="keywordflow">while</span> (<a class="code" href="structVamp_1_1RealTime.html#2078835bef7bb92514a65b6051cfc6c8">nsec</a> < 0) { <a class="code" href="structVamp_1_1RealTime.html#2078835bef7bb92514a65b6051cfc6c8">nsec</a> += <a class="code" href="RealTime_8cpp.html#f05eba65a3d4d0547dba7e69e440db2c">ONE_BILLION</a>; --<a class="code" href="structVamp_1_1RealTime.html#b4d81983384a9f57ce064e6c343f2267">sec</a>; } | |
108 <a name="l00087"></a>00087 } | |
109 <a name="l00088"></a>00088 } | |
110 <a name="l00089"></a>00089 | |
111 <a name="l00090"></a>00090 <a class="code" href="structVamp_1_1RealTime.html" title="RealTime represents time values to nanosecond precision with accurate arithmetic...">RealTime</a> | |
112 <a name="l00091"></a><a class="code" href="structVamp_1_1RealTime.html#754901a59483036097d8111b8c02f4f3">00091</a> RealTime::fromSeconds(<span class="keywordtype">double</span> sec) | |
113 <a name="l00092"></a>00092 { | |
114 <a name="l00093"></a>00093 <span class="keywordflow">return</span> <a class="code" href="structVamp_1_1RealTime.html#d703be11b7beb07af08ddf133aa2ae79">RealTime</a>(<span class="keywordtype">int</span>(sec), <span class="keywordtype">int</span>((sec - <span class="keywordtype">int</span>(sec)) * <a class="code" href="RealTime_8cpp.html#f05eba65a3d4d0547dba7e69e440db2c">ONE_BILLION</a> + 0.5)); | |
115 <a name="l00094"></a>00094 } | |
116 <a name="l00095"></a>00095 | |
117 <a name="l00096"></a>00096 <a class="code" href="structVamp_1_1RealTime.html" title="RealTime represents time values to nanosecond precision with accurate arithmetic...">RealTime</a> | |
118 <a name="l00097"></a><a class="code" href="structVamp_1_1RealTime.html#512ca91f967c1d7923456f426926a9f6">00097</a> <a class="code" href="structVamp_1_1RealTime.html#512ca91f967c1d7923456f426926a9f6">RealTime::fromMilliseconds</a>(<span class="keywordtype">int</span> <a class="code" href="structVamp_1_1RealTime.html#76e22815db51ae180c38021110da9947">msec</a>) | |
119 <a name="l00098"></a>00098 { | |
120 <a name="l00099"></a>00099 <span class="keywordflow">return</span> <a class="code" href="structVamp_1_1RealTime.html#d703be11b7beb07af08ddf133aa2ae79">RealTime</a>(msec / 1000, (msec % 1000) * 1000000); | |
121 <a name="l00100"></a>00100 } | |
122 <a name="l00101"></a>00101 | |
123 <a name="l00102"></a>00102 <span class="preprocessor">#ifndef _WIN32</span> | |
124 <a name="l00103"></a>00103 <span class="preprocessor"></span><a class="code" href="structVamp_1_1RealTime.html" title="RealTime represents time values to nanosecond precision with accurate arithmetic...">RealTime</a> | |
125 <a name="l00104"></a><a class="code" href="structVamp_1_1RealTime.html#ffdd22eee09b38335d3133c0e9a8f7b3">00104</a> <a class="code" href="structVamp_1_1RealTime.html#ffdd22eee09b38335d3133c0e9a8f7b3">RealTime::fromTimeval</a>(<span class="keyword">const</span> <span class="keyword">struct</span> timeval &tv) | |
126 <a name="l00105"></a>00105 { | |
127 <a name="l00106"></a>00106 <span class="keywordflow">return</span> <a class="code" href="structVamp_1_1RealTime.html#d703be11b7beb07af08ddf133aa2ae79">RealTime</a>(tv.tv_sec, tv.tv_usec * 1000); | |
128 <a name="l00107"></a>00107 } | |
129 <a name="l00108"></a>00108 <span class="preprocessor">#endif</span> | |
130 <a name="l00109"></a>00109 <span class="preprocessor"></span> | |
131 <a name="l00110"></a><a class="code" href="namespaceVamp.html#84f347b339c111e035f4f0d6ed37f4e0">00110</a> std::ostream &<a class="code" href="namespaceVamp.html#84f347b339c111e035f4f0d6ed37f4e0">operator<<</a>(std::ostream &out, <span class="keyword">const</span> <a class="code" href="structVamp_1_1RealTime.html" title="RealTime represents time values to nanosecond precision with accurate arithmetic...">RealTime</a> &rt) | |
132 <a name="l00111"></a>00111 { | |
133 <a name="l00112"></a>00112 <span class="keywordflow">if</span> (rt < <a class="code" href="structVamp_1_1RealTime.html#be453371597710148b0fd19bb452f8a9">RealTime::zeroTime</a>) { | |
134 <a name="l00113"></a>00113 out << <span class="stringliteral">"-"</span>; | |
135 <a name="l00114"></a>00114 } <span class="keywordflow">else</span> { | |
136 <a name="l00115"></a>00115 out << <span class="stringliteral">" "</span>; | |
137 <a name="l00116"></a>00116 } | |
138 <a name="l00117"></a>00117 | |
139 <a name="l00118"></a>00118 <span class="keywordtype">int</span> s = (rt.<a class="code" href="structVamp_1_1RealTime.html#b4d81983384a9f57ce064e6c343f2267">sec</a> < 0 ? -rt.<a class="code" href="structVamp_1_1RealTime.html#b4d81983384a9f57ce064e6c343f2267">sec</a> : rt.<a class="code" href="structVamp_1_1RealTime.html#b4d81983384a9f57ce064e6c343f2267">sec</a>); | |
140 <a name="l00119"></a>00119 <span class="keywordtype">int</span> n = (rt.<a class="code" href="structVamp_1_1RealTime.html#2078835bef7bb92514a65b6051cfc6c8">nsec</a> < 0 ? -rt.<a class="code" href="structVamp_1_1RealTime.html#2078835bef7bb92514a65b6051cfc6c8">nsec</a> : rt.<a class="code" href="structVamp_1_1RealTime.html#2078835bef7bb92514a65b6051cfc6c8">nsec</a>); | |
141 <a name="l00120"></a>00120 | |
142 <a name="l00121"></a>00121 out << s << <span class="stringliteral">"."</span>; | |
143 <a name="l00122"></a>00122 | |
144 <a name="l00123"></a>00123 <span class="keywordtype">int</span> nn(n); | |
145 <a name="l00124"></a>00124 <span class="keywordflow">if</span> (nn == 0) out << <span class="stringliteral">"00000000"</span>; | |
146 <a name="l00125"></a>00125 <span class="keywordflow">else</span> <span class="keywordflow">while</span> (nn < (<a class="code" href="RealTime_8cpp.html#f05eba65a3d4d0547dba7e69e440db2c">ONE_BILLION</a> / 10)) { | |
147 <a name="l00126"></a>00126 out << <span class="stringliteral">"0"</span>; | |
148 <a name="l00127"></a>00127 nn *= 10; | |
149 <a name="l00128"></a>00128 } | |
150 <a name="l00129"></a>00129 | |
151 <a name="l00130"></a>00130 out << n << <span class="stringliteral">"R"</span>; | |
152 <a name="l00131"></a>00131 <span class="keywordflow">return</span> out; | |
153 <a name="l00132"></a>00132 } | |
154 <a name="l00133"></a>00133 | |
155 <a name="l00134"></a>00134 std::string | |
156 <a name="l00135"></a><a class="code" href="structVamp_1_1RealTime.html#d44476618183bd736996a87292d03c07">00135</a> <a class="code" href="structVamp_1_1RealTime.html#d44476618183bd736996a87292d03c07" title="Return a human-readable debug-type string to full precision (probably not a format...">RealTime::toString</a>()<span class="keyword"> const</span> | |
157 <a name="l00136"></a>00136 <span class="keyword"></span>{ | |
158 <a name="l00137"></a>00137 <a class="code" href="RealTime_8cpp.html#f265757a67f4d68101c17dbc0ce1294e">std::stringstream</a> out; | |
159 <a name="l00138"></a>00138 out << *<span class="keyword">this</span>; | |
160 <a name="l00139"></a>00139 | |
161 <a name="l00140"></a>00140 <span class="preprocessor">#if (__GNUC__ < 3)</span> | |
162 <a name="l00141"></a>00141 <span class="preprocessor"></span> out << std::ends; | |
163 <a name="l00142"></a>00142 <span class="preprocessor">#endif</span> | |
164 <a name="l00143"></a>00143 <span class="preprocessor"></span> | |
165 <a name="l00144"></a>00144 std::string s = out.str(); | |
166 <a name="l00145"></a>00145 | |
167 <a name="l00146"></a>00146 <span class="comment">// remove trailing R</span> | |
168 <a name="l00147"></a>00147 <span class="keywordflow">return</span> s.substr(0, s.length() - 1); | |
169 <a name="l00148"></a>00148 } | |
170 <a name="l00149"></a>00149 | |
171 <a name="l00150"></a>00150 std::string | |
172 <a name="l00151"></a><a class="code" href="structVamp_1_1RealTime.html#d75b927afadfa422ae512d169ccda0aa">00151</a> <a class="code" href="structVamp_1_1RealTime.html#d75b927afadfa422ae512d169ccda0aa" title="Return a user-readable string to the nearest millisecond in a form like HH:MM:SS...">RealTime::toText</a>(<span class="keywordtype">bool</span> fixedDp)<span class="keyword"> const</span> | |
173 <a name="l00152"></a>00152 <span class="keyword"></span>{ | |
174 <a name="l00153"></a>00153 <span class="keywordflow">if</span> (*<span class="keyword">this</span> < <a class="code" href="structVamp_1_1RealTime.html#be453371597710148b0fd19bb452f8a9">RealTime::zeroTime</a>) <span class="keywordflow">return</span> <span class="stringliteral">"-"</span> + (-*<span class="keyword">this</span>).<a class="code" href="structVamp_1_1RealTime.html#d75b927afadfa422ae512d169ccda0aa" title="Return a user-readable string to the nearest millisecond in a form like HH:MM:SS...">toText</a>(); | |
175 <a name="l00154"></a>00154 | |
176 <a name="l00155"></a>00155 <a class="code" href="RealTime_8cpp.html#f265757a67f4d68101c17dbc0ce1294e">std::stringstream</a> out; | |
177 <a name="l00156"></a>00156 | |
178 <a name="l00157"></a>00157 <span class="keywordflow">if</span> (<a class="code" href="structVamp_1_1RealTime.html#b4d81983384a9f57ce064e6c343f2267">sec</a> >= 3600) { | |
179 <a name="l00158"></a>00158 out << (<a class="code" href="structVamp_1_1RealTime.html#b4d81983384a9f57ce064e6c343f2267">sec</a> / 3600) << <span class="stringliteral">":"</span>; | |
180 <a name="l00159"></a>00159 } | |
181 <a name="l00160"></a>00160 | |
182 <a name="l00161"></a>00161 <span class="keywordflow">if</span> (<a class="code" href="structVamp_1_1RealTime.html#b4d81983384a9f57ce064e6c343f2267">sec</a> >= 60) { | |
183 <a name="l00162"></a>00162 out << (<a class="code" href="structVamp_1_1RealTime.html#b4d81983384a9f57ce064e6c343f2267">sec</a> % 3600) / 60 << <span class="stringliteral">":"</span>; | |
184 <a name="l00163"></a>00163 } | |
185 <a name="l00164"></a>00164 | |
186 <a name="l00165"></a>00165 <span class="keywordflow">if</span> (<a class="code" href="structVamp_1_1RealTime.html#b4d81983384a9f57ce064e6c343f2267">sec</a> >= 10) { | |
187 <a name="l00166"></a>00166 out << ((<a class="code" href="structVamp_1_1RealTime.html#b4d81983384a9f57ce064e6c343f2267">sec</a> % 60) / 10); | |
188 <a name="l00167"></a>00167 } | |
189 <a name="l00168"></a>00168 | |
190 <a name="l00169"></a>00169 out << (<a class="code" href="structVamp_1_1RealTime.html#b4d81983384a9f57ce064e6c343f2267">sec</a> % 10); | |
191 <a name="l00170"></a>00170 | |
192 <a name="l00171"></a>00171 <span class="keywordtype">int</span> ms = <a class="code" href="structVamp_1_1RealTime.html#76e22815db51ae180c38021110da9947">msec</a>(); | |
193 <a name="l00172"></a>00172 | |
194 <a name="l00173"></a>00173 <span class="keywordflow">if</span> (ms != 0) { | |
195 <a name="l00174"></a>00174 out << <span class="stringliteral">"."</span>; | |
196 <a name="l00175"></a>00175 out << (ms / 100); | |
197 <a name="l00176"></a>00176 ms = ms % 100; | |
198 <a name="l00177"></a>00177 <span class="keywordflow">if</span> (ms != 0) { | |
199 <a name="l00178"></a>00178 out << (ms / 10); | |
200 <a name="l00179"></a>00179 ms = ms % 10; | |
201 <a name="l00180"></a>00180 } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (fixedDp) { | |
202 <a name="l00181"></a>00181 out << <span class="stringliteral">"0"</span>; | |
203 <a name="l00182"></a>00182 } | |
204 <a name="l00183"></a>00183 <span class="keywordflow">if</span> (ms != 0) { | |
205 <a name="l00184"></a>00184 out << ms; | |
206 <a name="l00185"></a>00185 } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (fixedDp) { | |
207 <a name="l00186"></a>00186 out << <span class="stringliteral">"0"</span>; | |
208 <a name="l00187"></a>00187 } | |
209 <a name="l00188"></a>00188 } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (fixedDp) { | |
210 <a name="l00189"></a>00189 out << <span class="stringliteral">".000"</span>; | |
211 <a name="l00190"></a>00190 } | |
212 <a name="l00191"></a>00191 | |
213 <a name="l00192"></a>00192 <span class="preprocessor">#if (__GNUC__ < 3)</span> | |
214 <a name="l00193"></a>00193 <span class="preprocessor"></span> out << std::ends; | |
215 <a name="l00194"></a>00194 <span class="preprocessor">#endif</span> | |
216 <a name="l00195"></a>00195 <span class="preprocessor"></span> | |
217 <a name="l00196"></a>00196 std::string s = out.str(); | |
218 <a name="l00197"></a>00197 | |
219 <a name="l00198"></a>00198 <span class="keywordflow">return</span> s; | |
220 <a name="l00199"></a>00199 } | |
221 <a name="l00200"></a>00200 | |
222 <a name="l00201"></a>00201 | |
223 <a name="l00202"></a>00202 <a class="code" href="structVamp_1_1RealTime.html" title="RealTime represents time values to nanosecond precision with accurate arithmetic...">RealTime</a> | |
224 <a name="l00203"></a><a class="code" href="structVamp_1_1RealTime.html#c88cda961da5cb728d823b29c5456c06">00203</a> <a class="code" href="structVamp_1_1RealTime.html#c88cda961da5cb728d823b29c5456c06">RealTime::operator/</a>(<span class="keywordtype">int</span> d)<span class="keyword"> const</span> | |
225 <a name="l00204"></a>00204 <span class="keyword"></span>{ | |
226 <a name="l00205"></a>00205 <span class="keywordtype">int</span> secdiv = <a class="code" href="structVamp_1_1RealTime.html#b4d81983384a9f57ce064e6c343f2267">sec</a> / d; | |
227 <a name="l00206"></a>00206 <span class="keywordtype">int</span> secrem = <a class="code" href="structVamp_1_1RealTime.html#b4d81983384a9f57ce064e6c343f2267">sec</a> % d; | |
228 <a name="l00207"></a>00207 | |
229 <a name="l00208"></a>00208 <span class="keywordtype">double</span> nsecdiv = (double(<a class="code" href="structVamp_1_1RealTime.html#2078835bef7bb92514a65b6051cfc6c8">nsec</a>) + <a class="code" href="RealTime_8cpp.html#f05eba65a3d4d0547dba7e69e440db2c">ONE_BILLION</a> * double(secrem)) / d; | |
230 <a name="l00209"></a>00209 | |
231 <a name="l00210"></a>00210 <span class="keywordflow">return</span> <a class="code" href="structVamp_1_1RealTime.html#d703be11b7beb07af08ddf133aa2ae79">RealTime</a>(secdiv, <span class="keywordtype">int</span>(nsecdiv + 0.5)); | |
232 <a name="l00211"></a>00211 } | |
233 <a name="l00212"></a>00212 | |
234 <a name="l00213"></a>00213 <span class="keywordtype">double</span> | |
235 <a name="l00214"></a><a class="code" href="structVamp_1_1RealTime.html#a6e50a94c81a1448ec1d61421ccf6e3f">00214</a> <a class="code" href="structVamp_1_1RealTime.html#c88cda961da5cb728d823b29c5456c06">RealTime::operator/</a>(<span class="keyword">const</span> <a class="code" href="structVamp_1_1RealTime.html" title="RealTime represents time values to nanosecond precision with accurate arithmetic...">RealTime</a> &r)<span class="keyword"> const</span> | |
236 <a name="l00215"></a>00215 <span class="keyword"></span>{ | |
237 <a name="l00216"></a>00216 <span class="keywordtype">double</span> lTotal = double(<a class="code" href="structVamp_1_1RealTime.html#b4d81983384a9f57ce064e6c343f2267">sec</a>) * <a class="code" href="RealTime_8cpp.html#f05eba65a3d4d0547dba7e69e440db2c">ONE_BILLION</a> + double(<a class="code" href="structVamp_1_1RealTime.html#2078835bef7bb92514a65b6051cfc6c8">nsec</a>); | |
238 <a name="l00217"></a>00217 <span class="keywordtype">double</span> rTotal = double(r.<a class="code" href="structVamp_1_1RealTime.html#b4d81983384a9f57ce064e6c343f2267">sec</a>) * <a class="code" href="RealTime_8cpp.html#f05eba65a3d4d0547dba7e69e440db2c">ONE_BILLION</a> + double(r.<a class="code" href="structVamp_1_1RealTime.html#2078835bef7bb92514a65b6051cfc6c8">nsec</a>); | |
239 <a name="l00218"></a>00218 | |
240 <a name="l00219"></a>00219 <span class="keywordflow">if</span> (rTotal == 0) <span class="keywordflow">return</span> 0.0; | |
241 <a name="l00220"></a>00220 <span class="keywordflow">else</span> <span class="keywordflow">return</span> lTotal/rTotal; | |
242 <a name="l00221"></a>00221 } | |
243 <a name="l00222"></a>00222 | |
244 <a name="l00223"></a>00223 <span class="keywordtype">long</span> | |
245 <a name="l00224"></a><a class="code" href="structVamp_1_1RealTime.html#1c32b50b1511cdca17cd6c1c3c05d9b5">00224</a> <a class="code" href="structVamp_1_1RealTime.html#1c32b50b1511cdca17cd6c1c3c05d9b5" title="Convert a RealTime into a sample frame at the given sample rate.">RealTime::realTime2Frame</a>(<span class="keyword">const</span> <a class="code" href="structVamp_1_1RealTime.html" title="RealTime represents time values to nanosecond precision with accurate arithmetic...">RealTime</a> &time, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> sampleRate) | |
246 <a name="l00225"></a>00225 { | |
247 <a name="l00226"></a>00226 <span class="keywordflow">if</span> (time < <a class="code" href="structVamp_1_1RealTime.html#be453371597710148b0fd19bb452f8a9">zeroTime</a>) <span class="keywordflow">return</span> -<a class="code" href="structVamp_1_1RealTime.html#1c32b50b1511cdca17cd6c1c3c05d9b5" title="Convert a RealTime into a sample frame at the given sample rate.">realTime2Frame</a>(-time, sampleRate); | |
248 <a name="l00227"></a>00227 <span class="keywordtype">double</span> s = time.<a class="code" href="structVamp_1_1RealTime.html#b4d81983384a9f57ce064e6c343f2267">sec</a> + double(time.<a class="code" href="structVamp_1_1RealTime.html#2078835bef7bb92514a65b6051cfc6c8">nsec</a> + 1) / 1000000000.0; | |
249 <a name="l00228"></a>00228 <span class="keywordflow">return</span> long(s * sampleRate); | |
250 <a name="l00229"></a>00229 } | |
251 <a name="l00230"></a>00230 | |
252 <a name="l00231"></a>00231 <a class="code" href="structVamp_1_1RealTime.html" title="RealTime represents time values to nanosecond precision with accurate arithmetic...">RealTime</a> | |
253 <a name="l00232"></a><a class="code" href="structVamp_1_1RealTime.html#3a5ecc8888b559aad3b7d96911786b3a">00232</a> <a class="code" href="structVamp_1_1RealTime.html#3a5ecc8888b559aad3b7d96911786b3a" title="Convert a sample frame at the given sample rate into a RealTime.">RealTime::frame2RealTime</a>(<span class="keywordtype">long</span> frame, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> sampleRate) | |
254 <a name="l00233"></a>00233 { | |
255 <a name="l00234"></a>00234 <span class="keywordflow">if</span> (frame < 0) <span class="keywordflow">return</span> -<a class="code" href="structVamp_1_1RealTime.html#3a5ecc8888b559aad3b7d96911786b3a" title="Convert a sample frame at the given sample rate into a RealTime.">frame2RealTime</a>(-frame, sampleRate); | |
256 <a name="l00235"></a>00235 | |
257 <a name="l00236"></a>00236 <a class="code" href="structVamp_1_1RealTime.html" title="RealTime represents time values to nanosecond precision with accurate arithmetic...">RealTime</a> rt; | |
258 <a name="l00237"></a>00237 rt.<a class="code" href="structVamp_1_1RealTime.html#b4d81983384a9f57ce064e6c343f2267">sec</a> = frame / long(sampleRate); | |
259 <a name="l00238"></a>00238 frame -= rt.<a class="code" href="structVamp_1_1RealTime.html#b4d81983384a9f57ce064e6c343f2267">sec</a> * long(sampleRate); | |
260 <a name="l00239"></a>00239 rt.<a class="code" href="structVamp_1_1RealTime.html#2078835bef7bb92514a65b6051cfc6c8">nsec</a> = (int)(((<span class="keywordtype">double</span>(frame) * 1000000.0) / sampleRate) * 1000.0); | |
261 <a name="l00240"></a>00240 <span class="keywordflow">return</span> rt; | |
262 <a name="l00241"></a>00241 } | |
263 <a name="l00242"></a>00242 | |
264 <a name="l00243"></a>00243 <span class="keyword">const</span> <a class="code" href="structVamp_1_1RealTime.html" title="RealTime represents time values to nanosecond precision with accurate arithmetic...">RealTime</a> <a class="code" href="structVamp_1_1RealTime.html#be453371597710148b0fd19bb452f8a9">RealTime::zeroTime</a>(0,0); | |
265 <a name="l00244"></a>00244 | |
266 <a name="l00245"></a>00245 } | |
267 </pre></div></div> | |
268 <hr size="1"><address style="text-align: right;"><small>Generated on Wed Jul 9 11:36:07 2008 for VampPluginSDK by | |
269 <a href="http://www.doxygen.org/index.html"> | |
270 <img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.5.5 </small></address> | |
271 </body> | |
272 </html> |