Skip to content

Commit

Permalink
Add API to terminate encoding and add final transition - #65
Browse files Browse the repository at this point in the history
  • Loading branch information
x42 committed Sep 4, 2022
1 parent 0217c50 commit 500ba0e
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/encoder.c
Original file line number Diff line number Diff line change
Expand Up @@ -106,3 +106,21 @@ int encode_byte(LTCEncoder *e, int byte, double speed) {

return err;
}

int encode_transition(LTCEncoder *e) {
if (e->offset + 1 >= e->bufsize) {
return -1;
}

int off = e->offset;

int n = e->bufsize - e->offset - 1;
e->state = !e->state;
int err = addvalues(e, n);

if (e->filter_const <= 0) {
e->offset = off + 1;
}

return err;
}
1 change: 1 addition & 0 deletions src/encoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,4 @@ struct LTCEncoder {
};

int encode_byte(LTCEncoder *e, int byte, double speed);
int encode_transition(LTCEncoder *e);
4 changes: 4 additions & 0 deletions src/ltc.c
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,10 @@ int ltc_encoder_encode_byte(LTCEncoder *e, int byte, double speed) {
return encode_byte(e, byte, speed);
}

int ltc_encoder_end_encode(LTCEncoder *e) {
return encode_transition(e);
}

void ltc_encoder_encode_frame(LTCEncoder *e) {
int byte;
for (byte = 0 ; byte < 10 ; byte++) {
Expand Down
21 changes: 21 additions & 0 deletions src/ltc.h
Original file line number Diff line number Diff line change
Expand Up @@ -826,6 +826,27 @@ void ltc_encoder_set_filter(LTCEncoder *e, double rise_time);
*/
int ltc_encoder_encode_byte(LTCEncoder *e, int byte, double speed);

/**
* 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)
*/
int ltc_encoder_end_encode(LTCEncoder *e);

/**
* Encode a full LTC frame at fixed speed.
* This is equivalent to calling \ref ltc_encoder_encode_byte 10 times for
Expand Down

0 comments on commit 500ba0e

Please sign in to comment.