aboutsummaryrefslogtreecommitdiff
path: root/wahwah~.c
diff options
context:
space:
mode:
Diffstat (limited to 'wahwah~.c')
-rw-r--r--wahwah~.c246
1 files changed, 124 insertions, 122 deletions
diff --git a/wahwah~.c b/wahwah~.c
index 9819f09..322b078 100644
--- a/wahwah~.c
+++ b/wahwah~.c
@@ -79,41 +79,41 @@ static t_class *wahwah_class;
static void wahwah_set_coeffs (t_wahwah *x)
{
- t_int i;
- double omega;
- double sn,cs;
- double alpha = 0.0;
- /* filter coefficients */
- double a0,a1,a2,b0,b1,b2;
- double A;
+ t_int i;
+ double omega;
+ double sn,cs;
+ double alpha = 0.0;
+ /* filter coefficients */
+ double a0,a1,a2,b0,b1,b2;
+ double A;
A = exp(x->x_dbgain/40.0)*log(10.0);
for (i = 0; i < COEFFSIZE; i++)
{
- omega = 2.0*M_PI*(double)i/(double)x->x_samplerate;
- sn = sin(omega);
- cs = cos(omega);
- if (x->x_bandwidth)
- alpha = sn*sin(log(2.0)/2.0*x->x_bandwidth*omega/sn);
- else
- /* if Q is specified instead of bandwidth */
- if (x->x_Q)
- alpha = sn/(2.0*x->x_Q);
-
- /* then compute the coefs for whichever filter type you want */
- b0 = 1.0 + alpha*A;
- b1 = -2.0*cs ;
- b2 = 1.0 - alpha*A;
- a0 = 1.0 + alpha/A;
- a1 = -2.0*cs ;
- a2 = 1.0 - alpha/A;
-
- *(x->x_coeffs+i*NBCOEFFS) = (b0/a0);
- *(x->x_coeffs+i*NBCOEFFS+1) = (b1/a0);
- *(x->x_coeffs+i*NBCOEFFS+2) = (b2/a0);
- *(x->x_coeffs+i*NBCOEFFS+3) = (a1/a0);
- *(x->x_coeffs+i*NBCOEFFS+4) = (a2/a0);
- // post( "wahwah~ : coeff : %f", *(x->x_coeffs+i*NBCOEFFS+4) );
+ omega = 2.0*M_PI*(double)i/(double)x->x_samplerate;
+ sn = sin(omega);
+ cs = cos(omega);
+ if (x->x_bandwidth)
+ alpha = sn*sin(log(2.0)/2.0*x->x_bandwidth*omega/sn);
+ else
+ /* if Q is specified instead of bandwidth */
+ if (x->x_Q)
+ alpha = sn/(2.0*x->x_Q);
+
+ /* then compute the coefs for whichever filter type you want */
+ b0 = 1.0 + alpha*A;
+ b1 = -2.0*cs ;
+ b2 = 1.0 - alpha*A;
+ a0 = 1.0 + alpha/A;
+ a1 = -2.0*cs ;
+ a2 = 1.0 - alpha/A;
+
+ *(x->x_coeffs+i*NBCOEFFS) = (b0/a0);
+ *(x->x_coeffs+i*NBCOEFFS+1) = (b1/a0);
+ *(x->x_coeffs+i*NBCOEFFS+2) = (b2/a0);
+ *(x->x_coeffs+i*NBCOEFFS+3) = (a1/a0);
+ *(x->x_coeffs+i*NBCOEFFS+4) = (a2/a0);
+ // post( "wahwah~ : coeff : %f", *(x->x_coeffs+i*NBCOEFFS+4) );
}
x->min_coef = x->x_minfc;
x->max_coef = x->x_maxfc;
@@ -127,11 +127,11 @@ static void wahwah_bandwidth(t_wahwah *x, t_floatarg fbandwidth )
{
if ( fbandwidth > 10.0 )
{
- fbandwidth = 10.0;
+ fbandwidth = 10.0;
}
if ( fbandwidth < 0.0 )
{
- fbandwidth = 0.0;
+ fbandwidth = 0.0;
}
x->x_bandwidth = fbandwidth;
// post( "wahwah~ : bandwidth: %f", x->x_bandwidth );
@@ -142,11 +142,11 @@ static void wahwah_dbgain(t_wahwah *x, t_floatarg fdbgain )
{
if ( fdbgain > 15.0 )
{
- fdbgain = 15.0;
+ fdbgain = 15.0;
}
if ( fdbgain < -15.0 )
{
- fdbgain = -15.0;
+ fdbgain = -15.0;
}
x->x_dbgain = fdbgain;
// post( "wahwah~ : dbgain: %f", x->x_dbgain );
@@ -157,11 +157,11 @@ static void wahwah_maxstep(t_wahwah *x, t_floatarg fmaxstep )
{
if ( fmaxstep > 100.0 )
{
- fmaxstep = 100.0;
+ fmaxstep = 100.0;
}
if ( fmaxstep < 0.0 )
{
- fmaxstep = 0.0;
+ fmaxstep = 0.0;
}
x->x_maxstep = fmaxstep;
// post( "wahwah~ : maxstep: %f", x->x_maxstep );
@@ -172,11 +172,11 @@ static void wahwah_sensibility(t_wahwah *x, t_floatarg fsensibility )
{
if ( fsensibility > 1000.0 )
{
- fsensibility = 1000.0;
+ fsensibility = 1000.0;
}
if ( fsensibility < 0.0 )
{
- fsensibility = 0.0;
+ fsensibility = 0.0;
}
x->x_sense = fsensibility;
// post( "wahwah~ : sensibility: %f", x->x_sense );
@@ -187,11 +187,11 @@ static void wahwah_maxfreq(t_wahwah *x, t_floatarg fmaxfreq )
{
if ( fmaxfreq > 3000.0 )
{
- fmaxfreq = 3000.0;
+ fmaxfreq = 3000.0;
}
if ( fmaxfreq < 0.0 )
{
- fmaxfreq = 0.0;
+ fmaxfreq = 0.0;
}
x->x_maxfc = fmaxfreq;
// post( "wahwah~ : maxfreq: %f", x->x_maxfc );
@@ -202,11 +202,11 @@ static void wahwah_minfreq(t_wahwah *x, t_floatarg fminfreq )
{
if ( fminfreq > 3000.0 )
{
- fminfreq = 3000.0;
+ fminfreq = 3000.0;
}
if ( fminfreq < 0.0 )
{
- fminfreq = 0.0;
+ fminfreq = 0.0;
}
x->x_minfc = fminfreq;
// post( "wahwah~ : minfreq: %f", x->x_minfc );
@@ -217,22 +217,22 @@ static void wahwah_step(t_wahwah *x, t_floatarg fstep )
{
if ( fstep > x->x_maxstep )
{
- fstep = x->x_maxstep;
+ fstep = x->x_maxstep;
}
if ( fstep < 0 )
{
- fstep = 0;
+ fstep = 0;
}
x->step = fstep*x->x_sense/x->x_samplerate;
}
static t_int *wahwah_perform(t_int *w)
{
- t_float *in = (t_float *)(w[1]);
- t_float *out = (t_float *)(w[2]);
- t_int n = (int)(w[3]);
- t_wahwah *x = (t_wahwah*)(w[4]);
- t_int i;
+ t_float *in = (t_float *)(w[1]);
+ t_float *out = (t_float *)(w[2]);
+ t_int n = (int)(w[3]);
+ t_wahwah *x = (t_wahwah*)(w[4]);
+ t_int i;
for (i=0; i<n; i++)
{
@@ -240,10 +240,10 @@ static t_int *wahwah_perform(t_int *w)
x->x0 = (int)((*(in+i))*32768);
x->y0 = (*(x->x_coeffs+(int)x->cur_coef*NBCOEFFS))*x->x0
- + (*(x->x_coeffs+(int)x->cur_coef*NBCOEFFS+1))*x->x1
- + (*(x->x_coeffs+(int)x->cur_coef*NBCOEFFS+2))*x->x2
- - (*(x->x_coeffs+(int)x->cur_coef*NBCOEFFS+3))*x->y1
- - (*(x->x_coeffs+(int)x->cur_coef*NBCOEFFS+4))*x->y2;
+ + (*(x->x_coeffs+(int)x->cur_coef*NBCOEFFS+1))*x->x1
+ + (*(x->x_coeffs+(int)x->cur_coef*NBCOEFFS+2))*x->x2
+ - (*(x->x_coeffs+(int)x->cur_coef*NBCOEFFS+3))*x->y1
+ - (*(x->x_coeffs+(int)x->cur_coef*NBCOEFFS+4))*x->y2;
x->y2 = x->y1;
x->y1 = x->y0;
@@ -279,60 +279,60 @@ static void wahwah_preset(t_wahwah *x, t_float pnumber)
{
switch ( (int)pnumber )
{
- /* fast change medium wah wah */
- case 1:
- x->x_minfc = 100.0;
- x->x_maxfc = 1600.0;
- x->x_sense = 100.0;
- x->x_maxstep = 60.0;
- x->x_dbgain = 15.0;
- x->x_Q = 1.0;
- break;
-
- /* slow change medium wah wah */
- case 2:
- x->x_minfc = 100.0;
- x->x_maxfc = 1600.0;
- x->x_sense = 50.0;
- x->x_maxstep = 36.0;
- x->x_dbgain = 15.0;
- x->x_Q = 1.0;
- break;
-
- /* fast wah wah */
- case 3:
- x->x_minfc = 100.0;
- x->x_maxfc = 600.0;
- x->x_sense = 100.0;
- x->x_maxstep = 66.0;
- x->x_dbgain = 15.0;
- x->x_Q = 1.0;
- break;
-
- /* ranged wah wah */
- case 4:
- x->x_minfc = 10.0;
- x->x_maxfc = 2900.0;
- x->x_sense = 100.0;
- x->x_maxstep = 66.0;
- x->x_dbgain = 15.0;
- x->x_Q = 1.0;
- break;
-
- /* wah wah 400 - 2000 */
- case 5:
- x->x_minfc = 400.0;
- x->x_maxfc = 2000.0;
- x->x_sense = 100.0;
- x->x_maxstep = 66.0;
- x->x_dbgain = 15.0;
- x->x_Q = 1.0;
- break;
-
- default:
- post( "wahwah~ : unknown preset requested : %d", pnumber );
- return;
- break;
+ /* fast change medium wah wah */
+ case 1:
+ x->x_minfc = 100.0;
+ x->x_maxfc = 1600.0;
+ x->x_sense = 100.0;
+ x->x_maxstep = 60.0;
+ x->x_dbgain = 15.0;
+ x->x_Q = 1.0;
+ break;
+
+ /* slow change medium wah wah */
+ case 2:
+ x->x_minfc = 100.0;
+ x->x_maxfc = 1600.0;
+ x->x_sense = 50.0;
+ x->x_maxstep = 36.0;
+ x->x_dbgain = 15.0;
+ x->x_Q = 1.0;
+ break;
+
+ /* fast wah wah */
+ case 3:
+ x->x_minfc = 100.0;
+ x->x_maxfc = 600.0;
+ x->x_sense = 100.0;
+ x->x_maxstep = 66.0;
+ x->x_dbgain = 15.0;
+ x->x_Q = 1.0;
+ break;
+
+ /* ranged wah wah */
+ case 4:
+ x->x_minfc = 10.0;
+ x->x_maxfc = 2900.0;
+ x->x_sense = 100.0;
+ x->x_maxstep = 66.0;
+ x->x_dbgain = 15.0;
+ x->x_Q = 1.0;
+ break;
+
+ /* wah wah 400 - 2000 */
+ case 5:
+ x->x_minfc = 400.0;
+ x->x_maxfc = 2000.0;
+ x->x_sense = 100.0;
+ x->x_maxstep = 66.0;
+ x->x_dbgain = 15.0;
+ x->x_Q = 1.0;
+ break;
+
+ default:
+ post( "wahwah~ : unknown preset requested : %d", pnumber );
+ return;
+ break;
}
wahwah_set_coeffs( x );
}
@@ -342,18 +342,20 @@ static void wahwah_dsp(t_wahwah *x, t_signal **sp)
dsp_add(wahwah_perform, 4, sp[0]->s_vec, sp[1]->s_vec, sp[0]->s_n, x );
}
- /* clean up */
+/* clean up */
static void wahwah_free(t_wahwah *x)
{
- if ( x->x_buf != NULL ) {
- freebytes(x->x_buf, BFSZ*sizeof( double ) );
- post( "Freed %d bytes", BFSZ*sizeof( double ) );
- x->x_buf = NULL;
+ if ( x->x_buf != NULL )
+ {
+ freebytes(x->x_buf, BFSZ*sizeof( double ) );
+ post( "Freed %d bytes", BFSZ*sizeof( double ) );
+ x->x_buf = NULL;
}
- if ( x->x_coeffs != NULL ) {
- freebytes(x->x_coeffs, COEFFSIZE*NBCOEFFS*sizeof( t_float ) );
- post( "Freed %d bytes", COEFFSIZE*NBCOEFFS*sizeof( t_float ));
- x->x_coeffs = NULL;
+ if ( x->x_coeffs != NULL )
+ {
+ freebytes(x->x_coeffs, COEFFSIZE*NBCOEFFS*sizeof( t_float ) );
+ post( "Freed %d bytes", COEFFSIZE*NBCOEFFS*sizeof( t_float ));
+ x->x_coeffs = NULL;
}
}
@@ -373,13 +375,13 @@ static void *wahwah_new(void)
if ( !( x->x_buf = ( double* ) getbytes( BFSZ*sizeof( double ) ) ) )
{
- post ("wahwah~ : could not allocate buffer" );
- return NULL;
+ post ("wahwah~ : could not allocate buffer" );
+ return NULL;
}
if ( !( x->x_coeffs = ( t_float* ) getbytes( COEFFSIZE*NBCOEFFS*sizeof( t_float ) ) ) )
{
- post ("wahwah~ : could not allocate coeffs" );
- return NULL;
+ post ("wahwah~ : could not allocate coeffs" );
+ return NULL;
}
// set default parameters
@@ -393,7 +395,7 @@ void wahwah_tilde_setup(void)
{
verbose(0, wahwah_version );
wahwah_class = class_new(gensym("wahwah~"), (t_newmethod)wahwah_new, (t_method)wahwah_free,
- sizeof(t_wahwah), 0, 0);
+ sizeof(t_wahwah), 0, 0);
CLASS_MAINSIGNALIN( wahwah_class, t_wahwah, x_f );
class_addmethod(wahwah_class, (t_method)wahwah_step, gensym("step"), A_FLOAT, 0);