diff options
Diffstat (limited to 'ltc')
-rw-r--r-- | ltc/libltc.lib | bin | 0 -> 44586 bytes | |||
-rw-r--r-- | ltc/ltc.odin | 726 |
2 files changed, 726 insertions, 0 deletions
diff --git a/ltc/libltc.lib b/ltc/libltc.lib Binary files differnew file mode 100644 index 0000000..5919fce --- /dev/null +++ b/ltc/libltc.lib diff --git a/ltc/ltc.odin b/ltc/ltc.odin new file mode 100644 index 0000000..247ea8e --- /dev/null +++ b/ltc/ltc.odin @@ -0,0 +1,726 @@ +package ltc + +import "core:c" + +foreign import lib "libltc.lib" + +#assert(size_of(b32) == size_of(c.int)) + + +/* libltc version */ +VERSION :: "1.3.2" +VERSION_MAJOR :: 1 +VERSION_MINOR :: 3 +VERSION_MICRO :: 2 + +/* interface revision number + * http://www.gnu.org/software/libtool/manual/html_node/Updating-version-info.html + */ +CUR :: 13 +REV :: 0 +AGE :: 2 + + +/** + * default audio sample type: 8bit unsigned (mono) + */ +snd_sample_t :: u8 // used to be distinct + +/** + * sample-count offset - 64bit wide + */ +off_t :: i64 + +FRAME_BIT_COUNT :: 80 + +Frame :: bit_field [10]u8 { + frame_units: u32 | 4, // SMPTE framenumber BCD unit 0..9 + user1: u32 | 4, + + frame_tens: u32 | 2, // SMPTE framenumber BCD tens 0..3 + dfbit: bool | 1, // indicated drop-frame timecode + col_frame: bool | 1, // colour-frame: timecode intentionally synchronized to a colour TV field sequence + user2: u32 | 4, + + secs_units: u32 | 4, // SMPTE seconds BCD unit 0..9 + user3: u32 | 4, + + secs_tens: u32 | 3, // SMPTE seconds BCD tens 0..6 + biphase_mark_phase_correction: bool | 1, // see note on Bit 27 in description and \ref ltc_frame_set_parity . + user4: u32 | 4, + + mins_units: u32 | 4, // SMPTE minutes BCD unit 0..9 + user5: u32 | 4, + + mins_tens: u32 | 3, // SMPTE minutes BCD tens 0..6 + binary_group_flag_bit0: bool | 1, // indicate user-data char encoding, see table above - bit 43 + user6: u32 | 4, + + hours_units: u32 | 4, // SMPTE hours BCD unit 0..9 + user7: u32 | 4, + + hours_tens: u32 | 2, // SMPTE hours BCD tens 0..2 + binary_group_flag_bit1: bool | 1, // indicate timecode is local time wall-clock, see table above - bit 58 + binary_group_flag_bit2: bool | 1, // indicate user-data char encoding (or parity with 25fps), see table above - bit 59 + user8: u32 | 4, + + sync_word: u16 | 16, +}; + +/** 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. + */ +TV_STANDARD :: enum c.int { + TV_525_60, ///< 30fps + TV_625_50, ///< 25fps + TV_1125_60,///< 30fps + TV_FILM_24, ///< 24fps +}; + +/** encoder and LTCframe <> timecode operation flags */ +BG_FLAGS :: distinct bit_set[BG_FLAG; c.int] +BG_FLAG :: enum c.int { + USE_DATE = 0, // 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) + TC_CLOCK = 1, // the Timecode is wall-clock aka freerun. This also sets BGF1 (unless LTC_BGF_DONT_TOUCH is given) + BGF_DONT_TOUCH = 2, // encoder init or re-init does not touch the BGF bits (initial values after initialization is zero) + NO_PARITY = 3, // parity bit is left untouched when setting or in/decrementing the encoder frame-number +} + + +/** + * 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. + * + * \ref 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. + * + */ +FrameExt:: struct { + ltc: Frame, // the actual LTC frame. see \ref LTCFrame + off_start: off_t, // \anchor off_start the approximate sample in the stream corresponding to the start of the LTC frame. + off_end: off_t, // \anchor off_end the sample in the stream corresponding to the end of the LTC frame. + reverse: c.int, // 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). + biphase_tics: [FRAME_BIT_COUNT]f32, // 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 = (\ref off_end - \ref off_start + 1). + sample_min: snd_sample_t, // the minimum input sample signal for this frame (0..255) + sample_max: snd_sample_t, // the maximum input sample signal for this frame (0..255) + volume: f64, // the volume of the input signal in dbFS +} + + +/** + * Human readable time representation, decimal values. + */ +SMPTETimecode :: struct { + timezone: [6]u8 `fmt:"s,0"`, ///< the timezone 6bytes: "+HHMM" textual representation + years: u8, // LTC-date uses 2-digit year 00.99 + months: u8, // valid months are 1..12 + days: u8, // day of month 1..31 + + hours: u8, // hour 0..23 + mins: u8, // minute 0..60 + secs: u8, // second 0..60 + frame: u8, // sub-second frame 0..(FPS - 1) +} + +SAMPLE_CENTER :: 128 // unsigned 8 bit. + +Decoder :: struct { + queue: [^]FrameExt, + queue_len: c.int, + queue_read_off: c.int, + queue_write_off: c.int, + + biphase_state: u8, + biphase_prev: u8, + snd_to_biphase_state: u8, + snd_to_biphase_cnt: c.int, ///< counts the samples in the current period + snd_to_biphase_lmt: c.int, ///< specifies when a state-change is considered biphase-clock or 2*biphase-clock + snd_to_biphase_period: f64, ///< track length of a period - used to set snd_to_biphase_lmt + + snd_to_biphase_min: snd_sample_t, + snd_to_biphase_max: snd_sample_t, + + decoder_sync_word: u16, + ltc_frame: Frame, + bit_cnt: c.int, + + frame_start_off: off_t, + frame_start_prev: off_t, + + biphase_tics: [FRAME_BIT_COUNT]f64, + biphase_tic: c.int, +}; + +Encoder :: struct { + fps: f64, + sample_rate: f64, + filter_const: f64, + flags: BG_FLAGS, + standard: TV_STANDARD, + enc_lo, enc_hi: snd_sample_t, + + offset: c.size_t, + bufsize: c.size_t, + buf: [^]snd_sample_t, + + state: u8, + + samples_per_clock: f64, + samples_per_clock_2: f64, + sample_remainder: f64, + + f: Frame, +} + +@(default_calling_convention="c") +@(link_prefix="ltc_") +foreign lib { + /** + * Convert binary LTCFrame into SMPTETimecode struct + * + * @param stime output + * @param frame input + * @param flags binary combination of \ref 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. + */ + frame_to_time :: proc(stime: ^SMPTETimecode, frame: ^Frame, flags: BG_FLAGS) --- + + /** + * Translate SMPTETimecode struct into its binary LTC representation + * and set the LTC frame's parity bit accordingly (see \ref ltc_frame_set_parity) + * + * @param frame output - the frame to be set + * @param stime input - timecode input + * @param standard the TV standard to use for parity bit assignment + * @param flags binary combination of \ref LTC_BG_FLAGS - here only LTC_USE_DATE and LTC_NO_PARITY are relevant. + * if LTC_USE_DATE is given, user-fields in LTCFrame will be set from the date in SMPTETimecode, + * otherwise the user-bits are not modified. All non-timecode fields remain untouched - except for the parity bit + * unless LTC_NO_PARITY is given. + */ + time_to_frame :: proc(frame: ^Frame, stime: ^SMPTETimecode, standard: TV_STANDARD, flags: BG_FLAGS) --- + + /** + * 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 \ref ltc_frame_set_parity) + * @param frame the LTCFrame to reset + */ + frame_reset :: proc(frame: ^Frame) --- + + /** + * Increment the timecode by one Frame (1/framerate seconds) + * and set the Frame's parity bit accordingly (see \ref ltc_frame_set_parity) + * + * @param frame the LTC-timecode to increment + * @param fps integer framerate (for drop-frame-timecode set frame->dfbit and round-up the fps). + * @param 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. + * @param flags binary combination of \ref 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.) + * @return 1 if timecode was wrapped around after 23:59:59:ff, 0 otherwise + */ + frame_increment :: proc(frame: ^Frame, fps: c.int , standard: TV_STANDARD, flags: BG_FLAGS) -> b32 --- + + /** + * Decrement the timecode by one Frame (1/framerate seconds) + * and set the Frame's parity bit accordingly (see \ref ltc_frame_set_parity) + * + * @param frame the LTC-timecode to decrement + * @param fps integer framerate (for drop-frame-timecode set frame->dfbit and round-up the fps). + * @param 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. + * @param flags binary combination of \ref 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 + * @return 1 if timecode was wrapped around at 23:59:59:ff, 0 otherwise + */ + frame_decrement :: proc(frame: ^Frame, fps: c.int, standard: TV_STANDARD, flags: BG_FLAGS) -> c.int --- + + @(link_name="decode_ltc") + decode_ltc :: proc(d: ^Decoder, sound: [^]snd_sample_t, size: c.size_t, posinfo: off_t) --- + + /** + * Create a new LTC decoder. + * + * @param 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. + * @param queue_size length of the internal queue to store decoded frames + * to SMPTEDecoderWrite. + * @return decoder handle or NULL if out-of-memory + */ + decoder_create :: proc(apv: c.int, queue_size: c.int) -> ^Decoder --- + + + /** + * Release memory of decoder. + * @param d decoder handle + */ + decoder_free :: proc(d: ^Decoder) -> c.int --- + + /** + * Feed the LTC decoder with new audio samples. + * + * Parse raw audio for LTC timestamps. Once a complete LTC frame has been + * decoded it is pushed into a queue (\ref ltc_decoder_read) + * + * @param d decoder handle + * @param buf pointer to ltcsnd_sample_t - unsigned 8 bit mono audio data + * @param size size number of samples to parse + * @param posinfo (optional, recommended) sample-offset in the audio-stream. It is added to \ref off_start, \ref off_end in \ref LTCFrameExt and should be monotonic (ie incremented by \p size for every call to ltc_decoder_write) + */ + decoder_write :: proc(d: ^Decoder, + buf: [^]snd_sample_t, size: c.size_t, + posinfo: off_t) --- + + /** + * Wrapper around \ref ltc_decoder_write that accepts 64-bit floating point + * audio samples. Note: internally libltc uses 8 bit only. + * + * @param d decoder handle + * @param buf pointer to audio sample data + * @param size number of samples to parse + * @param posinfo (optional, recommended) sample-offset in the audio-stream. + */ + decoder_write_double :: proc(d: ^Decoder, buf: [^]f64, size: c.size_t, posinfo: off_t) --- + + /** + * Wrapper around \ref ltc_decoder_write that accepts 32-bit floating point + * audio samples. Note: internally libltc uses 8 bit only. + * + * @param d decoder handle + * @param buf pointer to audio sample data + * @param size number of samples to parse + * @param posinfo (optional, recommended) sample-offset in the audio-stream. + */ + decoder_write_float :: proc(d: ^Decoder, buf: [^]f32, size: c.size_t, posinfo: off_t) --- + + /** + * Wrapper around \ref ltc_decoder_write that accepts signed 16 bit + * audio samples. Note: internally libltc uses 8 bit only. + * + * @param d decoder handle + * @param buf pointer to audio sample data + * @param size number of samples to parse + * @param posinfo (optional, recommended) sample-offset in the audio-stream. + */ + decoder_write_s16 :: proc(d: ^Decoder, buf: [^]i16, size: c.size_t, posinfo: off_t) --- + + /** + * Wrapper around \ref ltc_decoder_write that accepts unsigned 16 bit + * audio samples. Note: internally libltc uses 8 bit only. + * + * @param d decoder handle + * @param buf pointer to audio sample data + * @param size number of samples to parse + * @param posinfo (optional, recommended) sample-offset in the audio-stream. + */ + decoder_write_u16 :: proc(d: ^Decoder, buf: [^]u16, size: c.size_t, posinfo: off_t) --- + + /** + * Decoded LTC frames are placed in a queue. This function retrieves + * a frame from the queue, and stores it at LTCFrameExt* + * + * @param d decoder handle + * @param frame the decoded LTC frame is copied there + * @return 1 on success or 0 when no frames queued. + */ + decoder_read :: proc(d: ^Decoder, frame: ^FrameExt) -> c.int --- + + /** + * Remove all LTC frames from the internal queue. + * @param d decoder handle + */ + decoder_queue_flush :: proc(d: ^Decoder) --- + + /** + * Count number of LTC frames currently in the queue. + * @param d decoder handle + * @return number of queued frames + */ + decoder_queue_length :: proc(d: ^Decoder) -> c.int --- + + + @(link_name="encode_byte") + encode_byte :: proc(e: ^Encoder, byte: c.int, speed: f64) -> c.int --- + @(link_name="encode_transition") + encode_transition :: proc(e: ^Encoder) -> c.int --- + + + /** + * Allocate and initialize LTC audio encoder. + * + * calls \ref ltc_encoder_reinit internally see, see notes there. + * + * @param sample_rate audio sample rate (eg. 48000) + * @param fps video-frames per second (e.g. 25.0) + * @param standard the TV standard to use for Binary Group Flag bit position + * @param flags binary combination of \ref LTC_BG_FLAGS + */ + encoder_create :: proc(sample_rate: f64, fps: f64, standard: TV_STANDARD, flags: BG_FLAGS) -> ^Encoder --- + + /** + * Release memory of the encoder. + * @param e encoder handle + */ + encoder_free :: proc(e: ^Encoder) --- + + /** + * Set the encoder LTC-frame to the given SMPTETimecode. + * The next call to \ref ltc_encoder_encode_byte or + * \ref ltc_encoder_encode_frame will encode this time to LTC audio-samples. + * + * Internally this call uses \ref ltc_time_to_frame because + * the LTCEncoder operates on LTCframes only. + * see als \ref ltc_encoder_set_frame + * + * @param e encoder handle + * @param t timecode to set. + */ + encoder_set_timecode :: proc(e: ^Encoder, t: ^SMPTETimecode) --- + + /** + * Query the current encoder timecode. + * + * Note: the decoder stores its internal state in an LTC-frame, + * this function converts that LTC-Frame into SMPTETimecode on demand. + * see also \ref ltc_encoder_get_frame. + * + * @param e encoder handle + * @param t is set to current timecode + */ + encoder_get_timecode :: proc(e: ^Encoder, t: ^SMPTETimecode) --- + + /** + * 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. + * + * @param e encoder handle + * @param data the data to write + */ + encoder_set_user_bits :: proc(e: ^Encoder, data: c.ulong) --- + + /** + * Get the 32-bits unsigned integer from the user-data bits. + * The data should be written LSB first in the frame + * + * @param f LTC frame data to parse + */ + frame_get_user_bits :: proc(f: ^Frame) -> c.ulong --- + + /** + * Move the encoder to the next timecode frame. + * uses \ref ltc_frame_increment() internally. + */ + encoder_inc_timecode :: proc(e: ^Encoder) -> c.int --- + + /** + * Move the encoder to the previous timecode frame. + * This is useful for encoding reverse LTC. + * uses \ref ltc_frame_decrement() internally. + */ + encoder_dec_timecode :: proc(e: ^Encoder) -> c.int --- + + /** + * Low-level access to the internal LTCFrame data. + * + * Note: be careful to about f->dfbit, the encoder sets this [only] upon + * initialization. + * + * @param e encoder handle + * @param f LTC frame data to use + */ + encoder_set_frame :: proc(e: ^Encoder, f: ^Frame) --- + + /** + * Low-level access to the encoder internal LTCFrame data + * + * @param e encoder handle + * @param f return LTC frame data + */ + encoder_get_frame :: proc(e: ^Encoder, f: ^Frame) --- + + /** + * Copy the accumulated encoded audio to the given + * sample-buffer and flush the internal buffer. + * + * @param e encoder handle + * @param buf place to store the audio-samples, needs to be large enough + * to hold \ref ltc_encoder_get_buffersize bytes + * @return the number of bytes written to the memory area + * pointed to by buf. + */ + encoder_copy_buffer :: proc(e: ^Encoder, buf: [^]snd_sample_t) -> c.int --- + + + /** + * Retrieve a pointer to the accumulated encoded audio-data. + * + * @param e encoder handle + * @param buf if set, the pointer to encoder-buffer + * @param flush call \ref ltc_encoder_buffer_flush - reset the buffer write-pointer + * @return the number of valid bytes in the buffer + */ + encoder_get_bufferptr :: proc(e: ^Encoder, buf: ^[^]snd_sample_t, flush: b32) -> c.int --- + + /** + * reset the write-pointer of the encoder-buffer + * @param e encoder handle + */ + encoder_buffer_flush :: proc(e: ^Encoder) --- + + /** + * 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 \ref ltc_encoder_get_bufferptr + * + * @param e encoder handle + * @return size of the allocated internal buffer. + */ + encoder_get_buffersize :: proc(e: ^Encoder) -> c.size_t --- + + /** + * Change the encoder settings without re-allocating any + * library internal data structure (realtime safe). + * changing the fps and or sample-rate implies a buffer flush, + * and biphase state reset. + * + * This call will fail if the internal buffer is too small + * to hold one full LTC frame. Use \ref ltc_encoder_set_buffersize to + * prepare an internal buffer large enough to accommodate all + * sample_rate, fps combinations that you would like to 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). + * + * @param e encoder handle + * @param sample_rate audio sample rate (eg. 48000) + * @param fps video-frames per second (e.g. 25.0) + * @param standard the TV standard to use for Binary Group Flag bit position + * @param flags binary combination of \ref LTC_BG_FLAGS + */ + encoder_reinit :: proc(e: ^Encoder, sample_rate: f64, fps: f64, standard: TV_STANDARD, flags: BG_FLAGS) -> c.int --- + + /** + * reset ecoder state. + * flushes buffer, reset biphase state + * + * @param e encoder handle + */ + encoder_reset :: proc(e: ^Encoder) --- + + /** + * Configure a custom size for the internal buffer. + * + * This is needed if you are planning to call \ref 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 \ref ltc_encoder_buffer_flush. + * + * @param e encoder handle + * @param sample_rate audio sample rate (eg. 48000) + * @param fps video-frames per second (e.g. 25.0) + * @return 0 on success, -1 if allocation fails (which makes the + * encoder unusable, call \ref ltc_encoder_free or realloc the buffer) + */ + encoder_set_buffersize :: proc(e: ^Encoder, sample_rate: f64, fps: f64) -> c.int --- + + /** + * Query the volume of the generated LTC signal + * + * @param e encoder handle + * @return the volume in dB full-scale (<= 0.0) + */ + encoder_get_volume :: proc(e: ^Encoder) -> f64 --- + + /** + * Set the volume of the generated LTC signal + * + * 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. + * + * 0dB corresponds to a signal range of 127 + * 1..255 with 128 at the center. + * + * @param e encoder handle + * @param dBFS the volume in dB full-scale (<= 0.0) + * @return 0 on success, -1 if the value was out of range + */ + encoder_set_volume :: proc(e: ^Encoder, dBFS: f64) -> c.int --- + + /** + * Get encoder signal rise-time / signal filtering + * + * @param e encoder handle + * @return the signal rise-time in us (10^(-6) sec) + */ + encoder_get_filter :: proc(e: ^Encoder) -> f64 --- + + /** + * 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. + * + * If you want a perfect square wave, set 'rise_time' to 0. + * + * Note \ref ltc_encoder_reinit resets the filter-time-constant to use + * the default 40us for the given sample-rate, overriding any value + * previously set with \ref ltc_encoder_set_filter + * + * @param e encoder handle + * @param rise_time the signal rise-time in us (10^(-6) sec), set to 0 for perfect square wave, default 40.0 + */ + encoder_set_filter :: proc(e: ^Encoder, rise_time: f64) --- + + /** + * Generate LTC audio for given byte of the LTC-frame and + * place it into the internal buffer. + * + * see \ref ltc_encoder_copy_buffer and \ref 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 \ref ltc_encoder_set_volume + * + * if speed is < 0, the bits are encoded in reverse. + * slowdown > 10.0 requires custom buffer sizes; see \ref ltc_encoder_set_buffersize + * + * @param e encoder handle + * @param byte byte of the LTC-frame to encode 0..9 + * @param speed vari-speed, < 1.0 faster, > 1.0 slower ; must be != 0 + * + * @return 0 on success, -1 if byte is invalid or buffer overflow (speed > 10.0) + */ + encoder_encode_byte :: proc(e: ^Encoder, byte: c.int, speed: f64) -> c.int --- + + /** + * Terminate encoding and add final transition + * + * Refer to the image at \ref 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 \ref ltc_encoder_reset() or \ref ltc_encoder_free. + * + * @param e encoder handle + * @return 0 on success, -1 if byte is invalid or buffer overflow (speed > 10.0) + */ + encoder_end_encode :: proc(e: ^Encoder) -> c.int --- + + /** + * Encode a full LTC frame at fixed speed. + * This is equivalent to calling \ref ltc_encoder_encode_byte 10 times for + * bytes 0..9 with speed 1.0. + * + * 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 + * \ref ltc_encoder_copy_buffer after calling this function. + * + * The default internal buffersize is exactly one full LTC frame at speed 1.0. + * + * @param e encoder handle + */ + encoder_encode_frame :: proc(e: ^Encoder) --- + + /** + * Encode a full LTC frame at fixed speed -1. + * This is equivalent to calling \ref ltc_encoder_encode_byte 10 times for + * bytes 9..0, rolling in reverse at speed 1. + * + * 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 + * \ref ltc_encoder_copy_buffer after calling this function. + * + * @param e encoder handle + */ + encoder_encode_reversed_frame :: proc(e: ^Encoder) --- + + /** + * 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. + * 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. + * + * There is usually no need to call this function directly. The encoder utility + * functions \ref ltc_time_to_frame, \ref ltc_frame_increment and + * \ref ltc_frame_decrement include a call to it. + * + * @param frame the LTC to analyze and set or clear the biphase_mark_phase_correction bit. + * @param 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. + */ + frame_set_parity :: proc(frame: ^Frame, standard: TV_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 + * + * @param frame LTC frame data analyze + * @param standard the TV standard to use -- see \ref LTCFrame for BGF assignment + * @return LTC Binary Group Flags + */ + frame_parse_bcg_flags :: proc(frame: ^Frame, standard: TV_STANDARD) -> c.int --- + + /** + * 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. + * + * For film frames or HDV the offset is zero. + * + * @param samples_per_frame audio-samples per timecode-frame (eg. 1920 = 48000/25) + * @param standard the TV standard + * @return offset in samples + */ + frame_alignment :: proc(samples_per_frame: f64, standard: TV_STANDARD) -> off_t --- +} + |