From 26ad72ea2ba40cb55c8f40ce592ac33a6da822cc Mon Sep 17 00:00:00 2001 From: DL1YCF Date: Sun, 3 Oct 2021 13:02:33 +0200 Subject: [PATCH] a) moved call to set_agc down when creating receivers, such that the AGC threshold line is calculated correctly at the beginning of the program b) straightened arguments of set_agc c) use set_agc instead of direct WDSP calls when possible --- actions.c | 2 +- agc_menu.c | 2 +- dsp_menu.c | 8 +------- ext.c | 2 +- receiver.c | 10 +++++----- receiver.h | 2 +- sliders.c | 8 ++------ 7 files changed, 12 insertions(+), 22 deletions(-) diff --git a/actions.c b/actions.c index 39335bd..4ba5881 100644 --- a/actions.c +++ b/actions.c @@ -270,7 +270,7 @@ int process_action(void *data) { if(active_receiver->agc>+AGC_LAST) { active_receiver->agc=0; } - set_agc(active_receiver, active_receiver->agc); + set_agc(active_receiver); g_idle_add(ext_vfo_update, NULL); } break; diff --git a/agc_menu.c b/agc_menu.c index 36e2caa..b79b6f6 100644 --- a/agc_menu.c +++ b/agc_menu.c @@ -65,7 +65,7 @@ static void agc_select_cb (GtkToggleButton *widget, gpointer data) { send_agc(client_socket,active_receiver->id,active_receiver->agc); } else { #endif - set_agc(active_receiver, active_receiver->agc); + set_agc(active_receiver); g_idle_add(ext_vfo_update, NULL); #ifdef CLIENT_SERVER } diff --git a/dsp_menu.c b/dsp_menu.c index ca03670..8a375f6 100644 --- a/dsp_menu.c +++ b/dsp_menu.c @@ -58,13 +58,7 @@ static gboolean delete_event(GtkWidget *widget, GdkEvent *event, gpointer user_d static void agc_hang_threshold_value_changed_cb(GtkWidget *widget, gpointer data) { active_receiver->agc_hang_threshold=(int)gtk_range_get_value(GTK_RANGE(widget)); - if(active_receiver->agc==AGC_LONG || active_receiver->agc==AGC_SLOW) { - SetRXAAGCHangThreshold(active_receiver->id, (int)active_receiver->agc_hang_threshold); - // - // recalculate position of hang line for panadapter - // - GetRXAAGCHangLevel(active_receiver->id, &active_receiver->agc_hang); - } + set_agc(active_receiver); } static void pre_post_agc_cb(GtkToggleButton *widget, gpointer data) { diff --git a/ext.c b/ext.c index 7cfa1de..8cb611f 100644 --- a/ext.c +++ b/ext.c @@ -656,7 +656,7 @@ int ext_agc_update(void *data) { if(active_receiver->agc>+AGC_LAST) { active_receiver->agc=0; } - set_agc(active_receiver, active_receiver->agc); + set_agc(active_receiver); g_idle_add(ext_vfo_update, NULL); return 0; } diff --git a/receiver.c b/receiver.c index 0ac4b10..2707fb2 100644 --- a/receiver.c +++ b/receiver.c @@ -705,13 +705,13 @@ void set_deviation(RECEIVER *rx) { SetRXAFMDeviation(rx->id, (double)rx->deviation); } -void set_agc(RECEIVER *rx, int agc) { +void set_agc(RECEIVER *rx) { - SetRXAAGCMode(rx->id, agc); + SetRXAAGCMode(rx->id, rx->agc); //SetRXAAGCThresh(rx->id, agc_thresh_point, 4096.0, rx->sample_rate); SetRXAAGCSlope(rx->id,rx->agc_slope); SetRXAAGCTop(rx->id,rx->agc_gain); - switch(agc) { + switch(rx->agc) { case AGC_OFF: break; case AGC_LONG: @@ -1145,8 +1145,6 @@ g_print("%s: OpenChannel id=%d buffer_size=%d fft_size=%d sample_rate=%d\n", RXASetNC(rx->id, rx->fft_size); RXASetMP(rx->id, rx->low_latency); - set_agc(rx, rx->agc); - SetRXAAMDSBMode(rx->id, 0); SetRXAShiftRun(rx->id, 0); @@ -1199,6 +1197,8 @@ g_print("%s: rx=%p id=%d local_audio=%d\n",__FUNCTION__,rx,rx->id,rx->local_audi rx->local_audio=0; } } + // defer set_agc until here, otherwise the AGC threshold is not computed correctly + set_agc(rx); return rx; } diff --git a/receiver.h b/receiver.h index ce511fd..eb88e2b 100644 --- a/receiver.h +++ b/receiver.h @@ -181,7 +181,7 @@ extern void receiver_change_pan(RECEIVER *rx,double pan); extern void set_mode(RECEIVER* rx,int m); extern void set_filter(RECEIVER *rx,int low,int high); -extern void set_agc(RECEIVER *rx, int agc); +extern void set_agc(RECEIVER *rx); extern void set_offset(RECEIVER *rx, long long offset); extern void set_deviation(RECEIVER *rx); diff --git a/sliders.c b/sliders.c index d2da100..476352c 100644 --- a/sliders.c +++ b/sliders.c @@ -273,9 +273,7 @@ static void agcgain_value_changed_cb(GtkWidget *widget, gpointer data) { send_agc_gain(client_socket,active_receiver->id,(int)active_receiver->agc_gain,(int)active_receiver->agc_hang,(int)active_receiver->agc_thresh); } else { #endif - SetRXAAGCTop(active_receiver->id, active_receiver->agc_gain); - GetRXAAGCHangLevel(active_receiver->id, &active_receiver->agc_hang); - GetRXAAGCThresh(active_receiver->id, &active_receiver->agc_thresh, 4096.0, (double)active_receiver->sample_rate); + set_agc(active_receiver); #ifdef CLIENT_SERVER } #endif @@ -284,9 +282,7 @@ static void agcgain_value_changed_cb(GtkWidget *widget, gpointer data) { void set_agc_gain(int rx,double value) { g_print("%s\n",__FUNCTION__); receiver[rx]->agc_gain=value; - SetRXAAGCTop(receiver[rx]->id, receiver[rx]->agc_gain); - GetRXAAGCHangLevel(receiver[rx]->id, &receiver[rx]->agc_hang); - GetRXAAGCThresh(receiver[rx]->id, &receiver[rx]->agc_thresh, 4096.0, (double)receiver[rx]->sample_rate); + set_agc(receiver[rx]); if(display_sliders) { gtk_range_set_value (GTK_RANGE(agc_scale),receiver[rx]->agc_gain); } else { -- 2.45.2