Skip to content

Commit 3cb8bd6

Browse files
committed
rtl_fm: proportional squelch
1 parent 9ed9ffa commit 3cb8bd6

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

‎src/rtl_fm.c‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -699,6 +699,25 @@ int rms(int16_t *samples, int len, int step)
699699
return (int)sqrt((p-err) / len);
700700
}
701701

702+
int squelch_to_rms(int db, struct dongle_state *dongle, struct demod_state *demod)
703+
/* 0 dB = 1 rms at 50dB gain and 1024 downsample */
704+
{
705+
double linear, gain, downsample;
706+
if (db == 0) {
707+
return 0;}
708+
linear = pow(10.0, (double)db/20.0);
709+
gain = 50.0;
710+
if (dongle->gain != AUTO_GAIN) {
711+
gain = (double)(dongle->gain) / 10.0;
712+
}
713+
gain = 50.0 - gain;
714+
gain = pow(10.0, gain/20.0);
715+
downsample = 1024.0 / (double)demod->downsample;
716+
linear = linear / gain;
717+
linear = linear / downsample;
718+
return (int)linear + 1;
719+
}
720+
702721
void arbitrary_upsample(int16_t *buf1, int16_t *buf2, int len1, int len2)
703722
/* linear interpolation, len1 < len2 */
704723
{
@@ -964,6 +983,7 @@ static void *controller_thread_fn(void *arg)
964983

965984
/* set up primary channel */
966985
optimal_settings(s->freqs[0], demod.rate_in);
986+
demod.squelch_level = squelch_to_rms(demod.squelch_level, &dongle, &demod);
967987
if (dongle.direct_sampling) {
968988
verbose_direct_sampling(dongle.dev, dongle.direct_sampling);}
969989
if (dongle.offset_tuning) {

0 commit comments

Comments
 (0)