+/* 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) {
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) {
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);
}
}
+/* 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();
#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);
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) {
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);
gtk_widget_show_all(dialog);
+ if(vox_enabled) {
+ start_level_thread();
+ }
+
}