static int hdcd_envelope(int32_t *samples, int count, int stride, int gain, int target_gain, int extend)

{

    int i;

    int32_t *samples_end = samples + stride * count;



    if (extend) {

        for (i = 0; i < count; i++) {

            int32_t sample = samples[i * stride];

            int32_t asample = abs(sample) - 0x5981;

            if (asample >= 0)

                sample = sample >= 0 ? peaktab[asample] : -peaktab[asample];

            else

                sample <<= 15;



            samples[i * stride] = sample;

        }

    } else {

        for (i = 0; i < count; i++)

            samples[i * stride] <<= 15;

    }



    if (gain <= target_gain) {

        int len = FFMIN(count, target_gain - gain);

        /* attenuate slowly */

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

            ++gain;

            APPLY_GAIN(*samples, gain);

            samples += stride;

        }

        count -= len;

    } else {

        int len = FFMIN(count, (gain - target_gain) >> 3);

        /* amplify quickly */

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

            gain -= 8;

            APPLY_GAIN(*samples, gain);

            samples += stride;

        }

        if (gain - 8 < target_gain)

            gain = target_gain;

        count -= len;

    }



    /* hold a steady level */

    if (gain == 0) {

        if (count > 0)

            samples += count * stride;

    } else {

        while (--count >= 0) {

            APPLY_GAIN(*samples, gain);

            samples += stride;

        }

    }



    av_assert0(samples == samples_end);



    return gain;

}

static int hdcd_envelope(int32_t *samples, int count, int stride, int gain, int target_gain, int extend)

{

    int i;

    int32_t *samples_end = samples + stride * count;



    if (extend) {

        for (i = 0; i < count; i++) {

            int32_t sample = samples[i * stride];

            int32_t asample = abs(sample) - 0x5981;

            if (asample >= 0)

                sample = sample >= 0 ? peaktab[asample] : -peaktab[asample];

            else

                sample <<= 15;



            samples[i * stride] = sample;

        }

    } else {

        for (i = 0; i < count; i++)

            samples[i * stride] <<= 15;

    }



    if (gain <= target_gain) {

        int len = FFMIN(count, target_gain - gain);

        

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

            ++gain;

            APPLY_GAIN(*samples, gain);

            samples += stride;

        }

        count -= len;

    } else {

        int len = FFMIN(count, (gain - target_gain) >> 3);

        

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

            gain -= 8;

            APPLY_GAIN(*samples, gain);

            samples += stride;

        }

        if (gain - 8 < target_gain)

            gain = target_gain;

        count -= len;

    }



    

    if (gain == 0) {

        if (count > 0)

            samples += count * stride;

    } else {

        while (--count >= 0) {

            APPLY_GAIN(*samples, gain);

            samples += stride;

        }

    }



    av_assert0(samples == samples_end);



    return gain;

}

static int FUNC_0(int32_t *VAR_0, int VAR_1, int VAR_2, int VAR_3, int VAR_4, int VAR_5)

{

    int VAR_6;

    int32_t *samples_end = VAR_0 + VAR_2 * VAR_1;



    if (VAR_5) {

        for (VAR_6 = 0; VAR_6 < VAR_1; VAR_6++) {

            int32_t sample = VAR_0[VAR_6 * VAR_2];

            int32_t asample = abs(sample) - 0x5981;

            if (asample >= 0)

                sample = sample >= 0 ? peaktab[asample] : -peaktab[asample];

            else

                sample <<= 15;



            VAR_0[VAR_6 * VAR_2] = sample;

        }

    } else {

        for (VAR_6 = 0; VAR_6 < VAR_1; VAR_6++)

            VAR_0[VAR_6 * VAR_2] <<= 15;

    }



    if (VAR_3 <= VAR_4) {

        int VAR_8 = FFMIN(VAR_1, VAR_4 - VAR_3);

        

        for (VAR_6 = 0; VAR_6 < VAR_8; VAR_6++) {

            ++VAR_3;

            APPLY_GAIN(*VAR_0, VAR_3);

            VAR_0 += VAR_2;

        }

        VAR_1 -= VAR_8;

    } else {

        int VAR_8 = FFMIN(VAR_1, (VAR_3 - VAR_4) >> 3);

        

        for (VAR_6 = 0; VAR_6 < VAR_8; VAR_6++) {

            VAR_3 -= 8;

            APPLY_GAIN(*VAR_0, VAR_3);

            VAR_0 += VAR_2;

        }

        if (VAR_3 - 8 < VAR_4)

            VAR_3 = VAR_4;

        VAR_1 -= VAR_8;

    }



    

    if (VAR_3 == 0) {

        if (VAR_1 > 0)

            VAR_0 += VAR_1 * VAR_2;

    } else {

        while (--VAR_1 >= 0) {

            APPLY_GAIN(*VAR_0, VAR_3);

            VAR_0 += VAR_2;

        }

    }



    av_assert0(VAR_0 == samples_end);



    return VAR_3;

}

static int FUNC_0(int32_t *VAR_0, int VAR_1, int VAR_2, int VAR_3, int VAR_4, int VAR_5)
{ int VAR_6; int32_t *samples_end = VAR_0 + VAR_2 * VAR_1; if (VAR_5) { for (VAR_6 = 0; VAR_6 < VAR_1; VAR_6++) { int32_t sample = VAR_0[VAR_6 * VAR_2]; int32_t asample = abs(sample) - 0x5981; if (asample >= 0)
sample = sample >= 0 ? peaktab[asample] : -peaktab[asample]; else
sample <<= 15; VAR_0[VAR_6 * VAR_2] = sample; } } else { for (VAR_6 = 0; VAR_6 < VAR_1; VAR_6++) VAR_0[VAR_6 * VAR_2] <<= 15; } if (VAR_3 <= VAR_4) { int VAR_8 = FFMIN(VAR_1, VAR_4 - VAR_3); for (VAR_6 = 0; VAR_6 < VAR_8; VAR_6++) { ++VAR_3; APPLY_GAIN(*VAR_0, VAR_3); VAR_0 += VAR_2; } VAR_1 -= VAR_8; } else { int VAR_8 = FFMIN(VAR_1, (VAR_3 - VAR_4) >> 3); for (VAR_6 = 0; VAR_6 < VAR_8; VAR_6++) { VAR_3 -= 8; APPLY_GAIN(*VAR_0, VAR_3); VAR_0 += VAR_2; } if (VAR_3 - 8 < VAR_4)
VAR_3 = VAR_4; VAR_1 -= VAR_8; } if (VAR_3 == 0) { if (VAR_1 > 0)
VAR_0 += VAR_1 * VAR_2; } else { while (--VAR_1 >= 0) { APPLY_GAIN(*VAR_0, VAR_3); VAR_0 += VAR_2; } } av_assert0(VAR_0 == samples_end); return VAR_3; }