From patchwork Mon Jul 10 00:01:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Niedermayer X-Patchwork-Id: 42571 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:6da1:b0:131:a7d0:bc6d with SMTP id gl33csp360441pzb; Sun, 9 Jul 2023 17:01:17 -0700 (PDT) X-Google-Smtp-Source: APBJJlGRno3DbTJDtiQBFzgXinS5FIVod5FD2nTCrVhE3U4SUwu60ghTTgr5hemlMOmtZ1wc0p/z X-Received: by 2002:a2e:a314:0:b0:2b4:6d59:7863 with SMTP id l20-20020a2ea314000000b002b46d597863mr8612659lje.25.1688947277363; Sun, 09 Jul 2023 17:01:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688947277; cv=none; d=google.com; s=arc-20160816; b=D9GXQl1jPTqIB7J4ooNFYlDtKsUuIGj9pJgCeWtbyxDvvJeqlabU2RlOSg04T6dkAI yWX6cD7LFSxDp5tX5Enf+/+1vtL0vU2A/4Gm3OiHzeLC/tI0IXD3yImUE68Sdjsd4pVJ CV6IKGvBEX6NGyBhPwPFJm8A53deN3M5hd+P7P6fviT2Via0P+Cqp96dbjnMQGGgtug8 bYxHatJZMGiWBKkt05eaZPvTv+SrW74i2EvmXQAwJjjBlSMGBXORoG5hXYwTqP31GIdz 5bRz+BMgq5yTNRSpCSHU90fXlOwB2hPvnYfwP9bRWmdj5PQ2++HI7CiloBzRhmNRrSMl R+cw== 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:message-id:date:to:from :delivered-to; bh=acjA108rYhZ6REP5oPysFjoPuuZryavN8YNYtArYCsk=; fh=YYwLYmpaV0Fpw/rxmSKNRLS2XzDkAlGbHATiKOPtZrY=; b=kclBpP4C9trr7bJF1Lfs5bMshzwUO1CsXZf3ziLKOlgxKHPzeJJjrb3VvAYnCJppET ERHaTw7dbE3OcNyol+cYfCYZ02tqrd4NBp8ThGY//KLPXm5UyUSO08Xx8LSfyWF/jP7c n/FvmXZVyUzuTnseNr+qT2exMzQcyghdHrnEcSE+tKY4sz9EsApNDt/INo29C0W5kUc8 7F7qe0MJBIo4QCVKmuDqQPIoSMpbBD/NFKFgkk5NFMrn3ghmanD72AEKlxx6qiaLnYiQ lxLnAonfBa67yBUtBSLbiJ6ztRFKAW+pOhl1qzPmic0bBcrXGnzI7Dh3uS2ZLfd6sS65 l0Qg== 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 lc1-20020a170906dfe100b00992cef85664si7485849ejc.139.2023.07.09.17.01.16; Sun, 09 Jul 2023 17:01:17 -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 7919568C580; Mon, 10 Jul 2023 03:01:13 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from relay7-d.mail.gandi.net (relay7-d.mail.gandi.net [217.70.183.200]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 9795368C4CF for ; Mon, 10 Jul 2023 03:01:06 +0300 (EEST) X-GND-Sasl: michael@niedermayer.cc Received: by mail.gandi.net (Postfix) with ESMTPSA id C991920005 for ; Mon, 10 Jul 2023 00:01:05 +0000 (UTC) From: Michael Niedermayer To: FFmpeg development discussions and patches Date: Mon, 10 Jul 2023 02:01:00 +0200 Message-Id: <20230710000104.3597392-1-michael@niedermayer.cc> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 1/5] avradio/sdrdemux: Factorize synchronous_am_demodulation* functions 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: FCN6u2uyTcbN Signed-off-by: Michael Niedermayer --- libavradio/sdrdemux.c | 56 ++++++++++++++++++++----------------------- 1 file changed, 26 insertions(+), 30 deletions(-) diff --git a/libavradio/sdrdemux.c b/libavradio/sdrdemux.c index 7cc71b2cfb..92b218d899 100644 --- a/libavradio/sdrdemux.c +++ b/libavradio/sdrdemux.c @@ -616,43 +616,39 @@ static double find_am_carrier(SDRContext *sdr, const AVComplexFloat *data, int d } /** - * Demodulate with a carrier that is in the middle of the signal like in AM - * This will normalize the signal based on the carrier amplitude and subtract the carrier + * Demodulate with a carrier that is a N-th of the frequency. + * If N is one the carrier will be subtracted from the signal too. + * N==1 corresponds to classical AM, N>1 are demodulations with suppressed carriers. + * + * For N==1 and N==3 the signal will be normalized. For N==2 it will not be + * This is to avoid a sqrt() and happens to be what we want in the current use cases. + * + * The output will be scaled by the window. */ -static void synchronous_am_demodulation(AVComplexFloat *iblock, AVComplexFloat *icarrier, float *window, int len) +static av_always_inline void synchronous_am_demodulationN(AVComplexFloat *iblock, AVComplexFloat *icarrier, float *window, int len, int N) { + av_assert0(N>=1 && N<=3); //currently supported, trivial to add more if needed + for (int i = 0; i 0); + AVComplexFloat c2= {c.re*c.re, c.im*c.im}; + float den = w/(c2.re + c2.im); + + if (N==2) { + c.im *= c.re + c.re; + c.re = c2.re - c2.im; + } else if (N==3) { + den *= den; + c.re *= c2.re - 3*c2.im; + c.im *= 3*c2.re - c2.im; + } iblock[i].re = ( s.im*c.im + s.re*c.re) * den; iblock[i].im = ( s.im*c.re - s.re*c.im) * den; - iblock[i].re -= w; - } -} - -/** - * Demodulate with a carrier that is half the frequency and reduced amplitude - * This will not normalize the signal based on the carrier amplitude - */ -static void synchronous_am_demodulation2(AVComplexFloat *iblock, AVComplexFloat *icarrier, float *window, int len) -{ - for (int i = 0; i 0); - - c2.re = c.re*c.re - c.im*c.im; - c2.im = c.re*c.im + c.im*c.re; - - iblock[i].re = ( s.im*c2.im + s.re*c2.re) * den; - iblock[i].im = ( s.im*c2.re - s.re*c2.im) * den; + if (N==1) + iblock[i].re -= w; } } @@ -728,7 +724,7 @@ static int demodulate_am(SDRContext *sdr, int stream_index, AVPacket *pkt) sst->block[i] = sdr->block[index + i - len]; sst->ifft(sst->ifft_ctx, sst->icarrier, sst->block, sizeof(AVComplexFloat)); - synchronous_am_demodulation(sst->iblock, sst->icarrier, sst->window, 2*sst->block_size); + synchronous_am_demodulationN(sst->iblock, sst->icarrier, sst->window, 2*sst->block_size, 1); scale = 0.9; } else { // Synchronous demodulation using Macleod based systhesized carrier @@ -997,7 +993,7 @@ static int demodulate_fm(SDRContext *sdr, int stream_index, AVPacket *pkt) apply_deemphasis(sdr, sst->block + i + 2*carrier19_i - 2*shift, sst->block_size_p2, sample_rate_p2, + 1); apply_deemphasis(sdr, sst->block + i + 2*carrier19_i - 2*shift, sst->block_size_p2, sample_rate_p2, - 1); sst->ifft_p2(sst->ifft_p2_ctx, sst->iside , sst->block + i, sizeof(AVComplexFloat)); - synchronous_am_demodulation2(sst->iside, sst->icarrier, sst->window_p2, 2*sst->block_size_p2); + synchronous_am_demodulationN(sst->iside, sst->icarrier, sst->window_p2, 2*sst->block_size_p2, 2); } memset(sst->block + len17_i, 0, (2*sst->block_size_p2 - len17_i) * sizeof(AVComplexFloat)); apply_deemphasis(sdr, sst->block, 2*sst->block_size_p2, sample_rate_p2, + 1);