Go to the documentation of this file.
52 #define CONTEXT SineContext
53 #define FLAGS AV_OPT_FLAG_AUDIO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
55 #define OPT_GENERIC(name, field, def, min, max, descr, type, deffield, ...) \
56 { name, descr, offsetof(CONTEXT, field), AV_OPT_TYPE_ ## type, \
57 { .deffield = def }, min, max, FLAGS, __VA_ARGS__ }
59 #define OPT_INT(name, field, def, min, max, descr, ...) \
60 OPT_GENERIC(name, field, def, min, max, descr, INT, i64, __VA_ARGS__)
62 #define OPT_DBL(name, field, def, min, max, descr, ...) \
63 OPT_GENERIC(name, field, def, min, max, descr, DOUBLE, dbl, __VA_ARGS__)
65 #define OPT_DUR(name, field, def, min, max, descr, ...) \
66 OPT_GENERIC(name, field, def, min, max, descr, DURATION, str, __VA_ARGS__)
68 #define OPT_STR(name, field, def, min, max, descr, ...) \
69 OPT_GENERIC(name, field, def, min, max, descr, STRING, str, __VA_ARGS__)
72 OPT_DBL(
"frequency", frequency, 440, 0, DBL_MAX,
"set the sine frequency",),
73 OPT_DBL(
"f", frequency, 440, 0, DBL_MAX,
"set the sine frequency",),
74 OPT_DBL(
"beep_factor", beep_factor, 0, 0, DBL_MAX,
"set the beep frequency factor",),
75 OPT_DBL(
"b", beep_factor, 0, 0, DBL_MAX,
"set the beep frequency factor",),
76 OPT_INT(
"sample_rate", sample_rate, 44100, 1, INT_MAX,
"set the sample rate",),
77 OPT_INT(
"r", sample_rate, 44100, 1, INT_MAX,
"set the sample rate",),
78 OPT_DUR(
"duration",
duration, 0, 0, INT64_MAX,
"set the audio duration",),
80 OPT_STR(
"samples_per_frame", samples_per_frame,
"1024", 0, 0,
"set the number of samples per frame",),
87 #define AMPLITUDE 4095
88 #define AMPLITUDE_SHIFT 3
94 uint64_t unit2 = (uint64_t)(ampls * ampls) << 32;
95 unsigned step,
i,
c,
s, k, new_k, n2;
100 sin[half_pi] = ampls;
105 for (
i = 0;
i < half_pi / 2;
i +=
step) {
107 c = sin[half_pi -
i] + sin[half_pi -
i -
step];
111 new_k = (k + unit2 / ((uint64_t)k * n2) + 1) >> 1;
116 sin[
i +
step / 2] = (k *
s + 0x7FFF) >> 16;
117 sin[half_pi -
i -
step / 2] = (k *
c + 0x8000) >> 16;
121 for (
i = 0;
i <= half_pi;
i++)
124 for (
i = 0;
i < half_pi;
i++)
125 sin[half_pi * 2 -
i] = sin[
i];
126 for (
i = 0;
i < 2 * half_pi;
i++)
127 sin[
i + 2 * half_pi] = -sin[
i];
225 if (nb_samples <= 0) {
227 "defaulting to 1024\n", nb_samples);
243 for (
i = 0;
i < nb_samples;
i++) {
255 sine->
pts += nb_samples;
277 .priv_class = &sine_class,
AVFrame * ff_get_audio_buffer(AVFilterLink *link, int nb_samples)
Request an audio samples buffer with a specific set of permissions.
#define AV_LOG_WARNING
Something somehow does not look correct.
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
static const AVOption sine_options[]
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
static enum AVSampleFormat sample_fmts[]
#define AVERROR_EOF
End of file.
AVFILTER_DEFINE_CLASS(sine)
static const int sample_rates[]
This structure describes decoded (raw) audio or video data.
trying all byte sequences megabyte in length and selecting the best looking sequence will yield cases to try But a word about which is also called distortion Distortion can be quantified by almost any quality measurement one chooses the sum of squared differences is used but more complex methods that consider psychovisual effects can be used as well It makes no difference in this discussion First step
static av_cold int config_props(AVFilterLink *outlink)
static av_cold int query_formats(const AVFilterContext *ctx, AVFilterFormatsConfig **cfg_in, AVFilterFormatsConfig **cfg_out)
const char * name
Filter name.
static void make_sin_table(int16_t *sin)
A link between two filters.
static int activate(AVFilterContext *ctx)
Link properties exposed to filter code, but not external callers.
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.
static av_cold void uninit(AVFilterContext *ctx)
void * priv
private data for use by the filter
#define OPT_DBL(name, field, def, min, max, descr,...)
void av_expr_free(AVExpr *e)
Free a parsed expression previously created with av_expr_parse().
A filter pad used for either input or output.
static void ff_outlink_set_status(AVFilterLink *link, int status, int64_t pts)
Set the status field of a link from the source filter.
static double av_q2d(AVRational a)
Convert an AVRational to a double.
double av_expr_eval(AVExpr *e, const double *const_values, void *opaque)
Evaluate a previously parsed expression.
static const char *const var_names[]
#define FILTER_OUTPUTS(array)
#define OPT_DUR(name, field, def, min, max, descr,...)
AVExpr * samples_per_frame_expr
Describe the class of an AVClass context structure.
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several inputs
uint32_t dphi_beep
phase increment of the beep
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated Undefined Behavior must not occur in a C it is not safe even if the output of undefined operations is unused The unsafety may seem nit picking but Optimizing compilers have in fact optimized code on the assumption that no undefined Behavior occurs Optimizing code based on wrong assumptions can and has in some cases lead to effects beyond the output of computations The signed integer overflow problem in speed critical code Code which is highly optimized and works with signed integers sometimes has the problem that often the output of the computation does not c
static FilterLink * ff_filter_link(AVFilterLink *link)
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
An AVChannelLayout holds information about the channel layout of audio data.
#define OPT_STR(name, field, def, min, max, descr,...)
static const AVFilterPad sine_outputs[]
AVFilterContext * src
source filter
#define OPT_INT(name, field, def, min, max, descr,...)
#define i(width, name, range_min, range_max)
uint32_t phi
current phase of the sine (2pi = 1<<32)
#define AV_TIME_BASE
Internal time base represented as integer.
#define av_assert1(cond)
assert() equivalent, that does not lie in speed critical code.
AVSampleFormat
Audio sample formats.
#define FILTER_QUERY_FUNC2(func)
@ AV_SAMPLE_FMT_S16
signed 16 bits
const char * name
Pad name.
int64_t av_rescale(int64_t a, int64_t b, int64_t c)
Rescale a 64-bit integer with rounding to nearest.
static av_cold int init(AVFilterContext *ctx)
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several the filter must be ready for frames arriving randomly on any input any filter with several inputs will most likely require some kind of queuing mechanism It is perfectly acceptable to have a limited queue and to drop frames when the inputs are too unbalanced request_frame For filters that do not use the this method is called when a frame is wanted on an output For a it should directly call filter_frame on the corresponding output For a if there are queued frames already one of these frames should be pushed If the filter should request a frame on one of its repeatedly until at least one frame has been pushed Return or at least make progress towards producing a frame
uint32_t dphi
phase increment between two samples
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several the filter must be ready for frames arriving randomly on any input any filter with several inputs will most likely require some kind of queuing mechanism It is perfectly acceptable to have a limited queue and to drop frames when the inputs are too unbalanced request_frame For filters that do not use the this method is called when a frame is wanted on an output For a it should directly call filter_frame on the corresponding output For a if there are queued frames already one of these frames should be pushed If the filter should request a frame on one of its repeatedly until at least one frame has been pushed Return values
Filter the word “frame” indicates either a video frame or a group of audio samples
AVRational time_base
Define the time base used by the PTS of the frames/samples which will pass through this link.
const AVFilter ff_asrc_sine
#define AV_CHANNEL_LAYOUT_MONO
the definition of that something depends on the semantic of the filter The callback must examine the status of the filter s links and proceed accordingly The status of output links is stored in the status_in and status_out fields and tested by the ff_outlink_frame_wanted() function. If this function returns true
uint32_t phi_beep
current phase of the beep
int64_t frame_count_in
Number of past frames sent through the link.