Skip to content

Commit

Permalink
Add self-test encode -> decode, test ltc_encoder_end_encode()
Browse files Browse the repository at this point in the history
  • Loading branch information
x42 committed Sep 4, 2022
1 parent fa8597f commit e71afb3
Show file tree
Hide file tree
Showing 3 changed files with 107 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ config.*
*.swp
tests/ltcdecode
tests/ltcencode
tests/ltcloop
tests/output.raw

doc/html/
Expand Down
9 changes: 8 additions & 1 deletion tests/Makefile.am
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
check_PROGRAMS = ltcencode ltcdecode
check_PROGRAMS = ltcencode ltcdecode ltcloop

CLEANFILES = output.raw atconfig

Expand All @@ -18,6 +18,11 @@ ltcencode_SOURCES = ltcencode.c
ltcencode_CFLAGS=-g -Wall
ltcencode_LDADD = $(LIBLTCDIR)/libltc.la -lm

ltcloop_SOURCES = ltcloop.c
ltcloop_CFLAGS=-g -Wall
ltcloop_LDADD = $(LIBLTCDIR)/libltc.la -lm


check: $(check_PROGRAMS)
date
uname -a
Expand All @@ -30,5 +35,7 @@ check: $(check_PROGRAMS)
@echo "-----------------------------------------------------------------"
./ltcdecode $(srcdir)/timecode.raw 882 | diff -q $(srcdir)/timecode.txt -
@echo "-----------------------------------------------------------------"
./ltcloop
@echo "-----------------------------------------------------------------"
@echo " ${PACKAGE}-${VERSION} passed all tests."
@echo "-----------------------------------------------------------------"
98 changes: 98 additions & 0 deletions tests/ltcloop.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
/**
@brief self-test encode and decode LTC
@file ltcloop.c
@author Robin Gareus <[email protected]>
Copyright (C) 2006-2022 Robin Gareus <[email protected]>
Copyright (C) 2008-2009 Jan <[email protected]>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser Public License as published by
the Free Software Foundation; either version 3, 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 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, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <ltc.h>


int main(int argc, char **argv) {
double fps = 25;
double samplerate = 48000;
int vframe_cnt = 0;
int vframe_end = 1;

LTCEncoder* encoder = ltc_encoder_create (samplerate, fps, 0, 0);
ltc_encoder_set_filter(encoder, 0);
ltc_encoder_set_volume(encoder, -3.0);

int frame_size = ltc_encoder_get_buffersize (encoder) * sizeof (ltcsnd_sample_t);

ltcsnd_sample_t* buf = malloc ((1 + vframe_end) * frame_size);

/* Encode */
int off = 0;
for (vframe_cnt = 0; vframe_cnt < vframe_end; ++ vframe_cnt) {
ltc_encoder_encode_frame (encoder);
off += ltc_encoder_copy_buffer (encoder, &buf[off]);
ltc_encoder_inc_timecode (encoder);
}

/* finish frame */
ltc_encoder_end_encode (encoder);
off += ltc_encoder_copy_buffer (encoder, &buf[off]);
ltc_encoder_free(encoder);

#if 0
printf ("Encoded: %d [bytes]\n", off);
ltcsnd_sample_t last = 0;
for (int i = 0; i < off; ++i) {
if (buf[i] != last) {
printf ("%3d : %d\n", i, buf[i]);
last = buf[i];
}
}
#endif

/* Decode */
LTCDecoder* decoder = ltc_decoder_create(samplerate / fps, vframe_end);
LTCFrameExt frame;
ltc_decoder_write (decoder, buf, off, 0);

while (ltc_decoder_read (decoder, &frame)) {
SMPTETimecode stime;
ltc_frame_to_time (&stime, &frame.ltc, 0);
--vframe_cnt;

#if 0
printf("%02d:%02d:%02d%c%02d | %8lld %8lld%s\n",
stime.hours,
stime.mins,
stime.secs,
(frame.ltc.dfbit) ? '.' : ':',
stime.frame,
frame.off_start,
frame.off_end,
frame.reverse ? " R" : ""
);
#endif
}

ltc_decoder_free (decoder);
free (buf);

return vframe_cnt == 0 ? 0 : -1;
}

0 comments on commit e71afb3

Please sign in to comment.