Go to the documentation of this file.
50 #define MEAN_SUM(suffix, type, zero) \
51 static type mean_sum_##suffix(const type *in, \
54 type mean_sum = zero; \
56 for (int i = 0; i < size; i++) \
65 #define SQUARE_SUM(suffix, type, zero) \
66 static type square_sum_##suffix(const type *x, \
70 type square_sum = zero; \
72 for (int i = 0; i < size; i++) \
73 square_sum += x[i] * y[i]; \
81 #define XCORRELATE(suffix, type, zero, small, sqrtfun)\
82 static type xcorrelate_##suffix(const type *x, \
85 type sumy, int size) \
87 const type xm = sumx / size, ym = sumy / size; \
88 type num = zero, den, den0 = zero, den1 = zero; \
90 for (int i = 0; i < size; i++) { \
91 type xd = x[i] - xm; \
92 type yd = y[i] - ym; \
100 den = sqrtfun((den0 * den1) / size / size); \
102 return den <= small ? zero : num / den; \
108 #define XCORRELATE_SLOW(suffix, type) \
109 static int xcorrelate_slow_##suffix(AVFilterContext *ctx, \
110 AVFrame *out, int available) \
112 AudioXCorrelateContext *s = ctx->priv; \
113 const int size = FFMIN(available, s->size); \
116 for (int ch = 0; ch < out->ch_layout.nb_channels; ch++) { \
117 const type *x = (const type *)s->cache[0]->extended_data[ch]; \
118 const type *y = (const type *)s->cache[1]->extended_data[ch]; \
119 type *sumx = (type *)s->mean_sum[0]->extended_data[ch]; \
120 type *sumy = (type *)s->mean_sum[1]->extended_data[ch]; \
121 type *dst = (type *)out->extended_data[ch]; \
125 sumx[0] = mean_sum_##suffix(x, size); \
126 sumy[0] = mean_sum_##suffix(y, size); \
130 for (int n = 0; n < out->nb_samples; n++) { \
131 const int idx = available <= s->size ? out->nb_samples - n - 1 : n + size; \
133 dst[n] = xcorrelate_##suffix(x + n, y + n, \
150 #define XCORRELATE_FAST(suffix, type, zero, small, sqrtfun) \
151 static int xcorrelate_fast_##suffix(AVFilterContext *ctx, AVFrame *out, \
154 AudioXCorrelateContext *s = ctx->priv; \
155 const int size = FFMIN(available, s->size); \
158 for (int ch = 0; ch < out->ch_layout.nb_channels; ch++) { \
159 const type *x = (const type *)s->cache[0]->extended_data[ch]; \
160 const type *y = (const type *)s->cache[1]->extended_data[ch]; \
161 type *num_sum = (type *)s->num_sum->extended_data[ch]; \
162 type *den_sumx = (type *)s->den_sum[0]->extended_data[ch]; \
163 type *den_sumy = (type *)s->den_sum[1]->extended_data[ch]; \
164 type *dst = (type *)out->extended_data[ch]; \
168 num_sum[0] = square_sum_##suffix(x, y, size); \
169 den_sumx[0] = square_sum_##suffix(x, x, size); \
170 den_sumy[0] = square_sum_##suffix(y, y, size); \
174 for (int n = 0; n < out->nb_samples; n++) { \
175 const int idx = available <= s->size ? out->nb_samples - n - 1 : n + size; \
178 num = num_sum[0] / size; \
179 den = sqrtfun((den_sumx[0] * den_sumy[0]) / size / size); \
181 dst[n] = den <= small ? zero : num / den; \
183 num_sum[0] -= x[n] * y[n]; \
184 num_sum[0] += x[idx] * y[idx]; \
185 den_sumx[0] -= x[n] * x[n]; \
186 den_sumx[0] += x[idx] * x[idx]; \
187 den_sumx[0] = FFMAX(den_sumx[0], zero); \
188 den_sumy[0] -= y[n] * y[n]; \
189 den_sumy[0] += y[idx] * y[idx]; \
190 den_sumy[0] = FFMAX(den_sumy[0], zero); \
210 for (
int i = 0;
i < 2;
i++) {
228 if (!
s->cache[0] ||
s->cache[0]->nb_samples <
available) {
235 if (!
s->cache[1] ||
s->cache[1]->nb_samples <
available) {
257 s->pts += out_samples;
265 for (
int i = 0;
i < 2 && !
s->eof;
i++) {
284 for (
int i = 0;
i < 2;
i++) {
304 if (!
s->fifo[0] || !
s->fifo[1])
312 if (!
s->mean_sum[0] || !
s->mean_sum[1] || !
s->num_sum ||
313 !
s->den_sum[0] || !
s->den_sum[1])
317 case 0:
s->xcorrelate = xcorrelate_slow_f;
break;
318 case 1:
s->xcorrelate = xcorrelate_fast_f;
break;
323 case 0:
s->xcorrelate = xcorrelate_slow_d;
break;
324 case 1:
s->xcorrelate = xcorrelate_fast_d;
break;
348 .
name =
"axcorrelate0",
352 .name =
"axcorrelate1",
365 #define AF AV_OPT_FLAG_AUDIO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
366 #define OFFSET(x) offsetof(AudioXCorrelateContext, x)
379 .
name =
"axcorrelate",
382 .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
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
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.
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.
const char * name
Filter name.
int nb_channels
Number of channels in this layout.
A link between two filters.
#define XCORRELATE_FAST(suffix, type, zero, small, sqrtfun)
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)
int av_audio_fifo_write(AVAudioFifo *af, void **data, int nb_samples)
Write data to an AVAudioFifo.
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.
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_size(AVAudioFifo *af)
Get the current number of samples in the AVAudioFifo available for reading.
static av_cold void uninit(AVFilterContext *ctx)
#define i(width, name, range_min, range_max)
static const AVOption axcorrelate_options[]
static const AVFilterPad inputs[]
const char * name
Pad name.
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several the filter must be ready for frames arriving randomly on any input any filter with several inputs will most likely require some kind of queuing mechanism It is perfectly acceptable to have a limited queue and to drop frames when the inputs are too unbalanced request_frame For filters that do not use the this method is called when a frame is wanted on an output For a it should directly call filter_frame on the corresponding output For a if there are queued frames already one of these frames should be pushed If the filter should request a frame on one of its repeatedly until at least one frame has been pushed Return or at least make progress towards producing a frame
static int activate(AVFilterContext *ctx)
@ 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
int av_audio_fifo_peek(AVAudioFifo *af, void **data, int nb_samples)
Peek data from an AVAudioFifo.
#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.
static const AVFilterPad outputs[]