static int compand_delay(AVFilterContext *ctx, AVFrame *frame)

{

    CompandContext *s    = ctx->priv;

    AVFilterLink *inlink = ctx->inputs[0];

    const int channels = inlink->channels;

    const int nb_samples = frame->nb_samples;

    int chan, i, av_uninit(dindex), oindex, av_uninit(count);

    AVFrame *out_frame   = NULL;



    if (s->pts == AV_NOPTS_VALUE) {

        s->pts = (frame->pts == AV_NOPTS_VALUE) ? 0 : frame->pts;

    }



    av_assert1(channels > 0); /* would corrupt delay_count and delay_index */



    for (chan = 0; chan < channels; chan++) {

        AVFrame *delay_frame = s->delay_frame;

        const double *src = (double *)frame->extended_data[chan];

        double *dbuf      = (double *)delay_frame->extended_data[chan];

        ChanParam *cp        = &s->channels[chan];

        double *dst;



        count  = s->delay_count;

        dindex = s->delay_index;

        for (i = 0, oindex = 0; i < nb_samples; i++) {

            const double in = src[i];

            update_volume(cp, fabs(in));



            if (count >= s->delay_samples) {

                if (!out_frame) {

                    out_frame = ff_get_audio_buffer(inlink, nb_samples - i);

                    if (!out_frame) {

                        av_frame_free(&frame);

                        return AVERROR(ENOMEM);

                    }

                    av_frame_copy_props(out_frame, frame);

                    out_frame->pts = s->pts;

                    s->pts += av_rescale_q(nb_samples - i,

                        (AVRational){ 1, inlink->sample_rate },

                        inlink->time_base);

                }



                dst = (double *)out_frame->extended_data[chan];

                dst[oindex++] = av_clipd(dbuf[dindex] *

                        get_volume(s, cp->volume), -1, 1);

            } else {

                count++;

            }



            dbuf[dindex] = in;

            dindex = MOD(dindex + 1, s->delay_samples);

        }

    }



    s->delay_count = count;

    s->delay_index = dindex;



    av_frame_free(&frame);

    return out_frame ? ff_filter_frame(ctx->outputs[0], out_frame) : 0;

}

static int compand_delay(AVFilterContext *ctx, AVFrame *frame)

{

    CompandContext *s    = ctx->priv;

    AVFilterLink *inlink = ctx->inputs[0];

    const int channels = inlink->channels;

    const int nb_samples = frame->nb_samples;

    int chan, i, av_uninit(dindex), oindex, av_uninit(count);

    AVFrame *out_frame   = NULL;



    if (s->pts == AV_NOPTS_VALUE) {

        s->pts = (frame->pts == AV_NOPTS_VALUE) ? 0 : frame->pts;

    }



    av_assert1(channels > 0); 



    for (chan = 0; chan < channels; chan++) {

        AVFrame *delay_frame = s->delay_frame;

        const double *src = (double *)frame->extended_data[chan];

        double *dbuf      = (double *)delay_frame->extended_data[chan];

        ChanParam *cp        = &s->channels[chan];

        double *dst;



        count  = s->delay_count;

        dindex = s->delay_index;

        for (i = 0, oindex = 0; i < nb_samples; i++) {

            const double in = src[i];

            update_volume(cp, fabs(in));



            if (count >= s->delay_samples) {

                if (!out_frame) {

                    out_frame = ff_get_audio_buffer(inlink, nb_samples - i);

                    if (!out_frame) {

                        av_frame_free(&frame);

                        return AVERROR(ENOMEM);

                    }

                    av_frame_copy_props(out_frame, frame);

                    out_frame->pts = s->pts;

                    s->pts += av_rescale_q(nb_samples - i,

                        (AVRational){ 1, inlink->sample_rate },

                        inlink->time_base);

                }



                dst = (double *)out_frame->extended_data[chan];

                dst[oindex++] = av_clipd(dbuf[dindex] *

                        get_volume(s, cp->volume), -1, 1);

            } else {

                count++;

            }



            dbuf[dindex] = in;

            dindex = MOD(dindex + 1, s->delay_samples);

        }

    }



    s->delay_count = count;

    s->delay_index = dindex;



    av_frame_free(&frame);

    return out_frame ? ff_filter_frame(ctx->outputs[0], out_frame) : 0;

}

static int FUNC_0(AVFilterContext *VAR_0, AVFrame *VAR_1)

{

    CompandContext *s    = VAR_0->priv;

    AVFilterLink *inlink = VAR_0->inputs[0];

    const int VAR_2 = inlink->VAR_2;

    const int VAR_3 = VAR_1->VAR_3;

    int VAR_4, VAR_5, FUNC_1(dindex), oindex, FUNC_1(count);

    AVFrame *out_frame   = NULL;



    if (s->pts == AV_NOPTS_VALUE) {

        s->pts = (VAR_1->pts == AV_NOPTS_VALUE) ? 0 : VAR_1->pts;

    }



    av_assert1(VAR_2 > 0); 



    for (VAR_4 = 0; VAR_4 < VAR_2; VAR_4++) {

        AVFrame *delay_frame = s->delay_frame;

        const double *VAR_6 = (double *)VAR_1->extended_data[VAR_4];

        double *VAR_7      = (double *)delay_frame->extended_data[VAR_4];

        ChanParam *cp        = &s->VAR_2[VAR_4];

        double *VAR_8;



        count  = s->delay_count;

        dindex = s->delay_index;

        for (VAR_5 = 0, oindex = 0; VAR_5 < VAR_3; VAR_5++) {

            const double VAR_9 = VAR_6[VAR_5];

            update_volume(cp, fabs(VAR_9));



            if (count >= s->delay_samples) {

                if (!out_frame) {

                    out_frame = ff_get_audio_buffer(inlink, VAR_3 - VAR_5);

                    if (!out_frame) {

                        av_frame_free(&VAR_1);

                        return AVERROR(ENOMEM);

                    }

                    av_frame_copy_props(out_frame, VAR_1);

                    out_frame->pts = s->pts;

                    s->pts += av_rescale_q(VAR_3 - VAR_5,

                        (AVRational){ 1, inlink->sample_rate },

                        inlink->time_base);

                }



                VAR_8 = (double *)out_frame->extended_data[VAR_4];

                VAR_8[oindex++] = av_clipd(VAR_7[dindex] *

                        get_volume(s, cp->volume), -1, 1);

            } else {

                count++;

            }



            VAR_7[dindex] = VAR_9;

            dindex = MOD(dindex + 1, s->delay_samples);

        }

    }



    s->delay_count = count;

    s->delay_index = dindex;



    av_frame_free(&VAR_1);

    return out_frame ? ff_filter_frame(VAR_0->outputs[0], out_frame) : 0;

}

static int FUNC_0(AVFilterContext *VAR_0, AVFrame *VAR_1)
{ CompandContext *s    = VAR_0->priv; AVFilterLink *inlink = VAR_0->inputs[0]; const int VAR_2 = inlink->VAR_2; const int VAR_3 = VAR_1->VAR_3; int VAR_4, VAR_5, FUNC_1(dindex), oindex, FUNC_1(count); AVFrame *out_frame   = NULL; if (s->pts == AV_NOPTS_VALUE) { s->pts = (VAR_1->pts == AV_NOPTS_VALUE) ? 0 : VAR_1->pts; } av_assert1(VAR_2 > 0); for (VAR_4 = 0; VAR_4 < VAR_2; VAR_4++) { AVFrame *delay_frame = s->delay_frame; const double *VAR_6 = (double *)VAR_1->extended_data[VAR_4]; double *VAR_7      = (double *)delay_frame->extended_data[VAR_4]; ChanParam *cp        = &s->VAR_2[VAR_4]; double *VAR_8; count  = s->delay_count; dindex = s->delay_index; for (VAR_5 = 0, oindex = 0; VAR_5 < VAR_3; VAR_5++) { const double VAR_9 = VAR_6[VAR_5]; update_volume(cp, fabs(VAR_9)); if (count >= s->delay_samples) { if (!out_frame) { out_frame = ff_get_audio_buffer(inlink, VAR_3 - VAR_5); if (!out_frame) { av_frame_free(&VAR_1); return AVERROR(ENOMEM); } av_frame_copy_props(out_frame, VAR_1); out_frame->pts = s->pts; s->pts += av_rescale_q(VAR_3 - VAR_5,
(AVRational){ 1, inlink->sample_rate }, inlink->time_base); } VAR_8 = (double *)out_frame->extended_data[VAR_4]; VAR_8[oindex++] = av_clipd(VAR_7[dindex] *
get_volume(s, cp->volume), -1, 1); } else { count++; } VAR_7[dindex] = VAR_9; dindex = MOD(dindex + 1, s->delay_samples); } } s->delay_count = count; s->delay_index = dindex; av_frame_free(&VAR_1); return out_frame ? ff_filter_frame(VAR_0->outputs[0], out_frame) : 0; }