From a784d08d022294e95e0f6d51225ce5e027c64b8e Mon Sep 17 00:00:00 2001 From: John Melton - G0ORX/N6LYT Date: Tue, 6 Dec 2016 22:20:16 +0000 Subject: [PATCH] vox.c and vox.h --- vox.c | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ vox.h | 2 ++ 2 files changed, 62 insertions(+) create mode 100644 vox.c create mode 100644 vox.h diff --git a/vox.c b/vox.c new file mode 100644 index 0000000..183a164 --- /dev/null +++ b/vox.c @@ -0,0 +1,60 @@ + +#include + +#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;ipeak) { + 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 index 0000000..ed1bb46 --- /dev/null +++ b/vox.h @@ -0,0 +1,2 @@ +extern void update_vox(double *in,int length); +extern void vox_cancel(); -- 2.45.2