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 3724846CE3 for ; Fri, 7 Jul 2023 17:23:13 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id E358A68C7BE; Fri, 7 Jul 2023 20:22:39 +0300 (EEST) Received: from relay4-d.mail.gandi.net (relay4-d.mail.gandi.net [217.70.183.196]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id A3BDF68C7D6 for ; Fri, 7 Jul 2023 20:22:32 +0300 (EEST) X-GND-Sasl: michael@niedermayer.cc Received: by mail.gandi.net (Postfix) with ESMTPSA id DC447E0004 for ; Fri, 7 Jul 2023 17:22:31 +0000 (UTC) From: Michael Niedermayer To: FFmpeg development discussions and patches Date: Fri, 7 Jul 2023 19:22:20 +0200 Message-Id: <20230707172224.2368067-5-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 5/9] avradio/sdr: Allow user to adjust FM/AM thresholds 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: Signed-off-by: Michael Niedermayer --- doc/demuxers.texi | 9 +++++++++ libavradio/sdr.h | 3 +++ libavradio/sdrdemux.c | 18 +++++++----------- 3 files changed, 19 insertions(+), 11 deletions(-) diff --git a/doc/demuxers.texi b/doc/demuxers.texi index fc2ab9fc27..81c46ce08f 100644 --- a/doc/demuxers.texi +++ b/doc/demuxers.texi @@ -956,6 +956,15 @@ for debuging. @item kbd_alpha Kaiser Bessel derived window parameter +@item am_threshold +AM station detection threshold + +@item fm_threshold +FM station detection threshold, a lower value allows detection of weaker stations but +it can also result in the detection of SDR artifacts such as reflections of strong FM stations +as weak stations. Future versions may be better able to separate weak stations from artifacts +looking like weak stations. + @item am_mode AM Demodulation method. Several different methods are supported. @table @samp diff --git a/libavradio/sdr.h b/libavradio/sdr.h index 00066850f9..838fb1cef7 100644 --- a/libavradio/sdr.h +++ b/libavradio/sdr.h @@ -152,6 +152,9 @@ typedef struct SDRContext { int emphasis_mode; int am_fft_ref; + float am_threshold; + float fm_threshold; + pthread_t hw_thread; int thread_started; pthread_mutex_t mutex; ///< Mutex to protect common variable between mainthread and hw_thread, and also to protect soapy from concurrent calls diff --git a/libavradio/sdrdemux.c b/libavradio/sdrdemux.c index 769cf3ade6..ad3e253ced 100644 --- a/libavradio/sdrdemux.c +++ b/libavradio/sdrdemux.c @@ -64,17 +64,9 @@ #define STATION_TIMEOUT 100 ///< The number of frames after which a station is removed if it was not detected #define CANDIDATE_STATION_TIMEOUT 4 -/* - * 100 detects nothing - * 50 detects a good bit but not all - */ -#define AM_THRESHOLD 20 - #define AM_MAX23 0.06 //smaller causes failure on synthetic signals #define AM_MAX4 0.02 -#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) { @@ -529,7 +521,7 @@ static int probe_am(SDRContext *sdr) continue; //TODO also check for symmetry in the spectrum - if (mid > 0 && score > AM_THRESHOLD && + if (mid > 0 && score > sdr->am_threshold && sdr->len2block[i - 1] < mid && sdr->len2block[i + 1] <= mid && sdr->len2block[i - 2] < mid*AM_MAX23 && sdr->len2block[i + 2] < mid*AM_MAX23 && sdr->len2block[i - 3] < mid*AM_MAX23 && sdr->len2block[i + 3] < mid*AM_MAX23 @@ -583,7 +575,7 @@ static double find_am_carrier(SDRContext *sdr, const AVComplexFloat *data, int d avg += len2block[i + index]; score = len * mid / (avg - mid); //find optimal frequency for this block if we have a carrier - if (score > AM_THRESHOLD / 4) { + if (score > sdr->am_threshold / 4) { double peak_i = find_peak_macleod(sdr, data, i_max, data_len, NULL); if (peak_i < 0) return peak_i; @@ -858,7 +850,7 @@ static int probe_fm(SDRContext *sdr) if (last_score[1] >= last_score[0] && last_score[1] > last_score[2] && - last_score[1] > FM_THRESHOLD) { + last_score[1] > sdr->fm_threshold) { 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); @@ -2122,6 +2114,10 @@ const AVOption avpriv_sdr_options[] = { { "emphasis75us", "FM De-Emphasis 75us", 0, AV_OPT_TYPE_CONST, {.i64 = EMPHASIS_75us}, 0, 0, DEC, "fm_emphasis"}, { "emphasis50us", "FM De-Emphasis 50us", 0, AV_OPT_TYPE_CONST, {.i64 = EMPHASIS_50us}, 0, 0, DEC, "fm_emphasis"}, { "none" , "No FM De-Emphasis" , 0, AV_OPT_TYPE_CONST, {.i64 = EMPHASIS_NONE}, 0, 0, DEC, "fm_emphasis"}, + + { "am_threshold" , "AM detection threshold", OFFSET(am_threshold), AV_OPT_TYPE_FLOAT, {.dbl = 20}, 0, FLT_MAX, DEC}, + { "fm_threshold" , "FM detection threshold", OFFSET(fm_threshold), AV_OPT_TYPE_FLOAT, {.dbl = 50}, 0, FLT_MAX, DEC}, + { NULL }, }; -- 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".