00001 #ifndef TRAVERSO_TYPES_H
00002 #define TRAVERSO_TYPES_H
00003
00004 #include <inttypes.h>
00005 #include <QtGlobal>
00006 #include <QMetaType>
00007 #include "FastDelegate.h"
00008
00009
00010
00011
00012
00013
00014 #if defined(__ppc__) || defined(__powerpc__) || defined(__PPC__)
00015
00016 # define T_ATOMIC_MEMORY_BARRIER __asm__ ("sync" : : : "memory")
00017
00018 static inline int t_atomic_int_get (volatile int *atomic)
00019 {
00020 T_ATOMIC_MEMORY_BARRIER;
00021 return *atomic;
00022 }
00023
00024 static inline void t_atomic_int_set (volatile int *atomic, int newval)
00025 {
00026 *atomic = newval;
00027 T_ATOMIC_MEMORY_BARRIER;
00028 }
00029
00030 #else
00031
00032 # define t_atomic_int_get(atomic) (*(atomic))
00033 # define t_atomic_int_set(atomic, newval) ((void) (*(atomic) = (newval)))
00034
00035 #endif // ENDIF __ppc__
00036
00037
00038 using namespace fastdelegate;
00039
00043 typedef uint32_t nframes_t;
00044
00045 enum {
00046 TransportStopped = 0,
00047 TransportRolling = 1,
00048 TransportLooping = 2,
00049 TransportStarting = 3
00050 };
00051
00052
00053 static const qint64 UNIVERSAL_SAMPLE_RATE = 28224000;
00054 static const qint64 ONE_HOUR_UNIVERSAL_SAMPLE_RATE = 101606400000LL;
00055 static const qint64 ONE_MINUTE_UNIVERSAL_SAMPLE_RATE = 1693440000LL;
00056
00057 struct TimeRef {
00058
00059 TimeRef() {
00060 m_position = 0;
00061 }
00062 explicit TimeRef(qint64 position) : m_position(position) {}
00063 explicit TimeRef(double position) : m_position(qint64(position)) {}
00064
00065 TimeRef(nframes_t frame, int rate) {
00066 m_position = (UNIVERSAL_SAMPLE_RATE / rate) * frame;
00067 }
00068
00069 TimeRef(qreal frame, int rate) {
00070 m_position = qint64((qreal(UNIVERSAL_SAMPLE_RATE) / rate) * frame);
00071 }
00072
00073 void add_frames(nframes_t frames, int rate) {
00074 m_position += ((UNIVERSAL_SAMPLE_RATE / rate) * frames);
00075 }
00076
00077 nframes_t to_frame(int rate) {
00078 Q_ASSERT(rate);
00079 return nframes_t(m_position / (UNIVERSAL_SAMPLE_RATE / rate));
00080 }
00081
00082 qint64 universal_frame() const {return m_position;}
00083
00084 TimeRef& operator =(const qint64 value) {
00085 m_position = value;
00086 return *this;
00087 }
00088
00089 TimeRef& operator =(double value) {
00090 m_position = qint64(value);
00091 return *this;
00092 }
00093
00094 friend int operator!=(const TimeRef& left, const TimeRef& right) {
00095 return left.m_position != right.m_position;
00096 }
00097
00098 friend int operator!=(const TimeRef& left, qint64 right) {
00099 return left.m_position != right;
00100 }
00101
00102 friend int operator!=(const TimeRef& left, double right) {
00103 return left.m_position != qint64(right);
00104 }
00105
00106 friend TimeRef operator-(const TimeRef& left, const TimeRef& right) {
00107 return TimeRef(left.m_position - right.m_position);
00108 }
00109
00110 friend TimeRef operator-(const TimeRef& left, qint64 right) {
00111 return TimeRef(left.m_position - right);
00112 }
00113
00114 friend TimeRef operator-(const TimeRef& left, double right) {
00115 return TimeRef(left.m_position - qint64(right));
00116 }
00117
00118 friend TimeRef& operator-=(TimeRef& left, const TimeRef& right) {
00119 left.m_position -= right.m_position;
00120 return left;
00121 }
00122
00123 friend TimeRef& operator-=(TimeRef& left, qint64 right) {
00124 left.m_position -= right;
00125 return left;
00126 }
00127
00128 friend TimeRef& operator-=(TimeRef& left, double right) {
00129 left.m_position -= qint64(right);
00130 return left;
00131 }
00132
00133 friend TimeRef operator+(const TimeRef& left, const TimeRef& right) {
00134 return TimeRef(left.m_position + right.m_position);
00135 }
00136
00137 friend TimeRef operator+(const TimeRef& left, qint64 right) {
00138 return TimeRef(left.m_position + right);
00139 }
00140
00141 friend TimeRef operator+(const TimeRef& left, double right) {
00142 return TimeRef(left.m_position + qint64(right));
00143 }
00144
00145 friend TimeRef& operator+=(TimeRef& left, const TimeRef& right) {
00146 left.m_position += right.m_position;
00147 return left;
00148 }
00149
00150 friend TimeRef& operator+=(TimeRef& left, qint64 right) {
00151 left.m_position += right;
00152 return left;
00153 }
00154
00155 friend TimeRef& operator+=(TimeRef& left, double right) {
00156 left.m_position += qint64(right);
00157 return left;
00158 }
00159
00160 friend TimeRef operator/(const TimeRef& left, const TimeRef& right) {
00161 Q_ASSERT(right.m_position != 0);
00162 return TimeRef(left.m_position / right.m_position);
00163 }
00164
00165 friend qreal operator/(const TimeRef& left, const qint64 right) {
00166 Q_ASSERT(right != 0);
00167 return (qreal)left.m_position / right;
00168 }
00169
00170 friend qreal operator/(const TimeRef& left, double right) {
00171 Q_ASSERT(right != 0);
00172 return (qreal)left.m_position / qint64(right);
00173 }
00174
00175 friend TimeRef operator*(const qint64 left, TimeRef& right) {
00176 return TimeRef(left * right.m_position);
00177 }
00178
00179 friend TimeRef operator*(const TimeRef& left, const TimeRef& right) {
00180 return TimeRef(left.m_position * right.m_position);
00181 }
00182
00183 friend TimeRef operator*(const TimeRef& left, double right) {
00184 return TimeRef(left.m_position * qint64(right));
00185 }
00186
00187 friend int operator<(const TimeRef& left, const TimeRef& right) {
00188 return left.m_position < right.m_position;
00189 }
00190
00191 friend int operator<(const TimeRef& left, qint64 right) {
00192 return left.m_position < right;
00193 }
00194
00195 friend int operator<(const TimeRef& left, double right) {
00196 return left.m_position < qint64(right);
00197 }
00198
00199 friend int operator<(double left, const TimeRef& right) {
00200 return (qint64(left) < right.m_position);
00201 }
00202
00203 friend int operator>(const TimeRef& left, const TimeRef& right) {
00204 return left.m_position > right.m_position;
00205 }
00206
00207 friend int operator>(const TimeRef& left, qint64 right) {
00208 return left.m_position > right;
00209 }
00210
00211 friend int operator>(const TimeRef& left, double right) {
00212 return left.m_position > qint64(right);
00213 }
00214
00215 friend int operator>(double left, const TimeRef& right) {
00216 return left > right.m_position;
00217 }
00218
00219 friend int operator<=(const TimeRef& left, const TimeRef& right) {
00220 return left.m_position <= right.m_position;
00221 }
00222
00223 friend int operator<=(const TimeRef& left, qint64 right) {
00224 return left.m_position <= right;
00225 }
00226
00227 friend int operator<=(const TimeRef& left, double right) {
00228 return left.m_position <= qint64(right);
00229 }
00230
00231 friend int operator>=(const TimeRef& left, const TimeRef& right) {
00232 return left.m_position >= right.m_position;
00233 }
00234
00235 friend int operator>=(const TimeRef& left, qint64 right) {
00236 return left.m_position >= right;
00237 }
00238
00239 friend int operator>=(const TimeRef& left, double right) {
00240 return left.m_position >= qint64(right);
00241 }
00242
00243 friend int operator==(const TimeRef& left, const TimeRef& right) {
00244 return left.m_position == right.m_position;
00245 }
00246
00247 friend int operator==(const TimeRef& left, qint64 right) {
00248 return left.m_position == right;
00249 }
00250
00251 friend int operator==(const TimeRef& left, double right) {
00252 return left.m_position == qint64(right);
00253 }
00254
00255 private:
00256 qint64 m_position;
00257 };
00258
00259 Q_DECLARE_METATYPE(TimeRef);
00260
00261 typedef struct {
00262 int tranport;
00263 bool isSlave;
00264 bool realtime;
00265 TimeRef location;
00266 } transport_state_t;
00267
00272 typedef double trav_time_t;
00273
00274 typedef unsigned long channel_t;
00275
00276 typedef float audio_sample_t;
00277
00278 typedef short peak_data_t;
00279
00280
00281 typedef FastDelegate1<nframes_t, int> ProcessCallback;
00282 typedef FastDelegate0<int> RunCycleCallback;
00283 typedef FastDelegate1<transport_state_t, int> TransportControlCallback;
00284
00285
00290 #define JACK_DEFAULT_AUDIO_TYPE "32 bit float mono audio"
00291
00292
00299 enum PortFlags {
00300
00305 PortIsInput = 0x1,
00306
00311 PortIsOutput = 0x2,
00312
00317 PortIsPhysical = 0x4,
00318
00332 PortCanMonitor = 0x8,
00333
00348 PortIsTerminal = 0x10
00349 };
00350
00351
00352 #if defined(_MSC_VER) || defined(__MINGW32__)
00353 # include <time.h>
00354 #ifndef _TIMEVAL_DEFINED
00355 #define _TIMEVAL_DEFINED
00356 struct timeval {
00357 long tv_sec;
00358 long tv_usec;
00359 };
00360 #endif
00361 #else
00362 # include <sys/time.h>
00363 #endif
00364
00365
00366 #if defined(_MSC_VER) || defined(__MINGW32__)
00367
00368 #include <windows.h>
00369
00370 #ifdef __cplusplus
00371 extern "C" {
00372 #endif
00373
00374 static inline int gettimeofday(struct timeval* tp, void* tzp) {
00375 DWORD t;
00376 t = timeGetTime();
00377 tp->tv_sec = t / 1000;
00378 tp->tv_usec = t % 1000;
00379
00380 return 0;
00381 }
00382
00383 typedef uint8_t u_int8_t;
00384
00385 #ifdef __cplusplus
00386 }
00387 #endif
00388
00389 #endif
00390
00391
00392 static inline trav_time_t get_microseconds()
00393 {
00394 struct timeval now;
00395 gettimeofday(&now, 0);
00396 trav_time_t time = (now.tv_sec * 1000000.0 + now.tv_usec);
00397 return time;
00398 }
00399
00400 #if defined (RELAYTOOL_PRESENT)
00401
00402 #define RELAYTOOL_JACK \
00403 extern int libjack_is_present;\
00404 extern int libjack_symbol_is_present(char *s);
00405
00406
00407
00408
00409
00410
00411 #define RELAYTOOL_WAVPACK \
00412 static const int libwavpack_is_present=1;\
00413 static int __attribute__((unused)) libwavpack_symbol_is_present(char *) { return 1; }
00414
00415 #define RELAYTOOL_FLAC \
00416 extern int libFLAC_is_present;\
00417 extern int libFLAC_symbol_is_present(char *s);
00418
00419
00420 #define RELAYTOOL_MAD \
00421 extern int libmad_is_present;\
00422 extern int libmad_symbol_is_present(char *s);
00423
00424 #define RELAYTOOL_OGG \
00425 extern int libogg_is_present;\
00426 extern int libogg_symbol_is_present(char *s);
00427
00428 #define RELAYTOOL_VORBIS \
00429 extern int libvorbis_is_present;\
00430 extern int libvorbis_symbol_is_present(char *s);
00431
00432 #define RELAYTOOL_VORBISFILE \
00433 extern int libvorbisfile_is_present;\
00434 extern int libvorbisfile_symbol_is_present(char *s);
00435
00436 #define RELAYTOOL_VORBISENC \
00437 extern int libvorbisenc_is_present;\
00438 extern int libvorbisenc_symbol_is_present(char *s);
00439
00440 #define RELAYTOOL_MP3LAME \
00441 extern int libmp3lame_is_present;\
00442 extern int libmp3lame_symbol_is_present(char *s);
00443
00444 #else
00445
00446
00447 #define RELAYTOOL_JACK \
00448 static const int libjack_is_present=1;\
00449 static int __attribute__((unused)) libjack_symbol_is_present(char *) { return 1; }
00450
00451 #define RELAYTOOL_WAVPACK \
00452 static const int libwavpack_is_present=1;\
00453 static int __attribute__((unused)) libwavpack_symbol_is_present(char *) { return 1; }
00454
00455 #define RELAYTOOL_FLAC \
00456 static const int libFLAC_is_present=1;\
00457 static int __attribute__((unused)) libFLAC_symbol_is_present(char *) { return 1; }
00458
00459 #define RELAYTOOL_MAD \
00460 static const int libmad_is_present=1;\
00461 static int __attribute__((unused)) libmad_symbol_is_present(char *) { return 1; }
00462
00463 #define RELAYTOOL_OGG \
00464 static const int libogg_is_present=1;\
00465 static int __attribute__((unused)) libogg_symbol_is_present(char *) { return 1; }
00466
00467 #define RELAYTOOL_VORBIS \
00468 static const int libvorbis_is_present=1;\
00469 static int __attribute__((unused)) libvorbis_symbol_is_present(char *) { return 1; }
00470
00471 #define RELAYTOOL_VORBISFILE \
00472 static const int libvorbisfile_is_present=1;\
00473 static int __attribute__((unused)) libvorbisfile_symbol_is_present(char *) { return 1; }
00474
00475 #define RELAYTOOL_VORBISENC \
00476 static const int libvorbisenc_is_present=1;\
00477 static int __attribute__((unused)) libvorbisenc_symbol_is_present(char *) { return 1; }
00478
00479 #define RELAYTOOL_MP3LAME \
00480 static const int libmp3lame_is_present=1;\
00481 static int __attribute__((unused)) libmp3lame_symbol_is_present(char *) { return 1; }
00482
00483 #endif // endif RELAYTOOL_PRESENT
00484
00485
00486 #define PROFILE_START trav_time_t starttime = get_microseconds();
00487 #define PROFILE_END(args...) int processtime = (int) (get_microseconds() - starttime);printf("Process time for %s: %d useconds\n\n", args, processtime);
00488
00489 #define DEFAULT_RESAMPLE_QUALITY 2
00490
00491 #endif // endif TRAVERSO_TYPES_H
00492
00493