| Gentlemen, good evening.
I offer to you a humble attempt at the subject line of this thread.
This file was written for use with *MacCsound* 1.2a5 and will also work
transparently with [csoundapi~] for Pd as well as any other
encapsulation of the CsoundLib that implements the transmission of
invalue/outvalue; so feasibly TclCsound and [csound~] for Max/MSP as
well - without any modification to the .csd file.
It is _not_ required that users are using version 5 of the language to
run this example.
For users running this with version 5, you can run this without
transmitting any of the invalues, as they are only used for the effects
UDO's (that are not on the repository at present time but I will mark
them up shortly) without any noticeable effect on it's basic
functionality.
Anyway, I hope this helps to understand a good way to use the sensekey
- in this example I am just implementing a "meta" instrument that's
always on and that generates events. This is also a useful technique
for MIDI, say for program change messages for example.
Please do not hesitate to email this list further with any inquiries
regarding the attached file. I'll be happy to clarify or elaborate on
anything you may wonder or postulate about.
sr = 44100
kr = 4410
ksmps = 10
nchnls = 2
gifn1 ftgen 1,0,16384,10,1
gifn5 ftgen 5,0,16384,21,6,1
/*---
:: ASCII Key Drum Model
--:: by David Akbari
Current Implementation:
(Key) : (Drum type)
----- -----------
A = Snare drum
S = Kick drum
D = Closed Hi-hat
F = Open Hi-hat
(Invalue) : (Function)
"pre" = Pre-gain to Hyperbolic tangent distortion UDO
"vol" = Output volume of Hyperbolic tangent distortion UDO
"levl" = Output volume of sample rate reduce UDO
"sr" = Sample rate of sample rate reduce UDO
---*/
/* hyperbolic tangent distortion UDO */
opcode hyptan, a, akk
asig, kpre, kvol xin
; make these continuously variable??
ks1 = 0.8
ks2 = 0.8
;;
kpregn = kpre / 8000 ; Pregain/Overdrive
kpostg = kvol * 20000 ; Postgain/Volume
ka1 = ks1 / 8000 ; Shape 1 0=flat
ka2 = ks2 / 8000 ; Shape 2
irect = 0 ; Rectification
ioutlvl = 1 ; Output Level
krms rms asig, 10
asig = asig + irect * krms
koffs1 = irect * krms * (kpre / 1000 + (ks1 - .5) / 8000)
koffs2 = -irect * krms * (kpre / 1000 + (ks2 - .5) / 8000)
koffs3 = irect * krms * (kpre / 1000)
koffs = ( exp(koffs1) - exp(koffs2)) / ( exp(koffs3) +
exp(-koffs3))
ax1 = asig * (kpregn + ka1) ; Precalculate a
few values to save time
ax2 = -asig * (kpregn + ka2)
ax3 = asig * kpregn
aout = (( exp(ax1) - exp(ax2)) / ( exp(ax3) + exp(-ax3)) -
koffs) * kpostg ; modified tanh distortion
xout aout * ioutlvl ; Output the result
endop
/* sample rate reduce UDO */
opcode srReduce, a, akk
ain, klevl, ksr xin
ibits = (2 ^ 16) ; Bit depth
kfold = sr / ksr ; Sample rate
kin downsamp ain ; Convert to kr
kin = kin + 32768 ; Add DC to avoid (-)
kin = kin*(ibits/65536) ; Divide signal level
kin = int(kin) ; Quantise
aout upsamp kin ; Convert to sr
aout = aout*(65536/ibits) - 32768 ; Scale and remove DC
aout fold aout, kfold ; Resample
xout aout * klevl ; Level and output
endop
/**********************************/
instr 1 ;snare drum
; init
kpre invalue "pre"
kvol invalue "vol"
klevl invalue "levl"
ksr invalue "sr"
idur = p3
iamp = ampdb(p4)
ifrq = p5
iatk = p6
; synth
kampenv expseg iatk, .5, .001
;asnare oscil kampenv, ifrq, 5
asnare foscil kampenv, ifrq, 1, 1, 100, 5
klfo oscil .5, .25, 1
klfo = klfo + .5
;asnare hyptan asnare,kpre,kvol
;asnare srReduce asnare,klevl,ksr
outs asnare*klfo, asnare*(1-klfo)
endin
/**********************************/
instr 2 ;kick drum
; init
kpre invalue "pre"
kvol invalue "vol"
klevl invalue "levl"
ksr invalue "sr"
idur = p3
indx = p4
ivel = p5
; synth
kpenv expon 60, 1, 40
kampenv expseg .001, .01, ivel, 1, .001
akick foscil kampenv, kpenv, 1, 4, indx, 1
alpf butterlp akick, 80
;alpf hyptan alpf,kpre,kvol
;alpf srReduce alpf,klevl,ksr
outs alpf, alpf
endin
/**********************************/
instr 3 ;hi hat
; init
kpre invalue "pre"
kvol invalue "vol"
klevl invalue "levl"
ksr invalue "sr"
idur = p3
iamp = p4
ifrq = p5
idrum = p6
ilforate = p7
iseed = p8
ipan = .5
if (idrum == 1) kgoto closed
if (idrum == 2) kgoto open
kgoto end
; synth
closed:
kampenv expseg p4+5000, .2, .01
kgoto contin
open:
kampenv linseg p4+5000, .2, .01
kgoto contin
contin:
kamplfo oscil .5, ilforate, 1
kpan oscil .5, idur/4, 1
kamplfo = kamplfo + .5
;ahhat oscil ((kampenv + ampdb(kamplfo))/2), ifrq, 5
ahhat foscil ((kampenv + ampdb(kamplfo))/2), ifrq, 1, 1, 100, 5
afilt2 atone ahhat, 8000
afilt1 atone afilt2, 8000
kpan = kpan + .5
;afilt1 hyptan afilt1,kpre,kvol
;afilt1 srReduce afilt1,klevl,ksr
outs afilt1 * (1 - kpan), afilt1 * (kpan)
end:
endin
/**********************************/
instr 4 ;meta keys
k1 sensekey
if (k1 == 97) then
event "i",1,0,1,78,1289,15000
elseif (k1 == 115) then
event "i",2,0,0.75,1,15000
elseif (k1 == 100) then
event "i",3,0,0.5,20000,1289,1,0.25,0
elseif (k1 == 102) then
event "i",3,0,0.5,20000,1289,2,0.25,0
else
endif
endin
i4 0 300
e
Version: 3
Render: Real
Ask: Yes
Functions: ioObject
WindowBounds: 364 44 1037 793
Options: -b1024 -A -s -m7 -K -R
ioView background {65535, 64997, 56784}
ioListing {14, 11} {405, 500}
ioGraph {419, 11} {447, 500}
ioSlider {25, 524} {102, 34} 0.000000 1.000000 0.464700 pre
ioSlider {147, 524} {102, 34} 0.000000 1.000000 0.676000 vol
ioSlider {277, 522} {102, 34} 0.000000 1.000000 1.000000 levl
ioSlider {418, 521} {102, 34} 1.000000 44100.000000 26085.560547 sr
ioText {24, 556} {103, 37} label 0.000000 0.001000 "" left "Lucida
Grande" 10 {0, 0, 0} {65535, 65535, 65535} nobackground noborder
pregain
ioText {148, 558} {101, 35} label 0.000000 0.001000 "" left "Lucida
Grande" 10 {0, 0, 0} {65535, 65535, 65535} nobackground noborder volume
ioText {277, 557} {101, 35} label 0.000000 0.001000 "" left "Lucida
Grande" 10 {0, 0, 0} {65535, 65535, 65535} nobackground noborder level
ioText {418, 557} {101, 35} label 0.000000 0.001000 "" left "Lucida
Grande" 10 {0, 0, 0} {65535, 65535, 65535} nobackground noborder sr
-David |