ltc.h(3)

๐Ÿ“ฆ
version 1.3.2 ยท 5 versions
, in alpine 3.24, debian bookworm, debian trixie, nixos 26.05, nixpkgs unstable, opensuse-leap 16.0, ubuntu noble, ubuntu questing, ubuntu resolute, ubuntu stonking

ltc.h(3) โ€” the libltc manual, section 3 โœจ okay bestie sit down, we're doing headers today


๐ŸŒธ NAME ๐ŸŒธ

ltc.h โ€” libltc โ€” en+decode linear timecode ๐Ÿ’–


โœจ SYNOPSIS โœจ

#include <endian.h>
#include <stddef.h>

๐ŸŽ€ Data Structures

  • struct LTCFrame
  • struct LTCFrameExt
  • struct SMPTETimecode

๐Ÿฆ‹ Macros

  • #define DEPRECATED_EXPORT
  • #define LTC_FRAME_BIT_COUNT 80

๐ŸŒˆ Typedefs

  • typedef unsigned char ltcsnd_sample_t
  • typedef long long int ltc_off_t
  • typedef struct LTCFrame LTCFrame
  • typedef struct LTCFrameExt LTCFrameExt
  • typedef struct SMPTETimecode SMPTETimecode
  • typedef struct LTCDecoder LTCDecoder
  • typedef struct LTCEncoder LTCEncoder

๐Ÿ’… Enumerations

enum LTC_TV_STANDARD โ€” the whole squad:

enum LTC_TV_STANDARD { LTC_TV_525_60, LTC_TV_625_50, LTC_TV_1125_60,
    LTC_TV_FILM_24 }

enum LTC_BG_FLAGS โ€” and these ones literally have numbers attached, no cap:

enum LTC_BG_FLAGS { LTC_USE_DATE = 1, LTC_TC_CLOCK = 2,
    LTC_BGF_DONT_TOUCH = 4, LTC_NO_PARITY = 8 }

๐Ÿ‘‘ Functions

Bestie. There are a LOT. Every single one, in order, no skips, we ate:

  • void ltc_frame_to_time (SMPTETimecode *stime, LTCFrame *frame, int flags)
  • void ltc_time_to_frame (LTCFrame *frame, SMPTETimecode *stime, enum LTC_TV_STANDARD standard, int flags)
  • void ltc_frame_reset (LTCFrame *frame)
  • int ltc_frame_increment (LTCFrame *frame, int fps, enum LTC_TV_STANDARD standard, int flags)
  • int ltc_frame_decrement (LTCFrame *frame, int fps, enum LTC_TV_STANDARD standard, int flags)
  • LTCDecoder * ltc_decoder_create (int apv, int queue_size)
  • int ltc_decoder_free (LTCDecoder *d)
  • void ltc_decoder_write (LTCDecoder *d, ltcsnd_sample_t *buf, size_t size, ltc_off_t posinfo)
  • void ltc_decoder_write_double (LTCDecoder *d, double *buf, size_t size, ltc_off_t posinfo)
  • void ltc_decoder_write_float (LTCDecoder *d, float *buf, size_t size, ltc_off_t posinfo)
  • void ltc_decoder_write_s16 (LTCDecoder *d, short *buf, size_t size, ltc_off_t posinfo)
  • void ltc_decoder_write_u16 (LTCDecoder *d, unsigned short *buf, size_t size, ltc_off_t posinfo)
  • int ltc_decoder_read (LTCDecoder *d, LTCFrameExt *frame)
  • void ltc_decoder_queue_flush (LTCDecoder *d)
  • int ltc_decoder_queue_length (LTCDecoder *d)
  • LTCEncoder * ltc_encoder_create (double sample_rate, double fps, enum LTC_TV_STANDARD standard, int flags)
  • void ltc_encoder_free (LTCEncoder *e)
  • void ltc_encoder_set_timecode (LTCEncoder *e, SMPTETimecode *t)
  • void ltc_encoder_get_timecode (LTCEncoder *e, SMPTETimecode *t)
  • void ltc_encoder_set_user_bits (LTCEncoder *e, unsigned long data)
  • unsigned long ltc_frame_get_user_bits (LTCFrame *f)
  • int ltc_encoder_inc_timecode (LTCEncoder *e)
  • int ltc_encoder_dec_timecode (LTCEncoder *e)
  • void ltc_encoder_set_frame (LTCEncoder *e, LTCFrame *f)
  • void ltc_encoder_get_frame (LTCEncoder *e, LTCFrame *f)
  • int ltc_encoder_get_buffer (LTCEncoder *e, ltcsnd_sample_t *buf) DEPRECATED_EXPORT
  • int ltc_encoder_copy_buffer (LTCEncoder *e, ltcsnd_sample_t *buf)
  • ltcsnd_sample_t * ltc_encoder_get_bufptr (LTCEncoder *e, int *size, int flush) DEPRECATED_EXPORT
  • int ltc_encoder_get_bufferptr (LTCEncoder *e, ltcsnd_sample_t **buf, int flush)
  • void ltc_encoder_buffer_flush (LTCEncoder *e)
  • size_t ltc_encoder_get_buffersize (LTCEncoder *e)
  • int ltc_encoder_reinit (LTCEncoder *e, double sample_rate, double fps, enum LTC_TV_STANDARD standard, int flags)
  • void ltc_encoder_reset (LTCEncoder *e)
  • int ltc_encoder_set_bufsize (LTCEncoder *e, double sample_rate, double fps) DEPRECATED_EXPORT
  • int ltc_encoder_set_buffersize (LTCEncoder *e, double sample_rate, double fps)
  • double ltc_encoder_get_volume (LTCEncoder *e)
  • int ltc_encoder_set_volume (LTCEncoder *e, double dBFS)
  • double ltc_encoder_get_filter (LTCEncoder *e)
  • void ltc_encoder_set_filter (LTCEncoder *e, double rise_time)
  • int ltc_encoder_encode_byte (LTCEncoder *e, int byte, double speed)
  • int ltc_encoder_end_encode (LTCEncoder *e)
  • void ltc_encoder_encode_frame (LTCEncoder *e)
  • void ltc_encoder_encode_reversed_frame (LTCEncoder *e)
  • void ltc_frame_set_parity (LTCFrame *frame, enum LTC_TV_STANDARD standard)
  • int ltc_frame_parse_bcg_flags (LTCFrame *frame, enum LTC_TV_STANDARD standard)
  • ltc_off_t ltc_frame_alignment (double samples_per_frame, enum LTC_TV_STANDARD standard)
Heads up bestie: three of those are marked DEPRECATED_EXPORT โ€” ltc_encoder_get_buffer, ltc_encoder_get_bufptr, and ltc_encoder_set_bufsize. They still exist, they still show up in the list, but they're giving "old news" energy. We'll get into them later, no skipping. ๐Ÿ’€

๐Ÿซถ Detailed Description ๐Ÿซถ

libltc โ€” en+decode linear timecode

Linear (or Longitudinal) Timecode (LTC) is an encoding of timecode data as a Manchester-Biphase encoded audio signal. The audio signal is commonly recorded on a VTR track or other storage media.

libltc facilitates decoding and encoding of LTC from/to timecode, including SMPTE date support. ๐ŸŒŸ

๐ŸŒธ Author ๐ŸŒธ

Robin Gareus robin@gareus.org

Copyright (C) 2006-2022 Robin Gareus robin@gareus.org

Copyright (C) 2008-2009 Jan WeiรŸ jan@geheimwerk.de

Inspired by SMPTE Decoder โ€” Maarten de Boer mdeboer@iua.upf.es

This program is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with this library. If not, see http://www.gnu.org/licenses/.

okay real talk for one sec: that "WITHOUT ANY WARRANTY" line is not a vibe, it's the actual legal deal. No warranty, periodt. Read the LGPL if you need the receipts. ๐Ÿ™ˆ

๐Ÿฆ‹ Data Structure Documentation ๐Ÿฆ‹

bestie we are SO not done, the actual struct deep-dives are literally next ๐Ÿ’–

struct LTCFrame

Raw 80 bit LTC frame. ๐Ÿ’–

okay so picture this: the datastream for each video frame of Longitudinal Timecode is made of eighty bit-periods. that's it, that's the whole vibe.

At a frame-rate of 30 fps, the bit-rate corresponds to 30 [fps] * 80 [bits/f] = 2400 bits per second. The frequency for a stream of zeros would be 1.2 kHz and for a stream of ones it would be 2.4 kHz. With all commonly used video-frame-rates and audio-sample-rates, LTC timecode can be recorded easily into an audio-track. bestie it literally just fits. ๐ŸŽ€

In each frame, 26 of the eighty bits carry the SMPTE time in binary coded decimal (BCD).

These Bits are FRAME-UNITS, FRAME-TENS, SECS-UNITS, SECS-TENS, MINS-UNITS, MINS-TENS, HOURS-UNITS and HOURS-TENS. The BCD digits are loaded 'least significant bit first' (libltc takes care of the architecture specific alignment, she's got it handled ๐Ÿ’…).

32 bits are assigned as eight groups of four USER-BITS (also sometimes called the 'Binary Groups'). This capacity is generally used to carry extra info such as reel number and/or date. The User Bits may be allocated howsoever one wishes as long as both Binary Group Flag Bits are cleared.

The function ltc_frame_to_time can interpret the user-bits as SMPTE Date+Timezone according to SMPTE 309M-1999. similarly ltc_time_to_frame will do the reverse. ๐Ÿฆ‹

The last 16 Bits make up the SYNC WORD. These bits indicate the frame boundary, the tape direction, and the bit-rate of the sync tone. The values of these Bits are fixed as 0011 1111 1111 1101. no cap, they just are.

The Bi-Phase Mark Phase Correction Bit (Bit 27 or 59) may be set or cleared so that that every 80-bit word contains an even number of zeroes. This means that the phase of the pulse train in every Sync Word will be the same. โœจ

Bit 10 indicates drop-frame timecode. The Colour Frame Flag col.frm is Bit 11; if the timecode intentionally synchronized to a colour TV field sequence, this bit is set.

Bit 58 is not required for the BCD count for HOURS-TENS (which has a maximum value of two) and has not been given any other special purpose so remains unassigned. This Bit has been RESERVED for future assignment. ๐Ÿ‘€

The Binary Group Flag Bits (bits 43 and 59) are two bits indicate the format of the User Bits data. SMPTE 12M-1999 defines the previously reserved bit 58 to signals that the time is locked to wall-clock within a tolerance of ยฑ 0.5 seconds.

SMPTE 12M-1999 also changes the numbering schema of the BGF. (BGF1 was renamed to BGF2 and bit 58 becomes BGFB1) โ€” yes they really did that to us, iconic chaos honestly ๐Ÿ’€

To further complicate matters, the BGFB assignment as well as the biphase_mark_phase_correction (aka parity) bit depends on the timecode-format used.

                25 fps   24, 30 fps
        BGF0      27        43
        BGF1      58        58
        BGF2      43        59
        Parity    59        27

The variable naming chosen for the LTCFrame struct is based on the 24,30 fps standard.

The Binary Group Flag Bits should be used only as shown in the truth table below. The Unassigned entries in the table should not be used, as they may be allocated specific meanings in the future. ๐Ÿ”ฎ

                                                       BGF0      BGF1    BGF2
             user-bits                     timecode    Bit 43   Bit 58  Bit 59 (30fps, 24 fps)
                                          |        |   Bit 27   Bit 58  Bit 43 (25fps)
        No User Bits format specified     |   ?    |     0       0        0
        Eight-bit character set (1)       |   ?    |     1       0        0
        Date and Timezone set             |   ?    |     0       0        1
        Page/Line multiplex (2)           |   ?    |     1       0        1
        Character set not specified       |  clk   |     0       1        0
        Reserved                          |   ?    |     1       1        0
        Date and Timezone set             |  clk   |     0       1        1
        Page/Line multiplex (2)           |  clk   |     1       1        1

(1) ISO/IEC 646 or ISO/IEC 2022 character set. If the seven-bit ISO codes are being used, they shall be converted to eight-bit codes by setting the eighth bit to zero. 4 ISO codes can be encoded, user7 and user8 are to be used for the first code with LSB 7 and MSB in 8. the remaining ISO codes are to be distributed in the same manner to user5/6 user3/4 and user1/2 accordingly.

(2) The Page/Line indicates ANSI/SMPTE-262M is used for the user-bits. It is multiplex system that can be used to encode large amounts of data in the binary groups through the use of time multiplexing.

libltc does not use any of the BGF โ€” except for the Parity bit which can be calculated and set with ltc_frame_set_parity. Setting and interpreting the BGF is left to the application using libltc. However libltc provides functionality to parse or set date and timezone according to SMPTE 309M-1999.

further information: http://www.philrees.co.uk/articles/timecode.htm and http://www.barney-wol.net/time/timecode.html ๐ŸŒˆ

Data Fields:

  • unsigned int binary_group_flag_bit0:1 โ€” indicate user-data char encoding, see table above - bit 43
  • unsigned int binary_group_flag_bit1:1 โ€” indicate timecode is local time wall-clock, see table above - bit 58
  • unsigned int binary_group_flag_bit2:1 โ€” indicate user-data char encoding (or parity with 25fps), see table above - bit 59
  • unsigned int biphase_mark_phase_correction:1 โ€” see note on Bit 27 in description and ltc_frame_set_parity.
  • unsigned int col_frame:1 โ€” colour-frame: timecode intentionally synchronized to a colour TV field sequence
  • unsigned int dfbit:1 โ€” indicated drop-frame timecode
  • unsigned int frame_tens:2 โ€” SMPTE framenumber BCD tens 0..3.
  • unsigned int frame_units:4 โ€” SMPTE framenumber BCD unit 0..9.
  • unsigned int hours_tens:2 โ€” SMPTE hours BCD tens 0..2.
  • unsigned int hours_units:4 โ€” SMPTE hours BCD unit 0..9.
  • unsigned int mins_tens:3 โ€” SMPTE minutes BCD tens 0..6.
  • unsigned int mins_units:4 โ€” SMPTE minutes BCD unit 0..9.
  • unsigned int secs_tens:3 โ€” SMPTE seconds BCD tens 0..6.
  • unsigned int secs_units:4 โ€” SMPTE seconds BCD unit 0..9.
  • unsigned int sync_word:16
  • unsigned int user1:4
  • unsigned int user2:4
  • unsigned int user3:4
  • unsigned int user4:4
  • unsigned int user5:4
  • unsigned int user6:4
  • unsigned int user7:4
  • unsigned int user8:4

struct LTCFrameExt

Extended LTC frame - includes audio-sample position offsets, volume, etc. ๐Ÿ’–

Note: For TV systems, the sample in the LTC audio data stream where the LTC Frame starts is not necessarily at the same time as the video-frame which is described by the LTC Frame. ๐Ÿ˜ญ they're not synced like that, bestie.

off_start denotes the time of the first transition of bit 0 in the LTC frame.

For 525/60 Television systems, the first transition shall occur at the beginning of line 5 of the frame with which it is associated. The tolerance is ยฑ 1.5 lines.

For 625/50 systems, the first transition shall occur at the beginning of line 2 ยฑ 1.5 lines of the frame with which it is associated.

Only for 1125/60 systems, the first transition occurs exactly at the vertical sync timing reference of the frame. ยฑ 1 line.

Examples

ltcdecode.c. ๐Ÿ‘‘

Data Fields:

  • 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-frames. Summing all 80 values in the array will yield audio-frames/LTC-frame = (off_end - off_start + 1).
  • LTCFrame ltc โ€” the actual LTC frame. see LTCFrame
  • ltc_off_t off_end โ€” the sample in the stream corresponding to the end of the LTC frame.
  • ltc_off_t off_start โ€” the approximate sample in the stream corresponding to the start of the LTC frame.
  • 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).
  • ltcsnd_sample_t sample_max โ€” the maximum input sample signal for this frame (0..255)
  • ltcsnd_sample_t sample_min โ€” the minimum input sample signal for this frame (0..255)
  • double volume โ€” the volume of the input signal in dbFS

struct SMPTETimecode

Human readable time representation, decimal values. ๐ŸŒธ yes queen, actual numbers you can read with your eyeballs.

Examples

example_encode.c, ltcdecode.c, and ltcencode.c. โœจ

Data Fields:

  • unsigned char days โ€” day of month 1..31
  • unsigned char frame โ€” sub-second frame 0..(FPS - 1)
  • unsigned char hours โ€” hour 0..23
  • unsigned char mins โ€” minute 0..60
  • unsigned char months โ€” valid months are 1..12
  • unsigned char secs โ€” second 0..60
  • char timezone[6] โ€” the timezone 6bytes: '+HHMM' textual representation
  • unsigned char years โ€” LTC-date uses 2-digit year 00.99.

โœจ Macro Definition Documentation โœจ

#define DEPRECATED_EXPORT

#define LTC_FRAME_BIT_COUNT 80

eighty. iconic number. she said what she said. ๐Ÿ’…


๐Ÿฆ‹ Typedef Documentation ๐Ÿฆ‹

  • typedef long long int ltc_off_t โ€” sample-count offset - 64bit wide
  • typedef struct LTCDecoder LTCDecoder โ€” Opaque structure see: ltc_decoder_create, ltc_decoder_free
  • typedef struct LTCEncoder LTCEncoder โ€” Opaque structure see: ltc_encoder_create, ltc_encoder_free
  • typedef struct LTCFrame LTCFrame โ€” see LTCFrame
  • typedef struct LTCFrameExt LTCFrameExt โ€” see LTCFrameExt
  • typedef unsigned char ltcsnd_sample_t โ€” default audio sample type: 8bit unsigned (mono)
  • typedef struct SMPTETimecode SMPTETimecode โ€” see SMPTETimecode

๐ŸŒˆ Enumeration Type Documentation ๐ŸŒˆ

enum LTC_BG_FLAGS

encoder and LTCframe <> timecode operation flags

Enumerator

  • LTC_USE_DATE โ€” LTCFrame <> SMPTETimecode converter and LTCFrame increment/decrement use date, also set BGF2 to '1' when encoder is initialized or re-initialized (unless LTC_BGF_DONT_TOUCH is given)
  • LTC_TC_CLOCK โ€” the Timecode is wall-clock aka freerun. This also sets BGF1 (unless LTC_BGF_DONT_TOUCH is given)
  • LTC_BGF_DONT_TOUCH โ€” encoder init or re-init does not touch the BGF bits (initial values after initialization is zero)
  • LTC_NO_PARITY โ€” parity bit is left untouched when setting or in/decrementing the encoder frame-number

enum LTC_TV_STANDARD

the standard defines the assignment of the binary-group-flag bits โ€” basically only 25fps is different, but other standards defined in the SMPTE spec have been included for completeness. ๐Ÿซถ

Enumerator

  • LTC_TV_525_60 โ€” 30fps
  • LTC_TV_625_50 โ€” 25fps
  • LTC_TV_1125_60 โ€” 30fps
  • LTC_TV_FILM_24 โ€” 24fps

๐Ÿ’œ Function Documentation ๐Ÿ’œ

LTCDecoder* ltc_decoder_create (int apv, int queue_size)

Create a new LTC decoder.

Parameters

  • apv โ€” audio-frames per video frame. This is just used for initial settings, the speed is tracked dynamically. setting this in the right ballpark is needed to properly decode the first LTC frame in a sequence.
  • queue_size โ€” length of the internal queue to store decoded frames to SMPTEDecoderWrite.

Returns

decoder handle or NULL if out-of-memory

Examples

ltcdecode.c.


int ltc_decoder_free (LTCDecoder * d)

Release memory of decoder. ๐Ÿ’– Give that decoder its final rest, bestie.

Parameters

  • d โ€” decoder handle

Examples

ltcdecode.c.


void ltc_decoder_queue_flush (LTCDecoder * d)

Remove all LTC frames from the internal queue. ๐Ÿงน Itโ€™s giving clean slate.

Parameters

  • d โ€” decoder handle

int ltc_decoder_queue_length (LTCDecoder * d)

Count number of LTC frames currently in the queue. ๐Ÿ”ข How many frames are vibing in there?

Parameters

  • d โ€” decoder handle

Returns

number of queued frames


int ltc_decoder_read (LTCDecoder * d, LTCFrameExt * frame)

Decoded LTC frames are placed in a queue. This function retrieves a frame from the queue, and stores it at LTCFrameExt* ๐Ÿ’… like pulling a lil gift out of the queue.

Parameters

  • d โ€” decoder handle
  • frame โ€” the decoded LTC frame is copied there

Returns

1 on success or 0 when no frames queued.

Examples

ltcdecode.c.


void ltc_decoder_write (LTCDecoder * d, ltcsnd_sample_t * buf, size_t size, ltc_off_t posinfo)

Feed the LTC decoder with new audio samples. ๐ŸŽง Snack time for the decoder.

Parse raw audio for LTC timestamps. Once a complete LTC frame has been decoded it is pushed into a queue (ltc_decoder_read)

Parameters

  • d โ€” decoder handle
  • buf โ€” pointer to ltcsnd_sample_t - unsigned 8 bit mono audio data
  • size โ€” size number of samples to parse
  • posinfo โ€” (optional, recommended) sample-offset in the audio-stream. It is added to off_start, off_end in LTCFrameExt and should be monotonic (ie incremented by size for every call to ltc_decoder_write)

Examples

ltcdecode.c.


void ltc_decoder_write_double (LTCDecoder * d, double * buf, size_t size, ltc_off_t posinfo)

Wrapper around ltc_decoder_write that accepts 64-bit floating point audio samples. Note: internally libltc uses 8 bit only. So yeah, itโ€™s a fancy wrapper but the inside is still 8-bit core.

Parameters

  • d โ€” decoder handle
  • buf โ€” pointer to audio sample data
  • size โ€” number of samples to parse
  • posinfo โ€” (optional, recommended) sample-offset in the audio-stream.

void ltc_decoder_write_float (LTCDecoder * d, float * buf, size_t size, ltc_off_t posinfo)

Wrapper around ltc_decoder_write that accepts 32-bit floating point audio samples. Note: internally libltc uses 8 bit only. Same tea, different cup.

Parameters

  • d โ€” decoder handle
  • buf โ€” pointer to audio sample data
  • size โ€” number of samples to parse
  • posinfo โ€” (optional, recommended) sample-offset in the audio-stream.

void ltc_decoder_write_s16 (LTCDecoder * d, short * buf, size_t size, ltc_off_t posinfo)

Wrapper around ltc_decoder_write that accepts signed 16 bit audio samples. Note: internally libltc uses 8 bit only. Still 8-bit under the hood, no cap.

Parameters

  • d โ€” decoder handle
  • buf โ€” pointer to audio sample data
  • size โ€” number of samples to parse
  • posinfo โ€” (optional, recommended) sample-offset in the audio-stream.

void ltc_decoder_write_u16 (LTCDecoder * d, unsigned short * buf, size_t size, ltc_off_t posinfo)

Wrapper around ltc_decoder_write that accepts unsigned 16 bit audio samples. Note: internally libltc uses 8 bit only. You already know: 8 bit inside.

Parameters

  • d โ€” decoder handle
  • buf โ€” pointer to audio sample data
  • size โ€” number of samples to parse
  • posinfo โ€” (optional, recommended) sample-offset in the audio-stream.

void ltc_encoder_buffer_flush (LTCEncoder * e)

reset the write-pointer of the encoder-buffer ๐Ÿ”„ Rewind that pointer, periodt.

Parameters

  • e โ€” encoder handle

int ltc_encoder_copy_buffer (LTCEncoder * e, ltcsnd_sample_t * buf)

Copy the accumulated encoded audio to the given sample-buffer and flush the internal buffer. Grab the audio, then wipe the slate.

Parameters

  • e โ€” encoder handle
  • buf โ€” place to store the audio-samples, needs to be large enough to hold ltc_encoder_get_buffersize bytes

Returns

the number of bytes written to the memory area pointed to by buf.

Examples

example_encode.c.


LTCEncoder* ltc_encoder_create (double sample_rate, double fps, enum LTC_TV_STANDARD standard, int flags)

Allocate and initialize LTC audio encoder. New encoder just dropped.

calls ltc_encoder_reinit internally see, see notes there.

Parameters

  • sample_rate โ€” audio sample rate (eg. 48000)
  • fps โ€” video-frames per second (e.g. 25.0)
  • standard โ€” the TV standard to use for Binary Group Flag bit position
  • flags โ€” binary combination of LTC_BG_FLAGS

Examples

example_encode.c, and ltcencode.c.


int ltc_encoder_dec_timecode (LTCEncoder * e)

Move the encoder to the previous timecode frame. This is useful for encoding reverse LTC. uses ltc_frame_decrement() internally. Going backwards, but make it iconic.


int ltc_encoder_encode_byte (LTCEncoder * e, int byte, double speed)

Generate LTC audio for given byte of the LTC-frame and place it into the internal buffer. One byte at a time, chefโ€™s kiss.

see ltc_encoder_copy_buffer and ltc_encoder_get_bufferptr

LTC has 10 bytes per frame: 0 <= bytecnt < 10 use SMPTESetTime(..) to set the current frame before Encoding. see tests/encoder.c for an example.

The default output signal is @ -3dBFS (38..218 at 8 bit unsigned). see also ltc_encoder_set_volume

if speed is < 0, the bits are encoded in reverse. slowdown > 10.0 requires custom buffer sizes; see ltc_encoder_set_buffersize

Parameters

  • e โ€” encoder handle
  • byte โ€” byte of the LTC-frame to encode 0..9
  • speed โ€” vari-speed, < 1.0 faster, > 1.0 slower ; must be != 0

Returns

0 on success, -1 if byte is invalid or buffer overflow (speed > 10.0)

Examples

example_encode.c.


void ltc_encoder_encode_frame (LTCEncoder * e)

Encode a full LTC frame at fixed speed. This is equivalent to calling ltc_encoder_encode_byte 10 times for bytes 0..9 with speed 1.0. Full frame, no skips.

โš ๏ธ Note: The internal buffer must be empty before calling this function. Otherwise it may overflow. This is usually the case if it is read with ltc_encoder_copy_buffer after calling this function.

The default internal buffersize is exactly one full LTC frame at speed 1.0.

Parameters

  • e โ€” encoder handle

Examples

example_encode.c, and ltcencode.c.


void ltc_encoder_encode_reversed_frame (LTCEncoder * e)

Encode a full LTC frame at fixed speed -1. This is equivalent to calling ltc_encoder_encode_byte 10 times for bytes 9..0, rolling in reverse at speed 1. Backwards frame, but make it slay.

โš ๏ธ Note: The internal buffer must be empty before calling this function. Otherwise it may overflow. This is usually the case if it is read with ltc_encoder_copy_buffer after calling this function.

Parameters

  • e โ€” encoder handle

int ltc_encoder_end_encode (LTCEncoder * e)

Terminate encoding and add final transition Wrap it up with a lil transition, bestie.

Refer to the image at LTCFrame. In this example, the encoded data starts and ends with a rising edge. The transition at the start of tne next frame marks the end of the previous frame. This transition is encoded at the beginning of a frame. However if there is no additional frame to be encoded, a final terminating transition has to be added.

Since LTC is usually sent as continuous stream, this is of no concern. However for a fixed, finite duration to be encoded, this method adds a terminating transition to the buffer.

After this one must either call ltc_encoder_reset() or ltc_encoder_free.

Parameters

  • e โ€” encoder handle

Returns

0 on success, -1 if byte is invalid or buffer overflow (speed > 10.0)


void ltc_encoder_free (LTCEncoder * e)

Release memory of the encoder. Say bye to the encoder, it ate.

Parameters

  • e โ€” encoder handle

Examples

example_encode.c, and ltcencode.c.


int ltc_encoder_get_buffer (LTCEncoder * e, ltcsnd_sample_t * buf)

Copy the accumulated encoded audio to the given sample-buffer and flush the internal buffer. Old-school version. Deprecated.

Parameters

  • e โ€” encoder handle
  • buf โ€” place to store the audio-samples, needs to be large enough to hold ltc_encoder_get_buffersize bytes

Returns

the number of bytes written to the memory area pointed to by buf.

Deprecated

please use ltc_encoder_copy_buffer() instead


int ltc_encoder_get_bufferptr (LTCEncoder * e, ltcsnd_sample_t ** buf, int flush)

Retrieve a pointer to the accumulated encoded audio-data. Pointer reveal ๐Ÿ’…

Parameters

  • e โ€” encoder handle
  • buf โ€” if set, the pointer to encoder-buffer
  • flush โ€” call ltc_encoder_buffer_flush - reset the buffer write-pointer

Returns

the number of valid bytes in the buffer

Examples

example_encode.c, and ltcencode.c.


size_t ltc_encoder_get_buffersize (LTCEncoder * e)

Query the length of the internal buffer. It is allocated to hold audio-frames for exactly one LTC frame for the given sample-rate and frame-rate. ie. (1 + sample-rate / fps) bytes

Note this returns the total size of the buffer, not the used/free part. See also ltc_encoder_get_bufferptr

Parameters

  • e โ€” encoder handle

Returns

size of the allocated internal buffer.

Examples

example_encode.c.


ltcsnd_sample_t* ltc_encoder_get_bufptr (LTCEncoder * e, int * size, int flush)

Retrieve a pointer to the accumulated encoded audio-data. Another pointer moment.

Parameters

  • e โ€” encoder handle
  • size โ€” if set, the number of valid bytes in the buffer is stored there
  • flush โ€” call ltc_encoder_buffer_flush - reset the buffer write-pointer

Returns

pointer to encoder-buffer

Deprecated

please use ltc_encoder_get_bufferptr() instead


double ltc_encoder_get_filter (LTCEncoder * e)

Get encoder signal rise-time / signal filtering How fast does the signal rise? Letโ€™s find out.

Parameters

  • e โ€” encoder handle

Returns

the signal rise-time in us (10^(-6) sec)


void ltc_encoder_get_frame (LTCEncoder * e, LTCFrame * f)

Low-level access to the encoder internal LTCFrame data Peek behind the curtain.

Parameters

  • e โ€” encoder handle
  • f โ€” return LTC frame data

void ltc_encoder_get_timecode (LTCEncoder * e, SMPTETimecode * t)

Query the current encoder timecode. What time is it? Encoder time.

Note: the decoder stores its internal state in an LTC-frame, this function converts that LTC-Frame into SMPTETimecode on demand. see also ltc_encoder_get_frame.

Parameters

  • e โ€” encoder handle
  • t โ€” is set to current timecode

double ltc_encoder_get_volume (LTCEncoder * e)

Query the volume of the generated LTC signal Turn it up? Or down? Find out.

Parameters

  • e โ€” encoder handle

Returns

the volume in dB full-scale (<= 0.0)


int ltc_encoder_inc_timecode (LTCEncoder * e)

Move the encoder to the next timecode frame. uses ltc_frame_increment() internally. Forward march, timecode edition.

Examples

example_encode.c, and ltcencode.c.

ltc_encoder_reinit() ๐Ÿ’ซ

int ltc_encoder_reinit (LTCEncoder * e, double sample_rate, double fps, enum LTC_TV_STANDARD standard, int flags)

okay so this one lets you change the encoder settings without re-allocating any of the library's internal data structures โ€” which makes it realtime safe, bestie, no surprise allocation jumpscares mid-stream. ๐Ÿซถ

changing the fps and or sample-rate does imply a buffer flush, plus a biphase state reset. so like, know that going in.

This call will fail if the internal buffer is too small to hold one full LTC frame. so pls use ltc_encoder_set_buffersize to prepare an internal buffer big enough to accommodate all the sample_rate / fps combos you'd wanna re-init to. โœจ

The LTC frame payload data is not modified by this call โ€” however, the flag-bits of the LTC-Frame are updated: if fps equals to 29.97 or 30000.0/1001.0, the LTCFrame's 'dfbit' bit is set to 1 to indicate drop-frame timecode.

Unless the LTC_BGF_DONT_TOUCH flag is set, the BGF1 is set or cleared depending on LTC_TC_CLOCK and BGF0,2 according to LTC_USE_DATE and the given standard. col_frame is cleared and the parity recomputed (unless LTC_NO_PARITY is given).

Parameters

  • e โ€” encoder handle
  • sample_rate โ€” audio sample rate (eg. 48000)
  • fps โ€” video-frames per second (e.g. 25.0)
  • standard โ€” the TV standard to use for Binary Group Flag bit position
  • flags โ€” binary combination of LTC_BG_FLAGS

Examples

ltcencode.c.


ltc_encoder_reset() ๐ŸŒ€

void ltc_encoder_reset (LTCEncoder * e)

reset encoder state. flushes buffer, resets biphase state. clean slate energy, we love a fresh start. ๐Ÿ’…

Parameters

  • e โ€” encoder handle

ltc_encoder_set_buffersize() ๐Ÿ“ฆ

int ltc_encoder_set_buffersize (LTCEncoder * e, double sample_rate, double fps)

Configure a custom size for the internal buffer.

This is needed if you're planning to call ltc_encoder_reinit() or if you want to keep more than one LTC frame's worth of data in the library's internal buffer. lowkey essential for the re-init girlies.

The buffer-size is (1 + sample_rate / fps) bytes. resizing the internal buffer will flush all existing data in it โ€” alike ltc_encoder_buffer_flush. so yeah, everything in there is getting evicted, no cap. ๐Ÿ—‘๏ธ

Parameters

  • e โ€” encoder handle
  • sample_rate โ€” audio sample rate (eg. 48000)
  • fps โ€” video-frames per second (e.g. 25.0)

Returns

0 on success, -1 if allocation fails (which makes the encoder unusable, call ltc_encoder_free or realloc the buffer)

Examples

ltcencode.c.


ltc_encoder_set_bufsize() โš ๏ธ

int ltc_encoder_set_bufsize (LTCEncoder * e, double sample_rate, double fps)

Configure a custom size for the internal buffer.

This is needed if you are planning to call ltc_encoder_reinit() or if you want to keep more than one LTC frame's worth of data in the library's internal buffer.

The buffer-size is (1 + sample_rate / fps) bytes. resizing the internal buffer will flush all existing data in it - alike ltc_encoder_buffer_flush.

Parameters

  • e โ€” encoder handle
  • sample_rate โ€” audio sample rate (eg. 48000)
  • fps โ€” video-frames per second (e.g. 25.0)

Returns

0 on success, -1 if allocation fails (which makes the encoder unusable, call ltc_encoder_free or realloc the buffer)

Deprecated โ€” please use ltc_encoder_set_buffersize() instead. it's the same vibe but with an s in the middle. iconic of them tbh. ๐Ÿ™ˆ

ltc_encoder_set_filter() ๐ŸŒŠ

void ltc_encoder_set_filter (LTCEncoder * e, double rise_time)

Set encoder signal rise-time / signal filtering.

LTC signal should have a rise time of 40us +/- 10 us. by default the encoder honors this and low-pass filters the output depending on the sample-rate. so it's already doing the right thing unless you go messing with it.

If you want a perfect square wave, set 'rise_time' to 0. go off, sharp edges. ๐Ÿ”ฅ

Note: ltc_encoder_reinit resets the filter-time-constant to use the default 40us for the given sample-rate, overriding any value previously set with ltc_encoder_set_filter. so your custom filter? gone. poof. ๐Ÿ’€

Parameters

  • e โ€” encoder handle
  • rise_time โ€” the signal rise-time in us (10^(-6) sec), set to 0 for perfect square wave, default 40.0

Examples

ltcencode.c.


ltc_encoder_set_frame() ๐ŸŽฌ

void ltc_encoder_set_frame (LTCEncoder * e, LTCFrame * f)

Low-level access to the internal LTCFrame data. we're going under the hood, bestie.

Note: be careful to about f->dfbit, the encoder sets this [only] upon initialization. so if you're hand-feeding frames, this one's on you. ๐Ÿ‘€

Parameters

  • e โ€” encoder handle
  • f โ€” LTC frame data to use

ltc_encoder_set_timecode() โฑ๏ธ

void ltc_encoder_set_timecode (LTCEncoder * e, SMPTETimecode * t)

Set the encoder LTC-frame to the given SMPTETimecode. The next call to ltc_encoder_encode_byte or ltc_encoder_encode_frame will encode this time to LTC audio-samples.

Internally this call uses ltc_time_to_frame because the LTCEncoder operates on LTCframes only. see als ltc_encoder_set_frame. yeah that "als" is literally in the source, we keep it, it's part of the lore. ๐Ÿ’–

Parameters

  • e โ€” encoder handle
  • t โ€” timecode to set.

Examples

example_encode.c, and ltcencode.c.


ltc_encoder_set_user_bits() ๐ŸŽ€

void ltc_encoder_set_user_bits (LTCEncoder * e, unsigned long data)

Set the user-bits of the frame to the given data.

The data should be a 32-bits unsigned integer. It is written LSB first continiously int the eight user fields. (typos preserved, we respect the original ๐Ÿ’…)

Parameters

  • e โ€” encoder handle
  • data โ€” the data to write

ltc_encoder_set_volume() ๐Ÿ”Š

int ltc_encoder_set_volume (LTCEncoder * e, double dBFS)

Set the volume of the generated LTC signal. turn it up, turn it down, we vibe either way.

typically LTC is sent at 0dBu ; in EBU callibrated systems that corresponds to -18dBFS. - by default libltc creates -3dBFS.

since libltc generated 8bit audio-data, the minimum dBFS is about -42dB which corresponds to 1 bit. so tiny. microscopic. a single bit of signal. ๐Ÿ˜ญ

0dB corresponds to a signal range of 127 1..255 with 128 at the center.

Parameters

  • e โ€” encoder handle
  • dBFS โ€” the volume in dB full-scale (<= 0.0)

Returns

0 on success, -1 if the value was out of range

Examples

ltcencode.c.


ltc_frame_alignment() ๐Ÿ“

ltc_off_t ltc_frame_alignment (double samples_per_frame, enum LTC_TV_STANDARD standard)

LTCFrame sample alignment offset.

There is a relative offset of the LTC-Frame start and the TV-frame. The first bit of a LTC frame corresponds to a specific line in the actual video frame. When decoding this offset needs to be subtracted from the LTC-frame's audio-sample-time to match the TV-frame's start position. so it's giving "yes we're slightly misaligned and you have to do math about it." ๐Ÿงฎ

For film frames or HDV the offset is zero.

Parameters

  • samples_per_frame โ€” audio-samples per timecode-frame (eg. 1920 = 48000/25)
  • standard โ€” the TV standard

Returns

offset in samples


ltc_frame_decrement() โช

int ltc_frame_decrement (LTCFrame * frame, int fps, enum LTC_TV_STANDARD standard, int flags)

Decrement the timecode by one Frame (1/framerate seconds) and set the Frame's parity bit accordingly (see ltc_frame_set_parity). going backwards in time, iconic.

Parameters

  • frame โ€” the LTC-timecode to decrement
  • fps โ€” integer framerate (for drop-frame-timecode set frame->dfbit and round-up the fps).
  • standard โ€” the TV standard to use for parity bit assignment if set to 1 the 25fps standard is enabled and LTC Frame bit 59 instead of 27 is used for the parity. It only has only has effect flag bit 4 (LTC_NO_PARITY) is cleared. (double "only has" is canon, leaving it in ๐Ÿซถ)
  • flags โ€” binary combination of LTC_BG_FLAGS - here only LTC_USE_DATE and LTC_NO_PARITY are relevant. if the bit 0 is set (1) interpret user-data as date and decrement date if timecode wraps at 24h. (Note: leap-years are taken into account, but since the year is two-digit only, the 100,400yr rules are ignored. '00' is assumed to be year 2000 which was a leap year.) bit 3 (8) indicates that the parity bit should not be touched

Returns

1 if timecode was wrapped around at 23:59:59:ff, 0 otherwise


ltc_frame_get_user_bits() ๐Ÿ”

unsigned long ltc_frame_get_user_bits (LTCFrame * f)

Get the 32-bits unsigned integer from the user-data bits. The data should be written LSB first in the frame. pull those bits out, bestie. ๐Ÿซณ

Parameters

  • f โ€” LTC frame data to parse

ltc_frame_increment() โฉ

int ltc_frame_increment (LTCFrame * frame, int fps, enum LTC_TV_STANDARD standard, int flags)

Increment the timecode by one Frame (1/framerate seconds) and set the Frame's parity bit accordingly (see ltc_frame_set_parity). time moves forward, we move with it. โœจ

Parameters

  • frame โ€” the LTC-timecode to increment
  • fps โ€” integer framerate (for drop-frame-timecode set frame->dfbit and round-up the fps).
  • standard โ€” the TV standard to use for parity bit assignment if set to 1 the 25fps standard is enabled and LTC Frame bit 59 instead of 27 is used for the parity. It only has only has effect flag bit 4 (LTC_NO_PARITY) is cleared.
  • flags โ€” binary combination of LTC_BG_FLAGS - here only LTC_USE_DATE and LTC_NO_PARITY are relevant. If the bit 0 (1) is set (1) interpret user-data as date and increment date if timecode wraps after 24h. (Note: leap-years are taken into account, but since the year is two-digit only, the 100,400yr rules are ignored. '00' is assumed to be year 2000 which was a leap year.)

Returns

1 if timecode was wrapped around after 23:59:59:ff, 0 otherwise


ltc_frame_parse_bcg_flags() ๐Ÿณ๏ธ

int ltc_frame_parse_bcg_flags (LTCFrame * frame, enum LTC_TV_STANDARD standard)

Parse Binary Coded Group Flags into standard independent format: bit 0 (1) - BGF 0, bit 1 (2) - BGF 1, bit 2 (4) - BGF 2. cute little flags, very demure, very mindful. ๐ŸŽ€

Parameters

  • frame โ€” LTC frame data analyze
  • standard โ€” the TV standard to use -- see LTCFrame for BGF assignment

Returns

LTC Binary Group Flags


ltc_frame_reset() ๐Ÿงผ

void ltc_frame_reset (LTCFrame * frame)

Reset all values of a LTC FRAME to zero, except for the sync-word (0x3FFD) at the end. The sync word is set according to architecture (big/little endian). Also set the Frame's parity bit accordingly (see ltc_frame_set_parity). everything zeroed except the one thing that has to stay. main character behavior honestly. ๐Ÿ‘‘

Parameters

  • frame โ€” the LTCFrame to reset

ltc_frame_set_parity() โš–๏ธ

void ltc_frame_set_parity (LTCFrame * frame, enum LTC_TV_STANDARD standard)

Set the parity of the LTC frame.

Bi-Phase Mark Phase Correction bit (bit 27 - or 59) may be set or cleared so that that every 80-bit word contains an even number of zeroes. (double "that that", kept, love that for us ๐Ÿ’œ) This means that the phase in every Sync Word will be the same.

This is merely cosmetic; the motivation to keep the polarity of the waveform constant is to make finding the Sync Word visibly (on a scope) easier. so like, it's not deep, it's just so your scope looks tidy. โœจ

There is usually no need to call this function directly. The encoder utility functions ltc_time_to_frame, ltc_frame_increment and ltc_frame_decrement include a call to it. so let them handle it, bestie, you're free. ๐Ÿฆ‹

Parameters

  • frame โ€” the LTC to analyze and set or clear the biphase_mark_phase_correction bit.
  • standard โ€” If 1 (aka LTC_TV_625_50) , the 25fps mode (bit 59 - aka binary_group_flag_bit2) is used, otherwise the 30fps, 24fps mode (bit 27 -- biphase_mark_phase_correction) is set or cleared.

ltc_frame_to_time() ๐Ÿ•ฐ๏ธ

void ltc_frame_to_time (SMPTETimecode * stime, LTCFrame * frame, int flags)

Convert binary LTCFrame into SMPTETimecode struct. glow-up from bits to something readable, we love a transformation. ๐ŸŒˆ

Parameters

  • stime โ€” output
  • frame โ€” input
  • flags โ€” binary combination of LTC_BG_FLAGS - here only LTC_USE_DATE is relevant. if LTC_USE_DATE is set, the user-fields in LTCFrame will be parsed into the date variable of SMPTETimecode. otherwise the date information in the SMPTETimecode is set to zero.

Examples

ltcdecode.c.


ltc_time_to_frame() ๐Ÿ”„

void ltc_time_to_frame (LTCFrame * frame, SMPTETimecode * stime, enum LTC_TV_STANDARD standard, int flags)

Translate SMPTETimecode struct into its binary LTC representation and set the LTC frame's parity bit accordingly (see ltc_frame_set_parity)

โœจ Parameters โœจ

okay bestie, here's what you're feeding this function, and every single one matters ๐Ÿ’…

  • frame output โ€” this is the frame getting set. she's the one being written to, the main character, the one who receives everything. ๐Ÿ‘‘
  • stime input โ€” the timecode coming in. the source material, the tea being poured. ๐Ÿซ–
  • standard โ€” the TV standard to use for parity bit assignment. yes, this actually changes how your parity bits get placed, so don't just yeet any old value in there. ๐ŸŽ€
  • flags โ€” a binary combination of LTC_BG_FLAGS. ngl this one's got a little nuance so listen up:
    • only LTC_USE_DATE and LTC_NO_PARITY are relevant here. the rest are justโ€ฆ not doing anything in this context. ๐Ÿ™ˆ
    • if LTC_USE_DATE is given, the user-fields in LTCFrame will be set from the date in SMPTETimecode. if it's not given, the user-bits are not modified โ€” they stay exactly as they were, no touchy. ๐Ÿ’–
and the big one, fr fr: all non-timecode fields remain untouched โ€” except for the parity bit, unless LTC_NO_PARITY is given. so like, if you're precious about your parity bit and you want it left alone, you know what to pass. otherwise she's getting rewritten whether you like it or not. ๐Ÿ’€

๐Ÿ’œ Author

Generated automatically by Doxygen for libltc from the source code. no human hands typed this, she just spawned into existence fully formed. iconic behavior honestly. โœจ


and that's the whole page bestie!! ๐ŸŽ‰ we did it!! this was libltc version 1.3.2, dated Sun Sep 4 2022, and it's the ltc.h(3) manual page โ€” go forth and write some flawless timecode, you absolute legend ๐Ÿฆ‹๐Ÿ’–๐Ÿ‘‘