From: John Melton - G0ORX/N6LYT Date: Wed, 7 Dec 2016 11:29:50 +0000 (+0000) Subject: added vox level to vox_menu X-Git-Url: https://git.rkrishnan.org/components/-?a=commitdiff_plain;h=030cc94b2592445a856e6bc6e730fedb998d66d0;p=pihpsdr.git added vox level to vox_menu --- diff --git a/vox.c b/vox.c index 183a164..540f591 100644 --- a/vox.c +++ b/vox.c @@ -1,3 +1,21 @@ +/* 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 @@ -7,19 +25,25 @@ static guint vox_timeout; +static double peak=0.0; + static int vox_timeout_cb(gpointer data) { -fprintf(stderr,"vox_timeout_cb: setVox: 0\n"); setVox(0); g_idle_add(vfo_update,NULL); return FALSE; } + +double vox_get_peak() { + return peak; +} + void update_vox(double *in,int length) { // assumes in is interleaved left and right channel with length samples int previous_vox=vox; int i; - double peak=0.0; double sample; + peak=0.0; for(i=0;ithreshold) { -fprintf(stderr,"update_vox: threshold=%f\n",threshold); if(previous_vox) { -fprintf(stderr,"update_vox: g_source_remove: vox_timeout\n"); g_source_remove(vox_timeout); } else { -fprintf(stderr,"update_vox: setVox: 1\n"); setVox(1); } -fprintf(stderr,"g_timeout_add: %d\n",(int)vox_hang); vox_timeout=g_timeout_add((int)vox_hang,vox_timeout_cb,NULL); } if(vox!=previous_vox) { @@ -52,9 +72,7 @@ fprintf(stderr,"g_timeout_add: %d\n",(int)vox_hang); void vox_cancel() { if(vox) { -fprintf(stderr,"vox_cancel: g_source_remove: vox_timeout\n"); g_source_remove(vox_timeout); -fprintf(stderr,"vox_cancel: setVox: 0\n"); setVox(0); } } diff --git a/vox.h b/vox.h index ed1bb46..b5d5d40 100644 --- a/vox.h +++ b/vox.h @@ -1,2 +1,22 @@ +/* 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. +* +*/ + extern void update_vox(double *in,int length); extern void vox_cancel(); +extern double vox_get_peak(); diff --git a/vox_menu.c b/vox_menu.c index 6028b9b..75e0966 100644 --- a/vox_menu.c +++ b/vox_menu.c @@ -21,15 +21,36 @@ #include #include #include +#include #include "new_menu.h" #include "vox_menu.h" +#include "vox.h" #include "radio.h" static GtkWidget *parent_window=NULL; static GtkWidget *dialog=NULL; +static GtkWidget *level; + +static pthread_t level_thread_id; +static int run_level=0; +static double peak=0.0; + +static int level_update(void *data) { + gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(level),peak); + return 0; +} + +static void *level_thread(void* arg) { + while(run_level && !gtk_widget_in_destruction(dialog)) { + peak=vox_get_peak(); + g_idle_add(level_update,NULL); + usleep(100000); // 100ms + } +} + static gboolean close_cb (GtkWidget *widget, GdkEventButton *event, gpointer data) { if(dialog!=NULL) { gtk_widget_destroy(dialog); @@ -39,8 +60,24 @@ static gboolean close_cb (GtkWidget *widget, GdkEventButton *event, gpointer dat return TRUE; } +static void start_level_thread() { + int rc; + fprintf(stderr,"start_level_thread\n"); + run_level=1; + rc=pthread_create(&level_thread_id,NULL,level_thread,NULL); + if(rc != 0) { + fprintf(stderr,"vox_menu: pthread_create failed on level_thread: rc=%d\n", rc); + run_level=0; + } +} + static void vox_cb(GtkWidget *widget, gpointer data) { vox_enabled=vox_enabled==1?0:1; + if(vox_enabled) { + start_level_thread(); + } else { + run_level=0; + } } static void vox_value_changed_cb(GtkWidget *widget, gpointer data) { @@ -89,6 +126,21 @@ void vox_menu(GtkWidget *parent) { gtk_grid_attach(GTK_GRID(grid),vox_b,0,1,1,1); g_signal_connect(vox_b,"toggled",G_CALLBACK(vox_cb),NULL); + level=gtk_progress_bar_new(); + gtk_widget_show(level); + gtk_grid_attach(GTK_GRID(grid),level,1,1,1,1); + +/* + GtkStyleContext *style_context; + GtkCssProvider *provider = gtk_css_provider_new (); + gchar tmp[64]; + style_context = gtk_widget_get_style_context(level); + gtk_style_context_add_provider(style_context, GTK_STYLE_PROVIDER(provider), GTK_STYLE_PROVIDER_PRIORITY_APPLICATION); + g_snprintf(tmp, sizeof tmp, "GtkProgressBar.progress { background-color: %s; }", "red"); + gtk_css_provider_load_from_data(GTK_CSS_PROVIDER(provider), tmp, -1, NULL); + g_object_unref (provider); +*/ + GtkWidget *threshold_label=gtk_label_new("VOX Threshold:"); gtk_misc_set_alignment (GTK_MISC(threshold_label), 0, 0); gtk_widget_show(threshold_label); @@ -128,5 +180,9 @@ void vox_menu(GtkWidget *parent) { gtk_widget_show_all(dialog); + if(vox_enabled) { + start_level_thread(); + } + }