]> git.sesse.net Git - ffmpeg/blobdiff - libavfilter/af_sofalizer.c
hwcontext_vulkan: dynamically load functions
[ffmpeg] / libavfilter / af_sofalizer.c
index c30f99c8108adb3196d664771cb322cd830615b4..e62cad24994b02d63583a20089ea77c0185b2e93 100644 (file)
@@ -35,6 +35,7 @@
 #include "libavutil/intmath.h"
 #include "libavutil/opt.h"
 #include "avfilter.h"
+#include "filters.h"
 #include "internal.h"
 #include "audio.h"
 
@@ -81,6 +82,7 @@ typedef struct SOFAlizerContext {
     int buffer_length;          /* is: longest IR plus max. delay in all SOFA files */
                                 /* then choose next power of 2 */
     int n_fft;                  /* number of samples in one FFT block */
+    int nb_samples;
 
                                 /* netCDF variables */
     int *delay[2];              /* broadband delay for each channel/IR to be convolved */
@@ -88,7 +90,8 @@ typedef struct SOFAlizerContext {
     float *data_ir[2];          /* IRs for all channels to be convolved */
                                 /* (this excludes the LFE) */
     float *temp_src[2];
-    FFTComplex *temp_fft[2];
+    FFTComplex *temp_fft[2];    /* Array to hold FFT values */
+    FFTComplex *temp_afft[2];   /* Array to accumulate FFT values prior to IFFT */
 
                          /* control variables */
     float gain;          /* filter gain (in dB) */
@@ -151,7 +154,7 @@ static int preload_sofa(AVFilterContext *ctx, char *filename, int *samplingrate)
         mysofa_loudness(s->sofa.hrtf);
 
     if (s->minphase)
-        mysofa_minphase(s->sofa.hrtf, 0.01);
+        mysofa_minphase(s->sofa.hrtf, 0.01f);
 
     mysofa_tocartesian(s->sofa.hrtf);
 
@@ -180,10 +183,11 @@ static int preload_sofa(AVFilterContext *ctx, char *filename, int *samplingrate)
     return 0;
 }
 
-static int parse_channel_name(char **arg, int *rchannel, char *buf)
+static int parse_channel_name(AVFilterContext *ctx, char **arg, int *rchannel)
 {
     int len, i, channel_id = 0;
     int64_t layout, layout0;
+    char buf[8] = {0};
 
     /* try to parse a channel name, e.g. "FL" */
     if (av_sscanf(*arg, "%7[A-Z]%n", buf, &len)) {
@@ -196,8 +200,18 @@ static int parse_channel_name(char **arg, int *rchannel, char *buf)
             }
         }
         /* reject layouts that are not a single channel */
-        if (channel_id >= 64 || layout0 != 1LL << channel_id)
+        if (channel_id >= 64 || layout0 != 1LL << channel_id) {
+            av_log(ctx, AV_LOG_WARNING, "Failed to parse \'%s\' as channel name.\n", buf);
+            return AVERROR(EINVAL);
+        }
+        *rchannel = channel_id;
+        *arg += len;
+        return 0;
+    } else if (av_sscanf(*arg, "%d%n", &channel_id, &len) == 1) {
+        if (channel_id < 0 || channel_id >= 64) {
+            av_log(ctx, AV_LOG_WARNING, "Failed to parse \'%d\' as channel number.\n", channel_id);
             return AVERROR(EINVAL);
+        }
         *rchannel = channel_id;
         *arg += len;
         return 0;
@@ -215,13 +229,11 @@ static void parse_speaker_pos(AVFilterContext *ctx, int64_t in_channel_layout)
     p = args;
 
     while ((arg = av_strtok(p, "|", &tokenizer))) {
-        char buf[8];
         float azim, elev;
         int out_ch_id;
 
         p = NULL;
-        if (parse_channel_name(&arg, &out_ch_id, buf)) {
-            av_log(ctx, AV_LOG_WARNING, "Failed to parse \'%s\' as channel name.\n", buf);
+        if (parse_channel_name(ctx, &arg, &out_ch_id)) {
             continue;
         }
         if (av_sscanf(arg, "%f %f", &azim, &elev) == 2) {
@@ -243,11 +255,11 @@ static int get_speaker_pos(AVFilterContext *ctx,
 {
     struct SOFAlizerContext *s = ctx->priv;
     uint64_t channels_layout = ctx->inputs[0]->channel_layout;
-    float azim[16] = { 0 };
-    float elev[16] = { 0 };
+    float azim[64] = { 0 };
+    float elev[64] = { 0 };
     int m, ch, n_conv = ctx->inputs[0]->channels; /* get no. input channels */
 
-    if (n_conv > 16)
+    if (n_conv < 0 || n_conv > 64)
         return AVERROR(EINVAL);
 
     s->lfe_channel = -1;
@@ -322,6 +334,7 @@ typedef struct ThreadData {
     float **ringbuffer;
     float **temp_src;
     FFTComplex **temp_fft;
+    FFTComplex **temp_afft;
 } ThreadData;
 
 static int sofalizer_convolute(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
@@ -338,19 +351,23 @@ static int sofalizer_convolute(AVFilterContext *ctx, void *arg, int jobnr, int n
     float *temp_src = td->temp_src[jobnr];
     const int ir_samples = s->sofa.ir_samples; /* length of one IR */
     const int n_samples = s->sofa.n_samples;
-    const float *src = (const float *)in->data[0]; /* get pointer to audio input buffer */
-    float *dst = (float *)out->data[0]; /* get pointer to audio output buffer */
+    const int planar = in->format == AV_SAMPLE_FMT_FLTP;
+    const int mult = 1 + !planar;
+    const float *src = (const float *)in->extended_data[0]; /* get pointer to audio input buffer */
+    float *dst = (float *)out->extended_data[jobnr * planar]; /* get pointer to audio output buffer */
     const int in_channels = s->n_conv; /* number of input channels */
     /* ring buffer length is: longest IR plus max. delay -> next power of 2 */
     const int buffer_length = s->buffer_length;
     /* -1 for AND instead of MODULO (applied to powers of 2): */
     const uint32_t modulo = (uint32_t)buffer_length - 1;
-    float *buffer[16]; /* holds ringbuffer for each input channel */
+    float *buffer[64]; /* holds ringbuffer for each input channel */
     int wr = *write;
     int read;
     int i, l;
 
-    dst += offset;
+    if (!planar)
+        dst += offset;
+
     for (l = 0; l < in_channels; l++) {
         /* get starting address of ringbuffer for each input channel */
         buffer[l] = ringbuffer + l * buffer_length;
@@ -360,9 +377,18 @@ static int sofalizer_convolute(AVFilterContext *ctx, void *arg, int jobnr, int n
         const float *temp_ir = ir; /* using same set of IRs for each sample */
 
         dst[0] = 0;
-        for (l = 0; l < in_channels; l++) {
-            /* write current input sample to ringbuffer (for each channel) */
-            buffer[l][wr] = src[l];
+        if (planar) {
+            for (l = 0; l < in_channels; l++) {
+                const float *srcp = (const float *)in->extended_data[l];
+
+                /* write current input sample to ringbuffer (for each channel) */
+                buffer[l][wr] = srcp[i];
+            }
+        } else {
+            for (l = 0; l < in_channels; l++) {
+                /* write current input sample to ringbuffer (for each channel) */
+                buffer[l][wr] = src[l];
+            }
         }
 
         /* loop goes through all channels to be convolved */
@@ -372,7 +398,7 @@ static int sofalizer_convolute(AVFilterContext *ctx, void *arg, int jobnr, int n
             if (l == s->lfe_channel) {
                 /* LFE is an input channel but requires no convolution */
                 /* apply gain to LFE signal and add to output buffer */
-                *dst += *(buffer[s->lfe_channel] + wr) * s->gain_lfe;
+                dst[0] += *(buffer[s->lfe_channel] + wr) * s->gain_lfe;
                 temp_ir += n_samples;
                 continue;
             }
@@ -380,12 +406,12 @@ static int sofalizer_convolute(AVFilterContext *ctx, void *arg, int jobnr, int n
             /* current read position in ringbuffer: input sample write position
              * - delay for l-th ch. + diff. betw. IR length and buffer length
              * (mod buffer length) */
-            read = (wr - delay[l] - (n_samples - 1) + buffer_length) & modulo;
+            read = (wr - delay[l] - (ir_samples - 1) + buffer_length) & modulo;
 
-            if (read + n_samples < buffer_length) {
-                memmove(temp_src, bptr + read, n_samples * sizeof(*temp_src));
+            if (read + ir_samples < buffer_length) {
+                memmove(temp_src, bptr + read, ir_samples * sizeof(*temp_src));
             } else {
-                int len = FFMIN(n_samples - (read % n_samples), buffer_length - read);
+                int len = FFMIN(n_samples - (read % ir_samples), buffer_length - read);
 
                 memmove(temp_src, bptr + read, len * sizeof(*temp_src));
                 memmove(temp_src + len, bptr, (n_samples - len) * sizeof(*temp_src));
@@ -401,7 +427,7 @@ static int sofalizer_convolute(AVFilterContext *ctx, void *arg, int jobnr, int n
             n_clippings[0]++;
 
         /* move output buffer pointer by +2 to get to next sample of processed channel: */
-        dst += 2;
+        dst += mult;
         src += in_channels;
         wr   = (wr + 1) & modulo; /* update ringbuffer write position */
     }
@@ -421,15 +447,17 @@ static int sofalizer_fast_convolute(AVFilterContext *ctx, void *arg, int jobnr,
     FFTComplex *hrtf = s->data_hrtf[jobnr]; /* get pointers to current HRTF data */
     int *n_clippings = &td->n_clippings[jobnr];
     float *ringbuffer = td->ringbuffer[jobnr];
-    const int n_samples = s->sofa.n_samples; /* length of one IR */
-    const float *src = (const float *)in->data[0]; /* get pointer to audio input buffer */
-    float *dst = (float *)out->data[0]; /* get pointer to audio output buffer */
+    const int ir_samples = s->sofa.ir_samples; /* length of one IR */
+    const int planar = in->format == AV_SAMPLE_FMT_FLTP;
+    const int mult = 1 + !planar;
+    float *dst = (float *)out->extended_data[jobnr * planar]; /* get pointer to audio output buffer */
     const int in_channels = s->n_conv; /* number of input channels */
     /* ring buffer length is: longest IR plus max. delay -> next power of 2 */
     const int buffer_length = s->buffer_length;
     /* -1 for AND instead of MODULO (applied to powers of 2): */
     const uint32_t modulo = (uint32_t)buffer_length - 1;
     FFTComplex *fft_in = s->temp_fft[jobnr]; /* temporary array for FFT input/output data */
+    FFTComplex *fft_acc = s->temp_afft[jobnr];
     FFTContext *ifft = s->ifft[jobnr];
     FFTContext *fft = s->fft[jobnr];
     const int n_conv = s->n_conv;
@@ -440,29 +468,42 @@ static int sofalizer_fast_convolute(AVFilterContext *ctx, void *arg, int jobnr,
     int n_read;
     int i, j;
 
-    dst += offset;
+    if (!planar)
+        dst += offset;
 
     /* find minimum between number of samples and output buffer length:
      * (important, if one IR is longer than the output buffer) */
-    n_read = FFMIN(s->sofa.n_samples, in->nb_samples);
+    n_read = FFMIN(ir_samples, in->nb_samples);
     for (j = 0; j < n_read; j++) {
         /* initialize output buf with saved signal from overflow buf */
-        dst[2 * j]     = ringbuffer[wr];
-        ringbuffer[wr] = 0.0; /* re-set read samples to zero */
+        dst[mult * j]  = ringbuffer[wr];
+        ringbuffer[wr] = 0.0f; /* re-set read samples to zero */
         /* update ringbuffer read/write position */
         wr  = (wr + 1) & modulo;
     }
 
     /* initialize rest of output buffer with 0 */
     for (j = n_read; j < in->nb_samples; j++) {
-        dst[2 * j] = 0;
+        dst[mult * j] = 0;
     }
 
+    /* fill FFT accumulation with 0 */
+    memset(fft_acc, 0, sizeof(FFTComplex) * n_fft);
+
     for (i = 0; i < n_conv; i++) {
+        const float *src = (const float *)in->extended_data[i * planar]; /* get pointer to audio input buffer */
+
         if (i == s->lfe_channel) { /* LFE */
-            for (j = 0; j < in->nb_samples; j++) {
-                /* apply gain to LFE signal and add to output buffer */
-                dst[2 * j] += src[i + j * in_channels] * s->gain_lfe;
+            if (in->format == AV_SAMPLE_FMT_FLT) {
+                for (j = 0; j < in->nb_samples; j++) {
+                    /* apply gain to LFE signal and add to output buffer */
+                    dst[2 * j] += src[i + j * in_channels] * s->gain_lfe;
+                }
+            } else {
+                for (j = 0; j < in->nb_samples; j++) {
+                    /* apply gain to LFE signal and add to output buffer */
+                    dst[j] += src[j] * s->gain_lfe;
+                }
             }
             continue;
         }
@@ -474,10 +515,18 @@ static int sofalizer_fast_convolute(AVFilterContext *ctx, void *arg, int jobnr,
         /* fill FFT input with 0 (we want to zero-pad) */
         memset(fft_in, 0, sizeof(FFTComplex) * n_fft);
 
-        for (j = 0; j < in->nb_samples; j++) {
-            /* prepare input for FFT */
-            /* write all samples of current input channel to FFT input array */
-            fft_in[j].re = src[j * in_channels + i];
+        if (in->format == AV_SAMPLE_FMT_FLT) {
+            for (j = 0; j < in->nb_samples; j++) {
+                /* prepare input for FFT */
+                /* write all samples of current input channel to FFT input array */
+                fft_in[j].re = src[j * in_channels + i];
+            }
+        } else {
+            for (j = 0; j < in->nb_samples; j++) {
+                /* prepare input for FFT */
+                /* write all samples of current input channel to FFT input array */
+                fft_in[j].re = src[j];
+            }
         }
 
         /* transform input signal of current channel to frequency domain */
@@ -490,37 +539,34 @@ static int sofalizer_fast_convolute(AVFilterContext *ctx, void *arg, int jobnr,
 
             /* complex multiplication of input signal and HRTFs */
             /* output channel (real): */
-            fft_in[j].re = re * hcomplex->re - im * hcomplex->im;
+            fft_acc[j].re += re * hcomplex->re - im * hcomplex->im;
             /* output channel (imag): */
-            fft_in[j].im = re * hcomplex->im + im * hcomplex->re;
+            fft_acc[j].im += re * hcomplex->im + im * hcomplex->re;
         }
+    }
 
-        /* transform output signal of current channel back to time domain */
-        av_fft_permute(ifft, fft_in);
-        av_fft_calc(ifft, fft_in);
+    /* transform output signal of current channel back to time domain */
+    av_fft_permute(ifft, fft_acc);
+    av_fft_calc(ifft, fft_acc);
 
-        for (j = 0; j < in->nb_samples; j++) {
-            /* write output signal of current channel to output buffer */
-            dst[2 * j] += fft_in[j].re * fft_scale;
-        }
+    for (j = 0; j < in->nb_samples; j++) {
+        /* write output signal of current channel to output buffer */
+        dst[mult * j] += fft_acc[j].re * fft_scale;
+    }
 
-        for (j = 0; j < n_samples - 1; j++) { /* overflow length is IR length - 1 */
-            /* write the rest of output signal to overflow buffer */
-            int write_pos = (wr + j) & modulo;
+    for (j = 0; j < ir_samples - 1; j++) { /* overflow length is IR length - 1 */
+        /* write the rest of output signal to overflow buffer */
+        int write_pos = (wr + j) & modulo;
 
-            *(ringbuffer + write_pos) += fft_in[in->nb_samples + j].re * fft_scale;
-        }
+        *(ringbuffer + write_pos) += fft_acc[in->nb_samples + j].re * fft_scale;
     }
 
     /* go through all samples of current output buffer: count clippings */
     for (i = 0; i < out->nb_samples; i++) {
         /* clippings counter */
-        if (fabsf(dst[0]) > 1) { /* if current output sample > 1 */
+        if (fabsf(dst[i * mult]) > 1) { /* if current output sample > 1 */
             n_clippings[0]++;
         }
-
-        /* move output buffer pointer by +2 to get to next sample of processed channel: */
-        dst += 2;
     }
 
     /* remember read/write position in ringbuffer for next call */
@@ -549,10 +595,11 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in)
     td.delay = s->delay; td.ir = s->data_ir; td.n_clippings = n_clippings;
     td.ringbuffer = s->ringbuffer; td.temp_src = s->temp_src;
     td.temp_fft = s->temp_fft;
+    td.temp_afft = s->temp_afft;
 
     if (s->type == TIME_DOMAIN) {
         ctx->internal->execute(ctx, sofalizer_convolute, &td, NULL, 2);
-    } else {
+    } else if (s->type == FREQUENCY_DOMAIN) {
         ctx->internal->execute(ctx, sofalizer_fast_convolute, &td, NULL, 2);
     }
     emms_c();
@@ -567,16 +614,45 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in)
     return ff_filter_frame(outlink, out);
 }
 
+static int activate(AVFilterContext *ctx)
+{
+    AVFilterLink *inlink = ctx->inputs[0];
+    AVFilterLink *outlink = ctx->outputs[0];
+    SOFAlizerContext *s = ctx->priv;
+    AVFrame *in;
+    int ret;
+
+    FF_FILTER_FORWARD_STATUS_BACK(outlink, inlink);
+
+    if (s->nb_samples)
+        ret = ff_inlink_consume_samples(inlink, s->nb_samples, s->nb_samples, &in);
+    else
+        ret = ff_inlink_consume_frame(inlink, &in);
+    if (ret < 0)
+        return ret;
+    if (ret > 0)
+        return filter_frame(inlink, in);
+
+    FF_FILTER_FORWARD_STATUS(inlink, outlink);
+    FF_FILTER_FORWARD_WANTED(outlink, inlink);
+
+    return FFERROR_NOT_READY;
+}
+
 static int query_formats(AVFilterContext *ctx)
 {
     struct SOFAlizerContext *s = ctx->priv;
     AVFilterFormats *formats = NULL;
     AVFilterChannelLayouts *layouts = NULL;
     int ret, sample_rates[] = { 48000, -1 };
+    static const enum AVSampleFormat sample_fmts[] = {
+        AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_FLTP,
+        AV_SAMPLE_FMT_NONE
+    };
 
-    ret = ff_add_format(&formats, AV_SAMPLE_FMT_FLT);
-    if (ret)
-        return ret;
+    formats = ff_make_format_list(sample_fmts);
+    if (!formats)
+        return AVERROR(ENOMEM);
     ret = ff_set_common_formats(ctx, formats);
     if (ret)
         return ret;
@@ -585,7 +661,7 @@ static int query_formats(AVFilterContext *ctx)
     if (!layouts)
         return AVERROR(ENOMEM);
 
-    ret = ff_channel_layouts_ref(layouts, &ctx->inputs[0]->out_channel_layouts);
+    ret = ff_channel_layouts_ref(layouts, &ctx->inputs[0]->outcfg.channel_layouts);
     if (ret)
         return ret;
 
@@ -594,7 +670,7 @@ static int query_formats(AVFilterContext *ctx)
     if (ret)
         return ret;
 
-    ret = ff_channel_layouts_ref(layouts, &ctx->outputs[0]->in_channel_layouts);
+    ret = ff_channel_layouts_ref(layouts, &ctx->outputs[0]->incfg.channel_layouts);
     if (ret)
         return ret;
 
@@ -679,12 +755,20 @@ static int load_data(AVFilterContext *ctx, int azim, int elev, float radius, int
     n_samples = s->sofa.n_samples;
     ir_samples = s->sofa.ir_samples;
 
-    s->data_ir[0] = av_calloc(n_samples, sizeof(float) * s->n_conv);
-    s->data_ir[1] = av_calloc(n_samples, sizeof(float) * s->n_conv);
+    if (s->type == TIME_DOMAIN) {
+        s->data_ir[0] = av_calloc(n_samples, sizeof(float) * s->n_conv);
+        s->data_ir[1] = av_calloc(n_samples, sizeof(float) * s->n_conv);
+
+        if (!s->data_ir[0] || !s->data_ir[1]) {
+            ret = AVERROR(ENOMEM);
+            goto fail;
+        }
+    }
+
     s->delay[0] = av_calloc(s->n_conv, sizeof(int));
     s->delay[1] = av_calloc(s->n_conv, sizeof(int));
 
-    if (!s->data_ir[0] || !s->data_ir[1] || !s->delay[0] || !s->delay[1]) {
+    if (!s->delay[0] || !s->delay[1]) {
         ret = AVERROR(ENOMEM);
         goto fail;
     }
@@ -738,7 +822,7 @@ static int load_data(AVFilterContext *ctx, int azim, int elev, float radius, int
                               data_ir_r + n_samples * i,
                               &delay_l, &delay_r);
         if (ret < 0)
-            return ret;
+            goto fail;
 
         s->delay[0][i] = delay_l * sample_rate;
         s->delay[1][i] = delay_r * sample_rate;
@@ -760,12 +844,12 @@ static int load_data(AVFilterContext *ctx, int azim, int elev, float radius, int
     if (s->type == FREQUENCY_DOMAIN) {
         av_fft_end(s->fft[0]);
         av_fft_end(s->fft[1]);
-        s->fft[0] = av_fft_init(log2(s->n_fft), 0);
-        s->fft[1] = av_fft_init(log2(s->n_fft), 0);
+        s->fft[0] = av_fft_init(av_log2(s->n_fft), 0);
+        s->fft[1] = av_fft_init(av_log2(s->n_fft), 0);
         av_fft_end(s->ifft[0]);
         av_fft_end(s->ifft[1]);
-        s->ifft[0] = av_fft_init(log2(s->n_fft), 1);
-        s->ifft[1] = av_fft_init(log2(s->n_fft), 1);
+        s->ifft[0] = av_fft_init(av_log2(s->n_fft), 1);
+        s->ifft[1] = av_fft_init(av_log2(s->n_fft), 1);
 
         if (!s->fft[0] || !s->fft[1] || !s->ifft[0] || !s->ifft[1]) {
             av_log(ctx, AV_LOG_ERROR, "Unable to create FFT contexts of size %d.\n", s->n_fft);
@@ -777,7 +861,7 @@ static int load_data(AVFilterContext *ctx, int azim, int elev, float radius, int
     if (s->type == TIME_DOMAIN) {
         s->ringbuffer[0] = av_calloc(s->buffer_length, sizeof(float) * nb_input_channels);
         s->ringbuffer[1] = av_calloc(s->buffer_length, sizeof(float) * nb_input_channels);
-    } else {
+    } else if (s->type == FREQUENCY_DOMAIN) {
         /* get temporary HRTF memory for L and R channel */
         data_hrtf_l = av_malloc_array(n_fft, sizeof(*data_hrtf_l) * n_conv);
         data_hrtf_r = av_malloc_array(n_fft, sizeof(*data_hrtf_r) * n_conv);
@@ -790,7 +874,10 @@ static int load_data(AVFilterContext *ctx, int azim, int elev, float radius, int
         s->ringbuffer[1] = av_calloc(s->buffer_length, sizeof(float));
         s->temp_fft[0] = av_malloc_array(s->n_fft, sizeof(FFTComplex));
         s->temp_fft[1] = av_malloc_array(s->n_fft, sizeof(FFTComplex));
-        if (!s->temp_fft[0] || !s->temp_fft[1]) {
+        s->temp_afft[0] = av_malloc_array(s->n_fft, sizeof(FFTComplex));
+        s->temp_afft[1] = av_malloc_array(s->n_fft, sizeof(FFTComplex));
+        if (!s->temp_fft[0] || !s->temp_fft[1] ||
+            !s->temp_afft[0] || !s->temp_afft[1]) {
             ret = AVERROR(ENOMEM);
             goto fail;
         }
@@ -825,7 +912,7 @@ static int load_data(AVFilterContext *ctx, int azim, int elev, float radius, int
                 s->data_ir[0][offset + j] = lir[ir_samples - 1 - j] * gain_lin;
                 s->data_ir[1][offset + j] = rir[ir_samples - 1 - j] * gain_lin;
             }
-        } else {
+        } else if (s->type == FREQUENCY_DOMAIN) {
             memset(fft_in_l, 0, n_fft * sizeof(*fft_in_l));
             memset(fft_in_r, 0, n_fft * sizeof(*fft_in_r));
 
@@ -834,7 +921,7 @@ static int load_data(AVFilterContext *ctx, int azim, int elev, float radius, int
                 /* load non-reversed IRs of the specified source position
                  * sample-by-sample and apply gain,
                  * L channel is loaded to real part, R channel to imag part,
-                 * IRs ared shifted by L and R delay */
+                 * IRs are shifted by L and R delay */
                 fft_in_l[s->delay[0][i] + j].re = lir[j] * gain_lin;
                 fft_in_r[s->delay[1][i] + j].re = rir[j] * gain_lin;
             }
@@ -913,14 +1000,11 @@ static int config_input(AVFilterLink *inlink)
     SOFAlizerContext *s = ctx->priv;
     int ret;
 
-    if (s->type == FREQUENCY_DOMAIN) {
-        inlink->partial_buf_size =
-        inlink->min_samples =
-        inlink->max_samples = s->framesize;
-    }
+    if (s->type == FREQUENCY_DOMAIN)
+        s->nb_samples = s->framesize;
 
-    /* gain -3 dB per channel, -6 dB to get LFE on a similar level */
-    s->gain_lfe = expf((s->gain - 3 * inlink->channels - 6 + s->lfe_gain) / 20 * M_LN10);
+    /* gain -3 dB per channel */
+    s->gain_lfe = expf((s->gain - 3 * inlink->channels + s->lfe_gain) / 20 * M_LN10);
 
     s->n_conv = inlink->channels;
 
@@ -957,6 +1041,8 @@ static av_cold void uninit(AVFilterContext *ctx)
     av_freep(&s->speaker_elev);
     av_freep(&s->temp_src[0]);
     av_freep(&s->temp_src[1]);
+    av_freep(&s->temp_afft[0]);
+    av_freep(&s->temp_afft[1]);
     av_freep(&s->temp_fft[0]);
     av_freep(&s->temp_fft[1]);
     av_freep(&s->data_hrtf[0]);
@@ -994,7 +1080,6 @@ static const AVFilterPad inputs[] = {
         .name         = "default",
         .type         = AVMEDIA_TYPE_AUDIO,
         .config_props = config_input,
-        .filter_frame = filter_frame,
     },
     { NULL }
 };
@@ -1007,12 +1092,13 @@ static const AVFilterPad outputs[] = {
     { NULL }
 };
 
-AVFilter ff_af_sofalizer = {
+const AVFilter ff_af_sofalizer = {
     .name          = "sofalizer",
     .description   = NULL_IF_CONFIG_SMALL("SOFAlizer (Spatially Oriented Format for Acoustics)."),
     .priv_size     = sizeof(SOFAlizerContext),
     .priv_class    = &sofalizer_class,
     .init          = init,
+    .activate      = activate,
     .uninit        = uninit,
     .query_formats = query_formats,
     .inputs        = inputs,