Go to the documentation of this file.
46 #define OFFSET(x) offsetof(AudioEmphasisContext, x)
47 #define FLAGS AV_OPT_FLAG_AUDIO_PARAM|AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_RUNTIME_PARAM
71 double *
w,
double level_in,
double level_out)
73 const double a0 = bq->
a0;
74 const double a1 = bq->
a1;
75 const double a2 = bq->
a2;
76 const double b1 = bq->
b1;
77 const double b2 = bq->
b2;
81 for (
int i = 0;
i < nb_samples;
i++) {
82 double n =
src[
i] * level_in;
83 double tmp = n - w1 *
b1 - w2 *
b2;
89 dst[
i] =
out * level_out;
103 const double level_out =
s->level_out;
104 const double level_in =
s->level_in;
111 for (
int ch = start; ch < end; ch++) {
113 double *
w = (
double *)
s->w->extended_data[ch];
114 double *dst = (
double *)
out->extended_data[ch];
116 if (
s->rc.use_brickw) {
156 double A = sqrt(peak);
157 double w0 = freq * 2 *
M_PI / sr;
158 double alpha = sin(w0) / (2 * q);
159 double cw0 = cos(w0);
161 double b0 = 0, ib0 = 0;
163 bq->
a0 =
A*( (
A+1) + (
A-1)*cw0 +
tmp);
164 bq->
a1 = -2*
A*( (
A-1) + (
A+1)*cw0);
165 bq->
a2 =
A*( (
A+1) + (
A-1)*cw0 -
tmp);
167 bq->
b1 = 2*( (
A-1) - (
A+1)*cw0);
168 bq->
b2 = (
A+1) - (
A-1)*cw0 -
tmp;
180 double omega = 2.0 *
M_PI *
fc / sr;
181 double sn = sin(omega);
182 double cs = cos(omega);
183 double alpha = sn/(2 * q);
184 double inv = 1.0/(1.0 +
alpha);
186 bq->
a2 = bq->
a0 = gain * inv * (1.0 - cs) * 0.5;
188 bq->
b1 = (-2.0 * cs * inv);
189 bq->
b2 = ((1.0 -
alpha) * inv);
196 freq *= 2.0 *
M_PI / sr;
201 return hypot(
c->a0 +
c->a1*zr +
c->a2*(zr*zr-zi*zi),
c->a1*zi + 2*
c->a2*zr*zi) /
202 hypot(1 +
c->b1*zr +
c->b2*(zr*zr-zi*zi),
c->b1*zi + 2*
c->b2*zr*zi);
207 double i, j, k,
g, t,
a0,
a1,
a2,
b1,
b2, tau1, tau2, tau3;
208 double cutfreq, gain1kHz, gc, sr =
inlink->sample_rate;
239 i = 1. / (2. *
M_PI * tau1);
240 j = 1. / (2. *
M_PI * tau2);
241 k = 1. / (2. *
M_PI * tau3);
247 i = 1. / (2. *
M_PI * tau1);
248 j = 1. / (2. *
M_PI * tau2);
249 k = 1. / (2. *
M_PI * tau3);
255 i = 1. / (2. *
M_PI * tau1);
256 j = 1. / (2. *
M_PI * tau2);
257 k = 1. / (2. *
M_PI * tau3);
263 i = 1. / (2. *
M_PI * tau1);
264 j = 1. / (2. *
M_PI * tau2);
265 k = 1. / (2. *
M_PI * tau3);
276 if (
s->type == 7 ||
s->type == 8) {
277 double tau = (
s->type == 7 ? 0.000050 : 0.000075);
278 double f = 1.0 / (2 *
M_PI * tau);
279 double nyq = sr * 0.5;
280 double gain = sqrt(1.0 + nyq * nyq / (
f *
f));
281 double cfreq = sqrt((gain - 1.0) *
f *
f);
285 q = pow((sr / 3269.0) + 19.5, -0.25);
287 q = pow((sr / 4750.0) + 19.5, -0.25);
292 s->rc.use_brickw = 0;
294 s->rc.use_brickw = 1;
296 g = 1. / (4.+2.*
i*t+2.*k*t+
i*k*t*t);
299 a2 = (-2.*t+j*t*t)*
g;
300 b1 = (-8.+2.*
i*k*t*t)*
g;
301 b2 = (4.-2.*
i*t-2.*k*t+
i*k*t*t)*
g;
303 g = 1. / (2.*t+j*t*t);
304 a0 = (4.+2.*
i*t+2.*k*t+
i*k*t*t)*
g;
305 a1 = (-8.+2.*
i*k*t*t)*
g;
306 a2 = (4.-2.*
i*t-2.*k*t+
i*k*t*t)*
g;
308 b2 = (-2.*t+j*t*t)*
g;
320 gain1kHz =
freq_gain(&coeffs, 1000.0, sr);
323 s->rc.r1.a0 = coeffs.
a0 * gc;
324 s->rc.r1.a1 = coeffs.
a1 * gc;
325 s->rc.r1.a2 = coeffs.
a2 * gc;
326 s->rc.r1.b1 = coeffs.
b1;
327 s->rc.r1.b2 = coeffs.
b2;
330 cutfreq =
FFMIN(0.45 * sr, 21000.);
337 char *res,
int res_len,
int flags)
368 .priv_class = &aemphasis_class,
static void biquad_process(BiquadCoeffs *bq, double *dst, const double *src, int nb_samples, double *w, double level_in, double level_out)
AVFrame * ff_get_audio_buffer(AVFilterLink *link, int nb_samples)
Request an audio samples buffer with a specific set of permissions.
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 double freq_gain(BiquadCoeffs *c, double freq, double sr)
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
#define FILTER_SINGLE_SAMPLEFMT(sample_fmt_)
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
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 int filter_frame(AVFilterLink *inlink, AVFrame *in)
AVFILTER_DEFINE_CLASS(aemphasis)
#define fc(width, name, range_min, range_max)
const char * name
Filter name.
int nb_channels
Number of channels in this layout.
A link between two filters.
static double b1(void *priv, double x, double y)
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
A filter pad used for either input or output.
static const AVOption aemphasis_options[]
static int process_command(AVFilterContext *ctx, const char *cmd, const char *args, char *res, int res_len, int flags)
static const AVFilterPad avfilter_af_aemphasis_inputs[]
#define FILTER_INPUTS(array)
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.
const AVFilterPad ff_audio_default_filterpad[1]
An AVFilterPad array whose only entry has name "default" and is of type AVMEDIA_TYPE_AUDIO.
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 int filter_channels(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
static void set_lp_rbj(BiquadCoeffs *bq, double fc, double q, double sr, double gain)
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
static av_const double hypot(double x, double y)
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.
static double b2(void *priv, double x, double y)
#define AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC
Some filters support a generic "enable" expression option that can be used to enable or disable a fil...
int nb_samples
number of audio samples (per channel) described by this frame
#define i(width, name, range_min, range_max)
static void set_highshelf_rbj(BiquadCoeffs *bq, double freq, double q, double peak, double sr)
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.
@ AV_SAMPLE_FMT_DBLP
double, planar
#define AVFILTER_FLAG_SLICE_THREADS
The filter supports multithreading by splitting frames into multiple parts and processing them concur...
static const int16_t alpha[]
#define FILTER_OUTPUTS(array)
static int config_input(AVFilterLink *inlink)
static av_cold void uninit(AVFilterContext *ctx)
#define flags(name, subs,...)
static double b0(void *priv, double x, double y)
const AVFilter ff_af_aemphasis
static av_always_inline int ff_filter_execute(AVFilterContext *ctx, avfilter_action_func *func, void *arg, int *ret, int nb_jobs)