update libltc to v1.1.4-4-gb034a23 (endianess issue)
authorRobin Gareus <robin@gareus.org>
Wed, 9 Sep 2015 14:54:26 +0000 (16:54 +0200)
committerRobin Gareus <robin@gareus.org>
Wed, 9 Sep 2015 14:54:26 +0000 (16:54 +0200)
libs/libltc/encoder.c
libs/libltc/ltc.c
libs/libltc/ltc/ltc.h
libs/libltc/timecode.c

index fce2a0ce51fcfc5773bd6fda52800ca80b15928d..4e6168ea9bddc97a6bb0f3cf35829cdb9908d5f4 100644 (file)
@@ -32,7 +32,9 @@ static int addvalues(LTCEncoder *e, int n) {
        const ltcsnd_sample_t tgtval = e->state ? e->enc_hi : e->enc_lo;
 
        if (e->offset + n >= e->bufsize) {
+#if 0
                fprintf(stderr, "libltc: buffer overflow: %d/%lu\n", (int) e->offset, (unsigned long) e->bufsize);
+#endif
                return 1;
        }
 
index c0dd5a7d2c7098269d526c8a698919b50463db06..1a662f9744a04aa594c50106145ab7fea07dc019 100644 (file)
@@ -65,24 +65,31 @@ void ltc_decoder_write(LTCDecoder *d, ltcsnd_sample_t *buf, size_t size, ltc_off
        decode_ltc(d, buf, size, posinfo);
 }
 
+#define LTC_CONVERSION_BUF_SIZE 1024
+
 #define LTCWRITE_TEMPLATE(FN, FORMAT, CONV) \
 void ltc_decoder_write_ ## FN (LTCDecoder *d, FORMAT *buf, size_t size, ltc_off_t posinfo) { \
-       ltcsnd_sample_t tmp[1024]; \
-       size_t remain = size; \
-       while (remain > 0) { \
-               int c = (remain > 1024) ? 1024 : remain; \
+       ltcsnd_sample_t tmp[LTC_CONVERSION_BUF_SIZE]; \
+       size_t copyStart = 0; \
+       while (copyStart < size) { \
                int i; \
-               for (i=0; i<c; i++) { \
+               int c = size - copyStart; \
+               c = (c > LTC_CONVERSION_BUF_SIZE) ? LTC_CONVERSION_BUF_SIZE : c; \
+               for (i=0; i < c; i++) { \
                        tmp[i] = CONV; \
                } \
-               decode_ltc(d, tmp, c, posinfo + (ltc_off_t)c); \
-               remain -= c; \
+               decode_ltc(d, tmp, c, posinfo + (ltc_off_t)copyStart); \
+               copyStart += c; \
        } \
 }
 
-LTCWRITE_TEMPLATE(float, float, 128 + (buf[i] * 127.0))
-LTCWRITE_TEMPLATE(s16, short, 128 + (buf[i] >> 8))
-LTCWRITE_TEMPLATE(u16, short, (buf[i] >> 8))
+LTCWRITE_TEMPLATE(float, float, 128 + (buf[copyStart+i] * 127.0))
+/* this relies on the compiler to use an arithemtic right-shift for signed values */
+LTCWRITE_TEMPLATE(s16, short, 128 + (buf[copyStart+i] >> 8))
+/* this relies on the compiler to use a logical right-shift for unsigned values */
+LTCWRITE_TEMPLATE(u16, unsigned short, (buf[copyStart+i] >> 8))
+
+#undef LTC_CONVERSION_BUF_SIZE
 
 int ltc_decoder_read(LTCDecoder* d, LTCFrameExt* frame) {
        if (!frame) return -1;
index 3ffbeeb3f6d09064f24f94c39ab81e2f62d82038..726b0ca9f7152b16671f013431fbb3d762f61e92 100644 (file)
@@ -13,7 +13,7 @@
    @author Robin Gareus <robin@gareus.org>
    @copyright
 
-   Copyright (C) 2006-2012 Robin Gareus <robin@gareus.org>
+   Copyright (C) 2006-2014 Robin Gareus <robin@gareus.org>
 
    Copyright (C) 2008-2009 Jan Weiß <jan@geheimwerk.de>
 
 extern "C" {
 #endif
 
+#if defined _WIN32 && !defined(__LITTLE_ENDIAN__)
+#define __LITTLE_ENDIAN__
+#endif
+
+#ifdef __BIG_ENDIAN__
+# define LTC_BIG_ENDIAN
+#elif defined _BIG_ENDIAN
+# define LTC_BIG_ENDIAN
+#elif defined __BYTE_ORDER__
+# if __BYTE_ORDER__ ==  __ORDER_BIG_ENDIAN__
+#  define LTC_BIG_ENDIAN
+# endif
+#elif !defined __LITTLE_ENDIAN__
+# include <endian.h> // machine/endian.h
+# if (defined __BYTE_ORDER__ && defined __ORDER_BIG_ENDIAN__ && __BYTE_ORDER__ ==  __ORDER_BIG_ENDIAN__)
+#  define LTC_BIG_ENDIAN
+# endif
+#endif
+
 #include <stddef.h> /* size_t */
 
 #ifndef DOXYGEN_IGNORE
 /* libltc version */
-#define LIBLTC_VERSION "1.1.1"
+#define LIBLTC_VERSION "1.1.4"
 #define LIBLTC_VERSION_MAJOR  1
 #define LIBLTC_VERSION_MINOR  1
-#define LIBLTC_VERSION_MICRO  1
+#define LIBLTC_VERSION_MICRO  4
 
 /* interface revision number
  * http://www.gnu.org/software/libtool/manual/html_node/Updating-version-info.html
  */
 #define LIBLTC_CUR 11
-#define LIBLTC_REV  1
+#define LIBLTC_REV  3
 #define LIBLTC_AGE  0
 #endif /* end DOXYGEN_IGNORE */
 
@@ -159,7 +178,7 @@ typedef long long int ltc_off_t;
  * further information: http://www.philrees.co.uk/articles/timecode.htm
  * and http://www.barney-wol.net/time/timecode.html
  */
-#if (defined __BIG_ENDIAN__ && !defined DOXYGEN_IGNORE)
+#if (defined LTC_BIG_ENDIAN && !defined DOXYGEN_IGNORE)
 // Big Endian version, bytes are "upside down"
 struct LTCFrame {
        unsigned int user1:4;
@@ -449,7 +468,7 @@ void ltc_decoder_write_s16(LTCDecoder *d, short *buf, size_t size, ltc_off_t pos
  * @param size number of samples to parse
  * @param posinfo (optional, recommended) sample-offset in the audio-stream.
  */
-void ltc_decoder_write_u16(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);
 
 /**
  * Decoded LTC frames are placed in a queue. This function retrieves
index 83e8e1926b8e92bc5fbac1004f0a0f43ae9f006a..c1524380eb2df8ffd91e5aed8991eabc66fee4a7 100644 (file)
@@ -216,7 +216,7 @@ void ltc_time_to_frame(LTCFrame* frame, SMPTETimecode* stime, enum LTC_TV_STANDA
 void ltc_frame_reset(LTCFrame* frame) {
        memset(frame, 0, sizeof(LTCFrame));
        // syncword = 0x3FFD
-#ifdef __BIG_ENDIAN__
+#ifdef LTC_BIG_ENDIAN
        // mirrored BE bit order: FCBF
        frame->sync_word = 0xFCBF;
 #else