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
95 double w0 = 2 *
M_PI * frequency / sample_rate;
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);
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++) {
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++) {
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)
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++) {
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])
455 out->nb_samples /=
s->oversample;
477 .p.name =
"asoftclip",
479 .p.priv_class = &asoftclip_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 const AVFilterPad inputs[]
static int config_input(AVFilterLink *inlink)
static void filter_dbl(void **d, const void **s, int nb_samples, int channels, float contrast)
static void filter_flt(void **d, const void **s, int nb_samples, int channels, float contrast)
static double run_lowpassd(const Lowpass *const s, double src, double *w)
static const AVOption asoftclip_options[]
const FFFilter ff_af_asoftclip
static void filter_dbl(ASoftClipContext *s, void **dptr, const void **sptr, int nb_samples, int channels, int start, int end)
static void get_lowpass(Lowpass *s, double frequency, double sample_rate)
static int filter_channels(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
static int config_input(AVFilterLink *inlink)
static void filter_flt(ASoftClipContext *s, void **dptr, const void **sptr, int nb_samples, int channels, int start, int end)
static int filter_frame(AVFilterLink *inlink, AVFrame *in)
static av_cold void uninit(AVFilterContext *ctx)
static float run_lowpassf(const Lowpass *const s, float src, float *w)
static AVFormatContext * ctx
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.
simple assert() macros that are a bit more flexible than ISO C assert().
#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.
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 i(width, name, range_min, range_max)
Public libavutil channel layout APIs header.
#define FFABS(a)
Absolute value, Note, INT_MIN / INT64_MIN result in undefined behavior as they are not representable ...
static __device__ float sqrtf(float a)
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_FLTP
float, planar
@ AV_SAMPLE_FMT_DBLP
double, planar
static const int16_t alpha[]
static void scale(int *out, const int *in, const int w, const int h, const int shift)
static av_cold void uninit(AVBitStreamFilterContext *ctx)
#define FILTER_INPUTS(array)
#define FILTER_OUTPUTS(array)
#define FILTER_SAMPLEFMTS(...)
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 AVFILTER_DEFINE_CLASS(fname)
static const int factor[16]
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
static double erf(double z)
erf function Algorithm taken from the Boost project, source: http://www.boost.org/doc/libs/1_46_1/boo...
Lowpass lowpass[MAX_OVERSAMPLE]
void(* filter)(struct ASoftClipContext *s, void **dst, const void **src, int nb_samples, int channels, int start, int end)
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
AVFilterContext * dst
dest filter
int format
agreed upon media format
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.