From patchwork Fri Jul 7 17:22:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Niedermayer X-Patchwork-Id: 42525 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:3b1e:b0:12b:9ae3:586d with SMTP id c30csp7450208pzh; Fri, 7 Jul 2023 10:23:33 -0700 (PDT) X-Google-Smtp-Source: APBJJlHkkxcgVmj5qA9OmtudrkMlUktURqn+S6RO+M4xREQMfGQHXWWCbvhwtSHZ6v4HZ3YmsTV+ X-Received: by 2002:a2e:964a:0:b0:2b7:310:65da with SMTP id z10-20020a2e964a000000b002b7031065damr794763ljh.24.1688750613473; Fri, 07 Jul 2023 10:23:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688750613; cv=none; d=google.com; s=arc-20160816; b=uaiqzeR1qLKx9FtJq4maSKs5G3sMMRhZ6u2kVhqylX2r7X2Ga+nLE2K7Hi6I1kyzyX xhT6AxiVe+TB5GUsOHRMZu2jy2HYOJHvQPU92pz/nooYAAE9AnwZZ34InljmA2wFnQCG pdjLQ3ru7IkxJDpICfKN9sa0HyP34aqEMLnchNmqIkfjylLm14f1KybQ7NCsFfUqDN8C Lu6tlOCN3Leo67Rw5eMkscRMkKd9s8cJJ5fxpvpmkydfCHDzEcejXxgEO1wZyhv5Wg4V sJJ3fFpwyiGU7McmCL3BAtO8+EQJxi26+N9mEKgDuZvsWhZyAzEwfqKl2yVTcuMCif9O puTA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:reply-to:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:mime-version:references:in-reply-to:message-id :date:to:from:delivered-to; bh=lqTmIgJj8HHgsZguCZaA27+sDS+FRvDWrz2tsKxpxms=; fh=YYwLYmpaV0Fpw/rxmSKNRLS2XzDkAlGbHATiKOPtZrY=; b=bIwYhhA5VyM2mH0uEhqYF93Q6vh5KTmfX+jiFY0kKBemjYmGcHpYBH1qGvFzWFvHJ2 zkrWnPcuQ/BrZjAHRosFYLIdUJOxzcA+IWf5YP/jptWWAvjJ0+vgJhW6Lg/5xOvDz8sD ugr1teIjaZVrO0+HwNy2YklpJw5Ali6O4IheA378bi5i8IkJT+rcfZARZ0d17CUMFFfj LtNkcBMkznTVYtFxT1pBE6lQpFolvXSwYCUqjxxVWpKy+0TVOFsW2j6Qq5RR3GLtJWME Bk8KvHxghHtk+vbYt4gTm2lDwaNVe/SzvMUboyQnXXrVTKCjNJdF6ycvQAn5i6Kp9bMH LKpQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id jp19-20020a170906f75300b00992ca771e71si602812ejb.138.2023.07.07.10.23.32; Fri, 07 Jul 2023 10:23:33 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 303B168C7DA; Fri, 7 Jul 2023 20:22:43 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: I1Z9Lo1V6VdI 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;