Skip to content

Commit

Permalink
Merge pull request supercollider#19 from sonoro1234/master
Browse files Browse the repository at this point in the history
DWGPlucked: add DWGPluckedStiff, make ThirianDispersion templated
  • Loading branch information
telephon committed Jun 10, 2014
2 parents 5283836 + aac8ddf commit fb98b85
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 9 deletions.
6 changes: 3 additions & 3 deletions source/DWGUGens/DWGBowed.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ struct DWGBowed : public DWGBowedSimple
{

DCBlocker dcblock;
ThirianDispersion disper;
ThirianDispersion<4> disper;
DWGBowed(Unit* unit);

int SolveHyperbolicm1(float vdeltap,float fb,float &sol);
Expand Down Expand Up @@ -317,7 +317,7 @@ void DWGBowed_next(DWGBowed *unit, int inNumSamples)
unit->Z = ZIN0(8);
float B = ZIN0(9)/100000;

unit->disper.setcoeffs(freq,B,4);
unit->disper.setcoeffs(freq,B);
float disperdelay = unit->disper.groupdelay(SAMPLERATE);
//Print("disperdellay %g\n",disperdelay);

Expand Down Expand Up @@ -377,7 +377,7 @@ void DWGBowedTor_next(DWGBowedTor *unit, int inNumSamples)
float factra = unit->Z/unit->Ztra;
float factor = unit->Z/unit->Ztor;

unit->disper.setcoeffs(freq,B,4);
unit->disper.setcoeffs(freq,B);
float disperdelay = unit->disper.groupdelay(SAMPLERATE);
//Print("disperdellay %g\n",disperdelay);

Expand Down
58 changes: 58 additions & 0 deletions source/DWGUGens/DWGPlucked.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,63 @@ void DWGPlucked_next(DWGPlucked *unit, int inNumSamples)
unit->Release(trig,out,inNumSamples);
}

/////////////////////////////////////////
//DWGPluckedStiff////////////////////////////////////////////////////

struct DWGPluckedStiff : public DWGPlucked
{
ThirianDispersion<4> disper;
DWGPluckedStiff(Unit* unit);
};
SCWrapClass(DWGPluckedStiff);

DWGPluckedStiff::DWGPluckedStiff(Unit* unit):DWGPlucked(unit)
{
SETCALC(DWGPluckedStiff_next);
}

void DWGPluckedStiff_next(DWGPluckedStiff *unit, int inNumSamples)
{
float *out = OUT(0);
float freq = ZIN0(0);
float amp = ZIN0(1);
float trig = ZIN0(2);
float pos = ZIN0(3);

float c1 = ZIN0(4);
float c3 = std::max(ZIN0(5),(float)1e-9);
float *in = IN(6);
float B = ZIN0(8)/100000;

unit->disper.setcoeffs(freq,B);
float disperdelay = unit->disper.groupdelay(SAMPLERATE);

unit->Loss.setcoeffs(freq,c1,c3);
float lossdelay = unit->Loss.groupdelay(freq,SAMPLERATE);
float deltot = SAMPLERATE/freq;
float del1 = (deltot - lossdelay - disperdelay)*0.5 - 1;

float PMAS,PMAS2;
float PMENOS;
for (int i=0; i < inNumSamples; ++i)
{
unit->DWGF[0].add(in[i],pos*del1);
unit->DWGF[1].add(in[i],del1*(1-pos));

PMAS = unit->DWGF[0].delay(del1);
PMAS2 = unit->Loss.filter(PMAS);
PMAS2 = unit->disper.filter(PMAS2);
PMENOS = unit->DWGF[1].delay(del1);

unit->DWGF[1].push(-PMAS2);
unit->DWGF[0].push(-PMENOS);

out[i] = PMAS + PMAS2;

}
unit->Release(trig,out,inNumSamples);
}

/////////////////////////////////////////
//DWGPlucked2////////////////////////////////////////////////////

Expand Down Expand Up @@ -187,5 +244,6 @@ PluginLoad(DWGPlucked)
{
ft = inTable;
DefineDtorUnit(DWGPlucked);
DefineDtorUnit(DWGPluckedStiff);
DefineDtorUnit(DWGPlucked2);
}
12 changes: 6 additions & 6 deletions source/DWGUGens/dwglib/DWG.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -763,19 +763,19 @@ struct FDN8{
float c[8];
int lengths[8];// = {37,87,181,271,359,593,688,721};//{37, 87, 181,271, 359, 492, 687, 721};//{37,87,181,271,359,592,687,721};
};

template<int M>
struct ThirianDispersion{
int M;

float freq;
float B;
ThirianT<2> dispersion[4];
void setcoeffs(float freq,float B,int M){
void setcoeffs(float freq,float B){
if(B==0){
this->B = 0.0;
return;
}
//if(approximatelyEqual(this->freq,freq) && approximatelyEqual(this->B,B) && this->M==M)
if(this->freq==freq && this->B==B && this->M==M)

if(this->freq==freq && this->B==B)
return;
float D = ValimakiDispersion(B,freq,M);
//if(D <=1)
Expand All @@ -784,7 +784,7 @@ struct ThirianDispersion{
dispersion[i].setcoeffs(D);
this->freq = freq;
this->B = B;
this->M = M;

}
float groupdelay(float FS){
if(B==0)
Expand Down
6 changes: 6 additions & 0 deletions source/DWGUGens/sc/classes/DWGPlucked.sc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ DWGPlucked : UGen
^this.multiNew('audio',freq, amp, gate,pos,c1,c3,inp,release);
}
}
DWGPluckedStiff : UGen
{
*ar { arg freq=440, amp=0.5, gate=1, pos=0.14, c1=1, c3=30, inp= 0, release=0.1, fB=2;
^this.multiNew('audio',freq, amp, gate,pos,c1,c3,inp,release, fB);
}
}
DWGPlucked2 : UGen
{
*ar { arg freq=440, amp=0.5, gate=1, pos=0.14, c1=1, c3=30, inp= 0, release=0.1, mistune=1.008, mp = 0.55, gc = 0.01;
Expand Down

0 comments on commit fb98b85

Please sign in to comment.