Added a squelch
This commit is contained in:
parent
43e554da37
commit
4230198d91
4 changed files with 335 additions and 256 deletions
|
@ -387,6 +387,10 @@ It doubles every input sample.
|
|||
|
||||
See the [buffer sizes](#buffer_sizes) section.
|
||||
|
||||
squelch_and_smeter_cc --fifo <squelch_fifo> --outfifo <smeter_fifo> <use_every_nth> <report_every_nth>
|
||||
|
||||
This is a controllable squelch, which reads the squelch level input from `<squelch_fifo>` and writes the power level output to `<smeter_fifo>`. Both input and output are in the format of `%g\n`. While calculating the power level, it takes only every `<use_every_nth>` sample into consideration. It writes the S-meter value for every `<report_every_nth>` buffer to `<smeter_fifo>`. If the squelch level is set to 0, it it forces the squelch to be open. If the squelch is closed, it fills the output with zero.
|
||||
|
||||
#### Control via pipes
|
||||
|
||||
Some parameters can be changed while the `csdr` process is running. To achieve this, some `csdr` functions have special parameters. You have to supply a fifo previously created by the `mkfifo` command. Processing will only start after the first control command has been received by `csdr` over the FIFO.
|
||||
|
|
59
csdr.c
59
csdr.c
|
@ -71,7 +71,9 @@ char usage[]=
|
|||
" floatdump_f\n"
|
||||
" flowcontrol <data_rate> <reads_per_second> [prebuffer_sec] [thrust]\n"
|
||||
" shift_math_cc <rate>\n"
|
||||
" shift_math_cc --fifo <fifo_path>\n"
|
||||
" shift_addition_cc <rate>\n"
|
||||
" shift_addition_cc --fifo <fifo_path>\n"
|
||||
" shift_addition_cc_test\n"
|
||||
" shift_table_cc <rate> [table_size]\n"
|
||||
" decimating_shift_addition_cc <rate> [decimation]\n"
|
||||
|
@ -95,6 +97,7 @@ char usage[]=
|
|||
" logpower_cf [add_db]\n"
|
||||
" fft_benchmark <fft_size> <fft_cycles> [--benchmark]\n"
|
||||
" bandpass_fir_fft_cc <low_cut> <high_cut> <transition_bw> [window]\n"
|
||||
" bandpass_fir_fft_cc --fifo <fifo_path> <transition_bw> [window]\n"
|
||||
" encode_ima_adpcm_s16_u8\n"
|
||||
" decode_ima_adpcm_u8_s16\n"
|
||||
" compress_fft_adpcm_f_u8 <fft_size>\n"
|
||||
|
@ -107,6 +110,7 @@ char usage[]=
|
|||
" monos2stereo_s16\n"
|
||||
" setbuf <buffer_size>\n"
|
||||
" fft_exchange_sides_ff <fft_size>\n"
|
||||
" squelch_and_smeter_cc --fifo <squelch_fifo> --outfifo <smeter_fifo> <use_every_nth> <report_every_nth>\n"
|
||||
" \n"
|
||||
;
|
||||
|
||||
|
@ -1681,6 +1685,59 @@ int main(int argc, char *argv[])
|
|||
}
|
||||
}
|
||||
|
||||
if(!strcmp(argv[1],"squelch_and_smeter_cc"))
|
||||
{
|
||||
if(!sendbufsize(initialize_buffers())) return -2;
|
||||
float power;
|
||||
float squelch_level;
|
||||
int decimation;
|
||||
int report_every_nth;
|
||||
int fd;
|
||||
char power_value_buf[101];
|
||||
int power_value_buf_size;
|
||||
int report_cntr=0;
|
||||
complexf* zerobuf = (complexf*)malloc(sizeof(complexf)*the_bufsize);
|
||||
for(int i=0;i<the_bufsize*2;i++) *(((float*)zerobuf)+i)=0;
|
||||
if(fd=init_fifo(argc,argv)) while(!read_fifo_ctl(fd,"%g\n",&squelch_level)) usleep(10000);
|
||||
else return badsyntax("need required parameter (--fifo <fifo>)");
|
||||
fprintf(stderr, "squelch_and_power_cc: initial squelch level is %g\n", squelch_level);
|
||||
if((argc<=5)||((argc>5)&&(strcmp(argv[4],"--outfifo")))) return badsyntax("need required parameter (--outfifo <fifo>)");
|
||||
int fd2 = open(argv[5], O_WRONLY);
|
||||
if(fd2==-1) return badsyntax("error while opening --outfifo");
|
||||
int flags = fcntl(fd2, F_GETFL, 0);
|
||||
fcntl(fd2, F_SETFL, flags | O_NONBLOCK);
|
||||
if(argc<=6) return badsyntax("need required parameter (use_every_nth)");
|
||||
sscanf(argv[6],"%d",&decimation);
|
||||
if(decimation<=0) return badsyntax("use_every_nth <= 0 is invalid");
|
||||
if(argc<=7) return badsyntax("need required parameter (report_every_nth)");
|
||||
sscanf(argv[7],"%d",&report_every_nth);
|
||||
if(report_every_nth<=0) return badsyntax("report_every_nth <= 0 is invalid");
|
||||
for(;;)
|
||||
{
|
||||
FEOF_CHECK;
|
||||
FREAD_C; //read input data
|
||||
power = get_power_c((complexf*)input_buffer, the_bufsize, decimation);
|
||||
if(report_cntr++>report_every_nth)
|
||||
{
|
||||
report_cntr=0;
|
||||
power_value_buf_size=snprintf(power_value_buf,100,"%g\n",power);
|
||||
write(fd2,power_value_buf,power_value_buf_size*sizeof(char));
|
||||
}
|
||||
if(squelch_level==0||power>=squelch_level)
|
||||
{
|
||||
//fprintf(stderr,"P");
|
||||
fwrite(input_buffer, sizeof(complexf), the_bufsize, stdout);
|
||||
}
|
||||
else
|
||||
{
|
||||
//fprintf(stderr,"S");
|
||||
fwrite(zerobuf, sizeof(complexf), the_bufsize, stdout);
|
||||
}
|
||||
if(read_fifo_ctl(fd,"%g\n",&squelch_level)) fprintf(stderr, "squelch_and_power_cc: new squelch level is %g\n", squelch_level);
|
||||
TRY_YIELD;
|
||||
}
|
||||
}
|
||||
|
||||
if(!strcmp(argv[1],"none"))
|
||||
{
|
||||
return 0;
|
||||
|
@ -1689,5 +1746,3 @@ int main(int argc, char *argv[])
|
|||
return badsyntax("function name given in argument 1 does not exist. Possible causes:\n- You mistyped the commandline.\n- You need to update csdr to a newer version (if available).");
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
22
libcsdr.c
22
libcsdr.c
|
@ -818,6 +818,26 @@ void gain_ff(float* input, float* output, int input_size, float gain)
|
|||
for(int i=0;i<input_size;i++) output[i]=gain*input[i]; //@gain_ff
|
||||
}
|
||||
|
||||
float get_power_f(float* input, int input_size, int decimation)
|
||||
{
|
||||
float acc = 0;
|
||||
for(int i=0;i<input_size;i+=decimation)
|
||||
{
|
||||
acc += (input[i]*input[i])/input_size;
|
||||
}
|
||||
return acc;
|
||||
}
|
||||
|
||||
float get_power_c(complexf* input, int input_size, int decimation)
|
||||
{
|
||||
float acc = 0;
|
||||
for(int i=0;i<input_size;i+=decimation)
|
||||
{
|
||||
acc += (iof(input,i)*iof(input,i)+qof(input,i)*qof(input,i))/input_size;
|
||||
}
|
||||
return acc;
|
||||
}
|
||||
|
||||
/*
|
||||
__ __ _ _ _
|
||||
| \/ | | | | | | |
|
||||
|
@ -989,5 +1009,3 @@ int trivial_vectorize()
|
|||
}
|
||||
return c[0];
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -161,6 +161,8 @@ int log2n(int x);
|
|||
int next_pow2(int x);
|
||||
void apply_fir_fft_cc(FFT_PLAN_T* plan, FFT_PLAN_T* plan_inverse, complexf* taps_fft, complexf* last_overlap, int overlap_size);
|
||||
void gain_ff(float* input, float* output, int input_size, float gain);
|
||||
float get_power_f(float* input, int input_size, int decimation);
|
||||
float get_power_c(complexf* input, int input_size, int decimation);
|
||||
|
||||
void add_dcoffset_cc(complexf* input, complexf* output, int input_size);
|
||||
float fmmod_fc(float* input, complexf* output, int input_size, float last_phase);
|
||||
|
|
Loading…
Reference in a new issue