annotate sdk/RealTime.h @ 1:ad9aa1881a70

* Add most basic load-library-and-list-plugins host
author cannam
date Fri, 31 Mar 2006 15:00:29 +0000
parents 6479539d1b32
children
rev   line source
cannam@0 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
cannam@0 2
cannam@0 3 /*
cannam@0 4 Vamp
cannam@0 5
cannam@0 6 An API for audio analysis and feature extraction plugins.
cannam@0 7
cannam@0 8 Centre for Digital Music, Queen Mary, University of London.
cannam@0 9 Copyright 2006 Chris Cannam.
cannam@0 10
cannam@0 11 Permission is hereby granted, free of charge, to any person
cannam@0 12 obtaining a copy of this software and associated documentation
cannam@0 13 files (the "Software"), to deal in the Software without
cannam@0 14 restriction, including without limitation the rights to use, copy,
cannam@0 15 modify, merge, publish, distribute, sublicense, and/or sell copies
cannam@0 16 of the Software, and to permit persons to whom the Software is
cannam@0 17 furnished to do so, subject to the following conditions:
cannam@0 18
cannam@0 19 The above copyright notice and this permission notice shall be
cannam@0 20 included in all copies or substantial portions of the Software.
cannam@0 21
cannam@0 22 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
cannam@0 23 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
cannam@0 24 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
cannam@0 25 NONINFRINGEMENT. IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR
cannam@0 26 ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
cannam@0 27 CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
cannam@0 28 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
cannam@0 29
cannam@0 30 Except as contained in this notice, the names of the Centre for
cannam@0 31 Digital Music; Queen Mary, University of London; and Chris Cannam
cannam@0 32 shall not be used in advertising or otherwise to promote the sale,
cannam@0 33 use or other dealings in this Software without prior written
cannam@0 34 authorization.
cannam@0 35 */
cannam@0 36
cannam@0 37 /*
cannam@0 38 This is a modified version of a source file from the
cannam@0 39 Rosegarden MIDI and audio sequencer and notation editor.
cannam@0 40 This file copyright 2000-2006 Chris Cannam; relicensed as detailed above
cannam@0 41 */
cannam@0 42
cannam@0 43 #ifndef _REAL_TIME_H_
cannam@0 44 #define _REAL_TIME_H_
cannam@0 45
cannam@0 46 #include <iostream>
cannam@0 47 #include <string>
cannam@0 48
cannam@0 49 struct timeval;
cannam@0 50
cannam@0 51 namespace Vamp {
cannam@0 52
cannam@0 53 /**
cannam@0 54 * RealTime represents time values to nanosecond precision
cannam@0 55 * with accurate arithmetic and frame-rate conversion functions.
cannam@0 56 */
cannam@0 57
cannam@0 58 struct RealTime
cannam@0 59 {
cannam@0 60 int sec;
cannam@0 61 int nsec;
cannam@0 62
cannam@0 63 int usec() const { return nsec / 1000; }
cannam@0 64 int msec() const { return nsec / 1000000; }
cannam@0 65
cannam@0 66 RealTime(): sec(0), nsec(0) {}
cannam@0 67 RealTime(int s, int n);
cannam@0 68
cannam@0 69 RealTime(const RealTime &r) :
cannam@0 70 sec(r.sec), nsec(r.nsec) { }
cannam@0 71
cannam@0 72 static RealTime fromSeconds(double sec);
cannam@0 73 static RealTime fromMilliseconds(int msec);
cannam@0 74 static RealTime fromTimeval(const struct timeval &);
cannam@0 75
cannam@0 76 RealTime &operator=(const RealTime &r) {
cannam@0 77 sec = r.sec; nsec = r.nsec; return *this;
cannam@0 78 }
cannam@0 79
cannam@0 80 RealTime operator+(const RealTime &r) const {
cannam@0 81 return RealTime(sec + r.sec, nsec + r.nsec);
cannam@0 82 }
cannam@0 83 RealTime operator-(const RealTime &r) const {
cannam@0 84 return RealTime(sec - r.sec, nsec - r.nsec);
cannam@0 85 }
cannam@0 86 RealTime operator-() const {
cannam@0 87 return RealTime(-sec, -nsec);
cannam@0 88 }
cannam@0 89
cannam@0 90 bool operator <(const RealTime &r) const {
cannam@0 91 if (sec == r.sec) return nsec < r.nsec;
cannam@0 92 else return sec < r.sec;
cannam@0 93 }
cannam@0 94
cannam@0 95 bool operator >(const RealTime &r) const {
cannam@0 96 if (sec == r.sec) return nsec > r.nsec;
cannam@0 97 else return sec > r.sec;
cannam@0 98 }
cannam@0 99
cannam@0 100 bool operator==(const RealTime &r) const {
cannam@0 101 return (sec == r.sec && nsec == r.nsec);
cannam@0 102 }
cannam@0 103
cannam@0 104 bool operator!=(const RealTime &r) const {
cannam@0 105 return !(r == *this);
cannam@0 106 }
cannam@0 107
cannam@0 108 bool operator>=(const RealTime &r) const {
cannam@0 109 if (sec == r.sec) return nsec >= r.nsec;
cannam@0 110 else return sec >= r.sec;
cannam@0 111 }
cannam@0 112
cannam@0 113 bool operator<=(const RealTime &r) const {
cannam@0 114 if (sec == r.sec) return nsec <= r.nsec;
cannam@0 115 else return sec <= r.sec;
cannam@0 116 }
cannam@0 117
cannam@0 118 RealTime operator/(int d) const;
cannam@0 119
cannam@0 120 // Find the fractional difference between times
cannam@0 121 //
cannam@0 122 double operator/(const RealTime &r) const;
cannam@0 123
cannam@0 124 // Return a human-readable debug-type string to full precision
cannam@0 125 // (probably not a format to show to a user directly)
cannam@0 126 //
cannam@0 127 std::string toString() const;
cannam@0 128
cannam@0 129 // Return a user-readable string to the nearest millisecond
cannam@0 130 // in a form like HH:MM:SS.mmm
cannam@0 131 //
cannam@0 132 std::string toText(bool fixedDp = false) const;
cannam@0 133
cannam@0 134 // Convenience functions for handling sample frames
cannam@0 135 //
cannam@0 136 static long realTime2Frame(const RealTime &r, unsigned int sampleRate);
cannam@0 137 static RealTime frame2RealTime(long frame, unsigned int sampleRate);
cannam@0 138
cannam@0 139 static const RealTime zeroTime;
cannam@0 140 };
cannam@0 141
cannam@0 142 std::ostream &operator<<(std::ostream &out, const RealTime &rt);
cannam@0 143
cannam@0 144 }
cannam@0 145
cannam@0 146 #endif