From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id AE5E946CE0 for ; Fri, 7 Jul 2023 17:23:30 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id F20BE68C83F; Fri, 7 Jul 2023 20:22:42 +0300 (EEST) Received: from relay5-d.mail.gandi.net (relay5-d.mail.gandi.net [217.70.183.197]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 4D33868C7ED for ; Fri, 7 Jul 2023 20:22:34 +0300 (EEST) X-GND-Sasl: michael@niedermayer.cc Received: by mail.gandi.net (Postfix) with ESMTPSA id B5A391C0005 for ; Fri, 7 Jul 2023 17:22:33 +0000 (UTC) From: Michael Niedermayer To: FFmpeg development discussions and patches Date: Fri, 7 Jul 2023 19:22:22 +0200 Message-Id: <20230707172224.2368067-7-michael@niedermayer.cc> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20230707172224.2368067-1-michael@niedermayer.cc> References: <20230707172224.2368067-1-michael@niedermayer.cc> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 7/9] avradio/sdr: Compute and use detection histogram X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: By analyzing the behavior of the detectability of stations with different SDR settings we can separate some SDR artifacts from weak stations. Signed-off-by: Michael Niedermayer --- libavradio/sdr.h | 5 +++++ libavradio/sdrdemux.c | 36 +++++++++++++++++++++++++++++++++++- 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/libavradio/sdr.h b/libavradio/sdr.h index 838fb1cef7..1053e45efe 100644 --- a/libavradio/sdr.h +++ b/libavradio/sdr.h @@ -66,6 +66,8 @@ typedef enum Modulation { //QAM, PSK, ... } Modulation; +#define HISTOGRAMM_SIZE 9 + typedef struct Station { char *name; enum Modulation modulation; @@ -78,6 +80,9 @@ typedef struct Station { int timeout; //since how many blocks was this detectable but not detected int multiplex_index; //DAB can have multiple stations on one frequency + int detection_per_mix_frequency[HISTOGRAMM_SIZE]; + int non_detection_per_mix_frequency[HISTOGRAMM_SIZE]; + struct SDRStream *stream; } Station; diff --git a/libavradio/sdrdemux.c b/libavradio/sdrdemux.c index 6cb9d3b70a..1fc528317c 100644 --- a/libavradio/sdrdemux.c +++ b/libavradio/sdrdemux.c @@ -111,6 +111,23 @@ static void free_station(Station *station) av_free(station); } +static inline int histogram_index(SDRContext *sdr, double f) +{ + f = HISTOGRAMM_SIZE*((f - sdr->block_center_freq) / sdr->sdr_sample_rate + 0.5); + return av_clip((int)f, 0, HISTOGRAMM_SIZE-1); +} + +static int histogram_score(Station *s) +{ + int score = 0; + for(int i = 0; idetection_per_mix_frequency[i] > s->non_detection_per_mix_frequency[i]) + -(5*s->detection_per_mix_frequency[i] < s->non_detection_per_mix_frequency[i]); + } + return score; +} + typedef struct FindStationContext { double freq; double range; @@ -184,6 +201,10 @@ static int create_station(SDRContext *sdr, Station *candidate_station) { if (candidate_station->in_station_list) return 0; + // suspect looking histogram + if (histogram_score(candidate_station) <= 0) + return 0; + Station *station_list[1000]; int nb_stations = find_stations(sdr, sdr->block_center_freq, sdr->sdr_sample_rate*0.5, station_list, FF_ARRAY_ELEMS(station_list)); for (i=0; ifrequency + station->bandwidth/2 > sdr->block_center_freq + sdr->bandwidth/2) continue; + if (station->timeout) + station->non_detection_per_mix_frequency[histogram_index(sdr, station->frequency)] ++; + if (station->in_station_list) { - if (station->timeout++ > STATION_TIMEOUT) { + int station_timeout = STATION_TIMEOUT; + int hs = histogram_score(station); + + if (hs == 0) { + station_timeout = 5; //give the station a moment to be properly detected and then discard it + } else if(hs < 0) { + station_timeout = 0; //probably not a station + } + + if (station->timeout++ > station_timeout) { if (!station->stream) station->in_station_list = 0; } @@ -376,6 +409,7 @@ static int create_candidate_station(SDRContext *sdr, enum Modulation modulation, } station->frequency /= ++station->nb_frequency; + station->detection_per_mix_frequency[histogram_index(sdr, freq)] ++; station->modulation = modulation; station->bandwidth = bandwidth; station->bandwidth_p2 = bandwidth_p2; -- 2.31.1 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".