Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build for Visual Studio #55

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 69 additions & 0 deletions src/Makefile.msc
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# Makefile for libltc using Microsoft (Visual) C
#
# Usage:
# nmake -f Makefile.msc (standard build)
#
# run within src folder!

# The toplevel directory of the source tree.
#
TOP = .

# optional build flags
LOC =

# variables
STATICLIB = libltc.lib
SHAREDLIB = libltc.dll
IMPLIB = libltc.lib

CC = cl
AS = ml
LD = link
AR = lib
RC = rc
CFLAGS = -nologo /MT -W3 -O2 -Oy- -Fd"libltc" $(LOC) /GF -DWIN32 /TC
WFLAGS = -D_CRT_SECURE_NO_DEPRECATE -D_CRT_NONSTDC_NO_DEPRECATE
ASFLAGS = -coff -Zi $(LOC)
LDFLAGS = -nologo -incremental:no -opt:ref
ARFLAGS = -nologo
RCFLAGS = /dWIN32 /r

OBJS = ltc.obj encoder.obj decoder.obj timecode.obj
OBJA =

#


# targets
all: $(STATICLIB) $(SHAREDLIB)

$(STATICLIB): $(OBJS) $(OBJA)
$(AR) $(ARFLAGS) -out:$@ $(OBJS) $(OBJA)

$(SHAREDLIB): $(OBJS) $(OBJA) libltc.res
$(LD) $(LDFLAGS) -dll -implib:$(IMPLIB) \
-out:$@ $(OBJS) $(OBJA) -def:$(TOP)/libltc.def libltc.res


libltc.res: $(TOP)/libltc.rc
$(RC) $(RCFLAGS) /fo$@ $(TOP)/libltc.rc

{$(TOP)}.c.obj:
$(CC) -c $(WFLAGS) $(CFLAGS) $<




# cleanup
clean:
-del $(STATICLIB)
-del $(SHAREDLIB)
-del $(IMPLIB)
-del *.obj
-del *.res
-del *.exp
-del *.exe
-del *.pdb
-del *.manifest

20 changes: 13 additions & 7 deletions src/decoder.c
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,13 @@
#endif

#if (!defined INFINITY && defined _MSC_VER)

#ifdef __cplusplus
#define INFINITY std::numeric_limits<double>::infinity()
#else
// #define INFINITY
#endif

#endif
#if (!defined INFINITY && defined HUGE_VAL)
#define INFINITY HUGE_VAL
Expand All @@ -125,7 +131,7 @@ static void parse_ltc(LTCDecoder *d, unsigned char bit, ltc_off_t offset, ltc_of
memset(&d->ltc_frame, 0, sizeof(LTCFrame));

if (d->frame_start_prev < 0) {
d->frame_start_off = posinfo - d->snd_to_biphase_period;
d->frame_start_off = (ltc_off_t) (posinfo - d->snd_to_biphase_period);
} else {
d->frame_start_off = d->frame_start_prev;
}
Expand Down Expand Up @@ -153,7 +159,7 @@ static void parse_ltc(LTCDecoder *d, unsigned char bit, ltc_off_t offset, ltc_of
((unsigned char*)&d->ltc_frame)[k] = bo;
}

d->frame_start_off += ceil(d->snd_to_biphase_period);
d->frame_start_off += (ltc_off_t) ceil(d->snd_to_biphase_period);
d->bit_cnt--;
}

Expand Down Expand Up @@ -243,9 +249,9 @@ static void parse_ltc(LTCDecoder *d, unsigned char bit, ltc_off_t offset, ltc_of
d->queue[d->queue_write_off].biphase_tics[bc] = d->biphase_tics[btc];
}

d->queue[d->queue_write_off].off_start = d->frame_start_off - 16 * d->snd_to_biphase_period;
d->queue[d->queue_write_off].off_end = posinfo + (ltc_off_t) offset - 1LL - 16 * d->snd_to_biphase_period;
d->queue[d->queue_write_off].reverse = (LTC_FRAME_BIT_COUNT >> 3) * 8 * d->snd_to_biphase_period;
d->queue[d->queue_write_off].off_start = (ltc_off_t) (d->frame_start_off - 16 * d->snd_to_biphase_period);
d->queue[d->queue_write_off].off_end = (ltc_off_t) (posinfo + (ltc_off_t) offset - 1LL - 16 * d->snd_to_biphase_period);
d->queue[d->queue_write_off].reverse = (int) ((LTC_FRAME_BIT_COUNT >> 3) * 8 * d->snd_to_biphase_period);
d->queue[d->queue_write_off].volume = calc_volume_db(d);
d->queue[d->queue_write_off].sample_min = d->snd_to_biphase_min;
d->queue[d->queue_write_off].sample_max = d->snd_to_biphase_max;
Expand All @@ -261,10 +267,10 @@ static void parse_ltc(LTCDecoder *d, unsigned char bit, ltc_off_t offset, ltc_of

static inline void biphase_decode2(LTCDecoder *d, ltc_off_t offset, ltc_off_t pos) {

d->biphase_tics[d->biphase_tic] = d->snd_to_biphase_period;
d->biphase_tics[d->biphase_tic] = (float) d->snd_to_biphase_period;
d->biphase_tic = (d->biphase_tic + 1) % LTC_FRAME_BIT_COUNT;
if (d->snd_to_biphase_cnt <= 2 * d->snd_to_biphase_period) {
pos -= (d->snd_to_biphase_period - d->snd_to_biphase_cnt);
pos -= (ltc_off_t) (d->snd_to_biphase_period - d->snd_to_biphase_cnt);
}

if (d->snd_to_biphase_state == d->biphase_prev) {
Expand Down
32 changes: 22 additions & 10 deletions src/encoder.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,21 @@
* add values to the output buffer
*/
static int addvalues(LTCEncoder *e, int n) {

double tcf;
ltcsnd_sample_t * wave;

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;
}

ltcsnd_sample_t * const wave = &(e->buf[e->offset]);
const double tcf = e->filter_const;
wave = &(e->buf[e->offset]);
tcf = e->filter_const;
if (tcf > 0) {
/* low-pass-filter
* LTC signal should have a rise time of 40 us +/- 10 us.
Expand All @@ -51,10 +55,12 @@ static int addvalues(LTCEncoder *e, int n) {
* e->cutoff = 1.0 -exp( -1.0 / (sample_rate * .000020 / exp(1.0)) );
*/
int i;
int m;

ltcsnd_sample_t val = SAMPLE_CENTER;
int m = (n+1)>>1;
m = (n+1)>>1;
for (i = 0 ; i < m ; i++) {
val = val + tcf * (tgtval - val);
val = (ltcsnd_sample_t) ( val + tcf * (tgtval - val));
wave[n-i-1] = wave[i] = val;
}
} else {
Expand All @@ -67,14 +73,20 @@ static int addvalues(LTCEncoder *e, int n) {
}

int encode_byte(LTCEncoder *e, int byte, double speed) {

int err = 0;
unsigned char c;
unsigned char b;
double spc;
double sph;

if (byte < 0 || byte > 9) return -1;
if (speed ==0) return -1;

int err = 0;
const unsigned char c = ((unsigned char*)&e->f)[byte];
unsigned char b = (speed < 0)?128:1; // bit
const double spc = e->samples_per_clock * fabs(speed);
const double sph = e->samples_per_clock_2 * fabs(speed);
c = ((unsigned char*)&e->f)[byte];
b = (speed < 0)?128:1; // bit
spc = e->samples_per_clock * fabs(speed);
sph = e->samples_per_clock_2 * fabs(speed);

do
{
Expand Down
39 changes: 39 additions & 0 deletions src/libltc.def
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
; libltc data compression library
EXPORTS
ltc_decoder_create
ltc_decoder_free
ltc_decoder_queue_flush
ltc_decoder_queue_length
ltc_decoder_read
ltc_decoder_write
ltc_decoder_write_float
ltc_decoder_write_s16
ltc_decoder_write_u16
ltc_encoder_buffer_flush
ltc_encoder_create
ltc_encoder_dec_timecode
ltc_encoder_encode_byte
ltc_encoder_encode_frame
ltc_encoder_free
ltc_encoder_get_buffer
ltc_encoder_get_buffersize
ltc_encoder_get_bufptr
ltc_encoder_get_frame
ltc_encoder_get_timecode
ltc_encoder_inc_timecode
ltc_encoder_reinit
ltc_encoder_reset
ltc_encoder_set_bufsize
ltc_encoder_set_filter
ltc_encoder_set_frame
ltc_encoder_set_timecode
ltc_encoder_set_user_bits
ltc_encoder_set_volume
ltc_frame_alignment
ltc_frame_decrement
ltc_frame_get_user_bits
ltc_frame_increment
ltc_frame_reset
ltc_frame_set_parity
ltc_frame_to_time
ltc_time_to_frame
40 changes: 40 additions & 0 deletions src/libltc.rc
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#include <winver.h>
#include "ltc.h"

#ifdef GCC_WINDRES
VS_VERSION_INFO VERSIONINFO
#else
VS_VERSION_INFO VERSIONINFO MOVEABLE IMPURE LOADONCALL DISCARDABLE
#endif
FILEVERSION LIBLTC_VERSION_MAJOR,LIBLTC_VERSION_MINOR,LIBLTC_VERSION_MICRO,0
PRODUCTVERSION LIBLTC_VERSION_MAJOR,LIBLTC_VERSION_MINOR,LIBLTC_VERSION_MICRO,0
FILEFLAGSMASK VS_FFI_FILEFLAGSMASK
#ifdef _DEBUG
FILEFLAGS 1
#else
FILEFLAGS 0
#endif
FILEOS VOS__WINDOWS32
FILETYPE VFT_DLL
FILESUBTYPE 0 // not used
BEGIN
BLOCK "StringFileInfo"
BEGIN
BLOCK "040904E4"
//language ID = U.S. English, char set = Windows, Multilingual
BEGIN
VALUE "FileDescription", "Linear/Logitudinal Time Code (LTC) Library\0"
VALUE "FileVersion", LIBLTC_VERSION "\0"
VALUE "InternalName", "libltc.dll\0"
VALUE "LegalCopyright", "Copyright (C) Robin Gareus and Jan Weiß\0"
VALUE "OriginalFilename", "libltc.dll\0"
VALUE "ProductName", "libltc\0"
VALUE "ProductVersion", LIBLTC_VERSION "\0"
VALUE "Comments", "For more information visit https://x42.github.io/libltc/\0"
END
END
BLOCK "VarFileInfo"
BEGIN
VALUE "Translation", 0x0409, 1252
END
END
Loading