Ejemplo n.º 1
0
/*
 * Prepare the Oscillator
 */
void OscilGen::prepare()
{
    int      i, j, k;
    REALTYPE a, b, c, d, hmagnew;

    if((oldbasepar != Pbasefuncpar) || (oldbasefunc != Pcurrentbasefunc)
       || (oldbasefuncmodulation != Pbasefuncmodulation)
       || (oldbasefuncmodulationpar1 != Pbasefuncmodulationpar1)
       || (oldbasefuncmodulationpar2 != Pbasefuncmodulationpar2)
       || (oldbasefuncmodulationpar3 != Pbasefuncmodulationpar3))
        changebasefunction();

    for(i = 0; i < MAX_AD_HARMONICS; i++)
        hphase[i] = (Phphase[i] - 64.0) / 64.0 * PI / (i + 1);

    for(i = 0; i < MAX_AD_HARMONICS; i++) {
        hmagnew = 1.0 - fabs(Phmag[i] / 64.0 - 1.0);
        switch(Phmagtype) {
        case 1:
            hmag[i] = exp(hmagnew * log(0.01));
            break;
        case 2:
            hmag[i] = exp(hmagnew * log(0.001));
            break;
        case 3:
            hmag[i] = exp(hmagnew * log(0.0001));
            break;
        case 4:
            hmag[i] = exp(hmagnew * log(0.00001));
            break;
        default:
            hmag[i] = 1.0 - hmagnew;
            break;
        }

        if(Phmag[i] < 64)
            hmag[i] = -hmag[i];
    }

    //remove the harmonics where Phmag[i]==64
    for(i = 0; i < MAX_AD_HARMONICS; i++)
        if(Phmag[i] == 64)
            hmag[i] = 0.0;


    for(i = 0; i < OSCIL_SIZE / 2; i++) {
        oscilFFTfreqs.c[i] = 0.0;
        oscilFFTfreqs.s[i] = 0.0;
    }
    if(Pcurrentbasefunc == 0) { //the sine case
        for(i = 0; i < MAX_AD_HARMONICS; i++) {
            oscilFFTfreqs.c[i + 1] = -hmag[i] * sin(hphase[i] * (i + 1)) / 2.0;
            oscilFFTfreqs.s[i + 1] = hmag[i] * cos(hphase[i] * (i + 1)) / 2.0;
        }
    }
    else {
        for(j = 0; j < MAX_AD_HARMONICS; j++) {
            if(Phmag[j] == 64)
                continue;
            for(i = 1; i < OSCIL_SIZE / 2; i++) {
                k = i * (j + 1);
                if(k >= OSCIL_SIZE / 2)
                    break;
                a = basefuncFFTfreqs.c[i];
                b = basefuncFFTfreqs.s[i];
                c = hmag[j] * cos(hphase[j] * k);
                d = hmag[j] * sin(hphase[j] * k);
                oscilFFTfreqs.c[k] += a * c - b * d;
                oscilFFTfreqs.s[k] += a * d + b * c;
            }
        }
    }

    if(Pharmonicshiftfirst != 0)
        shiftharmonics();



    if(Pfilterbeforews == 0) {
        waveshape();
        oscilfilter();
    }
    else {
        oscilfilter();
        waveshape();
    }

    modulation();
    spectrumadjust();
    if(Pharmonicshiftfirst == 0)
        shiftharmonics();

    oscilFFTfreqs.c[0] = 0.0;

    oldhmagtype      = Phmagtype;
    oldharmonicshift = Pharmonicshift + Pharmonicshiftfirst * 256;

    oscilprepared    = 1;
}
Ejemplo n.º 2
0
void OscilGen::prepare(fft_t *freqs)
{
    if((oldbasepar != Pbasefuncpar) || (oldbasefunc != Pcurrentbasefunc)
       || DIFF(basefuncmodulation) || DIFF(basefuncmodulationpar1)
       || DIFF(basefuncmodulationpar2) || DIFF(basefuncmodulationpar3))
        changebasefunction();

    for(int i = 0; i < MAX_AD_HARMONICS; ++i)
        hphase[i] = (Phphase[i] - 64.0f) / 64.0f * PI / (i + 1);

    for(int i = 0; i < MAX_AD_HARMONICS; ++i) {
        const float hmagnew = 1.0f - fabs(Phmag[i] / 64.0f - 1.0f);
        switch(Phmagtype) {
            case 1:
                hmag[i] = expf(hmagnew * logf(0.01f));
                break;
            case 2:
                hmag[i] = expf(hmagnew * logf(0.001f));
                break;
            case 3:
                hmag[i] = expf(hmagnew * logf(0.0001f));
                break;
            case 4:
                hmag[i] = expf(hmagnew * logf(0.00001f));
                break;
            default:
                hmag[i] = 1.0f - hmagnew;
                break;
        }

        if(Phmag[i] < 64)
            hmag[i] = -hmag[i];
    }

    //remove the harmonics where Phmag[i]==64
    for(int i = 0; i < MAX_AD_HARMONICS; ++i)
        if(Phmag[i] == 64)
            hmag[i] = 0.0f;


    clearAll(freqs, synth.oscilsize);
    if(Pcurrentbasefunc == 0)   //the sine case
        for(int i = 0; i < MAX_AD_HARMONICS - 1; ++i) {
            freqs[i + 1] =
                std::complex<float>(-hmag[i] * sinf(hphase[i] * (i + 1)) / 2.0f,
                        hmag[i] * cosf(hphase[i] * (i + 1)) / 2.0f);
        }
    else
        for(int j = 0; j < MAX_AD_HARMONICS; ++j) {
            if(Phmag[j] == 64)
                continue;
            for(int i = 1; i < synth.oscilsize / 2; ++i) {
                int k = i * (j + 1);
                if(k >= synth.oscilsize / 2)
                    break;
                freqs[k] += basefuncFFTfreqs[i] * FFTpolar<fftw_real>(
                    hmag[j],
                    hphase[j] * k);
            }
        }

    if(Pharmonicshiftfirst != 0)
        shiftharmonics(freqs);

    if(Pfilterbeforews) {
        oscilfilter(freqs);
        waveshape(freqs);
    } else {
        waveshape(freqs);
        oscilfilter(freqs);
    }

    modulation(freqs);
    spectrumadjust(freqs);
    if(Pharmonicshiftfirst == 0)
        shiftharmonics(freqs);

    clearDC(freqs);

    oldhmagtype      = Phmagtype;
    oldharmonicshift = Pharmonicshift + Pharmonicshiftfirst * 256;

    oscilprepared = 1;
}