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 DBFC2406EC for ; Sat, 29 Jan 2022 01:08:58 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 9C0C768B158; Sat, 29 Jan 2022 03:08:55 +0200 (EET) Received: from mail-pj1-f52.google.com (mail-pj1-f52.google.com [209.85.216.52]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 3836668A948 for ; Sat, 29 Jan 2022 03:08:49 +0200 (EET) Received: by mail-pj1-f52.google.com with SMTP id h12so8087168pjq.3 for ; Fri, 28 Jan 2022 17:08:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=smhFGe8H+5tdEangudZuGU0xgQwft4VztE85t9GxTRo=; b=gLo8tpXZvNw5dYzxvoxoayh3qP8P0lGRjH0m2zM+Mausftq7bZ4G9weqi9EkSoCdc5 Albf0dqRjbvxhsK59BV2a7WYqM7EG5Pzu7yMPzQt5CIsF92UJtrOKUvbj1KbqAL4kSUE k2M2RCODSN81vz+LDWqRx8X2GJEGCQ5Qn0bNb1Cw8dRQggxZNlgdphdLQIzCzrL7zHya mmtXJdSl5d5tn5uPdkrmeV/M6p9zhI0QkJ5SyaJiHlq6qCtFMazWoZbSvIgCFHedTk/u Hwci1lX216HodZmkTa191qODaIQ4OCqjaWKOENdHdOcNXpTJbUREdwphQx68Uc3OT49H adog== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=smhFGe8H+5tdEangudZuGU0xgQwft4VztE85t9GxTRo=; b=mR3o4LOzV9JpCkbIDb6eIs8oAP91PxnuktKDYwgZ7GUNmlaxyeON1fsnGkVzYrt0J8 NdpCKFgud8PM2KRqFTbpgCyR+G7m4P4pkn4yG5hBNqb2Qq31c9OjMjQ334KbVVWjUpAl NARbFE3Hm9k09na65h5yWo1mE6NSHWIUAcNMREyKYQz6DNxjn6UI0kxVdmWTVmOQeJ5l zunZxOR/78f2Tb8JyX1ZceB+jdepiQK+Z8ozLP+ADDMhQZnSdLCkzl3hlToC7flbv7FU saf4fCWCTAE5KMLXRAeRqCsEZpk8QVkpiigSJRkrGksYR7IGlivDx47AgyeB+6yAIMvJ jIwA== X-Gm-Message-State: AOAM53048bcfXEjPxDISjGDs0e+pM3x/3GkpzsFh24iA5C8zxHRoEYF6 V20F5UfTklFnRP+1K8Oys/RpdNF9lfN0fQ== X-Google-Smtp-Source: ABdhPJy8Ecl2428VoTWjugLMsJQb9CsCXqNhBcPiuV76QDGI82PbvAqECCug1aRT9LXNr9XqGyv0Zw== X-Received: by 2002:a17:90b:4ad0:: with SMTP id mh16mr21673179pjb.89.1643418526879; Fri, 28 Jan 2022 17:08:46 -0800 (PST) Received: from ryzen-archlinux.localdomain (node-1w7jr9quwtshe9pluzzjlv6my.ipv6.telus.net. [2001:569:7da8:e800:e2d5:5eff:fe8e:845a]) by smtp.googlemail.com with ESMTPSA id j2sm8123097pfc.209.2022.01.28.17.08.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 28 Jan 2022 17:08:46 -0800 (PST) From: Jason Jang To: ffmpeg-devel@ffmpeg.org Date: Fri, 28 Jan 2022 17:08:27 -0800 Message-Id: <20220129010827.307903-1-jcj83429@gmail.com> X-Mailer: git-send-email 2.35.0 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 1/3] avfilter/af_apsyclip: fix FFT bin indexing 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 Cc: Jason Jang 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: With a complex FFT instead of real FFT, the negative frequencies are not dropped from the spectrum output, so they need to be scaled when the positive frequencies are scaled. The location of the top bin is also different. Signed-off-by: Jason Jang --- libavfilter/af_apsyclip.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/libavfilter/af_apsyclip.c b/libavfilter/af_apsyclip.c index dc3a8e9..0bc469c 100644 --- a/libavfilter/af_apsyclip.c +++ b/libavfilter/af_apsyclip.c @@ -292,10 +292,9 @@ static void calculate_mask_curve(AudioPsyClipContext *s, if (i == 0) { magnitude = FFABS(spectrum[0]); } else if (i == s->fft_size / 2) { - magnitude = FFABS(spectrum[1]); + magnitude = FFABS(spectrum[s->fft_size]); } else { - // although the negative frequencies are omitted because they are redundant, - // the magnitude of the positive frequencies are not doubled. + // Because the input signal is real, the + and - frequencies are redundant. // Multiply the magnitude by 2 to simulate adding up the + and - frequencies. magnitude = hypotf(spectrum[2 * i], spectrum[2 * i + 1]) * 2; } @@ -315,10 +314,9 @@ static void calculate_mask_curve(AudioPsyClipContext *s, for (int i = s->num_psy_bins; i < s->fft_size / 2 + 1; i++) { float magnitude; if (i == s->fft_size / 2) { - magnitude = FFABS(spectrum[1]); + magnitude = FFABS(spectrum[s->fft_size]); } else { - // although the negative frequencies are omitted because they are redundant, - // the magnitude of the positive frequencies are not doubled. + // Because the input signal is real, the + and - frequencies are redundant. // Multiply the magnitude by 2 to simulate adding up the + and - frequencies. magnitude = hypotf(spectrum[2 * i], spectrum[2 * i + 1]) * 2; } @@ -360,19 +358,20 @@ static void limit_clip_spectrum(AudioPsyClipContext *s, for (int i = 1; i < s->fft_size / 2; i++) { float real = clip_spectrum[i * 2]; float imag = clip_spectrum[i * 2 + 1]; - // although the negative frequencies are omitted because they are redundant, - // the magnitude of the positive frequencies are not doubled. + // Because the input signal is real, the + and - frequencies are redundant. // Multiply the magnitude by 2 to simulate adding up the + and - frequencies. relative_distortion_level = hypotf(real, imag) * 2 / mask_curve[i]; if (relative_distortion_level > 1.0) { clip_spectrum[i * 2] /= relative_distortion_level; clip_spectrum[i * 2 + 1] /= relative_distortion_level; + clip_spectrum[s->fft_size * 2 - i * 2] /= relative_distortion_level; + clip_spectrum[s->fft_size * 2 - i * 2 + 1] /= relative_distortion_level; } } // bin N/2 - relative_distortion_level = FFABS(clip_spectrum[1]) / mask_curve[s->fft_size / 2]; + relative_distortion_level = FFABS(clip_spectrum[s->fft_size]) / mask_curve[s->fft_size / 2]; if (relative_distortion_level > 1.f) - clip_spectrum[1] /= relative_distortion_level; + clip_spectrum[s->fft_size] /= relative_distortion_level; } static void r2c(float *buffer, int size) -- 2.35.0 _______________________________________________ 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".