Mercurial > hg > vamp-website
view 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 |
line wrap: on
line source
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8"> <title>VampPluginSDK: RealTime.cpp Source File</title> <link href="doxygen.css" rel="stylesheet" type="text/css"> <link href="tabs.css" rel="stylesheet" type="text/css"> </head><body> <!-- Generated by Doxygen 1.5.5 --> <div class="navigation" id="top"> <div class="tabs"> <ul> <li><a href="main.html"><span>Main Page</span></a></li> <li><a href="namespaces.html"><span>Namespaces</span></a></li> <li><a href="annotated.html"><span>Classes</span></a></li> <li class="current"><a href="files.html"><span>Files</span></a></li> <li><a href="dirs.html"><span>Directories</span></a></li> </ul> </div> <div class="navpath"><a class="el" href="dir_5b77fce4b90561041d958141b45c7c55.html">vamp-sdk</a> </div> </div> </div> <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> <a name="l00002"></a>00002 <a name="l00003"></a>00003 <span class="comment">/*</span> <a name="l00004"></a>00004 <span class="comment"> Vamp</span> <a name="l00005"></a>00005 <span class="comment"></span> <a name="l00006"></a>00006 <span class="comment"> An API for audio analysis and feature extraction plugins.</span> <a name="l00007"></a>00007 <span class="comment"></span> <a name="l00008"></a>00008 <span class="comment"> Centre for Digital Music, Queen Mary, University of London.</span> <a name="l00009"></a>00009 <span class="comment"> Copyright 2006 Chris Cannam.</span> <a name="l00010"></a>00010 <span class="comment"> </span> <a name="l00011"></a>00011 <span class="comment"> Permission is hereby granted, free of charge, to any person</span> <a name="l00012"></a>00012 <span class="comment"> obtaining a copy of this software and associated documentation</span> <a name="l00013"></a>00013 <span class="comment"> files (the "Software"), to deal in the Software without</span> <a name="l00014"></a>00014 <span class="comment"> restriction, including without limitation the rights to use, copy,</span> <a name="l00015"></a>00015 <span class="comment"> modify, merge, publish, distribute, sublicense, and/or sell copies</span> <a name="l00016"></a>00016 <span class="comment"> of the Software, and to permit persons to whom the Software is</span> <a name="l00017"></a>00017 <span class="comment"> furnished to do so, subject to the following conditions:</span> <a name="l00018"></a>00018 <span class="comment"></span> <a name="l00019"></a>00019 <span class="comment"> The above copyright notice and this permission notice shall be</span> <a name="l00020"></a>00020 <span class="comment"> included in all copies or substantial portions of the Software.</span> <a name="l00021"></a>00021 <span class="comment"></span> <a name="l00022"></a>00022 <span class="comment"> THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,</span> <a name="l00023"></a>00023 <span class="comment"> EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF</span> <a name="l00024"></a>00024 <span class="comment"> MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND</span> <a name="l00025"></a>00025 <span class="comment"> NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR</span> <a name="l00026"></a>00026 <span class="comment"> ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF</span> <a name="l00027"></a>00027 <span class="comment"> CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION</span> <a name="l00028"></a>00028 <span class="comment"> WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.</span> <a name="l00029"></a>00029 <span class="comment"></span> <a name="l00030"></a>00030 <span class="comment"> Except as contained in this notice, the names of the Centre for</span> <a name="l00031"></a>00031 <span class="comment"> Digital Music; Queen Mary, University of London; and Chris Cannam</span> <a name="l00032"></a>00032 <span class="comment"> shall not be used in advertising or otherwise to promote the sale,</span> <a name="l00033"></a>00033 <span class="comment"> use or other dealings in this Software without prior written</span> <a name="l00034"></a>00034 <span class="comment"> authorization.</span> <a name="l00035"></a>00035 <span class="comment">*/</span> <a name="l00036"></a>00036 <a name="l00037"></a>00037 <span class="comment">/*</span> <a name="l00038"></a>00038 <span class="comment"> This is a modified version of a source file from the </span> <a name="l00039"></a>00039 <span class="comment"> Rosegarden MIDI and audio sequencer and notation editor.</span> <a name="l00040"></a>00040 <span class="comment"> This file copyright 2000-2006 Chris Cannam.</span> <a name="l00041"></a>00041 <span class="comment"> Relicensed by the author as detailed above.</span> <a name="l00042"></a>00042 <span class="comment">*/</span> <a name="l00043"></a>00043 <a name="l00044"></a>00044 <span class="preprocessor">#include <iostream></span> <a name="l00045"></a>00045 <a name="l00046"></a>00046 <span class="preprocessor">#if (__GNUC__ < 3)</span> <a name="l00047"></a>00047 <span class="preprocessor"></span><span class="preprocessor">#include <strstream></span> <a name="l00048"></a><a class="code" href="RealTime_8cpp.html#f265757a67f4d68101c17dbc0ce1294e">00048</a> <span class="preprocessor">#define stringstream strstream</span> <a name="l00049"></a>00049 <span class="preprocessor"></span><span class="preprocessor">#else</span> <a name="l00050"></a>00050 <span class="preprocessor"></span><span class="preprocessor">#include <sstream></span> <a name="l00051"></a>00051 <span class="preprocessor">#endif</span> <a name="l00052"></a>00052 <span class="preprocessor"></span> <a name="l00053"></a>00053 <span class="keyword">using</span> std::cerr; <a name="l00054"></a>00054 <span class="keyword">using</span> std::endl; <a name="l00055"></a>00055 <a name="l00056"></a>00056 <span class="preprocessor">#include "<a class="code" href="RealTime_8h.html">RealTime.h</a>"</span> <a name="l00057"></a>00057 <a name="l00058"></a>00058 <span class="preprocessor">#ifndef _WIN32</span> <a name="l00059"></a>00059 <span class="preprocessor"></span><span class="preprocessor">#include <sys/time.h></span> <a name="l00060"></a>00060 <span class="preprocessor">#endif</span> <a name="l00061"></a>00061 <span class="preprocessor"></span> <a name="l00062"></a>00062 <span class="keyword">namespace </span>Vamp { <a name="l00063"></a>00063 <a name="l00064"></a>00064 <span class="comment">// A RealTime consists of two ints that must be at least 32 bits each.</span> <a name="l00065"></a>00065 <span class="comment">// A signed 32-bit int can store values exceeding +/- 2 billion. This</span> <a name="l00066"></a>00066 <span class="comment">// means we can safely use our lower int for nanoseconds, as there are</span> <a name="l00067"></a>00067 <span class="comment">// 1 billion nanoseconds in a second and we need to handle double that</span> <a name="l00068"></a>00068 <span class="comment">// because of the implementations of addition etc that we use.</span> <a name="l00069"></a>00069 <span class="comment">//</span> <a name="l00070"></a>00070 <span class="comment">// The maximum valid RealTime on a 32-bit system is somewhere around</span> <a name="l00071"></a>00071 <span class="comment">// 68 years: 999999999 nanoseconds longer than the classic Unix epoch.</span> <a name="l00072"></a>00072 <a name="l00073"></a><a class="code" href="RealTime_8cpp.html#f05eba65a3d4d0547dba7e69e440db2c">00073</a> <span class="preprocessor">#define ONE_BILLION 1000000000</span> <a name="l00074"></a>00074 <span class="preprocessor"></span> <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) : <a name="l00076"></a>00076 sec(s), nsec(n) <a name="l00077"></a>00077 { <a name="l00078"></a>00078 <span class="keywordflow">if</span> (<a class="code" href="structVamp_1_1RealTime.html#b4d81983384a9f57ce064e6c343f2267">sec</a> == 0) { <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>; } <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>; } <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) { <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>; } <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>; } <a name="l00084"></a>00084 } <span class="keywordflow">else</span> { <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>; } <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>; } <a name="l00087"></a>00087 } <a name="l00088"></a>00088 } <a name="l00089"></a>00089 <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> <a name="l00091"></a><a class="code" href="structVamp_1_1RealTime.html#754901a59483036097d8111b8c02f4f3">00091</a> RealTime::fromSeconds(<span class="keywordtype">double</span> sec) <a name="l00092"></a>00092 { <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)); <a name="l00094"></a>00094 } <a name="l00095"></a>00095 <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> <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>) <a name="l00098"></a>00098 { <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); <a name="l00100"></a>00100 } <a name="l00101"></a>00101 <a name="l00102"></a>00102 <span class="preprocessor">#ifndef _WIN32</span> <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> <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) <a name="l00105"></a>00105 { <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); <a name="l00107"></a>00107 } <a name="l00108"></a>00108 <span class="preprocessor">#endif</span> <a name="l00109"></a>00109 <span class="preprocessor"></span> <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) <a name="l00111"></a>00111 { <a name="l00112"></a>00112 <span class="keywordflow">if</span> (rt < <a class="code" href="structVamp_1_1RealTime.html#be453371597710148b0fd19bb452f8a9">RealTime::zeroTime</a>) { <a name="l00113"></a>00113 out << <span class="stringliteral">"-"</span>; <a name="l00114"></a>00114 } <span class="keywordflow">else</span> { <a name="l00115"></a>00115 out << <span class="stringliteral">" "</span>; <a name="l00116"></a>00116 } <a name="l00117"></a>00117 <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>); <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>); <a name="l00120"></a>00120 <a name="l00121"></a>00121 out << s << <span class="stringliteral">"."</span>; <a name="l00122"></a>00122 <a name="l00123"></a>00123 <span class="keywordtype">int</span> nn(n); <a name="l00124"></a>00124 <span class="keywordflow">if</span> (nn == 0) out << <span class="stringliteral">"00000000"</span>; <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)) { <a name="l00126"></a>00126 out << <span class="stringliteral">"0"</span>; <a name="l00127"></a>00127 nn *= 10; <a name="l00128"></a>00128 } <a name="l00129"></a>00129 <a name="l00130"></a>00130 out << n << <span class="stringliteral">"R"</span>; <a name="l00131"></a>00131 <span class="keywordflow">return</span> out; <a name="l00132"></a>00132 } <a name="l00133"></a>00133 <a name="l00134"></a>00134 std::string <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> <a name="l00136"></a>00136 <span class="keyword"></span>{ <a name="l00137"></a>00137 <a class="code" href="RealTime_8cpp.html#f265757a67f4d68101c17dbc0ce1294e">std::stringstream</a> out; <a name="l00138"></a>00138 out << *<span class="keyword">this</span>; <a name="l00139"></a>00139 <a name="l00140"></a>00140 <span class="preprocessor">#if (__GNUC__ < 3)</span> <a name="l00141"></a>00141 <span class="preprocessor"></span> out << std::ends; <a name="l00142"></a>00142 <span class="preprocessor">#endif</span> <a name="l00143"></a>00143 <span class="preprocessor"></span> <a name="l00144"></a>00144 std::string s = out.str(); <a name="l00145"></a>00145 <a name="l00146"></a>00146 <span class="comment">// remove trailing R</span> <a name="l00147"></a>00147 <span class="keywordflow">return</span> s.substr(0, s.length() - 1); <a name="l00148"></a>00148 } <a name="l00149"></a>00149 <a name="l00150"></a>00150 std::string <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> <a name="l00152"></a>00152 <span class="keyword"></span>{ <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>(); <a name="l00154"></a>00154 <a name="l00155"></a>00155 <a class="code" href="RealTime_8cpp.html#f265757a67f4d68101c17dbc0ce1294e">std::stringstream</a> out; <a name="l00156"></a>00156 <a name="l00157"></a>00157 <span class="keywordflow">if</span> (<a class="code" href="structVamp_1_1RealTime.html#b4d81983384a9f57ce064e6c343f2267">sec</a> >= 3600) { <a name="l00158"></a>00158 out << (<a class="code" href="structVamp_1_1RealTime.html#b4d81983384a9f57ce064e6c343f2267">sec</a> / 3600) << <span class="stringliteral">":"</span>; <a name="l00159"></a>00159 } <a name="l00160"></a>00160 <a name="l00161"></a>00161 <span class="keywordflow">if</span> (<a class="code" href="structVamp_1_1RealTime.html#b4d81983384a9f57ce064e6c343f2267">sec</a> >= 60) { <a name="l00162"></a>00162 out << (<a class="code" href="structVamp_1_1RealTime.html#b4d81983384a9f57ce064e6c343f2267">sec</a> % 3600) / 60 << <span class="stringliteral">":"</span>; <a name="l00163"></a>00163 } <a name="l00164"></a>00164 <a name="l00165"></a>00165 <span class="keywordflow">if</span> (<a class="code" href="structVamp_1_1RealTime.html#b4d81983384a9f57ce064e6c343f2267">sec</a> >= 10) { <a name="l00166"></a>00166 out << ((<a class="code" href="structVamp_1_1RealTime.html#b4d81983384a9f57ce064e6c343f2267">sec</a> % 60) / 10); <a name="l00167"></a>00167 } <a name="l00168"></a>00168 <a name="l00169"></a>00169 out << (<a class="code" href="structVamp_1_1RealTime.html#b4d81983384a9f57ce064e6c343f2267">sec</a> % 10); <a name="l00170"></a>00170 <a name="l00171"></a>00171 <span class="keywordtype">int</span> ms = <a class="code" href="structVamp_1_1RealTime.html#76e22815db51ae180c38021110da9947">msec</a>(); <a name="l00172"></a>00172 <a name="l00173"></a>00173 <span class="keywordflow">if</span> (ms != 0) { <a name="l00174"></a>00174 out << <span class="stringliteral">"."</span>; <a name="l00175"></a>00175 out << (ms / 100); <a name="l00176"></a>00176 ms = ms % 100; <a name="l00177"></a>00177 <span class="keywordflow">if</span> (ms != 0) { <a name="l00178"></a>00178 out << (ms / 10); <a name="l00179"></a>00179 ms = ms % 10; <a name="l00180"></a>00180 } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (fixedDp) { <a name="l00181"></a>00181 out << <span class="stringliteral">"0"</span>; <a name="l00182"></a>00182 } <a name="l00183"></a>00183 <span class="keywordflow">if</span> (ms != 0) { <a name="l00184"></a>00184 out << ms; <a name="l00185"></a>00185 } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (fixedDp) { <a name="l00186"></a>00186 out << <span class="stringliteral">"0"</span>; <a name="l00187"></a>00187 } <a name="l00188"></a>00188 } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (fixedDp) { <a name="l00189"></a>00189 out << <span class="stringliteral">".000"</span>; <a name="l00190"></a>00190 } <a name="l00191"></a>00191 <a name="l00192"></a>00192 <span class="preprocessor">#if (__GNUC__ < 3)</span> <a name="l00193"></a>00193 <span class="preprocessor"></span> out << std::ends; <a name="l00194"></a>00194 <span class="preprocessor">#endif</span> <a name="l00195"></a>00195 <span class="preprocessor"></span> <a name="l00196"></a>00196 std::string s = out.str(); <a name="l00197"></a>00197 <a name="l00198"></a>00198 <span class="keywordflow">return</span> s; <a name="l00199"></a>00199 } <a name="l00200"></a>00200 <a name="l00201"></a>00201 <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> <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> <a name="l00204"></a>00204 <span class="keyword"></span>{ <a name="l00205"></a>00205 <span class="keywordtype">int</span> secdiv = <a class="code" href="structVamp_1_1RealTime.html#b4d81983384a9f57ce064e6c343f2267">sec</a> / d; <a name="l00206"></a>00206 <span class="keywordtype">int</span> secrem = <a class="code" href="structVamp_1_1RealTime.html#b4d81983384a9f57ce064e6c343f2267">sec</a> % d; <a name="l00207"></a>00207 <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; <a name="l00209"></a>00209 <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)); <a name="l00211"></a>00211 } <a name="l00212"></a>00212 <a name="l00213"></a>00213 <span class="keywordtype">double</span> <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> <a name="l00215"></a>00215 <span class="keyword"></span>{ <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>); <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>); <a name="l00218"></a>00218 <a name="l00219"></a>00219 <span class="keywordflow">if</span> (rTotal == 0) <span class="keywordflow">return</span> 0.0; <a name="l00220"></a>00220 <span class="keywordflow">else</span> <span class="keywordflow">return</span> lTotal/rTotal; <a name="l00221"></a>00221 } <a name="l00222"></a>00222 <a name="l00223"></a>00223 <span class="keywordtype">long</span> <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) <a name="l00225"></a>00225 { <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); <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; <a name="l00228"></a>00228 <span class="keywordflow">return</span> long(s * sampleRate); <a name="l00229"></a>00229 } <a name="l00230"></a>00230 <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> <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) <a name="l00233"></a>00233 { <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); <a name="l00235"></a>00235 <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; <a name="l00237"></a>00237 rt.<a class="code" href="structVamp_1_1RealTime.html#b4d81983384a9f57ce064e6c343f2267">sec</a> = frame / long(sampleRate); <a name="l00238"></a>00238 frame -= rt.<a class="code" href="structVamp_1_1RealTime.html#b4d81983384a9f57ce064e6c343f2267">sec</a> * long(sampleRate); <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); <a name="l00240"></a>00240 <span class="keywordflow">return</span> rt; <a name="l00241"></a>00241 } <a name="l00242"></a>00242 <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); <a name="l00244"></a>00244 <a name="l00245"></a>00245 } </pre></div></div> <hr size="1"><address style="text-align: right;"><small>Generated on Wed Jul 9 11:36:07 2008 for VampPluginSDK by <a href="http://www.doxygen.org/index.html"> <img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.5.5 </small></address> </body> </html>