]> git.rkrishnan.org Git - pihpsdr.git/commitdiff
added vox level to vox_menu
authorJohn Melton - G0ORX/N6LYT <john.d.melton@googlemail.com>
Wed, 7 Dec 2016 11:29:50 +0000 (11:29 +0000)
committerJohn Melton - G0ORX/N6LYT <john.d.melton@googlemail.com>
Wed, 7 Dec 2016 11:29:50 +0000 (11:29 +0000)
vox.c
vox.h
vox_menu.c

diff --git a/vox.c b/vox.c
index 183a16438a19d5d0d568dcb9893b6b1f4c71592b..540f59118924f82f92b5929ba553f764e9bde004 100644 (file)
--- 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 <gtk/gtk.h>
 
 
 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;i<length;i++) {
     sample=in[(i*2)+0];
     if(sample<0.0) {
@@ -34,15 +58,11 @@ void update_vox(double *in,int length) {
     threshold=vox_threshold*vox_gain;
   }
   if(peak>threshold) {
-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 ed1bb460e4964c631e5f85ebafdf337931cba4ba..b5d5d40ecbb656b68b2f3392c29e50e328ed00df 100644 (file)
--- 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();
index 6028b9b69bb1d529f1f5a8d02fe577d0613d38de..75e0966c7e7cd08b40531e52455b734676dc8eed 100644 (file)
 #include <semaphore.h>
 #include <stdio.h>
 #include <string.h>
+#include <pthread.h>
 
 #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();
+  }
+
 }