]> git.rkrishnan.org Git - pihpsdr.git/commitdiff
vox.c and vox.h
authorJohn Melton - G0ORX/N6LYT <john.d.melton@googlemail.com>
Tue, 6 Dec 2016 22:20:16 +0000 (22:20 +0000)
committerJohn Melton - G0ORX/N6LYT <john.d.melton@googlemail.com>
Tue, 6 Dec 2016 22:20:16 +0000 (22:20 +0000)
vox.c [new file with mode: 0644]
vox.h [new file with mode: 0644]

diff --git a/vox.c b/vox.c
new file mode 100644 (file)
index 0000000..183a164
--- /dev/null
+++ b/vox.c
@@ -0,0 +1,60 @@
+
+#include <gtk/gtk.h>
+
+#include "radio.h"
+#include "vox.h"
+#include "vfo.h"
+
+static guint vox_timeout;
+
+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;
+}
+
+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;
+  for(i=0;i<length;i++) {
+    sample=in[(i*2)+0];
+    if(sample<0.0) {
+      sample=-sample;
+    }
+    if(sample>peak) {
+      peak=sample;
+    }
+  }
+  double threshold=vox_threshold;
+  if(mic_boost && !local_microphone) {
+    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) {
+    g_idle_add(vfo_update,NULL);
+  }
+}
+
+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
new file mode 100644 (file)
index 0000000..ed1bb46
--- /dev/null
+++ b/vox.h
@@ -0,0 +1,2 @@
+extern void update_vox(double *in,int length);
+extern void vox_cancel();