From 1f7abfc232f70d4c6b2241ebdf962b51699b3e6e Mon Sep 17 00:00:00 2001 From: c vw Date: Thu, 19 Dec 2019 11:26:20 +0100 Subject: [PATCH] TX audio problem solved, and "setting out-of-band frequency" fixed. --- audio.c | 4 +- band.c | 1 + ext.c | 1 - freqent_menu.c | 4 -- portaudio.c | 12 +++--- rigctl.c | 112 ------------------------------------------------- rigctl.h | 1 - store_menu.c | 1 - vfo_menu.c | 19 ++------- 9 files changed, 15 insertions(+), 140 deletions(-) diff --git a/audio.c b/audio.c index 50ab759..30ad173 100644 --- a/audio.c +++ b/audio.c @@ -75,8 +75,10 @@ AUDIO_DEVICE output_devices[MAX_AUDIO_DEVICES]; // // Ring buffer for "local microphone" samples +// NOTE: lead large buffer for some "loopback" devices which produce +// samples in large chunks if fed from digimode programs. // -#define MICRINGLEN 2048 +#define MICRINGLEN 6000 float *mic_ring_buffer=NULL; int mic_ring_read_pt=0; int mic_ring_write_pt=0; diff --git a/band.c b/band.c index 194c9df..7bb9c87 100644 --- a/band.c +++ b/band.c @@ -645,6 +645,7 @@ int get_band_from_frequency(long long f) { } } } + if (found < 0) found=bandGen; g_print("get_band_from_frequency: %lld id %d\n",f,found); return found; } diff --git a/ext.c b/ext.c index 15d9b6f..0436735 100644 --- a/ext.c +++ b/ext.c @@ -65,7 +65,6 @@ int ext_set_frequency(void *data) { long long freq = *(long long *)data; int id=active_receiver->id; int b = get_band_from_frequency(freq); - if (b < 0) b=bandGen; if (b != vfo[id].band) { vfo_band_changed(b); } diff --git a/freqent_menu.c b/freqent_menu.c index 7a1fdc5..b378b3a 100644 --- a/freqent_menu.c +++ b/freqent_menu.c @@ -121,10 +121,6 @@ static gboolean freqent_select_cb (GtkWidget *widget, gpointer data) { sprintf(output, "%lld", f); gtk_label_set_markup (GTK_LABEL (label), output); int b=get_band_from_frequency(f); - if(b<0) { - fprintf(stderr,"get_band_from_frequency: failed for f=%lld\n",f); - b=bandGen; - } if(b!=band_get_current()) { BAND *band=band_set_current(b); set_mode(active_receiver,entry->mode); diff --git a/portaudio.c b/portaudio.c index 9827569..c797fe1 100644 --- a/portaudio.c +++ b/portaudio.c @@ -51,8 +51,10 @@ int n_output_devices=0; // // Ring buffer for "local microphone" samples +// NOTE: lead large buffer for some "loopback" devices which produce +// samples in large chunks if fed from digimode programs. // -#define MICRINGLEN 2048 +#define MICRINGLEN 6000 float *mic_ring_buffer=NULL; int mic_ring_read_pt=0; int mic_ring_write_pt=0; @@ -318,7 +320,7 @@ int audio_open_output(RECEIVER *rx) rx->local_audio_buffer=g_new(float,BUFFER_SIZE); rx->local_audio_buffer_offset=0; err = Pa_OpenStream(&(rx->playback_handle), NULL, &outputParameters, 48000.0, framesPerBuffer, paNoFlag, NULL, NULL); - if (err != paNoError) { + if (err != paNoError || rx->local_audio_buffer == NULL) { fprintf(stderr,"PORTAUDIO ERROR: out open stream: %s\n",Pa_GetErrorText(err)); rx->playback_handle = NULL; if (rx->local_audio_buffer) g_free(rx->local_audio_buffer); @@ -339,7 +341,7 @@ int audio_open_output(RECEIVER *rx) // Write one buffer to avoid under-flow errors // (this gives us 5 msec to pass before we have to call audio_write the first time) bzero(rx->local_audio_buffer, (size_t) BUFFER_SIZE*sizeof(float)); - err=Pa_WriteStream(rx->playback_handle, rx->local_audio_buffer, (unsigned long) BUFFER_SIZE); + Pa_WriteStream(rx->playback_handle, rx->local_audio_buffer, (unsigned long) BUFFER_SIZE); g_mutex_unlock(&rx->local_audio_mutex); return 0; } @@ -441,10 +443,10 @@ int audio_write (RECEIVER *rx, float left, float right) } g_mutex_lock(&rx->local_audio_mutex); - if (rx->playback_handle != NULL && rx->local_audio_buffer != NULL) { + if (rx->playback_handle != NULL && buffer != NULL) { buffer[rx->local_audio_buffer_offset++] = (left+right)*0.5; // mix to MONO if (rx->local_audio_buffer_offset == BUFFER_SIZE) { - Pa_WriteStream(rx->playback_handle, rx->local_audio_buffer, (unsigned long) BUFFER_SIZE); + Pa_WriteStream(rx->playback_handle, buffer, (unsigned long) BUFFER_SIZE); rx->local_audio_buffer_offset=0; // do not check on errors, there will be underflows every now and then } diff --git a/rigctl.c b/rigctl.c index 7ff0035..a6e86ff 100644 --- a/rigctl.c +++ b/rigctl.c @@ -1750,11 +1750,6 @@ void parse_cmd ( char * cmd_input,int len,int client_sock) { *p= new_freqA; g_idle_add(ext_set_frequency,(gpointer)p); g_idle_add(ext_vfo_update,NULL); - //g_idle_add(set_band,(gpointer) p_int); - //long long * freq_p; - //*freq_p=new_freqA; - //setFrequency(new_freqA); - //g_idle_add(gui_vfo_move_to,(gpointer)freq_p); return; } else { if(len==2) { @@ -4032,113 +4027,6 @@ void set_freqB(long long new_freqB) { } -int set_band (gpointer data) { - - BANDSTACK *bandstack; - long long new_freq = *(long long *) data; - free(data); - - #ifdef RIGCTL_DEBUG - fprintf(stderr,"RIGCTL set_band: New freq=%lld\n",new_freq); - #endif - - // If CTUN=1 - can only change frequencies within the sample_rate range! - if((vfo[active_receiver->id].ctun == 1) && - ((vfo[active_receiver->id].ctun_frequency + (active_receiver->sample_rate/2) < new_freq) || - (vfo[active_receiver->id].ctun_frequency - (active_receiver->sample_rate/2) > new_freq))) { - fprintf(stderr,"RIGCTL: *** set_band: CTUN Bounce ***\n"); - return 0; - } - - int b = get_band_from_frequency (new_freq); - - if(b == -1) { // Not in the ham bands! - // We're not going to update the bandstack - but rather just - // change the frequency and move on - vfo[active_receiver->id].frequency=new_freq; - receiver_vfo_changed(receiver[active_receiver->id]); - g_idle_add(ext_vfo_update,NULL); - return 0; - } - - #ifdef RIGCTL_DEBUG - fprintf(stderr,"RIGCTL set_band: New Band=%d\n",b); - #endif - int id=active_receiver->id; - - //if(id==0) { - // fprintf(stderr,"RIGCTL set_band: id=0\n"); - // vfo_save_bandstack(); - //} - if(b==vfo[id].band) { - //fprintf(stderr,"RIGCTL set_band:b=cur_band \n"); - // same band selected - step to the next band stack - bandstack=bandstack_get_bandstack(b); - vfo[id].bandstack++; - if(vfo[id].bandstack>=bandstack->entries) { - //fprintf(stderr,"VFO_BAND_CHANGED: bandstack set to 0\n"); - vfo[id].bandstack=0; - } - } else { - // new band - get band stack entry - //fprintf(stderr,"VFO_BAND_CHANGED: new_band\n"); - bandstack=bandstack_get_bandstack(b) ; - vfo[id].bandstack=bandstack->current_entry; - //fprintf(stderr,"VFO_BAND_CHANGED: vfo[id].banstack=%d\n",vfo[id].bandstack); - } - - BAND *band=band_get_band(b); - BANDSTACK_ENTRY *entry=&bandstack->entry[vfo[id].bandstack]; - if(vfo[id].band != b) { - vfo[id].mode=entry->mode; - } - vfo[id].band=b; - entry->frequency = new_freq; - //vfo[id].frequency=entry->frequency; - if(vfo[id].ctun == 1) { - fprintf(stderr,"RIGCTL: set_band #### Change frequency"); - if(new_freq > vfo[id].ctun_frequency) { - vfo[id].offset = new_freq - vfo[id].ctun_frequency; - } else { - vfo[id].offset = vfo[id].ctun_frequency - new_freq; - } - fprintf(stderr,"RIGCTL: set_band OFSET= %011lld\n",vfo[id].offset); - } else { - entry->frequency = new_freq; - } - - //vfo[id].mode=entry->mode; - vfo[id].filter=entry->filter; - vfo[id].lo=band->frequencyLO; - - switch(id) { - case 0: - bandstack->current_entry=vfo[id].bandstack; - receiver_vfo_changed(receiver[id]); - BAND *band=band_get_band(vfo[id].band); - set_alex_rx_antenna(band->alexRxAntenna); - set_alex_tx_antenna(band->alexTxAntenna); - set_alex_attenuation(band->alexAttenuation); - receiver_vfo_changed(receiver[0]); - break; - case 1: - if(receivers==2) { - receiver_vfo_changed(receiver[1]); - } - break; - } - - if(split) { - tx_set_mode(transmitter,vfo[VFO_B].mode); - } else { - tx_set_mode(transmitter,vfo[VFO_A].mode); - } - calcDriveLevel(); - //calcTuneDriveLevel(); - g_idle_add(ext_vfo_update,NULL); - - return 0; -} int set_alc(gpointer data) { int * lcl_ptr = (int *) data; alc = *lcl_ptr; diff --git a/rigctl.h b/rigctl.h index da827eb..45a8ad0 100644 --- a/rigctl.h +++ b/rigctl.h @@ -10,7 +10,6 @@ int rigctlGetMode(); int lookup_band(int); char * rigctlGetFilter(); void set_freqB(long long); -int set_band(void *); extern int cat_control; int set_alc(gpointer); extern int rigctl_busy; diff --git a/store_menu.c b/store_menu.c index e8d1c4e..29f8808 100644 --- a/store_menu.c +++ b/store_menu.c @@ -98,7 +98,6 @@ static gboolean recall_select_cb (GtkWidget *widget, gpointer data) { fprintf(stderr,"recall_select_cb: mode=%d\n",mem[index].mode); fprintf(stderr,"recall_select_cb: filter=%d\n",mem[index].filter); - //set_band(mem[index].frequency,index); vfo[active_receiver->id].frequency = new_freq; vfo[active_receiver->id].band = get_band_from_frequency(new_freq); vfo[active_receiver->id].mode = mem[index].mode; diff --git a/vfo_menu.c b/vfo_menu.c index 3f5da0d..8744a27 100644 --- a/vfo_menu.c +++ b/vfo_menu.c @@ -86,7 +86,7 @@ static gboolean freqent_select_cb (GtkWidget *widget, gpointer data) { double mult; long long f; static int set = 0; - int id, b; + long long *fp; // Instead of messing with LOCALE settings, // we print a "0.0" and look what the decimal @@ -152,20 +152,9 @@ static gboolean freqent_select_cb (GtkWidget *widget, gpointer data) { f = ((long long)(atof(buffer)*mult)+5)/10; sprintf(output, "%lld", f); gtk_label_set_markup (GTK_LABEL (label), output); - id=active_receiver->id; - b = get_band_from_frequency(f); - if (b < 0) { - b=bandGen; - } - // - // If new frequency is outside of current band, - // behave as if the user had chosen the new band - // via the menu prior to changing the frequency - // - if (b != vfo[id].band) { - g_idle_add(ext_vfo_band_changed, GINT_TO_POINTER(b)); - } - setFrequency(f); + fp = malloc(sizeof(long long)); + *fp = f; + g_idle_add(ext_set_frequency, fp); g_idle_add(ext_vfo_update,NULL); set = 1; } -- 2.45.2