Debian Codegraph @

examples/biquad.csd

raw
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 kfco = p6
24 krez = p7
25
26 ; Calculate the biquadratic filter's coefficients
27 kfcon = 2*3.14159265*kfco/sr
28 kalpha = 1-2*krez*cos(kfcon)*cos(kfcon)+krez*krez*cos(2*kfcon)
29 kbeta = krez*krez*sin(2*kfcon)-2*krez*cos(kfcon)*sin(kfcon)
30 kgama = 1+cos(kfcon)
31 km1 = kalpha*kgama+kbeta*sin(kfcon)
32 km2 = kalpha*kgama-kbeta*sin(kfcon)
33 kden = sqrt(km1*km1+km2*km2)
34 kb0 = 1.5*(kalpha*kalpha+kbeta*kbeta)/kden
35 kb1 = kb0
36 kb2 = 0
37 ka0 = 1
38 ka1 = -2*krez*cos(kfcon)
39 ka2 = krez*krez
40
41 ; Generate an input signal.
42 axn vco 1, icps, 1
43
44 ; Filter the input signal.
45 ayn biquad axn, kb0, kb1, kb2, ka0, ka1, ka2
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 Fco Rez
57 i 1 0.0 1.0 20000 6.00 1000 .8
58 i 1 1.0 1.0 20000 6.03 2000 .95
59 e
60
61
62 </CsScore>
63 </CsoundSynthesizer>