From: Jason Jang <jcj83429@gmail.com>
To: ffmpeg-devel@ffmpeg.org
Cc: Jason Jang <jcj83429@gmail.com>
Subject: [FFmpeg-devel] [PATCH 1/3] avfilter/af_apsyclip: fix FFT bin indexing
Date: Fri, 28 Jan 2022 17:08:27 -0800
Message-ID: <20220129010827.307903-1-jcj83429@gmail.com> (raw)
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 <jcj83429@gmail.com>
---
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".
reply other threads:[~2022-01-29 1:08 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20220129010827.307903-1-jcj83429@gmail.com \
--to=jcj83429@gmail.com \
--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