static int build_filter(ResampleContext *c, void *filter, double factor, int tap_count, int alloc, int phase_count, int scale,

                        int filter_type, int kaiser_beta){

    int ph, i;

    double x, y, w;

    double *tab = av_malloc_array(tap_count,  sizeof(*tab));

    const int center= (tap_count-1)/2;



    if (!tab)

        return AVERROR(ENOMEM);



    /* if upsampling, only need to interpolate, no filter */

    if (factor > 1.0)

        factor = 1.0;



    for(ph=0;ph<phase_count;ph++) {

        double norm = 0;

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

            x = M_PI * ((double)(i - center) - (double)ph / phase_count) * factor;

            if (x == 0) y = 1.0;

            else        y = sin(x) / x;

            switch(filter_type){

            case SWR_FILTER_TYPE_CUBIC:{

                const float d= -0.5; //first order derivative = -0.5

                x = fabs(((double)(i - center) - (double)ph / phase_count) * factor);

                if(x<1.0) y= 1 - 3*x*x + 2*x*x*x + d*(            -x*x + x*x*x);

                else      y=                       d*(-4 + 8*x - 5*x*x + x*x*x);

                break;}

            case SWR_FILTER_TYPE_BLACKMAN_NUTTALL:

                w = 2.0*x / (factor*tap_count) + M_PI;

                y *= 0.3635819 - 0.4891775 * cos(w) + 0.1365995 * cos(2*w) - 0.0106411 * cos(3*w);

                break;

            case SWR_FILTER_TYPE_KAISER:

                w = 2.0*x / (factor*tap_count*M_PI);

                y *= bessel(kaiser_beta*sqrt(FFMAX(1-w*w, 0)));

                break;

            default:

                av_assert0(0);

            }



            tab[i] = y;

            norm += y;

        }



        /* normalize so that an uniform color remains the same */

        switch(c->format){

        case AV_SAMPLE_FMT_S16P:

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

                ((int16_t*)filter)[ph * alloc + i] = av_clip(lrintf(tab[i] * scale / norm), INT16_MIN, INT16_MAX);

            break;

        case AV_SAMPLE_FMT_S32P:

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

                ((int32_t*)filter)[ph * alloc + i] = av_clipl_int32(llrint(tab[i] * scale / norm));

            break;

        case AV_SAMPLE_FMT_FLTP:

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

                ((float*)filter)[ph * alloc + i] = tab[i] * scale / norm;

            break;

        case AV_SAMPLE_FMT_DBLP:

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

                ((double*)filter)[ph * alloc + i] = tab[i] * scale / norm;

            break;

        }

    }

#if 0

    {

#define LEN 1024

        int j,k;

        double sine[LEN + tap_count];

        double filtered[LEN];

        double maxff=-2, minff=2, maxsf=-2, minsf=2;

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

            double ss=0, sf=0, ff=0;

            for(j=0; j<LEN+tap_count; j++)

                sine[j]= cos(i*j*M_PI/LEN);

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

                double sum=0;

                ph=0;

                for(k=0; k<tap_count; k++)

                    sum += filter[ph * tap_count + k] * sine[k+j];

                filtered[j]= sum / (1<<FILTER_SHIFT);

                ss+= sine[j + center] * sine[j + center];

                ff+= filtered[j] * filtered[j];

                sf+= sine[j + center] * filtered[j];

            }

            ss= sqrt(2*ss/LEN);

            ff= sqrt(2*ff/LEN);

            sf= 2*sf/LEN;

            maxff= FFMAX(maxff, ff);

            minff= FFMIN(minff, ff);

            maxsf= FFMAX(maxsf, sf);

            minsf= FFMIN(minsf, sf);

            if(i%11==0){

                av_log(NULL, AV_LOG_ERROR, "i:%4d ss:%f ff:%13.6e-%13.6e sf:%13.6e-%13.6e\n", i, ss, maxff, minff, maxsf, minsf);

                minff=minsf= 2;

                maxff=maxsf= -2;

            }

        }

    }

#endif



    av_free(tab);

    return 0;

}

static int build_filter(ResampleContext *c, void *filter, double factor, int tap_count, int alloc, int phase_count, int scale,

                        int filter_type, int kaiser_beta){

    int ph, i;

    double x, y, w;

    double *tab = av_malloc_array(tap_count,  sizeof(*tab));

    const int center= (tap_count-1)/2;



    if (!tab)

        return AVERROR(ENOMEM);



    

    if (factor > 1.0)

        factor = 1.0;



    for(ph=0;ph<phase_count;ph++) {

        double norm = 0;

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

            x = M_PI * ((double)(i - center) - (double)ph / phase_count) * factor;

            if (x == 0) y = 1.0;

            else        y = sin(x) / x;

            switch(filter_type){

            case SWR_FILTER_TYPE_CUBIC:{

                const float d= -0.5; 

                x = fabs(((double)(i - center) - (double)ph / phase_count) * factor);

                if(x<1.0) y= 1 - 3*x*x + 2*x*x*x + d*(            -x*x + x*x*x);

                else      y=                       d*(-4 + 8*x - 5*x*x + x*x*x);

                break;}

            case SWR_FILTER_TYPE_BLACKMAN_NUTTALL:

                w = 2.0*x / (factor*tap_count) + M_PI;

                y *= 0.3635819 - 0.4891775 * cos(w) + 0.1365995 * cos(2*w) - 0.0106411 * cos(3*w);

                break;

            case SWR_FILTER_TYPE_KAISER:

                w = 2.0*x / (factor*tap_count*M_PI);

                y *= bessel(kaiser_beta*sqrt(FFMAX(1-w*w, 0)));

                break;

            default:

                av_assert0(0);

            }



            tab[i] = y;

            norm += y;

        }



        

        switch(c->format){

        case AV_SAMPLE_FMT_S16P:

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

                ((int16_t*)filter)[ph * alloc + i] = av_clip(lrintf(tab[i] * scale / norm), INT16_MIN, INT16_MAX);

            break;

        case AV_SAMPLE_FMT_S32P:

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

                ((int32_t*)filter)[ph * alloc + i] = av_clipl_int32(llrint(tab[i] * scale / norm));

            break;

        case AV_SAMPLE_FMT_FLTP:

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

                ((float*)filter)[ph * alloc + i] = tab[i] * scale / norm;

            break;

        case AV_SAMPLE_FMT_DBLP:

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

                ((double*)filter)[ph * alloc + i] = tab[i] * scale / norm;

            break;

        }

    }

#if 0

    {

#define LEN 1024

        int j,k;

        double sine[LEN + tap_count];

        double filtered[LEN];

        double maxff=-2, minff=2, maxsf=-2, minsf=2;

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

            double ss=0, sf=0, ff=0;

            for(j=0; j<LEN+tap_count; j++)

                sine[j]= cos(i*j*M_PI/LEN);

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

                double sum=0;

                ph=0;

                for(k=0; k<tap_count; k++)

                    sum += filter[ph * tap_count + k] * sine[k+j];

                filtered[j]= sum / (1<<FILTER_SHIFT);

                ss+= sine[j + center] * sine[j + center];

                ff+= filtered[j] * filtered[j];

                sf+= sine[j + center] * filtered[j];

            }

            ss= sqrt(2*ss/LEN);

            ff= sqrt(2*ff/LEN);

            sf= 2*sf/LEN;

            maxff= FFMAX(maxff, ff);

            minff= FFMIN(minff, ff);

            maxsf= FFMAX(maxsf, sf);

            minsf= FFMIN(minsf, sf);

            if(i%11==0){

                av_log(NULL, AV_LOG_ERROR, "i:%4d ss:%f ff:%13.6e-%13.6e sf:%13.6e-%13.6e\n", i, ss, maxff, minff, maxsf, minsf);

                minff=minsf= 2;

                maxff=maxsf= -2;

            }

        }

    }

#endif



    av_free(tab);

    return 0;

}

    double *tab = av_malloc_array(tap_count,  sizeof(*tab));     for(ph=0;ph<phase_count;ph++) {         for(i=0;i<tap_count;i++) {             norm += y;
static int FUNC_0(ResampleContext *VAR_0, void *VAR_1, double VAR_2, int VAR_3, int VAR_4, int VAR_5, int VAR_6,

                        int VAR_7, int VAR_8){

    int VAR_9, VAR_10;

    double VAR_11, VAR_12, VAR_13;

    double *VAR_14 = av_malloc_array(VAR_3,  sizeof(*VAR_14));

    const int VAR_15= (VAR_3-1)/2;



    if (!VAR_14)

        return AVERROR(ENOMEM);



    

    if (VAR_2 > 1.0)

        VAR_2 = 1.0;



    for(VAR_9=0;VAR_9<VAR_5;VAR_9++) {

        double VAR_16 = 0;

        for(VAR_10=0;VAR_10<VAR_3;VAR_10++) {

            VAR_11 = M_PI * ((double)(VAR_10 - VAR_15) - (double)VAR_9 / VAR_5) * VAR_2;

            if (VAR_11 == 0) VAR_12 = 1.0;

            else        VAR_12 = sin(VAR_11) / VAR_11;

            switch(VAR_7){

            case SWR_FILTER_TYPE_CUBIC:{

                const float VAR_17= -0.5; 

                VAR_11 = fabs(((double)(VAR_10 - VAR_15) - (double)VAR_9 / VAR_5) * VAR_2);

                if(VAR_11<1.0) VAR_12= 1 - 3*VAR_11*VAR_11 + 2*VAR_11*VAR_11*VAR_11 + VAR_17*(            -VAR_11*VAR_11 + VAR_11*VAR_11*VAR_11);

                else      VAR_12=                       VAR_17*(-4 + 8*VAR_11 - 5*VAR_11*VAR_11 + VAR_11*VAR_11*VAR_11);

                break;}

            case SWR_FILTER_TYPE_BLACKMAN_NUTTALL:

                VAR_13 = 2.0*VAR_11 / (VAR_2*VAR_3) + M_PI;

                VAR_12 *= 0.3635819 - 0.4891775 * cos(VAR_13) + 0.1365995 * cos(2*VAR_13) - 0.0106411 * cos(3*VAR_13);

                break;

            case SWR_FILTER_TYPE_KAISER:

                VAR_13 = 2.0*VAR_11 / (VAR_2*VAR_3*M_PI);

                VAR_12 *= bessel(VAR_8*sqrt(FFMAX(1-VAR_13*VAR_13, 0)));

                break;

            default:

                av_assert0(0);

            }



            VAR_14[VAR_10] = VAR_12;

            VAR_16 += VAR_12;

        }



        

        switch(VAR_0->format){

        case AV_SAMPLE_FMT_S16P:

            for(VAR_10=0;VAR_10<VAR_3;VAR_10++)

                ((int16_t*)VAR_1)[VAR_9 * VAR_4 + VAR_10] = av_clip(lrintf(VAR_14[VAR_10] * VAR_6 / VAR_16), INT16_MIN, INT16_MAX);

            break;

        case AV_SAMPLE_FMT_S32P:

            for(VAR_10=0;VAR_10<VAR_3;VAR_10++)

                ((int32_t*)VAR_1)[VAR_9 * VAR_4 + VAR_10] = av_clipl_int32(llrint(VAR_14[VAR_10] * VAR_6 / VAR_16));

            break;

        case AV_SAMPLE_FMT_FLTP:

            for(VAR_10=0;VAR_10<VAR_3;VAR_10++)

                ((float*)VAR_1)[VAR_9 * VAR_4 + VAR_10] = VAR_14[VAR_10] * VAR_6 / VAR_16;

            break;

        case AV_SAMPLE_FMT_DBLP:

            for(VAR_10=0;VAR_10<VAR_3;VAR_10++)

                ((double*)VAR_1)[VAR_9 * VAR_4 + VAR_10] = VAR_14[VAR_10] * VAR_6 / VAR_16;

            break;

        }

    }

#if 0

    {

#define LEN 1024

        int j,k;

        double sine[LEN + VAR_3];

        double filtered[LEN];

        double maxff=-2, minff=2, maxsf=-2, minsf=2;

        for(VAR_10=0; VAR_10<LEN; VAR_10++){

            double ss=0, sf=0, ff=0;

            for(j=0; j<LEN+VAR_3; j++)

                sine[j]= cos(VAR_10*j*M_PI/LEN);

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

                double sum=0;

                VAR_9=0;

                for(k=0; k<VAR_3; k++)

                    sum += VAR_1[VAR_9 * VAR_3 + k] * sine[k+j];

                filtered[j]= sum / (1<<FILTER_SHIFT);

                ss+= sine[j + VAR_15] * sine[j + VAR_15];

                ff+= filtered[j] * filtered[j];

                sf+= sine[j + VAR_15] * filtered[j];

            }

            ss= sqrt(2*ss/LEN);

            ff= sqrt(2*ff/LEN);

            sf= 2*sf/LEN;

            maxff= FFMAX(maxff, ff);

            minff= FFMIN(minff, ff);

            maxsf= FFMAX(maxsf, sf);

            minsf= FFMIN(minsf, sf);

            if(VAR_10%11==0){

                av_log(NULL, AV_LOG_ERROR, "VAR_10:%4d ss:%f ff:%13.6e-%13.6e sf:%13.6e-%13.6e\n", VAR_10, ss, maxff, minff, maxsf, minsf);

                minff=minsf= 2;

                maxff=maxsf= -2;

            }

        }

    }

#endif



    av_free(VAR_14);

    return 0;

}

static int FUNC_0(ResampleContext *VAR_0, void *VAR_1, double VAR_2, int VAR_3, int VAR_4, int VAR_5, int VAR_6,
int VAR_7, int VAR_8){ int VAR_9, VAR_10; double VAR_11, VAR_12, VAR_13; double *VAR_14 = av_malloc_array(VAR_3,  sizeof(*VAR_14)); const int VAR_15= (VAR_3-1)/2; if (!VAR_14)
return AVERROR(ENOMEM); if (VAR_2 > 1.0)
VAR_2 = 1.0; for(VAR_9=0;VAR_9<VAR_5;VAR_9++) { double VAR_16 = 0; for(VAR_10=0;VAR_10<VAR_3;VAR_10++) { VAR_11 = M_PI * ((double)(VAR_10 - VAR_15) - (double)VAR_9 / VAR_5) * VAR_2; if (VAR_11 == 0) VAR_12 = 1.0; else        VAR_12 = sin(VAR_11) / VAR_11; switch(VAR_7){ case SWR_FILTER_TYPE_CUBIC:{ const float VAR_17= -0.5; VAR_11 = fabs(((double)(VAR_10 - VAR_15) - (double)VAR_9 / VAR_5) * VAR_2); if(VAR_11<1.0) VAR_12= 1 - 3*VAR_11*VAR_11 + 2*VAR_11*VAR_11*VAR_11 + VAR_17*(            -VAR_11*VAR_11 + VAR_11*VAR_11*VAR_11); else      VAR_12=                       VAR_17*(-4 + 8*VAR_11 - 5*VAR_11*VAR_11 + VAR_11*VAR_11*VAR_11); break;} case SWR_FILTER_TYPE_BLACKMAN_NUTTALL:
VAR_13 = 2.0*VAR_11 / (VAR_2*VAR_3) + M_PI; VAR_12 *= 0.3635819 - 0.4891775 * cos(VAR_13) + 0.1365995 * cos(2*VAR_13) - 0.0106411 * cos(3*VAR_13); break; case SWR_FILTER_TYPE_KAISER:
VAR_13 = 2.0*VAR_11 / (VAR_2*VAR_3*M_PI); VAR_12 *= bessel(VAR_8*sqrt(FFMAX(1-VAR_13*VAR_13, 0))); break; default:
av_assert0(0); } VAR_14[VAR_10] = VAR_12; VAR_16 += VAR_12; } switch(VAR_0->format){ case AV_SAMPLE_FMT_S16P:
for(VAR_10=0;VAR_10<VAR_3;VAR_10++) ((int16_t*)VAR_1)[VAR_9 * VAR_4 + VAR_10] = av_clip(lrintf(VAR_14[VAR_10] * VAR_6 / VAR_16), INT16_MIN, INT16_MAX); break; case AV_SAMPLE_FMT_S32P:
for(VAR_10=0;VAR_10<VAR_3;VAR_10++) ((int32_t*)VAR_1)[VAR_9 * VAR_4 + VAR_10] = av_clipl_int32(llrint(VAR_14[VAR_10] * VAR_6 / VAR_16)); break; case AV_SAMPLE_FMT_FLTP:
for(VAR_10=0;VAR_10<VAR_3;VAR_10++) ((float*)VAR_1)[VAR_9 * VAR_4 + VAR_10] = VAR_14[VAR_10] * VAR_6 / VAR_16; break; case AV_SAMPLE_FMT_DBLP:
for(VAR_10=0;VAR_10<VAR_3;VAR_10++) ((double*)VAR_1)[VAR_9 * VAR_4 + VAR_10] = VAR_14[VAR_10] * VAR_6 / VAR_16; break; } } #if 0
{ #define LEN 1024
int j,k; double sine[LEN + VAR_3]; double filtered[LEN]; double maxff=-2, minff=2, maxsf=-2, minsf=2; for(VAR_10=0; VAR_10<LEN; VAR_10++){ double ss=0, sf=0, ff=0; for(j=0; j<LEN+VAR_3; j++) sine[j]= cos(VAR_10*j*M_PI/LEN); for(j=0; j<LEN; j++){ double sum=0; VAR_9=0; for(k=0; k<VAR_3; k++) sum += VAR_1[VAR_9 * VAR_3 + k] * sine[k+j]; filtered[j]= sum / (1<<FILTER_SHIFT); ss+= sine[j + VAR_15] * sine[j + VAR_15]; ff+= filtered[j] * filtered[j]; sf+= sine[j + VAR_15] * filtered[j]; } ss= sqrt(2*ss/LEN); ff= sqrt(2*ff/LEN); sf= 2*sf/LEN; maxff= FFMAX(maxff, ff); minff= FFMIN(minff, ff); maxsf= FFMAX(maxsf, sf); minsf= FFMIN(minsf, sf); if(VAR_10%11==0){ av_log(NULL, AV_LOG_ERROR, "VAR_10:%4d ss:%f ff:%13.6e-%13.6e sf:%13.6e-%13.6e\n", VAR_10, ss, maxff, minff, maxsf, minsf); minff=minsf= 2; maxff=maxsf= -2; } } } #endif
av_free(VAR_14); return 0; }