void distort(sample &buf, float amount) { if (amount>=0.99) amount = 0.99; float k=2*amount/(1-amount); for(unsigned int i=0; i<buf.get_length(); i++) { buf[i]=((1+k)*buf[i]/(1+k*fabs(buf[i])))*(1-amount); } }
void moving_hard_clip(sample &buf, const sample &level) { for(unsigned int i=0; i<buf.get_length(); i++) { float l=fabs(level[i]); if (feq(l,0,0.0001)) l=0.0001; if (buf[i]>l) buf[i]=l; if (buf[i]<-l) buf[i]=-l; buf[i]*=1/l; } }
void hard_clip(sample &buf, float level) { if (feq(level,0,0.0001)) level==0.0001; for(unsigned int i=0; i<buf.get_length(); i++) { if (buf[i]>level) buf[i]=level; if (buf[i]<-level) buf[i]=-level; buf[i]*=1/level; } }
void moving_distort(sample &buf, const sample &amount) { for(unsigned int i=0; i<buf.get_length(); i++) { float a =fabs(amount[i]); if (a>0.99) a = 0.99; float k=2*a/(1-a); buf[i]=((1+k)*buf[i]/(1+k*fabs(buf[i])))*(1-a); } }
void crush(sample &buf, float freq, float bits) { float step = pow((float)0.5,(float)bits); float phasor = 1; float last = 0; for(unsigned int i=0; i<buf.get_length(); i++) { phasor = phasor + freq; if (phasor >= 1.0) { phasor = phasor - 1.0; last = step * floor( buf[i]/step + 0.5 ); } buf[i] = last; } }