;  #############################################################
;  orchestra file examples ex6-4-1, 6-4-2 and 6-4-3
; non-12 tone tuning examples
;  #############################################################

sr=44100
kr=2205
ksmps=20
nchnls=1


instr 1

icps  cps2pch  p4, p6
        ; convert pch to midi note number
        imidinote =  int((p4) - 3) * 12
        imidinote = int(imidinote + ((frac(p4) * (12/p6)) * 100))
; ------------------------------------------

  ; use function tables 99 & 98 to get closest multisample soundfile
ifno	table	imidinote, 99  ;keyboard mapping to gen1 function tables 
ibasno	table	ifno, 98        ; returns midi notes of the sonudfile samples
ibasoct	=	ibasno/12. + 3.
ibasepitch = cpsoct(ibasoct)
; ------------------------------------------
iendloop = 1 ; dummy end loop point for loscil
                       ; csound aborts without an end loop value, even
                       ; if no looping is specified

asig	loscil	1, icps , ifno, ibasepitch , 0, 0, iendloop
print icps, imidinote, ifno, ibasepitch
; ------------------------------------------
; AMPLITUDE SCALING and OPTIONAL NEW AMPLITUDE ENVELOPE
	iamp = p5
	irise = (p7 = 0? .0001 : p7)
	idec = (p8 = 0? .0001 : p8)
kamp expseg .005, irise, iamp, p3 - (irise + idec), iamp , idec, .005
asig = asig * kamp
; ------------------------------------------
out asig
endin
