Skip to content

Commit

Permalink
TX audio problem solved, and "setting out-of-band frequency" fixed.
Browse files Browse the repository at this point in the history
  • Loading branch information
dl1ycf committed Dec 19, 2019
1 parent 93ac01c commit 1f7abfc
Show file tree
Hide file tree
Showing 9 changed files with 15 additions and 140 deletions.
4 changes: 3 additions & 1 deletion audio.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions band.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
1 change: 0 additions & 1 deletion ext.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
4 changes: 0 additions & 4 deletions freqent_menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,6 @@ static gboolean freqent_select_cb (GtkWidget *widget, gpointer data) {
sprintf(output, "<big>%lld</big>", 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);
Expand Down
12 changes: 7 additions & 5 deletions portaudio.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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;
}
Expand Down Expand Up @@ -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
}
Expand Down
112 changes: 0 additions & 112 deletions rigctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
Expand Down
1 change: 0 additions & 1 deletion rigctl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 0 additions & 1 deletion store_menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
19 changes: 4 additions & 15 deletions vfo_menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -152,20 +152,9 @@ static gboolean freqent_select_cb (GtkWidget *widget, gpointer data) {
f = ((long long)(atof(buffer)*mult)+5)/10;
sprintf(output, "<big>%lld</big>", 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;
}
Expand Down

0 comments on commit 1f7abfc

Please sign in to comment.