[FFmpeg-devel] [PATCH] lavf: add more beep options to sine asrc
Michael Bradshaw
mjbshaw at gmail.com
Fri Oct 6 19:27:57 EEST 2017
From: Michael Bradshaw <mjbshaw at google.com>
Signed-off-by: Michael Bradshaw <mjbshaw at google.com>
---
doc/filters.texi | 13 ++++++++++++-
libavfilter/asrc_sine.c | 17 +++++++++++++----
2 files changed, 25 insertions(+), 5 deletions(-)
diff --git a/doc/filters.texi b/doc/filters.texi
index 57189c77b0..ec1c335950 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -4624,7 +4624,18 @@ Set the carrier frequency. Default is 440 Hz.
@item beep_factor, b
Enable a periodic beep every second with frequency @var{beep_factor} times
-the carrier frequency. Default is 0, meaning the beep is disabled.
+the carrier frequency. Default is 0, meaning the beep is disabled. If
+ at var{frequency} is 0, this value is interpreted as the beep frequency (in Hertz)
+(rather than a multiplier of the @var{frequency}).
+
+ at item beep_delay
+The delay for the first beep, in seconds. Default is 0.
+
+ at item beep_period
+The time beriod between two beeps, in seconds. Default is 1.
+
+ at item beep_duration
+The duration of a beep, in seconds. Default is 0.04.
@item sample_rate, r
Specify the sample rate, default is 44100.
diff --git a/libavfilter/asrc_sine.c b/libavfilter/asrc_sine.c
index 3a87210b4b..643952792f 100644
--- a/libavfilter/asrc_sine.c
+++ b/libavfilter/asrc_sine.c
@@ -32,6 +32,9 @@ typedef struct SineContext {
const AVClass *class;
double frequency;
double beep_factor;
+ double beep_delay;
+ double beep_period_opt;
+ double beep_duration;
char *samples_per_frame;
AVExpr *samples_per_frame_expr;
int sample_rate;
@@ -71,6 +74,9 @@ static const AVOption sine_options[] = {
OPT_DBL("f", frequency, 440, 0, DBL_MAX, "set the sine frequency",),
OPT_DBL("beep_factor", beep_factor, 0, 0, DBL_MAX, "set the beep frequency factor",),
OPT_DBL("b", beep_factor, 0, 0, DBL_MAX, "set the beep frequency factor",),
+ OPT_DBL("beep_delay", beep_delay, 0, 0, DBL_MAX, "set the delay for the first beep",),
+ OPT_DBL("beep_period", beep_period_opt, 1, DBL_MIN, DBL_MAX, "set the gap between beeps",),
+ OPT_DBL("beep_duration", beep_duration, 0.04, DBL_MIN, DBL_MAX, "set the duration of a beep",),
OPT_INT("sample_rate", sample_rate, 44100, 1, INT_MAX, "set the sample rate",),
OPT_INT("r", sample_rate, 44100, 1, INT_MAX, "set the sample rate",),
OPT_DUR("duration", duration, 0, 0, INT64_MAX, "set the audio duration",),
@@ -152,10 +158,13 @@ static av_cold int init(AVFilterContext *ctx)
make_sin_table(sine->sin);
if (sine->beep_factor) {
- sine->beep_period = sine->sample_rate;
- sine->beep_length = sine->beep_period / 25;
- sine->dphi_beep = ldexp(sine->beep_factor * sine->frequency, 32) /
- sine->sample_rate + 0.5;
+ unsigned beep_start = sine->beep_delay * sine->sample_rate;
+ double beep_frequency = (sine->frequency ? sine->frequency : 1.0) *
+ sine->beep_factor;
+ sine->beep_period = sine->beep_period_opt * sine->sample_rate;
+ sine->beep_index = (sine->beep_period - beep_start) % sine->beep_period;
+ sine->beep_length = sine->beep_duration * sine->sample_rate;
+ sine->dphi_beep = ldexp(beep_frequency, 32) / sine->sample_rate + 0.5;
}
ret = av_expr_parse(&sine->samples_per_frame_expr,
--
2.13.5 (Apple Git-94)
More information about the ffmpeg-devel
mailing list