From: Santanu Biswas <shbisws@gmail.com> To: ffmpeg-devel@ffmpeg.org Cc: Santanu Biswas <shbisws@gmail.com> Subject: [FFmpeg-devel] [PATCH] avfilter/asrc_sine: Generate full amplitude sine wave. Date: Sat, 28 May 2022 14:09:21 +0530 Message-ID: <20220528083921.16538-1-shbisws@gmail.com> (raw) Previously, generating a full amplitude sine wave require to either use the 'volume' filter in combination with this filter or manually generate sine wave using 'aevalsrc' (e.g "aevalsrc=sin(2*PI*t*440)"). This method is not bit-exact; therefore it is much coherent to not scale the amplitude by 1/8 and keep it as it is. Signed-off-by: Santanu Biswas <shbisws@gmail.com> --- doc/filters.texi | 2 +- libavfilter/asrc_sine.c | 8 ++------ 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/doc/filters.texi b/doc/filters.texi index 0e10946cca..a42e27b9b5 100644 --- a/doc/filters.texi +++ b/doc/filters.texi @@ -7452,7 +7452,7 @@ Set number of taps for low-pass filter. @section sine -Generate an audio signal made of a sine wave with amplitude 1/8. +Generate an audio signal made of a sine wave. The audio signal is bit-exact. diff --git a/libavfilter/asrc_sine.c b/libavfilter/asrc_sine.c index c0d8d2265b..6c2f9d40f3 100644 --- a/libavfilter/asrc_sine.c +++ b/libavfilter/asrc_sine.c @@ -83,13 +83,11 @@ static const AVOption sine_options[] = { AVFILTER_DEFINE_CLASS(sine); #define LOG_PERIOD 15 -#define AMPLITUDE 4095 -#define AMPLITUDE_SHIFT 3 static void make_sin_table(int16_t *sin) { unsigned half_pi = 1 << (LOG_PERIOD - 2); - unsigned ampls = AMPLITUDE << AMPLITUDE_SHIFT; + unsigned ampls = 32767; uint64_t unit2 = (uint64_t)(ampls * ampls) << 32; unsigned step, i, c, s, k, new_k, n2; @@ -116,9 +114,7 @@ static void make_sin_table(int16_t *sin) sin[half_pi - i - step / 2] = (k * c + 0x8000) >> 16; } } - /* Unshift amplitude */ - for (i = 0; i <= half_pi; i++) - sin[i] = (sin[i] + (1 << (AMPLITUDE_SHIFT - 1))) >> AMPLITUDE_SHIFT; + /* Use symmetries to fill the other three quarters */ for (i = 0; i < half_pi; i++) sin[half_pi * 2 - i] = sin[i]; -- 2.35.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 reply other threads:[~2022-05-28 8:39 UTC|newest] Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top 2022-05-28 8:39 Santanu Biswas [this message] 2022-05-28 8:48 ` Paul B Mahol
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=20220528083921.16538-1-shbisws@gmail.com \ --to=shbisws@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