From: Michael Niedermayer <michael@niedermayer.cc> To: FFmpeg development discussions and patches <ffmpeg-devel@ffmpeg.org> Subject: [FFmpeg-devel] [PATCH 5/9] avradio/sdr: Allow user to adjust FM/AM thresholds Date: Fri, 7 Jul 2023 19:22:20 +0200 Message-ID: <20230707172224.2368067-5-michael@niedermayer.cc> (raw) In-Reply-To: <20230707172224.2368067-1-michael@niedermayer.cc> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc> --- 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".
next prev parent reply other threads:[~2023-07-07 17:23 UTC|newest] Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top 2023-07-07 17:22 [FFmpeg-devel] [PATCH 1/9] avradio/sdr: use AVTree for candidate stations Michael Niedermayer 2023-07-07 17:22 ` [FFmpeg-devel] [PATCH 2/9] avradio/sdr: Consolidate candidate station entries Michael Niedermayer 2023-07-07 17:22 ` [FFmpeg-devel] [PATCH 3/9] avradio/sdr: consolidate the candidate station list with the main list Michael Niedermayer 2023-07-07 17:22 ` [FFmpeg-devel] [PATCH 4/9] avradio/sdr: Eliminate station list Michael Niedermayer 2023-07-07 17:22 ` Michael Niedermayer [this message] 2023-07-07 17:22 ` [FFmpeg-devel] [PATCH 6/9] avradio/sdrdemux: count timeout irrespective of a station being active Michael Niedermayer 2023-07-07 17:22 ` [FFmpeg-devel] [PATCH 7/9] avradio/sdr: Compute and use detection histogram Michael Niedermayer 2023-07-07 17:22 ` [FFmpeg-devel] [PATCH 8/9] avradio/sdrdemux: increase the FM station frequency tolerance Michael Niedermayer 2023-07-07 17:22 ` [FFmpeg-devel] [PATCH 9/9] avradio/sdrdemux: Use 2 differnt FM station detectors Michael Niedermayer 2023-07-08 15:42 ` [FFmpeg-devel] [PATCH 1/9] avradio/sdr: use AVTree for candidate stations Michael Niedermayer
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20230707172224.2368067-5-michael@niedermayer.cc \ --to=michael@niedermayer.cc \ --cc=ffmpeg-devel@ffmpeg.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel This inbox may be cloned and mirrored by anyone: git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git # If you have public-inbox 1.1+ installed, you may # initialize and index your mirror using the following commands: public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \ ffmpegdev@gitmailbox.com public-inbox-index ffmpegdev Example config snippet for mirrors. AGPL code for this site: git clone https://public-inbox.org/public-inbox.git