static int convert_coeffs(AVFilterContext *ctx, AVFilterLink *inlink)

{

    struct HeadphoneContext *s = ctx->priv;

    const int ir_len = s->ir_len;

    int nb_irs = s->nb_irs;

    int nb_input_channels = ctx->inputs[0]->channels;

    float gain_lin = expf((s->gain - 3 * nb_input_channels) / 20 * M_LN10);

    FFTComplex *data_hrtf_l = NULL;

    FFTComplex *data_hrtf_r = NULL;

    FFTComplex *fft_in_l = NULL;

    FFTComplex *fft_in_r = NULL;

    float *data_ir_l = NULL;

    float *data_ir_r = NULL;

    int offset = 0;

    int n_fft;

    int i, j;



    s->buffer_length = 1 << (32 - ff_clz(s->ir_len));

    s->n_fft = n_fft = 1 << (32 - ff_clz(s->ir_len + inlink->sample_rate));



    if (s->type == FREQUENCY_DOMAIN) {

        fft_in_l = av_calloc(n_fft, sizeof(*fft_in_l));

        fft_in_r = av_calloc(n_fft, sizeof(*fft_in_r));

        if (!fft_in_l || !fft_in_r) {

            return AVERROR(ENOMEM);

        }



        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);

        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);



        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);

            return AVERROR(ENOMEM);

        }

    }



    s->data_ir[0] = av_calloc(FFALIGN(s->ir_len, 16), sizeof(float) * s->nb_irs);

    s->data_ir[1] = av_calloc(FFALIGN(s->ir_len, 16), sizeof(float) * s->nb_irs);

    s->delay[0] = av_malloc_array(s->nb_irs, sizeof(float));

    s->delay[1] = av_malloc_array(s->nb_irs, sizeof(float));



    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 {

        s->ringbuffer[0] = av_calloc(s->buffer_length, sizeof(float));

        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])

            return AVERROR(ENOMEM);

    }



    if (!s->data_ir[0] || !s->data_ir[1] ||

        !s->ringbuffer[0] || !s->ringbuffer[1])

        return AVERROR(ENOMEM);



    s->in[0].frame = ff_get_audio_buffer(ctx->inputs[0], s->size);

    if (!s->in[0].frame)

        return AVERROR(ENOMEM);

    for (i = 0; i < s->nb_irs; i++) {

        s->in[i + 1].frame = ff_get_audio_buffer(ctx->inputs[i + 1], s->ir_len);

        if (!s->in[i + 1].frame)

            return AVERROR(ENOMEM);

    }



    if (s->type == TIME_DOMAIN) {

        s->temp_src[0] = av_calloc(FFALIGN(ir_len, 16), sizeof(float));

        s->temp_src[1] = av_calloc(FFALIGN(ir_len, 16), sizeof(float));



        data_ir_l = av_calloc(nb_irs * FFALIGN(ir_len, 16), sizeof(*data_ir_l));

        data_ir_r = av_calloc(nb_irs * FFALIGN(ir_len, 16), sizeof(*data_ir_r));

        if (!data_ir_r || !data_ir_l || !s->temp_src[0] || !s->temp_src[1]) {

            av_free(data_ir_l);

            av_free(data_ir_r);

            return AVERROR(ENOMEM);

        }

    } else {

        data_hrtf_l = av_malloc_array(n_fft, sizeof(*data_hrtf_l) * nb_irs);

        data_hrtf_r = av_malloc_array(n_fft, sizeof(*data_hrtf_r) * nb_irs);

        if (!data_hrtf_r || !data_hrtf_l) {

            av_free(data_hrtf_l);

            av_free(data_hrtf_r);

            return AVERROR(ENOMEM);

        }

    }



    for (i = 0; i < s->nb_irs; i++) {

        int len = s->in[i + 1].ir_len;

        int delay_l = s->in[i + 1].delay_l;

        int delay_r = s->in[i + 1].delay_r;

        int idx = -1;

        float *ptr;



        for (j = 0; j < inlink->channels; j++) {

            if (s->mapping[i] < 0) {

                continue;

            }



            if ((av_channel_layout_extract_channel(inlink->channel_layout, j)) == (1LL << s->mapping[i])) {

                idx = j;

                break;

            }

        }

        if (idx == -1)

            continue;



        av_audio_fifo_read(s->in[i + 1].fifo, (void **)s->in[i + 1].frame->extended_data, len);

        ptr = (float *)s->in[i + 1].frame->extended_data[0];



        if (s->type == TIME_DOMAIN) {

            offset = idx * FFALIGN(len, 16);

            for (j = 0; j < len; j++) {

                data_ir_l[offset + j] = ptr[len * 2 - j * 2 - 2] * gain_lin;

                data_ir_r[offset + j] = ptr[len * 2 - j * 2 - 1] * gain_lin;

            }

        } else {

            memset(fft_in_l, 0, n_fft * sizeof(*fft_in_l));

            memset(fft_in_r, 0, n_fft * sizeof(*fft_in_r));



            offset = idx * n_fft;

            for (j = 0; j < len; j++) {

                fft_in_l[delay_l + j].re = ptr[j * 2    ] * gain_lin;

                fft_in_r[delay_r + j].re = ptr[j * 2 + 1] * gain_lin;

            }



            av_fft_permute(s->fft[0], fft_in_l);

            av_fft_calc(s->fft[0], fft_in_l);

            memcpy(data_hrtf_l + offset, fft_in_l, n_fft * sizeof(*fft_in_l));

            av_fft_permute(s->fft[0], fft_in_r);

            av_fft_calc(s->fft[0], fft_in_r);

            memcpy(data_hrtf_r + offset, fft_in_r, n_fft * sizeof(*fft_in_r));

        }

    }



    if (s->type == TIME_DOMAIN) {

        memcpy(s->data_ir[0], data_ir_l, sizeof(float) * nb_irs * FFALIGN(ir_len, 16));

        memcpy(s->data_ir[1], data_ir_r, sizeof(float) * nb_irs * FFALIGN(ir_len, 16));



        av_freep(&data_ir_l);

        av_freep(&data_ir_r);

    } else {

        s->data_hrtf[0] = av_malloc_array(n_fft * s->nb_irs, sizeof(FFTComplex));

        s->data_hrtf[1] = av_malloc_array(n_fft * s->nb_irs, sizeof(FFTComplex));

        if (!s->data_hrtf[0] || !s->data_hrtf[1]) {

            av_freep(&data_hrtf_l);

            av_freep(&data_hrtf_r);

            av_freep(&fft_in_l);

            av_freep(&fft_in_r);

            return AVERROR(ENOMEM);

        }



        memcpy(s->data_hrtf[0], data_hrtf_l,

            sizeof(FFTComplex) * nb_irs * n_fft);

        memcpy(s->data_hrtf[1], data_hrtf_r,

            sizeof(FFTComplex) * nb_irs * n_fft);



        av_freep(&data_hrtf_l);

        av_freep(&data_hrtf_r);



        av_freep(&fft_in_l);

        av_freep(&fft_in_r);

    }



    s->have_hrirs = 1;



    return 0;

}

static int convert_coeffs(AVFilterContext *ctx, AVFilterLink *inlink)

{

    struct HeadphoneContext *s = ctx->priv;

    const int ir_len = s->ir_len;

    int nb_irs = s->nb_irs;

    int nb_input_channels = ctx->inputs[0]->channels;

    float gain_lin = expf((s->gain - 3 * nb_input_channels) / 20 * M_LN10);

    FFTComplex *data_hrtf_l = NULL;

    FFTComplex *data_hrtf_r = NULL;

    FFTComplex *fft_in_l = NULL;

    FFTComplex *fft_in_r = NULL;

    float *data_ir_l = NULL;

    float *data_ir_r = NULL;

    int offset = 0;

    int n_fft;

    int i, j;



    s->buffer_length = 1 << (32 - ff_clz(s->ir_len));

    s->n_fft = n_fft = 1 << (32 - ff_clz(s->ir_len + inlink->sample_rate));



    if (s->type == FREQUENCY_DOMAIN) {

        fft_in_l = av_calloc(n_fft, sizeof(*fft_in_l));

        fft_in_r = av_calloc(n_fft, sizeof(*fft_in_r));

        if (!fft_in_l || !fft_in_r) {

            return AVERROR(ENOMEM);

        }



        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);

        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);



        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);

            return AVERROR(ENOMEM);

        }

    }



    s->data_ir[0] = av_calloc(FFALIGN(s->ir_len, 16), sizeof(float) * s->nb_irs);

    s->data_ir[1] = av_calloc(FFALIGN(s->ir_len, 16), sizeof(float) * s->nb_irs);

    s->delay[0] = av_malloc_array(s->nb_irs, sizeof(float));

    s->delay[1] = av_malloc_array(s->nb_irs, sizeof(float));



    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 {

        s->ringbuffer[0] = av_calloc(s->buffer_length, sizeof(float));

        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])

            return AVERROR(ENOMEM);

    }



    if (!s->data_ir[0] || !s->data_ir[1] ||

        !s->ringbuffer[0] || !s->ringbuffer[1])

        return AVERROR(ENOMEM);



    s->in[0].frame = ff_get_audio_buffer(ctx->inputs[0], s->size);

    if (!s->in[0].frame)

        return AVERROR(ENOMEM);

    for (i = 0; i < s->nb_irs; i++) {

        s->in[i + 1].frame = ff_get_audio_buffer(ctx->inputs[i + 1], s->ir_len);

        if (!s->in[i + 1].frame)

            return AVERROR(ENOMEM);

    }



    if (s->type == TIME_DOMAIN) {

        s->temp_src[0] = av_calloc(FFALIGN(ir_len, 16), sizeof(float));

        s->temp_src[1] = av_calloc(FFALIGN(ir_len, 16), sizeof(float));



        data_ir_l = av_calloc(nb_irs * FFALIGN(ir_len, 16), sizeof(*data_ir_l));

        data_ir_r = av_calloc(nb_irs * FFALIGN(ir_len, 16), sizeof(*data_ir_r));

        if (!data_ir_r || !data_ir_l || !s->temp_src[0] || !s->temp_src[1]) {

            av_free(data_ir_l);

            av_free(data_ir_r);

            return AVERROR(ENOMEM);

        }

    } else {

        data_hrtf_l = av_malloc_array(n_fft, sizeof(*data_hrtf_l) * nb_irs);

        data_hrtf_r = av_malloc_array(n_fft, sizeof(*data_hrtf_r) * nb_irs);

        if (!data_hrtf_r || !data_hrtf_l) {

            av_free(data_hrtf_l);

            av_free(data_hrtf_r);

            return AVERROR(ENOMEM);

        }

    }



    for (i = 0; i < s->nb_irs; i++) {

        int len = s->in[i + 1].ir_len;

        int delay_l = s->in[i + 1].delay_l;

        int delay_r = s->in[i + 1].delay_r;

        int idx = -1;

        float *ptr;



        for (j = 0; j < inlink->channels; j++) {

            if (s->mapping[i] < 0) {

                continue;

            }



            if ((av_channel_layout_extract_channel(inlink->channel_layout, j)) == (1LL << s->mapping[i])) {

                idx = j;

                break;

            }

        }

        if (idx == -1)

            continue;



        av_audio_fifo_read(s->in[i + 1].fifo, (void **)s->in[i + 1].frame->extended_data, len);

        ptr = (float *)s->in[i + 1].frame->extended_data[0];



        if (s->type == TIME_DOMAIN) {

            offset = idx * FFALIGN(len, 16);

            for (j = 0; j < len; j++) {

                data_ir_l[offset + j] = ptr[len * 2 - j * 2 - 2] * gain_lin;

                data_ir_r[offset + j] = ptr[len * 2 - j * 2 - 1] * gain_lin;

            }

        } else {

            memset(fft_in_l, 0, n_fft * sizeof(*fft_in_l));

            memset(fft_in_r, 0, n_fft * sizeof(*fft_in_r));



            offset = idx * n_fft;

            for (j = 0; j < len; j++) {

                fft_in_l[delay_l + j].re = ptr[j * 2    ] * gain_lin;

                fft_in_r[delay_r + j].re = ptr[j * 2 + 1] * gain_lin;

            }



            av_fft_permute(s->fft[0], fft_in_l);

            av_fft_calc(s->fft[0], fft_in_l);

            memcpy(data_hrtf_l + offset, fft_in_l, n_fft * sizeof(*fft_in_l));

            av_fft_permute(s->fft[0], fft_in_r);

            av_fft_calc(s->fft[0], fft_in_r);

            memcpy(data_hrtf_r + offset, fft_in_r, n_fft * sizeof(*fft_in_r));

        }

    }



    if (s->type == TIME_DOMAIN) {

        memcpy(s->data_ir[0], data_ir_l, sizeof(float) * nb_irs * FFALIGN(ir_len, 16));

        memcpy(s->data_ir[1], data_ir_r, sizeof(float) * nb_irs * FFALIGN(ir_len, 16));



        av_freep(&data_ir_l);

        av_freep(&data_ir_r);

    } else {

        s->data_hrtf[0] = av_malloc_array(n_fft * s->nb_irs, sizeof(FFTComplex));

        s->data_hrtf[1] = av_malloc_array(n_fft * s->nb_irs, sizeof(FFTComplex));

        if (!s->data_hrtf[0] || !s->data_hrtf[1]) {

            av_freep(&data_hrtf_l);

            av_freep(&data_hrtf_r);

            av_freep(&fft_in_l);

            av_freep(&fft_in_r);

            return AVERROR(ENOMEM);

        }



        memcpy(s->data_hrtf[0], data_hrtf_l,

            sizeof(FFTComplex) * nb_irs * n_fft);

        memcpy(s->data_hrtf[1], data_hrtf_r,

            sizeof(FFTComplex) * nb_irs * n_fft);



        av_freep(&data_hrtf_l);

        av_freep(&data_hrtf_r);



        av_freep(&fft_in_l);

        av_freep(&fft_in_r);

    }



    s->have_hrirs = 1;



    return 0;

}

    int offset = 0;             return AVERROR(ENOMEM);             return AVERROR(ENOMEM);         if (!s->temp_fft[0] || !s->temp_fft[1])             return AVERROR(ENOMEM);         !s->ringbuffer[0] || !s->ringbuffer[1])         return AVERROR(ENOMEM);     if (!s->in[0].frame)         return AVERROR(ENOMEM);         if (!s->in[i + 1].frame)             return AVERROR(ENOMEM);             av_free(data_ir_l);             av_free(data_ir_r);             return AVERROR(ENOMEM);             av_free(data_hrtf_l);             av_free(data_hrtf_r);             return AVERROR(ENOMEM);         av_freep(&data_ir_l);         av_freep(&data_ir_r);             av_freep(&data_hrtf_l);             av_freep(&data_hrtf_r);             av_freep(&fft_in_l);             av_freep(&fft_in_r);             return AVERROR(ENOMEM);         av_freep(&data_hrtf_l);         av_freep(&data_hrtf_r);         av_freep(&fft_in_l);         av_freep(&fft_in_r);     return 0;
static int FUNC_0(AVFilterContext *VAR_0, AVFilterLink *VAR_1)

{

    struct HeadphoneContext *VAR_2 = VAR_0->priv;

    const int VAR_3 = VAR_2->VAR_3;

    int VAR_4 = VAR_2->VAR_4;

    int VAR_5 = VAR_0->inputs[0]->channels;

    float VAR_6 = expf((VAR_2->gain - 3 * VAR_5) / 20 * M_LN10);

    FFTComplex *data_hrtf_l = NULL;

    FFTComplex *data_hrtf_r = NULL;

    FFTComplex *fft_in_l = NULL;

    FFTComplex *fft_in_r = NULL;

    float *VAR_7 = NULL;

    float *VAR_8 = NULL;

    int VAR_9 = 0;

    int VAR_10;

    int VAR_11, VAR_12;



    VAR_2->buffer_length = 1 << (32 - ff_clz(VAR_2->VAR_3));

    VAR_2->VAR_10 = VAR_10 = 1 << (32 - ff_clz(VAR_2->VAR_3 + VAR_1->sample_rate));



    if (VAR_2->type == FREQUENCY_DOMAIN) {

        fft_in_l = av_calloc(VAR_10, sizeof(*fft_in_l));

        fft_in_r = av_calloc(VAR_10, sizeof(*fft_in_r));

        if (!fft_in_l || !fft_in_r) {

            return AVERROR(ENOMEM);

        }



        av_fft_end(VAR_2->fft[0]);

        av_fft_end(VAR_2->fft[1]);

        VAR_2->fft[0] = av_fft_init(log2(VAR_2->VAR_10), 0);

        VAR_2->fft[1] = av_fft_init(log2(VAR_2->VAR_10), 0);

        av_fft_end(VAR_2->ifft[0]);

        av_fft_end(VAR_2->ifft[1]);

        VAR_2->ifft[0] = av_fft_init(log2(VAR_2->VAR_10), 1);

        VAR_2->ifft[1] = av_fft_init(log2(VAR_2->VAR_10), 1);



        if (!VAR_2->fft[0] || !VAR_2->fft[1] || !VAR_2->ifft[0] || !VAR_2->ifft[1]) {

            av_log(VAR_0, AV_LOG_ERROR, "Unable to create FFT contexts of size %d.\n", VAR_2->VAR_10);

            return AVERROR(ENOMEM);

        }

    }



    VAR_2->data_ir[0] = av_calloc(FFALIGN(VAR_2->VAR_3, 16), sizeof(float) * VAR_2->VAR_4);

    VAR_2->data_ir[1] = av_calloc(FFALIGN(VAR_2->VAR_3, 16), sizeof(float) * VAR_2->VAR_4);

    VAR_2->delay[0] = av_malloc_array(VAR_2->VAR_4, sizeof(float));

    VAR_2->delay[1] = av_malloc_array(VAR_2->VAR_4, sizeof(float));



    if (VAR_2->type == TIME_DOMAIN) {

        VAR_2->ringbuffer[0] = av_calloc(VAR_2->buffer_length, sizeof(float) * VAR_5);

        VAR_2->ringbuffer[1] = av_calloc(VAR_2->buffer_length, sizeof(float) * VAR_5);

    } else {

        VAR_2->ringbuffer[0] = av_calloc(VAR_2->buffer_length, sizeof(float));

        VAR_2->ringbuffer[1] = av_calloc(VAR_2->buffer_length, sizeof(float));

        VAR_2->temp_fft[0] = av_malloc_array(VAR_2->VAR_10, sizeof(FFTComplex));

        VAR_2->temp_fft[1] = av_malloc_array(VAR_2->VAR_10, sizeof(FFTComplex));

        if (!VAR_2->temp_fft[0] || !VAR_2->temp_fft[1])

            return AVERROR(ENOMEM);

    }



    if (!VAR_2->data_ir[0] || !VAR_2->data_ir[1] ||

        !VAR_2->ringbuffer[0] || !VAR_2->ringbuffer[1])

        return AVERROR(ENOMEM);



    VAR_2->in[0].frame = ff_get_audio_buffer(VAR_0->inputs[0], VAR_2->size);

    if (!VAR_2->in[0].frame)

        return AVERROR(ENOMEM);

    for (VAR_11 = 0; VAR_11 < VAR_2->VAR_4; VAR_11++) {

        VAR_2->in[VAR_11 + 1].frame = ff_get_audio_buffer(VAR_0->inputs[VAR_11 + 1], VAR_2->VAR_3);

        if (!VAR_2->in[VAR_11 + 1].frame)

            return AVERROR(ENOMEM);

    }



    if (VAR_2->type == TIME_DOMAIN) {

        VAR_2->temp_src[0] = av_calloc(FFALIGN(VAR_3, 16), sizeof(float));

        VAR_2->temp_src[1] = av_calloc(FFALIGN(VAR_3, 16), sizeof(float));



        VAR_7 = av_calloc(VAR_4 * FFALIGN(VAR_3, 16), sizeof(*VAR_7));

        VAR_8 = av_calloc(VAR_4 * FFALIGN(VAR_3, 16), sizeof(*VAR_8));

        if (!VAR_8 || !VAR_7 || !VAR_2->temp_src[0] || !VAR_2->temp_src[1]) {

            av_free(VAR_7);

            av_free(VAR_8);

            return AVERROR(ENOMEM);

        }

    } else {

        data_hrtf_l = av_malloc_array(VAR_10, sizeof(*data_hrtf_l) * VAR_4);

        data_hrtf_r = av_malloc_array(VAR_10, sizeof(*data_hrtf_r) * VAR_4);

        if (!data_hrtf_r || !data_hrtf_l) {

            av_free(data_hrtf_l);

            av_free(data_hrtf_r);

            return AVERROR(ENOMEM);

        }

    }



    for (VAR_11 = 0; VAR_11 < VAR_2->VAR_4; VAR_11++) {

        int VAR_13 = VAR_2->in[VAR_11 + 1].VAR_3;

        int VAR_14 = VAR_2->in[VAR_11 + 1].VAR_14;

        int VAR_15 = VAR_2->in[VAR_11 + 1].VAR_15;

        int VAR_16 = -1;

        float *VAR_17;



        for (VAR_12 = 0; VAR_12 < VAR_1->channels; VAR_12++) {

            if (VAR_2->mapping[VAR_11] < 0) {

                continue;

            }



            if ((av_channel_layout_extract_channel(VAR_1->channel_layout, VAR_12)) == (1LL << VAR_2->mapping[VAR_11])) {

                VAR_16 = VAR_12;

                break;

            }

        }

        if (VAR_16 == -1)

            continue;



        av_audio_fifo_read(VAR_2->in[VAR_11 + 1].fifo, (void **)VAR_2->in[VAR_11 + 1].frame->extended_data, VAR_13);

        VAR_17 = (float *)VAR_2->in[VAR_11 + 1].frame->extended_data[0];



        if (VAR_2->type == TIME_DOMAIN) {

            VAR_9 = VAR_16 * FFALIGN(VAR_13, 16);

            for (VAR_12 = 0; VAR_12 < VAR_13; VAR_12++) {

                VAR_7[VAR_9 + VAR_12] = VAR_17[VAR_13 * 2 - VAR_12 * 2 - 2] * VAR_6;

                VAR_8[VAR_9 + VAR_12] = VAR_17[VAR_13 * 2 - VAR_12 * 2 - 1] * VAR_6;

            }

        } else {

            memset(fft_in_l, 0, VAR_10 * sizeof(*fft_in_l));

            memset(fft_in_r, 0, VAR_10 * sizeof(*fft_in_r));



            VAR_9 = VAR_16 * VAR_10;

            for (VAR_12 = 0; VAR_12 < VAR_13; VAR_12++) {

                fft_in_l[VAR_14 + VAR_12].re = VAR_17[VAR_12 * 2    ] * VAR_6;

                fft_in_r[VAR_15 + VAR_12].re = VAR_17[VAR_12 * 2 + 1] * VAR_6;

            }



            av_fft_permute(VAR_2->fft[0], fft_in_l);

            av_fft_calc(VAR_2->fft[0], fft_in_l);

            memcpy(data_hrtf_l + VAR_9, fft_in_l, VAR_10 * sizeof(*fft_in_l));

            av_fft_permute(VAR_2->fft[0], fft_in_r);

            av_fft_calc(VAR_2->fft[0], fft_in_r);

            memcpy(data_hrtf_r + VAR_9, fft_in_r, VAR_10 * sizeof(*fft_in_r));

        }

    }



    if (VAR_2->type == TIME_DOMAIN) {

        memcpy(VAR_2->data_ir[0], VAR_7, sizeof(float) * VAR_4 * FFALIGN(VAR_3, 16));

        memcpy(VAR_2->data_ir[1], VAR_8, sizeof(float) * VAR_4 * FFALIGN(VAR_3, 16));



        av_freep(&VAR_7);

        av_freep(&VAR_8);

    } else {

        VAR_2->data_hrtf[0] = av_malloc_array(VAR_10 * VAR_2->VAR_4, sizeof(FFTComplex));

        VAR_2->data_hrtf[1] = av_malloc_array(VAR_10 * VAR_2->VAR_4, sizeof(FFTComplex));

        if (!VAR_2->data_hrtf[0] || !VAR_2->data_hrtf[1]) {

            av_freep(&data_hrtf_l);

            av_freep(&data_hrtf_r);

            av_freep(&fft_in_l);

            av_freep(&fft_in_r);

            return AVERROR(ENOMEM);

        }



        memcpy(VAR_2->data_hrtf[0], data_hrtf_l,

            sizeof(FFTComplex) * VAR_4 * VAR_10);

        memcpy(VAR_2->data_hrtf[1], data_hrtf_r,

            sizeof(FFTComplex) * VAR_4 * VAR_10);



        av_freep(&data_hrtf_l);

        av_freep(&data_hrtf_r);



        av_freep(&fft_in_l);

        av_freep(&fft_in_r);

    }



    VAR_2->have_hrirs = 1;



    return 0;

}

static int FUNC_0(AVFilterContext *VAR_0, AVFilterLink *VAR_1)
{ struct HeadphoneContext *VAR_2 = VAR_0->priv; const int VAR_3 = VAR_2->VAR_3; int VAR_4 = VAR_2->VAR_4; int VAR_5 = VAR_0->inputs[0]->channels; float VAR_6 = expf((VAR_2->gain - 3 * VAR_5) / 20 * M_LN10); FFTComplex *data_hrtf_l = NULL; FFTComplex *data_hrtf_r = NULL; FFTComplex *fft_in_l = NULL; FFTComplex *fft_in_r = NULL; float *VAR_7 = NULL; float *VAR_8 = NULL; int VAR_9 = 0; int VAR_10; int VAR_11, VAR_12; VAR_2->buffer_length = 1 << (32 - ff_clz(VAR_2->VAR_3)); VAR_2->VAR_10 = VAR_10 = 1 << (32 - ff_clz(VAR_2->VAR_3 + VAR_1->sample_rate)); if (VAR_2->type == FREQUENCY_DOMAIN) { fft_in_l = av_calloc(VAR_10, sizeof(*fft_in_l)); fft_in_r = av_calloc(VAR_10, sizeof(*fft_in_r)); if (!fft_in_l || !fft_in_r) { return AVERROR(ENOMEM); } av_fft_end(VAR_2->fft[0]); av_fft_end(VAR_2->fft[1]); VAR_2->fft[0] = av_fft_init(log2(VAR_2->VAR_10), 0); VAR_2->fft[1] = av_fft_init(log2(VAR_2->VAR_10), 0); av_fft_end(VAR_2->ifft[0]); av_fft_end(VAR_2->ifft[1]); VAR_2->ifft[0] = av_fft_init(log2(VAR_2->VAR_10), 1); VAR_2->ifft[1] = av_fft_init(log2(VAR_2->VAR_10), 1); if (!VAR_2->fft[0] || !VAR_2->fft[1] || !VAR_2->ifft[0] || !VAR_2->ifft[1]) { av_log(VAR_0, AV_LOG_ERROR, "Unable to create FFT contexts of size %d.\n", VAR_2->VAR_10); return AVERROR(ENOMEM); } } VAR_2->data_ir[0] = av_calloc(FFALIGN(VAR_2->VAR_3, 16), sizeof(float) * VAR_2->VAR_4); VAR_2->data_ir[1] = av_calloc(FFALIGN(VAR_2->VAR_3, 16), sizeof(float) * VAR_2->VAR_4); VAR_2->delay[0] = av_malloc_array(VAR_2->VAR_4, sizeof(float)); VAR_2->delay[1] = av_malloc_array(VAR_2->VAR_4, sizeof(float)); if (VAR_2->type == TIME_DOMAIN) { VAR_2->ringbuffer[0] = av_calloc(VAR_2->buffer_length, sizeof(float) * VAR_5); VAR_2->ringbuffer[1] = av_calloc(VAR_2->buffer_length, sizeof(float) * VAR_5); } else { VAR_2->ringbuffer[0] = av_calloc(VAR_2->buffer_length, sizeof(float)); VAR_2->ringbuffer[1] = av_calloc(VAR_2->buffer_length, sizeof(float)); VAR_2->temp_fft[0] = av_malloc_array(VAR_2->VAR_10, sizeof(FFTComplex)); VAR_2->temp_fft[1] = av_malloc_array(VAR_2->VAR_10, sizeof(FFTComplex)); if (!VAR_2->temp_fft[0] || !VAR_2->temp_fft[1])
return AVERROR(ENOMEM); } if (!VAR_2->data_ir[0] || !VAR_2->data_ir[1] ||
!VAR_2->ringbuffer[0] || !VAR_2->ringbuffer[1])
return AVERROR(ENOMEM); VAR_2->in[0].frame = ff_get_audio_buffer(VAR_0->inputs[0], VAR_2->size); if (!VAR_2->in[0].frame)
return AVERROR(ENOMEM); for (VAR_11 = 0; VAR_11 < VAR_2->VAR_4; VAR_11++) { VAR_2->in[VAR_11 + 1].frame = ff_get_audio_buffer(VAR_0->inputs[VAR_11 + 1], VAR_2->VAR_3); if (!VAR_2->in[VAR_11 + 1].frame)
return AVERROR(ENOMEM); } if (VAR_2->type == TIME_DOMAIN) { VAR_2->temp_src[0] = av_calloc(FFALIGN(VAR_3, 16), sizeof(float)); VAR_2->temp_src[1] = av_calloc(FFALIGN(VAR_3, 16), sizeof(float)); VAR_7 = av_calloc(VAR_4 * FFALIGN(VAR_3, 16), sizeof(*VAR_7)); VAR_8 = av_calloc(VAR_4 * FFALIGN(VAR_3, 16), sizeof(*VAR_8)); if (!VAR_8 || !VAR_7 || !VAR_2->temp_src[0] || !VAR_2->temp_src[1]) { av_free(VAR_7); av_free(VAR_8); return AVERROR(ENOMEM); } } else { data_hrtf_l = av_malloc_array(VAR_10, sizeof(*data_hrtf_l) * VAR_4); data_hrtf_r = av_malloc_array(VAR_10, sizeof(*data_hrtf_r) * VAR_4); if (!data_hrtf_r || !data_hrtf_l) { av_free(data_hrtf_l); av_free(data_hrtf_r); return AVERROR(ENOMEM); } } for (VAR_11 = 0; VAR_11 < VAR_2->VAR_4; VAR_11++) { int VAR_13 = VAR_2->in[VAR_11 + 1].VAR_3; int VAR_14 = VAR_2->in[VAR_11 + 1].VAR_14; int VAR_15 = VAR_2->in[VAR_11 + 1].VAR_15; int VAR_16 = -1; float *VAR_17; for (VAR_12 = 0; VAR_12 < VAR_1->channels; VAR_12++) { if (VAR_2->mapping[VAR_11] < 0) { continue; } if ((av_channel_layout_extract_channel(VAR_1->channel_layout, VAR_12)) == (1LL << VAR_2->mapping[VAR_11])) { VAR_16 = VAR_12; break; } } if (VAR_16 == -1)
continue; av_audio_fifo_read(VAR_2->in[VAR_11 + 1].fifo, (void **)VAR_2->in[VAR_11 + 1].frame->extended_data, VAR_13); VAR_17 = (float *)VAR_2->in[VAR_11 + 1].frame->extended_data[0]; if (VAR_2->type == TIME_DOMAIN) { VAR_9 = VAR_16 * FFALIGN(VAR_13, 16); for (VAR_12 = 0; VAR_12 < VAR_13; VAR_12++) { VAR_7[VAR_9 + VAR_12] = VAR_17[VAR_13 * 2 - VAR_12 * 2 - 2] * VAR_6; VAR_8[VAR_9 + VAR_12] = VAR_17[VAR_13 * 2 - VAR_12 * 2 - 1] * VAR_6; } } else { memset(fft_in_l, 0, VAR_10 * sizeof(*fft_in_l)); memset(fft_in_r, 0, VAR_10 * sizeof(*fft_in_r)); VAR_9 = VAR_16 * VAR_10; for (VAR_12 = 0; VAR_12 < VAR_13; VAR_12++) { fft_in_l[VAR_14 + VAR_12].re = VAR_17[VAR_12 * 2    ] * VAR_6; fft_in_r[VAR_15 + VAR_12].re = VAR_17[VAR_12 * 2 + 1] * VAR_6; } av_fft_permute(VAR_2->fft[0], fft_in_l); av_fft_calc(VAR_2->fft[0], fft_in_l); memcpy(data_hrtf_l + VAR_9, fft_in_l, VAR_10 * sizeof(*fft_in_l)); av_fft_permute(VAR_2->fft[0], fft_in_r); av_fft_calc(VAR_2->fft[0], fft_in_r); memcpy(data_hrtf_r + VAR_9, fft_in_r, VAR_10 * sizeof(*fft_in_r)); } } if (VAR_2->type == TIME_DOMAIN) { memcpy(VAR_2->data_ir[0], VAR_7, sizeof(float) * VAR_4 * FFALIGN(VAR_3, 16)); memcpy(VAR_2->data_ir[1], VAR_8, sizeof(float) * VAR_4 * FFALIGN(VAR_3, 16)); av_freep(&VAR_7); av_freep(&VAR_8); } else { VAR_2->data_hrtf[0] = av_malloc_array(VAR_10 * VAR_2->VAR_4, sizeof(FFTComplex)); VAR_2->data_hrtf[1] = av_malloc_array(VAR_10 * VAR_2->VAR_4, sizeof(FFTComplex)); if (!VAR_2->data_hrtf[0] || !VAR_2->data_hrtf[1]) { av_freep(&data_hrtf_l); av_freep(&data_hrtf_r); av_freep(&fft_in_l); av_freep(&fft_in_r); return AVERROR(ENOMEM); } memcpy(VAR_2->data_hrtf[0], data_hrtf_l,
sizeof(FFTComplex) * VAR_4 * VAR_10); memcpy(VAR_2->data_hrtf[1], data_hrtf_r,
sizeof(FFTComplex) * VAR_4 * VAR_10); av_freep(&data_hrtf_l); av_freep(&data_hrtf_r); av_freep(&fft_in_l); av_freep(&fft_in_r); } VAR_2->have_hrirs = 1; return 0; }