changed name of __WIN32__ define to not clash with other conventions, checked in...
authordrowe67 <drowe67@01035d8c-6547-0410-b346-abe4f91aad63>
Sat, 9 Jun 2012 23:20:46 +0000 (23:20 +0000)
committerdrowe67 <drowe67@01035d8c-6547-0410-b346-abe4f91aad63>
Sat, 9 Jun 2012 23:20:46 +0000 (23:20 +0000)
git-svn-id: https://svn.code.sf.net/p/freetel/code@536 01035d8c-6547-0410-b346-abe4f91aad63

codec2-dev/src/codec2.c
codec2-dev/src/codec2.h
codec2-dev/src/fdmdv.c
codec2-dev/src/fdmdv.h
codec2-dev/src/fdmdv_internal.h
codec2-dev/win32/Makefile
codec2-dev/win32/codec2.dll [new file with mode: 0755]
codec2-dev/win32/codec2.lib [new file with mode: 0644]

index 1aa7cff35a9b5477a82a07ba12181abaa25dd9e7..373f2fd418a1aad8576227b440ed774fa91f8635 100644 (file)
@@ -81,7 +81,7 @@ void codec2_decode_1200(struct CODEC2 *c2, short speech[], const unsigned char *
 
 \*---------------------------------------------------------------------------*/
 
-struct CODEC2 * WIN32SUPPORT codec2_create(int mode)
+struct CODEC2 * CODEC2_WIN32SUPPORT codec2_create(int mode)
 {
     struct CODEC2 *c2;
     int            i,l;
@@ -141,7 +141,7 @@ struct CODEC2 * WIN32SUPPORT codec2_create(int mode)
 
 \*---------------------------------------------------------------------------*/
 
-void WIN32SUPPORT codec2_destroy(struct CODEC2 *c2)
+void CODEC2_WIN32SUPPORT codec2_destroy(struct CODEC2 *c2)
 {
     assert(c2 != NULL);
     nlp_destroy(c2->nlp);
@@ -158,7 +158,7 @@ void WIN32SUPPORT codec2_destroy(struct CODEC2 *c2)
 
 \*---------------------------------------------------------------------------*/
 
-int WIN32SUPPORT codec2_bits_per_frame(struct CODEC2 *c2) {
+int CODEC2_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 WIN32SUPPORT codec2_bits_per_frame(struct CODEC2 *c2) {
 
 \*---------------------------------------------------------------------------*/
 
-int WIN32SUPPORT codec2_samples_per_frame(struct CODEC2 *c2) {
+int CODEC2_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 WIN32SUPPORT codec2_samples_per_frame(struct CODEC2 *c2) {
     return 0; /* shouldnt get here */
 }
 
-void WIN32SUPPORT codec2_encode(struct CODEC2 *c2, unsigned char *bits, short speech[])
+void CODEC2_WIN32SUPPORT codec2_encode(struct CODEC2 *c2, unsigned char *bits, short speech[])
 {
     assert(c2 != NULL);
     assert(
@@ -208,7 +208,7 @@ void WIN32SUPPORT codec2_encode(struct CODEC2 *c2, unsigned char *bits, short sp
        codec2_encode_1200(c2, bits, speech);
 }
 
-void WIN32SUPPORT codec2_decode(struct CODEC2 *c2, short speech[], const unsigned char *bits)
+void CODEC2_WIN32SUPPORT codec2_decode(struct CODEC2 *c2, short speech[], const unsigned char *bits)
 {
     assert(c2 != NULL);
     assert(
index e6c90b888de0193465d37c93eb9bf8e1066fc5dd..d4f31c6a266c013afb57c577bfacc5f2b186925b 100644 (file)
 #ifndef __CODEC2__
 #define  __CODEC2__
 
-#ifdef __WIN32__
-#ifdef __BUILDING_DLL__
-#define WIN32SUPPORT __declspec(dllexport) __stdcall
+/* set up the calling convention for DLL function import/export for
+   WIN32 cross compiling */
+
+#ifdef __CODEC2_WIN32__
+#ifdef __CODEC2_BUILDING_DLL__
+#define CODEC2_WIN32SUPPORT __declspec(dllexport) __stdcall
 #else
-#define WIN32SUPPORT __declspec(dllimport) __stdcall
+#define CODEC2_WIN32SUPPORT __declspec(dllimport) __stdcall
 #endif
 #else
-#define WIN32SUPPORT
+#define CODEC2_WIN32SUPPORT
 #endif
 
 #define CODEC2_MODE_2400 0
 
 struct CODEC2;
 
-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);
+struct CODEC2 * CODEC2_WIN32SUPPORT codec2_create(int mode);
+void CODEC2_WIN32SUPPORT codec2_destroy(struct CODEC2 *codec2_state);
+void CODEC2_WIN32SUPPORT codec2_encode(struct CODEC2 *codec2_state, unsigned char * bits, short speech_in[]);
+void CODEC2_WIN32SUPPORT codec2_decode(struct CODEC2 *codec2_state, short speech_out[], const unsigned char *bits);
+int  CODEC2_WIN32SUPPORT codec2_samples_per_frame(struct CODEC2 *codec2_state);
+int  CODEC2_WIN32SUPPORT codec2_bits_per_frame(struct CODEC2 *codec2_state);
 
 #endif
 
index 5e71da68999ffb7bdeade41545336b331a15bf25..c5a6ba1a648a32b532f2456c141febb8f12e96ea 100644 (file)
@@ -119,7 +119,7 @@ static float cabsolute(COMP a)
 
 \*---------------------------------------------------------------------------*/
 
-struct FDMDV * WIN32SUPPORT fdmdv_create(void)
+struct FDMDV * CODEC2_WIN32SUPPORT fdmdv_create(void)
 {
     struct FDMDV *f;
     int           c, i, k;
@@ -221,6 +221,9 @@ struct FDMDV * WIN32SUPPORT fdmdv_create(void)
        f->noise_est[c] = 0.0;
     }
 
+    for(i=0; i<2*FDMDV_NFFT; i++)
+       f->fft_buf[i] = 0.0;
+
     return f;
 }
 
@@ -234,7 +237,7 @@ struct FDMDV * WIN32SUPPORT fdmdv_create(void)
 
 \*---------------------------------------------------------------------------*/
 
-void WIN32SUPPORT fdmdv_destroy(struct FDMDV *fdmdv)
+void CODEC2_WIN32SUPPORT fdmdv_destroy(struct FDMDV *fdmdv)
 {
     assert(fdmdv != NULL);
     free(fdmdv);
@@ -252,7 +255,7 @@ void WIN32SUPPORT fdmdv_destroy(struct FDMDV *fdmdv)
 
 \*---------------------------------------------------------------------------*/
 
-void WIN32SUPPORT fdmdv_get_test_bits(struct FDMDV *f, int tx_bits[])
+void CODEC2_WIN32SUPPORT fdmdv_get_test_bits(struct FDMDV *f, int tx_bits[])
 {
     int i;
 
@@ -445,7 +448,8 @@ void fdm_upconvert(COMP tx_fdm[], COMP tx_baseband[NC+1][M], COMP phase_tx[], CO
 
 \*---------------------------------------------------------------------------*/
 
-void WIN32SUPPORT fdmdv_mod(struct FDMDV *fdmdv, COMP tx_fdm[], int tx_bits[], int *sync_bit)
+void CODEC2_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 +1031,9 @@ void snr_update(float sig_est[], float noise_est[], COMP phase_difference[])
 
 \*---------------------------------------------------------------------------*/
 
-void WIN32SUPPORT fdmdv_put_test_bits(struct FDMDV *f, int *sync, int *bit_errors, int *ntest_bits, int rx_bits[])
+void CODEC2_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 +1167,8 @@ int freq_state(int sync_bit, int *state)
 
 \*---------------------------------------------------------------------------*/
 
-void WIN32SUPPORT fdmdv_demod(struct FDMDV *fdmdv, int rx_bits[], int *sync_bit, float rx_fdm[], int *nin)
+void CODEC2_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 +1265,8 @@ float calc_snr(float sig_est[], float noise_est[])
 
 \*---------------------------------------------------------------------------*/
 
-void WIN32SUPPORT fdmdv_get_demod_stats(struct FDMDV *fdmdv, struct FDMDV_STATS *fdmdv_stats)
+void CODEC2_WIN32SUPPORT fdmdv_get_demod_stats(struct FDMDV *fdmdv, 
+                                              struct FDMDV_STATS *fdmdv_stats)
 {
     int   c;
 
@@ -1299,7 +1307,7 @@ void WIN32SUPPORT fdmdv_get_demod_stats(struct FDMDV *fdmdv, struct FDMDV_STATS
 
 \*---------------------------------------------------------------------------*/
 
-void WIN32SUPPORT fdmdv_8_to_48(float out48k[], float in8k[], int n)
+void CODEC2_WIN32SUPPORT fdmdv_8_to_48(float out48k[], float in8k[], int n)
 {
     int i,j,k,l;
 
@@ -1331,7 +1339,7 @@ void WIN32SUPPORT fdmdv_8_to_48(float out48k[], float in8k[], int n)
 
 \*---------------------------------------------------------------------------*/
 
-void WIN32SUPPORT fdmdv_48_to_8(float out8k[], float in48k[], int n)
+void CODEC2_WIN32SUPPORT fdmdv_48_to_8(float out8k[], float in48k[], int n)
 {
     int i,j;
 
@@ -1342,3 +1350,49 @@ void WIN32SUPPORT fdmdv_48_to_8(float out8k[], float in48k[], int n)
     }
 }
 
+/*---------------------------------------------------------------------------*\
+                                                       
+  FUNCTION....: fdmdv_get_fft()             
+  AUTHOR......: David Rowe                           
+  DATE CREATED: 9 June 2012
+
+  Performs a FFT on the received modem signal at the input of the
+  demod, returns the FDMDV_NFFT point magnitiude spectrum in dB.  0dB
+  is a signal with amplitude +/- 2^15.
+
+  The output can be used to plot a spectrum of the demod input.
+  Sucessive calls can be used to build up a waterfall or spectrogram
+  plot, but mapping the levels to colours.
+
+\*---------------------------------------------------------------------------*/
+
+void CODEC2_WIN32SUPPORT fdmdv_get_fft(struct FDMDV *f, float mag_dB[], float rx_fdm[], int nin) 
+{
+    int   i,j;
+    COMP  F[2*FDMDV_NFFT];
+    float fullscale_dB;
+
+    /* update buffer of input samples */
+
+    for(i=0; i<2*FDMDV_NFFT-nin; i++)
+       f->fft_buf[i] = f->fft_buf[i+nin];
+    for(j=0; j<nin; j++,i++)
+       f->fft_buf[i] = rx_fdm[j];
+
+    /* window and FFT */
+
+    for(i=0; i<2*FDMDV_NFFT; i++) {
+       F[i].real = f->fft_buf[i] * (0.5 - 0.5*cos((float)i*2.0*PI/FDMDV_NFFT));
+       F[i].imag = 0.0;
+    }
+    fft(&F[0].real, 2*FDMDV_NFFT, -1);
+
+    /* scale and convert to dB */
+
+    fullscale_dB = 20*log10(FDMDV_NFFT*32767.0);
+    for(i=0; i<FDMDV_NFFT; i++) {
+       mag_dB[i]  = 10*log10(F[i].real*F[i].real + F[i].imag*F[i].imag);
+       mag_dB[i] -= fullscale_dB;
+    }
+}
+
index b9227b361fdc5d23b3c90f0e1a69434a5dea34d7..6feb73e9d3adcdd96462e8daae3d5aa0c45bd576 100644 (file)
@@ -6,8 +6,8 @@
                                                                              
   A 1400 bit/s Frequency Division Multiplexed Digital Voice (FDMDV)
   modem.  Used for digital audio over HF SSB. See README_fdmdv.txt for
-  more information, and fdmdv_demo.c, fdmdv_mod.c and fdmdv_demod.c
-  for example usage.
+  more information, and fdmdv_mod.c and fdmdv_demod.c for example
+  usage.
                      
   References:
  
 extern "C" {
 #endif
 
-#ifdef __WIN32__
-#ifdef __BUILDING_DLL__
-#define WIN32SUPPORT __declspec(dllexport) __stdcall
+/* set up the calling convention for DLL function import/export for
+   WIN32 cross compiling */
+
+#ifdef __CODEC2_WIN32__
+#ifdef __CODEC2_BUILDING_DLL__
+#define CODEC2_WIN32SUPPORT __declspec(dllexport) __stdcall
 #else
-#define WIN32SUPPORT __declspec(dllimport) __stdcall
+#define CODEC2_WIN32SUPPORT __declspec(dllimport) __stdcall
 #endif
 #else
-#define WIN32SUPPORT
+#define CODEC2_WIN32SUPPORT
 #endif
 
 #include "comp.h"
@@ -63,6 +66,10 @@ extern "C" {
 #define FDMDV_OS                 6         /* oversampling rate           */
 #define FDMDV_OS_TAPS           48         /* number of OS filter taps    */
 
+/* FFT points */
+
+#define FDMDV_NFFT             256
+
 /* FDMDV states and stats structures */
 
 struct FDMDV;
@@ -76,20 +83,20 @@ struct FDMDV_STATS {
     float  clock_offset;           /* Estimated tx/rx sample clock offset in ppm         */
 };
 
-struct FDMDV * WIN32SUPPORT fdmdv_create(void);
-void           WIN32SUPPORT fdmdv_destroy(struct FDMDV *fdmdv_state);
+struct FDMDV * CODEC2_WIN32SUPPORT fdmdv_create(void);
+void           CODEC2_WIN32SUPPORT fdmdv_destroy(struct FDMDV *fdmdv_state);
     
-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           CODEC2_WIN32SUPPORT fdmdv_mod(struct FDMDV *fdmdv_state, COMP tx_fdm[], int tx_bits[], int *sync_bit);
+void           CODEC2_WIN32SUPPORT fdmdv_demod(struct FDMDV *fdmdv_state, int rx_bits[], int *sync_bit, float rx_fdm[], int *nin);
     
-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           CODEC2_WIN32SUPPORT fdmdv_get_test_bits(struct FDMDV *fdmdv_state, int tx_bits[]);
+void           CODEC2_WIN32SUPPORT fdmdv_put_test_bits(struct FDMDV *f, int *sync, int *bit_errors, int *ntest_bits, int rx_bits[]);
     
-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           CODEC2_WIN32SUPPORT fdmdv_get_demod_stats(struct FDMDV *fdmdv_state, struct FDMDV_STATS *fdmdv_stats);
+void           CODEC2_WIN32SUPPORT fdmdv_get_fft(struct FDMDV *fdmdv_state, float mag_dB[], float rx_fdm[], int nin);
 
-void           WIN32SUPPORT fdmdv_8_to_48(float out48k[], float in8k[], int n);
-void           WIN32SUPPORT fdmdv_48_to_8(float out8k[], float in48k[], int n);
+void           CODEC2_WIN32SUPPORT fdmdv_8_to_48(float out48k[], float in8k[], int n);
+void           CODEC2_WIN32SUPPORT fdmdv_48_to_8(float out8k[], float in48k[], int n);
 
 #endif
 
index a2647b2df15161741cf3f52f7b2267ef6b7fba13..fa49acc85abceda19b1074184a62530e293d7a2d 100644 (file)
@@ -30,6 +30,7 @@
 #define __FDMDV_INTERNAL__
 
 #include "comp.h"
+#include "fdmdv.h"
 
 /*---------------------------------------------------------------------------*\
                                                                              
@@ -131,6 +132,10 @@ struct FDMDV {
 
     float sig_est[NC+1];
     float noise_est[NC+1];
+
+    /* Buf for FFT/waterfall */
+
+    float fft_buf[2*FDMDV_NFFT];
 };
 
 /*---------------------------------------------------------------------------*\
index f59ec432df8ebb0d481283ca6f4a5e473a23a967..cb37a3c4008fe0279a83abe5c555eceab21c23e5 100644 (file)
@@ -18,7 +18,7 @@ CC_PREFIX = i586-mingw32msvc-
 DLLNAME = codec2.dll\r
 LIBNAME = codec2.lib\r
 \r
-CFLAGS  = -O2 -Wall -D__WIN32__\r
+CFLAGS  = -O2 -Wall -D__CODEC2_WIN32__\r
 \r
 HDRS = ../src/codec2.h ../src/fdmdv.h\r
 \r
@@ -30,7 +30,7 @@ $(DLLNAME): $(OBJS)
        $(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
+       $(CC_PREFIX)gcc $(CFLAGS) -D__CODEC2_BUILDING_DLL__ -c $< -o $@\r
 \r
 c2demo.exe: ../src/c2demo.c $(DLLNAME) $(LIBNAME)\r
        $(CC_PREFIX)gcc $(CFLAGS) $< -o $@ $(LIBNAME)\r
diff --git a/codec2-dev/win32/codec2.dll b/codec2-dev/win32/codec2.dll
new file mode 100755 (executable)
index 0000000..67837fa
Binary files /dev/null and b/codec2-dev/win32/codec2.dll differ
diff --git a/codec2-dev/win32/codec2.lib b/codec2-dev/win32/codec2.lib
new file mode 100644 (file)
index 0000000..38a7b5d
Binary files /dev/null and b/codec2-dev/win32/codec2.lib differ