예제 #1
0
Filter::Filter (Parameters *param, FilterParams * pars)
{
	this->param = param;
    unsigned char Ftype = pars->Ptype;
    unsigned char Fstages = pars->Pstages;

    category = pars->Pcategory;

    switch (category) {
    case 1:
        filter = new FormantFilter (param,pars);
        break;
    case 2:
        filter = new SVFilter(param, Ftype, 1000.0f, pars->getq (), Fstages);
        filter->outgain = dB2rap (pars->getgain ());
        if (filter->outgain > 1.0f)
            filter->outgain = sqrtf (filter->outgain);
        break;
    default:
        filter = new AnalogFilter (param, Ftype, 1000.0f, pars->getq (), Fstages);
        if ((Ftype >= 6) && (Ftype <= 8))
            filter->setgain (pars->getgain ());
        else
            filter->outgain = dB2rap (pars->getgain ());
        break;
    };
};
예제 #2
0
파일: Filter.C 프로젝트: NY-tram/rkrlv2
Filter::Filter (FilterParams * pars)
{
    unsigned char Ftype = pars->Ptype;
    unsigned char Fstages = pars->Pstages;

    category = pars->Pcategory;

    interpbuf = new float[pars->intermediate_bufsize];

    switch (category) {
    case 1:
        filter = new FormantFilter (pars, interpbuf);
        break;
    case 2:
        filter = new SVFilter(Ftype, 1000.0f, pars->getq (), Fstages, pars->fSAMPLE_RATE, interpbuf);
        filter->outgain = dB2rap (pars->getgain ());
        if (filter->outgain > 1.0f)
            filter->outgain = sqrtf (filter->outgain);
        break;
    default:
        filter = new AnalogFilter (Ftype, 1000.0f, pars->getq (), Fstages, pars->fSAMPLE_RATE, interpbuf);
        if ((Ftype >= 6) && (Ftype <= 8))
            filter->setgain (pars->getgain ());
        else
            filter->outgain = dB2rap (pars->getgain ());
        break;
    };
};
예제 #3
0
파일: Filter.cpp 프로젝트: Yoshimi/yoshimi
Filter::Filter(FilterParams *pars, SynthEngine *_synth):
    synth(_synth)
{
    unsigned char Ftype = pars->Ptype;
    unsigned char Fstages = pars->Pstages;

    category = pars->Pcategory;

    switch (category)
    {
        case 1:
            filter = new FormantFilter(pars, synth);
            break;

        case 2:
            filter = new SVFilter(Ftype, 1000.0f, pars->getq(), Fstages, synth);
            filter->outgain = dB2rap(pars->getgain());
            if (filter->outgain > 1.0f)
                filter->outgain = sqrtf(filter->outgain);
            break;

        default:
            filter = new AnalogFilter(Ftype, 1000.0f, pars->getq(), Fstages, synth);
            if (Ftype >= 6 && Ftype <= 8)
                filter->setgain(pars->getgain());
            else
                filter->outgain = dB2rap(pars->getgain());
            break;
    }
}
예제 #4
0
파일: Envelope.cpp 프로젝트: Cubiicle/lmms
/*
 * Envelope Output (dB)
 */
float Envelope::envout_dB()
{
    float out;
    if(linearenvelope != 0)
        return envout();

    if((currentpoint == 1) && (!keyreleased || (forcedrelase == 0))) { //first point is always lineary interpolated
        float v1 = dB2rap(envval[0]);
        float v2 = dB2rap(envval[1]);
        out = v1 + (v2 - v1) * t;

        t += inct;
        if(t >= 1.0f) {
            t    = 0.0f;
            inct = envdt[2];
            currentpoint++;
            out = v2;
        }

        if(out > 0.001f)
            envoutval = rap2dB(out);
        else
            envoutval = MIN_ENVELOPE_DB;
    }
    else
        out = dB2rap(envout());

    return out;
}
예제 #5
0
파일: Filter.cpp 프로젝트: ViktorNova/Carla
Filter *Filter::generate(Allocator &memory, FilterParams *pars,
        unsigned int srate, int bufsize)
{
    assert(srate != 0);
    assert(bufsize != 0);

    unsigned char Ftype   = pars->Ptype;
    unsigned char Fstages = pars->Pstages;

    Filter *filter;
    switch(pars->Pcategory) {
        case 1:
            filter = memory.alloc<FormantFilter>(pars, &memory, srate, bufsize);
            break;
        case 2:
            filter = memory.alloc<SVFilter>(Ftype, 1000.0f, pars->getq(), Fstages, srate, bufsize);
            filter->outgain = dB2rap(pars->getgain());
            if(filter->outgain > 1.0f)
                filter->outgain = sqrt(filter->outgain);
            break;
        default:
            filter = memory.alloc<AnalogFilter>(Ftype, 1000.0f, pars->getq(), Fstages, srate, bufsize);
            if((Ftype >= 6) && (Ftype <= 8))
                filter->setgain(pars->getgain());
            else
                filter->outgain = dB2rap(pars->getgain());
            break;
    }
    return filter;
}
예제 #6
0
파일: StompBox.C 프로젝트: NY-tram/rkrlv2
void
StompBox::changepar (int npar, int value)
{
    switch (npar) {
    case 0:
        setvolume (value);
        break;
    case 1:
        Phigh = value;
        if( value < 0) highb = ((float) value)/64.0f;
        if( value > 0) highb = ((float) value)/32.0f;
        break;
    case 2:
        Pmid = value;
        if( value < 0) midb = ((float) value)/64.0f;
        if( value > 0) midb = ((float) value)/32.0f;
        break;
    case 3:
        Plow = value;
        if( value < 0) lowb = ((float) value)/64.0f;
        if( value > 0) lowb = ((float) value)/32.0f;
        break;
    case 4:
        Pgain = value;
        gain = dB2rap(50.0f * ((float)value)/127.0f  - 50.0f);
        break;
    case 5:
        Pmode = value;
        init_mode (Pmode);
        break;

    };
    init_tone ();
};
예제 #7
0
void
RBFilter::setgain (float dBgain)
{
    gain = dB2rap (dBgain);
    if(!qmode) computefiltercoefs ();
    else computefiltercoefs_hiQ ();
};
예제 #8
0
void SVFilter::init(float sample_rate, int type, REALTYPE Ffreq, REALTYPE Fq, unsigned char Fstages, float gain)
{
  m_sample_rate = sample_rate;
  stages = Fstages;
  m_type = type;
  freq = Ffreq;
  q = Fq;
  m_gain = 1.0;
  m_outgain = 1.0;
  needsinterpolation = 0;
  firsttime = 1;

  if (stages >= MAX_FILTER_STAGES)
  {
    stages = MAX_FILTER_STAGES;
  }

  cleanup();
  setfreq_and_q(Ffreq,Fq);

  m_outgain = dB2rap(gain);
  if (m_outgain > 1.0)
  {
    m_outgain = sqrt(m_outgain);
  }
}
예제 #9
0
파일: CompBand.C 프로젝트: NY-tram/rkrlv2
void
CompBand::setlevel (int value)
{
    Plevel = value;
    level = dB2rap (60.0f * (float)value / 127.0f - 36.0f);


};
예제 #10
0
void
Sustainer::changepar (int npar, int value)
{
    switch (npar) {
    case 0:
        Pvolume = value;
        level = dB2rap(-30.0f * (1.0f - ((float) Pvolume/127.0f)));
        break;
    case 1:
        Psustain = value;
        fsustain =  (float) Psustain/127.0f;
        cratio = 1.25f - fsustain;
        input = dB2rap (42.0f * fsustain - 6.0f);
        cthresh = 0.25 + fsustain;
        break;

    };
};
예제 #11
0
파일: Vocoder.C 프로젝트: yroffin/Rakkarack
void
Vocoder::changepar (int npar, int value)
{
float tmp = 0;
  switch (npar)
    {
    case 0:
      setvolume (value);
      break;
    case 1:
      setpanning (value);
      break;
    case 2:
      Pmuffle = value;
      tmp = (float) Pmuffle;
      tmp *= 0.0001f + tmp/64000;
      alpha = ncSAMPLE_RATE/(ncSAMPLE_RATE + tmp);
      beta = 1.0f - alpha; 
      break;
    case 3: 
      Pqq = value;
      tmp = (float) value;
      adjustq(tmp);
      break;
    case 4:
      Pinput = value;
      input = dB2rap (75.0f * (float)Pinput / 127.0f - 40.0f);    
      break;      
    case 5:
      Plevel = value;
      level = dB2rap (60.0f * (float)Plevel / 127.0f - 40.0f);    
      break;      

    case 6:
      Pring = value;
      ringworm = (float) Pring/127.0f;    
      break; 
   };
};
예제 #12
0
파일: Expander.C 프로젝트: dtimms/rakarrack
void
Expander::Expander_Change (int np, int value)
{

    switch (np) {

    case 1:
        Pthreshold = value;
        tfactor = dB2rap (-((float) Pthreshold));
        tlevel = 1.0f/tfactor;
        break;
    case 2:
        Pshape = value;
        sfactor = dB2rap ((float)Pshape/2);
        sgain = expf(-sfactor);
        break;
    case 3:
        Pattack = value;
        a_rate = 1000.0f/((float)Pattack * fs);
        break;
    case 4:
        Pdecay = value;
        d_rate = 1000.0f/((float)Pdecay * fs);
        break;
    case 5:
        setlpf(value);
        break;
    case 6:
        sethpf(value);
        break;
    case 7:
        Plevel = value;
        level = dB2rap((float) value/6.0f);
        break;

    }


}
예제 #13
0
/*
 * Effect output
 */
void Distorsion::out(const Stereo<float *> &smp)
{
    int      i;
    REALTYPE l, r, lout, rout;

    REALTYPE inputvol = pow(5.0, (Pdrive - 32.0) / 127.0);
    if(Pnegate != 0)
        inputvol *= -1.0;

    if(Pstereo != 0) { //Stereo
        for(i = 0; i < SOUND_BUFFER_SIZE; i++) {
            efxoutl[i] = smp.l[i] * inputvol * panning;
            efxoutr[i] = smp.r[i] * inputvol * (1.0 - panning);
        }
    }
    else {
        for(i = 0; i < SOUND_BUFFER_SIZE; i++)
            efxoutl[i] =
                (smp.l[i] * panning + smp.r[i] * (1.0 - panning)) * inputvol;
        ;
    }

    if(Pprefiltering != 0)
        applyfilters(efxoutl, efxoutr);

    //no optimised, yet (no look table)
    waveshapesmps(SOUND_BUFFER_SIZE, efxoutl, Ptype + 1, Pdrive);
    if(Pstereo != 0)
        waveshapesmps(SOUND_BUFFER_SIZE, efxoutr, Ptype + 1, Pdrive);

    if(Pprefiltering == 0)
        applyfilters(efxoutl, efxoutr);

    if(Pstereo == 0)
        for(i = 0; i < SOUND_BUFFER_SIZE; i++)
            efxoutr[i] = efxoutl[i];

    REALTYPE level = dB2rap(60.0 * Plevel / 127.0 - 40.0);
    for(i = 0; i < SOUND_BUFFER_SIZE; i++) {
        lout = efxoutl[i];
        rout = efxoutr[i];
        l    = lout * (1.0 - lrcross) + rout * lrcross;
        r    = rout * (1.0 - lrcross) + lout * lrcross;
        lout = l;
        rout = r;

        efxoutl[i] = lout * 2.0 * level;
        efxoutr[i] = rout * 2.0 * level;
    }
}
예제 #14
0
FormantFilter::FormantFilter (FilterParams * pars)
{
  numformants = pars->Pnumformants;
  for (int i = 0; i < numformants; i++)
    formant[i] = new AnalogFilter (4 /*BPF*/, 1000.0f, 10.0f, pars->Pstages);
  cleanup ();
  inbuffer = new float[PERIOD];
  tmpbuf = new float[PERIOD];

  for (int j = 0; j < FF_MAX_VOWELS; j++)
    for (int i = 0; i < numformants; i++)
      {
	formantpar[j][i].freq =
	  pars->getformantfreq (pars->Pvowels[j].formants[i].freq);
	formantpar[j][i].amp =
	  pars->getformantamp (pars->Pvowels[j].formants[i].amp);
	formantpar[j][i].q =
	  pars->getformantq (pars->Pvowels[j].formants[i].q);
      };
  for (int i = 0; i < FF_MAX_FORMANTS; i++)
    oldformantamp[i] = 1.0;
  for (int i = 0; i < numformants; i++)
    {
      currentformants[i].freq = 1000.0f;
      currentformants[i].amp = 1.0f;
      currentformants[i].q = 2.0f;
    };

  formantslowness = powf (1.0f - ((float)pars->Pformantslowness / 128.0f), 3.0f);

  sequencesize = pars->Psequencesize;
  if (sequencesize == 0)
    sequencesize = 1;
  for (int k = 0; k < sequencesize; k++)
    sequence[k].nvowel = pars->Psequence[k].nvowel;

  vowelclearness = powf (10.0f, ((float)pars->Pvowelclearness - 32.0f) / 48.0f);

  sequencestretch = powf (0.1f, ((float)pars->Psequencestretch - 32.0f) / 48.0f);
  if (pars->Psequencereversed)
    sequencestretch *= -1.0f;

  outgain = dB2rap (pars->getgain ());

  oldinput = -1.0f;
  Qfactor = 1.0f;
  oldQfactor = Qfactor;
  firsttime = 1;
};
예제 #15
0
FormantFilter::FormantFilter(FilterParams *pars, SynthEngine *_synth):
    synth(_synth)
{
    numformants = pars->Pnumformants;
    for (int i = 0; i < numformants; ++i)
        formant[i] = new AnalogFilter(4/*BPF*/, 1000.0f, 10.0f, pars->Pstages, synth);
    cleanup();
    inbuffer = (float*)fftwf_malloc(synth->bufferbytes);
    tmpbuf = (float*)fftwf_malloc(synth->bufferbytes);

    for (int j = 0; j < FF_MAX_VOWELS; ++j)
        for (int i = 0; i < numformants; ++i)
        {
            formantpar[j][i].freq = pars->getformantfreq(pars->Pvowels[j].formants[i].freq);
            formantpar[j][i].amp = pars->getformantamp(pars->Pvowels[j].formants[i].amp);
            formantpar[j][i].q = pars->getformantq(pars->Pvowels[j].formants[i].q);
        }
    for (int i = 0; i < FF_MAX_FORMANTS; ++i)
        oldformantamp[i] = 1.0f;
    for (int i = 0; i < numformants; ++i)
    {
        currentformants[i].freq = 1000.0f;
        currentformants[i].amp = 1.0f;
        currentformants[i].q = 2.0f;
    }

    formantslowness = powf(1.0f - (pars->Pformantslowness / 128.0f), 3.0f);

    sequencesize = pars->Psequencesize;
    if (sequencesize == 0)
        sequencesize = 1;
    for (int k = 0; k < sequencesize; ++k)
        sequence[k].nvowel = pars->Psequence[k].nvowel;

    vowelclearness = powf(10.0f, (pars->Pvowelclearness - 32.0f) / 48.0f);

    sequencestretch = powf(0.1f, (pars->Psequencestretch - 32.0f) / 48.0f);
    if (pars->Psequencereversed)
        sequencestretch *= -1.0f;

    outgain = dB2rap(pars->getgain());

    oldinput = -1.0f;
    Qfactor = pars->getq();
    oldQfactor = Qfactor;
    firsttime = 1;
}
예제 #16
0
FormantFilter::FormantFilter(FilterParams *pars, Allocator *alloc, unsigned int srate, int bufsize)
    : Filter(srate, bufsize), memory(*alloc)
{
    numformants = pars->Pnumformants;
    for(int i = 0; i < numformants; ++i)
        formant[i] = memory.alloc<AnalogFilter>(4 /*BPF*/, 1000.0f, 10.0f, pars->Pstages, srate, bufsize);
    cleanup();

    for(int j = 0; j < FF_MAX_VOWELS; ++j)
        for(int i = 0; i < numformants; ++i) {
            formantpar[j][i].freq = pars->getformantfreq(
                pars->Pvowels[j].formants[i].freq);
            formantpar[j][i].amp = pars->getformantamp(
                pars->Pvowels[j].formants[i].amp);
            formantpar[j][i].q = pars->getformantq(
                pars->Pvowels[j].formants[i].q);
        }

    for(int i = 0; i < FF_MAX_FORMANTS; ++i)
        oldformantamp[i] = 1.0f;
    for(int i = 0; i < numformants; ++i) {
        currentformants[i].freq = 1000.0f;
        currentformants[i].amp  = 1.0f;
        currentformants[i].q    = 2.0f;
    }

    formantslowness = powf(1.0f - (pars->Pformantslowness / 128.0f), 3.0f);

    sequencesize = pars->Psequencesize;
    if(sequencesize == 0)
        sequencesize = 1;
    for(int k = 0; k < sequencesize; ++k)
        sequence[k].nvowel = pars->Psequence[k].nvowel;

    vowelclearness = powf(10.0f, (pars->Pvowelclearness - 32.0f) / 48.0f);

    sequencestretch = powf(0.1f, (pars->Psequencestretch - 32.0f) / 48.0f);
    if(pars->Psequencereversed)
        sequencestretch *= -1.0f;

    outgain = dB2rap(pars->getgain());

    oldinput   = -1.0f;
    Qfactor = pars->getq();
    oldQfactor = Qfactor;
    firsttime  = 1;
}
예제 #17
0
// Effect output
void Distorsion::out(float *smpsl, float *smpsr)
{
    float inputdrive = powf(5.0f, (Pdrive - 32.0f) / 127.0f);
    if (Pnegate)
        inputdrive *= -1.0f;

    if (Pstereo) // Stereo
    {
        for (int i = 0; i < synth->p_buffersize; ++i)
        {
            efxoutl[i] = smpsl[i] * inputdrive * pangainL;
            efxoutr[i] = smpsr[i] * inputdrive* pangainR;
        }
    }
    else // Mono
        for (int i = 0; i < synth->p_buffersize; ++i)
            efxoutl[i] = inputdrive * (smpsl[i]* pangainL + smpsr[i]* pangainR) * 0.7f;

    if (Pprefiltering)
        applyfilters(efxoutl, efxoutr);

    waveShapeSmps(synth->p_buffersize, efxoutl, Ptype + 1, Pdrive);
    if (Pstereo)
        waveShapeSmps(synth->p_buffersize, efxoutr, Ptype + 1, Pdrive);

    if (!Pprefiltering)
        applyfilters(efxoutl, efxoutr);
    if (!Pstereo)
        memcpy(efxoutr, efxoutl, synth->p_bufferbytes);

    float level = dB2rap(60.0f * Plevel / 127.0f - 40.0f);
    for (int i = 0; i < synth->p_buffersize; ++i)
    {
        float lout = efxoutl[i];
        float rout = efxoutr[i];
        float l = lout * (1.0f - lrcross) + rout * lrcross;
        float r = rout * (1.0f - lrcross) + lout * lrcross;
        lout = l;
        rout = r;
        efxoutl[i] = lout * 2.0f * level;
        efxoutr[i] = rout * 2.0f * level;
    }
}
예제 #18
0
//Effect output
void Distorsion::out(const Stereo<float *> &smp)
{
    float inputvol = powf(5.0f, (Pdrive - 32.0f) / 127.0f);
    if(Pnegate)
        inputvol *= -1.0f;

    if(Pstereo) //Stereo
        for(int i = 0; i < buffersize; ++i) {
            efxoutl[i] = smp.l[i] * inputvol * pangainL;
            efxoutr[i] = smp.r[i] * inputvol * pangainR;
        }
    else //Mono
        for(int i = 0; i < buffersize; ++i)
            efxoutl[i] = (smp.l[i] * pangainL + smp.r[i] * pangainR) * inputvol;

    if(Pprefiltering)
        applyfilters(efxoutl, efxoutr);

    waveShapeSmps(buffersize, efxoutl, Ptype + 1, Pdrive);
    if(Pstereo)
        waveShapeSmps(buffersize, efxoutr, Ptype + 1, Pdrive);

    if(!Pprefiltering)
        applyfilters(efxoutl, efxoutr);

    if(!Pstereo)
        memcpy(efxoutr, efxoutl, bufferbytes);

    float level = dB2rap(60.0f * Plevel / 127.0f - 40.0f);
    for(int i = 0; i < buffersize; ++i) {
        float lout = efxoutl[i];
        float rout = efxoutr[i];
        float l    = lout * (1.0f - lrcross) + rout * lrcross;
        float r    = rout * (1.0f - lrcross) + lout * lrcross;
        lout = l;
        rout = r;

        efxoutl[i] = lout * 2.0f * level;
        efxoutr[i] = rout * 2.0f * level;
    }
}
예제 #19
0
void
setgain (goomf_synth_t * s, AnalogFilter * filter, float dBgain)
{
  filter->gain = dB2rap (dBgain);
  computefiltercoefs (s, filter);
};
예제 #20
0
void FormantFilter::init(float sample_rate, FilterParams *pars)
{
  int i, j;

  m_numformants = pars->Pnumformants;

  for (i = 0 ; i < m_numformants ; i++)
  {
    m_formants[i].init(sample_rate, ZYN_FILTER_ANALOG_TYPE_BPF2, 1000.0, 10.0, pars->m_additional_stages, 0.0);
  }

  cleanup();

  for (j = 0 ; j < FF_MAX_VOWELS ; j++)
  {
    for (i = 0 ; i < m_numformants ; i++)
    {
      m_formantpar[j][i].frequency = pars->getformantfreq(pars->Pvowels[j].formants[i].freq);
      m_formantpar[j][i].amplitude = pars->getformantamp(pars->Pvowels[j].formants[i].amp);
      m_formantpar[j][i].q_factor = pars->getformantq(pars->Pvowels[j].formants[i].q);
    }
  }

  for (i = 0 ; i < FF_MAX_FORMANTS ; i++)
  {
    m_oldformantamp[i] = 1.0;
  }

  for (i = 0 ; i < m_numformants ; i++)
  {
    m_currentformants[i].frequency = 1000.0;
    m_currentformants[i].amplitude = 1.0;
    m_currentformants[i].q_factor = 2.0;
  }

  m_formantslowness = pow(1.0 - pars->Pformantslowness / 128.0, 3.0);

  m_sequencesize = pars->Psequencesize;
  if (m_sequencesize == 0)
  {
    m_sequencesize = 1;
  }

  for (i = 0 ; i < m_sequencesize ; i++)
  {
    m_sequence[i].nvowel = pars->Psequence[i].nvowel;
  }

  m_vowelclearness = pow(10.0, (pars->Pvowelclearness - 32.0) / 48.0);

  m_sequencestretch = pow(0.1, (pars->Psequencestretch - 32.0) / 48.0);
  if (pars->Psequencereversed)
  {
    m_sequencestretch *= -1.0;
  }

  m_outgain = dB2rap(pars->m_gain);

  m_oldinput = -1.0;

  m_Qfactor = 1.0;
  m_oldQfactor = m_Qfactor;

  m_firsttime = 1;
}
예제 #21
0
void
Compressor::Compressor_Change (int np, int value)
{

    switch (np) {

    case 1:
        tthreshold = value;
        thres_db = (float)tthreshold;    //implicit type cast int to float
        break;

    case 2:
        tratio = value;
        ratio = (float)tratio;
        break;

    case 3:
        toutput = value;
        break;

    case 4:
        tatt = value;
        att = cSAMPLE_RATE /(((float)value / 1000.0f) + cSAMPLE_RATE);
        attr = att;
        attl = att;
        break;

    case 5:
        trel = value;
        rel = cSAMPLE_RATE /(((float)value / 1000.0f) + cSAMPLE_RATE);
        rell = rel;
        relr = rel;
        break;

    case 6:
        a_out = value;
        break;

    case 7:
        tknee = value;  //knee expressed a percentage of range between thresh and zero dB
        kpct = (float)tknee/100.1f;
        break;

    case 8:
        stereo = value;
        break;
    case 9:
        peak = value;
        break;


    }

    kratio = logf(ratio)/LOG_2;  //  Log base 2 relationship matches slope
    knee = -kpct*thres_db;

    coeff_kratio = 1.0 / kratio;
    coeff_ratio = 1.0 / ratio;
    coeff_knee = 1.0 / knee;

    coeff_kk = knee * coeff_kratio;


    thres_mx = thres_db + knee;  //This is the value of the input when the output is at t+k
    makeup = -thres_db - knee/kratio + thres_mx/ratio;
    makeuplin = dB2rap(makeup);
    if (a_out)
        outlevel = dB2rap((float)toutput) * makeuplin;
    else
        outlevel = dB2rap((float)toutput);

}
예제 #22
0
void AnalogFilter::setgain(REALTYPE dBgain){
    gain=dB2rap(dBgain);
    computefiltercoefs();
};
예제 #23
0
void
Compressor::out (float *efxoutl, float *efxoutr)
{

    int i;


    for (i = 0; i < PERIOD; i++) {
        float rdelta = 0.0f;
        float ldelta = 0.0f;
//Right Channel

        if(peak) {
            if (rtimer > hold) {
                rpeak *= 0.9998f;   //The magic number corresponds to ~0.1s based on T/(RC + T),
                rtimer--;
            }
            if (ltimer > hold) {
                lpeak *= 0.9998f;	//leaky peak detector.
                ltimer --;  //keeps the timer from eventually exceeding max int & rolling over
            }
            ltimer++;
            rtimer++;
            if(rpeak<fabs(efxoutr[i])) {
                rpeak = fabs(efxoutr[i]);
                rtimer = 0;
            }
            if(lpeak<fabs(efxoutl[i])) {
                lpeak = fabs(efxoutl[i]);
                ltimer = 0;
            }

            if(lpeak>20.0f) lpeak = 20.0f;
            if(rpeak>20.0f) rpeak = 20.0f; //keeps limiter from getting locked up when signal levels go way out of bounds (like hundreds)

        } else {
            rpeak = efxoutr[i];
            lpeak = efxoutl[i];
        }

        if(stereo) {
            rdelta = fabsf (rpeak);
            if(rvolume < 0.9f) {
                attr = att;
                relr = rel;
            } else if (rvolume < 1.0f) {
                attr = att + ((1.0f - att)*(rvolume - 0.9f)*10.0f);	//dynamically change attack time for limiting mode
                relr = rel/(1.0f + (rvolume - 0.9f)*9.0f);  //release time gets longer when signal is above limiting
            } else {
                attr = 1.0f;
                relr = rel*0.1f;
            }

            if (rdelta > rvolume)
                rvolume = attr * rdelta + (1.0f - attr)*rvolume;
            else
                rvolume = relr * rdelta + (1.0f - relr)*rvolume;


            rvolume_db = rap2dB (rvolume);
            if (rvolume_db < thres_db) {
                rgain = outlevel;
            } else if (rvolume_db < thres_mx) {
                //Dynamic ratio that depends on volume.  As can be seen, ratio starts
                //at something negligibly larger than 1 once volume exceeds thres, and increases toward selected
                // ratio by the time it has reached thres_mx.  --Transmogrifox

                eratio = 1.0f + (kratio-1.0f)*(rvolume_db-thres_db)* coeff_knee;
                rgain =   outlevel*dB2rap(thres_db + (rvolume_db-thres_db)/eratio - rvolume_db);
            } else {
                rgain = outlevel*dB2rap(thres_db + coeff_kk + (rvolume_db-thres_mx)*coeff_ratio - rvolume_db);
                limit = 1;
            }

            if ( rgain < MIN_GAIN) rgain = MIN_GAIN;
            rgain_t = .4f * rgain + .6f * rgain_old;
        };

//Left Channel
        if(stereo)  {
            ldelta = fabsf (lpeak);
        } else  {
            ldelta = 0.5f*(fabsf (lpeak) + fabsf (rpeak));
        };  //It's not as efficient to check twice, but it's small expense worth code clarity

        if(lvolume < 0.9f) {
            attl = att;
            rell = rel;
        } else if (lvolume < 1.0f) {
            attl = att + ((1.0f - att)*(lvolume - 0.9f)*10.0f);	//dynamically change attack time for limiting mode
            rell = rel/(1.0f + (lvolume - 0.9f)*9.0f);  //release time gets longer when signal is above limiting
        } else {
            attl = 1.0f;
            rell = rel*0.1f;
        }

        if (ldelta > lvolume)
            lvolume = attl * ldelta + (1.0f - attl)*lvolume;
        else
            lvolume = rell*ldelta + (1.0f - rell)*lvolume;

        lvolume_db = rap2dB (lvolume);

        if (lvolume_db < thres_db) {
            lgain = outlevel;
        } else if (lvolume_db < thres_mx) { //knee region
            eratio = 1.0f + (kratio-1.0f)*(lvolume_db-thres_db)* coeff_knee;
            lgain =   outlevel*dB2rap(thres_db + (lvolume_db-thres_db)/eratio - lvolume_db);
        } else {
            lgain = outlevel*dB2rap(thres_db + coeff_kk + (lvolume_db-thres_mx)*coeff_ratio - lvolume_db);
            limit = 1;
        }


        if ( lgain < MIN_GAIN) lgain = MIN_GAIN;
        lgain_t = .4f * lgain + .6f * lgain_old;

        if (stereo) {
            efxoutl[i] *= lgain_t;
            efxoutr[i] *= rgain_t;
            rgain_old = rgain;
            lgain_old = lgain;
        } else {
            efxoutl[i] *= lgain_t;
            efxoutr[i] *= lgain_t;
            lgain_old = lgain;
        }

        if(peak) {
            if(efxoutl[i]>0.999f) {            //output hard limiting
                efxoutl[i] = 0.999f;
                clipping = 1;
            }
            if(efxoutl[i]<-0.999f) {
                efxoutl[i] = -0.999f;
                clipping = 1;
            }
            if(efxoutr[i]>0.999f) {
                efxoutr[i] = 0.999f;
                clipping = 1;
            }
            if(efxoutr[i]<-0.999f) {
                efxoutr[i] = -0.999f;
                clipping = 1;
            }
            //highly probably there is a more elegant way to do that, but what the hey...
        }
    }

}
예제 #24
0
void
setgain (ZEq10ban_t * s, AnalogFilter *filter, float dBgain)
{
  filter->gain = dB2rap (dBgain);
  computefiltercoefs (s,filter);
};
예제 #25
0
파일: MBDist.C 프로젝트: dtimms/rakarrack
/*
 * Effect output
 */
void
MBDist::out (float * smpsl, float * smpsr)
{
    int i;
    float l, r, lout, rout;

    float inputvol = powf (5.0f, ((float)Pdrive - 32.0f) / 127.0f);
    if (Pnegate != 0)
        inputvol *= -1.0f;


    if (Pstereo) {
        for (i = 0; i < PERIOD; i++) {
            efxoutl[i] = smpsl[i] * inputvol * 2.0f;
            efxoutr[i] = smpsr[i] * inputvol * 2.0f;
        };
    } else {
        for (i = 0; i < PERIOD; i++) {
            efxoutl[i] =
                (smpsl[i]  +  smpsr[i] ) * inputvol;
        };
    };


    memcpy(lowl,efxoutl,sizeof(float) * PERIOD);
    memcpy(midl,efxoutl,sizeof(float) * PERIOD);
    memcpy(highl,efxoutl,sizeof(float) * PERIOD);

    lpf1l->filterout(lowl);
    hpf1l->filterout(midl);
    lpf2l->filterout(midl);
    hpf2l->filterout(highl);

    if(volL> 0)  mbwshape1l->waveshapesmps (PERIOD, lowl, PtypeL, PdriveL, 1);
    if(volM> 0)  mbwshape2l->waveshapesmps (PERIOD, midl, PtypeM, PdriveM, 1);
    if(volH> 0)  mbwshape3l->waveshapesmps (PERIOD, highl, PtypeH, PdriveH, 1);


    if(Pstereo) {
        memcpy(lowr,efxoutr,sizeof(float) * PERIOD);
        memcpy(midr,efxoutr,sizeof(float) * PERIOD);
        memcpy(highr,efxoutr,sizeof(float) * PERIOD);

        lpf1r->filterout(lowr);
        hpf1r->filterout(midr);
        lpf2r->filterout(midr);
        hpf2r->filterout(highr);

        if(volL> 0)  mbwshape1r->waveshapesmps (PERIOD, lowr, PtypeL, PdriveL, 1);
        if(volM> 0)  mbwshape2r->waveshapesmps (PERIOD, midr, PtypeM, PdriveM, 1);
        if(volH> 0)  mbwshape3r->waveshapesmps (PERIOD, highr, PtypeH, PdriveH, 1);


    }

    for (i = 0; i < PERIOD; i++) {
        efxoutl[i]=lowl[i]*volL+midl[i]*volM+highl[i]*volH;
        if (Pstereo) efxoutr[i]=lowr[i]*volL+midr[i]*volM+highr[i]*volH;
    }

    if (!Pstereo) memcpy(efxoutr, efxoutl, sizeof(float)* PERIOD);


    float level = dB2rap (60.0f * (float)Plevel / 127.0f - 40.0f);

    for (i = 0; i < PERIOD; i++) {
        lout = efxoutl[i];
        rout = efxoutr[i];

        l = lout * (1.0f - lrcross) + rout * lrcross;
        r = rout * (1.0f - lrcross) + lout * lrcross;

        efxoutl[i] = l * 2.0f * level * panning;
        efxoutr[i] = r * 2.0f * level * (1.0f -panning);

    };

    DCr->filterout (efxoutr);
    DCl->filterout (efxoutl);



};
예제 #26
0
파일: Valve.C 프로젝트: NY-tram/rkrlv2
/*
 * Effect output
 */
void
Valve::out (float * smpsl, float * smpsr, uint32_t period)
{
    unsigned int i;

    float l, r, lout, rout, fx;


    if (Pstereo != 0) {
        //Stereo
        for (i = 0; i < period; i++) {
            efxoutl[i] = smpsl[i] * inputvol;
            efxoutr[i] = smpsr[i] * inputvol;
        };
    } else {
        for (i = 0; i < period; i++) {
            efxoutl[i] =
                (smpsl[i]  +  smpsr[i] ) * inputvol;
        };
    };

    harm->harm_out(efxoutl,efxoutr, period);


    if (Pprefiltering != 0)
        applyfilters (efxoutl, efxoutr, period);

    if(Ped) {
        for (i =0; i<period; i++) {
            efxoutl[i]=Wshape(efxoutl[i]);
            if (Pstereo != 0) efxoutr[i]=Wshape(efxoutr[i]);
        }
    }

    for (i =0; i<period; i++) { //soft limiting to 3.0 (max)
        fx = efxoutl[i];
        if (fx>1.0f) fx = 3.0f - 2.0f/sqrtf(fx);
        efxoutl[i] = fx;
        fx = efxoutr[i];
        if (fx>1.0f) fx = 3.0f - 2.0f/sqrtf(fx);
        efxoutr[i] = fx;
    }

    if (q == 0.0f) {
        for (i =0; i<period; i++) {
            if (efxoutl[i] == q) fx = fdist;
            else fx =efxoutl[i] / (1.0f - powf(2.0f,-dist * efxoutl[i] ));
            otml = atk * otml + fx - itml;
            itml = fx;
            efxoutl[i]= otml;
        }
    } else {
        for (i = 0; i < period; i++) {
            if (efxoutl[i] == q) fx = fdist + qcoef;
            else fx =(efxoutl[i] - q) / (1.0f - powf(2.0f,-dist * (efxoutl[i] - q))) + qcoef;
            otml = atk * otml + fx - itml;
            itml = fx;
            efxoutl[i]= otml;

        }
    }


    if (Pstereo != 0) {

        if (q == 0.0f) {
            for (i =0; i<period; i++) {
                if (efxoutr[i] == q) fx = fdist;
                else fx = efxoutr[i] / (1.0f - powf(2.0f,-dist * efxoutr[i] ));
                otmr = atk * otmr + fx - itmr;
                itmr = fx;
                efxoutr[i]= otmr;

            }
        } else {
            for (i = 0; i < period; i++) {
                if (efxoutr[i] == q) fx = fdist + qcoef;
                else fx = (efxoutr[i] - q) / (1.0f - powf(2.0f,-dist * (efxoutr[i] - q))) + qcoef;
                otmr = atk * otmr + fx - itmr;
                itmr = fx;
                efxoutr[i]= otmr;

            }
        }

    }



    if (Pprefiltering == 0)
        applyfilters (efxoutl, efxoutr, period);

    if (Pstereo == 0) memcpy (efxoutr , efxoutl, period * sizeof(float));


    float level = dB2rap (60.0f * (float)Plevel / 127.0f - 40.0f);

    for (i = 0; i < period; i++) {
        lout = efxoutl[i];
        rout = efxoutr[i];


        l = lout * (1.0f - lrcross) + rout * lrcross;
        r = rout * (1.0f - lrcross) + lout * lrcross;

        lout = l;
        rout = r;

        //efxoutl[i] = lout * 2.0f * level * panning;
        //efxoutr[i] = rout * 2.0f * level * (1.0f -panning);
        efxoutl[i] = lout * 2.0f * level * (1.0f -panning);
        efxoutr[i] = rout * 2.0f * level * panning;

    };



};
예제 #27
0
void SVFilter::setgain(float dBgain)
{
    gain = dB2rap(dBgain);
    computefiltercoefs();
}
예제 #28
0
파일: Master.C 프로젝트: kennethlyn/zynqt
/*
 * Parameter control
 */
void Master::setPvolume(char Pvolume_){
    Pvolume=Pvolume_;
    volume=dB2rap((Pvolume-96.0)/96.0*40.0);
};
예제 #29
0
void SVFilter::setgain(REALTYPE dBgain)
{
  m_gain = dB2rap(dBgain);
  computefiltercoefs();
}
예제 #30
0
/*
 * Effect output
 */
void
Distorsion::out (float * smpsl, float * smpsr)
{
  int i;
  float l, r, lout, rout;

  float inputvol = powf (5.0f, ((float)Pdrive - 32.0f) / 127.0f);
  if (Pnegate != 0)
    inputvol *= -1.0f;

  if (Pstereo != 0)
    {				//Stereo
      for (i = 0; i < PERIOD; i++)
	{
	  efxoutl[i] = smpsl[i] * inputvol * 2.0f;
	  efxoutr[i] = smpsr[i] * inputvol * 2.0f;
	};
    }
  else
    {
      for (i = 0; i < PERIOD; i++)
	{
	  efxoutl[i] =
	    (smpsl[i]  +  smpsr[i] ) * inputvol;
	};
    };

  if (Pprefiltering != 0)
    applyfilters (efxoutl, efxoutr);

  //no optimised, yet (no look table)


  dwshapel->waveshapesmps (PERIOD, efxoutl, Ptype, Pdrive, 1);
  if (Pstereo != 0)
  dwshaper->waveshapesmps (PERIOD, efxoutr, Ptype, Pdrive, 1);

  if (Pprefiltering == 0)
    applyfilters (efxoutl, efxoutr);

  if (Pstereo == 0) memcpy (efxoutr , efxoutl, PERIOD * sizeof(float));

  if (octmix > 0.01f)
  {
   for (i = 0; i < PERIOD; i++)
    {
      lout = efxoutl[i];
      rout = efxoutr[i];
      
	
	if ( (octave_memoryl < 0.0f) && (lout > 0.0f) ) togglel *= -1.0f;
	
	octave_memoryl = lout;    

	if ( (octave_memoryr < 0.0f) && (rout > 0.0f) ) toggler *= -1.0f;
	
	octave_memoryr = rout;    

        octoutl[i] = lout *  togglel;
        octoutr[i] = rout *  toggler;
      }
      
       blockDCr->filterout (octoutr);
       blockDCl->filterout (octoutl);
   }



  float level = dB2rap (60.0f * (float)Plevel / 127.0f - 40.0f);

  for (i = 0; i < PERIOD; i++)
    {
      lout = efxoutl[i];
      rout = efxoutr[i];
        
      
      l = lout * (1.0f - lrcross) + rout * lrcross;
      r = rout * (1.0f - lrcross) + lout * lrcross;

        if (octmix > 0.01f)
       {
        lout = l * (1.0f - octmix) + octoutl[i] * octmix;
        rout = r * (1.0f - octmix) + octoutr[i] * octmix;
       }
        else
       {
        lout = l;
        rout = r;  
       }
       
      efxoutl[i] = lout * 2.0f * level * panning;
      efxoutr[i] = rout * 2.0f * level * (1.0f -panning);  

    };
    
    DCr->filterout (efxoutr);
    DCl->filterout (efxoutl);
};