From: John Melton - G0ORX/N6LYT Date: Wed, 9 Nov 2016 17:00:19 +0000 (+0000) Subject: fixed old protocol support for local audio. Changed Mic gain to be in dB. X-Git-Url: https://git.rkrishnan.org/pf/components//%22%22.?a=commitdiff_plain;h=24cd1e8302280ece540e38454aac45366e688724;p=pihpsdr.git fixed old protocol support for local audio. Changed Mic gain to be in dB. --- diff --git a/audio.c b/audio.c index 3f3d4c6..443ad10 100644 --- a/audio.c +++ b/audio.c @@ -34,6 +34,7 @@ #include "audio.h" #include "new_protocol.h" +#include "old_protocol.h" #include "radio.h" int audio = 0; @@ -183,6 +184,7 @@ fprintf(stderr,"audio_open_input: %d\n",n_selected_input_device); break; } + fprintf(stderr,"audio_open_input: mic_buffer_size=%d\n",mic_buffer_size); i=0; while(selected[i]!=' ') { hw[i]=selected[i]; @@ -190,6 +192,7 @@ fprintf(stderr,"audio_open_input: %d\n",n_selected_input_device); } hw[i]='\0'; + fprintf(stderr,"audio_open_input: hw=%s\n",hw); if ((err = snd_pcm_open (&record_handle, hw, SND_PCM_STREAM_CAPTURE, 0)) < 0) { fprintf (stderr, "audio_open_input: cannot open audio device %s (%s)\n", @@ -309,20 +312,24 @@ int audio_write(short left_sample,short right_sample) { } static void *mic_read_thread(void *arg) { - int error; - if ((error = snd_pcm_prepare (record_handle)) < 0) { + int rc; + if ((rc = snd_pcm_prepare (record_handle)) < 0) { fprintf (stderr, "mic_read_thread: cannot prepare audio interface for use (%s)\n", - snd_strerror (error)); + snd_strerror (rc)); return; } +fprintf(stderr,"mic_read_thread: mic_buffer_size=%d\n",mic_buffer_size); while(running) { - if ((error = snd_pcm_readi (record_handle, mic_buffer, mic_buffer_size)) != mic_buffer_size) { + if ((rc = snd_pcm_readi (record_handle, mic_buffer, mic_buffer_size)) != mic_buffer_size) { if(running) { - fprintf (stderr, "mic_read_thread: read from audio interface failed (%s)\n", - snd_strerror (error)); - running=FALSE; + if(rc<0) { + fprintf (stderr, "mic_read_thread: read from audio interface failed (%s)\n", + snd_strerror (rc)); + running=FALSE; + } else { + fprintf(stderr,"mic_read_thread: read %d",rc); + } } - break; } else { // process the mic input switch(protocol) { @@ -337,6 +344,7 @@ static void *mic_read_thread(void *arg) { } } } +fprintf(stderr,"mic_read_thread: exiting\n"); } diff --git a/gpio.c b/gpio.c index 86a3a6a..af4859d 100644 --- a/gpio.c +++ b/gpio.c @@ -750,10 +750,10 @@ static int af_encoder_changed(void *data) { // mic gain double gain=mic_gain; gain+=(double)pos/100.0; - if(gain<0.0) { - gain=0.0; - } else if(gain>1.0) { - gain=1.0; + if(gain<-10.0) { + gain=-10.0; + } else if(gain>50.0) { + gain=50.0; } set_mic_gain(gain); } else { diff --git a/menu.c b/menu.c index 05e24d3..043e7ab 100644 --- a/menu.c +++ b/menu.c @@ -186,12 +186,17 @@ static void micboost_cb(GtkWidget *widget, gpointer data) { } static void local_audio_cb(GtkWidget *widget, gpointer data) { - if(local_audio) { - local_audio=0; - audio_close_output(); - } else { + if(gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget))) { if(audio_open_output()==0) { local_audio=1; + } else { + local_audio=0; + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget), FALSE); + } + } else { + if(local_audio) { + local_audio=0; + audio_close_output(); } } } @@ -208,18 +213,25 @@ static void local_output_changed_cb(GtkWidget *widget, gpointer data) { } static void local_microphone_cb(GtkWidget *widget, gpointer data) { - if(local_microphone) { - local_microphone=0; - audio_close_input(); - } else { +fprintf(stderr,"local_microphone_cb: %d\n",local_microphone); + if(gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget))) { if(audio_open_input()==0) { local_microphone=1; + } else { + local_microphone=0; + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget), FALSE); + } + } else { + if(local_microphone) { + local_microphone=0; + audio_close_input(); } } } static void local_input_changed_cb(GtkWidget *widget, gpointer data) { n_selected_input_device=(int)(long)data; +fprintf(stderr,"local_input_changed_cb: %d selected=%d\n",local_microphone,n_selected_input_device); if(local_microphone) { audio_close_input(); if(audio_open_input()==0) { diff --git a/new_protocol.c b/new_protocol.c index 774a18c..4935301 100644 --- a/new_protocol.c +++ b/new_protocol.c @@ -1114,7 +1114,7 @@ static void full_tx_buffer() { } } -void *new_protocol_process_local_mic(unsigned char *buffer,int le) { +void new_protocol_process_local_mic(unsigned char *buffer,int le) { int b; int leftmicsample; int rightmicsample; @@ -1128,14 +1128,11 @@ void *new_protocol_process_local_mic(unsigned char *buffer,int le) { if(le) { leftmicsample = (int)((unsigned char)buffer[b++] & 0xFF); leftmicsample |= (int)((signed char) buffer[b++]) << 8; - //rightmicsample = (int)((unsigned char)buffer[b++] & 0xFF); - //rightmicsample |= (int)((signed char) buffer[b++]) << 8; rightmicsample=leftmicsample; } else { leftmicsample = (int)((signed char) buffer[b++]) << 8; leftmicsample |= (int)((unsigned char)buffer[b++] & 0xFF); - rightmicsample = (int)((signed char) buffer[b++]) << 8; - rightmicsample |= (int)((unsigned char)buffer[b++] & 0xFF); + rightmicsample=leftmicsample; } #ifdef FREEDV if(mode==modeFREEDV && isTransmitting()) { diff --git a/new_protocol.h b/new_protocol.h index e53710c..e8df587 100644 --- a/new_protocol.h +++ b/new_protocol.h @@ -78,5 +78,5 @@ void setTune(int state); int getTune(); int isTransmitting(); -void *new_protocol_process_local_mic(unsigned char *buffer,int le); +void new_protocol_process_local_mic(unsigned char *buffer,int le); #endif diff --git a/old_protocol.c b/old_protocol.c index 42b3947..aeb1536 100644 --- a/old_protocol.c +++ b/old_protocol.c @@ -446,7 +446,7 @@ static void process_ozy_input_buffer(char *buffer) { left_sample_double=(double)left_sample/8388607.0; // 24 bit sample 2^23-1 right_sample_double=(double)right_sample/8388607.0; // 24 bit sample 2^23-1 - mic_sample_double=(double)mic_sample/32767.0; // 16 bit sample 2^16-1 + mic_sample_double = (1.0 / 2147483648.0) * (double)(mic_sample<<16); // add to buffer if(isTransmitting() && !local_microphone) { @@ -459,7 +459,7 @@ static void process_ozy_input_buffer(char *buffer) { for(s=0;sdevice==DEVICE_METIS && atlas_penelope) { @@ -653,37 +652,16 @@ static void full_tx_buffer() { gain=gain*drive; } } -fprintf(stderr,"full_tx_buffer: gain=%f\n",gain); for(j=0;jmax_sample) max_sample=left_tx_sample; - //if(right_tx_samplemax_sample) max_sample=right_tx_sample; - - if(left_tx_sample>32767) { - left_tx_sample=32767; -// overflow++; - } else if(left_tx_sample<-32767) { - left_tx_sample=-32767; -// overflow++; - } - if(right_tx_sample>32767) { - right_tx_sample=32767; -// overflow++; - } else if(right_tx_sample<-32767) { - right_tx_sample=-32767; -// overflow++; - } - output_buffer[output_buffer_index++]=left_rx_sample>>8; - output_buffer[output_buffer_index++]=left_rx_sample; - output_buffer[output_buffer_index++]=right_rx_sample>>8; - output_buffer[output_buffer_index++]=right_rx_sample; + output_buffer[output_buffer_index++]=0; + output_buffer[output_buffer_index++]=0; + output_buffer[output_buffer_index++]=0; + output_buffer[output_buffer_index++]=0; output_buffer[output_buffer_index++]=left_tx_sample>>8; output_buffer[output_buffer_index++]=left_tx_sample; output_buffer[output_buffer_index++]=right_tx_sample>>8; @@ -696,7 +674,7 @@ fprintf(stderr,"full_tx_buffer: gain=%f\n",gain); } -void *old_protocol_process_local_mic(unsigned char *buffer,int le) { +void old_protocol_process_local_mic(unsigned char *buffer,int le) { int b; int leftmicsample; int rightmicsample; @@ -710,14 +688,11 @@ void *old_protocol_process_local_mic(unsigned char *buffer,int le) { if(le) { leftmicsample = (int)((unsigned char)buffer[b++] & 0xFF); leftmicsample |= (int)((signed char) buffer[b++]) << 8; - //rightmicsample = (int)((unsigned char)buffer[b++] & 0xFF); - //rightmicsample |= (int)((signed char) buffer[b++]) << 8; rightmicsample=leftmicsample; } else { leftmicsample = (int)((signed char) buffer[b++]) << 8; leftmicsample |= (int)((unsigned char)buffer[b++] & 0xFF); - rightmicsample = (int)((signed char) buffer[b++]) << 8; - rightmicsample |= (int)((unsigned char)buffer[b++] & 0xFF); + rightmicsample=leftmicsample; } #ifdef FREEDV if(mode==modeFREEDV && !tune) { @@ -747,25 +722,28 @@ void *old_protocol_process_local_mic(unsigned char *buffer,int le) { } } else { #endif + leftmicsampledouble=(double)leftmicsample/32767.0; // 16 bit sample 2^16-1 if(mode==modeCWL || mode==modeCWU || tune) { - micinputbuffer[samples*2]=0.0; - micinputbuffer[(samples*2)+1]=0.0; - } else { - micinputbuffer[samples*2]=leftmicsampledouble; - micinputbuffer[(samples*2)+1]=leftmicsampledouble; - } - iqinputbuffer[samples*2]=0.0; - iqinputbuffer[(samples*2)+1]=0.0; - samples++; - if(samples==buffer_size) { - full_tx_buffer(); - samples=0; - } + micinputbuffer[samples*2]=0.0; + micinputbuffer[(samples*2)+1]=0.0; + } else { + micinputbuffer[samples*2]=leftmicsampledouble; + micinputbuffer[(samples*2)+1]=leftmicsampledouble; + } + iqinputbuffer[samples*2]=0.0; + iqinputbuffer[(samples*2)+1]=0.0; + samples++; + if(samples==buffer_size) { + full_tx_buffer(); + samples=0; + } #ifdef FREEDV } #endif } + } else { + //fprintf(stderr,"not transmitting - ignore local mic buffer\n"); } } @@ -941,15 +919,15 @@ void ozy_send_buffer() { break; case 3: { - float d=(float)drive; + double d=(double)drive; if(tune) { - d=(float)tune_drive; + d=(double)tune_drive; } int power=0; if(isTransmitting()) { BAND *band=band_get_current_band(); - d=d*((float)band->pa_calibration/100.0F); + d=d*((double)band->pa_calibration/100.0); power=(int)(d*255.0); } diff --git a/old_protocol.h b/old_protocol.h index 25872f6..c38f554 100644 --- a/old_protocol.h +++ b/old_protocol.h @@ -25,6 +25,6 @@ void old_protocol_stop(); void old_protocol_init(int rx,int pixels); void old_protocol_new_sample_rate(int rate); void schedule_frequency_changed(); -void *old_protocol_process_local_mic(unsigned char *buffer,int le); +void old_protocol_process_local_mic(unsigned char *buffer,int le); #endif diff --git a/pihpsdr b/pihpsdr index 8c7070a..a945910 100755 Binary files a/pihpsdr and b/pihpsdr differ diff --git a/radio.c b/radio.c index 7afd0d3..af6786e 100644 --- a/radio.c +++ b/radio.c @@ -86,7 +86,7 @@ int display_toolbar=1; int toolbar_dialog_buttons=1; double volume=0.2; -double mic_gain=0.5; +double mic_gain=0.0; int rx_dither=0; int rx_random=0; @@ -271,8 +271,7 @@ void setTune(int state) { } else { SetTXAPostGenToneFreq(CHANNEL_TX,(double)cw_keyer_sidetone_frequency); } - //SetTXAPostGenToneMag(CHANNEL_TX,0.99999); - SetTXAPostGenToneMag(CHANNEL_TX,1.0); + SetTXAPostGenToneMag(CHANNEL_TX,2.0); SetTXAPostGenRun(CHANNEL_TX,1); SetChannelState(CHANNEL_RX0,0,1); SetChannelState(CHANNEL_TX,1,0); @@ -473,7 +472,7 @@ void radioRestoreState() { value=getProperty("tune_drive"); if(value) {tune_drive=atof(value); if(tune_drive>1.0) tune_drive=1.0;} value=getProperty("mic_gain"); - if(value) { mic_gain=atof(value); if(mic_gain>1.0) mic_gain=1.0; } + if(value) { mic_gain=atof(value); if(mic_gain<1.0) mic_gain=0.0; } value=getProperty("mic_boost"); if(value) mic_boost=atof(value); value=getProperty("mic_linein"); diff --git a/release/pihpsdr.tar b/release/pihpsdr.tar index 913770c..ae8906f 100644 Binary files a/release/pihpsdr.tar and b/release/pihpsdr.tar differ diff --git a/release/pihpsdr/pihpsdr b/release/pihpsdr/pihpsdr index 8c7070a..1fc1b64 100755 Binary files a/release/pihpsdr/pihpsdr and b/release/pihpsdr/pihpsdr differ diff --git a/sliders.c b/sliders.c index 03c0d09..fd86935 100644 --- a/sliders.c +++ b/sliders.c @@ -20,6 +20,7 @@ #include #include #include +#include #include "sliders.h" #include "mode.h" @@ -194,15 +195,17 @@ void set_af_gain(double value) { } static void micgain_value_changed_cb(GtkWidget *widget, gpointer data) { - mic_gain=gtk_range_get_value(GTK_RANGE(widget))/100.0; - SetTXAPanelGain1(CHANNEL_TX,mic_gain); + mic_gain=gtk_range_get_value(GTK_RANGE(widget)); + double gain=pow(10.0, mic_gain / 20.0); + SetTXAPanelGain1(CHANNEL_TX,gain); } void set_mic_gain(double value) { mic_gain=value; - SetTXAPanelGain1(CHANNEL_TX,mic_gain); + double gain=pow(10.0, mic_gain / 20.0); + SetTXAPanelGain1(CHANNEL_TX,gain); if(display_sliders) { - gtk_range_set_value (GTK_RANGE(mic_gain_scale),mic_gain*100.0); + gtk_range_set_value (GTK_RANGE(mic_gain_scale),mic_gain); } else { if(scale_status!=MIC_GAIN) { if(scale_status!=NONE) { @@ -213,11 +216,11 @@ void set_mic_gain(double value) { } if(scale_status==NONE) { scale_status=MIC_GAIN; - scale_dialog=gtk_dialog_new_with_buttons(mic_linein?"Linein Gain":"Mic Gain",GTK_WINDOW(parent_window),GTK_DIALOG_DESTROY_WITH_PARENT,NULL,NULL); + scale_dialog=gtk_dialog_new_with_buttons(mic_linein?"Linein Gain (dB)":"Mic Gain (dB)",GTK_WINDOW(parent_window),GTK_DIALOG_DESTROY_WITH_PARENT,NULL,NULL); GtkWidget *content=gtk_dialog_get_content_area(GTK_DIALOG(scale_dialog)); - mic_gain_scale=gtk_scale_new_with_range(GTK_ORIENTATION_HORIZONTAL,0.0, 100.0, 1.00); + mic_gain_scale=gtk_scale_new_with_range(GTK_ORIENTATION_HORIZONTAL,-10.0, 50.0, 1.00); gtk_widget_set_size_request (mic_gain_scale, 400, 30); - gtk_range_set_value (GTK_RANGE(mic_gain_scale),mic_gain*100.0); + gtk_range_set_value (GTK_RANGE(mic_gain_scale),mic_gain); gtk_widget_show(mic_gain_scale); gtk_container_add(GTK_CONTAINER(content),mic_gain_scale); scale_timer=g_timeout_add(2000,scale_timeout_cb,NULL); @@ -225,7 +228,7 @@ void set_mic_gain(double value) { int result=gtk_dialog_run(GTK_DIALOG(scale_dialog)); } else { g_source_remove(scale_timer); - gtk_range_set_value (GTK_RANGE(mic_gain_scale),mic_gain*100.0); + gtk_range_set_value (GTK_RANGE(mic_gain_scale),mic_gain); scale_timer=g_timeout_add(2000,scale_timeout_cb,NULL); } @@ -351,13 +354,13 @@ GtkWidget *sliders_init(int my_width, int my_height, GtkWidget* parent) { - mic_gain_label=gtk_label_new(mic_linein?"Linein:":"Mic:"); + mic_gain_label=gtk_label_new(mic_linein?"Linein (dB):":"Mic (dB):"); //gtk_widget_override_font(mic_gain_label, pango_font_description_from_string("Arial 16")); gtk_widget_show(mic_gain_label); gtk_grid_attach(GTK_GRID(sliders),mic_gain_label,0,1,1,1); - mic_gain_scale=gtk_scale_new_with_range(GTK_ORIENTATION_HORIZONTAL,0.0, 100.0, 1.0); - gtk_range_set_value (GTK_RANGE(mic_gain_scale),mic_gain*100.0); + mic_gain_scale=gtk_scale_new_with_range(GTK_ORIENTATION_HORIZONTAL,-10.0, 50.0, 1.0); + gtk_range_set_value (GTK_RANGE(mic_gain_scale),mic_gain); gtk_widget_show(mic_gain_scale); gtk_grid_attach(GTK_GRID(sliders),mic_gain_scale,1,1,2,1); g_signal_connect(G_OBJECT(mic_gain_scale),"value_changed",G_CALLBACK(micgain_value_changed_cb),NULL); diff --git a/wdsp_init.c b/wdsp_init.c index fa80c7d..1e54f17 100644 --- a/wdsp_init.c +++ b/wdsp_init.c @@ -269,6 +269,8 @@ static void setupRX(int rx) { SetRXAANRRun(rx, nr); SetRXAANFRun(rx, anf); SetRXASNBARun(rx, snb); + + SetRXAPanelGain1(rx, volume); } static void setupTX(int tx) { @@ -299,6 +301,10 @@ static void setupTX(int tx) { SetTXAPostGenToneFreq(tx, 0.0); SetTXAPostGenRun(tx, 0); + SetTXAPanelRun(tx, 1); + double gain=pow(10.0, mic_gain / 20.0); + SetTXAPanelGain1(tx,gain); + //SetChannelState(tx,1,0); }