libltc 1.3.1
Linear/Logitudinal Time Code (LTC) Library
ltc.h
Go to the documentation of this file.
1
36#ifndef LTC_H
37#define LTC_H 1
38
39#ifdef __cplusplus
40extern "C" {
41#endif
42
43#if defined _WIN32 && !defined(__LITTLE_ENDIAN__)
44#define __LITTLE_ENDIAN__
45#endif
46
47#ifdef __BIG_ENDIAN__
48# define LTC_BIG_ENDIAN
49#elif defined _BIG_ENDIAN
50# define LTC_BIG_ENDIAN
51#elif defined __BYTE_ORDER__
52# if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
53# define LTC_BIG_ENDIAN
54# endif
55#elif !defined __LITTLE_ENDIAN__
56# include <endian.h> // machine/endian.h
57# if (defined __BYTE_ORDER__ && defined __ORDER_BIG_ENDIAN__ && __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)
58# define LTC_BIG_ENDIAN
59# endif
60#endif
61
62#include <stddef.h> /* size_t */
63
64#ifndef DOXYGEN_IGNORE
65/* libltc version */
66#define LIBLTC_VERSION "1.3.1"
67#define LIBLTC_VERSION_MAJOR 1
68#define LIBLTC_VERSION_MINOR 3
69#define LIBLTC_VERSION_MICRO 1
70
71/* interface revision number
72 * http://www.gnu.org/software/libtool/manual/html_node/Updating-version-info.html
73 */
74#define LIBLTC_CUR 12
75#define LIBLTC_REV 0
76#define LIBLTC_AGE 1
77#endif /* end DOXYGEN_IGNORE */
78
82typedef unsigned char ltcsnd_sample_t;
83
87typedef long long int ltc_off_t;
88
89#define LTC_FRAME_BIT_COUNT 80
90
181#if (defined LTC_BIG_ENDIAN && !defined DOXYGEN_IGNORE)
182// Big Endian version, bytes are "upside down"
183struct LTCFrame {
184 unsigned int user1:4;
185 unsigned int frame_units:4;
186
187 unsigned int user2:4;
188 unsigned int col_frame:1;
189 unsigned int dfbit:1;
190 unsigned int frame_tens:2;
191
192 unsigned int user3:4;
193 unsigned int secs_units:4;
194
195 unsigned int user4:4;
196 unsigned int biphase_mark_phase_correction:1;
197 unsigned int secs_tens:3;
198
199 unsigned int user5:4;
200 unsigned int mins_units:4;
201
202 unsigned int user6:4;
203 unsigned int binary_group_flag_bit0:1;
204 unsigned int mins_tens:3;
205
206 unsigned int user7:4;
207 unsigned int hours_units:4;
208
209 unsigned int user8:4;
210 unsigned int binary_group_flag_bit2:1;
211 unsigned int binary_group_flag_bit1:1;
212 unsigned int hours_tens:2;
213
214 unsigned int sync_word:16;
215};
216#else
217/* Little Endian version -- and doxygen doc */
218struct LTCFrame {
219 unsigned int frame_units:4;
220 unsigned int user1:4;
221
222 unsigned int frame_tens:2;
223 unsigned int dfbit:1;
224 unsigned int col_frame:1;
225 unsigned int user2:4;
226
227 unsigned int secs_units:4;
228 unsigned int user3:4;
229
230 unsigned int secs_tens:3;
232 unsigned int user4:4;
233
234 unsigned int mins_units:4;
235 unsigned int user5:4;
236
237 unsigned int mins_tens:3;
238 unsigned int binary_group_flag_bit0:1;
239 unsigned int user6:4;
240
241 unsigned int hours_units:4;
242 unsigned int user7:4;
243
244 unsigned int hours_tens:2;
245 unsigned int binary_group_flag_bit1:1;
246 unsigned int binary_group_flag_bit2:1;
247 unsigned int user8:4;
248
249 unsigned int sync_word:16;
250};
251#endif
252
263
269 LTC_NO_PARITY = 8
271
275typedef struct LTCFrame LTCFrame;
276
301 double volume;
302};
303
308
313 char timezone[6];
314 unsigned char years;
315 unsigned char months;
316 unsigned char days;
317
318 unsigned char hours;
319 unsigned char mins;
320 unsigned char secs;
321 unsigned char frame;
322};
323
328
329
334typedef struct LTCDecoder LTCDecoder;
335
340typedef struct LTCEncoder LTCEncoder;
341
351void ltc_frame_to_time(SMPTETimecode* stime, LTCFrame* frame, int flags);
352
365void ltc_time_to_frame(LTCFrame* frame, SMPTETimecode* stime, enum LTC_TV_STANDARD standard, int flags);
366
374
389int ltc_frame_increment(LTCFrame* frame, int fps, enum LTC_TV_STANDARD standard, int flags);
390
406int ltc_frame_decrement(LTCFrame* frame, int fps, enum LTC_TV_STANDARD standard, int flags);
407
416LTCDecoder * ltc_decoder_create(int apv, int queue_size);
417
418
424
437 ltcsnd_sample_t *buf, size_t size,
438 ltc_off_t posinfo);
439
449void ltc_decoder_write_float(LTCDecoder *d, float *buf, size_t size, ltc_off_t posinfo);
450
460void ltc_decoder_write_s16(LTCDecoder *d, short *buf, size_t size, ltc_off_t posinfo);
461
471void ltc_decoder_write_u16(LTCDecoder *d, unsigned short *buf, size_t size, ltc_off_t posinfo);
472
482
488
495
496
497
508LTCEncoder* ltc_encoder_create(double sample_rate, double fps, enum LTC_TV_STANDARD standard, int flags);
509
515
529
541
551void ltc_encoder_set_user_bits(LTCEncoder *e, unsigned long data);
552
561
567
574
585
593
605
606
616
622
635
662int ltc_encoder_reinit(LTCEncoder *e, double sample_rate, double fps, enum LTC_TV_STANDARD standard, int flags);
663
671
689int ltc_encoder_set_bufsize(LTCEncoder *e, double sample_rate, double fps);
690
708
725void ltc_encoder_set_filter(LTCEncoder *e, double rise_time);
726
749int ltc_encoder_encode_byte(LTCEncoder *e, int byte, double speed);
750
765
784
796
811ltc_off_t ltc_frame_alignment(double samples_per_frame, enum LTC_TV_STANDARD standard);
812
813#ifdef __cplusplus
814}
815#endif
816
817#endif
ltc_off_t off_end
the sample in the stream corresponding to the end of the LTC frame.
Definition: ltc.h:296
int ltc_encoder_set_bufsize(LTCEncoder *e, double sample_rate, double fps)
size_t ltc_encoder_get_buffersize(LTCEncoder *e)
LTCDecoder * ltc_decoder_create(int apv, int queue_size)
void ltc_encoder_free(LTCEncoder *e)
int ltc_encoder_get_buffer(LTCEncoder *e, ltcsnd_sample_t *buf)
void ltc_decoder_write_s16(LTCDecoder *d, short *buf, size_t size, ltc_off_t posinfo)
void ltc_encoder_get_timecode(LTCEncoder *e, SMPTETimecode *t)
unsigned char frame
sub-second frame 0..(FPS - 1)
Definition: ltc.h:321
unsigned char ltcsnd_sample_t
Definition: ltc.h:82
LTC_BG_FLAGS
Definition: ltc.h:265
@ LTC_TC_CLOCK
the Timecode is wall-clock aka freerun. This also sets BGF1 (unless LTC_BGF_DONT_TOUCH is given)
Definition: ltc.h:267
@ LTC_BGF_DONT_TOUCH
encoder init or re-init does not touch the BGF bits (initial values after initialization is zero)
Definition: ltc.h:268
@ LTC_USE_DATE
LTCFrame <> SMPTETimecode converter and LTCFrame increment/decrement use date, also set BGF2 to '1' w...
Definition: ltc.h:266
@ LTC_NO_PARITY
parity bit is left untouched when setting or in/decrementing the encoder frame-number
Definition: ltc.h:269
long long int ltc_off_t
Definition: ltc.h:87
int ltc_encoder_inc_timecode(LTCEncoder *e)
ltc_off_t ltc_frame_alignment(double samples_per_frame, enum LTC_TV_STANDARD standard)
unsigned int user7
Definition: ltc.h:242
int ltc_encoder_encode_byte(LTCEncoder *e, int byte, double speed)
void ltc_encoder_set_timecode(LTCEncoder *e, SMPTETimecode *t)
#define LTC_FRAME_BIT_COUNT
Definition: ltc.h:89
void ltc_encoder_set_user_bits(LTCEncoder *e, unsigned long data)
unsigned char months
valid months are 1..12
Definition: ltc.h:315
int ltc_encoder_dec_timecode(LTCEncoder *e)
unsigned int user4
Definition: ltc.h:232
unsigned int frame_units
SMPTE framenumber BCD unit 0..9.
Definition: ltc.h:219
unsigned int biphase_mark_phase_correction
see note on Bit 27 in description and ltc_frame_set_parity .
Definition: ltc.h:231
void ltc_encoder_buffer_flush(LTCEncoder *e)
unsigned char mins
minute 0..60
Definition: ltc.h:319
unsigned int user3
Definition: ltc.h:228
struct LTCEncoder LTCEncoder
Definition: ltc.h:340
int ltc_decoder_read(LTCDecoder *d, LTCFrameExt *frame)
void ltc_frame_set_parity(LTCFrame *frame, enum LTC_TV_STANDARD standard)
void ltc_encoder_get_frame(LTCEncoder *e, LTCFrame *f)
unsigned long ltc_frame_get_user_bits(LTCFrame *f)
unsigned char hours
hour 0..23
Definition: ltc.h:318
void ltc_decoder_write_float(LTCDecoder *d, float *buf, size_t size, ltc_off_t posinfo)
unsigned int frame_tens
SMPTE framenumber BCD tens 0..3.
Definition: ltc.h:222
unsigned int secs_units
SMPTE seconds BCD unit 0..9.
Definition: ltc.h:227
void ltc_encoder_set_filter(LTCEncoder *e, double rise_time)
ltcsnd_sample_t sample_max
the maximum input sample signal for this frame (0..255)
Definition: ltc.h:300
unsigned int user8
Definition: ltc.h:247
int ltc_frame_increment(LTCFrame *frame, int fps, enum LTC_TV_STANDARD standard, int flags)
void ltc_decoder_write_u16(LTCDecoder *d, unsigned short *buf, size_t size, ltc_off_t posinfo)
unsigned int hours_tens
SMPTE hours BCD tens 0..2.
Definition: ltc.h:244
ltc_off_t off_start
the approximate sample in the stream corresponding to the start of the LTC frame.
Definition: ltc.h:295
unsigned int binary_group_flag_bit0
indicate user-data char encoding, see table above - bit 43
Definition: ltc.h:238
int ltc_frame_decrement(LTCFrame *frame, int fps, enum LTC_TV_STANDARD standard, int flags)
void ltc_frame_to_time(SMPTETimecode *stime, LTCFrame *frame, int flags)
unsigned int col_frame
colour-frame: timecode intentionally synchronized to a colour TV field sequence
Definition: ltc.h:224
LTC_TV_STANDARD
Definition: ltc.h:257
@ LTC_TV_FILM_24
24fps
Definition: ltc.h:261
@ LTC_TV_625_50
25fps
Definition: ltc.h:259
@ LTC_TV_525_60
30fps
Definition: ltc.h:258
@ LTC_TV_1125_60
30fps
Definition: ltc.h:260
unsigned int sync_word
Definition: ltc.h:249
void ltc_time_to_frame(LTCFrame *frame, SMPTETimecode *stime, enum LTC_TV_STANDARD standard, int flags)
unsigned int user2
Definition: ltc.h:225
unsigned int user6
Definition: ltc.h:239
LTCEncoder * ltc_encoder_create(double sample_rate, double fps, enum LTC_TV_STANDARD standard, int flags)
int reverse
if non-zero, a reverse played LTC frame was detected. Since the frame was reversed,...
Definition: ltc.h:297
LTCFrame ltc
the actual LTC frame. see LTCFrame
Definition: ltc.h:294
int parse_bcg_flags(LTCFrame *f, enum LTC_TV_STANDARD standard)
float biphase_tics[LTC_FRAME_BIT_COUNT]
detailed timing info: phase of the LTC signal; the time between each bit in the LTC-frame in audio-fr...
Definition: ltc.h:298
int ltc_encoder_reinit(LTCEncoder *e, double sample_rate, double fps, enum LTC_TV_STANDARD standard, int flags)
unsigned int binary_group_flag_bit2
indicate user-data char encoding (or parity with 25fps), see table above - bit 59
Definition: ltc.h:246
ltcsnd_sample_t sample_min
the minimum input sample signal for this frame (0..255)
Definition: ltc.h:299
unsigned char days
day of month 1..31
Definition: ltc.h:316
unsigned int mins_units
SMPTE minutes BCD unit 0..9.
Definition: ltc.h:234
unsigned int dfbit
indicated drop-frame timecode
Definition: ltc.h:223
void ltc_encoder_reset(LTCEncoder *e)
void ltc_decoder_write(LTCDecoder *d, ltcsnd_sample_t *buf, size_t size, ltc_off_t posinfo)
void ltc_decoder_queue_flush(LTCDecoder *d)
void ltc_frame_reset(LTCFrame *frame)
char timezone[6]
the timezone 6bytes: "+HHMM" textual representation
Definition: ltc.h:313
void ltc_encoder_set_frame(LTCEncoder *e, LTCFrame *f)
unsigned int secs_tens
SMPTE seconds BCD tens 0..6.
Definition: ltc.h:230
unsigned int mins_tens
SMPTE minutes BCD tens 0..6.
Definition: ltc.h:237
unsigned char secs
second 0..60
Definition: ltc.h:320
unsigned int binary_group_flag_bit1
indicate timecode is local time wall-clock, see table above - bit 58
Definition: ltc.h:245
struct LTCDecoder LTCDecoder
Definition: ltc.h:334
void ltc_encoder_encode_frame(LTCEncoder *e)
int ltc_decoder_free(LTCDecoder *d)
unsigned int user1
Definition: ltc.h:220
double volume
the volume of the input signal in dbFS
Definition: ltc.h:301
unsigned int user5
Definition: ltc.h:235
ltcsnd_sample_t * ltc_encoder_get_bufptr(LTCEncoder *e, int *size, int flush)
unsigned char years
LTC-date uses 2-digit year 00.99.
Definition: ltc.h:314
int ltc_encoder_set_volume(LTCEncoder *e, double dBFS)
int ltc_decoder_queue_length(LTCDecoder *d)
unsigned int hours_units
SMPTE hours BCD unit 0..9.
Definition: ltc.h:241
Definition: ltc.h:218
Definition: ltc.h:293
Definition: ltc.h:312