annotate src/vamp-plugin-sdk-2.4/vamp-sdk/RealTime.h @ 169:223a55898ab9 tip default

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