aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/fl2k_ampliphase.c44
1 files 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<FL2K_BUF_LEN;i++){
filebuf[i] = (itxbuf[i] & 0xff) | ((uint32_t) qtxbuf[i]) << 8;
}
- if(fwrite(filebuf,1,sizeof(len),f) != len){
+ wrote = fwrite(filebuf, sizeof(len), 1, f);
+ if (wrote != 1){
perror("Error writing to debug file");
break;
}
@@ -511,6 +523,7 @@ static void *file_worker(void *arg){
pthread_mutex_lock(&iq_mutex);
pthread_cond_signal(&iq_cond);
pthread_mutex_unlock(&iq_mutex);
+ if (filebuf) free(filebuf);
return NULL;
}
@@ -625,6 +638,10 @@ int main(int argc, char **argv)
fprintf(stderr, "malloc error!\n");
exit(1);
}
+ memset(iambuf, 0, FL2K_BUF_LEN);
+ memset(itxbuf, 0, FL2K_BUF_LEN);
+ memset(qambuf, 0, FL2K_BUF_LEN);
+ memset(qtxbuf, 0, FL2K_BUF_LEN);
/* Baseband buffer */
@@ -632,8 +649,18 @@ int main(int argc, char **argv)
ampbuf = malloc(BUFFER_SAMPLES * sizeof(float complex));
pdbuf = malloc(BUFFER_SAMPLES * sizeof(long int));
pdslopebuf = malloc(BUFFER_SAMPLES * sizeof(long int));
- readpos = 0;
- writepos = 1;
+ if (!slopebuf || !ampbuf || !pdbuf || !pdslopebuf) {
+ fprintf(stderr, "malloc error!\n");
+ exit(1);
+ }
+
+ memset(slopebuf, 0, BUFFER_SAMPLES * sizeof(float complex));
+ memset(ampbuf, 0, BUFFER_SAMPLES * sizeof(float complex));
+ memset(pdbuf, 0, BUFFER_SAMPLES * sizeof(long int));
+ memset(pdslopebuf, 0, BUFFER_SAMPLES * sizeof(long int));
+
+ readpos = 0;
+ writepos = 0;
fprintf(stdout, "Samplerate: %3.2f MHz\n", (float)samp_rate/1000000);
fprintf(stdout, "Center frequency: %5.0f kHz\n", (float)base_freq/1000);
@@ -699,7 +726,6 @@ int main(int argc, char **argv)
sigign.sa_handler = SIG_IGN;
sigaction(SIGINT, &sigact, NULL);
sigaction(SIGTERM, &sigact, NULL);
- sigaction(SIGQUIT, &sigact, NULL);
sigaction(SIGPIPE, &sigign, NULL);
#else
SetConsoleCtrlHandler( (PHANDLER_ROUTINE) sighandler, TRUE );