Go to the documentation of this file.
28 #define MAX_OVERSAMPLE 64
65 int nb_samples,
int channels,
int start,
int end);
68 #define OFFSET(x) offsetof(ASoftClipContext, x)
69 #define A AV_OPT_FLAG_AUDIO_PARAM|AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_RUNTIME_PARAM
96 double alpha = sin(w0) / (2 * 0.8);
100 s->da1 = -2 * cos(w0);
102 s->db0 = (1 - cos(w0)) / 2;
103 s->db1 = 1 - cos(w0);
104 s->db2 = (1 - cos(w0)) / 2;
113 factor = (
s->da0 +
s->da1 +
s->da2) / (
s->db0 +
s->db1 +
s->db2);
131 dst =
src *
s->fb0 +
w[0];
132 w[0] =
s->fb1 *
src +
w[1] -
s->fa1 * dst;
133 w[1] =
s->fb2 *
src -
s->fa2 * dst;
139 void **dptr,
const void **sptr,
144 const int nb_osamples = nb_samples *
oversample;
151 for (
int c = start;
c < end;
c++) {
152 float *
w = (
float *)(
s->frame[0]->extended_data[
c]) + 2 * (
oversample - 1);
153 const float *
src = sptr[
c];
154 float *dst = dptr[
c];
156 for (
int n = 0; n < nb_samples; n++) {
163 for (
int n = 0; n < nb_osamples && oversample > 1; n++)
168 for (
int n = 0; n < nb_osamples; n++) {
174 for (
int n = 0; n < nb_osamples; n++) {
180 for (
int n = 0; n < nb_osamples; n++) {
186 for (
int n = 0; n < nb_osamples; n++) {
197 for (
int n = 0; n < nb_osamples; n++) {
198 dst[n] = 2.f / (1.f +
expf(-2.
f * dst[n] *
factor)) - 1.;
203 for (
int n = 0; n < nb_osamples; n++) {
211 for (
int n = 0; n < nb_osamples; n++) {
222 for (
int n = 0; n < nb_osamples; n++) {
233 for (
int n = 0; n < nb_osamples; n++) {
234 dst[n] = erff(dst[n] *
factor);
242 w = (
float *)(
s->frame[1]->extended_data[
c]) + 2 * (
oversample - 1);
243 for (
int n = 0; n < nb_osamples && oversample > 1; n++)
246 for (
int n = 0; n < nb_samples; n++)
252 double src,
double *
w)
256 dst =
src *
s->db0 +
w[0];
257 w[0] =
s->db1 *
src +
w[1] -
s->da1 * dst;
258 w[1] =
s->db2 *
src -
s->da2 * dst;
264 void **dptr,
const void **sptr,
269 const int nb_osamples = nb_samples *
oversample;
276 for (
int c = start;
c < end;
c++) {
277 double *
w = (
double *)(
s->frame[0]->extended_data[
c]) + 2 * (
oversample - 1);
278 const double *
src = sptr[
c];
279 double *dst = dptr[
c];
281 for (
int n = 0; n < nb_samples; n++) {
288 for (
int n = 0; n < nb_osamples && oversample > 1; n++)
293 for (
int n = 0; n < nb_osamples; n++) {
299 for (
int n = 0; n < nb_osamples; n++) {
305 for (
int n = 0; n < nb_osamples; n++) {
311 for (
int n = 0; n < nb_osamples; n++) {
322 for (
int n = 0; n < nb_osamples; n++) {
323 dst[n] = 2. / (1. +
exp(-2. * dst[n] *
factor)) - 1.;
328 for (
int n = 0; n < nb_osamples; n++) {
336 for (
int n = 0; n < nb_osamples; n++) {
347 for (
int n = 0; n < nb_osamples; n++) {
358 for (
int n = 0; n < nb_osamples; n++) {
367 w = (
double *)(
s->frame[1]->extended_data[
c]) + 2 * (
oversample - 1);
368 for (
int n = 0; n < nb_osamples && oversample > 1; n++)
371 for (
int n = 0; n < nb_samples; n++)
389 if (!
s->frame[0] || !
s->frame[1])
412 const int nb_samples =
td->nb_samples;
413 const int start = (
channels * jobnr) / nb_jobs;
414 const int end = (
channels * (jobnr+1)) / nb_jobs;
447 td.nb_samples = nb_samples;
455 out->nb_samples /=
s->oversample;
487 .priv_class = &asoftclip_class,
AVFrame * ff_get_audio_buffer(AVFilterLink *link, int nb_samples)
Request an audio samples buffer with a specific set of permissions.
@ AV_SAMPLE_FMT_FLTP
float, planar
static av_cold void uninit(AVFilterContext *ctx)
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
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
filter_frame For filters that do not use the this method is called when a frame is pushed to the filter s input It can be called at any time except in a reentrant way If the input frame is enough to produce output
The exact code depends on how similar the blocks are and how related they are to the and needs to apply these operations to the correct inlink or outlink if there are several Macros are available to factor that when no extra processing is inlink
static int config_input(AVFilterLink *inlink)
static const AVFilterPad outputs[]
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
This structure describes decoded (raw) audio or video data.
static const AVOption asoftclip_options[]
const char * name
Filter name.
int nb_channels
Number of channels in this layout.
A link between two filters.
static double run_lowpassd(const Lowpass *const s, double src, double *w)
AVChannelLayout ch_layout
Channel layout of the audio data.
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf type
static av_always_inline float scale(float x, float s)
A filter pad used for either input or output.
#define av_assert0(cond)
assert() equivalent, that is always enabled.
#define FILTER_INPUTS(array)
#define FFABS(a)
Absolute value, Note, INT_MIN / INT64_MIN result in undefined behavior as they are not representable ...
static void filter_dbl(ASoftClipContext *s, void **dptr, const void **sptr, int nb_samples, int channels, int start, int end)
static const AVFilterPad inputs[]
Describe the class of an AVClass context structure.
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
void(* filter)(struct ASoftClipContext *s, void **dst, const void **src, int nb_samples, int channels, int start, int end)
static float run_lowpassf(const Lowpass *const s, float src, float *w)
static __device__ float sqrtf(float a)
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
AVFILTER_DEFINE_CLASS(asoftclip)
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
int av_frame_is_writable(AVFrame *frame)
Check if the frame data is writable.
int ff_filter_process_command(AVFilterContext *ctx, const char *cmd, const char *arg, char *res, int res_len, int flags)
Generic processing of user supplied commands that are set in the same way as the filter options.
#define AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC
Some filters support a generic "enable" expression option that can be used to enable or disable a fil...
const AVFilter ff_af_asoftclip
int nb_samples
number of audio samples (per channel) described by this frame
#define i(width, name, range_min, range_max)
uint8_t ** extended_data
pointers to the data planes/channels.
int ff_filter_get_nb_threads(AVFilterContext *ctx)
Get number of threads for current filter instance.
Used for passing data between threads.
const char * name
Pad name.
static double erf(double z)
erf function Algorithm taken from the Boost project, source: http://www.boost.org/doc/libs/1_46_1/boo...
@ AV_SAMPLE_FMT_DBLP
double, planar
static void filter_flt(ASoftClipContext *s, void **dptr, const void **sptr, int nb_samples, int channels, int start, int end)
static const int factor[16]
#define AVFILTER_FLAG_SLICE_THREADS
The filter supports multithreading by splitting frames into multiple parts and processing them concur...
static int filter_channels(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
static const int16_t alpha[]
static void get_lowpass(Lowpass *s, double frequency, double sample_rate)
#define FILTER_OUTPUTS(array)
Lowpass lowpass[MAX_OVERSAMPLE]
static av_always_inline int ff_filter_execute(AVFilterContext *ctx, avfilter_action_func *func, void *arg, int *ret, int nb_jobs)
static int filter_frame(AVFilterLink *inlink, AVFrame *in)
#define FILTER_SAMPLEFMTS(...)