]> git.rkrishnan.org Git - pihpsdr.git/commitdiff
Fix protocol 1 local microphone audio
authorJohn Melton G0ORX <john.d.melton@googlemail.com>
Tue, 18 Aug 2020 16:38:00 +0000 (17:38 +0100)
committerJohn Melton G0ORX <john.d.melton@googlemail.com>
Tue, 18 Aug 2020 16:38:00 +0000 (17:38 +0100)
audio.c
old_protocol.c

diff --git a/audio.c b/audio.c
index d08adfc157839f245e32b189fc4d02aca9f2dc9c..3c4581a6eccb6d855651e37b109bc527d0c4d6af 100644 (file)
--- a/audio.c
+++ b/audio.c
@@ -179,24 +179,7 @@ int audio_open_input() {
 g_print("audio_open_input: %s\n",transmitter->microphone_name);
   
   mic_buffer_size = 256;
-/*
-  switch(protocol) {
-    case ORIGINAL_PROTOCOL:
-      mic_buffer_size = 720;
-      break;
-    case NEW_PROTOCOL:
-      mic_buffer_size = 64;
-      break;
-#ifdef SOAPYSDR
-    case SOAPYSDR_PROTOCOL:
-      mic_buffer_size = 720;
-      break;
-#endif
-    default:
-      break;
-  }
-*/
-  
+
   g_print("audio_open_input: mic_buffer_size=%d\n",mic_buffer_size);
   i=0;
   while(transmitter->microphone_name[i]!=' ') {
@@ -231,6 +214,7 @@ g_print("audio_open_input: using format %s (%s)\n",snd_pcm_format_name(formats[i
 
   if(i>=FORMATS) {
     g_print("audio_open_input: cannot find usable format\n");
+    audio_close_input();
     return err;
   }
 
@@ -255,6 +239,7 @@ g_print("audio_open_input: allocating ring buffer\n");
   mic_ring_buffer=(float *) g_new(float,MICRINGLEN);
   mic_ring_read_pt = mic_ring_write_pt=0;
   if (mic_ring_buffer == NULL) {
+    audio_close_input();
     return -1;
   }
 
@@ -263,6 +248,8 @@ g_print("audio_open_input: creating mic_read_thread\n");
   mic_read_thread_id = g_thread_try_new("microphone",mic_read_thread,NULL,&error);
   if(!mic_read_thread_id ) {
     g_print("g_thread_new failed on mic_read_thread: %s\n",error->message);
+    audio_close_input();
+    return -1;
   }
 
   return 0;
index 595a4c527397606c8ecaf06ecc95edcf7a57184b..054c2bca0e75bf746100f93f8479fecf7cf06240 100644 (file)
@@ -1168,6 +1168,7 @@ static int rx2channel;
 
 static void process_ozy_byte(int b) {
   int i,j;
+  float fsample;
   switch(state) {
     case SYNC_0:
       if(b==SYNC) {
@@ -1292,12 +1293,11 @@ static void process_ozy_byte(int b) {
       break;
     case MIC_SAMPLE_LOW:
       mic_sample|=(short)(b&0xFF);
-      if(!transmitter->local_microphone) {
-        mic_samples++;
-        if(mic_samples>=mic_sample_divisor) { // reduce to 48000
-          add_mic_sample(transmitter,(float)mic_sample/32768.0);
-          mic_samples=0;
-        }
+      mic_samples++;
+      if(mic_samples>=mic_sample_divisor) { // reduce to 48000
+        fsample = transmitter->local_microphone ? audio_get_next_mic_sample() : (float) mic_sample * 0.00003051;
+        add_mic_sample(transmitter,fsample);
+        mic_samples=0;
       }
       nsamples++;
       if(nsamples==iq_samples) {