]> git.rkrishnan.org Git - pihpsdr.git/commitdiff
make NB settings per receiver than global for all receivers
authorRamakrishnan Muthukrishnan <ram@rkrishnan.org>
Mon, 22 Aug 2022 05:02:39 +0000 (10:32 +0530)
committerRamakrishnan Muthukrishnan <ram@rkrishnan.org>
Mon, 22 Aug 2022 05:02:55 +0000 (10:32 +0530)
nb_menu.c
nb_menu.h
noise_menu.c
radio.c
receiver.c
receiver.h

index f7986106da0387b057f85f3c11a19bcf7c3c97d7..a8755d921952b7c03998226dc45b6998a96ffbfb 100644 (file)
--- a/nb_menu.c
+++ b/nb_menu.c
@@ -27,6 +27,7 @@
 
 #include "new_menu.h"
 #include "noise_menu.h"
+#include "radio.h"
 
 #include <wdsp.h>
 
@@ -34,13 +35,6 @@ static GtkWidget *parent_window = NULL;
 static GtkWidget *menu_b = NULL;
 static GtkWidget *dialog = NULL;
 
-// all the time are in ms
-double nb_lag_time = 0.01;
-double nb_lead_time = 0.01;
-double nb_transition_time = 0.01;
-double nb_threshold_value = 18.0;
-int nb2_mode = 0; // 0, 1, 2, 3, 4
-
 void nb_changed() {
     update_nb();
 }
@@ -64,31 +58,30 @@ static gboolean delete_event(GtkWidget *widget, GdkEvent *event, gpointer user_d
 }
 
 static void nb_lag_time_value_changed_cb(GtkWidget *widget, gpointer data) {
-    nb_lag_time = gtk_spin_button_get_value(GTK_SPIN_BUTTON(widget));
-    //nb_lag_time *= 0.001; // convert ms to sec
+    active_receiver->nb_lag_time = gtk_spin_button_get_value(GTK_SPIN_BUTTON(widget));
     nb_changed();
 }
 
 static void nb_lead_time_value_changed_cb(GtkWidget *widget, gpointer data) {
-    nb_lead_time = gtk_spin_button_get_value(GTK_SPIN_BUTTON(widget));
+    active_receiver->nb_lead_time = gtk_spin_button_get_value(GTK_SPIN_BUTTON(widget));
     //nb_lead_time *= 0.001;
     nb_changed();
 }
 
 static void nb_transition_time_value_changed_cb(GtkWidget *widget, gpointer data) {
-    nb_transition_time = gtk_spin_button_get_value(GTK_SPIN_BUTTON(widget));
+    active_receiver->nb_transition_time = gtk_spin_button_get_value(GTK_SPIN_BUTTON(widget));
     //nb_transition_time *= 0.001; // ms to s
     nb_changed();
 }
 
 static void nb_threshold_value_changed_cb(GtkWidget *widget, gpointer data) {
-    nb_threshold_value = gtk_spin_button_get_value(GTK_SPIN_BUTTON(widget));
+    active_receiver->nb_threshold_value = gtk_spin_button_get_value(GTK_SPIN_BUTTON(widget));
     // nb_threshold_value *= 0.165;
     nb_changed();
 }
 
 static void nb2_mode_changed_cb(GtkWidget *widget, gpointer data) {
-    nb2_mode = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(widget));
+    active_receiver->nb2_mode = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(widget));
     nb_changed();
 }
 
@@ -142,31 +135,31 @@ void nb_menu(GtkWidget *parent) {
 
     // lag time spin button
     GtkWidget *nb_lag_time_b=gtk_spin_button_new_with_range(0.0, 0.1, 0.0001);
-    gtk_spin_button_set_value(GTK_SPIN_BUTTON(nb_lag_time_b),(double)nb_lag_time);
+    gtk_spin_button_set_value(GTK_SPIN_BUTTON(nb_lag_time_b),(double)active_receiver->nb_lag_time);
     gtk_widget_show(nb_lag_time_b);
     gtk_grid_attach(GTK_GRID(grid),nb_lag_time_b,1,1,1,1);
     g_signal_connect(nb_lag_time_b,"value_changed",G_CALLBACK(nb_lag_time_value_changed_cb),NULL);
 
     GtkWidget *nb_lead_time_b=gtk_spin_button_new_with_range(0.0, 0.1, 0.0001);
-    gtk_spin_button_set_value(GTK_SPIN_BUTTON(nb_lead_time_b),(double)nb_lead_time);
+    gtk_spin_button_set_value(GTK_SPIN_BUTTON(nb_lead_time_b),(double)active_receiver->nb_lead_time);
     gtk_widget_show(nb_lead_time_b);
     gtk_grid_attach(GTK_GRID(grid),nb_lead_time_b,1,2,1,1);
     g_signal_connect(nb_lead_time_b,"value_changed",G_CALLBACK(nb_lead_time_value_changed_cb),NULL);
 
     GtkWidget *nb_transition_time_b=gtk_spin_button_new_with_range(0.0, 0.1, 0.0001);
-    gtk_spin_button_set_value(GTK_SPIN_BUTTON(nb_transition_time_b),(double)nb_transition_time);
+    gtk_spin_button_set_value(GTK_SPIN_BUTTON(nb_transition_time_b),(double)active_receiver->nb_transition_time);
     gtk_widget_show(nb_transition_time_b);
     gtk_grid_attach(GTK_GRID(grid),nb_transition_time_b,1,3,1,1);
     g_signal_connect(nb_transition_time_b,"value_changed",G_CALLBACK(nb_transition_time_value_changed_cb),NULL);
 
     GtkWidget *nb_threshold_value_b=gtk_spin_button_new_with_range(15.0, 500.0, 1.0);
-    gtk_spin_button_set_value(GTK_SPIN_BUTTON(nb_threshold_value_b),(double)nb_threshold_value);
+    gtk_spin_button_set_value(GTK_SPIN_BUTTON(nb_threshold_value_b),(double)active_receiver->nb_threshold_value);
     gtk_widget_show(nb_threshold_value_b);
     gtk_grid_attach(GTK_GRID(grid),nb_threshold_value_b,1,4,1,1);
     g_signal_connect(nb_threshold_value_b,"value_changed",G_CALLBACK(nb_threshold_value_changed_cb),NULL);
 
     GtkWidget *nb2_mode_b=gtk_spin_button_new_with_range(0, 5, 1);
-    gtk_spin_button_set_value(GTK_SPIN_BUTTON(nb2_mode_b),(int)nb2_mode);
+    gtk_spin_button_set_value(GTK_SPIN_BUTTON(nb2_mode_b),(int)active_receiver->nb2_mode);
     gtk_widget_show(nb2_mode_b);
     gtk_grid_attach(GTK_GRID(grid),nb2_mode_b,1,5,1,1);
     g_signal_connect(nb2_mode_b,"value_changed",G_CALLBACK(nb2_mode_changed_cb),NULL);
index f4f0b3058bf4f624344cbd53dd87e160ed2f8ebf..a866d98dacbe698a6f6bf0ff266777f55c51aa64 100644 (file)
--- a/nb_menu.h
+++ b/nb_menu.h
@@ -20,8 +20,3 @@
 
 extern void nb_menu(GtkWidget *parent);
 
-extern double nb_lag_time;
-extern double nb_lead_time;
-extern double nb_transition_time;
-extern double nb_threshold_value;
-extern int nb2_mode;
index c23859037ff147695bdcd55a12b58b653f19d7fc..95888418f0487f1e018e7e4eb26e83c2a5d50bf5 100644 (file)
@@ -26,7 +26,6 @@
 
 #include "new_menu.h"
 #include "noise_menu.h"
-#include "nb_menu.h"
 #include "channel.h"
 #include "band.h"
 #include "bandstack.h"
@@ -63,19 +62,19 @@ static gboolean delete_event(GtkWidget *widget, GdkEvent *event, gpointer user_d
 }
 
 void update_nb() {
-    SetEXTANBHangtime(active_receiver->id, nb_lag_time*0.001);
-    SetEXTANBAdvtime(active_receiver->id, nb_lead_time*0.001);
-    SetEXTANBTau(active_receiver->id, nb_transition_time*0.001);
-    SetEXTANBThreshold(active_receiver->id, nb_threshold_value*0.165);
+    SetEXTANBHangtime(active_receiver->id, active_receiver->nb_lag_time*0.001);
+    SetEXTANBAdvtime(active_receiver->id, active_receiver->nb_lead_time*0.001);
+    SetEXTANBTau(active_receiver->id, active_receiver->nb_transition_time*0.001);
+    SetEXTANBThreshold(active_receiver->id, active_receiver->nb_threshold_value*0.165);
 }
 
 void update_nb2() {
-    SetEXTNOBMode(active_receiver->id, nb2_mode);
+    SetEXTNOBMode(active_receiver->id, active_receiver->nb2_mode);
 
-    SetEXTNOBHangtime(active_receiver->id, nb_lag_time);
-    SetEXTNOBAdvtime(active_receiver->id, nb_lead_time);
-    SetEXTNOBTau(active_receiver->id, nb_transition_time);
-    SetEXTNOBThreshold(active_receiver->id, nb_threshold_value);
+    SetEXTNOBHangtime(active_receiver->id, active_receiver->nb_lag_time*0.001);
+    SetEXTNOBAdvtime(active_receiver->id, active_receiver->nb_lead_time*0.001);
+    SetEXTNOBTau(active_receiver->id, active_receiver->nb_transition_time*0.001);
+    SetEXTNOBThreshold(active_receiver->id, active_receiver->nb_threshold_value*0.165);
 }
 
 void set_noise() {
diff --git a/radio.c b/radio.c
index 2ae50219fd6600d2914af43fc6a191142b065c12..78a9d742dcb9366a16ce4afdc3c61b6f9e4a612a 100644 (file)
--- a/radio.c
+++ b/radio.c
@@ -43,7 +43,6 @@
 #include "filter.h"
 #include "main.h"
 #include "mode.h"
-#include "nb_menu.h"
 #include "new_menu.h"
 #include "new_protocol.h"
 #include "old_protocol.h"
@@ -2401,27 +2400,6 @@ void radioRestoreState() {
     listen_port = atoi(value);
 #endif
 
-  // restore NB values
-  value = getProperty("nb_lead_time");
-  if (value)
-      nb_lead_time = atof(value);
-
-  value = getProperty("nb_lag_time");
-  if (value)
-      nb_lag_time = atof(value);
-
-  value = getProperty("nb_transition_time");
-  if (value)
-      nb_transition_time = atof(value);
-
-  value = getProperty("nb_threshold_value");
-  if (value)
-      nb_threshold_value = atof(value);
-
-  value = getProperty("nb2_mode");
-  if (value)
-      nb2_mode = atoi(value);
-
   g_mutex_unlock(&property_mutex);
 }
 
@@ -2762,25 +2740,6 @@ void radioSaveState() {
   setProperty("radio.midi_enabled", value);
   midi_save_state();
 #endif
-
-  // nb values
-  sprintf(value, "%1.4f", nb_lag_time);
-  fprintf(stderr, "saving nb_lag_time: %s\n", value);
-  setProperty("nb_lag_time", value);
-
-  sprintf(value, "%1.4f", nb_lead_time);
-  fprintf(stderr, "saving nb_lead_time: %s\n", value);
-  setProperty("nb_lead_time", value);
-
-  sprintf(value, "%1.4f", nb_transition_time);
-  fprintf(stderr, "saving nb_transition_time: %s\n", value);
-  setProperty("nb_transition_time", value);
-
-  sprintf(value, "%1.4f", (nb_threshold_value));
-  setProperty("nb_threshold_value", value);
-
-  sprintf(value, "%d", nb2_mode);
-  setProperty("nb2_mode", value);
   
   saveProperties(property_path);
   g_mutex_unlock(&property_mutex);
index 576d115ae62879df7b5fdbe8b7f615f240f59617..4e0e9b73c673c8468b2112aef7aea081cae759b7 100644 (file)
@@ -318,6 +318,27 @@ void receiver_save_state(RECEIVER *rx) {
     sprintf(value,"%d",rx->nr2_ae);
     setProperty(name,value);
 
+    // nb values
+    sprintf(name,"receiver.%d.nb_lag_time",rx->id);
+    sprintf(value, "%1.4f", rx->nb_lag_time);
+    setProperty(name, value);
+
+    sprintf(name,"receiver.%d.nb_lead_time",rx->id);
+    sprintf(value, "%1.4f", rx->nb_lead_time);
+    setProperty(name, value);
+
+    sprintf(name,"receiver.%d.nb_transition_time",rx->id);
+    sprintf(value, "%1.4f", rx->nb_transition_time);
+    setProperty(name, value);
+
+    sprintf(name,"receiver.%d.nb_threshold_value",rx->id);
+    sprintf(value, "%1.4f", rx->nb_threshold_value);
+    setProperty(name, value);
+
+    sprintf(name,"receiver.%d.nb2_mode",rx->id);
+    sprintf(value, "%d", rx->nb2_mode);
+    setProperty(name, value);
+
     sprintf(name,"receiver.%d.low_latency",rx->id);
     sprintf(value,"%d",rx->low_latency);
     setProperty(name,value);
@@ -515,7 +536,33 @@ g_print("%s: id=%d\n",__FUNCTION__,rx->id);
     sprintf(name,"receiver.%d.ae",rx->id);
     value=getProperty(name);
     if(value) rx->nr2_ae=atoi(value);
-  
+
+      // restore NB values
+    sprintf(name, "receiver.%d.nb_lead_time", rx->id);
+    value = getProperty(name);
+    if (value)
+       rx->nb_lead_time = atof(value);
+
+    sprintf(name, "receiver.%d.nb_lag_time", rx->id);
+    value = getProperty(name);
+    if (value)
+       rx->nb_lag_time = atof(value);
+
+    sprintf(name, "receiver.%d.nb_transition_time", rx->id);
+    value = getProperty(name);
+    if (value)
+       rx->nb_transition_time = atof(value);
+
+    sprintf(name, "receiver.%d.nb_threshold_value", rx->id);
+    value = getProperty(name);
+    if (value)
+       rx->nb_threshold_value = atof(value);
+
+    sprintf(name, "receiver.%d.nb2_mode", rx->id);
+    value = getProperty(name);
+    if (value)
+       rx->nb2_mode = atoi(value);
+
     sprintf(name,"receiver.%d.low_latency",rx->id);
     value=getProperty(name);
     if(value) rx->low_latency=atoi(value);
@@ -891,6 +938,12 @@ g_print("%s: id=%d buffer_size=%d\n",__FUNCTION__,id,buffer_size);
   rx->nr2_gain_method=2;
   rx->nr2_npe_method=0;
   rx->nr2_ae=1;
+
+  rx->nb_lag_time = 0.0001;
+  rx->nb_lead_time = 0.0001;
+  rx->nb_transition_time = 0.0001;
+  rx->nb_threshold_value = 18.0;
+  rx->nb2_mode = 0;
   
   rx->alex_antenna=0;
   rx->alex_attenuation=0;
@@ -1025,7 +1078,13 @@ g_print("%s: id=%d sample_rate=%d\n",__FUNCTION__,rx->id, rx->sample_rate);
   rx->nr2_gain_method=2;
   rx->nr2_npe_method=0;
   rx->nr2_ae=1;
-  
+
+  rx->nb_lag_time = 0.0001;
+  rx->nb_lead_time = 0.0001;
+  rx->nb_transition_time = 0.0001;
+  rx->nb_threshold_value = 18.0;
+  rx->nb2_mode = 0;
+
   BAND *b=band_get_band(vfo[rx->id].band);
   rx->alex_antenna=b->alexRxAntenna;
   rx->alex_attenuation=b->alexAttenuation;
@@ -1112,8 +1171,11 @@ g_print("%s: OpenChannel id=%d buffer_size=%d fft_size=%d sample_rate=%d\n",
   SetRXAAMDSBMode(rx->id, 0);
   SetRXAShiftRun(rx->id, 0);
 
-  SetEXTANBRun(rx->id, rx->nb);
-  SetEXTNOBRun(rx->id, rx->nb2);
+  SetEXTANBHangtime(rx->id, rx->nb_lag_time*0.001);
+  SetEXTANBAdvtime(rx->id, rx->nb_lead_time*0.001);
+  SetEXTANBTau(rx->id, rx->nb_transition_time*0.001);
+  SetEXTANBThreshold(rx->id, rx->nb_threshold_value*0.165);
+  SetEXTNOBMode(rx->id, rx->nb2_mode);
 
   SetRXAEMNRPosition(rx->id, rx->nr_agc);
   SetRXAEMNRgainMethod(rx->id, rx->nr2_gain_method);
@@ -1121,12 +1183,14 @@ g_print("%s: OpenChannel id=%d buffer_size=%d fft_size=%d sample_rate=%d\n",
   SetRXAEMNRRun(rx->id, rx->nr2);
   SetRXAEMNRaeRun(rx->id, rx->nr2_ae);
 
+  SetEXTANBRun(rx->id, rx->nb);
+  SetEXTNOBRun(rx->id, rx->nb2);
+
   SetRXAANRVals(rx->id, 64, 16, 16e-4, 10e-7); // defaults
   SetRXAANRRun(rx->id, rx->nr);
   SetRXAANFRun(rx->id, rx->anf);
   SetRXASNBARun(rx->id, rx->snb);
 
-
   SetRXAPanelGain1(rx->id, rx->volume);
   SetRXAPanelBinaural(rx->id, binaural);
   SetRXAPanelRun(rx->id, 1);
index 5898a5225b2afb54f89cb2050b30b3a646c06d37..5513f67f29382d181fad1b7be2aa6fa52842cd8b 100644 (file)
@@ -89,6 +89,11 @@ typedef struct _receiver {
   int nr2_npe_method;
   int nr2_ae;
 
+  double nb_lag_time;
+  double nb_lead_time;
+  double nb_transition_time;
+  double nb_threshold_value;
+  int nb2_mode;
 
   gint alex_antenna;
   gint alex_attenuation;