From: drowe67 Date: Thu, 21 Aug 2014 03:26:55 +0000 (+0000) Subject: FreeDV tx & rx working in real time. Yayyyyyyyyy X-Git-Url: http://git.whiteaudio.com/gitweb/?a=commitdiff_plain;h=f2cc3082259411497fec61fc9e11e7d987b12957;p=freetel-svn-tracking.git FreeDV tx & rx working in real time. Yayyyyyyyyy git-svn-id: https://svn.code.sf.net/p/freetel/code@1813 01035d8c-6547-0410-b346-abe4f91aad63 --- diff --git a/codec2-dev/stm32/Makefile b/codec2-dev/stm32/Makefile index e33b8b9e..707c177b 100644 --- a/codec2-dev/stm32/Makefile +++ b/codec2-dev/stm32/Makefile @@ -287,7 +287,7 @@ src/init.c FREEDV_RX_PROFILE_SRCS += $(CODEC2_SRCS) freedv_rx_profile.elf: $(FREEDV_RX_PROFILE_SRCS) - $(CC) $(CFLAGS) -DPROFILE $^ -o $@ $(LIBPATHS) $(LIBS) + $(CC) $(CFLAGS) $^ -o $@ $(LIBPATHS) $(LIBS) clean: rm -f *.o diff --git a/codec2-dev/stm32/src/freedv_rx_profile.c b/codec2-dev/stm32/src/freedv_rx_profile.c index c116c7ff..5c0d216b 100644 --- a/codec2-dev/stm32/src/freedv_rx_profile.c +++ b/codec2-dev/stm32/src/freedv_rx_profile.c @@ -25,6 +25,9 @@ along with this program; if not, see . */ +#define PROFILE + +#include #include #include #include @@ -35,6 +38,7 @@ #include "gdb_stdio.h" #include "freedv_api.h" #include "machdep.h" +#include "codec2_fdmdv.h" #ifdef __EMBEDDED__ #define printf gdb_stdio_printf @@ -42,49 +46,85 @@ #define fclose gdb_stdio_fclose #define fread gdb_stdio_fread #define fwrite gdb_stdio_fwrite +#define fprintf gdb_stdio_fprintf #endif +#define FREEDV_NSAMPLES_16K (2*FREEDV_NSAMPLES) + int main(int argc, char *argv[]) { struct freedv *f; - short inbuf[FREEDV_NSAMPLES], outbuf[FREEDV_NSAMPLES]; - FILE *fin, *fout; - int frame, nin, nout = 0; - PROFILE_VAR(freedv_start); + short adc16k[FDMDV_OS_TAPS_16K+FREEDV_NSAMPLES_16K]; + short dac16k[FREEDV_NSAMPLES_16K]; + short adc8k[FREEDV_NSAMPLES]; + short dac8k[FDMDV_OS_TAPS_8K+FREEDV_NSAMPLES]; + FILE *fin, *fout, *ftotal; + int frame, nin_16k, nin, i, nout = 0; + struct FDMDV_STATS stats; + PROFILE_VAR(fdmdv_16_to_8_start, freedv_rx_start, fdmdv_8_to_16_start); machdep_profile_init(); f = freedv_open(FREEDV_MODE_1600); - // Transmit --------------------------------------------------------------------- + // Receive --------------------------------------------------------------------- frame = 0; - fin = fopen("mod.raw", "rb"); + fin = fopen("mod_16k.raw", "rb"); if (fin == NULL) { printf("Error opening input file\n"); exit(1); } - fout = fopen("stm_out.raw", "wb"); + fout = fopen("speechout_16k.raw", "wb"); if (fout == NULL) { printf("Error opening output file\n"); exit(1); } + ftotal = fopen("total.txt", "wt"); + assert(ftotal != NULL); + + /* clear filter memories */ + + for(i=0; ifdmdv, &stats); + + PROFILE_SAMPLE_AND_LOG(fdmdv_8_to_16_start, freedv_rx_start, " freedv_rx"); + + fdmdv_8_to_16_short(dac16k, &dac8k[FDMDV_OS_TAPS_8K], nout); + + PROFILE_SAMPLE_AND_LOG2(fdmdv_8_to_16_start, " fdmdv_8_to_16"); + + fprintf(ftotal, "%d\n", machdep_profile_sample() - fdmdv_16_to_8_start); machdep_profile_print_logged_samples(); - fwrite(outbuf, sizeof(short), nout, fout); - printf("frame: %d\n", ++frame); + + fwrite(dac16k, sizeof(short), 2*nout, fout); + fdmdv_get_demod_stats(f->fdmdv, &stats); + printf("frame: %d nin_16k: %d sync: %d SNR: %3.2f \n", + ++frame, nin_16k, stats.sync, (double)stats.snr_est); } fclose(fin); fclose(fout); + fclose(ftotal); return 0; } diff --git a/codec2-dev/stm32/src/sm1000_main.c b/codec2-dev/stm32/src/sm1000_main.c index 5aaabe9b..28694ece 100644 --- a/codec2-dev/stm32/src/sm1000_main.c +++ b/codec2-dev/stm32/src/sm1000_main.c @@ -36,12 +36,11 @@ int main(void) { struct freedv *f; - float adc16k[FDMDV_OS_TAPS_16K+FREEDV_NSAMPLES_16K]; - float adc8k[FREEDV_NSAMPLES]; - float dac8k[FDMDV_OS_TAPS_8K+FREEDV_NSAMPLES]; - float dac16k[FREEDV_NSAMPLES_16K]; - short buf[FREEDV_NSAMPLES_16K]; - + short adc16k[FDMDV_OS_TAPS_16K+FREEDV_NSAMPLES_16K]; + short dac16k[FREEDV_NSAMPLES_16K]; + short adc8k[FREEDV_NSAMPLES]; + short dac8k[FDMDV_OS_TAPS_8K+FREEDV_NSAMPLES]; + int nin, nout, i; /* init all the drivers for various peripherals */ @@ -49,7 +48,7 @@ int main(void) { //sm1000_leds_switches_init(); dac_open(4*DAC_BUF_SZ); adc_open(4*ADC_BUF_SZ); - //f = freedv_open(FREEDV_MODE_1600); + f = freedv_open(FREEDV_MODE_1600); /* LEDs into a known state */ @@ -78,34 +77,29 @@ int main(void) { dac8k[i] = 0.0; while(1) { - if(1) { + + + if (0) { /* Transmit -------------------------------------------------------------------------*/ /* ADC2 is the SM1000 microphone, DAC1 is the modulator signal we send to radio tx */ - if (adc1_read(buf, FREEDV_NSAMPLES_16K) == 0) { - + if (adc1_read(&adc16k[FDMDV_OS_TAPS_16K], FREEDV_NSAMPLES_16K) == 0) { GPIOE->ODR = (1 << 3); - for(i=0; iODR &= ~(1 << 3); + dac2_write(dac16k, FREEDV_NSAMPLES_16K); //led_ptt(1); led_rt(0); led_err(0); + GPIOE->ODR &= ~(1 << 3); } } @@ -115,18 +109,24 @@ int main(void) { /* ADC1 is the demod in signal from the radio rx, DAC2 is the SM1000 speaker */ - nin = freedv_nin(f); + nin = freedv_nin(f); + nout = nin; f->total_bit_errors = 0; - - if (adc1_read(buf, nin) == 0) { - nout = freedv_rx(f, buf, buf); - dac2_write(buf, nout); - led_ptt(0); led_rt(f->fdmdv_stats.sync); led_err(f->total_bit_errors); - nin = freedv_nin(f); + + if (adc1_read(&adc16k[FDMDV_OS_TAPS_16K], 2*nin) == 0) { + GPIOE->ODR = (1 << 3); + fdmdv_16_to_8_short(adc8k, &adc16k[FDMDV_OS_TAPS_16K], nin); + nout = freedv_rx(f, &dac8k[FDMDV_OS_TAPS_8K], adc8k); + //for(i=0; ifdmdv_stats.sync); led_err(f->total_bit_errors); + GPIOE->ODR &= ~(1 << 3); } } - + } /* while(1) ... */ } diff --git a/codec2-dev/stm32/src/stm32f4_adc.c b/codec2-dev/stm32/src/stm32f4_adc.c index 7790a4c2..73728ff6 100644 --- a/codec2-dev/stm32/src/stm32f4_adc.c +++ b/codec2-dev/stm32/src/stm32f4_adc.c @@ -137,7 +137,7 @@ void adc_configure(){ // Select the channel to be read from - ADC_RegularChannelConfig(ADCx,ADC_Channel_2,1,ADC_SampleTime_144Cycles); + ADC_RegularChannelConfig(ADCx,ADC_Channel_1,1,ADC_SampleTime_144Cycles); //ADC_VBATCmd(ENABLE); /* DMA configuration **************************************/