31#define WEIGHT_LUT_NBITS 20
32#define WEIGHT_LUT_SIZE (1<<WEIGHT_LUT_NBITS)
65#define OFFSET(x) offsetof(AudioNLMeansContext, x)
66#define AFT AV_OPT_FLAG_AUDIO_PARAM|AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_RUNTIME_PARAM
87static inline float sqrdiff(
float x,
float y)
89 const float diff = x - y;
98 for (
int k = -
K; k <=
K; k++)
105 ptrdiff_t
S, ptrdiff_t
K,
106 ptrdiff_t
i, ptrdiff_t jj)
110 for (
int j = jj; j < jj +
S; j++, v++)
119#if ARCH_X86 && HAVE_X86ASM
128 int newK, newS, newH, newN;
134 newN = newH + (newK + newS) * 2;
138 if (!
s->cache ||
s->cache->nb_samples < newS * 2) {
145 s->cache = new_cache;
153 if (!
s->window ||
s->window->nb_samples < newN) {
160 s->window = new_window;
170 float w = -
i /
s->pdiff_lut_scale;
206 const int om =
s->om;
207 const float *
f = (
const float *)(
s->window->extended_data[ch]) +
K;
208 float *cache = (
float *)
s->cache->extended_data[ch];
209 const float sw = (65536.f / (4 *
K + 2)) /
sqrtf(
s->a);
210 float *
dst = (
float *)
out->extended_data[ch];
211 const float *
const weight_lut =
s->weight_lut;
212 const float pdiff_lut_scale =
s->pdiff_lut_scale;
215 float *
src = (
float *)
s->window->extended_data[ch];
222 for (
int i =
S;
i <
H +
S;
i++) {
223 float P = 0.f,
Q = 0.f;
227 for (
int j =
i -
S; j <=
i +
S; j++) {
230 cache[v++] =
s->dsp.compute_distance_ssd(
f +
i,
f + j,
K);
233 s->dsp.compute_cache(cache,
f,
S,
K,
i,
i -
S);
234 s->dsp.compute_cache(cache +
S,
f,
S,
K,
i,
i + 1);
237 for (
int j = 0; j < 2 *
S && !
ctx->is_disabled; j++) {
239 unsigned weight_lut_idx;
247 weight_lut_idx =
w * pdiff_lut_scale;
249 w = weight_lut[weight_lut_idx];
250 P +=
w *
f[
i -
S + j + (j >=
S)];
325 char *res,
int res_len,
int flags)
354 .p.description =
NULL_IF_CONFIG_SMALL(
"Reduce broadband noise from stream using Non-Local Means."),
355 .p.priv_class = &anlmdn_class,
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
static const AVFilterPad outputs[]
static int process_command(AVFilterContext *ctx, const char *cmd, const char *args, char *res, int res_len, int flags)
static int config_filter(AVFilterContext *ctx)
static int filter_channel(AVFilterContext *ctx, void *arg, int ch, int nb_jobs)
const FFFilter ff_af_anlmdn
static const AVOption anlmdn_options[]
static int filter_frame(AVFilterLink *inlink, AVFrame *in)
static float compute_distance_ssd_c(const float *f1, const float *f2, ptrdiff_t K)
static void compute_cache_c(float *cache, const float *f, ptrdiff_t S, ptrdiff_t K, ptrdiff_t i, ptrdiff_t jj)
static int process_command(AVFilterContext *ctx, const char *cmd, const char *args, char *res, int res_len, int flags)
static int activate(AVFilterContext *ctx)
static av_cold void uninit(AVFilterContext *ctx)
static int config_output(AVFilterLink *outlink)
void ff_anlmdn_init(AudioNLMDNDSPContext *dsp)
static float sqrdiff(float x, float y)
void ff_anlmdn_init_x86(AudioNLMDNDSPContext *s)
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_assert2(cond)
assert() equivalent, that does lie in speed critical code.
int ff_inlink_acknowledge_status(AVFilterLink *link, int *rstatus, int64_t *rpts)
Test and acknowledge the change of status on the link.
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
int ff_outlink_frame_wanted(AVFilterLink *link)
Test if a frame is wanted on an output link.
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_inlink_consume_samples(AVFilterLink *link, unsigned min, unsigned max, AVFrame **rframe)
Take samples from the link's FIFO and update the link's stats.
void ff_filter_set_ready(AVFilterContext *filter, unsigned priority)
Mark a filter ready and schedule it for activation.
int ff_inlink_queued_samples(AVFilterLink *link)
void ff_inlink_request_frame(AVFilterLink *link)
Mark that a frame is wanted on the link.
Main libavfilter public API header.
#define flags(name, subs,...)
#define i(width, name, range_min, range_max)
static __device__ float sqrtf(float a)
float fminf(float, float)
@ AV_OPT_TYPE_CONST
Special option type for declaring named constants.
@ AV_OPT_TYPE_DURATION
Underlying C type is int64_t.
@ AV_OPT_TYPE_INT
Underlying C type is int.
@ AV_OPT_TYPE_FLOAT
Underlying C type is float.
#define AVFILTER_FLAG_SLICE_THREADS
The filter supports multithreading by splitting frames into multiple parts and processing them concur...
#define AVFILTER_FLAG_SUPPORT_TIMELINE_INTERNAL
Same as AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC, except that the filter will have its filter_frame() c...
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.
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
int64_t av_rescale(int64_t a, int64_t b, int64_t c)
Rescale a 64-bit integer with rounding to nearest.
@ AV_SAMPLE_FMT_FLTP
float, planar
int av_samples_copy(uint8_t *const *dst, uint8_t *const *src, int dst_offset, int src_offset, int nb_samples, int nb_channels, enum AVSampleFormat sample_fmt)
Copy samples from src to dst.
#define AV_TIME_BASE
Internal time base represented as integer.
static av_cold void uninit(AVBitStreamFilterContext *ctx)
static int activate(AVBitStreamFilterContext *ctx)
static int config_output(AVBitStreamFilterLink *outlink)
static void filter_channel(MLPDecodeContext *m, unsigned int substr, unsigned int channel)
Generate PCM samples using the prediction filters and residual values read from the data stream,...
#define FILTER_INPUTS(array)
#define FILTER_OUTPUTS(array)
static void ff_outlink_set_status(AVFilterLink *link, int status, int64_t pts)
Set the status field of a link from the source filter.
#define FF_FILTER_FORWARD_STATUS_BACK(outlink, inlink)
Forward the status on an output link to an input link.
#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 float distance(float x, float y, int band)
int nb_channels
Number of channels in this layout.
Describe the class of an AVClass context structure.
A link between two filters.
AVFilterContext * src
source filter
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
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
AVChannelLayout ch_layout
Channel layout of the audio data.
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames,...
uint8_t ** extended_data
pointers to the data planes/channels.
float(* compute_distance_ssd)(const float *f1, const float *f2, ptrdiff_t K)
void(* compute_cache)(float *cache, const float *f, ptrdiff_t S, ptrdiff_t K, ptrdiff_t i, ptrdiff_t jj)
float weight_lut[WEIGHT_LUT_SIZE]
static float smooth(DeshakeOpenCLContext *deshake_ctx, float *gauss_kernel, int length, float max_val, AVFifo *values)
static av_always_inline int diff(const struct color_info *a, const struct color_info *b, const int trans_thresh)