From: drowe67 Date: Sat, 9 Jun 2012 23:20:46 +0000 (+0000) Subject: changed name of __WIN32__ define to not clash with other conventions, checked in... X-Git-Url: http://git.whiteaudio.com/gitweb/?a=commitdiff_plain;h=d65c85979db3546a2c61238092be2bfc8b457a95;p=freetel-svn-tracking.git changed name of __WIN32__ define to not clash with other conventions, checked in Win32 .dll and .lib binaries for ease of use git-svn-id: https://svn.code.sf.net/p/freetel/code@536 01035d8c-6547-0410-b346-abe4f91aad63 --- diff --git a/codec2-dev/src/codec2.c b/codec2-dev/src/codec2.c index 1aa7cff3..373f2fd4 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 * 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( diff --git a/codec2-dev/src/codec2.h b/codec2-dev/src/codec2.h index e6c90b88..d4f31c6a 100644 --- a/codec2-dev/src/codec2.h +++ b/codec2-dev/src/codec2.h @@ -33,14 +33,17 @@ #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 @@ -49,12 +52,12 @@ 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 diff --git a/codec2-dev/src/fdmdv.c b/codec2-dev/src/fdmdv.c index 5e71da68..c5a6ba1a 100644 --- a/codec2-dev/src/fdmdv.c +++ b/codec2-dev/src/fdmdv.c @@ -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; jfft_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