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 CEAB046DE2 for ; Wed, 12 Jul 2023 23:37:42 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id D852268C606; Thu, 13 Jul 2023 02:37:18 +0300 (EEST) Received: from relay8-d.mail.gandi.net (relay8-d.mail.gandi.net [217.70.183.201]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 41B9C68C617 for ; Thu, 13 Jul 2023 02:37:11 +0300 (EEST) Received: by mail.gandi.net (Postfix) with ESMTPSA id A2F8D1BF203 for ; Wed, 12 Jul 2023 23:37:10 +0000 (UTC) From: Michael Niedermayer To: FFmpeg development discussions and patches Date: Thu, 13 Jul 2023 01:36:56 +0200 Message-Id: <20230712233706.449054-4-michael@niedermayer.cc> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20230712233706.449054-1-michael@niedermayer.cc> References: <20230712233706.449054-1-michael@niedermayer.cc> MIME-Version: 1.0 X-GND-Sasl: michael@niedermayer.cc Subject: [FFmpeg-devel] [PATCH 04/14] avradio/sdrdemux: Compute FM station frequency more exactly 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 --- libavradio/sdrdemux.c | 35 ++++++++++++++++++++++++++++++++--- 1 file changed, 32 insertions(+), 3 deletions(-) diff --git a/libavradio/sdrdemux.c b/libavradio/sdrdemux.c index fea4202709..fd3f5dd52d 100644 --- a/libavradio/sdrdemux.c +++ b/libavradio/sdrdemux.c @@ -383,6 +383,7 @@ static int create_candidate_station(SDRContext *sdr, enum Modulation modulation, Station *station_list[1000]; double snapdistance = modulation == AM ? AM_FREQ_TOLERANCE : FM_FREQ_TOLERANCE; int nb_stations = ff_sdr_find_stations(sdr, freq, snapdistance, station_list, FF_ARRAY_ELEMS(station_list)); + int update_freq = 1; if (nb_stations) { for(int i = 1; imodulation != FM || !station->in_station_list || !sdr->demodulate_all_fm; + // We will update the frequency so we need to reinsert tree_remove(&sdr->station_root, station, station_cmp, &next); - station->frequency = station->nb_frequency * station->frequency + freq; + if (update_freq) + station->frequency = station->nb_frequency * station->frequency + freq; station->timeout = 0; } - station->frequency /= ++station->nb_frequency; + if(update_freq) + station->frequency /= ++station->nb_frequency; station->detection_per_mix_frequency[histogram_index(sdr, freq)] ++; station->modulation = modulation; @@ -934,6 +941,22 @@ static int probe_fm(SDRContext *sdr) return 0; } +static void station_update_freq(SDRContext *sdr, Station *station, double freq) +{ + struct AVTreeNode *next = NULL; + void *tmp; + + //We must reinsert the station if we change the key (frequency) + tree_remove(&sdr->station_root, station, station_cmp, &next); + + station->frequency = station->nb_frequency * station->frequency + freq; + station->frequency /= ++station->nb_frequency; + + tmp = tree_insert(&sdr->station_root, station, station_cmp, &next); + av_assert0(!tmp || tmp == station); + av_freep(&next); +} + static int demodulate_fm(SDRContext *sdr, Station *station, AVStream *st, AVPacket *pkt) { SDRStream *sst = st ? st->priv_data : NULL; @@ -953,11 +976,12 @@ static int demodulate_fm(SDRContext *sdr, Station *station, AVStream *st, AVPack int len2_4_i = 2L*sdr->fm_block_size* 2400 / sample_rate; double carrier19_i_exact; int W= 5; + double dc = 0, dcw = 0; + int len2 = FFMIN(index, 2*sdr->block_size - index); av_assert0(!st || (sst == station->stream && sst->station == station)); //If only some of the bandwidth is available, just try with less - int len2 = FFMIN(index, 2*sdr->block_size - index); if (len2 < len && len2 > len/2) len = len2; @@ -979,9 +1003,14 @@ static int demodulate_fm(SDRContext *sdr, Station *station, AVStream *st, AVPack sdr->fm_iblock[i].re = atan2(x.im * y.re - x.re * y.im, x.re * y.re + x.im * y.im) * sdr->fm_window[i]; sdr->fm_iblock[i].im = 0; + dc += sdr->fm_iblock[i].re; + dcw+= sdr->fm_window[i] * sdr->fm_window[i]; } sdr->fm_iblock[i].re = 0; sdr->fm_iblock[i].im = 0; + dc *= M_PI/2 * sqrt((2*sdr->fm_block_size - 1) / dcw); + + station_update_freq(sdr, station, freq-dc); av_assert0(sdr->fm_block_size_p2 * 2 < sdr->fm_block_size); //FIXME this only needs to be a RDFT -- 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".