| 1 |
<CsoundSynthesizer> |
| 2 |
|
| 3 |
<CsOptions> |
| 4 |
; Select audio/midi flags here according to platform |
| 5 |
; Audio out Audio in |
| 6 |
-odac -iadc ;;;RT audio I/O |
| 7 |
; For Non-realtime ouput leave only the line below: |
| 8 |
; -o vcella.wav -W ;;; for file output any platform |
| 9 |
</CsOptions> |
| 10 |
|
| 11 |
<CsInstruments> |
| 12 |
; vcella.csd |
| 13 |
; by Anthony Kozar |
| 14 |
|
| 15 |
; This file demonstrates some of the new opcodes available in |
| 16 |
; Csound 5 that come from Gabriel Maldonado's CsoundAV. |
| 17 |
|
| 18 |
sr = 44100 |
| 19 |
kr = 4410 |
| 20 |
ksmps = 10 |
| 21 |
nchnls = 1 |
| 22 |
|
| 23 |
; Cellular automata-driven oscillator bank using vcella and adsynt |
| 24 |
instr 1 |
| 25 |
idur = p3 |
| 26 |
iCArate = p4 ; number of times per second the CA calculates new values |
| 27 |
|
| 28 |
; f-tables for CA parameters |
| 29 |
iCAinit = p5 ; CA initial states |
| 30 |
iCArule = p6 ; CA rule values |
| 31 |
; The rule is used as follows: |
| 32 |
; the states (values) of each cell are summed with their neighboring cells within |
| 33 |
; the specied radius (+/- 1 or 2 cells). Each sum is used as an index to read a |
| 34 |
; value from the rule table which becomes the new state value for its cell. |
| 35 |
; All new states are calculated first, then the new values are all applied |
| 36 |
; simultaneously. |
| 37 |
|
| 38 |
ielements = ftlen(iCAinit) |
| 39 |
inumrules = ftlen(iCArule) |
| 40 |
iradius = 1 |
| 41 |
|
| 42 |
; create some needed tables |
| 43 |
iCAstate ftgen 0, 0, ielements, -2, 0 ; will hold the current CA states |
| 44 |
ifreqs ftgen 0, 0, ielements, -2, 0 ; will hold the oscillator frequency for each cell |
| 45 |
iamps ftgen 0, 0, ielements, -2, 0 ; will hold the amplitude for each cell |
| 46 |
|
| 47 |
; calculate cellular automata state |
| 48 |
ktrig metro iCArate ; trigger the CA to update iCArate times per second |
| 49 |
vcella ktrig, 0, iCAstate, iCAinit, iCArule, ielements, inumrules, iradius |
| 50 |
|
| 51 |
; scale CA state for use as amplitudes of the oscillator bank |
| 52 |
vcopy iamps, iCAstate, ielements |
| 53 |
vmult iamps, (1/3), ielements ; divide by 3 since state values are 0-3 |
| 54 |
|
| 55 |
vport iamps, .01, ielements ; need to smooth the amplitude changes for adsynt |
| 56 |
; we could use adsynt2 instead of adsynt, but it does not seem to be working |
| 57 |
|
| 58 |
; i-time loop for calculating frequencies |
| 59 |
index = 0 |
| 60 |
inew = 1 |
| 61 |
iratio = 1.125 ; just major second (creating a whole tone scale) |
| 62 |
loop1: |
| 63 |
tableiw inew, index, ifreqs, 0 ; 0 indicates integer indices |
| 64 |
inew = inew * iratio |
| 65 |
index = index + 1 |
| 66 |
if (index < ielements) igoto loop1 |
| 67 |
|
| 68 |
; create sound with additive oscillator bank |
| 69 |
ifreqbase = 64 |
| 70 |
iwavefn = 1 |
| 71 |
iphs = 2 ; random oscillator phases |
| 72 |
|
| 73 |
kenv linseg 0.0, 0.5, 1.0, idur - 1.0, 1.0, 0.5, 0.0 |
| 74 |
aosc adsynt kenv, ifreqbase, iwavefn, ifreqs, iamps, ielements, iphs |
| 75 |
|
| 76 |
out aosc * ampdb(68) |
| 77 |
endin |
| 78 |
|
| 79 |
</CsInstruments> |
| 80 |
|
| 81 |
<CsScore> |
| 82 |
f1 0 16384 10 1 |
| 83 |
|
| 84 |
; This example uses a 4-state cellular automata |
| 85 |
; Possible state values are 0, 1, 2, and 3 |
| 86 |
|
| 87 |
; CA initial state |
| 88 |
; We have 16 cells in our CA, so the initial state table is size 16 |
| 89 |
f10 0 16 -2 0 1 0 0 1 0 0 2 2 0 0 1 0 0 1 0 |
| 90 |
|
| 91 |
; CA rule |
| 92 |
; The maximum sum with radius 1 (3 cells) is 9, so we need 10 values in the rule (0-9) |
| 93 |
f11 0 16 -2 1 0 3 2 1 0 0 2 1 0 |
| 94 |
|
| 95 |
; Here is our one and only note! |
| 96 |
i1 0 20 4 10 11 |
| 97 |
|
| 98 |
e |
| 99 |
|
| 100 |
</CsScore> |
| 101 |
</CsoundSynthesizer> |