Debian Codegraph @

examples/bpf.csd

raw
1 <CsoundSynthesizer>
2 <CsOptions>
3 -odac
4 </CsOptions>
5 <CsInstruments>
6
7 ; Example for opcode bpf
8
9 /*
10
11 bpf stands for Break Point Function
12
13 Given an x value and a series of pairs (x, y), it returns
14 the corresponding y value in the linear curve defined by the
15 pairs
16
17 It works both at i- and k- time
18
19 ky bpf kx, kx0, ky0, kx1, ky1, kx2, ky2, ...
20 kys[] bpf kxs[], kx0, ky0, kx1, ky1, kx2, ky2, ...
21
22 NB: x values must be ordered (kx0 < kx1 < kx2 etc)
23
24 See also: bpfcos, linlin, lincos
25
26 */
27
28 sr = 44100
29 ksmps = 64
30 nchnls = 2
31 0dbfs = 1
32
33 instr 1
34 kx line -1, p3, 2.5
35 ky bpf kx, \
36 0, 0, \
37 1.01, 10, \
38 2, 0.5, \
39 2.5, -1
40 if metro(10) == 1 then
41 printsk "kx: %f ky: %f \n", kx, ky
42 endif
43 endin
44
45 instr 2
46 ; test i-time
47 ix = 1.2
48 iy bpf ix, 0,0, 0.5,5, 1,10, 1.5,15, 2,20, 2.5,25, 3,30
49 prints "iy: %f", iy
50 turnoff
51 endin
52
53 instr 3
54 ; bpf also works with arrays
55 kx[] fillarray 0, 0.15, 0.25, 0.35, 0.45, 0.55, 0.6
56 ky[] bpf kx, 0,0, 0.1,10, 0.2,20, 0.3,30, 0.4,40, 0.5,50
57 printarray ky, 1, "", "ky="
58 turnoff
59 endin
60
61 instr 4
62 ; bpf as an envelope generator, like linsegb but driven by external phase
63 ; bpf + rms can also be used as compressor
64
65 atime linseg 0, p3*0.62, p3, p3*0.38, 0
66 aenv = bpf(atime, 0,0, 0.1,1, 0.5, 0.2) ^ 2
67 kbw = bpf(timeinsts(), 0, 0, p3*0.62, 1) ^ 3
68 asig = (beosc(1000, kbw, -1, rnd(6.28)) + beosc(1012, kbw, -1, rnd(6.28))) * 0.3
69 kratio bpf dbamp(rms:k(asig)), -12, 1, -6, 0.4, -3, 1/100
70 asig *= aenv * interp(lagud(kratio, 0.01, 0.1))
71 outs asig, asig
72 endin
73
74 </CsInstruments>
75 <CsScore>
76 ; i 1 0 3
77 ; i 2 0 -1
78 ; i 3 0 -1
79 i 4 0 3
80
81 </CsScore>
82 </CsoundSynthesizer>