static int sofalizer_convolute(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)

{

    SOFAlizerContext *s = ctx->priv;

    ThreadData *td = arg;

    AVFrame *in = td->in, *out = td->out;

    int offset = jobnr;

    int *write = &td->write[jobnr];

    const int *const delay = td->delay[jobnr];

    const float *const ir = td->ir[jobnr];

    int *n_clippings = &td->n_clippings[jobnr];

    float *ringbuffer = td->ringbuffer[jobnr];

    float *temp_src = td->temp_src[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 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 */

    int wr = *write;

    int read;

    int i, l;



    dst += offset;

    for (l = 0; l < in_channels; l++) {

        /* get starting address of ringbuffer for each input channel */

        buffer[l] = ringbuffer + l * buffer_length;

    }



    for (i = 0; i < in->nb_samples; i++) {

        const float *temp_ir = ir; /* using same set of IRs for each sample */



        *dst = 0;

        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 */

        for (l = 0; l < in_channels; l++) {

            const float *const bptr = buffer[l];



            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;

                temp_ir += n_samples;

                continue;

            }



            /* 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;



            if (read + n_samples < buffer_length) {

                memcpy(temp_src, bptr + read, n_samples * sizeof(*temp_src));

            } else {

                int len = FFMIN(n_samples - (read % n_samples), buffer_length - read);



                memcpy(temp_src, bptr + read, len * sizeof(*temp_src));

                memcpy(temp_src + len, bptr, (n_samples - len) * sizeof(*temp_src));

            }



            /* multiply signal and IR, and add up the results */

            dst[0] += s->fdsp->scalarproduct_float(temp_ir, temp_src, n_samples);

            temp_ir += n_samples;

        }



        /* clippings counter */

        if (fabs(*dst) > 1)

            *n_clippings += 1;



        /* move output buffer pointer by +2 to get to next sample of processed channel: */

        dst += 2;

        src += in_channels;

        wr   = (wr + 1) & modulo; /* update ringbuffer write position */

    }



    *write = wr; /* remember write position in ringbuffer for next call */



    return 0;

}

static int sofalizer_convolute(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)

{

    SOFAlizerContext *s = ctx->priv;

    ThreadData *td = arg;

    AVFrame *in = td->in, *out = td->out;

    int offset = jobnr;

    int *write = &td->write[jobnr];

    const int *const delay = td->delay[jobnr];

    const float *const ir = td->ir[jobnr];

    int *n_clippings = &td->n_clippings[jobnr];

    float *ringbuffer = td->ringbuffer[jobnr];

    float *temp_src = td->temp_src[jobnr];

    const int n_samples = s->sofa.n_samples; 

    const float *src = (const float *)in->data[0]; 

    float *dst = (float *)out->data[0]; 

    const int in_channels = s->n_conv; 

    

    const int buffer_length = s->buffer_length;

    

    const uint32_t modulo = (uint32_t)buffer_length - 1;

    float *buffer[16]; 

    int wr = *write;

    int read;

    int i, l;



    dst += offset;

    for (l = 0; l < in_channels; l++) {

        

        buffer[l] = ringbuffer + l * buffer_length;

    }



    for (i = 0; i < in->nb_samples; i++) {

        const float *temp_ir = ir; 



        *dst = 0;

        for (l = 0; l < in_channels; l++) {

            

            *(buffer[l] + wr) = src[l];

        }



        

        for (l = 0; l < in_channels; l++) {

            const float *const bptr = buffer[l];



            if (l == s->lfe_channel) {

                

                

                *dst += *(buffer[s->lfe_channel] + wr) * s->gain_lfe;

                temp_ir += n_samples;

                continue;

            }



            





            read = (wr - *(delay + l) - (n_samples - 1) + buffer_length) & modulo;



            if (read + n_samples < buffer_length) {

                memcpy(temp_src, bptr + read, n_samples * sizeof(*temp_src));

            } else {

                int len = FFMIN(n_samples - (read % n_samples), buffer_length - read);



                memcpy(temp_src, bptr + read, len * sizeof(*temp_src));

                memcpy(temp_src + len, bptr, (n_samples - len) * sizeof(*temp_src));

            }



            

            dst[0] += s->fdsp->scalarproduct_float(temp_ir, temp_src, n_samples);

            temp_ir += n_samples;

        }



        

        if (fabs(*dst) > 1)

            *n_clippings += 1;



        

        dst += 2;

        src += in_channels;

        wr   = (wr + 1) & modulo; 

    }



    *write = wr; 



    return 0;

}

                temp_ir += n_samples;             temp_ir += n_samples;
static int FUNC_0(AVFilterContext *VAR_0, void *VAR_1, int VAR_2, int VAR_3)

{

    SOFAlizerContext *s = VAR_0->priv;

    ThreadData *td = VAR_1;

    AVFrame *in = td->in, *out = td->out;

    int VAR_4 = VAR_2;

    int *VAR_5 = &td->VAR_5[VAR_2];

    const int *const VAR_6 = td->VAR_6[VAR_2];

    const float *const VAR_7 = td->VAR_7[VAR_2];

    int *VAR_8 = &td->VAR_8[VAR_2];

    float *VAR_9 = td->VAR_9[VAR_2];

    float *VAR_10 = td->VAR_10[VAR_2];

    const int VAR_11 = s->sofa.VAR_11; 

    const float *VAR_12 = (const float *)in->data[0]; 

    float *VAR_13 = (float *)out->data[0]; 

    const int VAR_14 = s->n_conv; 

    

    const int VAR_15 = s->VAR_15;

    

    const uint32_t VAR_16 = (uint32_t)VAR_15 - 1;

    float *VAR_17[16]; 

    int VAR_18 = *VAR_5;

    int VAR_19;

    int VAR_20, VAR_21;



    VAR_13 += VAR_4;

    for (VAR_21 = 0; VAR_21 < VAR_14; VAR_21++) {

        

        VAR_17[VAR_21] = VAR_9 + VAR_21 * VAR_15;

    }



    for (VAR_20 = 0; VAR_20 < in->nb_samples; VAR_20++) {

        const float *temp_ir = VAR_7; 



        *VAR_13 = 0;

        for (VAR_21 = 0; VAR_21 < VAR_14; VAR_21++) {

            

            *(VAR_17[VAR_21] + VAR_18) = VAR_12[VAR_21];

        }



        

        for (VAR_21 = 0; VAR_21 < VAR_14; VAR_21++) {

            const float *const bptr = VAR_17[VAR_21];



            if (VAR_21 == s->lfe_channel) {

                

                

                *VAR_13 += *(VAR_17[s->lfe_channel] + VAR_18) * s->gain_lfe;

                temp_ir += VAR_11;

                continue;

            }



            





            VAR_19 = (VAR_18 - *(VAR_6 + VAR_21) - (VAR_11 - 1) + VAR_15) & VAR_16;



            if (VAR_19 + VAR_11 < VAR_15) {

                memcpy(VAR_10, bptr + VAR_19, VAR_11 * sizeof(*VAR_10));

            } else {

                int len = FFMIN(VAR_11 - (VAR_19 % VAR_11), VAR_15 - VAR_19);



                memcpy(VAR_10, bptr + VAR_19, len * sizeof(*VAR_10));

                memcpy(VAR_10 + len, bptr, (VAR_11 - len) * sizeof(*VAR_10));

            }



            

            VAR_13[0] += s->fdsp->scalarproduct_float(temp_ir, VAR_10, VAR_11);

            temp_ir += VAR_11;

        }



        

        if (fabs(*VAR_13) > 1)

            *VAR_8 += 1;



        

        VAR_13 += 2;

        VAR_12 += VAR_14;

        VAR_18   = (VAR_18 + 1) & VAR_16; 

    }



    *VAR_5 = VAR_18; 



    return 0;

}

static int FUNC_0(AVFilterContext *VAR_0, void *VAR_1, int VAR_2, int VAR_3)
{ SOFAlizerContext *s = VAR_0->priv; ThreadData *td = VAR_1; AVFrame *in = td->in, *out = td->out; int VAR_4 = VAR_2; int *VAR_5 = &td->VAR_5[VAR_2]; const int *const VAR_6 = td->VAR_6[VAR_2]; const float *const VAR_7 = td->VAR_7[VAR_2]; int *VAR_8 = &td->VAR_8[VAR_2]; float *VAR_9 = td->VAR_9[VAR_2]; float *VAR_10 = td->VAR_10[VAR_2]; const int VAR_11 = s->sofa.VAR_11; const float *VAR_12 = (const float *)in->data[0]; float *VAR_13 = (float *)out->data[0]; const int VAR_14 = s->n_conv; const int VAR_15 = s->VAR_15; const uint32_t VAR_16 = (uint32_t)VAR_15 - 1; float *VAR_17[16]; int VAR_18 = *VAR_5; int VAR_19; int VAR_20, VAR_21; VAR_13 += VAR_4; for (VAR_21 = 0; VAR_21 < VAR_14; VAR_21++) { VAR_17[VAR_21] = VAR_9 + VAR_21 * VAR_15; } for (VAR_20 = 0; VAR_20 < in->nb_samples; VAR_20++) { const float *temp_ir = VAR_7; *VAR_13 = 0; for (VAR_21 = 0; VAR_21 < VAR_14; VAR_21++) { *(VAR_17[VAR_21] + VAR_18) = VAR_12[VAR_21]; } for (VAR_21 = 0; VAR_21 < VAR_14; VAR_21++) { const float *const bptr = VAR_17[VAR_21]; if (VAR_21 == s->lfe_channel) { *VAR_13 += *(VAR_17[s->lfe_channel] + VAR_18) * s->gain_lfe; temp_ir += VAR_11; continue; } VAR_19 = (VAR_18 - *(VAR_6 + VAR_21) - (VAR_11 - 1) + VAR_15) & VAR_16; if (VAR_19 + VAR_11 < VAR_15) { memcpy(VAR_10, bptr + VAR_19, VAR_11 * sizeof(*VAR_10)); } else { int len = FFMIN(VAR_11 - (VAR_19 % VAR_11), VAR_15 - VAR_19); memcpy(VAR_10, bptr + VAR_19, len * sizeof(*VAR_10)); memcpy(VAR_10 + len, bptr, (VAR_11 - len) * sizeof(*VAR_10)); } VAR_13[0] += s->fdsp->scalarproduct_float(temp_ir, VAR_10, VAR_11); temp_ir += VAR_11; } if (fabs(*VAR_13) > 1)
*VAR_8 += 1; VAR_13 += 2; VAR_12 += VAR_14; VAR_18   = (VAR_18 + 1) & VAR_16; } *VAR_5 = VAR_18; return 0; }