<info>
ESM Csound Library
orc: samp   sco: samp1
Mono output.
2 clusters: (1) a quarter-tone cluster centered on g3,with
diminuendo, and (2) a 1/6 tone cluster centered on cs5, with
crescendo & increasing brightness
Allan Schindler  1/97
</info>
<tk_interface>


</tk_interface>
<mono>
    
; p5  = amplitude (0 -1 ) integer 0 -127 = midi veloc or 1000 - 32000 raw value
; p4 = pitch :  0 - 13. = pch  |  14 - 127 = midi note | negative = herz
; p6 = detuning
; p7 = input gen1 function # { if f99 & f98 not used}
; p8 = input pitch  { if f99 & f98 not used}

instr 1

idur = p3
ibasepitch init 0
p12 = (p12 = 0 ? 2 : p12 ) ; dummy end loop point for loscil
                           ; csound aborts without an end loop value, even
                           ; if no looping is specified
;========get pitch & midi note number
if p4 > 13.0 igoto midinote
if p4  < 0  igoto herz
     ; p4 is in pch
     icps = cpspch(p4)
        ; convert pch to midi note number
        imnum =  int((p4) - 3) * 12
        imnum =  imnum + (frac(p4) * 100)
;            ioct = octcps(icps) ; DELETE -- NOT NEEDED HERE
     igoto gotnote
midinote: 
     ; p4 gives midi note number
     imnum = p4
        ; convert midi note num to cps
        ioct = (p4/12) + 3.  ; returns oct decimal
        icps  =  cpsoct(ioct)
     igoto gotnote
herz: ; p4 is negative, so it is in herz
     icps = abs(p4)
     ioct = octcps(icps) 
     ipch = pchoct(ioct) 
        ; convert pch to midi note number
     imnum =  int((ipch) - 3) * 12
     imnum =  imnum + (frac(ipch) * 100)
gotnote:

; ------------------------------------------
; get gen01 audio function number & base pitch of soundfile
if p7 = 0 igoto tables
    ifno = p7      ; input soundfile function number
   ; if gen1 func specified in p7, p8 = input pitch : pch, MIDI note or herz
     if p8 > 13.0 igoto inmidinote
     if p8  < 0  igoto inherz
          ; p8 is in pch
          ibasepitch = cpspch(p8)
          igoto gotinpitch
     inmidinote: if p8 < 0  igoto inherz
          ; p8 gives midi note number : convert this to cps
             inoct = (p8/12) + 3.  ; returns oct decimal
             ibasepitch  =  cpsoct(inoct)
          igoto gotinpitch
     inherz: ; p8 is negative, so it is in herz
          ibasepitch = abs(p8)
          igoto gotinpitch

tables:  ; use func tables 99 & 98 to get source soundfile
ifno	table	imnum, 99	;keyboard mapping to gen1 ftables 
ibasno	table	ifno, 98        ; returns midi notes of the sonudfile samples
ibasoct	=	ibasno/12. + 3.
ibasepitch = cpsoct(ibasoct)
gotinpitch:
; ------------------------------------------
        ;  --- Detuning  module (mostly for use with "chorus" ) ---
   idetunepf = p6
if idetunepf = 0 goto gotdetune ;skip all this if detuning set to 0 in score
       idtcount init 0  ; counter
       idtmult =  (idetunepf > 0 ? 1.05946 : .94387) ;1/2 step freqency ratios
   idetune init 1.  ; detuning multiplier for p4 pitch
        icheck = abs(idetunepf)
        icheck = int(icheck)

  dumbloop:
	      idtcount = idtcount + 1   ; increment counter
	      idtmult = (icheck = 0 ? 1 : idtmult)
   idetune = idetune * idtmult 
   if idtcount < icheck igoto dumbloop
 ; microtonal detuning:
	idtmult = abs(idetunepf)
	idtmult = frac(idtmult)
	idtmult = idtmult * .05496
	idtmult = (idetunepf > 0 ? idtmult : - idtmult)
   idetune = idetune + idtmult
icps = icps * idetune 
gotdetune:   ; ---end of detuning module -------
; -----------------------------------------------------------
; optional TURN OFF INSTRUMENT when p9 time reached {only a portion of the
; input soundfile, specified in p9,  is used}
if p9 = 0 goto playon
        istoptime = p9   ; 
;	inotedur = ( p3 < istoptime ? p3 : istoptime)
;	inoteoff = inotedur + p2
        itransp = ibasepitch/icps
	istoptime = istoptime * itransp 
	istoptime = istoptime - .005
	inotedur = ( p3 < istoptime ? p3 : istoptime)
        idur = inotedur
	inoteoff = inotedur + p2

        print p2, p4, inotedur, inoteoff  ; print note start time, dur & end time for user
	timout istoptime , p3 , shutdown
	goto playon
		shutdown: 
		turnoff
		kgoto output
playon:
 ; ==============================================================
; insert for lpcpitch, xsynpitch, gxsynpitch:
kpitch init icps
 ; ==============================================================
       ; Determine "peak" amplitude:
	iamp init 0
	iamp = (p5  < 10.1 ? p5  : iamp) ; p5  = multiplier for original soundfile amp.
	iamp = (p5  > 10.1 ? p5/32767 : iamp) ; p5  gives new raw amplitude
	iamp = (iamp = 0 ? 1. : iamp)
a1	loscil	iamp, icps , ifno, ibasepitch , p10, p11, p12
 ; ==============================================================
; FADE OUT and OPTIONAL NEW AMPLITUDE ENVELOPE
	irise = (p14 = 0? .0001 : p14)
	irise = (p14 < 100 ? irise : (p14 - 100)  * idur)
	irise = (p14 < 0 ? abs(p14)  * idur : irise)
	iatss = (p16 = 0  ? 1 : p16)
	idec = (p15 = 0? .0001 : p15)
	idec = (p15 < 100 ? idec : (p15 - 100)  * idur)
	idec = (p15 < 0 ? abs(p15)  * idur : idec)

        idec = (idec > .04 ? idec : .04) ; default decay of .04 to avoid clicks
                               ; if p3 is less than duration of input soundfile
	amp expseg .005, irise, 1., idur - (irise + idec), iatss , idec, .005
        a1 = a1 * amp
; ------------------------------------------
; OPTIONAL BRIGHTNESS -- use with new envelope for cresc & dim.
bright:  ibrightest = p17 + p18
if ibrightest = 0 goto output
kbright init p17
if p18 = 0 goto brightscale
   ip19 = (p19 > 100 ? ((p19 - 100) * idur) - .1 : p19)
   ip19 = (p19 < 0 ? (abs(p19) * idur) - .1 : p19)
   ip19 = (ip19 = 0 ? (.9*idur) - idec : ip19)

   ip20 init icps
if p20 = 0 igoto gotcf
   ip20 = (p20 < 13.1 ? cpspch(p20) : p20 )
gotcf:
   kbright expseg p17, .1,p17,ip19, p18, idur, p18
brightscale:
      ihp = icps*1.5
        iscale = octcps(ihp)
        iscale = (18.25 - iscale) * .1
        iscale = (iscale < 1. ? iscale : iscale * iscale )
      ihp = ihp * iscale
   ahi atone .9*a1, ihp
   alo tone  .9*a1, ihp
   a1 balance (kbright*ahi) + ((2. - kbright)* alo), a1
 ; --------------------------------------------------------
output:
;Standard out statement
out a1
endin
</mono>
<stereo>

</stereo>
<quad>


</quad>
<score>

f1 0 0 -1 "/sflib/voice/alto1.g3" 0 0 0 
f2 0 0 -1 "/sflib/voice/sop1.cs5" 0 0 0 
f100 0 1024 10 1.
f50 0 65 7 0 64 1.
f52 0 65 7 0 32 1. 32 0
f60 0 65 5 .01 64 1.
f57 0 64 7 0 31 0 1 1. 31 1. 1 0 
f58 0 64 7 0 21 0 1 1. 20 1. 1 -1 20 -1 1 0 
  i1 0.000 6.000 7.07 0.150 0 1 7.07 0 0 0 0 0 0.001 1.986 0.064 1.811 0.046 100.857 0
  i1 0.005 6.000 7.07 0.150 0.500 1 7.07 0 0 0 0 0 0.003 2.011 0.055 1.935 0.043 100.836 0
  i1 0.010 6.000 7.07 0.150 -0.500 1 7.07 0 0 0 0 0 0.009 1.925 0.051 1.823 0.044 100.809 0
  i1 0.012 6.000 7.07 0.150 1.000 1 7.07 0 0 0 0 0 0.010 1.939 0.063 1.901 0.036 100.862 0
  i1 0.017 6.000 7.07 0.150 -1 1 7.07 0 0 0 0 0 0.004 1.928 0.069 1.816 0.042 100.859 0
  i1 0.018 6.000 7.07 0.150 1.500 1 7.07 0 0 0 0 0 0.001 1.969 0.067 1.810 0.044 100.862 0
  i1 0.031 6.000 7.07 0.150 -1.500 1 7.07 0 0 0 0 0 0.009 1.935 0.054 1.826 0.046 100.834 0
  i1 0.034 6.000 7.07 0.150 2.000 1 7.07 0 0 0 0 0 0.007 1.903 0.068 1.809 0.049 100.836 0
  i1 0.036 6.000 7.07 0.150 -2 1 7.07 0 0 0 0 0 0.003 1.945 0.066 1.852 0.036 100.831 0
  i1 0.042 5.000 9.01 0.050 0 2 9.01 0 0 0 0 0 0.007 1.939 0.066 1.898 0.049 100.882 0
  i1 5.035 5.000 9.01 0.050 -0.330 2 9.01 0 0 0 0 0 2.034 0.068 4.044 0.032 1.820 100.925 0
  i1 5.045 5.000 9.01 0.050 0.330 2 9.01 0 0 0 0 0 1.933 0.086 3.999 0.025 1.947 100.902 0
  i1 5.053 5.000 9.01 0.050  -0.670 2 9.01 0 0 0 0 0 2.095 0.071 4.090 0.049 1.837 100.947 0
  i1 5.055 5.000 9.01 0.050 0.670 2 9.01 0 0 0 0 0 1.919 0.063 3.910 0.030 1.878 100.946 0
  i1 5.066 5.000 9.01 0.050 -1.000 2 9.01 0 0 0 0 0 1.956 0.073 4.008 0.035 1.908 100.931 0
  i1 5.077 5.000 9.01 0.050 1.000 2 9.01 0 0 0 0 0 1.991 0.084 3.979 0.046 1.952 100.931 0
  i1 5.086 5.000 9.01 0.050 -1.330 2 9.01 0 0 0 0 0 1.999 0.076 3.990 0.046 1.852 100.927 0
  i1 5.093 5.000 9.01 0.050 1.330 2 9.01 0 0 0 0 0 1.958 0.062 4.015 0.045 1.811 100.903 0
  i1 5.094 5.000 9.01 0.050 -1.670 2 9.01 0 0 0 0 0 2.033 0.080 4.032 0.026 1.850 100.934 0
  i1 5.101 5.000 9.01 0.050 1.670 2 9.01 0 0 0 0 0 2.011 0.083 4.018 0.027 1.813 100.909 0
  i1 5.104 5.000 9.01 0.050 -2.000 2 9.01 0 0 0 0 0 2.057 0.084 3.950 0.031 1.900 100.905 0
  i1 5.111 5.000 9.01 0.050 2 2 9.01 0 0 0 0 0 1.962 0.063 3.989 0.048 1.955 100.903 0
e
</score>

