diff mbox series

[FFmpeg-devel,03/18] avradio/sdr: Add fm multiple parameter

Message ID 20230708212530.109692-3-michael@niedermayer.cc
State New
Headers show
Series [FFmpeg-devel,01/18] avradio/sdrdemux: Fix uninitialized access | expand

Checks

Context Check Description
yinshiyou/configure_loongarch64 warning Failed to apply patch
andriy/configure_x86 warning Failed to apply patch

Commit Message

Michael Niedermayer July 8, 2023, 9:25 p.m. UTC
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
---
 doc/demuxers.texi     | 7 +++++++
 libavradio/sdr.h      | 1 +
 libavradio/sdrdemux.c | 9 +++++++++
 3 files changed, 17 insertions(+)
diff mbox series

Patch

diff --git a/doc/demuxers.texi b/doc/demuxers.texi
index 81c46ce08f..86f031b9ed 100644
--- a/doc/demuxers.texi
+++ b/doc/demuxers.texi
@@ -965,6 +965,13 @@  it can also result in the detection of SDR artifacts such as reflections of stro
 as weak stations. Future versions may be better able to separate weak stations from artifacts
 looking like weak stations.
 
+@item fm_multiple
+Multiple of frequency in hz at which to search for stations.
+you can set this to 100000 to probe stations at 0.1MHz increments
+Most SDR artifacts are not at exact multiplies, this is thus an effective
+way to eliminate these artifacts.
+disabled by default.
+
 @item am_mode
 AM Demodulation method. Several different methods are supported.
 @table @samp
diff --git a/libavradio/sdr.h b/libavradio/sdr.h
index 1053e45efe..ff4bfcaa1f 100644
--- a/libavradio/sdr.h
+++ b/libavradio/sdr.h
@@ -159,6 +159,7 @@  typedef struct SDRContext {
 
     float am_threshold;
     float fm_threshold;
+    float fm_multiple;
 
     pthread_t hw_thread;
     int thread_started;
diff --git a/libavradio/sdrdemux.c b/libavradio/sdrdemux.c
index 1f2d778978..13cec10505 100644
--- a/libavradio/sdrdemux.c
+++ b/libavradio/sdrdemux.c
@@ -915,6 +915,14 @@  static int probe_fm(SDRContext *sdr)
 
                     if (fabs(f2 - f) > 1000)
                         continue;
+
+                    if (sdr->fm_multiple) {
+                        double f3 = lrint(f2 / sdr->fm_multiple) * sdr->fm_multiple;
+                        if (fabs(f2 - f3) > FM_FREQ_TOLERANCE)
+                            continue;
+                        f2 = f3;
+                    }
+
                     create_candidate_station(sdr, FM, f2, bandwidth_f, bandwidth_p2, score);
                 }
             }
@@ -2169,6 +2177,7 @@  const AVOption avpriv_sdr_options[] = {
 
     { "am_threshold"     , "AM detection threshold", OFFSET(am_threshold), AV_OPT_TYPE_FLOAT, {.dbl = 20}, 0, FLT_MAX, DEC},
     { "fm_threshold"     , "FM detection threshold", OFFSET(fm_threshold), AV_OPT_TYPE_FLOAT, {.dbl = 50}, 0, FLT_MAX, DEC},
+    { "fm_multiple"      , "FM frequency mutiple",   OFFSET(fm_multiple ), AV_OPT_TYPE_FLOAT, {.dbl =  0}, 0, FLT_MAX, DEC},
 
     { NULL },
 };