17.01.2013 Views

musicdsp.org source code archive - WSInf

musicdsp.org source code archive - WSInf

musicdsp.org source code archive - WSInf

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

}<br />

double y;<br />

y = lp->b * (x + lp->x1) - lp->a * lp->y1;<br />

lp->x1 = x;<br />

lp->y1 = y;<br />

return y;<br />

/* dsf blit datatype<br />

*<br />

*/<br />

typedef struct<br />

{<br />

double phase; /* phase accumulator */<br />

double aNQ; /* attenuation at nyquist */<br />

double curcps; /* current frequency, updated once per cycle */<br />

double curper; /* current period, updated once per cycle */<br />

lowpass_t leaky; /* leaky integrator */<br />

double N; /* # partials */<br />

double a; /* dsf parameter which controls roll-off */<br />

double aN; /* former to the N */<br />

} blit_t;<br />

/* initializes a blit structure<br />

*<br />

* The aNQ parameter is the desired attenuation<br />

* at nyquist. A low value yields a duller<br />

* sawtooth but gets rid of those annoying CLICKS<br />

* when sweeping the frequency up real high. |aNQ|<br />

* must be strictly less than 1.0! Find a setting<br />

* which works for you.<br />

*<br />

* The cutoff parameter controls the leakiness of<br />

* the integrator.<br />

*/<br />

void init_blit(blit_t *b, double aNQ, double cutoff)<br />

{<br />

b->phase = 0.0;<br />

b->aNQ = aNQ;<br />

b->curcps = 0.0;<br />

b->curper = 0.0;<br />

init_lowpass(&b->leaky, cutoff);<br />

}<br />

/* Returns a sawtooth computed from a leaky integration<br />

* of a DSF bandlimited impulse train.<br />

*<br />

* cps (cycles per sample) is the fundamental<br />

* frequency: 0 -> 0.5 == 0 -> nyquist<br />

*/<br />

double update_blit(blit_t *b, double cps)<br />

{<br />

double P2, beta, Nbeta, cosbeta, n, d, blit, saw;<br />

if(b->phase >= 1.0 || b->curcps == 0.0)<br />

{<br />

/* New cycle, update frequency and everything<br />

* that depends on it<br />

*/<br />

if(b->phase >= 1.0)<br />

b->phase -= 1.0;<br />

}<br />

b->curcps = cps; /* this cycle\'s frequency */<br />

b->curper = 1.0 / cps; /* this cycle\'s period */<br />

P2 = b->curper / 2.0;<br />

b->N = 1.0 + floor(P2); /* # of partials incl. dc */<br />

/* find the roll-off parameter which gives<br />

* the desired attenuation at nyquist<br />

*/<br />

b->a = pow(b->aNQ, 1.0 / P2);<br />

b->aN = pow(b->a, b->N);<br />

beta = twopi * b->phase;

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!