From fb9c6f8842af636a26f828c5f35555845bb9fce3 Mon Sep 17 00:00:00 2001 From: John Melton - G0ORX/N6LYT Date: Fri, 2 Dec 2016 17:32:05 +0000 Subject: [PATCH] fixed radio microphone level. Changed FM mode to use deviation rather than filter sizes and added FM menu to enable/disable pre-emphasis --- Makefile | 3 ++ filter_menu.c | 69 +++++++++++++++++++++++++++++------- fm_menu.c | 95 ++++++++++++++++++++++++++++++++++++++++++++++++++ fm_menu.h | 20 +++++++++++ new_menu.c | 15 ++++++++ old_protocol.c | 6 ++-- radio.c | 11 ++++++ radio.h | 3 ++ vfo.c | 10 +++++- wdsp_init.c | 21 ++++++++--- wdsp_init.h | 3 +- 11 files changed, 234 insertions(+), 22 deletions(-) create mode 100644 fm_menu.c create mode 100644 fm_menu.h diff --git a/Makefile b/Makefile index fd59865..5e03aea 100644 --- a/Makefile +++ b/Makefile @@ -142,6 +142,7 @@ mode_menu.c \ filter_menu.c \ noise_menu.c \ agc_menu.c \ +fm_menu.c \ rit.c \ meter.c \ mode.c \ @@ -196,6 +197,7 @@ mode_menu.h \ filter_menu.h \ noise_menu.h \ agc_menu.h \ +fm_menu.h \ rit.h \ meter.h \ mode.h \ @@ -247,6 +249,7 @@ mode_menu.o \ filter_menu.o \ noise_menu.o \ agc_menu.o \ +fm_menu.o \ rit.o \ meter.o \ mode.o \ diff --git a/filter_menu.c b/filter_menu.c index 43f5bd4..9b9b0dc 100644 --- a/filter_menu.c +++ b/filter_menu.c @@ -30,6 +30,7 @@ #include "radio.h" #include "vfo.h" #include "button_text.h" +#include "wdsp_init.h" static GtkWidget *parent_window=NULL; @@ -60,6 +61,20 @@ static gboolean filter_select_cb (GtkWidget *widget, gpointer data) { vfo_update(NULL); } +static gboolean deviation_select_cb (GtkWidget *widget, gpointer data) { + deviation=(int)data; + if(deviation==2500) { + setFilter(-4000,4000); + } else { + setFilter(-8000,8000); + } + wdsp_set_deviation((double)deviation); + set_button_text_color(last_filter,"black"); + last_filter=widget; + set_button_text_color(last_filter,"orange"); + vfo_update(NULL); +} + void filter_menu(GtkWidget *parent) { GtkWidget *b; int i; @@ -94,18 +109,48 @@ void filter_menu(GtkWidget *parent) { BANDSTACK_ENTRY *entry=bandstack_entry_get_current(); FILTER* band_filters=filters[entry->mode]; - for(i=0;ifilter) { - set_button_text_color(b,"orange"); - last_filter=b; - } else { - set_button_text_color(b,"black"); - } - gtk_widget_show(b); - gtk_grid_attach(GTK_GRID(grid),b,i%5,1+(i/5),1,1); - g_signal_connect(b,"pressed",G_CALLBACK(filter_select_cb),(gpointer *)i); + switch(entry->mode) { + case modeFMN: + { + GtkWidget *l=gtk_label_new("Deviation:"); + gtk_grid_attach(GTK_GRID(grid),l,0,1,1,1); + + GtkWidget *b=gtk_button_new_with_label("2.5K"); + if(deviation==2500) { + set_button_text_color(b,"orange"); + last_filter=b; + } else { + set_button_text_color(b,"black"); + } + g_signal_connect(b,"pressed",G_CALLBACK(deviation_select_cb),(gpointer *)2500); + gtk_grid_attach(GTK_GRID(grid),b,1,1,1,1); + + b=gtk_button_new_with_label("5.0K"); + if(deviation==5000) { + set_button_text_color(b,"orange"); + last_filter=b; + } else { + set_button_text_color(b,"black"); + } + g_signal_connect(b,"pressed",G_CALLBACK(deviation_select_cb),(gpointer *)5000); + gtk_grid_attach(GTK_GRID(grid),b,2,1,1,1); + } + break; + + default: + for(i=0;ifilter) { + set_button_text_color(b,"orange"); + last_filter=b; + } else { + set_button_text_color(b,"black"); + } + gtk_grid_attach(GTK_GRID(grid),b,i%5,1+(i/5),1,1); + g_signal_connect(b,"pressed",G_CALLBACK(filter_select_cb),(gpointer *)i); + } + break; } gtk_container_add(GTK_CONTAINER(content),grid); diff --git a/fm_menu.c b/fm_menu.c new file mode 100644 index 0000000..00d1d6c --- /dev/null +++ b/fm_menu.c @@ -0,0 +1,95 @@ +/* Copyright (C) +* 2016 - John Melton, G0ORX/N6LYT +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* as published by the Free Software Foundation; either version 2 +* of the License, or (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software +* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +* +*/ + +#include +#include +#include + +#include "new_menu.h" +#include "fm_menu.h" +#include "radio.h" +#include "wdsp_init.h" + +static GtkWidget *parent_window=NULL; + +static GtkWidget *dialog=NULL; + +static GtkWidget *last_band; + +static gboolean close_cb (GtkWidget *widget, GdkEventButton *event, gpointer data) { + if(dialog!=NULL) { + gtk_widget_destroy(dialog); + dialog=NULL; + sub_menu=NULL; + } + return TRUE; +} + +static gboolean emp_cb (GtkWidget *widget, gpointer data) { + if(gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget))) { + pre_emphasize=1; + } else { + pre_emphasize=0; + } + wdsp_set_pre_emphasize(pre_emphasize); +} + +void fm_menu(GtkWidget *parent) { + GtkWidget *b; + int i; + + parent_window=parent; + + dialog=gtk_dialog_new(); + gtk_window_set_transient_for(GTK_WINDOW(dialog),GTK_WINDOW(parent_window)); + gtk_window_set_decorated(GTK_WINDOW(dialog),FALSE); + + GdkRGBA color; + color.red = 1.0; + color.green = 1.0; + color.blue = 1.0; + color.alpha = 1.0; + gtk_widget_override_background_color(dialog,GTK_STATE_FLAG_NORMAL,&color); + + GtkWidget *content=gtk_dialog_get_content_area(GTK_DIALOG(dialog)); + + GtkWidget *grid=gtk_grid_new(); + + gtk_grid_set_column_homogeneous(GTK_GRID(grid),TRUE); + gtk_grid_set_row_homogeneous(GTK_GRID(grid),TRUE); + gtk_grid_set_column_spacing (GTK_GRID(grid),5); + gtk_grid_set_row_spacing (GTK_GRID(grid),5); + + GtkWidget *close_b=gtk_button_new_with_label("Close FM"); + g_signal_connect (close_b, "pressed", G_CALLBACK(close_cb), NULL); + gtk_grid_attach(GTK_GRID(grid),close_b,0,0,1,1); + + GtkWidget *emp_b=gtk_check_button_new_with_label("FM TX Pre-emphasize before limiting"); + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (emp_b), pre_emphasize); + gtk_widget_show(emp_b); + gtk_grid_attach(GTK_GRID(grid),emp_b,0,1,3,1); + g_signal_connect(emp_b,"toggled",G_CALLBACK(emp_cb),NULL); + + gtk_container_add(GTK_CONTAINER(content),grid); + + sub_menu=dialog; + + gtk_widget_show_all(dialog); + +} diff --git a/fm_menu.h b/fm_menu.h new file mode 100644 index 0000000..64b3015 --- /dev/null +++ b/fm_menu.h @@ -0,0 +1,20 @@ +/* Copyright (C) +* 2016 - John Melton, G0ORX/N6LYT +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* as published by the Free Software Foundation; either version 2 +* of the License, or (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software +* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +* +*/ + +void fm_menu(GtkWidget *parent); diff --git a/new_menu.c b/new_menu.c index 82f8a6d..8af62e5 100644 --- a/new_menu.c +++ b/new_menu.c @@ -46,6 +46,7 @@ #include "filter_menu.h" #include "noise_menu.h" #include "agc_menu.h" +#include "fm_menu.h" static GtkWidget *parent_window=NULL; @@ -227,6 +228,16 @@ static gboolean agc_cb (GtkWidget *widget, GdkEventButton *event, gpointer data) return TRUE; } +void start_fm() { + cleanup(); + fm_menu(parent_window); +} + +static gboolean fm_cb (GtkWidget *widget, GdkEventButton *event, gpointer data) { + start_fm(); + return TRUE; +} + static gboolean new_menu_pressed_event_cb (GtkWidget *widget, GdkEventButton *event, gpointer data) @@ -314,6 +325,10 @@ static gboolean new_menu_pressed_event_cb (GtkWidget *widget, g_signal_connect (equalizer_b, "button-press-event", G_CALLBACK(equalizer_cb), NULL); gtk_grid_attach(GTK_GRID(grid),equalizer_b,4,2,1,1); + GtkWidget *fm_b=gtk_button_new_with_label("FM"); + g_signal_connect (fm_b, "button-press-event", G_CALLBACK(fm_cb), NULL); + gtk_grid_attach(GTK_GRID(grid),fm_b,5,2,1,1); + GtkWidget *step_b=gtk_button_new_with_label("Step"); g_signal_connect (step_b, "button-press-event", G_CALLBACK(step_cb), NULL); gtk_grid_attach(GTK_GRID(grid),step_b,0,3,1,1); diff --git a/old_protocol.c b/old_protocol.c index 4ec91a4..68eda8a 100644 --- a/old_protocol.c +++ b/old_protocol.c @@ -376,7 +376,7 @@ static void process_ozy_input_buffer(char *buffer) { int last_dash; int left_sample[RECEIVERS]; int right_sample[RECEIVERS]; - short mic_sample; + int mic_sample; double left_sample_double[RECEIVERS]; double right_sample_double[RECEIVERS]; double mic_sample_double; @@ -455,8 +455,8 @@ static void process_ozy_input_buffer(char *buffer) { right_sample[r] += (int)((unsigned char)buffer[b++]) << 8; right_sample[r] += (int)((unsigned char)buffer[b++]); } - mic_sample = (short)((signed char) buffer[b++]) << 16; - mic_sample |= (short)((unsigned char)buffer[b++]); + mic_sample = (int)((signed char) buffer[b++]) << 8; + mic_sample |= (int)((unsigned char)buffer[b++]); mic_sample_double = (1.0 / 2147483648.0) * (double)(mic_sample<<16); for(r=0;rmode]); cairo_move_to(cr, 190, 50); - cairo_show_text(cr, band_filter->title); + if(mode==modeFMN) { + if(deviation==2500) { + cairo_show_text(cr, "8k"); + } else { + cairo_show_text(cr, "16k"); + } + } else { + cairo_show_text(cr, band_filter->title); + } cairo_move_to(cr, 250, 50); if(nr) { diff --git a/wdsp_init.c b/wdsp_init.c index a366212..2ffabe3 100644 --- a/wdsp_init.c +++ b/wdsp_init.c @@ -234,6 +234,7 @@ static void setupRX(int rx) { setRXMode(rx,mode); SetRXABandpassFreqs(rx, (double)filterLow, (double)filterHigh); + SetRXAFMDeviation(rx,(double)deviation); //SetRXAAGCMode(rx, agc); //SetRXAAGCTop(rx,agc_gain); wdsp_set_agc(rx, agc); @@ -269,6 +270,9 @@ static void setupTX(int tx) { SetTXABandpassWindow(tx, 1); SetTXABandpassRun(tx, 1); + SetTXAFMDeviation(tx,(double)deviation); + SetTXAFMEmphPosition(tx,pre_emphasize); + SetTXACFIRRun(tx, protocol==NEW_PROTOCOL?1:0); // turned in if new protocol if(enable_tx_equalizer) { SetTXAGrphEQ(tx, tx_equalizer); @@ -300,11 +304,9 @@ static void setupTX(int tx) { SetTXAPostGenToneFreq(tx, 0.0); SetTXAPostGenRun(tx, 0); - if(protocol==NEW_PROTOCOL) { - double gain=pow(10.0, mic_gain / 20.0); - SetTXAPanelGain1(tx,gain); - //SetTXAPanelRun(tx, protocol==NEW_PROTOCOL?1:0); - } + double gain=pow(10.0, mic_gain / 20.0); + SetTXAPanelGain1(tx,gain); + SetTXAPanelRun(tx, 1); //SetChannelState(tx,1,0); } @@ -427,6 +429,15 @@ void wdsp_new_sample_rate(int rate) { SetChannelState(receiver,1,0); } +void wdsp_set_deviation(double deviation) { + SetRXAFMDeviation(CHANNEL_RX0, deviation); + SetTXAFMDeviation(CHANNEL_TX, deviation); +} + +void wdsp_set_pre_emphasize(int state) { + SetTXAFMEmphPosition(CHANNEL_TX,state); +} + static void initAnalyzer(int channel,int buffer_size) { int flp[] = {0}; double KEEP_TIME = 0.1; diff --git a/wdsp_init.h b/wdsp_init.h index eb49fd2..a61b170 100644 --- a/wdsp_init.h +++ b/wdsp_init.h @@ -30,5 +30,6 @@ extern int getFilterHigh(); extern void wdsp_init(int rx,int pixels,int protocol); extern void wdsp_new_sample_rate(int rate); extern void wdsp_set_agc(int rx, int agc); - +extern void wdsp_set_deviation(double deviation); +extern void wdsp_set_pre_emphasize(int state); #endif -- 2.45.2