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;
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)
365 .p.name =
"aemphasis",
367 .p.priv_class = &aemphasis_class,
static int fn filter_channels(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
static int config_input(AVFilterLink *inlink)
static int process_command(AVFilterContext *ctx, const char *cmd, const char *args, char *res, int res_len, int flags)
const FFFilter ff_af_aemphasis
static int filter_channels(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
static int config_input(AVFilterLink *inlink)
static const AVFilterPad avfilter_af_aemphasis_inputs[]
static int filter_frame(AVFilterLink *inlink, AVFrame *in)
static int process_command(AVFilterContext *ctx, const char *cmd, const char *args, char *res, int res_len, int flags)
static av_cold void uninit(AVFilterContext *ctx)
static double freq_gain(BiquadCoeffs *c, double freq, double sr)
static void biquad_process(BiquadCoeffs *bq, double *dst, const double *src, int nb_samples, double *w, double level_in, double level_out)
static void set_lp_rbj(BiquadCoeffs *bq, double fc, double q, double sr, double gain)
static void set_highshelf_rbj(BiquadCoeffs *bq, double freq, double q, double peak, double sr)
static const AVOption aemphasis_options[]
const AVFilterPad ff_audio_default_filterpad[1]
An AVFilterPad array whose only entry has name "default" and is of type AVMEDIA_TYPE_AUDIO.
AVFrame * ff_get_audio_buffer(AVFilterLink *link, int nb_samples)
Request an audio samples buffer with a specific set of permissions.
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
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.
int ff_filter_execute(AVFilterContext *ctx, avfilter_action_func *func, void *arg, int *ret, int nb_jobs)
int ff_filter_get_nb_threads(AVFilterContext *ctx)
Get number of threads for current filter instance.
Main libavfilter public API header.
#define flags(name, subs,...)
#define i(width, name, range_min, range_max)
static const uint16_t fc[]
static int filter_frame(DBEDecodeContext *s, AVFrame *frame)
@ AV_OPT_TYPE_CONST
Special option type for declaring named constants.
@ AV_OPT_TYPE_INT
Underlying C type is int.
@ AV_OPT_TYPE_DOUBLE
Underlying C type is double.
#define AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC
Some filters support a generic "enable" expression option that can be used to enable or disable a fil...
#define AVFILTER_FLAG_SLICE_THREADS
The filter supports multithreading by splitting frames into multiple parts and processing them concur...
int av_frame_is_writable(AVFrame *frame)
Check if the frame data is writable.
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
@ AV_SAMPLE_FMT_DBLP
double, planar
static const int16_t alpha[]
static av_cold void uninit(AVBitStreamFilterContext *ctx)
#define FILTER_INPUTS(array)
#define FILTER_OUTPUTS(array)
static int ff_slice_pos(int total, int jobnr, int nb_jobs)
Compute the boundary index for a slice when work of size total is split into nb_jobs slices.
#define FILTER_SINGLE_SAMPLEFMT(sample_fmt_)
#define AVFILTER_DEFINE_CLASS(fname)
#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 nb_channels
Number of channels in this layout.
Describe the class of an AVClass context structure.
A link between two filters.
int sample_rate
samples per second
AVChannelLayout ch_layout
channel layout of current buffer (see libavutil/channel_layout.h)
AVFilterContext * dst
dest filter
A filter pad used for either input or output.
This structure describes decoded (raw) audio or video data.
int nb_samples
number of audio samples (per channel) described by this frame
AVChannelLayout ch_layout
Channel layout of the audio data.
uint8_t ** extended_data
pointers to the data planes/channels.
Used for passing data between threads.
static AVFormatContext * ctx
static double b1(void *priv, double x, double y)
static double a0(void *priv, double x, double y)
static double b2(void *priv, double x, double y)
static double b0(void *priv, double x, double y)
static double a2(void *priv, double x, double y)
static double a1(void *priv, double x, double y)