; Fractal Music
; by Darren Nelsen
; http://www.curiomusic.com
; Copyright 2008 Darren Nelsen. Licensed to the public under cc by-nc-sa: http://creativecommons.org/licenses/by-nc-sa/3.0/us/
sr = 44100
ksmps = 10
nchnls = 2
;; global variables
gasend init 0 ; delay
gadrysig init 0 ; INITIALIZE GLOBAL VARIABLE for diffusion reverb
instr 100 ; main instr w/lfo panning and dynamic filtering
;inital vars
idur = p3
iamp = p4
ipchfn = p5
iseqfn = p6
idurx = p9 ;duration multiplier
iwavfn = p8
iatk = p10
irel = p11
indx = 0
;overall amp envelope
kenv linen 1, idur * iatk, idur, idur * irel
;panning
ipanfrq = p7 ; panning frequency
kpan oscil .5, ipanfrq, 1 ; panning lfo
kpanlfo = kpan + .5 ; bias
kpan2 = kpanlfo*3.14159265*.5
kpanl = cos(kpan2)
kpanr = sin(kpan2)
;reinit/reassign vars
start:
iseqnum table indx,iseqfn, 0, 0, 1 ;get a seq num, use a wraparound table
ipch table iseqnum,ipchfn, 0, 0, 1 ;get a pitch using a number from the sequence as an index
ipch = (ipch < 20) ? cpspch(ipch) : ipch ; allows you to use cpspch or Hz notation
idurn table indx,iseqfn, 0, 0, 1 ;get a duration using a number from the sequence as an index
idurn = idurn * idurx
;jump to the continue tag, outputting the sound
timout 0, idurn, continue
;go back to the start tag
reinit start
continue:
;print out vars
print indx
print iseqnum
print ipch
print idurn
;amp envelope for individual notes
k1 linen iamp, idurn * iatk, idurn, idurn * irel
;audio
a1 oscil k1, ipch, iwavfn
kfrq invalue "frq"
kbwdth invalue "bwdth"
afilt reson a1, kfrq, kbwdth
afin balance afilt, a1
;dispfft afin, idurn, 2048
;a1 buzz k1, ipch, 10, iwavfn
;a1 pluck k1, ipch, ipch, 2, iwavfn
;send to reverb (apply the envelope)
gadrysig = gadrysig + (afin *kenv)
;output in stereo
outs (afin*kenv)*kpanl, (afin*kenv)*kpanr
;increment the seq num
indx = indx + 1
endin
instr 101 ; main instr w/lfo panning and set filtering
;inital vars
idur = p3
iamp = p4
ipchfn = p5
iseqfn = p6
idurx = p9 ;duration multiplier
iwavfn = p8
iatk = p10
irel = p11
indx = 0
;overall amp envelope
kenv linen 1, idur * iatk, idur, idur * irel
;lfo panning
ipanfrq = p7 ; panning frequency
kpan oscil .5, ipanfrq, 1 ; panning lfo
kpanlfo = kpan + .5 ; bias
kpan2 = kpanlfo*3.14159265*.5
kpanl = cos(kpan2)
kpanr = sin(kpan2)
;reinit/reassign vars
start:
iseqnum table indx,iseqfn, 0, 0, 1 ;get a seq num, use a wraparound table
ipch table iseqnum,ipchfn, 0, 0, 1 ;get a pitch using a number from the sequence as an index
ipch = (ipch < 20) ? cpspch(ipch) : ipch ; allows you to use cpspch or Hz notation
idurn table indx,iseqfn, 0, 0, 1 ;get a duration using a number from the sequence as an index
idurn = idurn * idurx
;jump to the continue tag, outputting the sound
timout 0, idurn, continue
;go back to the start tag
reinit start
continue:
; print out vars
;print indx
;print iseqnum
;print ipch
;print idurn
;amp envelope for individual notes
k1 linen iamp, idurn * iatk, idurn, idurn * irel
;audio
a1 oscil k1, ipch, iwavfn
kfrq = p12 ;invalue "frq"
kbwdth = p13 ;invalue "bwdth"
afilt reson a1, kfrq, kbwdth
afin balance afilt, a1
;dispfft afin, idurn, 2048
;a1 buzz k1, ipch, 10, iwavfn
;a1 pluck k1, ipch, ipch, 2, iwavfn
;send to reverb (apply the envelope)
gadrysig = gadrysig + (afin *kenv)
;output in stereo
outs (afin*kenv)*kpanl, (afin*kenv)*kpanr
;increment the seq num
indx = indx + 1
endin
instr 102 ; main instr w/set panning and filtering
;inital vars
idur = p3
iamp = p4
ipchfn = p5
iseqfn = p6
idurx = p9 ;duration multiplier
iwavfn = p8
iatk = p10
irel = p11
indx = 0
;overall amp envelope
kenv linen 1, idur * iatk, idur, idur * irel
;panning
ipan = p7
kpan2 = ipan*3.14159265*.5
kpanl = cos(kpan2)
kpanr = sin(kpan2)
;reinit/reassign vars
start:
iseqnum table indx,iseqfn, 0, 0, 1 ;get a seq num, use a wraparound table
ipch table iseqnum,ipchfn, 0, 0, 1 ;get a pitch using a number from the sequence as an index
ipch = (ipch < 20) ? cpspch(ipch) : ipch ; allows you to use cpspch or Hz notation
idurn table indx,iseqfn, 0, 0, 1 ;get a duration using a number from the sequence as an index
idurn = idurn * idurx
;jump to the continue tag, outputting the sound
timout 0, idurn, continue
;go back to the start tag
reinit start
continue:
; print out vars
;print indx
;print iseqnum
;print ipch
;print idurn
;amp envelope for individual notes
k1 linen iamp, idurn * iatk, idurn, idurn * irel
;audio
a1 oscil k1, ipch, iwavfn
kfrq = p12 ;invalue "frq"
kbwdth = p13 ;invalue "bwdth"
afilt reson a1, kfrq, kbwdth
afin balance afilt, a1
;dispfft afin, idurn, 2048
;a1 buzz k1, ipch, 10, iwavfn
;a1 pluck k1, ipch, ipch, 2, iwavfn
;send to reverb (apply the envelope)
gadrysig = gadrysig + (afin *kenv)
;output in stereo
outs (afin*kenv)*kpanl, (afin*kenv)*kpanr
;increment the seq num
indx = indx + 1
endin
instr 128 ; 'Air' instrument
idur = p3
iamp = p4
ifrq = p5
iatk = p6
irel = p7
icf = p8 ; center frequency
icffromdev gauss p9 ; center frequency from deviation
icftodev gauss p9 ; center frequency to deviation
ibw = p10 ; bandwidth
ibwfromdev trirand p11 ; bandwidth from deviation
ibwtodev trirand p11 ; bandwidth to deviation
iCenterFreqFrom = icf + icffromdev
iCenterFreqTo = icf + icftodev
iBandwidthFrom = ibw + ibwfromdev
iBandwidthTo = ibw + ibwtodev
iwetamt = p13 ; for effects processing/reverb
;lfo panning
ipanfrq = p12 ; panning frequency
kpan oscil .5, ipanfrq, 1 ; panning lfo
kpanlfo = kpan + .5 ; bias
kpan2 = kpanlfo*3.14159265*.5
kpanl = cos(kpan2)
kpanr = sin(kpan2)
;TODO change this envelope
;name opcode, fromhere, atk, to, duration, tothisamp, durationcalculatedrighthere, tothisamp, rel, tohere
kenv linseg .0001, iatk, iamp, idur/6, iamp*.7, idur-(iatk+irel+idur/6), iamp*.9, irel, .0001
anoise rand ifrq
kcf expon iCenterFreqFrom, idur, iCenterFreqTo
kbw linseg iBandwidthFrom, idur*.7, iBandwidthTo, idur*.3, iBandwidthFrom*.8
;output values
outvalue "airFreq", kcf
outvalue "airBand", kbw
outvalue "airAmp", kenv
print iCenterFreqFrom
print iCenterFreqTo
print iBandwidthFrom
print iBandwidthTo
;apply filter
afilt reson anoise,kcf, kbw, 2
;send it to output var
aout = afilt*kenv
;apply reverb
gadrysig = gadrysig + aout * iwetamt
;send it out
outs aout*kpanl,aout*kpanr
display kenv, idur
;display kcf, idur
;display kbw, idur
endin
instr Chime1 ; Chimes
iwetamt = p12
;inital vars
idur = p3
iamp = p4
ipchfn = p5
iseqfn = p6
iwavfn = p7
ipan = p8
iatk = p9
irel = p10
indx = 0
iaugdim = p11 ;augmentation/diminution
;overall amp envelope
kenv linen 1, idur * iatk, idur, idur * irel
;panning
kpan2 = ipan*3.14159265*.5
kpanl = cos(kpan2)
kpanr = sin(kpan2)
;reinit/reassign vars
start:
iseqnum table indx, iseqfn, 0, 0, 1
ipch table iseqnum, ipchfn, 0, 0, 1
ipch = (ipch < 20) ? cpspch(ipch) : ipch ; allows you to use cpspch or Hz notation
idurn table indx, iseqfn, 0, 0, 1
idurn = idurn * iaugdim ; augment or diminish note durations by aug/dim multiplier
timout 0, idurn, continue ;jump to continue
reinit start ;go back to start
continue: ;do this stuff...
;amp envelope
isnddur = .6 ; percentage of duration that note sounds
isilence = 1 - isnddur ; percentage of duration that note is silenced
k1 linseg iamp, idurn * isnddur, 0, idurn * isilence, 0
;kgate linseg iamp, 3, 0, 1,0 ; .1 SECOND RAMP
asig pluck k1, ipch, ipch, iwavfn, 2, 1, 0 ; SIMPLE PLUCK
gasend = gasend + (asig*kenv) * iwetamt ; ADD TO GLOBAL VAR
outs (asig*kenv)*kpanl, (asig*kenv)*kpanr
indx = indx + 1
endin
instr Chime2 ; Chimes
iwetamt = p12
;inital vars
idur = p3
iamp = p4
ipchfn = p5
iseqfn = p6
iwavfn = p7
ipan = p8
iatk = p9
irel = p10
indx = 0
iaugdim = p11 ;augmentation/diminution
;overall amp envelope
kenv linen 1, idur * iatk, idur, idur * irel
;panning
kpan2 = ipan*3.14159265*.5
kpanl = cos(kpan2)
kpanr = sin(kpan2)
;reinit/reassign vars
start:
iseqnum table indx, iseqfn, 0, 0, 1
ipch table iseqnum, ipchfn, 0, 0, 1
ipch = (ipch < 20) ? cpspch(ipch) : ipch ; allows you to use cpspch or Hz notation
idurn table indx, iseqfn, 0, 0, 1
idurn = idurn * iaugdim ; augment or diminish note durations by aug/dim multiplier
timout 0, idurn, continue ;jump to continue
reinit start ;go back to start
continue: ;do this stuff...
;amp envelope
isnddur = .6 ; percentage of duration that note sounds
isilence = 1 - isnddur ; percentage of duration that note is silenced
k1 linseg iamp, idurn * isnddur, 0, idurn * isilence, 0
;kgate linseg iamp, 3, 0, 1,0 ; .1 SECOND RAMP
asig pluck k1, ipch, ipch, iwavfn, 2, 1, 0 ; SIMPLE PLUCK
kfrq = p13 ;invalue "frq"
kbwdth = p14 ;invalue "bwdth"
afilt reson asig, kfrq, kbwdth
afin balance afilt, asig
gasend = gasend + (afin*kenv) * iwetamt ; ADD TO GLOBAL VAR
outs (afin*kenv)*kpanl, (afin*kenv)*kpanr
indx = indx + 1
endin
instr 2203 ; global delay effect
atap1 delay gasend*p4,p6 ; use global var for inputs
atap2 delay gasend*p5,p7
outs atap1, atap2
gasend = 0
endin
instr 2305 ; stereo diffusion reverb
irevtime = p4
adelayline delayr 0.2
amtap1 deltap 0.0430
amtap2 deltap 0.0320
amtap3 deltap 0.1458
amtap4 deltap 0.1423
amtap5 deltap 0.0103
amtap6 deltap 0.0239
amtap7 deltap 0.0446
amtap8 deltap 0.1035
amtap9 deltap 0.1067
amtap10 deltap 0.0087
amtap11 deltap 0.0837
amtap12 deltap 0.1676
delayw gadrysig
adiffleft = amtap1+amtap2+amtap3+amtap4+amtap5+amtap6
adiffright = amtap7+amtap8+amtap9+amtap10+amtap11+amtap12
arevleft reverb adiffleft,irevtime
arevright reverb adiffright,irevtime
outs arevleft/6, arevright/6
gadrysig = 0
endin
; Fractal Music
; by Darren Nelsen
; http://www.curiomusic.com
; Copyright 2008 Darren Nelsen. Licensed to the public under cc by-nc-sa: http://creativecommons.org/licenses/by-nc-sa/3.0/us/
;================================================================================================
; BASIC WAVES
;sine wave
f 1 0 8192 10 1
;sawtooth wave
;p1 p2 p3 p4 p5
;id start size gen values
f 2 0 8192 10 1 .5 .333 .25 .2 .166 .142 .125 .111 .1 .09 .083 .076 .071 .066 .062
;square wave
;sounds like clarinet or bassoon / woodwind
f 3 0 8192 10 1 0 .333 0 .2 0 .143 0 .111 0 .0909 0 .077 0 .0666 0 .0588
;pulse wave
;sounds like trumpet / brass
f 4 0 8192 10 .8 .9 .95 .96 1 .91 .8 .75 .6 .42 .5 .4 .33 .28 .2 .15
;cosine wave (sine wave with intial phase of 90 degrees)
f 6 0 8192 9 1 1 90
;triangle wave
f 7 0 513 9 1 1 0 3 .333 180 5 .2 0 7 .143 180 9 .111 0
;half of a sine
f 8 0 513 9 .5 1 0
;================================================================================================
;================================================================================================
; SCALES
;f14 is a pitch table defining a four octave six-note scale in Pythagorean tuning
f 14 0 16 -2 98.0 110.75 124.03 147.0 165.38 186.05 196.0 220.5 248.06 294.0 330.75 372.1 392.0 441.0 496.13 588.0 661.50 744.19 784.0 882.0 992.25 1176.0 1323.0 1488.38
f 80 0 4 -2 6.00 6.02 6.04 6.07 6.09 6.11 7.00 7.02 ; c pelog
f 81 0 8 -2 7.00 7.02 7.04 7.07 7.09 7.11 8.00 8.02 ; c pelog
f 82 0 8 -2 8.00 8.02 8.04 8.07 8.09 8.11 9.00 9.02 ; c pelog
f 83 0 8 -2 9.00 9.02 9.04 9.07 9.09 9.11 10.00 10.02 ; c pelog
f 84 0 8 -2 10.00 10.02 10.04 10.07 10.09 10.11 11.00 11.02 ; c pelog
f 90 0 8 -2 6.02 6.04 6.07 6.09 6.11 7.00 7.02 7.04 ; c pelog
f 91 0 8 -2 7.02 7.04 7.07 7.09 7.11 8.00 8.02 8.04 ; c pelog
f 92 0 8 -2 8.02 8.04 8.07 8.09 8.11 9.00 9.02 9.04 ; c pelog
f 93 0 8 -2 9.02 9.04 9.07 9.09 9.11 10.00 10.02 10.04 ; c pelog
f 94 0 8 -2 10.02 10.04 10.07 10.09 10.11 11.00 11.02 11.04 ; c pelog
;================================================================================================
;================================================================================================
; FRACTAL SEQUENCES
; found at http://www.research.att.com/~njas/sequences/?q=fractal&language=english&go=Search
; p1 p2 p3 p4 p5
; id start size gen values
;----------------------------------------------------------------------------
;A054065 - Fractal sequence induced by tau
f 054065 0 64 -2 1 2 1 2 1 3 2 4 1 3 5 2 4 1 3 5 2 4 1 6 3 5 2 7 4 1 6 3 5 2 7 4 1 6 3 8 5 2 7 4 9 1 6 3 8 5 10 2 7 4 9 1 6 3 8 5 10 2 7 4 9 1 6 11 3 8 5 10 2 7 12
;A092106 - Fractal mountains in base 3.
f 092106 0 64 -2 0 1 3 2 2 3 1 0 0 1 3 6 6 7 9 8 8 9 11 14 18 19 21 24 24 25 27 26 26 27 25 24 24 21 19 18 18 19 21 20 20 21 19 18 18 19 21 24 24 25 27 26 26 27 25 24 24 21 19 18 14 11 9 8 8 9 7 6 6 3 1 0 0 1 3 2 2 3 1 0 0 1
;A093347 - 3 castle
f 093347 0 64 -2 0 1 0 3 2 3 0 1 0 9 8 9 6 7 6 9 8 9 0 1 0 3 2 3 0 1 0 27 26 27 24 25 24 27 26 27 18 19 18 21 20 21 18 19 18 27 26 27 24 25 24 27 26 27 0 1 0 3 2 3 0 1 0 9 8 9 6 7 6 9 8 9 0 1 0 3 2 3 0 1 0 81 80 81 78 79 78 81
;A093348 - 5 castle
f 093348 0 64 -2 0 1 0 1 0 5 4 5 4 5 0 1 0 1 0 5 4 5 4 5 0 1 0 1 0 25 24 25 24 25 20 21 20 21 20 25 24 25 24 25 20 21 20 21 20 25 24 25 24 25 0 1 0 1 0 5 4 5 4 5 0 1 0 1 0 5 4 5 4 5 0 1 0 1 0 25 24 25 24 25 20 21 20 21 20 25 24
;A105669 - A "fractal" transform of the Fibonacci numbers
f 105669 0 64 -2 1 2 2 4 7 7 6 6 12 11 11 9 20 20 19 19 17 14 14 15 15 33 32 32 30 27 27 28 28 22 23 23 25 54 54 53 53 51 48 48 49 49 43 44 44 46 35 35 36 36 38 41 41 40 40 88 87 87 85 82 82 83 83 77 78 78 80 69 69 70 70 72
;A131967 - Farey fractal sequence
f 131967 0 64 -2 1 2 1 3 2 1 4 3 5 2 1 6 4 3 5 7 2 1 8 6 4 9 3 10 5 7 11 2 1 12 8 6 4 9 3 10 5 7 11 13 2 1 14 12 8 6 15 4 9 16 3 17 10 5 18 7 11 13 19 2 1 20 14 12 8 6 15 4 21 9 16 3 17 10 22 5 18 7 11 13 19 23 2
;================================================================================================
;================================================================================================
; ADVANCE
;note: use skip(p3) to advance the score
; p1 p2 p3
;adv null str skip
;-----------------------
a 0 0 0
;================================================================================================
;================================================================================================
; TEMPO
t 0 40
;================================================================================================
;================================================================================================
; MAIN INSTRUMENTS
b 0
; p1 p2 p3 p4 p5 parameter6 p7 p8 p9 p10 p11 p12 p13
; ins strt dur amp pchfn sequencefn pn/fq wavfn durx atk rel cf bw
;------------------------------------------------------------------------------------------------
i 102 0 380 4600 80 093347 .35 4 1 .2 .3 4551 1000 ; tuba
i 102 30 350 3700 81 092106 .65 3 1 .2 .3 1100 1200 ; bass clarinet
i 101 15 360 3075 82 054065 .05 7 1.5 .125 .2 2111 1058 ; synth sound
;================================================================================================
;================================================================================================
;; CHIMES w/echoes
b 8
;v 10 ; time warp factor
; p1 p2 p3 p4 p5 parameter6 p7 p8 p9 p10 p11 p12 p13 p14
; ins st dur amp pchfn sequencefn wavfn pan atk rel au/di auxsd cf bw
;------------------------------------------------------------------------------------------------
i "Chime1" 40 330 2000 93 131967 1 .3 .2 .2 1 1 ; chimes
i "Chime1" 50 330 2000 94 131967 1 .7 .2 .2 1 1 ; chimes
; low chime w/out effects
i "Chime1" 65 315 3530 81 131967 1 .6 .2 .4 2 0 ; chimes
; higher chime w/different wave function
i "Chime2" 71 305 1200 83 131967 2 .2 .125 .325 1.5 .5 5000 1000
;================================================================================================
;================================================================================================
;; NOISE/AIR SOUNDS
b 261
;p1 p2 p3 p4 p5 p6 p7 p8 p9 p10 p11 p12 p13
;ins st dur amp frq atk rel cf cfdev bw bwdev panfq auxsd
;------------------------------------------------------------------------------------------------
i128 0 27 .10 20000 10 15 1000 600 700 500 .0312 .3
i128 + 26 .12 . < < < . . . < <
i128 . 27 < . . . . . . . . .
i128 . 24 . . . . . . . . . .
i128 . 25 .09 . 8 20 800 . . . .0624 .4
;================================================================================================
;================================================================================================
; EFFECTS
b0 ; start the effects from 0
; stereo diffusion reverb
; p1 p2 p3 p4
; INS ST DUR RT60
;-------------------------------------
i 2305 0 390 1.3
; Delay
; p1 p2 p3 p4 p5 p6 p7
; INS ST DUR FAC1 FAC2 ECHO1 ECHO2
;-----------------------------------------------
i 2203 0 390 .5 .5 2.5 3.5
;================================================================================================
e
Version: 3
Render: File
Ask: No
SFDIR: /Users/darren/Music/Works/Csound/Fractal Music
Functions: ioObject
Listing: ioObject
WindowBounds: 17 44 1471 1055
CurrentView: options
IOViewEdit: Off
Options: -b128 -A -o/Users/darren/Music/Csound/Fractal Music/Fractal Music.aif -l -m167 -R --midi-velocity-amp=4 --midi-key-cps=5
ioView background {60108, 65535, 63132}
ioListing {602, 3} {488, 836}
ioGraph {0, 3} {600, 836}
ioSlider {1117, 15} {34, 604} 20.000000 20000.000000 2111.906006 frq
ioSlider {1194, 12} {34, 604} 1.000000 2000.000000 1057.871338 bwdth
ioText {1103, 631} {73, 37} display 2111.906006 0.001000 "frq" center "Lucida Grande" 10 {0, 0, 0} {65535, 65535, 65535} nobackground noborder
ioText {1191, 630} {65, 32} display 1057.871338 0.100000 "bwdth" center "Lucida Grande" 10 {0, 0, 0} {65535, 65535, 65535} nobackground noborder
ioText {1110, 689} {81, 24} label 0.000000 0.001000 "" left "Lucida Grande" 10 {0, 0, 0} {65535, 65535, 65535} nobackground noborder Air Frequency
ioText {1201, 689} {84, 24} label 0.000000 0.001000 "" left "Lucida Grande" 10 {0, 0, 0} {65535, 65535, 65535} nobackground noborder Air Bandwidth
ioText {1110, 724} {82, 25} display 962.003113 0.100000 "airFreq" left "Lucida Grande" 10 {0, 0, 0} {65535, 65535, 65535} nobackground noborder
ioText {1201, 724} {77, 24} display 311.844482 0.100000 "airBand" left "Lucida Grande" 10 {0, 0, 0} {65535, 65535, 65535} nobackground noborder
ioText {1290, 724} {68, 24} display 0.000114 0.000100 "airAmp" left "Lucida Grande" 10 {0, 0, 0} {65535, 65535, 65535} nobackground noborder
ioText {1290, 689} {74, 24} label 0.000000 0.001000 "" left "Lucida Grande" 10 {0, 0, 0} {65535, 65535, 65535} nobackground noborder Air Volume