]> git.rkrishnan.org Git - pihpsdr.git/commitdiff
Moved adc attenuation / RF gain to ADC structure
authorc vw <dl1ycf@darc.de>
Wed, 19 May 2021 13:47:26 +0000 (15:47 +0200)
committerc vw <dl1ycf@darc.de>
Wed, 19 May 2021 13:47:26 +0000 (15:47 +0200)
16 files changed:
adc.h
dac.h
meter.c
midi3.c
new_protocol.c
old_protocol.c
radio.c
radio.h
radio_menu.c
receiver.c
receiver.h
rx_panadapter.c
sliders.c
soapy_protocol.c
soapy_protocol.h
waterfall.c

diff --git a/adc.h b/adc.h
index c1ab51d36a96c8c4547a21651b2c939a6d35daeb..f0a14b4f14ee96360c2ef263bdf2f989829a9a9a 100644 (file)
--- a/adc.h
+++ b/adc.h
@@ -65,8 +65,10 @@ typedef struct _adc {
   gboolean preamp;
   gint attenuation;
   gboolean enable_step_attenuation;
+  gdouble gain;
+  gdouble min_gain;
+  gdouble max_gain;
 #ifdef SOAPYSDR
-  gint *rx_gain;
   gboolean agc;
 #endif
 } ADC;
diff --git a/dac.h b/dac.h
index 5bd9ad4df4c53865aaa6b53f928683f2cca25365..851c4d2fe76b706c79f3d8777bda3d22c6d36c44 100644 (file)
--- a/dac.h
+++ b/dac.h
@@ -22,7 +22,7 @@
 
 typedef struct _dac {
   gint antenna;
-  gint *tx_gain;
+  double gain;
 } DAC;
 
 #endif
diff --git a/meter.c b/meter.c
index 462a334dee400c61692a1f829a30fec3ff9cfc41..937126623de065597d701d5adda4597c43321689 100644 (file)
--- a/meter.c
+++ b/meter.c
@@ -195,13 +195,13 @@ if(analog_meter) {
     case SMETER:
       {
       if(have_rx_gain) {
-        level=value+rx_gain_calibration-adc_attenuation[rx->adc];
+        level=value+rx_gain_calibration-adc[rx->adc].attenuation;
       } else {
-        level=value+(double)adc_attenuation[rx->adc];
+        level=value+(double)adc[rx->adc].attenuation;
       }
 #ifdef SOAPYSDR
       if(protocol==SOAPYSDR_PROTOCOL) {
-       level-=rx->rf_gain;
+       level-=adc[rx->id].gain;
       }
 #endif
       if (filter_board == CHARLY25) {
@@ -563,13 +563,13 @@ if(analog_meter) {
       text_location=10;
       offset=5.0;
       if(have_rx_gain) {
-        level=value+rx_gain_calibration-adc_attenuation[rx->adc];
+        level=value+rx_gain_calibration-adc[rx->adc].attenuation;
       } else {
-        level=value+(double)adc_attenuation[rx->adc];
+        level=value+(double)adc[rx->adc].attenuation;
       }
 #ifdef SOAPYSDR
       if(protocol==SOAPYSDR_PROTOCOL) {
-       level-=rx->rf_gain;
+       level-=adc[rx->id].gain;
       }
 #endif
       if (filter_board == CHARLY25) {
diff --git a/midi3.c b/midi3.c
index 3fc1b055f6ffb4277902840aa87e46c8d6faa5e6..a1abc4f0c3857214ea82c22c3d702c60e9f5b576 100644 (file)
--- a/midi3.c
+++ b/midi3.c
@@ -196,7 +196,7 @@ int DoTheRestOfTheMIDI(void *data) {
                }
                break;
              case MIDI_TYPE_WHEEL:
-               dnew=adc_attenuation[active_receiver->adc] + val;
+               dnew=adc[active_receiver->adc].attenuation + val;
                 if(have_rx_gain) {
                   if(dnew < -12.0) {
                     dnew = -12.0;
@@ -807,7 +807,7 @@ int DoTheRestOfTheMIDI(void *data) {
             if (type == MIDI_TYPE_KNOB) {
                 dnew=-12.0 + 0.6*val;
             } else  if (type == MIDI_TYPE_WHEEL) {
-                dnew=active_receiver->rf_gain+val;
+                dnew=adc[active_receiver->adc].gain+val;
             }
             if (dnew < -12.0) dnew = -12.0;
             if (dnew >  48.0) dnew =  48.0;
index aab24a1ab098c69bee107fabfc2014a5a6cdd4b5..7f20c825ff3db42fa26ee3a6c9fbafd66855ecdf 100644 (file)
@@ -1192,11 +1192,11 @@ static void new_protocol_high_priority() {
       high_priority_buffer_to_radio[1443]=transmitter->attenuation;
       high_priority_buffer_to_radio[1442]=31;
     } else {
-      high_priority_buffer_to_radio[1443]=adc_attenuation[0];  
+      high_priority_buffer_to_radio[1443]=adc[0].attenuation;  
       if (diversity_enabled) {
-        high_priority_buffer_to_radio[1442]=adc_attenuation[0];  // DIVERSITY: ADC0 att value for ADC1 as well
+        high_priority_buffer_to_radio[1442]=adc[0].attenuation;  // DIVERSITY: ADC0 att value for ADC1 as well
       } else {
-        high_priority_buffer_to_radio[1442]=adc_attenuation[1];
+        high_priority_buffer_to_radio[1442]=adc[1].attenuation;
       }
     }
 
index fab5d03cd7e81882f35c2c002fdda0d5a6b68c0a..eece1fb667c1d10d7da0a48df7856ec76225b4ea 100644 (file)
@@ -1655,7 +1655,7 @@ void ozy_send_buffer() {
          // is stored in rx_gain_slider. The firmware uses bit 6
          // of C4 to determine this case.
          //
-          int rxgain = adc_attenuation[active_receiver->adc]+12; // -12..48 to 0..60
+          int rxgain = adc[active_receiver->adc].gain+12; // -12..48 to 0..60
           if (rxgain <  0) rxgain=0;
           if (rxgain > 60) rxgain=60;
          // encode all 6 bits of RXgain in ATT value and set bit6
@@ -1685,7 +1685,7 @@ void ozy_send_buffer() {
           if (isTransmitting()) {
             output_buffer[C4]=0x20 | (transmitter->attenuation & 0x1F);
           } else {
-            output_buffer[C4]=0x20 | (adc_attenuation[0] & 0x1F);
+            output_buffer[C4]=0x20 | (adc[0].attenuation & 0x1F);
           } 
         }
         command=5;
@@ -1703,9 +1703,9 @@ void ozy_send_buffer() {
           } else {
            // if diversity is enabled, use RX1 att value for RX2
             if (diversity_enabled) {
-              output_buffer[C1]=0x20 | (adc_attenuation[receiver[0]->adc] & 0x1F);
+              output_buffer[C1]=0x20 | (adc[0].attenuation & 0x1F);
            } else {
-              output_buffer[C1]=0x20 | (adc_attenuation[receiver[1]->adc] & 0x1F);
+              output_buffer[C1]=0x20 | (adc[1].attenuation & 0x1F);
            }
           }
         }
diff --git a/radio.c b/radio.c
index a217fc434d705101cce25b5ffe3efd43c894207e..b1f418a30a2bbb12fb4e9f04267c78bd73aad956 100644 (file)
--- a/radio.c
+++ b/radio.c
@@ -1100,14 +1100,6 @@ void start_radio() {
   }
 #endif
 
-  adc_attenuation[0]=0;
-  adc_attenuation[1]=0;
-
-  if(have_rx_gain) {
-    adc_attenuation[0]=14;
-    adc_attenuation[1]=14;
-  }
-
   adc[0].antenna=ANTENNA_1;
   adc[0].filters=AUTOMATIC;
   adc[0].hpf=HPF_13;
@@ -1115,23 +1107,29 @@ void start_radio() {
   adc[0].dither=FALSE;
   adc[0].random=FALSE;
   adc[0].preamp=FALSE;
-  adc[0].attenuation=0;
+  if(have_rx_gain) {
+    adc[0].attenuation=14;
+  } else {
+    adc[0].attenuation=0;
+  }
 #ifdef SOAPYSDR
   adc[0].antenna=0;
   if(device==SOAPYSDR_USB_DEVICE) {
-    adc[0].rx_gain=malloc(radio->info.soapy.rx_gains*sizeof(gint));
-    for (size_t i = 0; i < radio->info.soapy.rx_gains; i++) {
-      adc[0].rx_gain[i]=0;
+    adc[0].gain=0;
+    if(radio->info.soapy.rx_gains>0) {
+      adc[0].min_gain=radio->info.soapy.rx_range[0].minimum;
+      adc[0].max_gain=radio->info.soapy.rx_range[0].maximum;;
+    } else {
+      adc[0].min_gain=0.0;
+      adc[0].max_gain=100.0;
     }
     adc[0].agc=FALSE;
     dac[0].antenna=1;
-    dac[0].tx_gain=malloc(radio->info.soapy.tx_gains*sizeof(gint));
-    for (size_t i = 0; i < radio->info.soapy.tx_gains; i++) {
-      dac[0].tx_gain[i]=0;
-    }
+    dac[0].gain=0;
   }
 #endif
 
+
   adc[1].antenna=ANTENNA_1;
   adc[1].filters=AUTOMATIC;
   adc[1].hpf=HPF_9_5;
@@ -1139,20 +1137,26 @@ void start_radio() {
   adc[1].dither=FALSE;
   adc[1].random=FALSE;
   adc[1].preamp=FALSE;
-  adc[1].attenuation=0;
+  if(have_rx_gain) {
+    adc[0].attenuation=14;
+  } else {
+    adc[1].attenuation=0;
+  }
 #ifdef SOAPYSDR
   adc[1].antenna=0;
   if(device==SOAPYSDR_USB_DEVICE) {
-    adc[1].rx_gain=malloc(radio->info.soapy.rx_gains*sizeof(gint));
-    for (size_t i = 0; i < radio->info.soapy.rx_gains; i++) {
-      adc[1].rx_gain[i]=0;
+    adc[1].gain=0;
+    if(radio->info.soapy.rx_gains>0) {
+      adc[1].min_gain=radio->info.soapy.rx_range[0].minimum;
+      adc[1].max_gain=radio->info.soapy.rx_range[0].maximum;;
+    } else {
+      adc[1].min_gain=0.0;
+      adc[1].max_gain=100.0;
     }
+    adc[1].max_gain=0;
     adc[1].agc=FALSE;
-
-    dac[1].tx_gain=malloc(radio->info.soapy.tx_gains*sizeof(gint));
-    for (size_t i = 0; i < radio->info.soapy.tx_gains; i++) {
-      dac[1].tx_gain[i]=0;
-    }
+    dac[1].antenna=1;
+    dac[1].gain=0;
   }
 
   radio_sample_rate=radio->info.soapy.sample_rate;
@@ -1257,28 +1261,14 @@ void start_radio() {
     if(can_transmit) {
       soapy_protocol_create_transmitter(transmitter);
       soapy_protocol_set_tx_antenna(transmitter,dac[0].antenna);
-/*
-      for(int i=0;i<radio->info.soapy.tx_gains;i++) {
-        soapy_protocol_set_tx_gain_element(transmitter,radio->info.soapy.tx_gain[i],dac[0].tx_gain[i]);
-      }
-*/
       soapy_protocol_set_tx_gain(transmitter,transmitter->drive);
       soapy_protocol_set_tx_frequency(transmitter);
       soapy_protocol_start_transmitter(transmitter);
     }
 
     soapy_protocol_set_rx_antenna(rx,adc[0].antenna);
-/*
-    for(int i=0;i<radio->info.soapy.rx_gains;i++) {
-      soapy_protocol_set_gain_element(rx,radio->info.soapy.rx_gain[i],adc[0].rx_gain[i]);
-    }
-*/
-
     soapy_protocol_set_rx_frequency(rx,VFO_A);
     soapy_protocol_set_automatic_gain(rx,adc[0].agc);
-    for(int i=0;i<radio->info.soapy.rx_gains;i++) {
-      soapy_protocol_set_gain_element(rx,radio->info.soapy.rx_gain[i],adc[0].rx_gain[i]);
-    }
 
     if(vfo[0].ctun) {
       setFrequency(vfo[0].ctun_frequency);
@@ -1286,7 +1276,7 @@ void start_radio() {
     soapy_protocol_start_receiver(rx);
 
 //g_print("radio: set rf_gain=%f\n",rx->rf_gain);
-    soapy_protocol_set_gain(rx,rx->rf_gain);
+    soapy_protocol_set_gain(rx);
 
   }
 #endif
@@ -1821,7 +1811,7 @@ void set_attenuation(int value) {
         break;
 #ifdef SOAPYSDR
       case SOAPYSDR_PROTOCOL:
-        soapy_protocol_set_gain(active_receiver,value * 1.0);
+        soapy_protocol_set_gain_element(active_receiver,radio->info.soapy.rx_gain[0],(int)adc[0].gain);
         break;
 #endif
     }
@@ -2119,28 +2109,81 @@ g_print("radioRestoreState: %s\n",property_path);
     value=getProperty("mute_rx_while_transmitting");
     if(value) mute_rx_while_transmitting=atoi(value);
 
-#ifdef SOAPYSDR
+    value=getProperty("radio.adc[0].filters");
+    if(value) adc[0].filters=atoi(value);
+    value=getProperty("radio.adc[0].hpf");
+    if(value) adc[0].hpf=atoi(value);
+    value=getProperty("radio.adc[0].lpf");
+    if(value) adc[0].lpf=atoi(value);
+    value=getProperty("radio.adc[0].antenna");
+    if(value) adc[0].antenna=atoi(value);
+    value=getProperty("radio.adc[0].dither");
+    if(value) adc[0].dither=atoi(value);
+    value=getProperty("radio.adc[0].random");
+    if(value) adc[0].random=atoi(value);
+    value=getProperty("radio.adc[0].preamp");
+    if(value) adc[0].preamp=atoi(value);
+    value=getProperty("radio.adc[0].attenuation");
+    if(value) adc[0].attenuation=atoi(value);
+    value=getProperty("radio.adc[0].enable_step_attenuation");
+    if(value) adc[0].enable_step_attenuation=atoi(value);
+    value=getProperty("radio.adc[0].gain");
+    if(value) adc[0].gain=atof(value);
+    value=getProperty("radio.adc[0].min_gain");
+    if(value) adc[0].min_gain=atof(value);
+    value=getProperty("radio.adc[0].max_gain");
+    if(value) adc[0].max_gain=atof(value);
+
+#ifdef  SOAPYSDR
     if(device==SOAPYSDR_USB_DEVICE) {
-      char name[128];
-      for(int i=0;i<radio->info.soapy.rx_gains;i++) {
-        sprintf(name,"radio.adc[0].rx_gain.%s",radio->info.soapy.rx_gain[i]) ;
-        value=getProperty(name);
-        if(value!=NULL) adc[0].rx_gain[i]=atoi(value);
-      }
       value=getProperty("radio.adc[0].agc");
-      if(value!=NULL) adc[0].agc=atoi(value);
-      value=getProperty("radio.adc[0].antenna");
-      if(value!=NULL) adc[0].antenna=atoi(value);
-  
-      value=getProperty("radio.dac[0].antenna");
-      if(value!=NULL) dac[0].antenna=atoi(value);
-      for(int i=0;i<radio->info.soapy.tx_gains;i++) {
-        sprintf(name,"radio.dac[0].tx_gain.%s",radio->info.soapy.tx_gain[i]);
-        value=getProperty(name);
-        if(value!=NULL) dac[0].tx_gain[i]=atoi(value);
-      }
+      if(value) adc[0].agc=atoi(value);
     }
 #endif
+    value=getProperty("radio.dac[0].antenna");
+    if(value) dac[0].antenna=atoi(value);
+    value=getProperty("radio.dac[0].gain");
+    if(value) dac[0].gain=atof(value);
+
+    if(receivers>1) {
+      value=getProperty("radio.adc[1].filters");
+      if(value) adc[1].filters=atoi(value);
+      value=getProperty("radio.adc[1].hpf");
+      if(value) adc[1].hpf=atoi(value);
+      value=getProperty("radio.adc[1].lpf");
+      if(value) adc[1].lpf=atoi(value);
+      value=getProperty("radio.adc[1].antenna");
+      if(value) adc[1].antenna=atoi(value);
+      value=getProperty("radio.adc[1].dither");
+      if(value) adc[1].dither=atoi(value);
+      value=getProperty("radio.adc[1].random");
+      if(value) adc[1].random=atoi(value);
+      value=getProperty("radio.adc[1].preamp");
+      if(value) adc[1].preamp=atoi(value);
+      value=getProperty("radio.adc[1].attenuation");
+      if(value) adc[1].attenuation=atoi(value);
+      value=getProperty("radio.adc[1].enable_step_attenuation");
+      if(value) adc[1].enable_step_attenuation=atoi(value);
+      value=getProperty("radio.adc[1].gain");
+      if(value) adc[1].gain=atof(value);
+      value=getProperty("radio.adc[1].min_gain");
+      if(value) adc[1].min_gain=atof(value);
+      value=getProperty("radio.adc[1].max_gain");
+      if(value) adc[1].max_gain=atof(value);
+
+
+#ifdef  SOAPYSDR
+      if(device==SOAPYSDR_USB_DEVICE) {
+        value=getProperty("radio.adc[1].agc");
+        if(value) adc[1].agc=atoi(value);
+      }
+#endif
+      value=getProperty("radio.dac[1].antenna");
+      if(value) dac[1].antenna=atoi(value);
+      value=getProperty("radio.dac[1].gain");
+      if(value) dac[1].gain=atof(value);
+
+    }
 
 #ifdef MIDI
     midi_restore_state();
@@ -2377,55 +2420,81 @@ g_print("radioSaveState: %s\n",property_path);
     sprintf(value,"%d",rx_gain_calibration);
     setProperty("rx_gain_calibration",value);
 
-#ifdef SOAPYSDR
+    sprintf(value,"%d", adc[0].filters);
+    setProperty("radio.adc[0].filters",value);
+    sprintf(value,"%d", adc[0].hpf);
+    setProperty("radio.adc[0].hpf",value);
+    sprintf(value,"%d", adc[0].lpf);
+    setProperty("radio.adc[0].lpf",value);
+    sprintf(value,"%d", adc[0].antenna);
+    setProperty("radio.adc[0].antenna",value);
+    sprintf(value,"%d", adc[0].dither);
+    setProperty("radio.adc[0].dither",value);
+    sprintf(value,"%d", adc[0].random);
+    setProperty("radio.adc[0].random",value);
+    sprintf(value,"%d", adc[0].preamp);
+    setProperty("radio.adc[0].preamp",value);
+    sprintf(value,"%d", adc[0].attenuation);
+    setProperty("radio.adc[0].attenuation",value);
+    sprintf(value,"%d", adc[0].enable_step_attenuation);
+    setProperty("radio.adc[0].enable_step_attenuation",value);
+    sprintf(value,"%f", adc[0].gain);
+    setProperty("radio.adc[0].gain",value);
+    sprintf(value,"%f", adc[0].min_gain);
+    setProperty("radio.adc[0].min_gain",value);
+    sprintf(value,"%f", adc[0].max_gain);
+    setProperty("radio.adc[0].max_gain",value);
+
+#ifdef  SOAPYSDR
     if(device==SOAPYSDR_USB_DEVICE) {
-      char name[128];
-      for(int i=0;i<radio->info.soapy.rx_gains;i++) {
-        sprintf(name,"radio.adc[0].rx_gain.%s",radio->info.soapy.rx_gain[i]);
-        sprintf(value,"%d", adc[0].rx_gain[i]);
-        setProperty(name,value);
-      }
-      sprintf(name,"radio.adc[0].agc");
       sprintf(value,"%d", soapy_protocol_get_automatic_gain(receiver[0]));
-      setProperty(name,value);
-      sprintf(name,"radio.adc[0].antenna");
-      sprintf(value,"%d", adc[0].antenna);
-      setProperty(name,value);
-
-      sprintf(name,"radio.dac[0].antenna");
-      sprintf(value,"%d", dac[0].antenna);
-      setProperty(name,value);
+      setProperty("radio.adc[0].agc",value);
+    }
+#endif
 
-      for(int i=0;i<radio->info.soapy.tx_gains;i++) {
-        sprintf(name,"radio.dac[0].tx_gain.%s",radio->info.soapy.tx_gain[i]);
-        sprintf(value,"%d", dac[0].tx_gain[i]);
-        setProperty(name,value);
-      }
+   sprintf(value,"%d", dac[0].antenna);
+   setProperty("radio.dac[0].antenna",value);
+   sprintf(value,"%f", dac[0].gain);
+   setProperty("radio.dac[0].gain",value);
 
-      for(int i=0;i<radio->info.soapy.rx_gains;i++) {
-        sprintf(name,"radio.adc[1].rx_gain.%s",radio->info.soapy.rx_gain[i]);
-        sprintf(value,"%d", adc[1].rx_gain[i]);
-        setProperty(name,value);
-      }
-      sprintf(name,"radio.adc[1].agc");
-      sprintf(value,"%d", soapy_protocol_get_automatic_gain(receiver[1]));
-      setProperty(name,value);
-      sprintf(name,"radio.adc[1].antenna");
+   if(receivers>1) {
+      sprintf(value,"%d", adc[1].filters);
+      setProperty("radio.adc[1].filters",value);
+      sprintf(value,"%d", adc[1].hpf);
+      setProperty("radio.adc[1].hpf",value);
+      sprintf(value,"%d", adc[1].lpf);
+      setProperty("radio.adc[1].lpf",value);
       sprintf(value,"%d", adc[1].antenna);
-      setProperty(name,value);
-
-      sprintf(name,"radio.dac[1].antenna");
-      sprintf(value,"%d", dac[1].antenna);
-      setProperty(name,value);
-
-      for(int i=0;i<radio->info.soapy.tx_gains;i++) {
-        sprintf(name,"radio.dac[1].tx_gain.%s",radio->info.soapy.tx_gain[i]);
-        sprintf(value,"%d", dac[1].tx_gain[i]);
-        setProperty(name,value);
+      setProperty("radio.adc[1].antenna",value);
+      sprintf(value,"%d", adc[1].dither);
+      setProperty("radio.adc[1].dither",value);
+      sprintf(value,"%d", adc[1].random);
+      setProperty("radio.adc[1].random",value);
+      sprintf(value,"%d", adc[1].preamp);
+      setProperty("radio.adc[1].preamp",value);
+      sprintf(value,"%d", adc[1].attenuation);
+      setProperty("radio.adc[1].attenuation",value);
+      sprintf(value,"%d", adc[1].enable_step_attenuation);
+      setProperty("radio.adc[1].enable_step_attenuation",value);
+      sprintf(value,"%f", adc[1].gain);
+      setProperty("radio.adc[1].gain",value);
+      sprintf(value,"%f", adc[1].min_gain);
+      setProperty("radio.adc[1].min_gain",value);
+      sprintf(value,"%f", adc[1].max_gain);
+      setProperty("radio.adc[1].max_gain",value);
+
+#ifdef  SOAPYSDR
+      if(device==SOAPYSDR_USB_DEVICE) {
+        sprintf(value,"%d", soapy_protocol_get_automatic_gain(receiver[1]));
+        setProperty("radio.adc[1].agc",value);
       }
-    }
 #endif
 
+      sprintf(value,"%d", dac[1].antenna);
+      setProperty("radio.dac[1].antenna",value);
+      sprintf(value,"%f", dac[1].gain);
+      setProperty("radio.dac[1].gain",value);
+    }
 
     sprintf(value,"%d",receivers);
     setProperty("receivers",value);
diff --git a/radio.h b/radio.h
index 6be879da84818f46a9aa25d47ef5cdef725725a6..e19bc89e6455b6a562e097ebe609aebc64a0824c 100644 (file)
--- a/radio.h
+++ b/radio.h
@@ -190,7 +190,6 @@ extern int receivers;
 
 extern ADC adc[2];
 extern DAC dac[2];
-extern int adc_attenuation[2];
 
 extern int locked;
 
index 3d4572448d9a3112a926c540e3637538a44df739..2b92bc83a4c5c60840f6d2b02e488774d88102a0 100644 (file)
@@ -81,10 +81,10 @@ static gboolean delete_event(GtkWidget *widget, GdkEvent *event, gpointer user_d
 #ifdef SOAPYSDR
 static void rf_gain_value_changed_cb(GtkWidget *widget, gpointer data) {
   ADC *adc=(ADC *)data;
-  active_receiver->rf_gain=gtk_spin_button_get_value(GTK_SPIN_BUTTON(widget));
+  adc->gain=gtk_spin_button_get_value(GTK_SPIN_BUTTON(widget));
   
   if(radio->device==SOAPYSDR_USB_DEVICE) {
-    soapy_protocol_set_gain(receiver[0],active_receiver->rf_gain);
+    soapy_protocol_set_gain(receiver[0]);
   }
 
 /*
@@ -881,7 +881,7 @@ void radio_menu(GtkWidget *parent) {
       max=73.0;
     }
     GtkWidget *rf_gain_b=gtk_spin_button_new_with_range(0.0,max,1.0);
-    gtk_spin_button_set_value(GTK_SPIN_BUTTON(rf_gain_b),active_receiver->rf_gain);
+    gtk_spin_button_set_value(GTK_SPIN_BUTTON(rf_gain_b),adc[active_receiver->id].gain);
     gtk_grid_attach(GTK_GRID(grid),rf_gain_b,col,row,1,1);
     g_signal_connect(rf_gain_b,"value_changed",G_CALLBACK(rf_gain_value_changed_cb),&adc[0]);
 
index a073e71e28ecdf1150fc23c38f114260e017200a..c6ffc05a200c7d681aa3c13d435ba02747a9b483 100644 (file)
@@ -277,9 +277,9 @@ void receiver_save_state(RECEIVER *rx) {
     sprintf(name,"receiver.%d.volume",rx->id);
     sprintf(value,"%f",rx->volume);
     setProperty(name,value);
-    sprintf(name,"receiver.%d.rf_gain",rx->id);
-    sprintf(value,"%f",rx->rf_gain);
-    setProperty(name,value);
+    //sprintf(name,"receiver.%d.rf_gain",rx->id);
+    //sprintf(value,"%f",rx->rf_gain);
+    //setProperty(name,value);
     sprintf(name,"receiver.%d.agc",rx->id);
     sprintf(value,"%d",rx->agc);
     setProperty(name,value);
@@ -471,9 +471,9 @@ fprintf(stderr,"receiver_restore_state: id=%d\n",rx->id);
     sprintf(name,"receiver.%d.volume",rx->id);
     value=getProperty(name);
     if(value) rx->volume=atof(value);
-    sprintf(name,"receiver.%d.rf_gain",rx->id);
-    value=getProperty(name);
-    if(value) rx->rf_gain=atof(value);
+    //sprintf(name,"receiver.%d.rf_gain",rx->id);
+    //value=getProperty(name);
+    //if(value) rx->rf_gain=atof(value);
     sprintf(name,"receiver.%d.agc",rx->id);
     value=getProperty(name);
     if(value) rx->agc=atoi(value);
@@ -896,7 +896,6 @@ fprintf(stderr,"create_pure_signal_receiver: id=%d buffer_size=%d\n",id,buffer_s
   rx->panadapter_step=20;
 
   rx->volume=5.0;
-  rx->rf_gain=50.0;
 
   rx->squelch_enable=0;
   rx->squelch=0;
@@ -1032,7 +1031,6 @@ fprintf(stderr,"create_receiver: id=%d default adc=%d\n",rx->id, rx->adc);
   rx->waterfall_automatic=1;
 
   rx->volume=0.1;
-  rx->rf_gain=50.0;
 
   rx->dither=0;
   rx->random=0;
@@ -1209,13 +1207,6 @@ void receiver_change_adc(RECEIVER *rx,int adc) {
 
 void receiver_change_sample_rate(RECEIVER *rx,int sample_rate) {
 
-//
-// For  the PS_RX_FEEDBACK receiver we have to change
-// the number of pixels in the display (needed for
-// conversion from higher sample rates to 48K such
-// that the central part can be displayed in the TX panadapter
-//
-
   g_mutex_lock(&rx->mutex);
 
   rx->sample_rate=sample_rate;
@@ -1224,20 +1215,22 @@ void receiver_change_sample_rate(RECEIVER *rx,int sample_rate) {
   rx->hz_per_pixel=(double)rx->sample_rate/(double)rx->width;
 
 g_print("receiver_change_sample_rate: id=%d rate=%d scale=%d buffer_size=%d output_samples=%d\n",rx->id,sample_rate,scale,rx->buffer_size,rx->output_samples);
+
 #ifdef PURESIGNAL
-  if (rx->id == PS_RX_FEEDBACK) {
-    if (protocol == ORIGINAL_PROTOCOL) {
-      rx->pixels = 2* scale * rx->width;
-    } else {
-      // We should never arrive here, since the sample rate of the
-      // PS feedback receiver is fixed.
-      rx->pixels = 8 * rx->width;
-    }
+  //
+  // In the old protocol, the RX_FEEDBACK sample rate is tied
+  // to the radio's sample rate and therefore may vary.
+  // Since there is no downstream WDSP receiver her, the only thing
+  // we have to do here is to adapt the spectrum display of the 
+  // feedback and must then return (rx->id is not a WDSP channel!)
+  // 
+  if (rx->id == PS_RX_FEEDBACK && protocol == ORIGINAL_PROTOCOL) {
+    rx->pixels = 2* scale * rx->width;
     g_free(rx->pixel_samples);
     rx->pixel_samples=g_new(float,rx->pixels);
     init_analyzer(rx);
-    fprintf(stderr,"PS FEEDBACK change sample rate:id=%d rate=%d buffer_size=%d output_samples=%d\n",
-                   rx->id, rx->sample_rate, rx->buffer_size, rx->output_samples);
+    g_print("%s: PS FEEDBACK: id=%d rate=%d buffer_size=%d output_samples=%d\n",
+            __FUNCTION__,rx->id, rx->sample_rate, rx->buffer_size, rx->output_samples);
     g_mutex_unlock(&rx->mutex);
     return;
   }
index 0551adccd82209cc712008e1bd0bd64e84789947..11af7fcd3fa633e8885a846365c451b34a26fffc 100644 (file)
@@ -43,7 +43,6 @@ typedef struct _receiver {
   gint adc;
 
   gdouble volume;
-  gdouble rf_gain;
 
   gint agc;
   gdouble agc_gain;
index c60cd7cbfc581603016d6839f13df71cd487c0fb..c7a78cb5d0d76e3fff024fc5ac61a31e1be4ec0e 100644 (file)
@@ -419,13 +419,13 @@ void rx_panadapter_update(RECEIVER *rx) {
 
   // agc
   if(rx->agc!=AGC_OFF) {
-    double knee_y=rx->agc_thresh+(double)adc_attenuation[rx->adc];
+    double knee_y=rx->agc_thresh+(double)adc[rx->adc].attenuation;
     if (filter_board == ALEX && rx->adc == 0) knee_y += (double)(10*rx->alex_attenuation);
     knee_y = floor((rx->panadapter_high - knee_y)
                         * (double) display_height
                         / (rx->panadapter_high - rx->panadapter_low));
 
-    double hang_y=rx->agc_hang+(double)adc_attenuation[rx->adc];
+    double hang_y=rx->agc_hang+(double)adc[rx->adc].attenuation;
     if (filter_board == ALEX && rx->adc == 0) hang_y += (double)(10*rx->alex_attenuation);
     hang_y = floor((rx->panadapter_high - hang_y)
                         * (double) display_height
@@ -487,9 +487,9 @@ void rx_panadapter_update(RECEIVER *rx) {
   samples[pan]=-200.0;
   samples[display_width-1+pan]=-200.0;
   if(have_rx_gain) {
-    s1=(double)samples[pan]+rx_gain_calibration-adc_attenuation[rx->adc];
+    s1=(double)samples[pan]+rx_gain_calibration-adc[rx->adc].attenuation;
   } else {
-    s1=(double)samples[pan]+(double)adc_attenuation[rx->adc];
+    s1=(double)samples[pan]+(double)adc[rx->adc].attenuation;
   }
   cairo_move_to(cr, 0.0, s1);
   if (filter_board == ALEX && rx->adc == 0) s1 += (double)(10*rx->alex_attenuation);
@@ -499,7 +499,7 @@ void rx_panadapter_update(RECEIVER *rx) {
   }
 #ifdef SOAPYSDR
   if(protocol==SOAPYSDR_PROTOCOL) {
-    s1-=rx->rf_gain;
+    s1-=adc[rx->adc].gain;
   }
 #endif
 
@@ -509,9 +509,9 @@ void rx_panadapter_update(RECEIVER *rx) {
   cairo_move_to(cr, 0.0, s1);
   for(i=1;i<display_width;i++) {
     if(have_rx_gain) {
-      s2=(double)samples[i+pan]+rx_gain_calibration-adc_attenuation[rx->adc];
+      s2=(double)samples[i+pan]+rx_gain_calibration-adc[rx->adc].attenuation;
     } else {
-      s2=(double)samples[i+pan]+(double)adc_attenuation[rx->adc];
+      s2=(double)samples[i+pan]+(double)adc[rx->adc].attenuation;
     }
     if (filter_board == ALEX && rx->adc == 0) s2 += (double)(10*rx->alex_attenuation);
     if (filter_board == CHARLY25) {
@@ -520,7 +520,7 @@ void rx_panadapter_update(RECEIVER *rx) {
     }
 #ifdef SOAPYSDR
     if(protocol==SOAPYSDR_PROTOCOL) {
-      s2-=rx->rf_gain;
+      s2-=adc[rx->adc].gain;
     }
 #endif
     s2 = floor((rx->panadapter_high - s2)
index 76163eda07d63e390d1c7d9b5b61d165f573a7a1..087abb09883d4f27733d76cf0a7d46349714d194 100644 (file)
--- a/sliders.c
+++ b/sliders.c
@@ -123,7 +123,7 @@ int sliders_active_receiver_changed(void *data) {
     if (filter_board == CHARLY25) {
       update_att_preamp();
     } else {
-      gtk_range_set_value (GTK_RANGE(attenuation_scale),(double)adc_attenuation[active_receiver->adc]);
+      gtk_range_set_value (GTK_RANGE(attenuation_scale),(double)adc[active_receiver->adc].attenuation);
     }
     char title[64];
     if (have_rx_gain) {
@@ -144,26 +144,26 @@ int scale_timeout_cb(gpointer data) {
 }
 
 static void attenuation_value_changed_cb(GtkWidget *widget, gpointer data) {
-  adc_attenuation[active_receiver->adc]=(int)gtk_range_get_value(GTK_RANGE(attenuation_scale));
+  adc[active_receiver->adc].attenuation=(int)gtk_range_get_value(GTK_RANGE(attenuation_scale));
 #ifdef CLIENT_SERVER
   if(radio_is_remote) {
-    send_attenuation(client_socket,active_receiver->id,(int)adc_attenuation[active_receiver->adc]);
+    send_attenuation(client_socket,active_receiver->id,(int)adc[active_receiver->adc].attenuation);
   } else {
 #endif
-    set_attenuation(adc_attenuation[active_receiver->adc]);
+    set_attenuation(adc[active_receiver->adc].attenuation);
 #ifdef CLIENT_SERVER
   }
 #endif
 }
 
 void set_attenuation_value(double value) {
-  adc_attenuation[active_receiver->adc]=(int)value;
-  set_attenuation(adc_attenuation[active_receiver->adc]);
+  adc[active_receiver->adc].attenuation=(int)value;
+  set_attenuation(adc[active_receiver->adc].attenuation);
   if(display_sliders) {
     if (have_rx_gain) {
-       gtk_range_set_value (GTK_RANGE(attenuation_scale),(double)adc_attenuation[active_receiver->adc]);
+       gtk_range_set_value (GTK_RANGE(attenuation_scale),(double)adc[active_receiver->adc].attenuation);
     } else {
-        gtk_range_set_value (GTK_RANGE(attenuation_scale),(double)adc_attenuation[active_receiver->adc]);
+        gtk_range_set_value (GTK_RANGE(attenuation_scale),(double)adc[active_receiver->adc].attenuation);
     }
   } else {
     if(scale_status!=ATTENUATION) {
@@ -189,7 +189,7 @@ void set_attenuation_value(double value) {
         attenuation_scale=gtk_scale_new_with_range(GTK_ORIENTATION_HORIZONTAL,0.0, 31.0, 1.00);
       }
       gtk_widget_set_size_request (attenuation_scale, 400, 30);
-      gtk_range_set_value (GTK_RANGE(attenuation_scale),(double)adc_attenuation[active_receiver->adc]);
+      gtk_range_set_value (GTK_RANGE(attenuation_scale),(double)adc[active_receiver->adc].attenuation);
       gtk_widget_show(attenuation_scale);
       gtk_container_add(GTK_CONTAINER(content),attenuation_scale);
       scale_timer=g_timeout_add(2000,scale_timeout_cb,NULL);
@@ -197,7 +197,7 @@ void set_attenuation_value(double value) {
       gtk_dialog_run(GTK_DIALOG(scale_dialog));
     } else {
       g_source_remove(scale_timer);
-      gtk_range_set_value (GTK_RANGE(attenuation_scale),(double)adc_attenuation[active_receiver->adc]);
+      gtk_range_set_value (GTK_RANGE(attenuation_scale),(double)adc[active_receiver->adc].attenuation);
       scale_timer=g_timeout_add(2000,scale_timeout_cb,NULL);
     }
   }
@@ -212,10 +212,10 @@ void update_att_preamp(void) {
       active_receiver->alex_attenuation=0;
       active_receiver->preamp=0;
       active_receiver->dither=0;
-      adc_attenuation[active_receiver->adc] = 0;
+      adc[active_receiver->adc].attenuation = 0;
     }
     sprintf(id, "%d", active_receiver->alex_attenuation);
-    adc_attenuation[active_receiver->adc] = 12*active_receiver->alex_attenuation;
+    adc[active_receiver->adc].attenuation = 12*active_receiver->alex_attenuation;
     gtk_combo_box_set_active_id(GTK_COMBO_BOX(c25_att_combobox), id);
     sprintf(id, "%d", active_receiver->preamp + active_receiver->dither);
     gtk_combo_box_set_active_id(GTK_COMBO_BOX(c25_preamp_combobox), id);
@@ -249,7 +249,7 @@ static void c25_att_combobox_changed(GtkWidget *widget, gpointer data) {
   if (active_receiver->adc == 0) {
     // this button is only valid for the first receiver
     // store attenuation, such that in meter.c the correct level is displayed
-    adc_attenuation[active_receiver->adc] = 12*val;
+    adc[active_receiver->adc].attenuation = 12*val;
     set_alex_attenuation(val);
   } else {
     // always show "0 dB" on the button if the second RX is active
@@ -388,27 +388,27 @@ void set_af_gain(int rx,double value) {
 }
 
 static void rf_gain_value_changed_cb(GtkWidget *widget, gpointer data) {
-    active_receiver->rf_gain=gtk_range_get_value(GTK_RANGE(af_gain_scale));
+    adc[active_receiver->adc].gain=gtk_range_get_value(GTK_RANGE(af_gain_scale));
 #ifdef SOAPYSDR
     if(protocol==SOAPYSDR_PROTOCOL) {
-      soapy_protocol_set_gain(active_receiver,active_receiver->rf_gain);
+      soapy_protocol_set_gain(active_receiver);
     }
 #endif
 }
 
 void update_rf_gain() {
-  set_rf_gain(active_receiver->id,active_receiver->rf_gain);
+  set_rf_gain(active_receiver->id,adc[active_receiver->id].gain);
 }
 
 void set_rf_gain(int rx,double value) {
-  receiver[rx]->rf_gain=value;
+  adc[receiver[rx]->adc].gain=value;
 #ifdef SOAPYSDR
   if(protocol==SOAPYSDR_PROTOCOL) {
-    soapy_protocol_set_gain(active_receiver,active_receiver->rf_gain);
+    soapy_protocol_set_gain(active_receiver);
   }
 #endif
   if(display_sliders) {
-    gtk_range_set_value (GTK_RANGE(attenuation_scale),receiver[rx]->rf_gain);
+    gtk_range_set_value (GTK_RANGE(rf_gain_scale),adc[receiver[rx]->id].gain);
   } else {
     if(scale_status!=RF_GAIN || scale_rx!=rx) {
       if(scale_status!=NO_FUNCTION) {
@@ -426,7 +426,7 @@ void set_rf_gain(int rx,double value) {
       GtkWidget *content=gtk_dialog_get_content_area(GTK_DIALOG(scale_dialog));
       rf_gain_scale=gtk_scale_new_with_range(GTK_ORIENTATION_HORIZONTAL,0.0, 100.0, 1.00);
       gtk_widget_set_size_request (rf_gain_scale, 400, 30);
-      gtk_range_set_value (GTK_RANGE(rf_gain_scale),receiver[rx]->rf_gain);
+      gtk_range_set_value (GTK_RANGE(rf_gain_scale),adc[receiver[rx]->id].gain);
       gtk_widget_show(rf_gain_scale);
       gtk_container_add(GTK_CONTAINER(content),rf_gain_scale);
       scale_timer=g_timeout_add(2000,scale_timeout_cb,NULL);
@@ -434,7 +434,7 @@ void set_rf_gain(int rx,double value) {
       gtk_dialog_run(GTK_DIALOG(scale_dialog));
     } else {
       g_source_remove(scale_timer);
-      gtk_range_set_value (GTK_RANGE(rf_gain_scale),receiver[rx]->rf_gain);
+      gtk_range_set_value (GTK_RANGE(rf_gain_scale),adc[receiver[rx]->id].gain);
       scale_timer=g_timeout_add(2000,scale_timeout_cb,NULL);
     }
   }
@@ -844,10 +844,10 @@ fprintf(stderr,"sliders_init: width=%d height=%d\n", width,height);
 
   if (have_rx_gain) {
        attenuation_scale=gtk_scale_new_with_range(GTK_ORIENTATION_HORIZONTAL,-12.0, 48.0, 1.0);
-       gtk_range_set_value (GTK_RANGE(attenuation_scale),adc_attenuation[active_receiver->adc]);
+       gtk_range_set_value (GTK_RANGE(attenuation_scale),adc[active_receiver->adc].attenuation);
   } else {
        attenuation_scale=gtk_scale_new_with_range(GTK_ORIENTATION_HORIZONTAL,0.0, 31.0, 1.0);
-       gtk_range_set_value (GTK_RANGE(attenuation_scale),adc_attenuation[active_receiver->adc]);
+       gtk_range_set_value (GTK_RANGE(attenuation_scale),adc[active_receiver->adc].attenuation);
   }
   gtk_range_set_increments (GTK_RANGE(attenuation_scale),1.0,1.0);
  
index c10550ad319edfd951311bfc2bdb63354e0b49c5..18d66845e6456dd7a07dbefd42989ee77293bd08 100644 (file)
@@ -466,10 +466,10 @@ void soapy_protocol_set_tx_antenna(TRANSMITTER *tx,int ant) {
   }
 }
 
-void soapy_protocol_set_gain(RECEIVER *rx,double gain) {
+void soapy_protocol_set_gain(RECEIVER *rx) {
   int rc;
 //fprintf(stderr,"soapy_protocol_set_gain: adc=%d gain=%f\n",gain);
-  rc=SoapySDRDevice_setGain(soapy_device,SOAPY_SDR_RX,rx->adc,gain);
+  rc=SoapySDRDevice_setGain(soapy_device,SOAPY_SDR_RX,rx->adc,adc[rx->adc].gain);
   if(rc!=0) {
     fprintf(stderr,"soapy_protocol: SoapySDRDevice_setGain failed: %s\n",SoapySDR_errToStr(rc));
   }
index 541dbf92974b1634a9d8af5e71c95c77cabc156b..b4973126cfbe0607dc3ef68581f104d269acb588 100644 (file)
@@ -32,7 +32,7 @@ void soapy_protocol_stop();
 void soapy_protocol_set_rx_frequency(RECEIVER *rx,int v);
 void soapy_protocol_set_rx_antenna(RECEIVER *rx,int ant);
 void soapy_protocol_set_lna_gain(RECEIVER *rx,int gain);
-void soapy_protocol_set_gain(RECEIVER *rx,double gain);
+void soapy_protocol_set_gain(RECEIVER *rx);
 void soapy_protocol_set_gain_element(RECEIVER *rx,char *name,int gain);
 int soapy_protocol_get_gain_element(RECEIVER *rx,char *name);
 void soapy_protocol_change_sample_rate(RECEIVER *rx);
index 479398c4ae8e7c0d1bbeb1f2098260b8496b801d..01bb5b71fbe3866e829d36075629c51d29276213 100644 (file)
@@ -183,9 +183,9 @@ void waterfall_update(RECEIVER *rx) {
 
     for(i=0;i<width;i++) {
             if(have_rx_gain) {
-              sample=samples[i+pan]+(float)(rx_gain_calibration-adc_attenuation[rx->adc]);
+              sample=samples[i+pan]+(float)(rx_gain_calibration-adc[rx->adc].attenuation);
             } else {
-              sample=samples[i+pan]+(float)adc_attenuation[rx->adc];
+              sample=samples[i+pan]+(float)adc[rx->adc].attenuation;
             }
             average+=(int)sample;
             if(sample<(float)rx->waterfall_low) {