2 * Copyright (C) 2017 Paul B Mahol
3 * Copyright (C) 2013-2015 Andreas Fuchs, Wolfgang Hrauda
4 * This file is part of FFmpeg.
6 * FFmpeg is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * FFmpeg is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with FFmpeg; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23 #include "libavutil/avstring.h"
24 #include "libavutil/channel_layout.h"
25 #include "libavutil/float_dsp.h"
26 #include "libavutil/intmath.h"
27 #include "libavutil/opt.h"
28 #include "libavcodec/avfft.h"
36 #define FREQUENCY_DOMAIN 1
41 typedef struct HeadphoneContext {
60 float lfe_gain, gain_lfe;
72 FFTComplex *temp_fft[2];
73 FFTComplex *temp_afft[2];
75 FFTContext *fft[2], *ifft[2];
76 FFTComplex *data_hrtf[2];
78 AVFloatDSPContext *fdsp;
79 struct headphone_inputs {
87 static int parse_channel_name(const char *arg, uint64_t *rchannel)
89 uint64_t layout = av_get_channel_layout(arg);
91 if (av_get_channel_layout_nb_channels(layout) != 1)
92 return AVERROR(EINVAL);
97 static void parse_map(AVFilterContext *ctx)
99 HeadphoneContext *s = ctx->priv;
100 char *arg, *tokenizer, *p;
101 uint64_t used_channels = 0;
107 while ((arg = av_strtok(p, "|", &tokenizer))) {
108 uint64_t out_channel;
111 if (parse_channel_name(arg, &out_channel)) {
112 av_log(ctx, AV_LOG_WARNING, "Failed to parse \'%s\' as channel name.\n", arg);
115 if (used_channels & out_channel) {
116 av_log(ctx, AV_LOG_WARNING, "Ignoring duplicate channel '%s'.\n", arg);
119 used_channels |= out_channel;
120 if (out_channel == AV_CH_LOW_FREQUENCY)
121 s->lfe_channel = s->nb_irs;
122 s->mapping[s->nb_irs] = out_channel;
126 if (s->hrir_fmt == HRIR_MULTI)
129 s->nb_inputs = s->nb_irs + 1;
132 typedef struct ThreadData {
139 FFTComplex **temp_fft;
140 FFTComplex **temp_afft;
143 static int headphone_convolute(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
145 HeadphoneContext *s = ctx->priv;
146 ThreadData *td = arg;
147 AVFrame *in = td->in, *out = td->out;
149 int *write = &td->write[jobnr];
150 const float *const ir = td->ir[jobnr];
151 int *n_clippings = &td->n_clippings[jobnr];
152 float *ringbuffer = td->ringbuffer[jobnr];
153 float *temp_src = td->temp_src[jobnr];
154 const int ir_len = s->ir_len;
155 const int air_len = s->air_len;
156 const float *src = (const float *)in->data[0];
157 float *dst = (float *)out->data[0];
158 const int in_channels = in->channels;
159 const int buffer_length = s->buffer_length;
160 const uint32_t modulo = (uint32_t)buffer_length - 1;
167 for (l = 0; l < in_channels; l++) {
168 buffer[l] = ringbuffer + l * buffer_length;
171 for (i = 0; i < in->nb_samples; i++) {
172 const float *temp_ir = ir;
175 for (l = 0; l < in_channels; l++) {
176 *(buffer[l] + wr) = src[l];
179 for (l = 0; l < in_channels; l++) {
180 const float *const bptr = buffer[l];
182 if (l == s->lfe_channel) {
183 *dst += *(buffer[s->lfe_channel] + wr) * s->gain_lfe;
188 read = (wr - (ir_len - 1) + buffer_length) & modulo;
190 if (read + ir_len < buffer_length) {
191 memcpy(temp_src, bptr + read, ir_len * sizeof(*temp_src));
193 int len = FFMIN(air_len - (read % ir_len), buffer_length - read);
195 memcpy(temp_src, bptr + read, len * sizeof(*temp_src));
196 memcpy(temp_src + len, bptr, (air_len - len) * sizeof(*temp_src));
199 dst[0] += s->fdsp->scalarproduct_float(temp_ir, temp_src, FFALIGN(ir_len, 32));
203 if (fabsf(dst[0]) > 1)
208 wr = (wr + 1) & modulo;
216 static int headphone_fast_convolute(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
218 HeadphoneContext *s = ctx->priv;
219 ThreadData *td = arg;
220 AVFrame *in = td->in, *out = td->out;
222 int *write = &td->write[jobnr];
223 FFTComplex *hrtf = s->data_hrtf[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];
229 const int in_channels = in->channels;
230 const int buffer_length = s->buffer_length;
231 const uint32_t modulo = (uint32_t)buffer_length - 1;
232 FFTComplex *fft_in = s->temp_fft[jobnr];
233 FFTComplex *fft_acc = s->temp_afft[jobnr];
234 FFTContext *ifft = s->ifft[jobnr];
235 FFTContext *fft = s->fft[jobnr];
236 const int n_fft = s->n_fft;
237 const float fft_scale = 1.0f / s->n_fft;
238 FFTComplex *hrtf_offset;
245 n_read = FFMIN(ir_len, in->nb_samples);
246 for (j = 0; j < n_read; j++) {
247 dst[2 * j] = ringbuffer[wr];
248 ringbuffer[wr] = 0.0;
249 wr = (wr + 1) & modulo;
252 for (j = n_read; j < in->nb_samples; j++) {
256 memset(fft_acc, 0, sizeof(FFTComplex) * n_fft);
258 for (i = 0; i < in_channels; i++) {
259 if (i == s->lfe_channel) {
260 for (j = 0; j < in->nb_samples; j++) {
261 dst[2 * j] += src[i + j * in_channels] * s->gain_lfe;
267 hrtf_offset = hrtf + offset;
269 memset(fft_in, 0, sizeof(FFTComplex) * n_fft);
271 for (j = 0; j < in->nb_samples; j++) {
272 fft_in[j].re = src[j * in_channels + i];
275 av_fft_permute(fft, fft_in);
276 av_fft_calc(fft, fft_in);
277 for (j = 0; j < n_fft; j++) {
278 const FFTComplex *hcomplex = hrtf_offset + j;
279 const float re = fft_in[j].re;
280 const float im = fft_in[j].im;
282 fft_acc[j].re += re * hcomplex->re - im * hcomplex->im;
283 fft_acc[j].im += re * hcomplex->im + im * hcomplex->re;
287 av_fft_permute(ifft, fft_acc);
288 av_fft_calc(ifft, fft_acc);
290 for (j = 0; j < in->nb_samples; j++) {
291 dst[2 * j] += fft_acc[j].re * fft_scale;
294 for (j = 0; j < ir_len - 1; j++) {
295 int write_pos = (wr + j) & modulo;
297 *(ringbuffer + write_pos) += fft_acc[in->nb_samples + j].re * fft_scale;
300 for (i = 0; i < out->nb_samples; i++) {
301 if (fabsf(dst[0]) > 1) {
313 static int check_ir(AVFilterLink *inlink, int input_number)
315 AVFilterContext *ctx = inlink->dst;
316 HeadphoneContext *s = ctx->priv;
317 int ir_len, max_ir_len;
319 ir_len = ff_inlink_queued_samples(inlink);
321 if (ir_len > max_ir_len) {
322 av_log(ctx, AV_LOG_ERROR, "Too big length of IRs: %d > %d.\n", ir_len, max_ir_len);
323 return AVERROR(EINVAL);
325 s->in[input_number].ir_len = ir_len;
326 s->ir_len = FFMAX(ir_len, s->ir_len);
331 static int headphone_frame(HeadphoneContext *s, AVFrame *in, AVFilterLink *outlink)
333 AVFilterContext *ctx = outlink->src;
334 int n_clippings[2] = { 0 };
338 out = ff_get_audio_buffer(outlink, in->nb_samples);
341 return AVERROR(ENOMEM);
345 td.in = in; td.out = out; td.write = s->write;
346 td.ir = s->data_ir; td.n_clippings = n_clippings;
347 td.ringbuffer = s->ringbuffer; td.temp_src = s->temp_src;
348 td.temp_fft = s->temp_fft;
349 td.temp_afft = s->temp_afft;
351 if (s->type == TIME_DOMAIN) {
352 ctx->internal->execute(ctx, headphone_convolute, &td, NULL, 2);
354 ctx->internal->execute(ctx, headphone_fast_convolute, &td, NULL, 2);
358 if (n_clippings[0] + n_clippings[1] > 0) {
359 av_log(ctx, AV_LOG_WARNING, "%d of %d samples clipped. Please reduce gain.\n",
360 n_clippings[0] + n_clippings[1], out->nb_samples * 2);
364 return ff_filter_frame(outlink, out);
367 static int convert_coeffs(AVFilterContext *ctx, AVFilterLink *inlink)
369 struct HeadphoneContext *s = ctx->priv;
370 const int ir_len = s->ir_len;
371 int nb_irs = s->nb_irs;
372 int nb_input_channels = ctx->inputs[0]->channels;
373 float gain_lin = expf((s->gain - 3 * nb_input_channels) / 20 * M_LN10);
374 FFTComplex *data_hrtf_l = NULL;
375 FFTComplex *data_hrtf_r = NULL;
376 FFTComplex *fft_in_l = NULL;
377 FFTComplex *fft_in_r = NULL;
378 int offset = 0, ret = 0;
382 s->air_len = 1 << (32 - ff_clz(ir_len));
383 if (s->type == TIME_DOMAIN) {
384 s->air_len = FFALIGN(s->air_len, 32);
386 s->buffer_length = 1 << (32 - ff_clz(s->air_len));
387 s->n_fft = n_fft = 1 << (32 - ff_clz(ir_len + s->size));
389 if (s->type == FREQUENCY_DOMAIN) {
390 fft_in_l = av_calloc(n_fft, sizeof(*fft_in_l));
391 fft_in_r = av_calloc(n_fft, sizeof(*fft_in_r));
392 if (!fft_in_l || !fft_in_r) {
393 ret = AVERROR(ENOMEM);
397 s->fft[0] = av_fft_init(av_log2(s->n_fft), 0);
398 s->fft[1] = av_fft_init(av_log2(s->n_fft), 0);
399 s->ifft[0] = av_fft_init(av_log2(s->n_fft), 1);
400 s->ifft[1] = av_fft_init(av_log2(s->n_fft), 1);
402 if (!s->fft[0] || !s->fft[1] || !s->ifft[0] || !s->ifft[1]) {
403 av_log(ctx, AV_LOG_ERROR, "Unable to create FFT contexts of size %d.\n", s->n_fft);
404 ret = AVERROR(ENOMEM);
409 if (s->type == TIME_DOMAIN) {
410 s->ringbuffer[0] = av_calloc(s->buffer_length, sizeof(float) * nb_input_channels);
411 s->ringbuffer[1] = av_calloc(s->buffer_length, sizeof(float) * nb_input_channels);
413 s->ringbuffer[0] = av_calloc(s->buffer_length, sizeof(float));
414 s->ringbuffer[1] = av_calloc(s->buffer_length, sizeof(float));
415 s->temp_fft[0] = av_calloc(s->n_fft, sizeof(FFTComplex));
416 s->temp_fft[1] = av_calloc(s->n_fft, sizeof(FFTComplex));
417 s->temp_afft[0] = av_calloc(s->n_fft, sizeof(FFTComplex));
418 s->temp_afft[1] = av_calloc(s->n_fft, sizeof(FFTComplex));
419 if (!s->temp_fft[0] || !s->temp_fft[1] ||
420 !s->temp_afft[0] || !s->temp_afft[1]) {
421 ret = AVERROR(ENOMEM);
426 if (!s->ringbuffer[0] || !s->ringbuffer[1]) {
427 ret = AVERROR(ENOMEM);
431 if (s->type == TIME_DOMAIN) {
432 s->temp_src[0] = av_calloc(s->air_len, sizeof(float));
433 s->temp_src[1] = av_calloc(s->air_len, sizeof(float));
435 s->data_ir[0] = av_calloc(nb_irs * s->air_len, sizeof(*s->data_ir[0]));
436 s->data_ir[1] = av_calloc(nb_irs * s->air_len, sizeof(*s->data_ir[1]));
437 if (!s->data_ir[0] || !s->data_ir[1] || !s->temp_src[0] || !s->temp_src[1]) {
438 ret = AVERROR(ENOMEM);
442 data_hrtf_l = av_calloc(n_fft, sizeof(*data_hrtf_l) * nb_irs);
443 data_hrtf_r = av_calloc(n_fft, sizeof(*data_hrtf_r) * nb_irs);
444 if (!data_hrtf_r || !data_hrtf_l) {
445 ret = AVERROR(ENOMEM);
450 for (i = 0; i < s->nb_inputs - 1; i++) {
451 int len = s->in[i + 1].ir_len;
454 ret = ff_inlink_consume_samples(ctx->inputs[i + 1], len, len, &s->in[i + 1].frame);
457 ptr = (float *)s->in[i + 1].frame->extended_data[0];
459 if (s->hrir_fmt == HRIR_STEREO) {
462 for (j = 0; j < inlink->channels; j++) {
463 if ((av_channel_layout_extract_channel(inlink->channel_layout, j)) == s->mapping[i]) {
471 if (s->type == TIME_DOMAIN) {
472 float *data_ir_l = s->data_ir[0] + idx * s->air_len;
473 float *data_ir_r = s->data_ir[1] + idx * s->air_len;
475 for (j = 0; j < len; j++) {
476 data_ir_l[j] = ptr[len * 2 - j * 2 - 2] * gain_lin;
477 data_ir_r[j] = ptr[len * 2 - j * 2 - 1] * gain_lin;
480 memset(fft_in_l, 0, n_fft * sizeof(*fft_in_l));
481 memset(fft_in_r, 0, n_fft * sizeof(*fft_in_r));
483 offset = idx * n_fft;
484 for (j = 0; j < len; j++) {
485 fft_in_l[j].re = ptr[j * 2 ] * gain_lin;
486 fft_in_r[j].re = ptr[j * 2 + 1] * gain_lin;
489 av_fft_permute(s->fft[0], fft_in_l);
490 av_fft_calc(s->fft[0], fft_in_l);
491 memcpy(data_hrtf_l + offset, fft_in_l, n_fft * sizeof(*fft_in_l));
492 av_fft_permute(s->fft[0], fft_in_r);
493 av_fft_calc(s->fft[0], fft_in_r);
494 memcpy(data_hrtf_r + offset, fft_in_r, n_fft * sizeof(*fft_in_r));
497 int I, N = ctx->inputs[1]->channels;
499 for (k = 0; k < N / 2; k++) {
502 for (j = 0; j < inlink->channels; j++) {
503 if ((av_channel_layout_extract_channel(inlink->channel_layout, j)) == s->mapping[k]) {
512 if (s->type == TIME_DOMAIN) {
513 float *data_ir_l = s->data_ir[0] + idx * s->air_len;
514 float *data_ir_r = s->data_ir[1] + idx * s->air_len;
516 for (j = 0; j < len; j++) {
517 data_ir_l[j] = ptr[len * N - j * N - N + I ] * gain_lin;
518 data_ir_r[j] = ptr[len * N - j * N - N + I + 1] * gain_lin;
521 memset(fft_in_l, 0, n_fft * sizeof(*fft_in_l));
522 memset(fft_in_r, 0, n_fft * sizeof(*fft_in_r));
524 offset = idx * n_fft;
525 for (j = 0; j < len; j++) {
526 fft_in_l[j].re = ptr[j * N + I ] * gain_lin;
527 fft_in_r[j].re = ptr[j * N + I + 1] * gain_lin;
530 av_fft_permute(s->fft[0], fft_in_l);
531 av_fft_calc(s->fft[0], fft_in_l);
532 memcpy(data_hrtf_l + offset, fft_in_l, n_fft * sizeof(*fft_in_l));
533 av_fft_permute(s->fft[0], fft_in_r);
534 av_fft_calc(s->fft[0], fft_in_r);
535 memcpy(data_hrtf_r + offset, fft_in_r, n_fft * sizeof(*fft_in_r));
540 av_frame_free(&s->in[i + 1].frame);
543 if (s->type == FREQUENCY_DOMAIN) {
544 s->data_hrtf[0] = av_calloc(n_fft * s->nb_irs, sizeof(FFTComplex));
545 s->data_hrtf[1] = av_calloc(n_fft * s->nb_irs, sizeof(FFTComplex));
546 if (!s->data_hrtf[0] || !s->data_hrtf[1]) {
547 ret = AVERROR(ENOMEM);
551 memcpy(s->data_hrtf[0], data_hrtf_l,
552 sizeof(FFTComplex) * nb_irs * n_fft);
553 memcpy(s->data_hrtf[1], data_hrtf_r,
554 sizeof(FFTComplex) * nb_irs * n_fft);
561 for (i = 0; i < s->nb_inputs - 1; i++)
562 av_frame_free(&s->in[i + 1].frame);
564 av_freep(&data_hrtf_l);
565 av_freep(&data_hrtf_r);
573 static int activate(AVFilterContext *ctx)
575 HeadphoneContext *s = ctx->priv;
576 AVFilterLink *inlink = ctx->inputs[0];
577 AVFilterLink *outlink = ctx->outputs[0];
581 FF_FILTER_FORWARD_STATUS_BACK_ALL(ctx->outputs[0], ctx);
584 for (i = 1; i < s->nb_inputs; i++) {
588 if ((ret = check_ir(ctx->inputs[i], i)) < 0)
591 if (ff_outlink_get_status(ctx->inputs[i]) == AVERROR_EOF) {
592 if (!ff_inlink_queued_samples(ctx->inputs[i])) {
593 av_log(ctx, AV_LOG_ERROR, "No samples provided for "
594 "HRIR stream %d.\n", i - 1);
595 return AVERROR_INVALIDDATA;
599 if (ff_outlink_frame_wanted(ctx->outputs[0]))
600 ff_inlink_request_frame(ctx->inputs[i]);
608 ret = convert_coeffs(ctx, inlink);
611 } else if (!s->have_hrirs)
614 if ((ret = ff_inlink_consume_samples(ctx->inputs[0], s->size, s->size, &in)) > 0) {
615 ret = headphone_frame(s, in, outlink);
623 FF_FILTER_FORWARD_STATUS(ctx->inputs[0], ctx->outputs[0]);
624 if (ff_outlink_frame_wanted(ctx->outputs[0]))
625 ff_inlink_request_frame(ctx->inputs[0]);
630 static int query_formats(AVFilterContext *ctx)
632 struct HeadphoneContext *s = ctx->priv;
633 AVFilterFormats *formats = NULL;
634 AVFilterChannelLayouts *layouts = NULL;
635 AVFilterChannelLayouts *stereo_layout = NULL;
636 AVFilterChannelLayouts *hrir_layouts = NULL;
639 ret = ff_add_format(&formats, AV_SAMPLE_FMT_FLT);
642 ret = ff_set_common_formats(ctx, formats);
646 layouts = ff_all_channel_layouts();
648 return AVERROR(ENOMEM);
650 ret = ff_channel_layouts_ref(layouts, &ctx->inputs[0]->outcfg.channel_layouts);
654 ret = ff_add_channel_layout(&stereo_layout, AV_CH_LAYOUT_STEREO);
657 ret = ff_channel_layouts_ref(stereo_layout, &ctx->outputs[0]->incfg.channel_layouts);
661 if (s->hrir_fmt == HRIR_MULTI) {
662 hrir_layouts = ff_all_channel_counts();
664 return AVERROR(ENOMEM);
665 ret = ff_channel_layouts_ref(hrir_layouts, &ctx->inputs[1]->outcfg.channel_layouts);
669 for (i = 1; i < s->nb_inputs; i++) {
670 ret = ff_channel_layouts_ref(stereo_layout, &ctx->inputs[i]->outcfg.channel_layouts);
676 formats = ff_all_samplerates();
678 return AVERROR(ENOMEM);
679 return ff_set_common_samplerates(ctx, formats);
682 static int config_input(AVFilterLink *inlink)
684 AVFilterContext *ctx = inlink->dst;
685 HeadphoneContext *s = ctx->priv;
687 if (s->nb_irs < inlink->channels) {
688 av_log(ctx, AV_LOG_ERROR, "Number of HRIRs must be >= %d.\n", inlink->channels);
689 return AVERROR(EINVAL);
695 static av_cold int init(AVFilterContext *ctx)
697 HeadphoneContext *s = ctx->priv;
702 .type = AVMEDIA_TYPE_AUDIO,
703 .config_props = config_input,
705 if ((ret = ff_insert_inpad(ctx, 0, &pad)) < 0)
709 av_log(ctx, AV_LOG_ERROR, "Valid mapping must be set.\n");
710 return AVERROR(EINVAL);
715 s->in = av_calloc(s->nb_inputs, sizeof(*s->in));
717 return AVERROR(ENOMEM);
719 for (i = 1; i < s->nb_inputs; i++) {
720 char *name = av_asprintf("hrir%d", i - 1);
723 .type = AVMEDIA_TYPE_AUDIO,
726 return AVERROR(ENOMEM);
727 if ((ret = ff_insert_inpad(ctx, i, &pad)) < 0) {
733 s->fdsp = avpriv_float_dsp_alloc(0);
735 return AVERROR(ENOMEM);
740 static int config_output(AVFilterLink *outlink)
742 AVFilterContext *ctx = outlink->src;
743 HeadphoneContext *s = ctx->priv;
744 AVFilterLink *inlink = ctx->inputs[0];
746 if (s->hrir_fmt == HRIR_MULTI) {
747 AVFilterLink *hrir_link = ctx->inputs[1];
749 if (hrir_link->channels < inlink->channels * 2) {
750 av_log(ctx, AV_LOG_ERROR, "Number of channels in HRIR stream must be >= %d.\n", inlink->channels * 2);
751 return AVERROR(EINVAL);
755 s->gain_lfe = expf((s->gain - 3 * inlink->channels + s->lfe_gain) / 20 * M_LN10);
760 static av_cold void uninit(AVFilterContext *ctx)
762 HeadphoneContext *s = ctx->priv;
764 av_fft_end(s->ifft[0]);
765 av_fft_end(s->ifft[1]);
766 av_fft_end(s->fft[0]);
767 av_fft_end(s->fft[1]);
768 av_freep(&s->data_ir[0]);
769 av_freep(&s->data_ir[1]);
770 av_freep(&s->ringbuffer[0]);
771 av_freep(&s->ringbuffer[1]);
772 av_freep(&s->temp_src[0]);
773 av_freep(&s->temp_src[1]);
774 av_freep(&s->temp_fft[0]);
775 av_freep(&s->temp_fft[1]);
776 av_freep(&s->temp_afft[0]);
777 av_freep(&s->temp_afft[1]);
778 av_freep(&s->data_hrtf[0]);
779 av_freep(&s->data_hrtf[1]);
783 for (unsigned i = 1; i < ctx->nb_inputs; i++)
784 av_freep(&ctx->input_pads[i].name);
787 #define OFFSET(x) offsetof(HeadphoneContext, x)
788 #define FLAGS AV_OPT_FLAG_AUDIO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
790 static const AVOption headphone_options[] = {
791 { "map", "set channels convolution mappings", OFFSET(map), AV_OPT_TYPE_STRING, {.str=NULL}, .flags = FLAGS },
792 { "gain", "set gain in dB", OFFSET(gain), AV_OPT_TYPE_FLOAT, {.dbl=0}, -20, 40, .flags = FLAGS },
793 { "lfe", "set lfe gain in dB", OFFSET(lfe_gain), AV_OPT_TYPE_FLOAT, {.dbl=0}, -20, 40, .flags = FLAGS },
794 { "type", "set processing", OFFSET(type), AV_OPT_TYPE_INT, {.i64=1}, 0, 1, .flags = FLAGS, "type" },
795 { "time", "time domain", 0, AV_OPT_TYPE_CONST, {.i64=0}, 0, 0, .flags = FLAGS, "type" },
796 { "freq", "frequency domain", 0, AV_OPT_TYPE_CONST, {.i64=1}, 0, 0, .flags = FLAGS, "type" },
797 { "size", "set frame size", OFFSET(size), AV_OPT_TYPE_INT, {.i64=1024},1024,96000, .flags = FLAGS },
798 { "hrir", "set hrir format", OFFSET(hrir_fmt), AV_OPT_TYPE_INT, {.i64=HRIR_STEREO}, 0, 1, .flags = FLAGS, "hrir" },
799 { "stereo", "hrir files have exactly 2 channels", 0, AV_OPT_TYPE_CONST, {.i64=HRIR_STEREO}, 0, 0, .flags = FLAGS, "hrir" },
800 { "multich", "single multichannel hrir file", 0, AV_OPT_TYPE_CONST, {.i64=HRIR_MULTI}, 0, 0, .flags = FLAGS, "hrir" },
804 AVFILTER_DEFINE_CLASS(headphone);
806 static const AVFilterPad outputs[] = {
809 .type = AVMEDIA_TYPE_AUDIO,
810 .config_props = config_output,
815 AVFilter ff_af_headphone = {
817 .description = NULL_IF_CONFIG_SMALL("Apply headphone binaural spatialization with HRTFs in additional streams."),
818 .priv_size = sizeof(HeadphoneContext),
819 .priv_class = &headphone_class,
822 .query_formats = query_formats,
823 .activate = activate,
826 .flags = AVFILTER_FLAG_SLICE_THREADS | AVFILTER_FLAG_DYNAMIC_INPUTS,