<CsoundSynthesizer>
<CsOptions
;-odevaudio -Ma -b400 -m0d
</CsOptions>
<CsInstruments>
sr     = 48000
kr     = 480
ksmps  = 100
nchnls = 2
 
massign 0, 101 ; alle Midi-Ereignisse an instr. 101

gkleftpedal init 0
instr 100
ichannelinstrumentone = 1
icontrollerinstrumentone = 67
gkleftpedal ctrl7 ichannelinstrumentone, icontrollerinstrumentone, 0, 1 ; controller 67 is the left pedal
endin
;
instr 101
gahall init 0
ileftpedal = i(gkleftpedal)

ieingesamtfaktor init 0.002

if ileftpedal >0 then
ieingesamtfaktor = 0.05 ; wenn das linke Pedal unten ist, ist die Einschwingphase insgesamt laenger
else
ieingesamtfaktor = 0.002
endif 

ituningtable = 10         ; Die Nummer der f-table, nach der die Stimmung ausgewählt wird

 icps    cpstmid   ituningtable

 
  iamp    ampmidi     1900

imidinote notnum ; Zuordnung der Midinoten
imidilaut veloc   ; Zuordnung der Key-Velocity
irel = 0.05
iz = 0.001
kzufallsfaktor gauss 0.00289
kzufall = 1+kzufallsfaktor
iwave = 1
; die einzelnen Teiltoene:
ipartial1 = icps
ipartial2 = icps*2.6406
ipartial3 = icps*4.2910
ipartial4 = icps*6.9729
ipartial5 = icps*8.8887
ipartial6 = icps*11.3310
ipartial7 = icps*14.4442
ipartial8 = icps*18.4128
ipartial9 = icps*21.6473
ipartial10 = icps*25.4501
ipartial11 = icps*29.0208
ipartial12 = icps*35.1769
ipartial13 = icps*38.1417
ipartial14 = icps*41.3564
ipartial15 = icps*44.842
ipartial16 = icps*48.6213
ipartial17 = icps*52.7192
; die unterschiedlichen Maxima der einzelnen Teiltoene:
ilautfaktortabellehigherpartials table imidinote, 88
ilautfaktortabellehighestpartials table imidinote, 89
imidilaut veloc 
ilautfaktor  table imidilaut, 90
imax1 = 1
imax2 = ilautfaktor^1.5
imax3 = ilautfaktor^1.6
imax4 = ilautfaktor^1.7
imax5 = ilautfaktor^2
imax6 = ilautfaktor^2.4*ilautfaktortabellehighestpartials
imax7 = ilautfaktor^2.7*ilautfaktortabellehighestpartials
imax8 = ilautfaktor^3*ilautfaktortabellehighestpartials
imax9 = ilautfaktor^4*ilautfaktortabellehighestpartials
imax10 = ilautfaktor^5*ilautfaktortabellehighestpartials
imax11 = ilautfaktor^6*ilautfaktortabellehighestpartials
imax12 = ilautfaktor^7*ilautfaktortabellehighestpartials
imax13 = ilautfaktor^8*ilautfaktortabellehighestpartials
imax14 = ilautfaktor^9*ilautfaktortabellehighestpartials
imax15 = ilautfaktor^10*ilautfaktortabellehighestpartials
imax16 = ilautfaktor^11*ilautfaktortabellehighestpartials
imax17 = ilautfaktor^12*ilautfaktortabellehighestpartials
;;;;;;;;;; huellkurven fuer das Ganze
ianfangslaut = 0.001
;:;; Einschwingzeit
ieinhochfundamental table imidinote, 100
ieinlautfundamental table imidilaut, 91
ieinlautlowerpartials table imidilaut, 92
ieinlauthigherpartials table imidilaut, 93
ieinlauthighestpartials table imidilaut, 94
iein1 = ieingesamtfaktor*ieinhochfundamental*ieinlautfundamental; sollte keine zu große Bandbreite haben
iein2 = ieingesamtfaktor*ieinhochfundamental*ieinlautlowerpartials; die Einwschingzeiten für die höheren Teiltöne dürfen ruhig eine höhere Bandbreite haben
iein3 = ieingesamtfaktor*ieinhochfundamental*ieinlauthigherpartials
iein4 = ieingesamtfaktor*ieinhochfundamental*ieinlauthighestpartials
;; Die Ausschwingphasen der einuzelnen Bereiche: 
iausallgemein = 18
iaushoch table imidinote, 101
iauslautfundamental table imidilaut, 95
iauslautlowerpartials table imidilaut, 96
iauslauthigherpartials table imidilaut, 97
iauslauthighestpartials table imidilaut, 98
iaus1 = iausallgemein*iaushoch*iauslautfundamental
iaus2 = iausallgemein*iaushoch*iauslautlowerpartials
iaus3 = iausallgemein*iaushoch*iauslauthigherpartials
iaus4 = iausallgemein*iaushoch*iauslauthighestpartials
iend = 0.00001
aenv1 expsegr ianfangslaut, iein1, 1, iaus1,  iend,  irel, iz 
aenv2 expsegr ianfangslaut,  iein2, 1, iaus2,  iend,  irel, iz 
aenv3 expsegr 0.3,0.01, 0.001,   iein3, 1, iaus3,  iend,  irel, iz 
aenv4 expsegr 0.3,0.01, 0.001,  iein4, 1, iaus4,  iend,  irel, iz 
; lfos fuer die Teiltoene 3-17
ilfoaus2 = iaus2*0.3
klfoenv3 linsegr 30, ilfoaus2, 0, 0, 0
klfoenv4 linsegr 30, ilfoaus2, 0, 0, 0
klfoenv5 linsegr 30, ilfoaus2, 0, 0, 0
klfoenv6 linsegr 30, iaus3, 0, 0, 0
klfoenv7 linsegr 30, iaus3, 0, 0, 0
klfoenv8 linsegr 30, iaus3, 0, 0, 0
klfoenv9 linsegr 30, iaus3, 0, 0, 0
klfoenv10 linsegr 30, iaus4, 0, 0, 0
klfoenv11 linsegr 30, iaus4, 0, 0, 0
klfoenv12 linsegr 30, iaus4, 0, 0, 0
klfoenv13 linsegr 30, iaus4, 0, 0, 0
klfoenv14 linsegr 30, iaus4, 0, 0, 0
klfoenv15 linsegr 30, iaus4, 0, 0, 0
klfoenv16 linsegr 30, iaus4, 0, 0, 0
klfoenv17 linsegr 30, iaus4,17 0, 0, 0
klfo3 lfo imax3*klfoenv3, klfoenv3*imax3
klfo4 lfo imax4*klfoenv4, klfoenv4*imax4
klfo5 lfo imax5*klfoenv5, klfoenv5*imax5
klfo6 lfo imax6*klfoenv6, klfoenv6*imax6
klfo7 lfo imax7*klfoenv7, klfoenv7*imax7
klfo8 lfo imax8*klfoenv8, klfoenv8*imax8
klfo9 lfo imax9*klfoenv9, klfoenv9*imax9
klfo10 lfo imax10*klfoenv10, klfoenv10*imax10
klfo11 lfo imax11*klfoenv11, klfoenv11*imax11
klfo12 lfo imax12*klfoenv12, klfoenv12*imax12
klfo13 lfo imax13*klfoenv13, klfoenv13*imax13
klfo14 lfo imax14*klfoenv14, klfoenv14*imax14
klfo15 lfo imax15*klfoenv15, klfoenv15*imax15
klfo16 lfo imax16*klfoenv16, klfoenv16*imax16
klfo17 lfo imax17*klfoenv17, klfoenv17*imax17
; die einzelnen Teiltoene:
a1 oscil imax1, ipartial1, iwave
a2 oscil imax2, ipartial2, iwave
a3 oscil imax3, ipartial3, iwave
a4 oscil imax4, ipartial4+klfo3, iwave
a5 oscil imax5, ipartial5+klfo4, iwave
a6 oscil imax6, ipartial6+klfo5, iwave
a7 oscil imax7, ipartial7+klfo6, iwave
a8 oscil imax8, ipartial8+klfo8, iwave
a9 oscil imax9, ipartial9+klfo9, iwave
a10 oscil imax10, ipartial10+klfo10, iwave
a11 oscil imax11, ipartial11+klfo11, iwave
a12 oscil imax12, ipartial12+klfo12, iwave
a13 oscil imax13, ipartial13+klfo13, iwave
a14 oscil imax14, ipartial14+klfo14, iwave
a15 oscil imax15, ipartial15+klfo15, iwave
a16 oscil imax16, ipartial16+klfo16, iwave
a17 oscil imax17, ipartial17+klfo17, iwave
; jetzt die einzelnen Komponenten des Klangs, mit Hüllkurven zusammengesetzt:
afundamental = aenv1*a1
alowerpartials = aenv2*(a2+a3+a4+a5)

ahigherpartials = aenv3*(a6+a7+a8+a9+a10+a11)
ahighestpartials =  aenv4*(a12+a13+a14+a15+a16+a17) 
;; das Anschlagsgerauesch:knenv linsegr iamp, 0.05, iamp, 0.05,0, 0, 0
inoisemax table imidilaut, 87
knenv linsegr inoisemax, 0.02, inoisemax, 0.02, inoisemax, 0.05, 0, 0, 0
anoise rand knenv
inoisefilterfrequenz table imidilaut, 86
anoisefiltered butterbp anoise, inoisefilterfrequenz, 100
anoisebalanced balance anoisefiltered, anoise


asig = iamp*(afundamental+alowerpartials+ahigherpartials+ahighestpartials)
ipan = 127/imidinote
asiglinks = asig*ipan
asigrechts = asig*(1-ipan)
      outs      asiglinks, asigrechts
gahall = gahall+asig
      endin 
 
;;;;;;;;;;;;; HALLLLL, RAUMKLANG ;;;;;;;;;;;;
instr 102
iSRate = 44100
kHFDamp = 0.75
kRoomSize = 0.5
ahalllinks, ahallrechts freeverb gahall, gahall, kRoomSize, kHFDamp, iSRate
outs 0.3*ahalllinks, 0.3*ahallrechts
gahall = 0

endin
</CsInstruments>
<CsScore>
f0 600
f1 0 8192 10 1 ; sinus!!
f10 0 64 -2 6 1.625 261.63  60 1.00  \
1.08428194851 1.17566734386 1.2747548784 1.38219370342 1.49868768196 1.625 ; tuning-table
; die Filterfrequenz fuer das Anschlagsgerauesch
f86 0 128 -5 5000 128 10000
; der Lautstaerke-Faktor fuer das Anschlagsgerauesch
f 87 0 128 -7 0 128  1
; der Lautstaerke-Faktor fuer die Teiltoene 6-11 in Abhängigkeit von der Tonhöhe
f88 0 128 -7 1.2 36  1 12 1 24 1 24 0 32 0
; der Lautstaerke-Faktor fuer die hoechsten Teiltoene in Abhängigkeit von der Tonhöhe
f89 0 128 -7  2 36 1 24 1 23 0 45 0
; relative Lautstaerke der Teiltoene in Abhaengigkeit von der Key-Velocity:
f 90 0 128 -7 0.1  16 0.2 48 0.25 16 0.3 16 0.35 16 0.4 16 0.6 16 0.76
;f 90 0 128 -7 0.3  16 0.4 48 0.45 16 0.5 16 0.5 16 0.5 16 0.5 16 0.8
; Einschwingphase in der Abhaengigkeit von der Lautstaerke, fuer Teilton 1:
f 91 0 128 -5 2 60 2 15 1.25 5 .75 5 0.6 5 .45 38 .45 
; Einschwingphase in der Abhaengigkeit von der Lautstaerke, fuer Teiltoene 2-5:
f 92 0 128 -5 2.1 60 3 15 1.3 5 .78 5 0.63 5 .46 38 .45 
; Einschwingphase in der Abhaengigkeit von der Lautstaerke, fuer die hoeheren Teiltoene:
f 93 0 128 -5 2.2 60 3.4 15 2 5  1 5 0.75 5  .6 38 .45 
; Einschwingphase in der Abhaengigkeit von der Lautstaerke, fuer die hoechsten Teiltoene:
f 94 0 128 -5 2.2 60 3.8 15 2.5 5  1.5 5 1 5  0.9 38 .45 
	   ; ausschwingphasen, in Abhaengigkeit von der Lautstaerke:
;;fuer Fundamentton:
f 95 0 128 -5 0.5 60 .5 15 0.7 5 1 5 1.2 5 1.75 38 1.75
;;fuer tiefere Teiltoene:
f 96 0 128 -5 0.49 60 .49 15 0.65 5 0.9 5 1.1 5 1.6 38 1.5
;;fuer hoehere Teiltoene:
f 97 0 128 -5 0.4 60 .4 15 0.6 5 0.8 5 1 5 1.5 38 1.4
;;fuer hoechste Teiltoene:
f 98 0 128 -5 0.4 60 .4 15 0.7 5 1 5 1.2 5 2 38 2
; Einschwingphase in der Abhaengigkeit von der Tonhoehe, fuer alle Teiltoene:
f 100 0 128 -7 2 30 2 45 1.5 5 1 10 1 38 .25 
; ausschwingphase in der Abhaengigkeit von der Tonhoehe, fuer alle Teiltoene:
f 101 0 128 -7 1.5 50 1.5 25 1 15 1 38 .5
i100   0    600
i102   0    600

</CsScore>
</CsoundSynthesizer>
