BltTime.h

Go to the documentation of this file.
00001 /*****************************************************************
00002 |
00003 |   BlueTune - Time Definitions
00004 |
00005 |   (c) 2002-2006 Gilles Boccon-Gibod
00006 |   Author: Gilles Boccon-Gibod (bok@bok.net)
00007 |
00008  ****************************************************************/
00013 #ifndef _BLT_TIME_H_
00014 #define _BLT_TIME_H_
00015 
00016 /*----------------------------------------------------------------------
00017 |   includes
00018 +---------------------------------------------------------------------*/
00019 #include "Atomix.h"
00020 #include "BltDefs.h"
00021 #include "BltTypes.h"
00022 #include "BltErrors.h"
00023 
00024 /*----------------------------------------------------------------------
00025 |   types
00026 +---------------------------------------------------------------------*/
00027 typedef struct {
00028     BLT_UInt8 h;
00029     BLT_UInt8 m;
00030     BLT_UInt8 s;
00031     BLT_UInt8 f;
00032 } BLT_TimeCode;
00033 
00034 typedef struct {
00035     BLT_Int32 seconds;
00036     BLT_Int32 nanoseconds;
00037 } BLT_TimeStamp;
00038 
00039 typedef BLT_TimeStamp BLT_Time;
00040 
00041 /*----------------------------------------------------------------------
00042 |   macros
00043 +---------------------------------------------------------------------*/
00044 #define BLT_TimeStamp_Set(t, s, n) \
00045     do {(t).seconds = (s); (t).nanoseconds = (n);} while(0)
00046 
00047 #define BLT_TimeStamp_IsLater(t0,t1)           \
00048 (                                              \
00049     ((t0).seconds > (t1).seconds) ||    \
00050     (                                          \
00051         (t0).seconds == (t1).seconds &&        \
00052         (t0).nanoseconds > (t1).nanoseconds    \
00053     )                                          \
00054 )
00055 
00056 #define BLT_TimeStamp_IsLaterOrEqual(t0,t1)       \
00057 (                                                 \
00058     (                                             \
00059         (t0).seconds == (t1).seconds &&           \
00060         (t0).nanoseconds == (t1).nanoseconds      \
00061     ) ||                                   \
00062     (                                             \
00063         ((t0).seconds > (t1).seconds) ||   \
00064         (                                         \
00065             (t0).seconds == (t1).seconds &&       \
00066             (t0).nanoseconds > (t1).nanoseconds   \
00067         )                                         \
00068     )                                             \
00069 )
00070 
00071 #define BLT_TimeStamp_Add(t0,t1,t2) do {                        \
00072     (t0).seconds = (t1).seconds + (t2).seconds;                 \
00073     (t0).nanoseconds = (t1).nanoseconds + (t2).nanoseconds;     \
00074     if ((t0).nanoseconds > 1000000000) {                        \
00075         (t0).seconds++;                                         \
00076         (t0).nanoseconds -= 1000000000;                         \
00077     }                                                           \
00078 } while (0)
00079 
00080 #define BLT_TimeStamp_Sub(t0,t1,t2) do {                        \
00081     (t0).seconds = (t1).seconds - (t2).seconds;                 \
00082     (t0).nanoseconds = (t1).nanoseconds - (t2).nanoseconds;     \
00083     if ((t0).nanoseconds < 0) {                                 \
00084         (t0).seconds--;                                         \
00085         (t0).nanoseconds += 1000000000;                         \
00086     }                                                           \
00087 } while (0)
00088 
00089 #define BLT_TimeStamp_ToInt64(t, i) do {                        \
00090     ATX_Int64_Set_Int32(i, t.seconds);                          \
00091     ATX_Int64_Mul_Int32(i, 1000000000);                         \
00092     ATX_Int64_Add_Int32(i, t.nanoseconds);                      \
00093 } while (0)
00094 
00095 /*----------------------------------------------------------------------
00096 |   functions
00097 +---------------------------------------------------------------------*/
00098 BLT_TimeStamp
00099 BLT_TimeStamp_FromSamples(ATX_Int64 sample_count,
00100                           ATX_Int32 sample_rate);
00101 
00102 #endif /* _BLT_TIME_H_ */