Exemplo n.º 1
0
void mdaTracker::setParameter(int32_t index, float value)
{
	switch(index)
  {
    case 0: fParam1 = value; break;
    case 1: fParam2 = value; break;
    case 2: fParam3 = value; break;
    case 3: fParam4 = value; break;
    case 4: fParam5 = value; break;
    case 5: fParam6 = value; break;
    case 6: fParam7 = value; break;
    case 7: fParam8 = value; break;
  }
  //calcs here
  mode = int(fParam1*4.9);
  fo = filterFreq(50.f); fi = (1.f - fo)*(1.f - fo);
  ddphi = fParam4 * fParam4;
  thr = (float)pow(10.0, 3.0*fParam7 - 3.8);
  max = (int32_t)(getSampleRate() / pow(10.0f, 1.6f + 2.2f * fParam6));
  trans = (float)pow(1.0594631,int(72.f*fParam5 - 36.f));
  wet = (float)pow(10.0, 2.0*fParam8 - 1.0);
  if(mode<4)
  {
    dyn = wet * 0.6f * fParam3 * fParam2;
    dry = wet * (float)sqrt(1.f - fParam3);
    wet = wet * 0.3f * fParam3 * (1.f - fParam2);
  }
  else
  {
    dry = wet * (1.f - fParam3);
    wet *= (0.02f*fParam3 - 0.004f);
    dyn = 0.f;
  }
  rel = (float)pow(10.0,-10.0/getSampleRate());
}
void AudioProcessorValueTreeStateDemoAudioProcessor::processBlock (AudioSampleBuffer& buffer, MidiBuffer& midiMessages)
{
    // In case we have more outputs than inputs, this code clears any output
    // channels that didn't contain input data, (because these aren't
    // guaranteed to be empty - they may contain garbage).
    // I've added this to avoid people getting screaming feedback
    // when they first compile the plugin, but obviously you don't need to
    // this code if your algorithm already fills all the output channels.
    for (int i = getTotalNumInputChannels(); i < getTotalNumOutputChannels(); ++i)
        buffer.clear (i, 0, buffer.getNumSamples());

    // This is the place where you'd normally do the guts of your plugin's
    // audio processing...
    
    // get parameters...
//    fParam1 = (float)0.8; //clip
//    fParam2 = (float)0.50; //bits
//    fParam3 = (float)0.65; //rate
//    fParam4 = (float)0.9; //postfilt
//    fParam5 = (float)0.58; //non-lin
//    fParam6 = (float)0.5; //level
    const float clip = *parameters.getRawParameterValue(PARAM_ID_CLIP);
    const float bits = *parameters.getRawParameterValue(PARAM_ID_BITS);
    const float rate = *parameters.getRawParameterValue(PARAM_ID_SAMPLERATE);
    const float postfilt = *parameters.getRawParameterValue(PARAM_ID_POSTFILT);
    const float nonlin = *parameters.getRawParameterValue(PARAM_ID_NONLIN);
    const long nonLinearityMode = *parameters.getRawParameterValue(PARAM_ID_NONLIN_MODE);
    const float level = *parameters.getRawParameterValue(PARAM_ID_LEVEL);
    const long sampleRateMode = (long)*parameters.getRawParameterValue(PARAM_ID_POSTFILT_MODE);
    
    long tn = (long) ( getSampleRate() / rate );

    if (tn < 1)
        tn = 1;

    float mode;
    if (sampleRateMode == Parameters::kSampleRateMode_SampleAndHold)
        mode = 1.0f;
    else
        mode = 0.0f;
    
    //	tcount = 1;	// XXX when does this need to happen?
    float clp = powf(10.0f, clip/20.0f);
    float fo2 = filterFreq( postfilt );
    float fi2 = (1.0f-fo2); fi2 = fi2*fi2; fi2 = fi2*fi2;
    float gi = powf(2.0f, (long)bits - 2);	// XXX why is this 2 - 14 instead of 4 - 16?
    float go = 1.0f / gi;
    if (sampleRateMode == Parameters::kSampleRateMode_SampleAndHold)
        gi = -gi/(float)tn;
    else
        gi = -gi;
    float ga = powf(10.0f, level/20.0f);
    float lin, lin2;
    lin = powf(10.0f, nonlin * -0.003f);
    if (nonLinearityMode == Parameters::kNonLinearityMode_Even)
        lin2 = lin;
    else
        lin2 = 1.0f;
    
    float b0=buf0;
    float b1=buf1, b2=buf2, b3=buf3, b4=buf4, b5=buf5;
    float b6=buf6, b7=buf7, b8=buf8, b9=buf9;
    long t = tcount;
    
    const float* input = buffer.getReadPointer(0);
    float* output = buffer.getWritePointer(0);
    
    float* output2 = nullptr;
    if (buffer.getNumChannels()>1)
        output2 = buffer.getWritePointer(1);
    
    for (int samp=0; samp < buffer.getNumSamples(); samp++)
    {
        b0 = input[samp] + mode * b0;
        
        if (t >= tn)
        {
            t = 0;
            b5 = (float)(go * (long)(b0 * gi));
            if (b5 > 0.0f)
            {
                b5 = powf(b5, lin2);
                if (b5 > clp)
                    b5 = clp;
            }
            else
            {
                b5 = -powf(-b5, lin);
                if (b5 < -clp)
                    b5 = -clp;
            }
            b0 = 0.0f;
        }
        t++;
        
        b1 = fi2 * (b5 * ga) + fo2 * b1;
        b2 = b1 + fo2 * b2;
        b3 = b2 + fo2 * b3;
        b4 = b3 + fo2 * b4;
        b6 = fi2 * b4 + fo2 * b6;
        b7 = b6 + fo2 * b7;
        b8 = b7 + fo2 * b8;
        b9 = b8 + fo2 * b9;
        
        output[samp] = b9;
        if (output2!=nullptr) output2[samp] = b9;
    }
    if (fabsf(b1) < 1.0e-10f)
    {
        buf1 = 0.0f;
        buf2 = 0.0f;
        buf3 = 0.0f;
        buf4 = 0.0f;
        buf6 = 0.0f;
        buf7 = 0.0f;
        buf8 = 0.0f;
        buf9 = 0.0f;
        buf0 = 0.0f;
        buf5 = 0.0f;
    }
    else 
    {
        buf1 = b1;
        buf2 = b2;
        buf3 = b3;
        buf4 = b4;
        buf6 = b6;
        buf7 = b7;
        buf8 = b8;
        buf9 = b9;
        buf0 = b0;
        buf5 = b5;
        tcount = t;
    }
}
Exemplo n.º 3
0
//--------------------------------------------------------------------------------
void Tracker::TrackerKernel::Process(const Float32 * inSourceP, Float32 * inDestP, UInt32 inFramesToProcess, UInt32, bool & ioSilence)
{
	// parameter-change calcs here
	long mode = (long) GetParameter(kParam_Mode);
	float fo = filterFreq(50.f);
	float fi = (1.f - fo)*(1.f - fo);
	float trackingValue = GetParameter(kParam_Tracking) * 0.01f;
	float ddphi = trackingValue * trackingValue;
	float thr = powf(10.0f, (GetParameter(kParam_Trigger)/20.0f) - 0.8f);
	long max = (long)(GetSampleRate() / GetParameter(kParam_Maximum));
	float trans = powf(1.0594631f, GetParameter(kParam_Transpose));	// XXX Sophia changed to be continuous and not stepped
	float wet = powf(10.0f, GetParameter(kParam_Output)/20.0f);
	float dynamicsValue = GetParameter(kParam_Dynamics) * 0.01f;
	float mixValue = GetParameter(kParam_Mix) * 0.01f;
	float dry = 0.0f;
	float dyn = 0.0f;
	if(mode<kMode_EQ)
	{
		dyn = wet * 0.6f * mixValue * dynamicsValue;
		dry = wet * sqrtf(1.f - mixValue);
		wet = wet * 0.3f * mixValue * (1.f - dynamicsValue);
	}
	else
	{
		dry = wet * (1.f - mixValue);
		wet *= (0.02f*mixValue - 0.004f);
		dyn = 0.f;
	}
	float rel = (float)pow(10.0,-10.0/GetSampleRate());
	bool channelLink = (GetParameter(kParam_ChannelLink) == 0.0f) ? false : true;


	float x, t=thr, p=phi, dp=dphi, ddp=ddphi, tmp, tmp2;
	float o=fo, i=fi, b1=buf1, b2=buf2, twopi=6.2831853f;
	float we=wet, dr=dry, bo=bold, r1=res1, r2=res2, b3=buf3, b4=buf4;
	float sw=saw, dsw=dsaw, dy=dyn, e=env, re=rel;
	long	m=max, n=num, s=sig, mn=min, mo=mode;

	for (UInt32 samp=0; samp < inFramesToProcess; samp++)
	{
		if (channelLink)
			x = ((Tracker*)mAudioUnit)->GetSummedInput(samp);
		else
			x = inSourceP[samp];

		tmp = (x>0.f)? x : -x; //dynamics envelope
		e = (tmp>e)? 0.5f*(tmp + e) : e * re;

		b1 = o*b1 + i*x; 
		b2 = o*b2 + b1; //low-pass filter
		
		if(b2>t) //if >thresh
		{	
			if(s<1) //and was <thresh
			{
				if(n<mn) //not long ago
				{
					tmp2 = b2 / (b2 - bo); //update period
					tmp = trans*twopi/(n + dn - tmp2); 
					dp = dp + ddp * (tmp - dp); 
					dn = tmp2;
					dsw = 0.3183098f * dp;
					if(mode==kMode_EQ) 
					{
						r1 = cosf(4.f*dp); //resonator
						r2 = sinf(4.f*dp);
					}	
				}
				n=0; //restart period measurement
			}
			s=1;
		}
		else 
		{
			if(n>m) s=0; //now <thresh 
		}
		n++;
		bo=b2;

		p = fmodf(p+dp,twopi);
		switch(mo)
		{
			case kMode_Sine: x=sinf(p); break; 
			case kMode_Square: x=(sin(p)>0.f)? 0.5f : -0.5f; break; 
			case kMode_Saw: sw = fmodf(sw+dsw,2.0f); x = sw - 1.f; break; 
			case kMode_Ring: x *= sinf(p); break; 
			case kMode_EQ: x += (b3 * r1) - (b4 * r2); 
							b4 = 0.996f * ((b3 * r2) + (b4 * r1)); 
							b3 = 0.996f * x; break; 
		}		
		x *= (we + dy * e); 
		inDestP[samp] = dr*inSourceP[samp] + x;
	}
	if(fabsf(b1)<1.0e-10f) {buf1=0.f; buf2=0.f; buf3=0.f; buf4=0.f; } 
	else {buf1=b1; buf2=b2; buf3=b3; buf4=b4;}
	phi=p; dphi=dp; sig=s; bold=bo;
	num=(n>100000)? 100000: n; 
	env=e; saw=sw; dsaw=dsw; res1=r1; res2=r2;
}
Exemplo n.º 4
0
Arquivo: mdaCombo.cpp Projeto: EQ4/lad
void mdaCombo::setParameter(int32_t index, float value)
{
	switch(index)
  {
    case 0: fParam1 = value; break;
    case 1: fParam2 = value; break;
    case 2: fParam3 = value; break;
    case 3: fParam4 = value; break;
    case 4: fParam5 = value; break;
    case 5: fParam6 = value; break;
    case 6: fParam7 = value; break;
  }
  //calcs here
  ster=0; if(fParam5>0.0) ster=1;
  hpf = filterFreq(25.f);
	switch(int(fParam1*6.9))
  {
    case 0: trim = 0.5f; lpf = 0.f;                 //DI
            mix1 = (float)0.0; mix2 = (float)0.0;
            del1 = 0; del2 = 0;
            break;

    case 1: trim = 0.53f; lpf = filterFreq(2700.f); //speaker sim
            mix1 = (float)0.0; mix2 = (float)0.0;
            del1 = 0; del2 = 0;
            hpf = filterFreq(382.f);
            break;

    case 2: trim = 1.10f; lpf = filterFreq(1685.f); //radio
            mix1 = -1.70f; mix2 = 0.82f;
            del1 = int(getSampleRate() / 6546.f);
            del2 = int(getSampleRate() / 4315.f);
            break;

    case 3: trim = 0.98f; lpf = filterFreq(1385.f); //mesa boogie 1"
            mix1 = -0.53f; mix2 = 0.21f;
            del1 = int(getSampleRate() / 7345.f);
            del2 = int(getSampleRate() / 1193.f);
            break;

    case 4: trim = 0.96f; lpf = filterFreq(1685.f); //mesa boogie 8"
            mix1 = -0.85f; mix2 = 0.41f;
            del1 = int(getSampleRate() / 6546.f);
            del2 = int(getSampleRate() / 3315.f);
            break;

    case 5: trim = 0.59f; lpf = filterFreq(2795.f);
            mix1 = -0.29f; mix2 = 0.38f;          //Marshall 4x12" celestion
            del1 = int(getSampleRate() / 982.f);
            del2 = int(getSampleRate() / 2402.f);
            hpf = filterFreq(459.f);
            break;

    case 6: trim = 0.30f; lpf = filterFreq(1744.f); //scooped-out metal
            mix1 = -0.96f; mix2 = 1.6f;
            del1 = int(getSampleRate() / 356.f);
            del2 = int(getSampleRate() / 1263.f);
            hpf = filterFreq(382.f);
            break;
  }

  mode = (fParam2<0.5)? 1 : 0;
  if(mode) //soft clipping
  {
    drive = (float)pow(10.f, 2.f - 6.f * fParam2);
    trim *= 0.55f + 150.f * (float)pow(fParam2,4.0f);
  }
  else //hard clipping
  {
    drive = 1.f;
    clip = 11.7f - 16.f*fParam2;
    if(fParam2>0.7)
    {
      drive = (float)pow(10.0f, 7.f*fParam2 - 4.9f);
      clip = 0.5f;
    }
  }
  bias = 1.2f * fParam3 - 0.6f;
  if(fParam2>0.5) bias /= (1.f + 3.f * (fParam2-0.5f));
             else bias /= (1.f + 3.f * (0.5f-fParam2));
  trim *= (float)pow(10.f, 2.f*fParam4 - 1.f);
  if(ster) trim *=2.f;

  hhf = fParam6;
  hhq = 1.1f - fParam7;
  if(fParam6>0.05f) drive = drive * (1 + 0.1f * drive);
}