88 const double *
src,
double *dst);
91 #define OFFSET(x) offsetof(AudioDeclickContext, x) 92 #define AF AV_OPT_FLAG_AUDIO_PARAM|AV_OPT_FLAG_FILTERING_PARAM 189 for (i = 0; i < inlink->
channels; i++) {
209 double *
output,
double scale)
213 for (i = 0; i <= order; i++) {
216 for (j = i; j <
size; j++)
217 value += input[j] * input[j - i];
219 output[
i] = value * scale;
229 memset(a, 0, ar_order *
sizeof(*a));
234 k[0] = a[0] = -r[1] / r[0];
235 alpha = r[0] * (1. - k[0] * k[0]);
239 for (j = 0; j <
i; j++)
240 epsilon += a[j] * r[i - j];
244 alpha *= (1. - k[
i] * k[
i]);
245 for (j = i - 1; j >= 0; j--)
246 k[j] = a[j] + k[i] * a[i - j - 1];
247 for (j = 0; j <=
i; j++)
273 if ((value < index[0]) || (value > index[size - 1]))
279 while (start <= end) {
280 i = (end + start) / 2;
281 if (index[i] == value)
283 if (value < index[i])
285 if (value > index[i])
296 for (i = 0; i < n; i++) {
297 const int in = i * n;
300 value = matrix[in +
i];
301 for (j = 0; j <
i; j++)
302 value -= matrix[j * n + j] * matrix[in + j] * matrix[in + j];
309 for (j = i + 1; j < n; j++) {
310 const int jn = j * n;
314 for (k = 0; k <
i; k++)
315 x -= matrix[k * n + k] * matrix[in + k] * matrix[jn + k];
316 matrix[jn +
i] = x / matrix[in +
i];
338 for (i = 0; i < n; i++) {
339 const int in = i * n;
343 for (j = 0; j <
i; j++)
344 value -= matrix[in + j] * y[j];
348 for (i = n - 1; i >= 0; i--) {
349 out[
i] = y[
i] / matrix[i * n +
i];
350 for (j = i + 1; j < n; j++)
351 out[i] -= matrix[j * n + i] * out[j];
376 for (i = 0; i < nb_errors; i++) {
377 const int im = i * nb_errors;
379 for (j = i; j < nb_errors; j++) {
380 if (
abs(index[j] - index[i]) <= ar_order) {
381 matrix[j * nb_errors +
i] = matrix[im + j] = auxiliary[
abs(index[j] - index[i])];
383 matrix[j * nb_errors +
i] = matrix[im + j] = 0;
388 for (i = 0; i < nb_errors; i++) {
391 for (j = -ar_order; j <=
ar_order; j++)
392 if (
find_index(index, index[i] - j, nb_errors))
393 value -= src[index[
i] - j] * auxiliary[
abs(j)];
403 double *unused1,
double *unused2,
405 const double *
src,
double *dst)
408 double max_amplitude = 0;
416 memset(histogram, 0,
sizeof(*histogram) * s->
nb_hbins);
426 for (i = s->
nb_hbins - 1; i > 1; i--) {
428 if (histogram[i] / (
double)
FFMAX(histogram[i - 1], 1) >
threshold) {
429 max_amplitude = i / (double)s->
nb_hbins;
435 if (max_amplitude > 0.) {
437 clip[
i] =
fabs(src[i]) >= max_amplitude;
441 memset(clip, 0, s->
ar_order *
sizeof(*clip));
446 index[nb_clips++] =
i;
455 const double *
src,
double *dst)
458 int i, j, nb_clicks = 0, prev = -1;
460 memset(detection, 0, s->
window_size *
sizeof(*detection));
463 for (j = 0; j <= s->
ar_order; j++) {
464 detection[
i] += acoefficients[j] * src[i - j];
478 for (j = prev + 1; j <
i; j++)
483 memset(click, 0, s->
ar_order *
sizeof(*click));
488 index[nb_clicks++] =
i;
519 nb_errors = s->
detector(s,
c, sigmae,
c->detection,
c->acoefficients,
520 c->click, index, src, dst);
525 nb_errors,
c->auxiliary, interpolated);
531 for (j = 0; j < nb_errors; j++) {
532 if (enabled[index[j]]) {
533 dst[index[j]] = interpolated[j];
544 buf[j] += dst[j] *
w[j];
549 buf[j] = dst[skip + j];
568 int ret = 0, j, ch, detected_errors = 0;
701 av_log(ctx,
AV_LOG_INFO,
"Detected %s in %"PRId64
" of %"PRId64
" samples (%g%%).\n",
762 .priv_class = &adeclick_class,
790 .priv_class = &adeclip_class,
static int detect_clips(AudioDeclickContext *s, DeclickChannel *c, double unused0, double *unused1, double *unused2, uint8_t *clip, int *index, const double *src, double *dst)
AVAudioFifo * av_audio_fifo_alloc(enum AVSampleFormat sample_fmt, int channels, int nb_samples)
Allocate an AVAudioFifo.
This structure describes decoded (raw) audio or video data.
static const AVFilterPad outputs[]
Main libavfilter public API header.
void av_audio_fifo_free(AVAudioFifo *af)
Free an AVAudioFifo.
The reader does not expect b to be semantically here and if the code is changed by maybe adding a a division or other the signedness will almost certainly be mistaken To avoid this confusion a new type was SUINT is the C unsigned type but it holds a signed int to use the same example SUINT a
static int config_input(AVFilterLink *inlink)
static av_cold int init(AVFilterContext *ctx)
int is_disabled
the enabled state from the last expression evaluation
static void ff_outlink_set_status(AVFilterLink *link, int status, int64_t pts)
Set the status field of a link from the source filter.
void * av_calloc(size_t nmemb, size_t size)
Non-inlined equivalent of av_mallocz_array().
const char * name
Pad name.
AVFilterLink ** inputs
array of pointers to input links
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
int(* detector)(struct AudioDeclickContext *s, DeclickChannel *c, double sigmae, double *detection, double *acoefficients, uint8_t *click, int *index, const double *src, double *dst)
static av_cold int end(AVCodecContext *avctx)
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
filter_frame For filters that do not use the this method is called when a frame is pushed to the filter s input It can be called at any time except in a reentrant way If the input frame is enough to produce output
GLsizei GLboolean const GLfloat * value
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
#define AVERROR_EOF
End of file.
#define FF_FILTER_FORWARD_STATUS_BACK(outlink, inlink)
Forward the status on an output link to an input link.
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 ff_inlink_acknowledge_status(AVFilterLink *link, int *rstatus, int64_t *rpts)
Test and acknowledge the change of status on the link.
int sample_rate
samples per second
AVFrame * ff_get_audio_buffer(AVFilterLink *link, int nb_samples)
Request an audio samples buffer with a specific set of permissions.
static __device__ float fabs(float a)
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
void * priv
private data for use by the filter
#define AVFILTER_FLAG_SLICE_THREADS
The filter supports multithreading by splitting frames into multiple parts and processing them concur...
AVRational time_base
Define the time base used by the PTS of the frames/samples which will pass through this link...
static int find_index(int *index, int value, int size)
Context for an Audio FIFO Buffer.
void av_fast_malloc(void *ptr, unsigned int *size, size_t min_size)
Allocate a buffer, reusing the given one if large enough.
int av_audio_fifo_size(AVAudioFifo *af)
Get the current number of samples in the AVAudioFifo available for reading.
int channels
number of audio channels, only used for audio.
static int detect_clicks(AudioDeclickContext *s, DeclickChannel *c, double sigmae, double *detection, double *acoefficients, uint8_t *click, int *index, const double *src, double *dst)
static int interpolation(DeclickChannel *c, const double *src, int ar_order, double *acoefficients, int *index, int nb_errors, double *auxiliary, double *interpolated)
static int activate(AVFilterContext *ctx)
static const AVOption adeclip_options[]
int format
agreed upon media format
A list of supported channel layouts.
#define AV_LOG_INFO
Standard information.
AVSampleFormat
Audio sample formats.
static int filter_frame(AVFilterLink *inlink)
Used for passing data between threads.
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.
static const int16_t alpha[]
static av_cold void uninit(AVFilterContext *ctx)
static int filter_channel(AVFilterContext *ctx, void *arg, int ch, int nb_jobs)
static const AVOption adeclick_options[]
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(const uint8_t *) pi-0x80)*(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(const uint8_t *) pi-0x80)*(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(const int16_t *) pi >> 8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t,*(const int16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t,*(const int16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(const int32_t *) pi >> 24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t,*(const int32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t,*(const int32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(const float *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(const float *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(const float *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(const double *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(const double *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(const double *) pi *(1U<< 31))))#define SET_CONV_FUNC_GROUP(ofmt, ifmt) static void set_generic_function(AudioConvert *ac){}void ff_audio_convert_free(AudioConvert **ac){if(!*ac) return;ff_dither_free(&(*ac) ->dc);av_freep(ac);}AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enum AVSampleFormat out_fmt, enum AVSampleFormat in_fmt, int channels, int sample_rate, int apply_map){AudioConvert *ac;int in_planar, out_planar;ac=av_mallocz(sizeof(*ac));if(!ac) return NULL;ac->avr=avr;ac->out_fmt=out_fmt;ac->in_fmt=in_fmt;ac->channels=channels;ac->apply_map=apply_map;if(avr->dither_method!=AV_RESAMPLE_DITHER_NONE &&av_get_packed_sample_fmt(out_fmt)==AV_SAMPLE_FMT_S16 &&av_get_bytes_per_sample(in_fmt) > 2){ac->dc=ff_dither_alloc(avr, out_fmt, in_fmt, channels, sample_rate, apply_map);if(!ac->dc){av_free(ac);return NULL;}return ac;}in_planar=ff_sample_fmt_is_planar(in_fmt, channels);out_planar=ff_sample_fmt_is_planar(out_fmt, channels);if(in_planar==out_planar){ac->func_type=CONV_FUNC_TYPE_FLAT;ac->planes=in_planar?ac->channels:1;}else if(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;else ac->func_type=CONV_FUNC_TYPE_DEINTERLEAVE;set_generic_function(ac);if(ARCH_AARCH64) ff_audio_convert_init_aarch64(ac);if(ARCH_ARM) ff_audio_convert_init_arm(ac);if(ARCH_X86) ff_audio_convert_init_x86(ac);return ac;}int ff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in){int use_generic=1;int len=in->nb_samples;int p;if(ac->dc){av_log(ac->avr, AV_LOG_TRACE,"%d samples - audio_convert: %s to %s (dithered)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));return ff_convert_dither(ac-> in
Describe the class of an AVClass context structure.
static void autocorrelation(const double *input, int order, int size, double *output, double scale)
Rational number (pair of numerator and denominator).
they must not be accessed directly The fifo field contains the frames that are queued in the input for processing by the filter The status_in and status_out fields contains the queued status(EOF or error) of the link
const char * name
Filter name.
and forward the test the status of outputs and forward it to the corresponding return FFERROR_NOT_READY If the filters stores internally one or a few frame for some input
#define AVFILTER_FLAG_SUPPORT_TIMELINE_INTERNAL
Same as AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC, except that the filter will have its filter_frame() c...
AVFilterLink ** outputs
array of pointers to output links
enum MovChannelLayoutTag * layouts
#define flags(name, subs,...)
AVFilterInternal * internal
An opaque struct for libavfilter internal use.
int av_audio_fifo_write(AVAudioFifo *af, void **data, int nb_samples)
Write data to an AVAudioFifo.
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
int av_audio_fifo_drain(AVAudioFifo *af, int nb_samples)
Drain data from an AVAudioFifo.
static int isfinite_array(double *samples, int nb_samples)
static double clip(void *opaque, double val)
Clip value val in the minval - maxval range.
static int factorization(double *matrix, int n)
void ff_filter_set_ready(AVFilterContext *filter, unsigned priority)
Mark a filter ready and schedule it for activation.
static const AVFilterPad inputs[]
double fmin(double, double)
int channels
Number of channels.
avfilter_execute_func * execute
FF_FILTER_FORWARD_WANTED(outlink, inlink)
static int do_interpolation(DeclickChannel *c, double *matrix, double *vector, int n, double *out)
AVFilterContext * dst
dest filter
The official guide to swscale for confused that is
int av_audio_fifo_peek(AVAudioFifo *af, void **data, int nb_samples)
Peek data from an AVAudioFifo.
static int query_formats(AVFilterContext *ctx)
static enum AVSampleFormat sample_fmts[]
Filter the word “frame” indicates either a video frame or a group of audio samples
AVFILTER_DEFINE_CLASS(adeclick)
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
uint8_t ** extended_data
pointers to the data planes/channels.
int nb_samples
number of audio samples (per channel) described by this frame
const AVFilter * filter
the AVFilter of which this is an instance
#define AV_NOPTS_VALUE
Undefined timestamp value.
static double autoregression(const double *samples, int ar_order, int nb_samples, double *k, double *r, double *a)