29 #define RDFT_BITS_MIN 4
30 #define RDFT_BITS_MAX 16
46 #define NB_GAIN_ENTRY_MAX 4096
93 #define OFFSET(x) offsetof(FIREqualizerContext, x)
94 #define FLAGS AV_OPT_FLAG_AUDIO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
175 if (nsamples <= s->nsamples_max) {
180 memcpy(buf, data, nsamples *
sizeof(*data));
181 memset(buf + nsamples, 0, (s->
rdft_len - nsamples) *
sizeof(*data));
184 buf[0] *= kernel_buf[0];
185 buf[1] *= kernel_buf[1];
186 for (k = 2; k < s->
rdft_len; k += 2) {
188 re = buf[k] * kernel_buf[k] - buf[k+1] * kernel_buf[k+1];
189 im = buf[k] * kernel_buf[k+1] + buf[k+1] * kernel_buf[k];
197 memcpy(data, buf, nsamples *
sizeof(*data));
207 fast_convolute(s, kernel_buf, conv_buf, idx, data + nsamples/2, nsamples - nsamples/2);
242 const double *freq = key;
245 if (*freq < entry[0].freq)
247 if (*freq > entry[1].freq)
265 if (freq <= s->gain_entry_tbl[0].freq)
275 d0 = freq - res[0].
freq;
276 d1 = res[1].
freq - freq;
279 return (d0 * res[1].gain + d1 * res[0].gain) / d;
311 const char *gain_entry_func_names[] = {
"entry",
NULL };
312 const char *gain_func_names[] = {
"gain_interpolate",
NULL };
313 double (*gain_entry_funcs[])(
void *, double, double) = {
entry_func,
NULL };
317 int ret, k, center, ch;
324 gain_entry_func_names, gain_entry_funcs, ctx, 0, ctx);
334 gain_func_names, gain_funcs,
NULL,
NULL, 0, ctx);
341 for (ch = 0; ch < inlink->
channels; ch++) {
358 for (k = 0; k <= center; k++) {
359 double u = k * (
M_PI/center);
366 win = 0.5 + 0.5 * cos(u);
369 win = 0.53836 + 0.46164 * cos(u);
372 win = 0.48 + 0.5 * cos(u) + 0.02 * cos(2*u);
375 win = 0.40897 + 0.5 * cos(u) + 0.09103 * cos(2*u);
378 win = 0.4243801 + 0.4973406 * cos(u) + 0.0782793 * cos(2*u);
381 win = 0.355768 + 0.487396 * cos(u) + 0.144232 * cos(2*u) + 0.012604 * cos(3*u);
384 win = 0.3635819 + 0.4891775 * cos(u) + 0.1365995 * cos(2*u) + 0.0106411 * cos(3*u);
387 win = 0.35875 + 0.48829 * cos(u) + 0.14128 * cos(2*u) + 0.01168 * cos(3*u);
395 for (k = 0; k < center - k; k++) {
401 for (k = 1; k <= center; k++)
476 av_log(ctx,
AV_LOG_DEBUG,
"sample_rate = %d, channels = %d, analysis_rdft_len = %d, rdft_len = %d, fir_len = %d, nsamples_max = %d.\n",
492 for (ch = 0; ch < inlink->
channels; ch++) {
531 char *res,
int res_len,
int flags)
536 if (!strcmp(cmd,
"gain")) {
550 }
else if (!strcmp(cmd,
"gain_entry")) {
551 char *gain_entry_cmd;
590 .
name =
"firequalizer",
596 .
inputs = firequalizer_inputs,
597 .
outputs = firequalizer_outputs,
598 .priv_class = &firequalizer_class,
This structure describes decoded (raw) audio or video data.
ptrdiff_t const GLvoid * data
static void common_uninit(FIREqualizerContext *s)
Main libavfilter public API header.
int max_samples
Maximum number of samples to filter at once.
static double gain_interpolate_func(void *p, double freq)
static enum AVSampleFormat formats[]
static int request_frame(AVFilterLink *outlink)
static int config_input(AVFilterLink *inlink)
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 AVRational av_make_q(int num, int den)
Create a rational.
#define NB_GAIN_ENTRY_MAX
static const AVFilterPad firequalizer_outputs[]
const char * name
Pad name.
AVFilterLink ** inputs
array of pointers to input links
#define av_assert0(cond)
assert() equivalent, that is always enabled.
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
static const char *const var_names[]
#define AVERROR_EOF
End of file.
A filter pad used for either input or output.
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
A link between two filters.
int av_expr_parse_and_eval(double *d, const char *s, const char *const *const_names, const double *const_values, const char *const *func1_names, double(*const *funcs1)(void *, double), const char *const *func2_names, double(*const *funcs2)(void *, double, double), void *opaque, int log_offset, void *log_ctx)
Parse and evaluate an expression.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
int av_samples_set_silence(uint8_t **audio_data, int offset, int nb_samples, int nb_channels, enum AVSampleFormat sample_fmt)
Fill an audio buffer with silence.
int min_samples
Minimum number of samples to filter at once.
int sample_rate
samples per second
static void fast_convolute(FIREqualizerContext *s, const float *kernel_buf, float *conv_buf, OverlapIndex *idx, float *data, int nsamples)
AVFrame * ff_get_audio_buffer(AVFilterLink *link, int nb_samples)
Request an audio samples buffer with a specific set of permissions.
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
AVFILTER_DEFINE_CLASS(firequalizer)
void * priv
private data for use by the filter
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
AVRational time_base
Define the time base used by the PTS of the frames/samples which will pass through this link...
simple assert() macros that are a bit more flexible than ISO C assert().
RDFTContext * analysis_irdft
static av_cold void uninit(AVFilterContext *ctx)
static const AVOption firequalizer_options[]
void av_rdft_calc(RDFTContext *s, FFTSample *data)
static const AVFilterPad firequalizer_inputs[]
void av_rdft_end(RDFTContext *s)
AVFilterContext * src
source filter
RDFTContext * av_rdft_init(int nbits, enum RDFTransformType trans)
Set up a real FFT.
int partial_buf_size
Size of the partial buffer to allocate.
static const AVFilterPad outputs[]
A list of supported channel layouts.
static double entry_func(void *p, double freq, double gain)
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames...
static const uint8_t vars[2][12]
static const AVFilterPad inputs[]
AVSampleFormat
Audio sample formats.
void av_expr_free(AVExpr *e)
Free a parsed expression previously created with av_expr_parse().
char * av_strdup(const char *s)
Duplicate the string s.
AVFilter ff_af_firequalizer
static int process_command(AVFilterContext *ctx, const char *cmd, const char *args, char *res, int res_len, int flags)
Describe the class of an AVClass context structure.
GainEntry gain_entry_tbl[NB_GAIN_ENTRY_MAX]
const char * name
Filter name.
AVFilterLink ** outputs
array of pointers to output links
enum MovChannelLayoutTag * layouts
void * av_calloc(size_t nmemb, size_t size)
Allocate a block of nmemb * size bytes with alignment suitable for all memory accesses (including vec...
uint64_t av_channel_layout_extract_channel(uint64_t channel_layout, int index)
Get the channel with the given index in channel_layout.
static int query_formats(AVFilterContext *ctx)
static int generate_kernel(AVFilterContext *ctx, const char *gain, const char *gain_entry)
uint64_t channel_layout
channel layout of current buffer (see libavutil/channel_layout.h)
int channels
Number of channels.
double av_expr_eval(AVExpr *e, const double *const_values, void *opaque)
Evaluate a previously parsed expression.
AVFilterContext * dst
dest filter
static int filter_frame(AVFilterLink *inlink, AVFrame *frame)
static enum AVSampleFormat sample_fmts[]
#define av_malloc_array(a, b)
static int gain_entry_compare(const void *key, const void *memb)
int ff_request_frame(AVFilterLink *link)
Request an input frame from the filter at the other end of the link.
uint8_t ** extended_data
pointers to the data planes/channels.
int nb_samples
number of audio samples (per channel) described by this frame
#define AV_NOPTS_VALUE
Undefined timestamp value.
simple arithmetic expression evaluator