support for cross compiling windows DLL
authordrowe67 <drowe67@01035d8c-6547-0410-b346-abe4f91aad63>
Sat, 9 Jun 2012 01:59:35 +0000 (01:59 +0000)
committerdrowe67 <drowe67@01035d8c-6547-0410-b346-abe4f91aad63>
Sat, 9 Jun 2012 01:59:35 +0000 (01:59 +0000)
git-svn-id: https://svn.code.sf.net/p/freetel/code@535 01035d8c-6547-0410-b346-abe4f91aad63

codec2-dev/README
codec2-dev/src/codec2.c
codec2-dev/src/codec2.h
codec2-dev/src/fdmdv.c
codec2-dev/src/fdmdv.h
codec2-dev/win32/Makefile [new file with mode: 0644]

index 46e8a3e80280d0e5e113e2823e8055bbbeb2c456..10f0a7615acc1972053b8353cdcdf4afb236ecff 100644 (file)
@@ -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
 ----
index a5ff1f974fbbec2e2b8da29b44fedb8914e48c50..1aa7cff35a9b5477a82a07ba12181abaa25dd9e7 100644 (file)
@@ -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(
index 6f12483ea439b7edddd63c1670ec42d9ee691855..e6c90b888de0193465d37c93eb9bf8e1066fc5dd 100644 (file)
@@ -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.
 
 \*---------------------------------------------------------------------------*/
 
 */
 
 #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
 
index 4fe36e0498235df7cb79ad2c93afe6368ae684cb..5e71da68999ffb7bdeade41545336b331a15bf25 100644 (file)
@@ -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;
 
index 733db21d1a02bcc0705e18a3e1c9306dec25832e..b9227b361fdc5d23b3c90f0e1a69434a5dea34d7 100644 (file)
 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 (file)
index 0000000..f59ec43
--- /dev/null
@@ -0,0 +1,59 @@
+# Win32 Makefile derived from the fine work of Peter Lawrence:\r
+#   http://code.google.com/p/codec2demo/\r
+#\r
+# David Rowe June 2012\r
+#\r
+# This makefile assumes the Linux version has been compiled first to generate\r
+# the machine-generated codebook source files.  It is designed to be cross compiled on\r
+# Linux.  \r
+# \r
+# TODO - get this integarted into Automake system, such that if i586-mingw32msvc exists\r
+# the Win32 code gets automatically built.\r
+\r
+# uncomment under Windows\r
+#CC_PREFIX = \r
+# uncomment under Linux (to cross-compile for Windows)\r
+CC_PREFIX = i586-mingw32msvc-\r
+\r
+DLLNAME = codec2.dll\r
+LIBNAME = codec2.lib\r
+\r
+CFLAGS  = -O2 -Wall -D__WIN32__\r
+\r
+HDRS = ../src/codec2.h ../src/fdmdv.h\r
+\r
+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\r
+\r
+all: $(DLLNAME) c2demo.exe c2enc.exe c2dec.exe fdmdv_get_test_bits.exe fdmdv_mod.exe fdmdv_demod.exe fdmdv_put_test_bits.exe\r
+\r
+$(DLLNAME): $(OBJS)\r
+       $(CC_PREFIX)gcc -shared -o $(DLLNAME) $(OBJS) -Wl,--out-implib,$(LIBNAME)\r
+\r
+%.o: ../src/%.c $(HDRS) Makefile\r
+       $(CC_PREFIX)gcc $(CFLAGS) -D__BUILDING_DLL__ -c $< -o $@\r
+\r
+c2demo.exe: ../src/c2demo.c $(DLLNAME) $(LIBNAME)\r
+       $(CC_PREFIX)gcc $(CFLAGS) $< -o $@ $(LIBNAME)\r
+\r
+c2enc.exe: ../src/c2enc.c $(DLLNAME) $(LIBNAME)\r
+       $(CC_PREFIX)gcc $(CFLAGS) $< -o $@ $(LIBNAME)\r
+\r
+c2dec.exe: ../src/c2dec.c $(DLLNAME) $(LIBNAME)\r
+       $(CC_PREFIX)gcc $(CFLAGS) $< -o $@ $(LIBNAME)\r
+\r
+fdmdv_get_test_bits.exe: ../src/fdmdv_get_test_bits.c $(DLLNAME) $(LIBNAME)\r
+       $(CC_PREFIX)gcc $(CFLAGS) $< -o $@ $(LIBNAME)\r
+\r
+fdmdv_mod.exe: ../src/fdmdv_mod.c $(DLLNAME) $(LIBNAME)\r
+       $(CC_PREFIX)gcc $(CFLAGS) $< -o $@ $(LIBNAME)\r
+\r
+fdmdv_demod.exe: ../src/fdmdv_demod.c ../src/octave.c $(DLLNAME) $(LIBNAME)\r
+       $(CC_PREFIX)gcc $(CFLAGS) $< ../src/octave.c -o $@ $(LIBNAME)\r
+\r
+fdmdv_put_test_bits.exe: ../src/fdmdv_put_test_bits.c $(DLLNAME) $(LIBNAME)\r
+       $(CC_PREFIX)gcc $(CFLAGS) $< -o $@ $(LIBNAME)\r
+\r
+clean:\r
+       rm -f $(DLLNAME) $(LIBNAME)\r
+       rm -f *.o *.exe\r
+\r