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 {
61 float lfe_gain, gain_lfe;
74 FFTComplex *temp_fft[2];
76 FFTContext *fft[2], *ifft[2];
77 FFTComplex *data_hrtf[2];
79 AVFloatDSPContext *fdsp;
80 struct headphone_inputs {
89 static int parse_channel_name(HeadphoneContext *s, int x, char **arg, int *rchannel, char *buf)
91 int len, i, channel_id = 0;
92 int64_t layout, layout0;
94 if (sscanf(*arg, "%7[A-Z]%n", buf, &len)) {
95 layout0 = layout = av_get_channel_layout(buf);
96 if (layout == AV_CH_LOW_FREQUENCY)
98 for (i = 32; i > 0; i >>= 1) {
99 if (layout >= 1LL << i) {
104 if (channel_id >= 64 || layout0 != 1LL << channel_id)
105 return AVERROR(EINVAL);
106 *rchannel = channel_id;
110 return AVERROR(EINVAL);
113 static void parse_map(AVFilterContext *ctx)
115 HeadphoneContext *s = ctx->priv;
116 char *arg, *tokenizer, *p, *args = av_strdup(s->map);
126 for (i = 0; i < 64; i++) {
130 while ((arg = av_strtok(p, "|", &tokenizer))) {
135 if (parse_channel_name(s, s->nb_irs, &arg, &out_ch_id, buf)) {
136 av_log(ctx, AV_LOG_WARNING, "Failed to parse \'%s\' as channel name.\n", buf);
139 s->mapping[s->nb_irs] = out_ch_id;
143 if (s->hrir_fmt == HRIR_MULTI)
146 s->nb_inputs = s->nb_irs + 1;
151 typedef struct ThreadData {
159 FFTComplex **temp_fft;
162 static int headphone_convolute(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
164 HeadphoneContext *s = ctx->priv;
165 ThreadData *td = arg;
166 AVFrame *in = td->in, *out = td->out;
168 int *write = &td->write[jobnr];
169 const int *const delay = td->delay[jobnr];
170 const float *const ir = td->ir[jobnr];
171 int *n_clippings = &td->n_clippings[jobnr];
172 float *ringbuffer = td->ringbuffer[jobnr];
173 float *temp_src = td->temp_src[jobnr];
174 const int ir_len = s->ir_len;
175 const float *src = (const float *)in->data[0];
176 float *dst = (float *)out->data[0];
177 const int in_channels = in->channels;
178 const int buffer_length = s->buffer_length;
179 const uint32_t modulo = (uint32_t)buffer_length - 1;
186 for (l = 0; l < in_channels; l++) {
187 buffer[l] = ringbuffer + l * buffer_length;
190 for (i = 0; i < in->nb_samples; i++) {
191 const float *temp_ir = ir;
194 for (l = 0; l < in_channels; l++) {
195 *(buffer[l] + wr) = src[l];
198 for (l = 0; l < in_channels; l++) {
199 const float *const bptr = buffer[l];
201 if (l == s->lfe_channel) {
202 *dst += *(buffer[s->lfe_channel] + wr) * s->gain_lfe;
203 temp_ir += FFALIGN(ir_len, 16);
207 read = (wr - *(delay + l) - (ir_len - 1) + buffer_length) & modulo;
209 if (read + ir_len < buffer_length) {
210 memcpy(temp_src, bptr + read, ir_len * sizeof(*temp_src));
212 int len = FFMIN(ir_len - (read % ir_len), buffer_length - read);
214 memcpy(temp_src, bptr + read, len * sizeof(*temp_src));
215 memcpy(temp_src + len, bptr, (ir_len - len) * sizeof(*temp_src));
218 dst[0] += s->fdsp->scalarproduct_float(temp_ir, temp_src, ir_len);
219 temp_ir += FFALIGN(ir_len, 16);
227 wr = (wr + 1) & modulo;
235 static int headphone_fast_convolute(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
237 HeadphoneContext *s = ctx->priv;
238 ThreadData *td = arg;
239 AVFrame *in = td->in, *out = td->out;
241 int *write = &td->write[jobnr];
242 FFTComplex *hrtf = s->data_hrtf[jobnr];
243 int *n_clippings = &td->n_clippings[jobnr];
244 float *ringbuffer = td->ringbuffer[jobnr];
245 const int ir_len = s->ir_len;
246 const float *src = (const float *)in->data[0];
247 float *dst = (float *)out->data[0];
248 const int in_channels = in->channels;
249 const int buffer_length = s->buffer_length;
250 const uint32_t modulo = (uint32_t)buffer_length - 1;
251 FFTComplex *fft_in = s->temp_fft[jobnr];
252 FFTContext *ifft = s->ifft[jobnr];
253 FFTContext *fft = s->fft[jobnr];
254 const int n_fft = s->n_fft;
255 const float fft_scale = 1.0f / s->n_fft;
256 FFTComplex *hrtf_offset;
263 n_read = FFMIN(s->ir_len, in->nb_samples);
264 for (j = 0; j < n_read; j++) {
265 dst[2 * j] = ringbuffer[wr];
266 ringbuffer[wr] = 0.0;
267 wr = (wr + 1) & modulo;
270 for (j = n_read; j < in->nb_samples; j++) {
274 for (i = 0; i < in_channels; i++) {
275 if (i == s->lfe_channel) {
276 for (j = 0; j < in->nb_samples; j++) {
277 dst[2 * j] += src[i + j * in_channels] * s->gain_lfe;
283 hrtf_offset = hrtf + offset;
285 memset(fft_in, 0, sizeof(FFTComplex) * n_fft);
287 for (j = 0; j < in->nb_samples; j++) {
288 fft_in[j].re = src[j * in_channels + i];
291 av_fft_permute(fft, fft_in);
292 av_fft_calc(fft, fft_in);
293 for (j = 0; j < n_fft; j++) {
294 const FFTComplex *hcomplex = hrtf_offset + j;
295 const float re = fft_in[j].re;
296 const float im = fft_in[j].im;
298 fft_in[j].re = re * hcomplex->re - im * hcomplex->im;
299 fft_in[j].im = re * hcomplex->im + im * hcomplex->re;
302 av_fft_permute(ifft, fft_in);
303 av_fft_calc(ifft, fft_in);
305 for (j = 0; j < in->nb_samples; j++) {
306 dst[2 * j] += fft_in[j].re * fft_scale;
309 for (j = 0; j < ir_len - 1; j++) {
310 int write_pos = (wr + j) & modulo;
312 *(ringbuffer + write_pos) += fft_in[in->nb_samples + j].re * fft_scale;
316 for (i = 0; i < out->nb_samples; i++) {
317 if (fabs(*dst) > 1) {
329 static int check_ir(AVFilterLink *inlink, int input_number)
331 AVFilterContext *ctx = inlink->dst;
332 HeadphoneContext *s = ctx->priv;
333 int ir_len, max_ir_len;
335 ir_len = ff_inlink_queued_samples(inlink);
337 if (ir_len > max_ir_len) {
338 av_log(ctx, AV_LOG_ERROR, "Too big length of IRs: %d > %d.\n", ir_len, max_ir_len);
339 return AVERROR(EINVAL);
341 s->in[input_number].ir_len = ir_len;
342 s->ir_len = FFMAX(ir_len, s->ir_len);
347 static int headphone_frame(HeadphoneContext *s, AVFrame *in, AVFilterLink *outlink)
349 AVFilterContext *ctx = outlink->src;
350 int n_clippings[2] = { 0 };
354 out = ff_get_audio_buffer(outlink, in->nb_samples);
357 return AVERROR(ENOMEM);
361 td.in = in; td.out = out; td.write = s->write;
362 td.delay = s->delay; td.ir = s->data_ir; td.n_clippings = n_clippings;
363 td.ringbuffer = s->ringbuffer; td.temp_src = s->temp_src;
364 td.temp_fft = s->temp_fft;
366 if (s->type == TIME_DOMAIN) {
367 ctx->internal->execute(ctx, headphone_convolute, &td, NULL, 2);
369 ctx->internal->execute(ctx, headphone_fast_convolute, &td, NULL, 2);
373 if (n_clippings[0] + n_clippings[1] > 0) {
374 av_log(ctx, AV_LOG_WARNING, "%d of %d samples clipped. Please reduce gain.\n",
375 n_clippings[0] + n_clippings[1], out->nb_samples * 2);
379 return ff_filter_frame(outlink, out);
382 static int convert_coeffs(AVFilterContext *ctx, AVFilterLink *inlink)
384 struct HeadphoneContext *s = ctx->priv;
385 const int ir_len = s->ir_len;
386 int nb_irs = s->nb_irs;
387 int nb_input_channels = ctx->inputs[0]->channels;
388 float gain_lin = expf((s->gain - 3 * nb_input_channels) / 20 * M_LN10);
389 FFTComplex *data_hrtf_l = NULL;
390 FFTComplex *data_hrtf_r = NULL;
391 FFTComplex *fft_in_l = NULL;
392 FFTComplex *fft_in_r = NULL;
393 float *data_ir_l = NULL;
394 float *data_ir_r = NULL;
395 int offset = 0, ret = 0;
399 s->buffer_length = 1 << (32 - ff_clz(s->ir_len));
400 s->n_fft = n_fft = 1 << (32 - ff_clz(s->ir_len + s->size));
402 if (s->type == FREQUENCY_DOMAIN) {
403 fft_in_l = av_calloc(n_fft, sizeof(*fft_in_l));
404 fft_in_r = av_calloc(n_fft, sizeof(*fft_in_r));
405 if (!fft_in_l || !fft_in_r) {
406 ret = AVERROR(ENOMEM);
410 av_fft_end(s->fft[0]);
411 av_fft_end(s->fft[1]);
412 s->fft[0] = av_fft_init(log2(s->n_fft), 0);
413 s->fft[1] = av_fft_init(log2(s->n_fft), 0);
414 av_fft_end(s->ifft[0]);
415 av_fft_end(s->ifft[1]);
416 s->ifft[0] = av_fft_init(log2(s->n_fft), 1);
417 s->ifft[1] = av_fft_init(log2(s->n_fft), 1);
419 if (!s->fft[0] || !s->fft[1] || !s->ifft[0] || !s->ifft[1]) {
420 av_log(ctx, AV_LOG_ERROR, "Unable to create FFT contexts of size %d.\n", s->n_fft);
421 ret = AVERROR(ENOMEM);
426 s->data_ir[0] = av_calloc(FFALIGN(s->ir_len, 16), sizeof(float) * s->nb_irs);
427 s->data_ir[1] = av_calloc(FFALIGN(s->ir_len, 16), sizeof(float) * s->nb_irs);
428 s->delay[0] = av_calloc(s->nb_irs, sizeof(float));
429 s->delay[1] = av_calloc(s->nb_irs, sizeof(float));
431 if (s->type == TIME_DOMAIN) {
432 s->ringbuffer[0] = av_calloc(s->buffer_length, sizeof(float) * nb_input_channels);
433 s->ringbuffer[1] = av_calloc(s->buffer_length, sizeof(float) * nb_input_channels);
435 s->ringbuffer[0] = av_calloc(s->buffer_length, sizeof(float));
436 s->ringbuffer[1] = av_calloc(s->buffer_length, sizeof(float));
437 s->temp_fft[0] = av_calloc(s->n_fft, sizeof(FFTComplex));
438 s->temp_fft[1] = av_calloc(s->n_fft, sizeof(FFTComplex));
439 if (!s->temp_fft[0] || !s->temp_fft[1]) {
440 ret = AVERROR(ENOMEM);
445 if (!s->data_ir[0] || !s->data_ir[1] ||
446 !s->ringbuffer[0] || !s->ringbuffer[1]) {
447 ret = AVERROR(ENOMEM);
451 if (s->type == TIME_DOMAIN) {
452 s->temp_src[0] = av_calloc(FFALIGN(ir_len, 16), sizeof(float));
453 s->temp_src[1] = av_calloc(FFALIGN(ir_len, 16), sizeof(float));
455 data_ir_l = av_calloc(nb_irs * FFALIGN(ir_len, 16), sizeof(*data_ir_l));
456 data_ir_r = av_calloc(nb_irs * FFALIGN(ir_len, 16), sizeof(*data_ir_r));
457 if (!data_ir_r || !data_ir_l || !s->temp_src[0] || !s->temp_src[1]) {
458 ret = AVERROR(ENOMEM);
462 data_hrtf_l = av_calloc(n_fft, sizeof(*data_hrtf_l) * nb_irs);
463 data_hrtf_r = av_calloc(n_fft, sizeof(*data_hrtf_r) * nb_irs);
464 if (!data_hrtf_r || !data_hrtf_l) {
465 ret = AVERROR(ENOMEM);
470 for (i = 0; i < s->nb_inputs - 1; i++) {
471 int len = s->in[i + 1].ir_len;
472 int delay_l = s->in[i + 1].delay_l;
473 int delay_r = s->in[i + 1].delay_r;
476 ret = ff_inlink_consume_samples(ctx->inputs[i + 1], len, len, &s->in[i + 1].frame);
479 ptr = (float *)s->in[i + 1].frame->extended_data[0];
481 if (s->hrir_fmt == HRIR_STEREO) {
484 for (j = 0; j < inlink->channels; j++) {
485 if (s->mapping[i] < 0) {
489 if ((av_channel_layout_extract_channel(inlink->channel_layout, j)) == (1LL << s->mapping[i])) {
497 if (s->type == TIME_DOMAIN) {
498 offset = idx * FFALIGN(len, 16);
499 for (j = 0; j < len; j++) {
500 data_ir_l[offset + j] = ptr[len * 2 - j * 2 - 2] * gain_lin;
501 data_ir_r[offset + j] = ptr[len * 2 - j * 2 - 1] * gain_lin;
504 memset(fft_in_l, 0, n_fft * sizeof(*fft_in_l));
505 memset(fft_in_r, 0, n_fft * sizeof(*fft_in_r));
507 offset = idx * n_fft;
508 for (j = 0; j < len; j++) {
509 fft_in_l[delay_l + j].re = ptr[j * 2 ] * gain_lin;
510 fft_in_r[delay_r + j].re = ptr[j * 2 + 1] * gain_lin;
513 av_fft_permute(s->fft[0], fft_in_l);
514 av_fft_calc(s->fft[0], fft_in_l);
515 memcpy(data_hrtf_l + offset, fft_in_l, n_fft * sizeof(*fft_in_l));
516 av_fft_permute(s->fft[0], fft_in_r);
517 av_fft_calc(s->fft[0], fft_in_r);
518 memcpy(data_hrtf_r + offset, fft_in_r, n_fft * sizeof(*fft_in_r));
521 int I, N = ctx->inputs[1]->channels;
523 for (k = 0; k < N / 2; k++) {
526 for (j = 0; j < inlink->channels; j++) {
527 if (s->mapping[k] < 0) {
531 if ((av_channel_layout_extract_channel(inlink->channel_layout, j)) == (1LL << s->mapping[k])) {
540 if (s->type == TIME_DOMAIN) {
541 offset = idx * FFALIGN(len, 16);
542 for (j = 0; j < len; j++) {
543 data_ir_l[offset + j] = ptr[len * N - j * N - N + I ] * gain_lin;
544 data_ir_r[offset + j] = ptr[len * N - j * N - N + I + 1] * gain_lin;
547 memset(fft_in_l, 0, n_fft * sizeof(*fft_in_l));
548 memset(fft_in_r, 0, n_fft * sizeof(*fft_in_r));
550 offset = idx * n_fft;
551 for (j = 0; j < len; j++) {
552 fft_in_l[delay_l + j].re = ptr[j * N + I ] * gain_lin;
553 fft_in_r[delay_r + j].re = ptr[j * N + I + 1] * gain_lin;
556 av_fft_permute(s->fft[0], fft_in_l);
557 av_fft_calc(s->fft[0], fft_in_l);
558 memcpy(data_hrtf_l + offset, fft_in_l, n_fft * sizeof(*fft_in_l));
559 av_fft_permute(s->fft[0], fft_in_r);
560 av_fft_calc(s->fft[0], fft_in_r);
561 memcpy(data_hrtf_r + offset, fft_in_r, n_fft * sizeof(*fft_in_r));
566 av_frame_free(&s->in[i + 1].frame);
569 if (s->type == TIME_DOMAIN) {
570 memcpy(s->data_ir[0], data_ir_l, sizeof(float) * nb_irs * FFALIGN(ir_len, 16));
571 memcpy(s->data_ir[1], data_ir_r, sizeof(float) * nb_irs * FFALIGN(ir_len, 16));
573 s->data_hrtf[0] = av_calloc(n_fft * s->nb_irs, sizeof(FFTComplex));
574 s->data_hrtf[1] = av_calloc(n_fft * s->nb_irs, sizeof(FFTComplex));
575 if (!s->data_hrtf[0] || !s->data_hrtf[1]) {
576 ret = AVERROR(ENOMEM);
580 memcpy(s->data_hrtf[0], data_hrtf_l,
581 sizeof(FFTComplex) * nb_irs * n_fft);
582 memcpy(s->data_hrtf[1], data_hrtf_r,
583 sizeof(FFTComplex) * nb_irs * n_fft);
590 av_freep(&data_ir_l);
591 av_freep(&data_ir_r);
593 av_freep(&data_hrtf_l);
594 av_freep(&data_hrtf_r);
602 static int activate(AVFilterContext *ctx)
604 HeadphoneContext *s = ctx->priv;
605 AVFilterLink *inlink = ctx->inputs[0];
606 AVFilterLink *outlink = ctx->outputs[0];
610 FF_FILTER_FORWARD_STATUS_BACK_ALL(ctx->outputs[0], ctx);
612 for (i = 1; i < s->nb_inputs; i++) {
616 if ((ret = check_ir(ctx->inputs[i], i)) < 0)
620 if (ff_outlink_get_status(ctx->inputs[i]) == AVERROR_EOF)
625 for (i = 1; i < s->nb_inputs; i++) {
630 if (i != s->nb_inputs) {
631 if (ff_outlink_frame_wanted(ctx->outputs[0])) {
632 for (i = 1; i < s->nb_inputs; i++) {
634 ff_inlink_request_frame(ctx->inputs[i]);
644 if (!s->have_hrirs && s->eof_hrirs) {
645 ret = convert_coeffs(ctx, inlink);
650 if ((ret = ff_inlink_consume_samples(ctx->inputs[0], s->size, s->size, &in)) > 0) {
651 ret = headphone_frame(s, in, outlink);
659 FF_FILTER_FORWARD_STATUS(ctx->inputs[0], ctx->outputs[0]);
660 if (ff_outlink_frame_wanted(ctx->outputs[0]))
661 ff_inlink_request_frame(ctx->inputs[0]);
666 static int query_formats(AVFilterContext *ctx)
668 struct HeadphoneContext *s = ctx->priv;
669 AVFilterFormats *formats = NULL;
670 AVFilterChannelLayouts *layouts = NULL;
671 AVFilterChannelLayouts *stereo_layout = NULL;
672 AVFilterChannelLayouts *hrir_layouts = NULL;
675 ret = ff_add_format(&formats, AV_SAMPLE_FMT_FLT);
678 ret = ff_set_common_formats(ctx, formats);
682 layouts = ff_all_channel_layouts();
684 return AVERROR(ENOMEM);
686 ret = ff_channel_layouts_ref(layouts, &ctx->inputs[0]->out_channel_layouts);
690 ret = ff_add_channel_layout(&stereo_layout, AV_CH_LAYOUT_STEREO);
694 if (s->hrir_fmt == HRIR_MULTI) {
695 hrir_layouts = ff_all_channel_counts();
697 ret = AVERROR(ENOMEM);
698 ret = ff_channel_layouts_ref(hrir_layouts, &ctx->inputs[1]->out_channel_layouts);
702 for (i = 1; i < s->nb_inputs; i++) {
703 ret = ff_channel_layouts_ref(stereo_layout, &ctx->inputs[i]->out_channel_layouts);
709 ret = ff_channel_layouts_ref(stereo_layout, &ctx->outputs[0]->in_channel_layouts);
713 formats = ff_all_samplerates();
715 return AVERROR(ENOMEM);
716 return ff_set_common_samplerates(ctx, formats);
719 static int config_input(AVFilterLink *inlink)
721 AVFilterContext *ctx = inlink->dst;
722 HeadphoneContext *s = ctx->priv;
724 if (s->nb_irs < inlink->channels) {
725 av_log(ctx, AV_LOG_ERROR, "Number of HRIRs must be >= %d.\n", inlink->channels);
726 return AVERROR(EINVAL);
732 static av_cold int init(AVFilterContext *ctx)
734 HeadphoneContext *s = ctx->priv;
739 .type = AVMEDIA_TYPE_AUDIO,
740 .config_props = config_input,
742 if ((ret = ff_insert_inpad(ctx, 0, &pad)) < 0)
746 av_log(ctx, AV_LOG_ERROR, "Valid mapping must be set.\n");
747 return AVERROR(EINVAL);
752 s->in = av_calloc(s->nb_inputs, sizeof(*s->in));
754 return AVERROR(ENOMEM);
756 for (i = 1; i < s->nb_inputs; i++) {
757 char *name = av_asprintf("hrir%d", i - 1);
760 .type = AVMEDIA_TYPE_AUDIO,
763 return AVERROR(ENOMEM);
764 if ((ret = ff_insert_inpad(ctx, i, &pad)) < 0) {
770 s->fdsp = avpriv_float_dsp_alloc(0);
772 return AVERROR(ENOMEM);
777 static int config_output(AVFilterLink *outlink)
779 AVFilterContext *ctx = outlink->src;
780 HeadphoneContext *s = ctx->priv;
781 AVFilterLink *inlink = ctx->inputs[0];
783 if (s->hrir_fmt == HRIR_MULTI) {
784 AVFilterLink *hrir_link = ctx->inputs[1];
786 if (hrir_link->channels < inlink->channels * 2) {
787 av_log(ctx, AV_LOG_ERROR, "Number of channels in HRIR stream must be >= %d.\n", inlink->channels * 2);
788 return AVERROR(EINVAL);
792 s->gain_lfe = expf((s->gain - 3 * inlink->channels - 6 + s->lfe_gain) / 20 * M_LN10);
797 static av_cold void uninit(AVFilterContext *ctx)
799 HeadphoneContext *s = ctx->priv;
802 av_fft_end(s->ifft[0]);
803 av_fft_end(s->ifft[1]);
804 av_fft_end(s->fft[0]);
805 av_fft_end(s->fft[1]);
806 av_freep(&s->delay[0]);
807 av_freep(&s->delay[1]);
808 av_freep(&s->data_ir[0]);
809 av_freep(&s->data_ir[1]);
810 av_freep(&s->ringbuffer[0]);
811 av_freep(&s->ringbuffer[1]);
812 av_freep(&s->temp_src[0]);
813 av_freep(&s->temp_src[1]);
814 av_freep(&s->temp_fft[0]);
815 av_freep(&s->temp_fft[1]);
816 av_freep(&s->data_hrtf[0]);
817 av_freep(&s->data_hrtf[1]);
820 for (i = 0; i < s->nb_inputs; i++) {
821 if (ctx->input_pads && i)
822 av_freep(&ctx->input_pads[i].name);
827 #define OFFSET(x) offsetof(HeadphoneContext, x)
828 #define FLAGS AV_OPT_FLAG_AUDIO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
830 static const AVOption headphone_options[] = {
831 { "map", "set channels convolution mappings", OFFSET(map), AV_OPT_TYPE_STRING, {.str=NULL}, .flags = FLAGS },
832 { "gain", "set gain in dB", OFFSET(gain), AV_OPT_TYPE_FLOAT, {.dbl=0}, -20, 40, .flags = FLAGS },
833 { "lfe", "set lfe gain in dB", OFFSET(lfe_gain), AV_OPT_TYPE_FLOAT, {.dbl=0}, -20, 40, .flags = FLAGS },
834 { "type", "set processing", OFFSET(type), AV_OPT_TYPE_INT, {.i64=1}, 0, 1, .flags = FLAGS, "type" },
835 { "time", "time domain", 0, AV_OPT_TYPE_CONST, {.i64=0}, 0, 0, .flags = FLAGS, "type" },
836 { "freq", "frequency domain", 0, AV_OPT_TYPE_CONST, {.i64=1}, 0, 0, .flags = FLAGS, "type" },
837 { "size", "set frame size", OFFSET(size), AV_OPT_TYPE_INT, {.i64=1024},1024,96000, .flags = FLAGS },
838 { "hrir", "set hrir format", OFFSET(hrir_fmt), AV_OPT_TYPE_INT, {.i64=HRIR_STEREO}, 0, 1, .flags = FLAGS, "hrir" },
839 { "stereo", "hrir files have exactly 2 channels", 0, AV_OPT_TYPE_CONST, {.i64=HRIR_STEREO}, 0, 0, .flags = FLAGS, "hrir" },
840 { "multich", "single multichannel hrir file", 0, AV_OPT_TYPE_CONST, {.i64=HRIR_MULTI}, 0, 0, .flags = FLAGS, "hrir" },
844 AVFILTER_DEFINE_CLASS(headphone);
846 static const AVFilterPad outputs[] = {
849 .type = AVMEDIA_TYPE_AUDIO,
850 .config_props = config_output,
855 AVFilter ff_af_headphone = {
857 .description = NULL_IF_CONFIG_SMALL("Apply headphone binaural spatialization with HRTFs in additional streams."),
858 .priv_size = sizeof(HeadphoneContext),
859 .priv_class = &headphone_class,
862 .query_formats = query_formats,
863 .activate = activate,
866 .flags = AVFILTER_FLAG_SLICE_THREADS | AVFILTER_FLAG_DYNAMIC_INPUTS,