| 1 |
<CsoundSynthesizer> |
| 2 |
<CsOptions> |
| 3 |
; Select audio/midi flags here according to platform |
| 4 |
; Audio out Audio in No messages |
| 5 |
-odac -iadc -d ;;;RT audio I/O |
| 6 |
; For Non-realtime ouput leave only the line below: |
| 7 |
; -o biquad.wav -W ;;; for file output any platform |
| 8 |
</CsOptions> |
| 9 |
<CsInstruments> |
| 10 |
|
| 11 |
; Initialize the global variables. |
| 12 |
sr = 44100 |
| 13 |
kr = 4410 |
| 14 |
ksmps = 10 |
| 15 |
nchnls = 2 |
| 16 |
|
| 17 |
; Instrument #1. |
| 18 |
instr 1 |
| 19 |
; Get the values from the score. |
| 20 |
idur = p3 |
| 21 |
iamp = p4 |
| 22 |
icps = cpspch(p5) |
| 23 |
afco expon 100, p3, 2000 |
| 24 |
arez line 0.8, p3, 0.99 |
| 25 |
|
| 26 |
; Calculate the biquadratic filter's coefficients |
| 27 |
afcon = 2*3.14159265*afco/sr |
| 28 |
aalpha = 1-2*arez*cos(afcon)*cos(afcon)+arez*arez*cos(2*afcon) |
| 29 |
abeta = arez*arez*sin(2*afcon)-2*arez*cos(afcon)*sin(afcon) |
| 30 |
agama = 1+cos(afcon) |
| 31 |
am1 = aalpha*agama+abeta*sin(afcon) |
| 32 |
am2 = aalpha*agama-abeta*sin(afcon) |
| 33 |
aden = sqrt(am1*am1+am2*am2) |
| 34 |
ab0 = 1.5*(aalpha*aalpha+abeta*abeta)/aden |
| 35 |
ab1 = ab0 |
| 36 |
ab2 = 0 |
| 37 |
aa0 = 1 |
| 38 |
aa1 = -2*arez*cos(afcon) |
| 39 |
aa2 = arez*arez |
| 40 |
|
| 41 |
; Generate an input signal. |
| 42 |
axn vco 1, icps, 1 |
| 43 |
|
| 44 |
; Filter the input signal. |
| 45 |
ayn biquada axn, ab0, ab1, ab2, aa0, aa1, aa2 |
| 46 |
outs ayn*iamp/2, ayn*iamp/2 |
| 47 |
endin |
| 48 |
|
| 49 |
|
| 50 |
</CsInstruments> |
| 51 |
<CsScore> |
| 52 |
|
| 53 |
; Table #1, a sine wave. |
| 54 |
f 1 0 16384 10 1 |
| 55 |
|
| 56 |
; Sta Dur Amp Pitch |
| 57 |
i 1 0.0 5.0 20000 6.00 |
| 58 |
e |
| 59 |
|
| 60 |
|
| 61 |
</CsScore> |
| 62 |
</CsoundSynthesizer> |