Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
<CsoundSynthesizer>
<CsOptions>
--opcode-lib=serialOpcodes.dylib -odac
</CsOptions>
<CsInstruments>
sr = 44100
ksmps = 150 ; the default krate can be too fast for the arduino to handle
nchnls = 2
0dbfs = 1
;Global rever freq
gawhiteverb init 0
gablackreverb init 0
; Global mixs for each deck
gadeckaL init 0
gadeckaR init 0
gadeckbL init 0
gadeckbR init 0
;Global crossfader state
gkfaderstateA init 0
gkfaderstateB init 0
instr 1 ; Logic and Arduino communication
iPort serialBegin "/dev/cu.usbmodem1421", 9600
kType serialRead iPort
;printk .001, kType
;Answer the Arduino handshake to start the application
if (kType == 120.00000) kgoto startarduino
; Crossfader value range
if (kType >= 10.00000 && kType <= 20.00000) kgoto mixer
;The Black Value
if (kType == 49.00000) kgoto blacknote
;The White Value
if (kType == 50.00000) kgoto whitenote
;The Green Value
if (kType == 52.00000) kgoto jreennote ;it's supooused to be green but G is global, haha
;The Red Value
if (kType == 51.00000) kgoto rednote
;It's no note
if (kType != 50.00000 && kType != 49.00000 && kType != 52.00000 && kType != 120.00000 && kType != 51.00000) kgoto nothing
startarduino:
serialWrite iPort, 200
goto nothing
mixer:
if (kType == 10.00000) then
gkfaderstateA = 0
gkfaderstateB = 1
endif
if (kType == 11.00000) then
gkfaderstateA = .1
gkfaderstateB = .9
endif
if (kType == 12.00000) then
gkfaderstateA = .2
gkfaderstateB = .8
endif
if (kType == 13.00000) then
gkfaderstateA = .3
gkfaderstateB = .7
endif
if (kType == 14.00000) then
gkfaderstateA = .4
gkfaderstateB = .6
endif
if (kType == 15.00000) then
gkfaderstateA = .5
gkfaderstateB = .5
endif
if (kType == 16.00000) then
gkfaderstateA = .6
gkfaderstateB = .4
endif
if (kType == 17.00000) then
gkfaderstateA = .7
gkfaderstateB = .3
endif
if (kType == 18.00000) then
gkfaderstateA = .8
gkfaderstateB = .2
endif
if (kType == 19.00000) then
gkfaderstateA = .9
gkfaderstateB = .1
endif
if (kType == 20.00000) then
gkfaderstateA = 1
gkfaderstateB = 0
endif
goto nothing
blacknote:
event "i", 2, 1, 0.1
goto nothing
whitenote:
event "i", 3, 0.01, 0.1
goto nothing
jreennote:
event "i", 4, 0.01, 5
goto nothing
rednote:
event "i", 5, 0.01, 3
goto nothing
nothing:
endin
instr 2 ; Black Instrument
;Pick a random table slot
ipchndx random 0,13
;Find it in the table
ipch table ipchndx, 3
;Alternating amplitdue values
iamp random 0.7, 1
;Random panning
ipan random 0, 1
aenv expseg 1, (p3), .01
asig poscil iamp*aenv, cpspch(ipch), 1
kcf expon 1000,p3,20 ; descending cutoff frequency
aSig moogladder asig, kcf, iamp ; filter audio signal
;outs aSig*ipan, aSig* (1-ipan)
gadeckaL += aSig*ipan
gadeckaR += aSig* (1-ipan)
;Reverb Send
gablackreverb += aSig
endin
instr 3 ; White instrument
ipchndx random 0,13
ipch table ipchndx, 2
;Alternating amplitdue values
iamp random 0.3, 0.5
;Random panning
ipan random 0, 1
;Percussive sound envelope
aenv expseg 0.001, p3*0.025, 1, p3*0.75, 0.001
asig poscil iamp*aenv, cpspch(ipch), 1
;outs asig * ipan, asig * (1-ipan)
gadeckaL += asig * ipan
gadeckaR += asig * (1-ipan)
;Reveb send
gawhiteverb += asig
endin
instr 4 ; Green Instrument
iranomone random 0,13
; Table four
inotelow table iranomone, 4
irandomtwo random 0,13
; Table three
inotehigh table irandomtwo, 3
;Alternating amplitdue values
iamp random 0.03,0.5
;Random panning
ipan random 0, 1
;Percussive sound envelope
aenv expseg 0.001, p3*0.25, 1, p3*0.75, 0.001
; High Note
ahigh poscil iamp*aenv, cpspch(inotehigh), 1
; Low Harmony
alow poscil iamp*aenv, cpspch(inotelow), 1
;outs alow*0.2 + ahigh*0.8, alow*0.2 + ahigh*0.8
gadeckbL += alow*0.2 + ahigh*0.8
gadeckbR += alow*0.2 + ahigh*0.8
endin
instr 5 ; Red Instrument
itable random 0,13
itabletwo random 0,13
kCarFreq table itable, 2
kModFreq table itabletwo, 2
kIndex = 5
kIndexM = 0
kMaxDev = kIndex*kModFreq
kMinDev = kIndexM * kModFreq
kVarDev = kMaxDev-kMinDev
aEnv expseg .001, 0.2, 1, p3-0.3, 1, 0.2, 0.001
aModAmp = kMinDev+kVarDev*aEnv
aModulator poscil aModAmp, cpspch(kModFreq), 1
aCarrier poscil 0.3*aEnv, kCarFreq+aModulator, 1
;outs aCarrier, aCarrier
gadeckbL += aCarrier
gadeckbR += aCarrier
endin
instr 98 ; Reverb
; Random number betweeb 0 and 1
ipan random 0, 1
; Delay line
adel delay gawhiteverb+gablackreverb, .5
asig moogvcf adel, 1500, .6, 1
;outs asig*0.1, asig*0.1
gawhiteverb = 0 ;clear
gablackreverb = 0 ;clear
endin
instr 99 ; Mixer
aDeckAmixL = gadeckaL * gkfaderstateB
aDeckAmixR = gadeckaR * gkfaderstateB
aDeckBmixL = gadeckbR * gkfaderstateA
aDeckBmixR = gadeckbL * gkfaderstateA
aMixL = aDeckAmixL + aDeckBmixL
aMixR = aDeckAmixR + aDeckBmixR
outs aMixL, aMixR
gadeckaL = 0;
gadeckaR = 0;
gadeckbL = 0;
gadeckbR = 0;
endin
</CsInstruments>
<CsScore>
/* Ftable 1 - Sine Wave */
f1 0 16384 10 1
/* Ftable 2 - Pentatonic Scale 2 octaves */
f2 0 64 -2 9 9.03 9.05 9.07 9.10 10 10.03 10.05 10.07 10.10 11
/* Ftable 3 - Pentatonic Scale 2 octaves (Low note version) */
f3 0 64 -2 7 7.03 7.05 7.07 7.10 8 8.03 8.05 8.07 8.10 9
/* Ftable 3 - Pentatonic Scale 2 octaves (Even lower for drone harmony) */
f4 0 64 -2 6 6.03 6.05 6.07 6.10 7 7.03 7.05 7.07 7.10 8
;Play instrument #1 for as long as needed (maybe a week?)
i 1 0 3500 ; keep the arduino serial open
i 98 0 3500 ; keep the reverb bus open
i 99 0 3500 ; keep the mixer open
e
</CsScore>
</CsoundSynthesizer>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment