diff --git a/cw_menu.c b/cw_menu.c index bc00e21a..8962769c 100644 --- a/cw_menu.c +++ b/cw_menu.c @@ -128,16 +128,6 @@ static void cw_keyer_sidetone_level_value_changed_cb(GtkWidget *widget, gpointer static void cw_keyer_sidetone_frequency_value_changed_cb(GtkWidget *widget, gpointer data) { cw_keyer_sidetone_frequency=gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(widget)); -/* - int txmode=get_tx_mode(); - if(txmode==modeCWL || txmode==modeCWU) { - BANDSTACK_ENTRY *entry=bandstack_entry_get_current(); - FILTER* band_filters=filters[entry->mode]; - FILTER* band_filter=&band_filters[entry->filter]; - //setFilter(band_filter->low,band_filter->high); - set_filter(active_receiver,band_filter->low,band_filter->high); - } -*/ cw_changed(); receiver_filter_changed(active_receiver); // changing the side tone frequency affects BFO frequency offsets diff --git a/filter.c b/filter.c index af0160a9..e8f215b2 100644 --- a/filter.c +++ b/filter.c @@ -42,19 +42,24 @@ FILTER filterLSB[FILTERS]={ {-2850,-150,"Var2"} }; +// +// DigiMode Filters up to 3000 Hz wide are centered +// around 1500, the broader ones start at +// zero (this also holds for DIGU). +// FILTER filterDIGL[FILTERS]={ - {-5150,-150,"5.0k"}, - {-4550,-150,"4.4k"}, - {-3950,-150,"3.8k"}, - {-3450,-150,"3.3k"}, - {-3050,-150,"2.9k"}, - {-2850,-150,"2.7k"}, - {-2550,-150,"2.4k"}, - {-2250,-150,"2.1k"}, - {-1950,-150,"1.8k"}, - {-1150,-150,"1.0k"}, - {-2850,-150,"Var1"}, - {-2850,-150,"Var2"} + {-5000, 0,"5.0k"}, + {-4000, 0,"4.0k"}, + {-3000, 0,"3.0k"}, + {-2750, -250,"2.5k"}, + {-2500, -500,"2.0k"}, + {-2250, -750,"1.5k"}, + {-2000,-1000,"1.0k"}, + {-1875,-1125,"750"}, + {-1750,-1250,"500"}, + {-1625,-1375,"250"}, + {-3000, 0,"Var1"}, + {-2000,-1000,"Var2"} }; FILTER filterUSB[FILTERS]={ @@ -73,18 +78,18 @@ FILTER filterUSB[FILTERS]={ }; FILTER filterDIGU[FILTERS]={ - {150,5150,"5.0k"}, - {150,4550,"4.4k"}, - {150,3950,"3.8k"}, - {150,3450,"3.3k"}, - {150,3050,"2.9k"}, - {150,2850,"2.7k"}, - {150,2550,"2.4k"}, - {150,2250,"2.1k"}, - {150,1950,"1.8k"}, - {150,1150,"1.0k"}, - {150,2850,"Var1"}, - {150,2850,"Var2"} + { 0,5000,"5.0k"}, + { 0,4000,"4.0k"}, + { 0,3000,"3.0k"}, + { 250,2750,"2.5k"}, + { 500,2500,"2.0k"}, + { 750,2250,"1.5k"}, + {1000,2000,"1.0k"}, + {1125,1875,"750"}, + {1250,1750,"500"}, + {1375,1625,"250"}, + { 0,3000,"Var1"}, + {1000,2000,"Var2"} }; FILTER filterCWL[FILTERS]={ diff --git a/filter_menu.c b/filter_menu.c index d026252e..14e0ddf4 100644 --- a/filter_menu.c +++ b/filter_menu.c @@ -75,15 +75,8 @@ static gboolean filter_select_cb (GtkWidget *widget, gpointer data) { static gboolean deviation_select_cb (GtkWidget *widget, gpointer data) { active_receiver->deviation=GPOINTER_TO_UINT(data); transmitter->deviation=GPOINTER_TO_UINT(data); - if(active_receiver->deviation==2500) { - //setFilter(-4000,4000); - set_filter(active_receiver,-5500,5500); - tx_set_filter(transmitter,-5500,5500); - } else { - //setFilter(-8000,8000); - set_filter(active_receiver,-8000,8000); - tx_set_filter(transmitter,-8000,8000); - } + set_filter(active_receiver); + tx_set_filter(transmitter); set_deviation(active_receiver); transmitter_set_deviation(transmitter); set_button_text_color(last_filter,"black"); diff --git a/receiver.c b/receiver.c index bc6fb27a..fd49fafd 100644 --- a/receiver.c +++ b/receiver.c @@ -665,16 +665,38 @@ void set_mode(RECEIVER *rx,int m) { SetRXAMode(rx->id, vfo[rx->id].mode); } -void set_filter(RECEIVER *rx,int low,int high) { - if(vfo[rx->id].mode==modeCWL) { - rx->filter_low=-cw_keyer_sidetone_frequency-low; - rx->filter_high=-cw_keyer_sidetone_frequency+high; - } else if(vfo[rx->id].mode==modeCWU) { - rx->filter_low=cw_keyer_sidetone_frequency-low; - rx->filter_high=cw_keyer_sidetone_frequency+high; - } else { - rx->filter_low=low; - rx->filter_high=high; +void set_filter(RECEIVER *rx) { + int m=vfo[rx->id].mode; + FILTER *mode_filters=filters[m]; + FILTER *filter=&mode_filters[vfo[rx->id].filter]; // ignored in FMN + + switch (m) { + case modeCWL: + rx->filter_low=-cw_keyer_sidetone_frequency-filter->low; + rx->filter_high=-cw_keyer_sidetone_frequency+filter->high; + break; + case modeCWU: + rx->filter_low=cw_keyer_sidetone_frequency-filter->low; + rx->filter_high=cw_keyer_sidetone_frequency+filter->high; + break; + case modeFMN: + // + // FM filter settings are ignored, instead, the filter + // size is calculated from the deviation + // + if(rx->deviation==2500) { + rx->filter_low=-5500; + rx->filter_high=5500; + } else { + rx->filter_low=-8000; + rx->filter_high=8000; + } + set_deviation(rx); + break; + default: + rx->filter_low=filter->low; + rx->filter_high=filter->high; + break; } RXASetPassband(rx->id,(double)rx->filter_low,(double)rx->filter_high); @@ -1280,31 +1302,10 @@ void receiver_frequency_changed(RECEIVER *rx) { } void receiver_filter_changed(RECEIVER *rx) { - int filter_low, filter_high; - int m=vfo[rx->id].mode; - if(m==modeFMN) { - if(rx->deviation==2500) { - filter_low=-5500; - filter_high=5500; - } else { - filter_low=-8000; - filter_high=8000; - } - set_filter(rx,filter_low,filter_high); - set_deviation(rx); - } else { - FILTER *mode_filters=filters[m]; - FILTER *filter=&mode_filters[vfo[rx->id].filter]; - filter_low=filter->low; - filter_high=filter->high; - set_filter(rx,filter_low,filter_high); - } - + set_filter(rx); if(can_transmit && transmitter!=NULL) { - if(transmitter->use_rx_filter) { - if(rx==active_receiver) { - tx_set_filter(transmitter,filter_low,filter_high); - } + if(transmitter->use_rx_filter && rx==active_receiver) { + tx_set_filter(transmitter); } } } diff --git a/receiver.h b/receiver.h index 5898a522..018a9885 100644 --- a/receiver.h +++ b/receiver.h @@ -167,7 +167,7 @@ extern void receiver_change_zoom(RECEIVER *rx,double zoom); 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_filter(RECEIVER *rx); extern void set_agc(RECEIVER *rx, int agc); extern void set_offset(RECEIVER *rx, long long offset); extern void set_deviation(RECEIVER *rx); diff --git a/rigctl.c b/rigctl.c index 26b343d5..df2e64d0 100644 --- a/rigctl.c +++ b/rigctl.c @@ -2772,15 +2772,11 @@ int parse_cmd(void *data) { } break; case 'W': //FW - // set/read filter width - // make sure filter is filterVar1 - if(vfo[active_receiver->id].filter!=filterVar1) { - vfo_filter_changed(filterVar1); - } - FILTER *mode_filters=filters[vfo[active_receiver->id].mode]; - FILTER *filter=&mode_filters[filterVar1]; - int val=0; + // set/read filter width. Switch to Var1 only when setting if(command[2]==';') { + int val=0; + FILTER *mode_filters=filters[vfo[active_receiver->id].mode]; + FILTER *filter=&mode_filters[vfo[active_receiver->id].filter]; switch(vfo[active_receiver->id].mode) { case modeCWL: case modeCWU: @@ -2802,8 +2798,13 @@ int parse_cmd(void *data) { send_resp(client->fd,reply) ; } } else if(command[6]==';') { + // make sure filter is filterVar1 + if(vfo[active_receiver->id].filter!=filterVar1) { + vfo_filter_changed(filterVar1); + } + FILTER *mode_filters=filters[vfo[active_receiver->id].mode]; + FILTER *filter=&mode_filters[filterVar1]; int fw=atoi(&command[2]); - int val= filter->low=fw; switch(vfo[active_receiver->id].mode) { case modeCWL: @@ -3366,15 +3367,10 @@ int parse_cmd(void *data) { } break; case 'H': //SH - { - // set/read filter high - // make sure filter is filterVar1 - if(vfo[active_receiver->id].filter!=filterVar1) { - vfo_filter_changed(filterVar1); - } - FILTER *mode_filters=filters[vfo[active_receiver->id].mode]; - FILTER *filter=&mode_filters[filterVar1]; + // set/read filter high, switch to Var1 only when setting if(command[2]==';') { + FILTER *mode_filters=filters[vfo[active_receiver->id].mode]; + FILTER *filter=&mode_filters[vfo[active_receiver->id].filter]; int fh=5; int high=filter->high; if(vfo[active_receiver->id].mode==modeLSB) { @@ -3408,6 +3404,12 @@ int parse_cmd(void *data) { sprintf(reply,"SH%02d;",fh); send_resp(client->fd,reply) ; } else if(command[4]==';') { + // make sure filter is filterVar1 + if(vfo[active_receiver->id].filter!=filterVar1) { + vfo_filter_changed(filterVar1); + } + FILTER *mode_filters=filters[vfo[active_receiver->id].mode]; + FILTER *filter=&mode_filters[filterVar1]; int i=atoi(&command[2]); int fh=100; switch(vfo[active_receiver->id].mode) { @@ -3484,22 +3486,16 @@ int parse_cmd(void *data) { } vfo_filter_changed(filterVar1); } - } break; case 'I': //SI // enter satellite memory name implemented=FALSE; break; case 'L': //SL - { - // set/read filter low - // make sure filter is filterVar1 - if(vfo[active_receiver->id].filter!=filterVar1) { - vfo_filter_changed(filterVar1); - } - FILTER *mode_filters=filters[vfo[active_receiver->id].mode]; - FILTER *filter=&mode_filters[filterVar1]; + // set/read filter low, switch to Var1 only when setting if(command[2]==';') { + FILTER *mode_filters=filters[vfo[active_receiver->id].mode]; + FILTER *filter=&mode_filters[vfo[active_receiver->id].filter]; int fl=2; int low=filter->low; if(vfo[active_receiver->id].mode==modeLSB) { @@ -3534,6 +3530,12 @@ int parse_cmd(void *data) { sprintf(reply,"SL%02d;",fl); send_resp(client->fd,reply) ; } else if(command[4]==';') { + // make sure filter is filterVar1 + if(vfo[active_receiver->id].filter!=filterVar1) { + vfo_filter_changed(filterVar1); + } + FILTER *mode_filters=filters[vfo[active_receiver->id].mode]; + FILTER *filter=&mode_filters[filterVar1]; int i=atoi(&command[2]); int fl=100; switch(vfo[active_receiver->id].mode) { @@ -3610,7 +3612,6 @@ int parse_cmd(void *data) { } vfo_filter_changed(filterVar1); } - } break; case 'M': //SM // read the S meter @@ -3634,7 +3635,7 @@ int parse_cmd(void *data) { if(command[2]=='0') { int p2=atoi(&command[3]); active_receiver->squelch=(int)((double)p2/255.0*100.0); - set_squelch(); + set_squelch(active_receiver); } } else { } diff --git a/transmitter.c b/transmitter.c index 59e7686e..e6232fa2 100644 --- a/transmitter.c +++ b/transmitter.c @@ -916,58 +916,83 @@ void tx_set_mode(TRANSMITTER* tx,int mode) { int filter_low, filter_high; tx->mode=mode; SetTXAMode(tx->id, tx->mode); - if(tx->use_rx_filter) { - int m=vfo[active_receiver->id].mode; - if(m==modeFMN) { - if(active_receiver->deviation==2500) { - filter_low=-5500; - filter_high=5500; - } else { - filter_low=-8000; - filter_high=8000; - } - } else { - FILTER *mode_filters=filters[m]; - FILTER *filter=&mode_filters[vfo[active_receiver->id].filter]; - filter_low=filter->low; - filter_high=filter->high; - } - } else { - filter_low=tx_filter_low; - filter_high=tx_filter_high; - } - tx_set_filter(tx,filter_low,filter_high); + tx_set_filter(tx); } } -void tx_set_filter(TRANSMITTER *tx,int low,int high) { +void tx_set_filter(TRANSMITTER *tx) { int txmode=get_tx_mode(); + // load default values + int low = tx_filter_low; + int high = tx_filter_high; // 0 < low < high + + if (tx->use_rx_filter) { + // + // Use only 'compatible' parts of RX filter settings + // to change TX values (important for split operation) + // + int id=active_receiver->id; + int rxmode=vfo[id].mode; + FILTER *mode_filters=filters[rxmode]; + FILTER *filter=&mode_filters[vfo[id].filter]; + + switch (rxmode) { + case modeDSB: + case modeAM: + case modeSAM: + case modeSPEC: + high = filter->high; + break; + case modeLSB: + case modeDIGL: + high = -filter->low; + low = -filter->high; + break; + case modeUSB: + case modeDIGU: + high = filter->high; + low = filter->low; + break; + } + } + switch(txmode) { - case modeLSB: case modeCWL: + case modeCWU: + // Our CW signal is always at zero in IQ space, but note + // WDSP is by-passed anyway. + tx->filter_low =-150; + tx->filter_high = 150; + break; + case modeDSB: + case modeAM: + case modeSAM: + case modeSPEC: + // disregard the "low" value and use (-high, high) + tx->filter_low =-high; + tx->filter_high= high; + break; + case modeLSB: case modeDIGL: + // in IQ space, the filter edges are (-high, -low) tx->filter_low=-high; tx->filter_high=-low; break; case modeUSB: - case modeCWU: case modeDIGU: + // in IQ space, the filter edges are (low, high) tx->filter_low=low; tx->filter_high=high; break; - case modeDSB: - case modeAM: - case modeSAM: - tx->filter_low=-high; - tx->filter_high=high; - break; case modeFMN: + // calculate filter size from deviation, + // assuming that the highest AF frequency is 3000 if(tx->deviation==2500) { - tx->filter_low=-5500; - tx->filter_high=5500; + tx->filter_low=-5500; // Carson's rule: +/-(deviation + max_af_frequency) + tx->filter_high=5500; // deviation=2500, max freq = 3000 } else { - tx->filter_low=-8000; + tx->filter_low=-8000; // deviation=5000, max freq = 3000 tx->filter_high=8000; } break; diff --git a/transmitter.h b/transmitter.h index 2e9fc288..ed6ca465 100644 --- a/transmitter.h +++ b/transmitter.h @@ -127,7 +127,7 @@ extern int cw_key_down; extern int cw_not_ready; extern void tx_set_mode(TRANSMITTER* tx,int m); -extern void tx_set_filter(TRANSMITTER *tx,int low,int high); +extern void tx_set_filter(TRANSMITTER *tx); extern void transmitter_set_deviation(TRANSMITTER *tx); extern void transmitter_set_am_carrier_level(TRANSMITTER *tx); extern void tx_set_pre_emphasize(TRANSMITTER *tx,int state); diff --git a/tx_menu.c b/tx_menu.c index e83f3d38..1b8be641 100644 --- a/tx_menu.c +++ b/tx_menu.c @@ -72,12 +72,12 @@ static void comp_cb(GtkWidget *widget, gpointer data) { static void tx_spin_low_cb (GtkWidget *widget, gpointer data) { tx_filter_low=gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(widget)); - tx_set_filter(transmitter,tx_filter_low,tx_filter_high); + tx_set_filter(transmitter); } static void tx_spin_high_cb (GtkWidget *widget, gpointer data) { tx_filter_high=gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(widget)); - tx_set_filter(transmitter,tx_filter_low,tx_filter_high); + tx_set_filter(transmitter); } static void micboost_cb(GtkWidget *widget, gpointer data) { @@ -128,30 +128,8 @@ static void tune_percent_cb (GtkWidget *widget, gpointer data) { static void use_rx_filter_cb(GtkWidget *widget, gpointer data) { transmitter->use_rx_filter=gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget)); - int filter_low,filter_high; - if(transmitter->use_rx_filter) { - int m=vfo[active_receiver->id].mode; - if(m==modeFMN) { - if(active_receiver->deviation==2500) { - filter_low=-5500; - filter_high=5500; - } else { - filter_low=-8000; - filter_high=8000; - } - } else { - FILTER *mode_filters=filters[m]; - FILTER *filter=&mode_filters[vfo[active_receiver->id].filter]; - filter_low=filter->low; - filter_high=filter->high; - } - } else { - filter_low=tx_filter_low; - filter_high=tx_filter_high; - } - - tx_set_filter(transmitter,filter_low,filter_high); + tx_set_filter(transmitter); if(transmitter->use_rx_filter) { gtk_widget_set_sensitive (tx_spin_low, FALSE);