58#define CONTEXT SineContext
59#define FLAGS AV_OPT_FLAG_AUDIO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
61#define OPT_GENERIC(name, field, def, min, max, descr, type, deffield, ...) \
62 { name, descr, offsetof(CONTEXT, field), AV_OPT_TYPE_ ## type, \
63 { .deffield = def }, min, max, FLAGS, __VA_ARGS__ }
65#define OPT_INT(name, field, def, min, max, descr, ...) \
66 OPT_GENERIC(name, field, def, min, max, descr, INT, i64, __VA_ARGS__)
68#define OPT_DBL(name, field, def, min, max, descr, ...) \
69 OPT_GENERIC(name, field, def, min, max, descr, DOUBLE, dbl, __VA_ARGS__)
71#define OPT_DUR(name, field, def, min, max, descr, ...) \
72 OPT_GENERIC(name, field, def, min, max, descr, DURATION, str, __VA_ARGS__)
74#define OPT_STR(name, field, def, min, max, descr, ...) \
75 OPT_GENERIC(name, field, def, min, max, descr, STRING, str, __VA_ARGS__)
78 OPT_DBL(
"frequency", frequency, 440, 0, DBL_MAX,
"set the sine frequency",),
79 OPT_DBL(
"f", frequency, 440, 0, DBL_MAX,
"set the sine frequency",),
80 OPT_DBL(
"beep_factor", beep_factor, 0, 0, DBL_MAX,
"set the beep frequency factor",),
81 OPT_DBL(
"b", beep_factor, 0, 0, DBL_MAX,
"set the beep frequency factor",),
82 OPT_INT(
"sample_rate", sample_rate, 44100, 1, INT_MAX,
"set the sample rate",),
83 OPT_INT(
"r", sample_rate, 44100, 1, INT_MAX,
"set the sample rate",),
84 OPT_DUR(
"duration",
duration, 0, 0, INT64_MAX,
"set the audio duration",),
86 OPT_STR(
"samples_per_frame", samples_per_frame,
"1024", 0, 0,
"set the number of samples per frame",),
94#define AMPLITUDE_SHIFT 3
100 uint64_t unit2 = (uint64_t)(ampls * ampls) << 32;
101 unsigned step,
i,
c,
s, k, new_k, n2;
106 sin[half_pi] = ampls;
107 for (step = half_pi; step > 1; step /= 2) {
111 for (
i = 0;
i < half_pi / 2;
i += step) {
112 s = sin[
i] + sin[
i + step];
113 c = sin[half_pi -
i] + sin[half_pi -
i - step];
117 new_k = (k + unit2 / ((uint64_t)k * n2) + 1) >> 1;
122 sin[
i + step / 2] = (k *
s + 0x7FFF) >> 16;
123 sin[half_pi -
i - step / 2] = (k *
c + 0x8000) >> 16;
127 for (
i = 0;
i <= half_pi;
i++)
130 for (
i = 0;
i < half_pi;
i++)
131 sin[half_pi * 2 -
i] = sin[
i];
132 for (
i = 0;
i < 2 * half_pi;
i++)
133 sin[
i + 2 * half_pi] = -sin[
i];
155 int r_den, max_r_den;
157 max_r_den = INT_MAX / sample_rate;
158 frequency = fmod(frequency, sample_rate);
159 r =
av_d2q(fmod(frequency, 1.0), max_r_den);
160 r_den =
FFMIN(
r.den, max_r_den);
161 c->dphi = ldexp(frequency, 32) / sample_rate;
162 c->dphi_den = r_den * sample_rate;
163 c->dphi_rem =
round((ldexp(frequency, 32) / sample_rate -
c->dphi) *
c->dphi_den);
164 if (
c->dphi_rem >=
c->dphi_den) {
168 c->phi_rem = (-
c->dphi_den - 1) / 2;
174 c->phi_rem +=
c->dphi_rem;
175 if (
c->phi_rem >= 0) {
176 c->phi_rem -=
c->dphi_den;
259 if (nb_samples <= 0) {
261 "defaulting to 1024\n", nb_samples);
275 samples = (int16_t *)
frame->data[0];
277 for (
i = 0;
i < nb_samples;
i++) {
289 sine->
pts += nb_samples;
304 .p.priv_class = &sine_class,
static enum AVSampleFormat sample_fmts[]
static int query_formats(const AVFilterContext *ctx, AVFilterFormatsConfig **cfg_in, AVFilterFormatsConfig **cfg_out)
const FFFilter ff_asrc_sine
#define OPT_STR(name, field, def, min, max, descr,...)
#define OPT_DBL(name, field, def, min, max, descr,...)
static void make_sin_table(int16_t *sin)
static const AVFilterPad sine_outputs[]
static av_always_inline void sampling_advance(SamplingContext *c)
#define OPT_DUR(name, field, def, min, max, descr,...)
static const AVOption sine_options[]
static av_cold int query_formats(const AVFilterContext *ctx, AVFilterFormatsConfig **cfg_in, AVFilterFormatsConfig **cfg_out)
static int activate(AVFilterContext *ctx)
#define OPT_INT(name, field, def, min, max, descr,...)
static av_cold void uninit(AVFilterContext *ctx)
static av_cold int config_props(AVFilterLink *outlink)
static void sampling_init(SamplingContext *c, double frequency, int sample_rate)
AVFrame * ff_get_audio_buffer(AVFilterLink *link, int nb_samples)
Request an audio samples buffer with a specific set of permissions.
simple assert() macros that are a bit more flexible than ISO C assert().
#define av_assert1(cond)
assert() equivalent, that does not lie in speed critical code.
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
int ff_outlink_frame_wanted(AVFilterLink *link)
Test if a frame is wanted on an output link.
Main libavfilter public API header.
#define i(width, name, range_min, range_max)
Public libavutil channel layout APIs header.
static const int sample_rates[]
int(* init)(AVBSFContext *ctx)
void av_expr_free(AVExpr *e)
Free a parsed expression previously created with av_expr_parse().
double av_expr_eval(AVExpr *e, const double *const_values, void *opaque)
Evaluate a previously parsed expression.
int av_expr_parse(AVExpr **expr, const char *s, const char *const *const_names, const char *const *func1_names, double(*const *funcs1)(void *, double), const char *const *func2_names, double(*const *funcs2)(void *, double, double), int log_offset, void *log_ctx)
Parse an expression.
simple arithmetic expression evaluator
#define AV_CHANNEL_LAYOUT_MONO
#define AVERROR_EOF
End of file.
#define AV_LOG_WARNING
Something somehow does not look correct.
AVRational av_d2q(double d, int max)
Convert a double precision floating point number to a rational.
static double av_q2d(AVRational a)
Convert an AVRational to a double.
int64_t av_rescale(int64_t a, int64_t b, int64_t c)
Rescale a 64-bit integer with rounding to nearest.
AVSampleFormat
Audio sample formats.
@ AV_SAMPLE_FMT_S16
signed 16 bits
#define AV_TIME_BASE
Internal time base represented as integer.
static av_cold void uninit(AVBitStreamFilterContext *ctx)
static int activate(AVBitStreamFilterContext *ctx)
#define FILTER_OUTPUTS(array)
static void ff_outlink_set_status(AVFilterLink *link, int status, int64_t pts)
Set the status field of a link from the source filter.
#define FFERROR_NOT_READY
Filters implementation helper functions and internal structures.
static FilterLink * ff_filter_link(AVFilterLink *link)
#define AVFILTER_DEFINE_CLASS(fname)
#define FILTER_QUERY_FUNC2(func)
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
static av_always_inline av_const double round(double x)
Memory handling functions.
static const char *const var_names[]
static int config_props(AVBitStreamFilterLink *link)
An AVChannelLayout holds information about the channel layout of audio data.
Describe the class of an AVClass context structure.
void * priv
private data for use by the filter
A link between two filters.
AVFilterContext * src
source filter
AVRational time_base
Define the time base used by the PTS of the frames/samples which will pass through this link.
A filter pad used for either input or output.
This structure describes decoded (raw) audio or video data.
Rational number (pair of numerator and denominator).
Link properties exposed to filter code, but not external callers.
int64_t frame_count_in
Number of past frames sent through the link.
uint32_t phi
current phase of the sine (2pi = 1<<32)
uint32_t dphi
phase increment between two samples
int phi_rem
current fractional phase in 1/dphi_den subfractions
AVExpr * samples_per_frame_expr
static AVFormatContext * ctx