Skip to content

Commit

Permalink
Merge pull request supercollider#40 from sonoro1234/libmodify
Browse files Browse the repository at this point in the history
Libmodify
  • Loading branch information
telephon committed Oct 16, 2015
2 parents 9367339 + 3cd0ed4 commit e059ac0
Show file tree
Hide file tree
Showing 4 changed files with 472 additions and 9 deletions.
72 changes: 67 additions & 5 deletions source/DWGUGens/DWGBowed.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,29 +50,37 @@ DWGBowedSimple::DWGBowedSimple(Unit* unit){
}
void DWGBowedSimple::Release(float trig,float *out,int NumSamples){

if(this->m_trig <=0 && trig > 0){
if(this->m_trig <=0.0f && trig > 0.0f){
this->m_trig = trig;
}
if((this->m_trig >0 && trig <= 0)){
if((this->m_trig >0.0f && trig <= 0.0f)){
int relcount = this->relcount;
float rellevel = this->rellevel;
float rellevelstep = this->rellevelstep;

for(int i=0; i<NumSamples; i++){
if(relcount > 0){
//if(relcount > 0){
rellevel -= rellevelstep;
rellevel = std::max(0.0f, rellevel);
relcount--;
}
//}
out[i] *=rellevel;
}
if(relcount <=0)
if(relcount <=0 && rellevel == 0.0f)
DoneAction(2,this);

this->relcount = relcount;
this->rellevel = rellevel;
}
}
////////////////////////////////////////////////////
struct DWGBowedStk : public DWGBowedSimple
{
DWGBowedStk(Unit* unit);
};
SCWrapClass(DWGBowedStk);
DWGBowedStk::DWGBowedStk(Unit* unit):DWGBowedSimple(unit){ SETCALC(DWGBowedStk_next);}
////////////////////////////////////////////////////
struct DWGBowed : public DWGBowedSimple
{

Expand Down Expand Up @@ -169,6 +177,16 @@ float Bow(float vb,float fb,float vsr_plus_vsl){
float ref = BowTable(vdeltap,fb);
return ref * vdeltap;
}

float BowStk(float vb,float fb,float vsr_plus_vsl){
float vdeltap = vb - (vsr_plus_vsl);
float slope = ( 5.0 - (4.0 * fb) );
float sample = vdeltap + 0.001; //offset
sample *= slope;
sample = fabs( sample ) + 0.75;
sample = pow( sample, -4.0 );
return sample;
}
/////////////////////////////////////////
float hyperbolicbow(float deltav,float fb){
float mus = 0.8;
Expand Down Expand Up @@ -477,12 +495,56 @@ void DWGBowedSimple_next(DWGBowedSimple *unit, int inNumSamples)
unit->Release(trig,out,inNumSamples);
}

void DWGBowedStk_next(DWGBowedStk *unit, int inNumSamples)
{

float *out = OUT(0);
float freq = ZIN0(0);
float bowvelocity = ZIN0(1);
float bowforce = ZIN0(2);
float trig = ZIN0(3);
float pos = ZIN0(4);

float c1 = ZIN0(6);
float c3 = std::max(ZIN0(7),(float)1e-9);


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


float PMAS,PMAS2;
float PMENOS;
for (int i=0; i < inNumSamples; ++i)
{
float vel = unit->DWGF[0].get(pos*del1) + unit->DWGF[1].get(del1*(1-pos));
vel = BowStk(bowvelocity,bowforce,vel);
//vel = unit->Bow2(bowvelocity,bowforce,vel);
unit->DWGF[0].add(vel,pos*del1);
unit->DWGF[1].add(vel,del1*(1-pos));

PMAS = unit->DWGF[0].delay(del1);
PMAS2 = unit->Loss.pushConvol(PMAS);
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);
}

/////////////////////////////////////////
PluginLoad(DWGBowed)
{
ft = inTable;
DefineDtorUnit(DWGBowed);
DefineDtorUnit(DWGBowedTor);
DefineDtorUnit(DWGBowedSimple);
DefineDtorUnit(DWGBowedStk);
DefineDtorUnit(DWGSoundBoard);
}
6 changes: 3 additions & 3 deletions source/DWGUGens/DWGPlucked.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,10 @@ void DWGPluckedStiff_next(DWGPluckedStiff *unit, int inNumSamples)
float B = ZIN0(8)/100000;

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

float disperdelay = unit->disper.phasedelay(SAMPLERATE);
//Print("diff %f\n",disperdelay - unit->disper.groupdelay(SAMPLERATE));
unit->Loss.setcoeffs(freq,c1,c3);
float lossdelay = unit->Loss.groupdelay(freq,SAMPLERATE);
float lossdelay = unit->Loss.phasedelay(freq,SAMPLERATE);
float deltot = SAMPLERATE/freq;
float del1 = (deltot - lossdelay - disperdelay)*0.5 - 1;

Expand Down
38 changes: 38 additions & 0 deletions source/DWGUGens/dwglib/DWG.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,18 @@ void volcar(const char *_Message, const char *_File, unsigned _Line)
{
Print("assertion %s ,%s:%d\n",_Message,_File,_Line);
}
void kill_denormals(float &val)
{
static const float anti_denormal = 1e-18;
val += anti_denormal;
val -= anti_denormal;
}
void kill_denormals(double &val)
{
static const double anti_denormal = 1e-18;
val += anti_denormal;
val -= anti_denormal;
}
float ValimakiDispersion(float B, float f, int M) {
float C1,C2,k1,k2,k3;
if(M==4) {
Expand Down Expand Up @@ -100,6 +112,32 @@ float groupdelay(float f,float *B,int sizeB,float *A,int sizeA,float FS){
float c[2] ; complex_divide(Num,AxB,c);
return c[0];
}
////
void evalpoly(float omega,float* B,int sizeB,float* A,int sizeA,float H[2]){
float HB[2];
float HA[2];
evalpolyB(omega,B,sizeB,HB);
evalpolyA(omega,A,sizeA,HA);
complex_divide(HB,HA,H);
}
float PhaseIIR(float omega,float* B,int sizeB,float* A,int sizeA){
float C[2];
evalpoly(omega,B,sizeB,A,sizeA,C);
return atan2(C[1],C[0]);
}
float PhaseDelayDerive(float omega,float* B,int sizeB,float* A,int sizeA,float delta){
float omega1 = omega - delta;
float omega2 = omega + delta;
float p1 = PhaseIIR(omega1,B,sizeB,A,sizeA);
float p2 = PhaseIIR(omega2,B,sizeB,A,sizeA);
return (-omega1*p2 + omega2*p1)/(2*delta*omega1*omega2);
}
float PhaseDelay(float f,float* B,int sizeB,float* A,int sizeA,float FS){
float grpdel = ::groupdelay(f,B,sizeB,A,sizeA,FS);
float omega = 2.0*M_PI*f/FS;
return grpdel - omega*PhaseDelayDerive(omega,B,sizeB,A,sizeA);
}
///
long Nchoose(long n, long k) {
long divisor = 1;
long multiplier = n;
Expand Down
Loading

0 comments on commit e059ac0

Please sign in to comment.