From patchwork Tue Jul 4 22:23:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Niedermayer X-Patchwork-Id: 42442 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:3b1e:b0:12b:9ae3:586d with SMTP id c30csp5378379pzh; Tue, 4 Jul 2023 15:23:58 -0700 (PDT) X-Google-Smtp-Source: APBJJlGjOKJa5y1s5s6nSzPThMoCRfkpQfx/4y50sccusW6jUkRMDRYBHnz+Fo8T4FW52lyqDMBq X-Received: by 2002:a17:906:a849:b0:988:7428:2c25 with SMTP id dx9-20020a170906a84900b0098874282c25mr9932675ejb.5.1688509437811; Tue, 04 Jul 2023 15:23:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688509437; cv=none; d=google.com; s=arc-20160816; b=TwOqNWdMQeLom8eTdHMO8urhZySLHicBWzvaSJXOLdd1kriAX1BU4qMzrttAYDHHnl 15GDEQw4rGesrV5Kxz6N9F0hoa45XYHUqGTp/MBCHB+tJ4J85NiNd2LUfSUHlqGC6cHV Qq7S52MlPJjbbOEMzEuPudf6AwoIaqly5Q8g85Nyy1ci61E8uRERfIPgQeHPAso5eMae GLWh3Oax7j2lkpkhO6YVWLLzIwBAMXg9TENYTfJPzel/mBlCnvBD5jmlQIgXX/HtFzLl NlnzjV3mQtRixCPADMImcwv7NZj+47085Yky0SUbFgSbNXHyfYm7dG3MMq9owLFy6J60 +lzA== 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=eyIi0CtEgPtl/My2EbdPSzBoeYNBqE1/XW08WEqGut0=; fh=e5zN9xSzcxLA6bGo3lF+CqTbY/oLwzApV03EO/RBfgQ=; b=xUPKqSUwwxoN4NOi0mXAFiPmr2XIYah+BZ7P7FUxI72HKZlCnHUxFT7qXLNSdqiLkg KfN+x6WIWgEUUs0+M3vMb620CESDYyIiusxK/92aZnXyuz06/7UGGObWmwRTZvsbe4O9 xtSkZEK7cLTjVCV2hc3ytuGrxnHbK74K7Bae0UVSg0bbWmiPVKko3S8bCyeJKclI9i/Q ObPW9d396g88YyYXfAQ02B/J6ZAQBQATkbUe3OjmZlBrgZ/xBnSolyPQQ+QjUgOsN9N5 spVzDiSZ4+XEybhYS+DHhv3p4fny0PdXgvYTfsYBd2C4Rd1Auf17VkG8JR+qpFfwHP5U Qh8w== 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 m11-20020a1709066d0b00b00992bbdebdcasi4836195ejr.209.2023.07.04.15.23.57; Tue, 04 Jul 2023 15:23:57 -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 8704768C66A; Wed, 5 Jul 2023 01:23:17 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from relay9-d.mail.gandi.net (relay9-d.mail.gandi.net [217.70.183.199]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id D45C868C647 for ; Wed, 5 Jul 2023 01:23:10 +0300 (EEST) X-GND-Sasl: michael@niedermayer.cc Received: by mail.gandi.net (Postfix) with ESMTPSA id 1B219FF802 for ; Tue, 4 Jul 2023 22:23:09 +0000 (UTC) From: Michael Niedermayer To: FFmpeg development discussions and patches Date: Wed, 5 Jul 2023 00:23:02 +0200 Message-Id: <20230704222302.1129450-6-michael@niedermayer.cc> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20230704222302.1129450-1-michael@niedermayer.cc> References: <20230704222302.1129450-1-michael@niedermayer.cc> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 6/6] avradio/sdrdemux: slightly different normalization of FM scores 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: iDsc8+nQlHo8 This way teh scores now resemble station vs noise floor while before they where "whatever" This results in somewhat cleaner results from probing as well Signed-off-by: Michael Niedermayer --- libavradio/sdrdemux.c | 78 ++++++++++++++++++++++++------------------- 1 file changed, 43 insertions(+), 35 deletions(-) diff --git a/libavradio/sdrdemux.c b/libavradio/sdrdemux.c index 598dab8f18..d3f0368d7d 100644 --- a/libavradio/sdrdemux.c +++ b/libavradio/sdrdemux.c @@ -72,7 +72,7 @@ #define AM_MAX23 0.06 //smaller causes failure on synthetic signals #define AM_MAX4 0.02 -#define FM_THRESHOLD .8 //TODO adjust +#define FM_THRESHOLD 50 //TODO adjust //Least squares fit at 1khz points of frequency response shown by Frank McClatchie, FM SYSTEMS, INC. 800-235-6960 static double emphasis75us(int f) @@ -707,53 +707,61 @@ static int probe_fm(SDRContext *sdr) int bandwidth_f = 180*1000; int bandwidth_p2 = 38*1000; //phase 2 bandwidth int half_bw_i = bandwidth_f * (int64_t)sdr->block_size / sdr->sdr_sample_rate; - double avg[2] = {0}, tri = 0; float last_score[3] = {FLT_MAX, FLT_MAX, FLT_MAX}; int border_i = (sdr->sdr_sample_rate - sdr->bandwidth) * sdr->block_size / sdr->sdr_sample_rate; + double noise_floor = FLT_MAX; if (2*half_bw_i > 2*sdr->block_size) return 0; - for (i = 0; ilen2block[i]; - tri += i*sdr->len2block[i]; - } - for (; i<2*half_bw_i; i++) { - avg[1] += sdr->len2block[i]; - tri += (2*half_bw_i-i)*sdr->len2block[i]; - } + for (int pass = 0; pass < 2; pass ++) { + double avg[2] = {0}, tri = 0; + for (i = 0; ilen2block[i]; + tri += i*sdr->len2block[i]; + } + for (; i<2*half_bw_i; i++) { + avg[1] += sdr->len2block[i]; + tri += (2*half_bw_i-i)*sdr->len2block[i]; + } - for(i = half_bw_i; i<2*sdr->block_size - half_bw_i; i++) { - double b = avg[0] + sdr->len2block[i]; - avg[0] += sdr->len2block[i] - sdr->len2block[i - half_bw_i]; - avg[1] -= sdr->len2block[i] - sdr->len2block[i + half_bw_i]; - b += avg[1]; - tri += avg[1] - avg[0]; + for(i = half_bw_i; i<2*sdr->block_size - half_bw_i; i++) { + double b = avg[0] + sdr->len2block[i]; + avg[0] += sdr->len2block[i] - sdr->len2block[i - half_bw_i]; + avg[1] -= sdr->len2block[i] - sdr->len2block[i + half_bw_i]; + b += avg[1]; + tri += avg[1] - avg[0]; - last_score[2] = last_score[1]; - last_score[1] = last_score[0]; - last_score[0] = tri / (b * half_bw_i); - if (i < border_i || i > 2*sdr->block_size - border_i) - continue; + if (i < border_i || i > 2*sdr->block_size - border_i) + continue; - if (last_score[1] >= last_score[0] && - last_score[1] > last_score[2] && - last_score[1] > FM_THRESHOLD) { + if (pass == 0) { + noise_floor = FFMIN(noise_floor, tri); + } else { + last_score[2] = last_score[1]; + last_score[1] = last_score[0]; + last_score[0] = tri / (noise_floor); - 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); - double peak_i; + if (last_score[1] >= last_score[0] && + last_score[1] > last_score[2] && + last_score[1] > FM_THRESHOLD) { - if (lowcount / (half_bw_i*0.5) > 0.99) - continue; + 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); + double peak_i; - // as secondary check, we could check that without the center 3 samples we are still having a strong signal FIXME + if (lowcount / (half_bw_i*0.5) > 0.99) + continue; - peak_i = find_peak(sdr, last_score, 1, 3) + i - 1; - 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]); + // as secondary check, we could check that without the center 3 samples we are still having a strong signal FIXME + + peak_i = find_peak(sdr, last_score, 1, 3) + i - 1; + 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]); + } + } } }