]> git.rkrishnan.org Git - pihpsdr.git/commitdiff
Test code for Paul to address the "Residual audio" problem,
authorc vw <dl1ycf@darc.de>
Tue, 4 Jan 2022 13:17:29 +0000 (14:17 +0100)
committerc vw <dl1ycf@darc.de>
Tue, 4 Jan 2022 13:17:29 +0000 (14:17 +0100)
to be removed if issue has settled down.

radio.c
receiver.c
receiver.h

diff --git a/radio.c b/radio.c
index 03ab3577c56e68ef0faefd0f9251310d8820b0d9..c2fab287d6346cda036819df7b1cf7004390a870 100644 (file)
--- a/radio.c
+++ b/radio.c
@@ -1546,6 +1546,10 @@ static void rxtx(int state) {
         gtk_fixed_put(GTK_FIXED(fixed),receiver[i]->panel,receiver[i]->x,receiver[i]->y);
         SetChannelState(receiver[i]->id,1,0);
         set_displaying(receiver[i],1);
+        receiver[i]->rxcount=0;
+        receiver[i]->maxcount=-1;
+       // if not duplex, clear RX iq buffer
+        receiver[i]->samples=0;
       }
     }
   }
index d350565e71afb2eedcaf835e803c50b1d4140fb7..933cc5f20332447758a06111341181b18413c39a 100644 (file)
@@ -1238,6 +1238,8 @@ g_print("%s: rx=%p id=%d local_audio=%d\n",__FUNCTION__,rx,rx->id,rx->local_audi
 
   // defer set_agc until here, otherwise the AGC threshold is not computed correctly
   set_agc(rx, rx->agc);
+
+  rx->rxcount=99999;
   return rx;
 }
 
@@ -1250,6 +1252,7 @@ void receiver_change_sample_rate(RECEIVER *rx,int sample_rate) {
   g_mutex_lock(&rx->mutex);
 
   rx->sample_rate=sample_rate;
+  rx->samples=0;  // clear RX iq buffer
   int scale=rx->sample_rate/48000;
   rx->output_samples=rx->buffer_size/scale;
   rx->hz_per_pixel=(double)rx->sample_rate/(double)rx->width;
@@ -1496,6 +1499,20 @@ static int rx_buffer_seen=0;
 static int tx_buffer_seen=0;
 
 void add_iq_samples(RECEIVER *rx, double i_sample,double q_sample) {
+
+  if (rx->rxcount <= 20000) {
+    if (i_sample*i_sample + q_sample*q_sample > 0.01) rx->maxcount=rx->rxcount;
+    if (rx->rxcount < (int)(rx->sample_rate >> 5)) {
+      i_sample=0.0;
+      q_sample=0.0;
+    }
+    if (rx->rxcount == 20000) {
+      fprintf(stderr,"ID=%d MAXCOUNT=%d\n", rx->id, rx->maxcount);
+      rx->rxcount = 99999;
+    }
+    rx->rxcount++;
+  }
+
   rx->iq_input_buffer[rx->samples*2]=i_sample;
   rx->iq_input_buffer[(rx->samples*2)+1]=q_sample;
   rx->samples=rx->samples+1;
index 5792b3c3a9c2e98048c3d35ecd6f16e15a196067..d72b0c61110b32b937ddf321729c6a9b550f0a33 100644 (file)
@@ -166,6 +166,8 @@ typedef struct _receiver {
 
   gint x;
   gint y;
+
+  int rxcount; int maxcount;
 } RECEIVER;
 
 extern RECEIVER *create_pure_signal_receiver(int id, int buffer_size,int sample_rate,int pixels);