libltcsmpte  0.4.4
ltcsmpte.h
Go to the documentation of this file.
1 
26 #ifndef LTCSMPTE_H
27 #define LTCSMPTE_H 1
28 
29 #ifdef __cplusplus
30 extern "C" {
31 #endif
32 #ifndef DOXYGEN_IGNORE
33 // libltcsmpte version
34 #define LIBLTCSMPTE_VERSION "0.4.4"
35 #define LIBLTCSMPTE_VERSION_MAJOR 0
36 #define LIBLTCSMPTE_VERSION_MINOR 4
37 #define LIBLTCSMPTE_VERSION_MICRO 4
38 
39 //interface revision number
40 //http://www.gnu.org/software/libtool/manual/html_node/Updating-version-info.html
41 #define LIBLTCSMPTE_CUR 1
42 #define LIBLTCSMPTE_REV 1
43 #define LIBLTCSMPTE_AGE 0
44 #endif
45 
46 #include <sys/types.h>
47 #include <ltcsmpte/framerate.h>
48 
49 
50 typedef double timeu;
51 #define FPRNT_TIME "%lf"
52 #define TIME_DELIM "\t"
53 
54 #ifdef DIAGNOSTICS_OUTPUT
55  #define WRITE_DECODER_BIPHASE_DIAGNOSTICS(A, B, C, D, E) SMPTEDecoderPrintDiagnosticsForAudacity(A, B, C, D, E, 0)
56  #define WRITE_DECODER_BITS_DIAGNOSTICS(A, B, C, D, E) SMPTEDecoderPrintDiagnosticsForAudacity(A, B, C, D, E, 1)
57 #else
58  #define WRITE_DECODER_BIPHASE_DIAGNOSTICS(A, B, C, D, E)
59  #define WRITE_DECODER_BITS_DIAGNOSTICS(A, B, C, D, E)
60 #endif
61 
62 #ifdef USE_FLOAT
63  typedef float sample_t;
64  typedef float curve_sample_t;
65  //#define SAMPLE_AND_CURVE_ARE_DIFFERENT_TYPE
66  #define SAMPLE_CENTER 0
67  #define CURVE_MIN -0.9765625
68  #define CURVE_MAX 0.9765625
69  //#define SAMPLE_IS_UNSIGNED
70  //#define SAMPLE_IS_INTEGER
71  typedef float diagnostics_t;
72 #else
73  #ifdef USE16BIT
74  typedef short sample_t;
75  typedef short curve_sample_t;
76  //#define SAMPLE_AND_CURVE_ARE_DIFFERENT_TYPE
77  #define SAMPLE_CENTER 0
78  #define CURVE_MIN -32000
79  #define CURVE_MAX 32000
80  //#define SAMPLE_IS_UNSIGNED
81  #define SAMPLE_IS_INTEGER
82  typedef int diagnostics_t;
83  #else
84  #define USE8BIT
85  typedef unsigned char sample_t;
86  typedef short curve_sample_t;
87  #define SAMPLE_AND_CURVE_ARE_DIFFERENT_TYPE
88  #define SAMPLE_CENTER 128 // unsigned 8 bit.
89  #define CURVE_MIN -127
90  #define CURVE_MAX 127
91  #define SAMPLE_IS_UNSIGNED
92  #define SAMPLE_IS_INTEGER
93  typedef int diagnostics_t;
94  #endif
95 #endif
96 
97 
98 #define LTC_FRAME_BIT_COUNT 80
99 
102 #ifdef __BIG_ENDIAN__
103 // Big Endian version, bytes are "upside down"
104 typedef struct SMPTEFrame {
105  unsigned int user1:4;
106  unsigned int frameUnits:4;
107 
108  unsigned int user2:4;
109  unsigned int colFrm:1;
110  unsigned int dfbit:1;
111  unsigned int frameTens:2;
112 
113  unsigned int user3:4;
114  unsigned int secsUnits:4;
115 
116  unsigned int user4:4;
117  unsigned int biphaseMarkPhaseCorrection:1;
118  unsigned int secsTens:3;
119 
120  unsigned int user5:4;
121  unsigned int minsUnits:4;
122 
123  unsigned int user6:4;
124  unsigned int binaryGroupFlagBit1:1;
125  unsigned int minsTens:3;
126 
127  unsigned int user7:4;
128  unsigned int hoursUnits:4;
129 
130  unsigned int user8:4;
131  unsigned int binaryGroupFlagBit2:1;
132  unsigned int reserved:1;
133  unsigned int hoursTens:2;
134 
135  unsigned int syncWord:16;
136 } SMPTEFrame;
137 
138 #else
139 // Little Endian version (default)
140 typedef struct SMPTEFrame {
141  unsigned int frameUnits:4;
142  unsigned int user1:4;
143 
144  unsigned int frameTens:2;
145  unsigned int dfbit:1;
146  unsigned int colFrm:1;
147  unsigned int user2:4;
148 
149  unsigned int secsUnits:4;
150  unsigned int user3:4;
151 
152  unsigned int secsTens:3;
154  unsigned int user4:4;
155 
156  unsigned int minsUnits:4;
157  unsigned int user5:4;
158 
159  unsigned int minsTens:3;
160  unsigned int binaryGroupFlagBit1:1;
161  unsigned int user6:4;
162 
163  unsigned int hoursUnits:4;
164  unsigned int user7:4;
165 
166  unsigned int hoursTens:2;
167  unsigned int reserved:1;
168  unsigned int binaryGroupFlagBit2:1;
169  unsigned int user8:4;
170 
171  unsigned int syncWord:16;
172 } SMPTEFrame;
173 
174 #endif
175 
179 typedef struct SMPTETime {
180 // these are only set when compiled with ENABLE_DATE
181  char timezone[6];
182  unsigned char years;
183  unsigned char months;
184  unsigned char days;
185 //
186  unsigned char hours;
187  unsigned char mins;
188  unsigned char secs;
189  unsigned char frame;
190 } SMPTETime;
191 
192 
193 
194 
199 typedef struct SMPTEFrameExt {
201  int delayed;
202  long int startpos;
203  long int endpos;
204 } SMPTEFrameExt;
205 
206 
211 typedef struct SMPTEDecoder SMPTEDecoder;
212 
217 typedef struct SMPTEEncoder SMPTEEncoder;
218 
219 
223 int SMPTEFrameToTime(SMPTEFrame* frame, SMPTETime* stime);
224 
228 int SMPTETimeToFrame(SMPTETime* stime, SMPTEFrame* frame);
229 
234 int SMPTEFrameReset(SMPTEFrame* frame);
235 
239 int SMPTEFrameIncrease(SMPTEFrame *frame, int framesPerSec);
240 
241 
250 SMPTEDecoder * SMPTEDecoderCreate(int sampleRate, FrameRate *fps, int queueSize, int correctJitter);
251 
252 
257 
262 
274 int SMPTEDecoderWrite(SMPTEDecoder *decoder, sample_t *buf, int size, long int posinfo);
275 
282 int SMPTEDecoderRead(SMPTEDecoder *decoder, SMPTEFrameExt *frame);
283 
289 int SMPTEDecoderReadLast(SMPTEDecoder* decoder, SMPTEFrameExt* frame);
290 
296 int SMPTEDecoderFrameToMillisecs(SMPTEDecoder* decoder, SMPTEFrameExt* frame, int *timems);
297 
302 timeu SMPTEDecoderSamplesToSeconds(SMPTEDecoder* d, long int sampleCount);
303 
307 int SMPTEDecoderErrors(SMPTEDecoder *decoder, int *errors);
308 
314 SMPTEEncoder * SMPTEEncoderCreate(int sampleRate, FrameRate *fps);
315 
320 
325 int SMPTESetNsamples(SMPTEEncoder *e, int val);
326 
332 
338 
343 
348 
353 
358 
366 int SMPTEGetBuffer(SMPTEEncoder *e, sample_t *buf);
367 
372 
379 int SMPTEEncode(SMPTEEncoder *e, int byteCnt);
380 
381 #ifdef __cplusplus
382 }
383 #endif
384 
385 #endif