cannam@21: cannam@21:
cannam@21:00001 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ cannam@21: 00002 cannam@21: 00003 /* cannam@21: 00004 Vamp cannam@21: 00005 cannam@21: 00006 An API for audio analysis and feature extraction plugins. cannam@21: 00007 cannam@21: 00008 Centre for Digital Music, Queen Mary, University of London. cannam@21: 00009 Copyright 2006 Chris Cannam. cannam@21: 00010 cannam@21: 00011 Permission is hereby granted, free of charge, to any person cannam@21: 00012 obtaining a copy of this software and associated documentation cannam@21: 00013 files (the "Software"), to deal in the Software without cannam@21: 00014 restriction, including without limitation the rights to use, copy, cannam@21: 00015 modify, merge, publish, distribute, sublicense, and/or sell copies cannam@21: 00016 of the Software, and to permit persons to whom the Software is cannam@21: 00017 furnished to do so, subject to the following conditions: cannam@21: 00018 cannam@21: 00019 The above copyright notice and this permission notice shall be cannam@21: 00020 included in all copies or substantial portions of the Software. cannam@21: 00021 cannam@21: 00022 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, cannam@21: 00023 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF cannam@21: 00024 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND cannam@21: 00025 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR cannam@21: 00026 ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF cannam@21: 00027 CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION cannam@21: 00028 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. cannam@21: 00029 cannam@21: 00030 Except as contained in this notice, the names of the Centre for cannam@21: 00031 Digital Music; Queen Mary, University of London; and Chris Cannam cannam@21: 00032 shall not be used in advertising or otherwise to promote the sale, cannam@21: 00033 use or other dealings in this Software without prior written cannam@21: 00034 authorization. cannam@21: 00035 */ cannam@21: 00036 cannam@21: 00037 /* cannam@21: 00038 This is a modified version of a source file from the cannam@21: 00039 Rosegarden MIDI and audio sequencer and notation editor. cannam@21: 00040 This file copyright 2000-2006 Chris Cannam. cannam@21: 00041 Relicensed by the author as detailed above. cannam@21: 00042 */ cannam@21: 00043 cannam@21: 00044 #ifndef _VAMP_REAL_TIME_H_ cannam@21: 00045 #define _VAMP_REAL_TIME_H_ cannam@21: 00046 cannam@21: 00047 #include <iostream> cannam@21: 00048 #include <string> cannam@21: 00049 cannam@21: 00050 #ifndef _WIN32 cannam@21: 00051 struct timeval; cannam@21: 00052 #endif cannam@21: 00053 cannam@21: 00054 #include "plugguard.h" cannam@21: 00055 _VAMP_SDK_PLUGSPACE_BEGIN(RealTime.h) cannam@21: 00056 cannam@21: 00057 namespace Vamp { cannam@21: 00058 cannam@21: 00066 struct RealTime cannam@21: 00067 { cannam@21: 00068 int sec; cannam@21: 00069 int nsec; cannam@21: 00070 cannam@21: 00071 int usec() const { return nsec / 1000; } cannam@21: 00072 int msec() const { return nsec / 1000000; } cannam@21: 00073 cannam@21: 00074 RealTime(): sec(0), nsec(0) {} cannam@21: 00075 RealTime(int s, int n); cannam@21: 00076 cannam@21: 00077 RealTime(const RealTime &r) : cannam@21: 00078 sec(r.sec), nsec(r.nsec) { } cannam@21: 00079 cannam@21: 00080 static RealTime fromSeconds(double sec); cannam@21: 00081 static RealTime fromMilliseconds(int msec); cannam@21: 00082 cannam@21: 00083 #ifndef _WIN32 cannam@21: 00084 static RealTime fromTimeval(const struct timeval &); cannam@21: 00085 #endif cannam@21: 00086 cannam@21: 00087 RealTime &operator=(const RealTime &r) { cannam@21: 00088 sec = r.sec; nsec = r.nsec; return *this; cannam@21: 00089 } cannam@21: 00090 cannam@21: 00091 RealTime operator+(const RealTime &r) const { cannam@21: 00092 return RealTime(sec + r.sec, nsec + r.nsec); cannam@21: 00093 } cannam@21: 00094 RealTime operator-(const RealTime &r) const { cannam@21: 00095 return RealTime(sec - r.sec, nsec - r.nsec); cannam@21: 00096 } cannam@21: 00097 RealTime operator-() const { cannam@21: 00098 return RealTime(-sec, -nsec); cannam@21: 00099 } cannam@21: 00100 cannam@21: 00101 bool operator <(const RealTime &r) const { cannam@21: 00102 if (sec == r.sec) return nsec < r.nsec; cannam@21: 00103 else return sec < r.sec; cannam@21: 00104 } cannam@21: 00105 cannam@21: 00106 bool operator >(const RealTime &r) const { cannam@21: 00107 if (sec == r.sec) return nsec > r.nsec; cannam@21: 00108 else return sec > r.sec; cannam@21: 00109 } cannam@21: 00110 cannam@21: 00111 bool operator==(const RealTime &r) const { cannam@21: 00112 return (sec == r.sec && nsec == r.nsec); cannam@21: 00113 } cannam@21: 00114 cannam@21: 00115 bool operator!=(const RealTime &r) const { cannam@21: 00116 return !(r == *this); cannam@21: 00117 } cannam@21: 00118 cannam@21: 00119 bool operator>=(const RealTime &r) const { cannam@21: 00120 if (sec == r.sec) return nsec >= r.nsec; cannam@21: 00121 else return sec >= r.sec; cannam@21: 00122 } cannam@21: 00123 cannam@21: 00124 bool operator<=(const RealTime &r) const { cannam@21: 00125 if (sec == r.sec) return nsec <= r.nsec; cannam@21: 00126 else return sec <= r.sec; cannam@21: 00127 } cannam@21: 00128 cannam@21: 00129 RealTime operator/(int d) const; cannam@21: 00130 cannam@21: 00134 double operator/(const RealTime &r) const; cannam@21: 00135 cannam@21: 00140 std::string toString() const; cannam@21: 00141 cannam@21: 00146 std::string toText(bool fixedDp = false) const; cannam@21: 00147 cannam@21: 00151 static long realTime2Frame(const RealTime &r, unsigned int sampleRate); cannam@21: 00152 cannam@21: 00156 static RealTime frame2RealTime(long frame, unsigned int sampleRate); cannam@21: 00157 cannam@21: 00158 static const RealTime zeroTime; cannam@21: 00159 }; cannam@21: 00160 cannam@21: 00161 std::ostream &operator<<(std::ostream &out, const RealTime &rt); cannam@21: 00162 cannam@21: 00163 } cannam@21: 00164 cannam@21: 00165 _VAMP_SDK_PLUGSPACE_END(RealTime.h) cannam@21: 00166 cannam@21: 00167 #endif cannam@21: