コード例 #1
0
ファイル: FilterParams.cpp プロジェクト: beatwise/ZynWise
/*
 * Transforms a parameter to the real value
 */
REALTYPE FilterParams::getformantfreq(unsigned char freq)
{
    REALTYPE result = getfreqx(freq / 127.0);
    return result;
}
コード例 #2
0
ファイル: FilterParams.cpp プロジェクト: beatwise/ZynWise
/*
 * Get the x coordinate from frequency (used by the UI)
 */
REALTYPE FilterParams::getfreqpos(REALTYPE freq)
{
    return (log(freq) - log(getfreqx(0.0))) / log(2.0) / getoctavesfreq();
}
コード例 #3
0
ファイル: FilterParams.cpp プロジェクト: beatwise/ZynWise
/*
 * Get the freq. response of the formant filter
 */
void FilterParams::formantfilterH(int nvowel, int nfreqs, REALTYPE *freqs)
{
    REALTYPE c[3], d[3];
    REALTYPE filter_freq, filter_q, filter_amp;
    REALTYPE omega, sn, cs, alpha;

    for(int i = 0; i < nfreqs; i++)
        freqs[i] = 0.0;

    //for each formant...
    for(int nformant = 0; nformant < Pnumformants; nformant++) {
        //compute formant parameters(frequency,amplitude,etc.)
        filter_freq = getformantfreq(Pvowels[nvowel].formants[nformant].freq);
        filter_q    = getformantq(Pvowels[nvowel].formants[nformant].q) * getq();
        if(Pstages > 0)
            filter_q =
                (filter_q > 1.0 ? POW(filter_q, 1.0 / (Pstages + 1)) : filter_q);

        filter_amp = getformantamp(Pvowels[nvowel].formants[nformant].amp);


        if(filter_freq <= (SAMPLE_RATE / 2 - 100.0)) {
            omega = 2 * PI * filter_freq / SAMPLE_RATE;
            sn    = sin(omega);
            cs    = cos(omega);
            alpha = sn / (2 * filter_q);
            REALTYPE tmp = 1 + alpha;
            c[0]  = alpha / tmp *sqrt(filter_q + 1);
            c[1]  = 0;
            c[2]  = -alpha / tmp *sqrt(filter_q + 1);
            d[1]  = -2 * cs / tmp * (-1);
            d[2]  = (1 - alpha) / tmp * (-1);
        }
        else
            continue;


        for(int i = 0; i < nfreqs; i++) {
            REALTYPE freq = getfreqx(i / (REALTYPE) nfreqs);
            if(freq > SAMPLE_RATE / 2) {
                for(int tmp = i; tmp < nfreqs; tmp++)
                    freqs[tmp] = 0.0;
                break;
            }
            REALTYPE fr = freq / SAMPLE_RATE * PI * 2.0;
            REALTYPE x  = c[0], y = 0.0;
            for(int n = 1; n < 3; n++) {
                x += cos(n * fr) * c[n];
                y -= sin(n * fr) * c[n];
            }
            REALTYPE h = x * x + y * y;
            x = 1.0;
            y = 0.0;
            for(int n = 1; n < 3; n++) {
                x -= cos(n * fr) * d[n];
                y += sin(n * fr) * d[n];
            }
            h = h / (x * x + y * y);

            freqs[i] += POW(h, (Pstages + 1.0) / 2.0) * filter_amp;
        }
    }
    for(int i = 0; i < nfreqs; i++) {
        if(freqs[i] > 0.000000001)
            freqs[i] = rap2dB(freqs[i]) + getgain();
        else
            freqs[i] = -90.0;
    }
}
コード例 #4
0
ファイル: resonance.cpp プロジェクト: XelaRellum/zyn
/*
 * Get the x coordinate from frequency (used by the UI)
 */
REALTYPE Resonance::getfreqpos(REALTYPE freq){
  return((log(freq)-log(getfreqx(0.0)))/log(2.0)/getoctavesfreq());
};