annotate osx/include/vamp-sdk/RealTime.h @ 27:fffb975dc0b1

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