-
Notifications
You must be signed in to change notification settings - Fork 4
/
osc_timetag.h
104 lines (81 loc) · 3.33 KB
/
osc_timetag.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/** @file osc_timetag.h Utilities for manipulating OSC timetags
@authors Andy Schmeder, John MacCallum
@{
*/
/*
Copyright (c) 2008. The Regents of the University of California (Regents).
All Rights Reserved.
Permission to use, copy, modify, and distribute this software and its
documentation for educational, research, and not-for-profit purposes, without
fee and without a signed licensing agreement, is hereby granted, provided that
the above copyright notice, this paragraph and the following two paragraphs
appear in all copies, modifications, and distributions. Contact The Office of
Technology Licensing, UC Berkeley, 2150 Shattuck Avenue, Suite 510, Berkeley,
CA 94720-1620, (510) 643-7201, for commercial licensing opportunities.
Written by Andy Schmeder and John MacCallum, The Center for New Music and
Audio Technologies, University of California, Berkeley.
IN NO EVENT SHALL REGENTS BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT,
SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS,
ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF
REGENTS HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
REGENTS SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
FOR A PARTICULAR PURPOSE. THE SOFTWARE AND ACCOMPANYING
DOCUMENTATION, IF ANY, PROVIDED HEREUNDER IS PROVIDED "AS IS".
REGENTS HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES,
ENHANCEMENTS, OR MODIFICATIONS.
*/
#ifndef __OSC_TIMETAG_H__
#define __OSC_TIMETAG_H__
#ifdef __cplusplus
extern "C" {
#endif
#include <stdint.h>
//#define OSC_TIMETAG_MSGSIZE_NTP 32
//#define OSC_TIME_RECORD "/osc/time/record\0\0\0\0,s\0\0"
//#define OSC_TIME_RECORD_LEN 24
enum {
OSC_TIMETAG_NTP,
OSC_TIMETAG_PTP
};
#define OSC_TIMETAG_SIZEOF_NTP 8
#define OSC_TIMETAG_SIZEOF_PTP 16 // correct?
#define OSC_TIMETAG_FORMAT OSC_TIMETAG_NTP
#if OSC_TIMETAG_FORMAT == OSC_TIMETAG_NTP
typedef struct _osc_timetag_ntptime{
uint32_t sec;
uint32_t frac_sec;
} t_osc_timetag_ntptime;
#define OSC_TIMETAG_SIZEOF OSC_TIMETAG_SIZEOF_NTP
//typedef uint64_t t_osc_timetag;
typedef t_osc_timetag_ntptime t_osc_timetag;
//#define OSC_TIMETAG_NULL 0
#define OSC_TIMETAG_NULL (t_osc_timetag){0, 0}
#define OSC_TIMETAG_IMMEDIATE (t_osc_timetag){0, 1}
#elif OSC_TIMETAG_FORMAT == OSC_TIMETAG_PTP
#define OSC_TIMETAG_SIZEOF OSC_TIMETAG_SIZEOF_NTP
#else
#error Unrecognized timetag format in osc_timetag.h!
#endif
// conversions
void osc_timetag_fromISO8601(char *s, t_osc_timetag *t);
char *osc_timetag_format(t_osc_timetag t);
long osc_timetag_nformat(char *buf, long n, t_osc_timetag t);
// operations
t_osc_timetag osc_timetag_add(t_osc_timetag t1, t_osc_timetag t2);
t_osc_timetag osc_timetag_subtract(t_osc_timetag t1, t_osc_timetag t2);
int osc_timetag_compare(t_osc_timetag t1, t_osc_timetag t2);
t_osc_timetag osc_timetag_floatToTimetag(double d);
double osc_timetag_timetagToFloat(t_osc_timetag timetag);
int osc_timetag_isImmediate(t_osc_timetag timetag);
// generation
t_osc_timetag osc_timetag_now(void);
t_osc_timetag osc_timetag_decodeFromHeader(char *buf);
void osc_timetag_encodeForHeader(t_osc_timetag t, char *buf);
uint32_t osc_timetag_ntp_getSeconds(t_osc_timetag t);
uint32_t osc_timetag_ntp_getFraction(t_osc_timetag t);
#ifdef __cplusplus
}
#endif
#endif
/**@}*/