diff mbox series

[FFmpeg-devel,04/14] avradio/sdrdemux: snap2station() should look only at the vissible window

Message ID 20230718214542.685375-4-michael@niedermayer.cc
State New
Headers show
Series [FFmpeg-devel,01/14] avradio/sdrdemux: Add Mittelwelle / Mediumwave / Mediumfrequency band | expand

Checks

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

Commit Message

Michael Niedermayer July 18, 2023, 9:45 p.m. UTC
Otherwise we can skip over areas not leaving time to scan them

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

Patch

diff --git a/libavradio/sdrdemux.c b/libavradio/sdrdemux.c
index ca0a9c5cf9..f189c85a0d 100644
--- a/libavradio/sdrdemux.c
+++ b/libavradio/sdrdemux.c
@@ -1291,11 +1291,11 @@  static int snap2station(SDRContext *sdr, int *seek_direction) {
     AVFormatContext *avfmt = sdr->avfmt;
     AVStream *st = avfmt->streams[sdr->single_ch_audio_st_index];
     SDRStream *sst = st->priv_data;
-    double current_freq;
+    double current_freq, current_view;
     double best_distance = INT64_MAX;
     Station *best_station = NULL;
     Station *station_list[MAX_STATIONS];
-    int nb_stations = ff_sdr_find_stations(sdr, sdr->block_center_freq, sdr->sdr_sample_rate*0.5, station_list, FF_ARRAY_ELEMS(station_list));
+    int nb_stations;
 
     if (sst->station) {
         current_freq = sst->station->frequency;
@@ -1304,6 +1304,15 @@  static int snap2station(SDRContext *sdr, int *seek_direction) {
     } else
         current_freq = sdr->block_center_freq;
 
+    if (sdr->block_center_freq) {
+        current_view = sdr->block_center_freq;
+    } else if (sst->station) {
+        current_view = sst->station->frequency;
+    } else
+        current_view = sdr->station_freq;
+
+    nb_stations = ff_sdr_find_stations(sdr, current_view, sdr->sdr_sample_rate*0.5, station_list, FF_ARRAY_ELEMS(station_list));
+
     for(int i = 0; i<nb_stations; i++) {
         Station *station = station_list[i];
         double distance = station->frequency - current_freq;