libltc  1.1.4
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
40 extern "C" {
41 #endif
42 
43 #ifdef __BIG_ENDIAN__
44 # define LTC_BIG_ENDIAN
45 #elif defined _BIG_ENDIAN
46 # define LTC_BIG_ENDIAN
47 #elif defined __BYTE_ORDER__
48 # if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
49 # define LTC_BIG_ENDIAN
50 # endif
51 #elif !defined __LITTLE_ENDIAN__
52 # include <endian.h>
53 # if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
54 # define LTC_BIG_ENDIAN
55 # endif
56 #endif
57 
58 
59 #include <stddef.h> /* size_t */
60 
61 #ifndef DOXYGEN_IGNORE
62 /* libltc version */
63 #define LIBLTC_VERSION "1.1.4"
64 #define LIBLTC_VERSION_MAJOR 1
65 #define LIBLTC_VERSION_MINOR 1
66 #define LIBLTC_VERSION_MICRO 4
67 
68 /* interface revision number
69  * http://www.gnu.org/software/libtool/manual/html_node/Updating-version-info.html
70  */
71 #define LIBLTC_CUR 11
72 #define LIBLTC_REV 3
73 #define LIBLTC_AGE 0
74 #endif /* end DOXYGEN_IGNORE */
75 
79 typedef unsigned char ltcsnd_sample_t;
80 
84 typedef long long int ltc_off_t;
85 
86 #define LTC_FRAME_BIT_COUNT 80
87 
178 #if (defined LTC_BIG_ENDIAN && !defined DOXYGEN_IGNORE)
179 // Big Endian version, bytes are "upside down"
180 struct LTCFrame {
181  unsigned int user1:4;
182  unsigned int frame_units:4;
183 
184  unsigned int user2:4;
185  unsigned int col_frame:1;
186  unsigned int dfbit:1;
187  unsigned int frame_tens:2;
188 
189  unsigned int user3:4;
190  unsigned int secs_units:4;
191 
192  unsigned int user4:4;
193  unsigned int biphase_mark_phase_correction:1;
194  unsigned int secs_tens:3;
195 
196  unsigned int user5:4;
197  unsigned int mins_units:4;
198 
199  unsigned int user6:4;
200  unsigned int binary_group_flag_bit0:1;
201  unsigned int mins_tens:3;
202 
203  unsigned int user7:4;
204  unsigned int hours_units:4;
205 
206  unsigned int user8:4;
207  unsigned int binary_group_flag_bit2:1;
208  unsigned int binary_group_flag_bit1:1;
209  unsigned int hours_tens:2;
210 
211  unsigned int sync_word:16;
212 };
213 #else
214 /* Little Endian version -- and doxygen doc */
215 struct LTCFrame {
216  unsigned int frame_units:4;
217  unsigned int user1:4;
218 
219  unsigned int frame_tens:2;
220  unsigned int dfbit:1;
221  unsigned int col_frame:1;
222  unsigned int user2:4;
223 
224  unsigned int secs_units:4;
225  unsigned int user3:4;
226 
227  unsigned int secs_tens:3;
229  unsigned int user4:4;
230 
231  unsigned int mins_units:4;
232  unsigned int user5:4;
233 
234  unsigned int mins_tens:3;
235  unsigned int binary_group_flag_bit0:1;
236  unsigned int user6:4;
237 
238  unsigned int hours_units:4;
239  unsigned int user7:4;
240 
241  unsigned int hours_tens:2;
242  unsigned int binary_group_flag_bit1:1;
243  unsigned int binary_group_flag_bit2:1;
244  unsigned int user8:4;
245 
246  unsigned int sync_word:16;
247 };
248 #endif
249 
259 };
260 
267 };
268 
272 typedef struct LTCFrame LTCFrame;
273 
290 struct LTCFrameExt {
294  int reverse;
298  double volume;
299 };
300 
304 typedef struct LTCFrameExt LTCFrameExt;
305 
310  char timezone[6];
311  unsigned char years;
312  unsigned char months;
313  unsigned char days;
314 
315  unsigned char hours;
316  unsigned char mins;
317  unsigned char secs;
318  unsigned char frame;
319 };
320 
325 
326 
331 typedef struct LTCDecoder LTCDecoder;
332 
337 typedef struct LTCEncoder LTCEncoder;
338 
348 void ltc_frame_to_time(SMPTETimecode* stime, LTCFrame* frame, int flags);
349 
362 void ltc_time_to_frame(LTCFrame* frame, SMPTETimecode* stime, enum LTC_TV_STANDARD standard, int flags);
363 
370 void ltc_frame_reset(LTCFrame* frame);
371 
386 int ltc_frame_increment(LTCFrame* frame, int fps, enum LTC_TV_STANDARD standard, int flags);
387 
403 int ltc_frame_decrement(LTCFrame* frame, int fps, enum LTC_TV_STANDARD standard, int flags);
404 
413 LTCDecoder * ltc_decoder_create(int apv, int queue_size);
414 
415 
421 
434  ltcsnd_sample_t *buf, size_t size,
435  ltc_off_t posinfo);
436 
446 void ltc_decoder_write_float(LTCDecoder *d, float *buf, size_t size, ltc_off_t posinfo);
447 
457 void ltc_decoder_write_s16(LTCDecoder *d, short *buf, size_t size, ltc_off_t posinfo);
458 
468 void ltc_decoder_write_u16(LTCDecoder *d, unsigned short *buf, size_t size, ltc_off_t posinfo);
469 
478 int ltc_decoder_read(LTCDecoder *d, LTCFrameExt *frame);
479 
485 
492 
493 
494 
505 LTCEncoder* ltc_encoder_create(double sample_rate, double fps, enum LTC_TV_STANDARD standard, int flags);
506 
512 
526 
538 
544 
551 
562 
570 
582 
583 
592 ltcsnd_sample_t *ltc_encoder_get_bufptr(LTCEncoder *e, int *size, int flush);
593 
599 
612 
639 int ltc_encoder_reinit(LTCEncoder *e, double sample_rate, double fps, enum LTC_TV_STANDARD standard, int flags);
640 
648 
666 int ltc_encoder_set_bufsize(LTCEncoder *e, double sample_rate, double fps);
667 
684 int ltc_encoder_set_volume(LTCEncoder *e, double dBFS);
685 
702 void ltc_encoder_set_filter(LTCEncoder *e, double rise_time);
703 
726 int ltc_encoder_encode_byte(LTCEncoder *e, int byte, double speed);
727 
742 
760 void ltc_frame_set_parity(LTCFrame *frame, enum LTC_TV_STANDARD standard);
761 
772 int parse_bcg_flags(LTCFrame *f, enum LTC_TV_STANDARD standard);
773 
788 ltc_off_t ltc_frame_alignment(double samples_per_frame, enum LTC_TV_STANDARD standard);
789 
790 #ifdef __cplusplus
791 }
792 #endif
793 
794 #endif
ltc_off_t ltc_frame_alignment(double samples_per_frame, enum LTC_TV_STANDARD standard)
unsigned char secs
second 0..60
Definition: ltc.h:317
void ltc_encoder_buffer_flush(LTCEncoder *e)
int ltc_encoder_inc_timecode(LTCEncoder *e)
void ltc_frame_to_time(SMPTETimecode *stime, LTCFrame *frame, int flags)
unsigned char ltcsnd_sample_t
Definition: ltc.h:79
void ltc_encoder_set_timecode(LTCEncoder *e, SMPTETimecode *t)
int ltc_encoder_dec_timecode(LTCEncoder *e)
int reverse
if non-zero, a reverse played LTC frame was detected. Since the frame was reversed, it started at off_end and finishes as off_start (off_end > off_start). (Note: in reverse playback the (reversed) sync-word of the next/previous frame is detected, this offset is corrected).
Definition: ltc.h:294
int ltc_decoder_free(LTCDecoder *d)
int ltc_decoder_queue_length(LTCDecoder *d)
unsigned int sync_word
Definition: ltc.h:246
LTCEncoder * ltc_encoder_create(double sample_rate, double fps, enum LTC_TV_STANDARD standard, int flags)
unsigned int user8
Definition: ltc.h:244
struct LTCEncoder LTCEncoder
Definition: ltc.h:337
unsigned char months
valid months are 1..12
Definition: ltc.h:312
ltcsnd_sample_t * ltc_encoder_get_bufptr(LTCEncoder *e, int *size, int flush)
unsigned int user3
Definition: ltc.h:225
void ltc_encoder_get_timecode(LTCEncoder *e, SMPTETimecode *t)
unsigned char days
day of month 1..31
Definition: ltc.h:313
void ltc_encoder_set_filter(LTCEncoder *e, double rise_time)
LTC_BG_FLAGS
Definition: ltc.h:262
25fps
Definition: ltc.h:256
the Timecode is wall-clock aka freerun. This also sets BGF1 (unless LTC_BGF_DONT_TOUCH is given) ...
Definition: ltc.h:264
unsigned int frame_tens
SMPTE framenumber BCD tens 0..3.
Definition: ltc.h:219
unsigned int mins_tens
SMPTE minutes BCD tens 0..6.
Definition: ltc.h:234
int ltc_encoder_set_volume(LTCEncoder *e, double dBFS)
int ltc_frame_decrement(LTCFrame *frame, int fps, enum LTC_TV_STANDARD standard, int flags)
unsigned int binary_group_flag_bit1
indicate timecode is local time wall-clock, see table above - bit 58
Definition: ltc.h:242
unsigned int user4
Definition: ltc.h:229
unsigned int frame_units
SMPTE framenumber BCD unit 0..9.
Definition: ltc.h:216
#define LTC_FRAME_BIT_COUNT
Definition: ltc.h:86
unsigned int user2
Definition: ltc.h:222
void ltc_frame_reset(LTCFrame *frame)
void ltc_encoder_reset(LTCEncoder *e)
24fps
Definition: ltc.h:258
void ltc_decoder_write_s16(LTCDecoder *d, short *buf, size_t size, ltc_off_t posinfo)
unsigned char frame
sub-second frame 0..(FPS - 1)
Definition: ltc.h:318
ltc_off_t off_end
Definition: ltc.h:293
void ltc_decoder_write_u16(LTCDecoder *d, unsigned short *buf, size_t size, ltc_off_t posinfo)
30fps
Definition: ltc.h:257
void ltc_decoder_queue_flush(LTCDecoder *d)
unsigned int biphase_mark_phase_correction
see note on Bit 27 in description and ltc_frame_set_parity .
Definition: ltc.h:228
int parse_bcg_flags(LTCFrame *f, enum LTC_TV_STANDARD standard)
unsigned int col_frame
colour-frame: timecode intentionally synchronized to a colour TV field sequence
Definition: ltc.h:221
int ltc_encoder_get_buffer(LTCEncoder *e, ltcsnd_sample_t *buf)
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:295
int ltc_encoder_set_bufsize(LTCEncoder *e, double sample_rate, double fps)
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:243
void ltc_decoder_write(LTCDecoder *d, ltcsnd_sample_t *buf, size_t size, ltc_off_t posinfo)
parity bit is left untouched when setting or in/decrementing the encoder frame-number ...
Definition: ltc.h:266
LTCFrame ltc
the actual LTC frame. see LTCFrame
Definition: ltc.h:291
Definition: ltc.h:290
void ltc_encoder_get_frame(LTCEncoder *e, LTCFrame *f)
void ltc_time_to_frame(LTCFrame *frame, SMPTETimecode *stime, enum LTC_TV_STANDARD standard, int flags)
void ltc_encoder_encode_frame(LTCEncoder *e)
void ltc_frame_set_parity(LTCFrame *frame, enum LTC_TV_STANDARD standard)
char timezone[6]
the timezone 6bytes: "+HHMM" textual representation
Definition: ltc.h:310
unsigned int user6
Definition: ltc.h:236
ltc_off_t off_start
Definition: ltc.h:292
unsigned char mins
minute 0..60
Definition: ltc.h:316
unsigned int dfbit
indicated drop-frame timecode
Definition: ltc.h:220
Definition: ltc.h:215
unsigned int hours_tens
SMPTE hours BCD tens 0..2.
Definition: ltc.h:241
unsigned int binary_group_flag_bit0
indicate user-data char encoding, see table above - bit 43
Definition: ltc.h:235
int ltc_frame_increment(LTCFrame *frame, int fps, enum LTC_TV_STANDARD standard, int flags)
encoder init or re-init does not touch the BGF bits (initial values after initialization is zero) ...
Definition: ltc.h:265
struct LTCDecoder LTCDecoder
Definition: ltc.h:331
int ltc_encoder_encode_byte(LTCEncoder *e, int byte, double speed)
ltcsnd_sample_t sample_max
the maximum input sample signal for this frame (0..255)
Definition: ltc.h:297
Definition: ltc.h:309
unsigned int mins_units
SMPTE minutes BCD unit 0..9.
Definition: ltc.h:231
double volume
the volume of the input signal in dbFS
Definition: ltc.h:298
unsigned char years
LTC-date uses 2-digit year 00.99.
Definition: ltc.h:311
void ltc_decoder_write_float(LTCDecoder *d, float *buf, size_t size, ltc_off_t posinfo)
unsigned int user1
Definition: ltc.h:217
void ltc_encoder_free(LTCEncoder *e)
unsigned int secs_units
SMPTE seconds BCD unit 0..9.
Definition: ltc.h:224
LTCFrame <> SMPTETimecode converter and LTCFrame increment/decrement use date, also set BGF2 to &#39;1&#39; w...
Definition: ltc.h:263
unsigned int hours_units
SMPTE hours BCD unit 0..9.
Definition: ltc.h:238
unsigned int secs_tens
SMPTE seconds BCD tens 0..6.
Definition: ltc.h:227
LTCDecoder * ltc_decoder_create(int apv, int queue_size)
30fps
Definition: ltc.h:255
unsigned char hours
hour 0..23
Definition: ltc.h:315
void ltc_encoder_set_frame(LTCEncoder *e, LTCFrame *f)
ltcsnd_sample_t sample_min
the minimum input sample signal for this frame (0..255)
Definition: ltc.h:296
LTC_TV_STANDARD
Definition: ltc.h:254
unsigned int user5
Definition: ltc.h:232
int ltc_decoder_read(LTCDecoder *d, LTCFrameExt *frame)
long long int ltc_off_t
Definition: ltc.h:84
size_t ltc_encoder_get_buffersize(LTCEncoder *e)
unsigned int user7
Definition: ltc.h:239