Go to the documentation of this file.
49 #define MEAN_SUM(suffix, type, zero) \
50 static type mean_sum_##suffix(const type *in, \
53 type mean_sum = zero; \
55 for (int i = 0; i < size; i++) \
64 #define SQUARE_SUM(suffix, type, zero) \
65 static type square_sum_##suffix(const type *x, \
69 type square_sum = zero; \
71 for (int i = 0; i < size; i++) \
72 square_sum += x[i] * y[i]; \
80 #define XCORRELATE(suffix, type, zero, small, sqrtfun)\
81 static type xcorrelate_##suffix(const type *x, \
84 type sumy, int size) \
86 const type xm = sumx / size, ym = sumy / size; \
87 type num = zero, den, den0 = zero, den1 = zero; \
89 for (int i = 0; i < size; i++) { \
90 type xd = x[i] - xm; \
91 type yd = y[i] - ym; \
99 den = sqrtfun((den0 * den1) / size / size); \
101 return den <= small ? zero : num / den; \
107 #define XCORRELATE_SLOW(suffix, type) \
108 static int xcorrelate_slow_##suffix(AVFilterContext *ctx, \
109 AVFrame *out, int available) \
111 AudioXCorrelateContext *s = ctx->priv; \
112 const int size = s->size; \
115 for (int ch = 0; ch < out->ch_layout.nb_channels; ch++) { \
116 const type *x = (const type *)s->cache[0]->extended_data[ch]; \
117 const type *y = (const type *)s->cache[1]->extended_data[ch]; \
118 type *sumx = (type *)s->mean_sum[0]->extended_data[ch]; \
119 type *sumy = (type *)s->mean_sum[1]->extended_data[ch]; \
120 type *dst = (type *)out->extended_data[ch]; \
124 sumx[0] = mean_sum_##suffix(x, size); \
125 sumy[0] = mean_sum_##suffix(y, size); \
129 for (int n = 0; n < out->nb_samples; n++) { \
130 const int idx = n + size; \
132 dst[n] = xcorrelate_##suffix(x + n, y + n, \
149 #define clipf(x) (av_clipf(x, -1.f, 1.f))
150 #define clipd(x) (av_clipd(x, -1.0, 1.0))
152 #define XCORRELATE_FAST(suffix, type, zero, small, sqrtfun, CLIP) \
153 static int xcorrelate_fast_##suffix(AVFilterContext *ctx, AVFrame *out, \
156 AudioXCorrelateContext *s = ctx->priv; \
157 const int size = s->size; \
160 for (int ch = 0; ch < out->ch_layout.nb_channels; ch++) { \
161 const type *x = (const type *)s->cache[0]->extended_data[ch]; \
162 const type *y = (const type *)s->cache[1]->extended_data[ch]; \
163 type *num_sum = (type *)s->num_sum->extended_data[ch]; \
164 type *den_sumx = (type *)s->den_sum[0]->extended_data[ch]; \
165 type *den_sumy = (type *)s->den_sum[1]->extended_data[ch]; \
166 type *dst = (type *)out->extended_data[ch]; \
170 num_sum[0] = square_sum_##suffix(x, y, size); \
171 den_sumx[0] = square_sum_##suffix(x, x, size); \
172 den_sumy[0] = square_sum_##suffix(y, y, size); \
176 for (int n = 0; n < out->nb_samples; n++) { \
177 const int idx = n + size; \
180 num = num_sum[0] / size; \
181 den = sqrtfun((den_sumx[0] * den_sumy[0]) / size / size); \
183 dst[n] = den <= small ? zero : CLIP(num / den); \
185 num_sum[0] -= x[n] * y[n]; \
186 num_sum[0] += x[idx] * y[idx]; \
187 den_sumx[0] -= x[n] * x[n]; \
188 den_sumx[0] += x[idx] * x[idx]; \
189 den_sumx[0] = FFMAX(den_sumx[0], zero); \
190 den_sumy[0] -= y[n] * y[n]; \
191 den_sumy[0] += y[idx] * y[idx]; \
192 den_sumy[0] = FFMAX(den_sumy[0], zero); \
202 #define XCORRELATE_BEST(suffix, type, zero, small, sqrtfun, FMAX, CLIP) \
203 static int xcorrelate_best_##suffix(AVFilterContext *ctx, AVFrame *out, \
206 AudioXCorrelateContext *s = ctx->priv; \
207 const int size = s->size; \
210 for (int ch = 0; ch < out->ch_layout.nb_channels; ch++) { \
211 const type *x = (const type *)s->cache[0]->extended_data[ch]; \
212 const type *y = (const type *)s->cache[1]->extended_data[ch]; \
213 type *mean_sumx = (type *)s->mean_sum[0]->extended_data[ch]; \
214 type *mean_sumy = (type *)s->mean_sum[1]->extended_data[ch]; \
215 type *num_sum = (type *)s->num_sum->extended_data[ch]; \
216 type *den_sumx = (type *)s->den_sum[0]->extended_data[ch]; \
217 type *den_sumy = (type *)s->den_sum[1]->extended_data[ch]; \
218 type *dst = (type *)out->extended_data[ch]; \
222 num_sum[0] = square_sum_##suffix(x, y, size); \
223 den_sumx[0] = square_sum_##suffix(x, x, size); \
224 den_sumy[0] = square_sum_##suffix(y, y, size); \
225 mean_sumx[0] = mean_sum_##suffix(x, size); \
226 mean_sumy[0] = mean_sum_##suffix(y, size); \
230 for (int n = 0; n < out->nb_samples; n++) { \
231 const int idx = n + size; \
232 type num, den, xm, ym; \
234 xm = mean_sumx[0] / size; \
235 ym = mean_sumy[0] / size; \
236 num = num_sum[0] - size * xm * ym; \
237 den = sqrtfun(FMAX(den_sumx[0] - size * xm * xm, zero)) * \
238 sqrtfun(FMAX(den_sumy[0] - size * ym * ym, zero)); \
240 dst[n] = den <= small ? zero : CLIP(num / den); \
242 mean_sumx[0]-= x[n]; \
243 mean_sumx[0]+= x[idx]; \
244 mean_sumy[0]-= y[n]; \
245 mean_sumy[0]+= y[idx]; \
246 num_sum[0] -= x[n] * y[n]; \
247 num_sum[0] += x[idx] * y[idx]; \
248 den_sumx[0] -= x[n] * x[n]; \
249 den_sumx[0] += x[idx] * x[idx]; \
250 den_sumx[0] = FMAX(den_sumx[0], zero); \
251 den_sumy[0] -= y[n] * y[n]; \
252 den_sumy[0] += y[idx] * y[idx]; \
253 den_sumy[0] = FMAX(den_sumy[0], zero); \
274 for (
int i = 0;
i < 2 && !
s->eof;
i++) {
292 if (!
s->cache[0] ||
s->cache[0]->nb_samples <
available) {
299 if (!
s->cache[1] ||
s->cache[1]->nb_samples <
available) {
321 s->pts += out_samples;
329 for (
int i = 0;
i < 2 && !
s->eof;
i++) {
361 for (
int i = 0;
i < 2;
i++) {
381 if (!
s->fifo[0] || !
s->fifo[1])
389 if (!
s->mean_sum[0] || !
s->mean_sum[1] || !
s->num_sum ||
390 !
s->den_sum[0] || !
s->den_sum[1])
394 case 0:
s->xcorrelate = xcorrelate_slow_f;
break;
395 case 1:
s->xcorrelate = xcorrelate_fast_f;
break;
396 case 2:
s->xcorrelate = xcorrelate_best_f;
break;
401 case 0:
s->xcorrelate = xcorrelate_slow_d;
break;
402 case 1:
s->xcorrelate = xcorrelate_fast_d;
break;
403 case 2:
s->xcorrelate = xcorrelate_best_d;
break;
427 .
name =
"axcorrelate0",
431 .name =
"axcorrelate1",
444 #define AF AV_OPT_FLAG_AUDIO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
445 #define OFFSET(x) offsetof(AudioXCorrelateContext, x)
459 .
name =
"axcorrelate",
462 .priv_class = &axcorrelate_class,
void av_audio_fifo_free(AVAudioFifo *af)
Free an AVAudioFifo.
AVFrame * ff_get_audio_buffer(AVFilterLink *link, int nb_samples)
Request an audio samples buffer with a specific set of permissions.
@ AV_SAMPLE_FMT_FLTP
float, planar
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
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
#define AVERROR_EOF
End of file.
#define XCORRELATE_FAST(suffix, type, zero, small, sqrtfun, CLIP)
int av_audio_fifo_write(AVAudioFifo *af, void *const *data, int nb_samples)
Write data to an AVAudioFifo.
AVFILTER_DEFINE_CLASS(axcorrelate)
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
This structure describes decoded (raw) audio or video data.
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
const char * name
Filter name.
int nb_channels
Number of channels in this layout.
A link between two filters.
int ff_inlink_consume_frame(AVFilterLink *link, AVFrame **rframe)
Take a frame from the link's FIFO and update the link's stats.
#define FF_FILTER_FORWARD_STATUS_BACK_ALL(outlink, filter)
Forward the status on an output link to all input links.
Context for an Audio FIFO Buffer.
int av_audio_fifo_drain(AVAudioFifo *af, int nb_samples)
Drain data from an AVAudioFifo.
#define XCORRELATE(suffix, type, zero, small, sqrtfun)
A filter pad used for either input or output.
#define SQUARE_SUM(suffix, type, zero)
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 ff_inlink_request_frame(AVFilterLink *link)
Mark that a frame is wanted on the link.
static int config_output(AVFilterLink *outlink)
const AVFilter ff_af_axcorrelate
#define FILTER_INPUTS(array)
Describe the class of an AVClass context structure.
int(* xcorrelate)(AVFilterContext *ctx, AVFrame *out, int available)
AVAudioFifo * av_audio_fifo_alloc(enum AVSampleFormat sample_fmt, int channels, int nb_samples)
Allocate an AVAudioFifo.
static __device__ float sqrtf(float a)
int ff_inlink_acknowledge_status(AVFilterLink *link, int *rstatus, int64_t *rpts)
Test and acknowledge the change of status on the link.
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
float fmaxf(float, float)
int format
agreed upon media format
#define XCORRELATE_SLOW(suffix, type)
#define AV_NOPTS_VALUE
Undefined timestamp value.
AVFilterContext * src
source filter
int av_audio_fifo_peek(const AVAudioFifo *af, void *const *data, int nb_samples)
Peek data from an AVAudioFifo.
int av_audio_fifo_size(AVAudioFifo *af)
Get the current number of samples in the AVAudioFifo available for reading.
static av_cold void uninit(AVFilterContext *ctx)
int nb_samples
number of audio samples (per channel) described by this frame
#define i(width, name, range_min, range_max)
uint8_t ** extended_data
pointers to the data planes/channels.
static const AVOption axcorrelate_options[]
static const AVFilterPad inputs[]
const char * name
Pad name.
static int activate(AVFilterContext *ctx)
double fmax(double, double)
@ AV_SAMPLE_FMT_DBLP
double, planar
AVChannelLayout ch_layout
channel layout of current buffer (see libavutil/channel_layout.h)
#define FILTER_OUTPUTS(array)
the definition of that something depends on the semantic of the filter The callback must examine the status of the filter s links and proceed accordingly The status of output links is stored in the status_in and status_out fields and tested by the ff_outlink_frame_wanted() function. If this function returns true
#define MEAN_SUM(suffix, type, zero)
#define FILTER_SAMPLEFMTS(...)
void ff_filter_set_ready(AVFilterContext *filter, unsigned priority)
Mark a filter ready and schedule it for activation.
#define XCORRELATE_BEST(suffix, type, zero, small, sqrtfun, FMAX, CLIP)
static const AVFilterPad outputs[]