From d334539c99f65aa4e2f65d053635199b043554e6 Mon Sep 17 00:00:00 2001 From: drowe67 Date: Sat, 9 Jun 2012 01:59:35 +0000 Subject: [PATCH] support for cross compiling windows DLL git-svn-id: https://svn.code.sf.net/p/freetel/code@535 01035d8c-6547-0410-b346-abe4f91aad63 --- codec2-dev/README | 1 + codec2-dev/src/codec2.c | 12 ++++---- codec2-dev/src/codec2.h | 31 +++++++++++++------- codec2-dev/src/fdmdv.c | 18 ++++++------ codec2-dev/src/fdmdv.h | 30 +++++++++++++------- codec2-dev/win32/Makefile | 59 +++++++++++++++++++++++++++++++++++++++ 6 files changed, 116 insertions(+), 35 deletions(-) create mode 100644 codec2-dev/win32/Makefile diff --git a/codec2-dev/README b/codec2-dev/README index 46e8a3e8..10f0a761 100644 --- a/codec2-dev/README +++ b/codec2-dev/README @@ -72,6 +72,7 @@ Directories unittest - unit test source code voicing - hand-estimated voicing files, used for development wav - speech files in wave file format + win32 - Support for building Windows DLL version of Codec 2 and FDMDV libraries TODO ---- diff --git a/codec2-dev/src/codec2.c b/codec2-dev/src/codec2.c index a5ff1f97..1aa7cff3 100644 --- a/codec2-dev/src/codec2.c +++ b/codec2-dev/src/codec2.c @@ -81,7 +81,7 @@ void codec2_decode_1200(struct CODEC2 *c2, short speech[], const unsigned char * \*---------------------------------------------------------------------------*/ -struct CODEC2 *codec2_create(int mode) +struct CODEC2 * WIN32SUPPORT codec2_create(int mode) { struct CODEC2 *c2; int i,l; @@ -141,7 +141,7 @@ struct CODEC2 *codec2_create(int mode) \*---------------------------------------------------------------------------*/ -void codec2_destroy(struct CODEC2 *c2) +void WIN32SUPPORT codec2_destroy(struct CODEC2 *c2) { assert(c2 != NULL); nlp_destroy(c2->nlp); @@ -158,7 +158,7 @@ void codec2_destroy(struct CODEC2 *c2) \*---------------------------------------------------------------------------*/ -int codec2_bits_per_frame(struct CODEC2 *c2) { +int WIN32SUPPORT codec2_bits_per_frame(struct CODEC2 *c2) { if (c2->mode == CODEC2_MODE_2400) return 48; if (c2->mode == CODEC2_MODE_1400) @@ -180,7 +180,7 @@ int codec2_bits_per_frame(struct CODEC2 *c2) { \*---------------------------------------------------------------------------*/ -int codec2_samples_per_frame(struct CODEC2 *c2) { +int WIN32SUPPORT codec2_samples_per_frame(struct CODEC2 *c2) { if (c2->mode == CODEC2_MODE_2400) return 160; if (c2->mode == CODEC2_MODE_1400) @@ -191,7 +191,7 @@ int codec2_samples_per_frame(struct CODEC2 *c2) { return 0; /* shouldnt get here */ } -void codec2_encode(struct CODEC2 *c2, unsigned char *bits, short speech[]) +void WIN32SUPPORT codec2_encode(struct CODEC2 *c2, unsigned char *bits, short speech[]) { assert(c2 != NULL); assert( @@ -208,7 +208,7 @@ void codec2_encode(struct CODEC2 *c2, unsigned char *bits, short speech[]) codec2_encode_1200(c2, bits, speech); } -void codec2_decode(struct CODEC2 *c2, short speech[], const unsigned char *bits) +void WIN32SUPPORT codec2_decode(struct CODEC2 *c2, short speech[], const unsigned char *bits) { assert(c2 != NULL); assert( diff --git a/codec2-dev/src/codec2.h b/codec2-dev/src/codec2.h index 6f12483e..e6c90b88 100644 --- a/codec2-dev/src/codec2.h +++ b/codec2-dev/src/codec2.h @@ -2,10 +2,10 @@ FILE........: codec2.h AUTHOR......: David Rowe - DATE CREATED: 21/8/2010 + DATE CREATED: 21 August 2010 - Codec2 fully quantised encoder and decoder functions. If you want use - codec2, these are the functions you need to call. + Codec 2 fully quantised encoder and decoder functions. If you want use + Codec 2, these are the functions you need to call. \*---------------------------------------------------------------------------*/ @@ -27,23 +27,34 @@ */ #ifdef __cplusplus -extern "C" { + extern "C" { #endif + #ifndef __CODEC2__ #define __CODEC2__ +#ifdef __WIN32__ +#ifdef __BUILDING_DLL__ +#define WIN32SUPPORT __declspec(dllexport) __stdcall +#else +#define WIN32SUPPORT __declspec(dllimport) __stdcall +#endif +#else +#define WIN32SUPPORT +#endif + #define CODEC2_MODE_2400 0 #define CODEC2_MODE_1400 1 #define CODEC2_MODE_1200 2 struct CODEC2; -struct CODEC2 *codec2_create(int mode); -void codec2_destroy(struct CODEC2 *codec2_state); -void codec2_encode(struct CODEC2 *codec2_state, unsigned char * bits, short speech_in[]); -void codec2_decode(struct CODEC2 *codec2_state, short speech_out[], const unsigned char *bits); -int codec2_samples_per_frame(struct CODEC2 *codec2_state); -int codec2_bits_per_frame(struct CODEC2 *codec2_state); +struct CODEC2 * WIN32SUPPORT codec2_create(int mode); +void WIN32SUPPORT codec2_destroy(struct CODEC2 *codec2_state); +void WIN32SUPPORT codec2_encode(struct CODEC2 *codec2_state, unsigned char * bits, short speech_in[]); +void WIN32SUPPORT codec2_decode(struct CODEC2 *codec2_state, short speech_out[], const unsigned char *bits); +int WIN32SUPPORT codec2_samples_per_frame(struct CODEC2 *codec2_state); +int WIN32SUPPORT codec2_bits_per_frame(struct CODEC2 *codec2_state); #endif diff --git a/codec2-dev/src/fdmdv.c b/codec2-dev/src/fdmdv.c index 4fe36e04..5e71da68 100644 --- a/codec2-dev/src/fdmdv.c +++ b/codec2-dev/src/fdmdv.c @@ -119,7 +119,7 @@ static float cabsolute(COMP a) \*---------------------------------------------------------------------------*/ -struct FDMDV *fdmdv_create(void) +struct FDMDV * WIN32SUPPORT fdmdv_create(void) { struct FDMDV *f; int c, i, k; @@ -234,7 +234,7 @@ struct FDMDV *fdmdv_create(void) \*---------------------------------------------------------------------------*/ -void fdmdv_destroy(struct FDMDV *fdmdv) +void WIN32SUPPORT fdmdv_destroy(struct FDMDV *fdmdv) { assert(fdmdv != NULL); free(fdmdv); @@ -252,7 +252,7 @@ void fdmdv_destroy(struct FDMDV *fdmdv) \*---------------------------------------------------------------------------*/ -void fdmdv_get_test_bits(struct FDMDV *f, int tx_bits[]) +void WIN32SUPPORT fdmdv_get_test_bits(struct FDMDV *f, int tx_bits[]) { int i; @@ -445,7 +445,7 @@ void fdm_upconvert(COMP tx_fdm[], COMP tx_baseband[NC+1][M], COMP phase_tx[], CO \*---------------------------------------------------------------------------*/ -void fdmdv_mod(struct FDMDV *fdmdv, COMP tx_fdm[], int tx_bits[], int *sync_bit) +void WIN32SUPPORT fdmdv_mod(struct FDMDV *fdmdv, COMP tx_fdm[], int tx_bits[], int *sync_bit) { COMP tx_symbols[NC+1]; COMP tx_baseband[NC+1][M]; @@ -1027,7 +1027,7 @@ void snr_update(float sig_est[], float noise_est[], COMP phase_difference[]) \*---------------------------------------------------------------------------*/ -void fdmdv_put_test_bits(struct FDMDV *f, int *sync, int *bit_errors, int *ntest_bits, int rx_bits[]) +void WIN32SUPPORT fdmdv_put_test_bits(struct FDMDV *f, int *sync, int *bit_errors, int *ntest_bits, int rx_bits[]) { int i,j; float ber; @@ -1161,7 +1161,7 @@ int freq_state(int sync_bit, int *state) \*---------------------------------------------------------------------------*/ -void fdmdv_demod(struct FDMDV *fdmdv, int rx_bits[], int *sync_bit, float rx_fdm[], int *nin) +void WIN32SUPPORT fdmdv_demod(struct FDMDV *fdmdv, int rx_bits[], int *sync_bit, float rx_fdm[], int *nin) { float foff_coarse, foff_fine; COMP rx_fdm_fcorr[M+M/P]; @@ -1258,7 +1258,7 @@ float calc_snr(float sig_est[], float noise_est[]) \*---------------------------------------------------------------------------*/ -void fdmdv_get_demod_stats(struct FDMDV *fdmdv, struct FDMDV_STATS *fdmdv_stats) +void WIN32SUPPORT fdmdv_get_demod_stats(struct FDMDV *fdmdv, struct FDMDV_STATS *fdmdv_stats) { int c; @@ -1299,7 +1299,7 @@ void fdmdv_get_demod_stats(struct FDMDV *fdmdv, struct FDMDV_STATS *fdmdv_stats) \*---------------------------------------------------------------------------*/ -void fdmdv_8_to_48(float out48k[], float in8k[], int n) +void WIN32SUPPORT fdmdv_8_to_48(float out48k[], float in8k[], int n) { int i,j,k,l; @@ -1331,7 +1331,7 @@ void fdmdv_8_to_48(float out48k[], float in8k[], int n) \*---------------------------------------------------------------------------*/ -void fdmdv_48_to_8(float out8k[], float in48k[], int n) +void WIN32SUPPORT fdmdv_48_to_8(float out8k[], float in48k[], int n) { int i,j; diff --git a/codec2-dev/src/fdmdv.h b/codec2-dev/src/fdmdv.h index 733db21d..b9227b36 100644 --- a/codec2-dev/src/fdmdv.h +++ b/codec2-dev/src/fdmdv.h @@ -39,6 +39,16 @@ extern "C" { #endif +#ifdef __WIN32__ +#ifdef __BUILDING_DLL__ +#define WIN32SUPPORT __declspec(dllexport) __stdcall +#else +#define WIN32SUPPORT __declspec(dllimport) __stdcall +#endif +#else +#define WIN32SUPPORT +#endif + #include "comp.h" #define FDMDV_BITS_PER_FRAME 28 /* 20ms frames, 1400 bit/s */ @@ -66,20 +76,20 @@ struct FDMDV_STATS { float clock_offset; /* Estimated tx/rx sample clock offset in ppm */ }; -struct FDMDV *fdmdv_create(void); -void fdmdv_destroy(struct FDMDV *fdmdv_state); +struct FDMDV * WIN32SUPPORT fdmdv_create(void); +void WIN32SUPPORT fdmdv_destroy(struct FDMDV *fdmdv_state); -void fdmdv_mod(struct FDMDV *fdmdv_state, COMP tx_fdm[], int tx_bits[], int *sync_bit); -void fdmdv_demod(struct FDMDV *fdmdv_state, int rx_bits[], int *sync_bit, float rx_fdm[], int *nin); +void WIN32SUPPORT fdmdv_mod(struct FDMDV *fdmdv_state, COMP tx_fdm[], int tx_bits[], int *sync_bit); +void WIN32SUPPORT fdmdv_demod(struct FDMDV *fdmdv_state, int rx_bits[], int *sync_bit, float rx_fdm[], int *nin); -void fdmdv_get_test_bits(struct FDMDV *fdmdv_state, int tx_bits[]); -void fdmdv_put_test_bits(struct FDMDV *f, int *sync, int *bit_errors, int *ntest_bits, int rx_bits[]); +void WIN32SUPPORT fdmdv_get_test_bits(struct FDMDV *fdmdv_state, int tx_bits[]); +void WIN32SUPPORT fdmdv_put_test_bits(struct FDMDV *f, int *sync, int *bit_errors, int *ntest_bits, int rx_bits[]); -void fdmdv_get_demod_stats(struct FDMDV *fdmdv_state, struct FDMDV_STATS *fdmdv_stats); -void fdmdv_get_waterfall_line(struct FDMDV *fdmdv_state, float magnitudes[], int *magnitude_points); +void WIN32SUPPORT fdmdv_get_demod_stats(struct FDMDV *fdmdv_state, struct FDMDV_STATS *fdmdv_stats); +void WIN32SUPPORT fdmdv_get_waterfall_line(struct FDMDV *fdmdv_state, float magnitudes[], int *magnitude_points); -void fdmdv_8_to_48(float out48k[], float in8k[], int n); -void fdmdv_48_to_8(float out8k[], float in48k[], int n); +void WIN32SUPPORT fdmdv_8_to_48(float out48k[], float in8k[], int n); +void WIN32SUPPORT fdmdv_48_to_8(float out8k[], float in48k[], int n); #endif diff --git a/codec2-dev/win32/Makefile b/codec2-dev/win32/Makefile new file mode 100644 index 00000000..f59ec432 --- /dev/null +++ b/codec2-dev/win32/Makefile @@ -0,0 +1,59 @@ +# Win32 Makefile derived from the fine work of Peter Lawrence: +# http://code.google.com/p/codec2demo/ +# +# David Rowe June 2012 +# +# This makefile assumes the Linux version has been compiled first to generate +# the machine-generated codebook source files. It is designed to be cross compiled on +# Linux. +# +# TODO - get this integarted into Automake system, such that if i586-mingw32msvc exists +# the Win32 code gets automatically built. + +# uncomment under Windows +#CC_PREFIX = +# uncomment under Linux (to cross-compile for Windows) +CC_PREFIX = i586-mingw32msvc- + +DLLNAME = codec2.dll +LIBNAME = codec2.lib + +CFLAGS = -O2 -Wall -D__WIN32__ + +HDRS = ../src/codec2.h ../src/fdmdv.h + +OBJS = dump.o lpc.o nlp.o postfilter.o sine.o codec2.o fdmdv.o fft.o kiss_fft.o interp.o lsp.o phase.o quantise.o pack.o codebook.o codebookd.o codebookvq.o codebookjnd.o codebookjvm.o codebookdt.o codebookge.o + +all: $(DLLNAME) c2demo.exe c2enc.exe c2dec.exe fdmdv_get_test_bits.exe fdmdv_mod.exe fdmdv_demod.exe fdmdv_put_test_bits.exe + +$(DLLNAME): $(OBJS) + $(CC_PREFIX)gcc -shared -o $(DLLNAME) $(OBJS) -Wl,--out-implib,$(LIBNAME) + +%.o: ../src/%.c $(HDRS) Makefile + $(CC_PREFIX)gcc $(CFLAGS) -D__BUILDING_DLL__ -c $< -o $@ + +c2demo.exe: ../src/c2demo.c $(DLLNAME) $(LIBNAME) + $(CC_PREFIX)gcc $(CFLAGS) $< -o $@ $(LIBNAME) + +c2enc.exe: ../src/c2enc.c $(DLLNAME) $(LIBNAME) + $(CC_PREFIX)gcc $(CFLAGS) $< -o $@ $(LIBNAME) + +c2dec.exe: ../src/c2dec.c $(DLLNAME) $(LIBNAME) + $(CC_PREFIX)gcc $(CFLAGS) $< -o $@ $(LIBNAME) + +fdmdv_get_test_bits.exe: ../src/fdmdv_get_test_bits.c $(DLLNAME) $(LIBNAME) + $(CC_PREFIX)gcc $(CFLAGS) $< -o $@ $(LIBNAME) + +fdmdv_mod.exe: ../src/fdmdv_mod.c $(DLLNAME) $(LIBNAME) + $(CC_PREFIX)gcc $(CFLAGS) $< -o $@ $(LIBNAME) + +fdmdv_demod.exe: ../src/fdmdv_demod.c ../src/octave.c $(DLLNAME) $(LIBNAME) + $(CC_PREFIX)gcc $(CFLAGS) $< ../src/octave.c -o $@ $(LIBNAME) + +fdmdv_put_test_bits.exe: ../src/fdmdv_put_test_bits.c $(DLLNAME) $(LIBNAME) + $(CC_PREFIX)gcc $(CFLAGS) $< -o $@ $(LIBNAME) + +clean: + rm -f $(DLLNAME) $(LIBNAME) + rm -f *.o *.exe + -- 2.25.1