From f85ba0d7247bf34192e85347bc72c5990eed3365 Mon Sep 17 00:00:00 2001 From: "Matthias P. Braendli" Date: Thu, 13 Oct 2022 21:15:22 +0200 Subject: Add a few ampliphase improvements --- src/fl2k_ampliphase.c | 44 +++++++++++++++++++++++++++++++++++--------- 1 file changed, 35 insertions(+), 9 deletions(-) diff --git a/src/fl2k_ampliphase.c b/src/fl2k_ampliphase.c index 7167ba7..38adcf1 100644 --- a/src/fl2k_ampliphase.c +++ b/src/fl2k_ampliphase.c @@ -257,7 +257,18 @@ static inline void dds_complex(dds_t *dds, int8_t * i, int8_t * q) amp_i = (int32_t) (creal(dds->amplitude) * 32767.0); // 0..15 amp_q = (int32_t) (cimag(dds->amplitude) * 32767.0); + if (phase_idx_i < 0 || phase_idx_i > 255) { + fprintf(stderr, "phase_idx_i wrong: %d\n", phase_idx_i); + fprintf(stderr, " dds->phase %ld\n", dds->phase); + fprintf(stderr, " dds->phase_delta %ld\n", dds->phase_delta); + abort(); + } amp_i = amp_i * trig_table.inphase[phase_idx_i]; // 0..31 + // + if (phase_idx_q < 0 || phase_idx_q > 255) { + fprintf(stderr, "phase_idx_q wrong: %d\n", phase_idx_q); + abort(); + } amp_q = amp_q * trig_table.quadrature[phase_idx_q]; // 0..31 *i = (int8_t) (amp_i >> 24); // 0..31 >> 24 => 0..8 @@ -266,6 +277,7 @@ static inline void dds_complex(dds_t *dds, int8_t * i, int8_t * q) /* advance modulation signal by interpolated input from baseband */ dds->amplitude += dds->ampslope; dds->phase_delta += dds->phase_slope; + //fprintf(stderr, "ps %ld pd %ld\n", dds->phase_slope, dds->phase_delta); return; } @@ -285,8 +297,6 @@ static inline void dds_complex_buf(dds_t *dds, int8_t *ibuf, int8_t *qbuf, int c * in the amp buffer */ static void *iq_worker(void *arg) { - register float freq; - register float tmp; dds_t base_signal; int8_t *tmp_ptr; uint32_t len = 0; @@ -489,18 +499,20 @@ static void *file_worker(void *arg){ uint32_t * filebuf; int i; const size_t len = sizeof(*filebuf) * FL2K_BUF_LEN; + size_t wrote; f = arg; filebuf = malloc(len); if(filebuf == NULL){ - fprintf(stderr,"Error allocating debug file buffer.\n"); + fprintf(stderr, "Error allocating debug file buffer.\n"); } - else{ - while(1){ + else { + while (!do_exit){ for(i=0;i