From: John Melton G0ORX Date: Tue, 18 Aug 2020 16:38:00 +0000 (+0100) Subject: Fix protocol 1 local microphone audio X-Git-Url: https://git.rkrishnan.org/components/vdrive//%22%22.?a=commitdiff_plain;h=6a11a4c363afa5f4ff180c7feb9c43d6a91c9793;p=pihpsdr.git Fix protocol 1 local microphone audio --- diff --git a/audio.c b/audio.c index d08adfc..3c4581a 100644 --- 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; diff --git a/old_protocol.c b/old_protocol.c index 595a4c5..054c2bc 100644 --- a/old_protocol.c +++ b/old_protocol.c @@ -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) {