Go to the documentation of this file.
38 #define FREQUENCY_DOMAIN 1
105 char *
arg, *tokenizer, *p;
106 uint64_t used_channels = 0;
117 if (used_channels & (1ULL << out_channel)) {
121 used_channels |= (1ULL << out_channel);
122 s->mapping[
s->nb_irs] = out_channel;
128 s->nb_hrir_inputs = 1;
130 s->nb_hrir_inputs =
s->nb_irs;
151 int *write = &
td->write[jobnr];
152 const float *
const ir =
td->ir[jobnr];
153 int *n_clippings = &
td->n_clippings[jobnr];
154 float *ringbuffer =
td->ringbuffer[jobnr];
155 float *temp_src =
td->temp_src[jobnr];
156 const int ir_len =
s->ir_len;
157 const int air_len =
s->air_len;
158 const float *
src = (
const float *)in->
data[0];
159 float *dst = (
float *)
out->data[0];
161 const int buffer_length =
s->buffer_length;
162 const uint32_t modulo = (uint32_t)buffer_length - 1;
169 for (l = 0; l < in_channels; l++) {
170 buffer[l] = ringbuffer + l * buffer_length;
174 const float *cur_ir = ir;
177 for (l = 0; l < in_channels; l++) {
181 for (l = 0; l < in_channels; cur_ir += air_len, l++) {
182 const float *
const bptr =
buffer[l];
184 if (l ==
s->lfe_channel) {
185 *dst += *(
buffer[
s->lfe_channel] + wr) *
s->gain_lfe;
189 read = (wr - (ir_len - 1)) & modulo;
191 if (
read + ir_len < buffer_length) {
192 memcpy(temp_src, bptr +
read, ir_len *
sizeof(*temp_src));
196 memcpy(temp_src, bptr +
read,
len *
sizeof(*temp_src));
197 memcpy(temp_src +
len, bptr, (air_len -
len) *
sizeof(*temp_src));
200 dst[0] +=
s->scalarproduct_float(cur_ir, temp_src,
FFALIGN(ir_len, 32));
203 if (
fabsf(dst[0]) > 1)
208 wr = (wr + 1) & modulo;
222 int *write = &
td->write[jobnr];
224 int *n_clippings = &
td->n_clippings[jobnr];
225 float *ringbuffer =
td->ringbuffer[jobnr];
226 const int ir_len =
s->ir_len;
227 const float *
src = (
const float *)in->
data[0];
228 float *dst = (
float *)
out->data[0];
230 const int buffer_length =
s->buffer_length;
231 const uint32_t modulo = (uint32_t)buffer_length - 1;
239 const int n_fft =
s->n_fft;
240 const float fft_scale = 1.0f /
s->n_fft;
249 for (j = 0; j < n_read; j++) {
250 dst[2 * j] = ringbuffer[wr];
251 ringbuffer[wr] = 0.0;
252 wr = (wr + 1) & modulo;
261 for (
i = 0;
i < in_channels;
i++) {
262 if (
i ==
s->lfe_channel) {
264 dst[2 * j] +=
src[
i + j * in_channels] *
s->gain_lfe;
270 hrtf_offset = hrtf +
s->hrir_map[
i] * n_fft;
275 fft_in[j].
re =
src[j * in_channels +
i];
278 tx_fn(fft, fft_out, fft_in,
sizeof(*fft_in));
280 for (j = 0; j < n_fft; j++) {
282 const float re = fft_out[j].
re;
283 const float im = fft_out[j].
im;
285 fft_acc[j].
re += re * hcomplex->
re - im * hcomplex->
im;
286 fft_acc[j].
im += re * hcomplex->
im + im * hcomplex->
re;
290 itx_fn(ifft, fft_out, fft_acc,
sizeof(*fft_acc));
293 dst[2 * j] += fft_out[j].
re * fft_scale;
294 if (
fabsf(dst[2 * j]) > 1)
298 for (j = 0; j < ir_len - 1; j++) {
299 int write_pos = (wr + j) & modulo;
301 *(ringbuffer + write_pos) += fft_out[in->
nb_samples + j].
re * fft_scale;
313 int ir_len, max_ir_len;
317 if (ir_len > max_ir_len) {
321 s->hrir_in[input_number].ir_len = ir_len;
322 s->ir_len =
FFMAX(ir_len,
s->ir_len);
325 s->hrir_in[input_number].eof = 1;
329 if (!
s->hrir_in[input_number].eof) {
340 int n_clippings[2] = { 0 };
351 td.in = in;
td.out =
out;
td.write =
s->write;
352 td.ir =
s->data_ir;
td.n_clippings = n_clippings;
353 td.ringbuffer =
s->ringbuffer;
td.temp_src =
s->temp_src;
354 td.out_fft =
s->out_fft;
355 td.in_fft =
s->in_fft;
356 td.temp_afft =
s->temp_afft;
364 if (n_clippings[0] + n_clippings[1] > 0) {
366 n_clippings[0] + n_clippings[1],
out->nb_samples * 2);
377 int nb_input_channels =
ctx->inputs[0]->ch_layout.nb_channels;
378 const int nb_hrir_channels =
s->nb_hrir_inputs == 1 ?
ctx->inputs[1]->ch_layout.nb_channels :
s->nb_hrir_inputs * 2;
379 float gain_lin =
expf((
s->gain - 3 * nb_input_channels) / 20 *
M_LN10);
389 s->buffer_length = 1 << (32 -
ff_clz(
s->air_len));
408 if (!
s->fft[0] || !
s->fft[1] || !
s->ifft[0] || !
s->ifft[1]) {
416 s->ringbuffer[0] =
av_calloc(
s->buffer_length,
sizeof(
float) * nb_input_channels);
417 s->ringbuffer[1] =
av_calloc(
s->buffer_length,
sizeof(
float) * nb_input_channels);
419 s->ringbuffer[0] =
av_calloc(
s->buffer_length,
sizeof(
float));
420 s->ringbuffer[1] =
av_calloc(
s->buffer_length,
sizeof(
float));
427 if (!
s->in_fft[0] || !
s->in_fft[1] ||
428 !
s->out_fft[0] || !
s->out_fft[1] ||
429 !
s->temp_afft[0] || !
s->temp_afft[1]) {
435 if (!
s->ringbuffer[0] || !
s->ringbuffer[1]) {
441 s->temp_src[0] =
av_calloc(
s->air_len,
sizeof(
float));
442 s->temp_src[1] =
av_calloc(
s->air_len,
sizeof(
float));
444 s->data_ir[0] =
av_calloc(nb_hrir_channels *
s->air_len,
sizeof(*
s->data_ir[0]));
445 s->data_ir[1] =
av_calloc(nb_hrir_channels *
s->air_len,
sizeof(*
s->data_ir[1]));
446 if (!
s->data_ir[0] || !
s->data_ir[1] || !
s->temp_src[0] || !
s->temp_src[1]) {
451 s->data_hrtf[0] =
av_calloc(
n_fft,
sizeof(*
s->data_hrtf[0]) * nb_hrir_channels);
452 s->data_hrtf[1] =
av_calloc(
n_fft,
sizeof(*
s->data_hrtf[1]) * nb_hrir_channels);
453 if (!
s->data_hrtf[0] || !
s->data_hrtf[1]) {
460 int len =
s->hrir_in[
i].ir_len;
466 ptr = (
float *)
frame->extended_data[0];
474 s->hrir_map[
i] = idx;
476 float *data_ir_l =
s->data_ir[0] + idx *
s->air_len;
477 float *data_ir_r =
s->data_ir[1] + idx *
s->air_len;
479 for (j = 0; j <
len; j++) {
480 data_ir_l[j] = ptr[
len * 2 - j * 2 - 2] * gain_lin;
481 data_ir_r[j] = ptr[
len * 2 - j * 2 - 1] * gain_lin;
489 for (j = 0; j <
len; j++) {
490 fft_in_l[j].
re = ptr[j * 2 ] * gain_lin;
491 fft_in_r[j].
re = ptr[j * 2 + 1] * gain_lin;
494 s->tx_fn[0](
s->fft[0], fft_out_l, fft_in_l,
sizeof(*fft_in_l));
495 s->tx_fn[0](
s->fft[0], fft_out_r, fft_in_r,
sizeof(*fft_in_r));
498 int I,
N =
ctx->inputs[1]->ch_layout.nb_channels;
500 for (k = 0; k <
N / 2; k++) {
506 s->hrir_map[k] = idx;
509 float *data_ir_l =
s->data_ir[0] + idx *
s->air_len;
510 float *data_ir_r =
s->data_ir[1] + idx *
s->air_len;
512 for (j = 0; j <
len; j++) {
513 data_ir_l[j] = ptr[
len *
N - j *
N -
N + I ] * gain_lin;
514 data_ir_r[j] = ptr[
len *
N - j *
N -
N + I + 1] * gain_lin;
522 for (j = 0; j <
len; j++) {
523 fft_in_l[j].
re = ptr[j *
N + I ] * gain_lin;
524 fft_in_r[j].
re = ptr[j *
N + I + 1] * gain_lin;
527 s->tx_fn[0](
s->fft[0], fft_out_l, fft_in_l,
sizeof(*fft_in_l));
528 s->tx_fn[0](
s->fft[0], fft_out_r, fft_in_r,
sizeof(*fft_in_r));
551 for (
i = 0;
i <
s->nb_hrir_inputs;
i++) {
554 if (
s->hrir_in[
i].eof)
560 if (
s->hrir_in[
i].eof) {
563 "HRIR stream %d.\n",
i);
579 }
else if (!
s->have_hrirs)
637 for (
i = 1;
i <=
s->nb_hrir_inputs;
i++) {
652 if (
s->nb_irs <
inlink->ch_layout.nb_channels) {
682 for (
i = 0;
i <
s->nb_hrir_inputs;
i++) {
720 s->gain_lfe =
expf((
s->gain - 3 *
inlink->ch_layout.nb_channels +
s->lfe_gain) / 20 *
M_LN10);
749 #define OFFSET(x) offsetof(HeadphoneContext, x)
750 #define FLAGS AV_OPT_FLAG_AUDIO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
778 .description =
NULL_IF_CONFIG_SMALL(
"Apply headphone binaural spatialization with HRTFs in additional streams."),
780 .priv_class = &headphone_class,
static int convert_coeffs(AVFilterContext *ctx, AVFilterLink *inlink)
AVFrame * ff_get_audio_buffer(AVFilterLink *link, int nb_samples)
Request an audio samples buffer with a specific set of permissions.
A list of supported channel layouts.
#define AV_LOG_WARNING
Something somehow does not look correct.
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf default minimum maximum flags name is the option name
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
AVComplexFloat ** out_fft
#define AV_CHANNEL_LAYOUT_STEREO
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
enum MovChannelLayoutTag * layouts
#define AVERROR_EOF
End of file.
AVComplexFloat * temp_afft[2]
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
char * av_asprintf(const char *fmt,...)
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).
#define FILTER_QUERY_FUNC(func)
const char * name
Filter name.
int nb_channels
Number of channels in this layout.
A link between two filters.
av_cold int av_tx_init(AVTXContext **ctx, av_tx_fn *tx, enum AVTXType type, int inv, int len, const void *scale, uint64_t flags)
Initialize a transform context with the given configuration (i)MDCTs with an odd length are currently...
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
AVComplexFloat * data_hrtf[2]
#define FF_FILTER_FORWARD_STATUS_BACK_ALL(outlink, filter)
Forward the status on an output link to all input links.
int ff_append_inpad(AVFilterContext *f, AVFilterPad *p)
Append a new input/output pad to the filter's list of such pads.
float(* scalarproduct_float)(const float *v1, const float *v2, int len)
static int activate(AVFilterContext *ctx)
AVChannelLayout ch_layout
Channel layout of the audio data.
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf type
#define AVFILTER_FLAG_DYNAMIC_INPUTS
The number of the filter inputs is not determined just by AVFilter.inputs.
static __device__ float fabsf(float a)
static int config_input(AVFilterLink *inlink)
A filter pad used for either input or output.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
int ff_inlink_check_available_samples(AVFilterLink *link, unsigned min)
Test if enough samples are available on the link.
void(* av_tx_fn)(AVTXContext *s, void *out, void *in, ptrdiff_t stride)
Function pointer to a function to perform the transform.
float(* scalarproduct_float)(const float *v1, const float *v2, int len)
Calculate the scalar product of two vectors of floats.
void ff_inlink_request_frame(AVFilterLink *link)
Mark that a frame is wanted on the link.
int av_channel_layout_from_mask(AVChannelLayout *channel_layout, uint64_t mask)
Initialize a native channel layout from a bitmask indicating which channels are present.
char * av_strtok(char *s, const char *delim, char **saveptr)
Split the string into several tokens which can be accessed by successive calls to av_strtok().
@ AV_TX_FLOAT_FFT
Standard complex to complex FFT with sample data type of AVComplexFloat, AVComplexDouble or AVComplex...
static int parse_channel_name(const char *arg, enum AVChannel *rchannel)
static av_cold void uninit(AVFilterContext *ctx)
static int headphone_convolute(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
Describe the class of an AVClass context structure.
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 void parse_map(AVFilterContext *ctx)
int ff_append_inpad_free_name(AVFilterContext *f, AVFilterPad *p)
static const AVFilterPad outputs[]
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 inputs
static int query_formats(AVFilterContext *ctx)
AVFILTER_DEFINE_CLASS(headphone)
static int headphone_frame(HeadphoneContext *s, AVFrame *in, AVFilterLink *outlink)
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
An AVChannelLayout holds information about the channel layout of audio data.
AVFilterContext * src
source filter
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf offset
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
av_cold void av_tx_uninit(AVTXContext **ctx)
Frees a context and sets *ctx to NULL, does nothing when *ctx == NULL.
static const AVOption headphone_options[]
int nb_samples
number of audio samples (per channel) described by this frame
#define i(width, name, range_min, range_max)
static av_cold int init(AVFilterContext *ctx)
Used for passing data between threads.
enum AVChannel mapping[64]
const char * name
Pad name.
int ff_inlink_queued_samples(AVFilterLink *link)
void * av_calloc(size_t nmemb, size_t size)
AVComplexFloat * in_fft[2]
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
enum AVChannel av_channel_from_string(const char *str)
This is the inverse function of av_channel_name().
AVComplexFloat ** temp_afft
AVChannelLayout map_channel_layout
the frame and frame reference mechanism is intended to as much as expensive copies of that data while still allowing the filters to produce correct results The data is stored in buffers represented by AVFrame structures Several references can point to the same frame buffer
int av_channel_layout_index_from_channel(const AVChannelLayout *channel_layout, enum AVChannel channel)
Get the index of a given channel in a channel layout.
static int headphone_fast_convolute(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
#define AVFILTER_FLAG_SLICE_THREADS
The filter supports multithreading by splitting frames into multiple parts and processing them concur...
const VDPAUPixFmtMap * map
AVChannelLayout ch_layout
channel layout of current buffer (see libavutil/channel_layout.h)
static void scale(int *out, const int *in, const int w, const int h, const int shift)
FF_FILTER_FORWARD_STATUS(inlink, outlink)
#define FILTER_OUTPUTS(array)
const AVFilter ff_af_headphone
av_cold AVFloatDSPContext * avpriv_float_dsp_alloc(int bit_exact)
Allocate a float DSP context.
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
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
static av_always_inline int ff_filter_execute(AVFilterContext *ctx, avfilter_action_func *func, void *arg, int *ret, int nb_jobs)
struct HeadphoneContext::hrir_inputs hrir_in[64]
static int config_output(AVFilterLink *outlink)
AVComplexFloat * out_fft[2]
static uint32_t BS_FUNC() read(BSCTX *bc, unsigned int n)
Return n bits from the buffer, n has to be in the 0-32 range.
void ff_filter_set_ready(AVFilterContext *filter, unsigned priority)
Mark a filter ready and schedule it for activation.
static int check_ir(AVFilterLink *inlink, int input_number)