[FFmpeg-devel] [PATCH] avfilter/asrc_sine: Generate full amplitude sine wave.
Santanu Biswas
shbisws at gmail.com
Sat May 28 11:39:21 EEST 2022
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 at 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
More information about the ffmpeg-devel
mailing list