annotate win32-mingw/include/vamp-sdk/RealTime.h @ 14:48209aa7aa51

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