| 1 |
<CsoundSynthesizer> |
| 2 |
<CsOptions> |
| 3 |
-odac |
| 4 |
</CsOptions> |
| 5 |
<CsInstruments> |
| 6 |
|
| 7 |
; Example for opcode bpfcos |
| 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 half cosine curve defined by the |
| 15 |
pairs |
| 16 |
|
| 17 |
It works both at i- and k- time |
| 18 |
|
| 19 |
ky bpfcos kx, kx0, ky0, kx1, ky1, kx2, ky2, ... |
| 20 |
kys[] bpfcos kxs[], kx0, ky0, kx1, ky1, kx2, ky2, ... |
| 21 |
ky bpfcos kx, kxs[], kys[] |
| 22 |
ky, kz bpfcos kx, kxs[], kys[], kzs[] |
| 23 |
|
| 24 |
NB: x values must be ordered (kx0 < kx1 < kx2 etc) |
| 25 |
|
| 26 |
See also: bpf, linlin, lincos |
| 27 |
|
| 28 |
*/ |
| 29 |
sr = 44100 |
| 30 |
ksmps = 64 |
| 31 |
nchnls = 1 |
| 32 |
0dbfs = 1 |
| 33 |
|
| 34 |
instr 1 |
| 35 |
kx line -1, p3, 2.5 |
| 36 |
ky bpfcos kx, \ |
| 37 |
0, 0, \ |
| 38 |
1.01, 10, \ |
| 39 |
2, 0.5, \ |
| 40 |
2.5, -1 |
| 41 |
printks "kx: %f ky: %f \n", 0.1, kx, ky |
| 42 |
endin |
| 43 |
|
| 44 |
instr 2 |
| 45 |
; test i-time |
| 46 |
ix = 1.2 |
| 47 |
iy bpfcos ix, 0,0, 0.5,5, 1,10, 1.5,15, 2,20, 2.5,25, 3,30 |
| 48 |
print iy |
| 49 |
turnoff |
| 50 |
endin |
| 51 |
|
| 52 |
instr 3 |
| 53 |
; bpfcos also works with arrays. For each kx value in kxs, |
| 54 |
; calculate the corresponding ky |
| 55 |
kxs[] fillarray 0, 0.15, 0.25, 0.35, 0.45, 0.55, 0.6 |
| 56 |
kys[] bpfcos kxs, 0,0, 0.1,10, 0.2,20, 0.3,30, 0.4,40, 0.5,50 |
| 57 |
printarray kys, 1, "", "kys=" |
| 58 |
turnoff |
| 59 |
endin |
| 60 |
|
| 61 |
instr 4 |
| 62 |
; bpfcos is useful to implement envelopes with ease-in/out shape |
| 63 |
kpitch bpfcos timeinsts(), 0, 60, 2, 61, 3, 65, 3.5, 60 |
| 64 |
a0 oscili 0.5, mtof(kpitch) |
| 65 |
kenv0 linseg 0, 0.5, 1, p3-1, 1, 0.5, 0 |
| 66 |
kenv bpfcos kenv0, 0, 0, 0.5, 0.25, 1, 0.7 |
| 67 |
a0 *= interp(kenv) |
| 68 |
outch 1, a0 |
| 69 |
endin |
| 70 |
|
| 71 |
instr 5 |
| 72 |
; arrays can also be used to define the points of a break-point-function |
| 73 |
; multiple arrays can be used simultaneously |
| 74 |
; In this case, we define a line and for each point in the line a |
| 75 |
; corresponding pitch (midinote) and amplitude |
| 76 |
; NB: kTimes uses absolute times |
| 77 |
kTimes[] fillarray 0, 1, 1.5, 2, 3, 5 |
| 78 |
kPitches[] fillarray 60, 65, 64, 69, 60, 61 |
| 79 |
kAmps[] fillarray 0, 1, 0.1, 1, 0.1, 1 |
| 80 |
; play the envelopes at half speed |
| 81 |
kpitch, kamp bpfcos timeinsts()*0.5, kTimes, kPitches, kAmps |
| 82 |
aout oscili a(kamp), a(mtof:k(kpitch)) |
| 83 |
; declick |
| 84 |
aout *= linsegr(0, 0.1, 1, 0.1, 0) |
| 85 |
outch 1, aout |
| 86 |
endin |
| 87 |
|
| 88 |
</CsInstruments> |
| 89 |
<CsScore> |
| 90 |
; i 1 1 3 |
| 91 |
; i 2 0 -1 |
| 92 |
; i 3 0 -1 |
| 93 |
; i 4 0 5 |
| 94 |
i 5 0 10 |
| 95 |
e 12 |
| 96 |
</CsScore> |
| 97 |
</CsoundSynthesizer> |