diff mbox series

[FFmpeg-devel,9/9] avradio/sdrdemux: Use 2 differnt FM station detectors

Message ID 20230707172224.2368067-9-michael@niedermayer.cc
State New
Headers show
Series [FFmpeg-devel,1/9] avradio/sdr: use AVTree for candidate stations | 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 7, 2023, 5:22 p.m. UTC
Detect station if both lie within 1kHz of each other
This eliminates some artifacts being detected

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
---
 libavradio/sdrdemux.c | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/libavradio/sdrdemux.c b/libavradio/sdrdemux.c
index 4c1ec7b51c..bed74ebd26 100644
--- a/libavradio/sdrdemux.c
+++ b/libavradio/sdrdemux.c
@@ -855,13 +855,17 @@  static int probe_fm(SDRContext *sdr)
 
     for (int pass = 0; pass < 2; pass ++) {
         double avg[2] = {0}, tri = 0;
+        double mean = 0;
+        double center = 0;
         for (i = 0; i<half_bw_i; i++) {
             avg[0] += sdr->len2block[i];
             tri    += i*sdr->len2block[i];
         }
+        mean = tri;
         for (; i<2*half_bw_i; i++) {
             avg[1] += sdr->len2block[i];
             tri    += (2*half_bw_i-i)*sdr->len2block[i];
+            mean   += i*sdr->len2block[i];
         }
 
         for(i = half_bw_i; i<2*sdr->block_size - half_bw_i; i++) {
@@ -871,6 +875,10 @@  static int probe_fm(SDRContext *sdr)
             b += avg[1];
             tri += avg[1] - avg[0];
 
+            mean += (i+half_bw_i)*sdr->len2block[i+half_bw_i];
+            center = mean / b;
+            mean -= (i-half_bw_i)*sdr->len2block[i-half_bw_i];
+
             if (i < border_i || i > 2*sdr->block_size - border_i)
                 continue;
 
@@ -884,6 +892,7 @@  static int probe_fm(SDRContext *sdr)
                 if (last_score[1] >= last_score[0] &&
                     last_score[1] > last_score[2] &&
                     last_score[1] > sdr->fm_threshold) {
+                    double score = last_score[1];
 
                     float rmax   = max_in_range(sdr, i-half_bw_i/4, i+half_bw_i/4);
                     int lowcount = countbelow(sdr, i-half_bw_i/4, i+half_bw_i/4, rmax / 100);
@@ -898,7 +907,12 @@  static int probe_fm(SDRContext *sdr)
                     if (peak_i < 0)
                         continue;
                     av_assert0(fabs(peak_i-i) < 2);
-                    create_candidate_station(sdr, FM, peak_i * 0.5 * sdr->sdr_sample_rate / sdr->block_size + sdr->block_center_freq - sdr->sdr_sample_rate/2, bandwidth_f, bandwidth_p2, last_score[1]);
+                    double f = peak_i * 0.5 * sdr->sdr_sample_rate / sdr->block_size + sdr->block_center_freq - sdr->sdr_sample_rate/2;
+                    double f2 = center * 0.5 * sdr->sdr_sample_rate / sdr->block_size + sdr->block_center_freq - sdr->sdr_sample_rate/2;
+
+                    if (fabs(f2 - f) > 1000)
+                        continue;
+                    create_candidate_station(sdr, FM, f2, bandwidth_f, bandwidth_p2, score);
                 }
             }
         }