<info>
ESM Csound Library example "tsamp3"
orc: tsamp   sco: tsamp3
Stereo out (p13)
"sets" used to select input soundfiles and transpositions; isorhythmic
rhythmic ostinato; tempo accelerates; timbale sounds become louder {p4}
and brighter {p17}

Allan Schindler  1/97

</info>
<tk_interface>


</tk_interface>
<mono>
    

</mono>
<stereo>
; p4 = transposition 
; p5  = amplitude (0 -1 ) integer 0 -127 = midi veloc or 1000 - 32000 raw value
; p6 = detuning (additional transposition, mostly for chorusing)
; p7 = input gen1 function # { if f99 & f98 not used}

instr 2

idur = p3
icps = 261.626  ; initial input pitch level for loscil
ibasepitch = 261.626  ; middle C reference input pitch for loscil
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 transposition {p4 & p6}
itransp init 1.  
idetune = p4 + p6  ; total pitch offset: transposition (p4) + detuning (p6)
if idetune = 0 goto gottransp ;skip all this if no transposition or detuning
       icount init 0  ; counter
       imult =  (idetune > 0 ? 1.05946 : .94387) ;1/2 step freqency ratios
        icheck = abs(idetune)
        icheck = int(icheck)

     dumbloop:
	      icount = icount + 1   ; increment counter
	      imult = (icheck = 0 ? 1 : imult)
	      itransp = itransp * imult 
     if icount < icheck igoto dumbloop
 ; microtonal transposition &/or detuning:
	imult = abs(idetune)
	imult = frac(imult)
	imult = imult * .05496
	imult = (idetune > 0 ? imult : - imult)
	itransp = itransp + imult
gottransp:
icps = icps * itransp
; ------------------------------------------
; get gen01 audio function number 
ifno = (p7 = 0 ? 1 : p7 )      ; input soundfile function number
; -----------------------------------------------------------
; 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:
 ; ==============================================================
       ; 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:
; mono in, stereo output : left-right output spatial placement
if p13 = -1 goto leftlow
if p13 = -2 goto  rightlow
if p13 = -3 goto  randrand
if p13 = -4 goto  randper
if p13 = -5 goto  done
a2 = (1. - p13) * a1
a1 = p13 * a1
goto done

leftlow: ;  p13 = -1 : lowest notes to LC, highest notes to RC 
        iplace = (p4 > 12. ? 12. : p4)
        iplace = (p4 < -12. ? -12. : p4)
        iplace = .5 + (iplace * .0416)
     a2 = iplace * a1
     a1 = (1. - iplace) * a1
goto  done

rightlow:  ; p13 = -2 : lowest notes to RC, highest notes to LC 
        iplace = (p4 > 12. ? 12. : p4)
        iplace = (p4 < -12. ? -12. : p4)
        iplace = .5 + (iplace * .0416)
     a2 = (1. - iplace) * a1
     a1 = iplace * a1
goto done

randrand:  ; p13 = -3 : random spatial placement with random moving pan : 
        iseed = frac(icps + iamp - idur) 
kplace  randi .25, 2. + (frac(iamp - icps + idur)) 
        kplace = kplace + .25 
        isign = (iseed > .5 ? -1 : 1 ) 
        kplace = (kplace * isign) + iseed 
     a2 = (1. - kplace) * a1
     a1 = kplace * a1
goto done

randper:   ; p13 = -4 : random spatial placement with periodic moving pan 
        iseed = frac(icps + iamp - idur) * .9
        iseed2 = ((1. - iseed) + .2) * .6
        ipancenter = (iseed * .5) + .25 
kspeed  linseg iseed*1.3,.2*idur, .8*iseed ,.3*idur,iseed2 , .35*idur ,.7*iseed ,.15*idur, .4*iseed2 
kspeed  linseg 1., .2 * idur , .4 , .3*idur , .9 , .35*idur , .4 , .15*idur, .3 
kplace  oscil .25, kspeed * 1.6 + (frac(icps - iamp)), 100,iseed 
        kplace = kplace + .25 
        isign = (iseed > .5 ? -1 : 1 ) 
        kplace = (kplace * isign) + ipancenter 
     a2 = (1. - kplace) * a1
     a1 = kplace * a1

done:
;Standard out statement
outs a1,a2
endin


</stereo>
<quad>


</quad>
<score>

f1 0 0 -1 "/sflib/perc/timb1" 0 0 0
f2 0 0 -1 "/sflib/perc/timb2" 0 0 0
f3 0 0 -1 "/sflib/perc/timb1.rim" 0 0 0
f4 0 0 -1 "/sflib/perc/timb2.rim" 0 0 0
f99 0 128 -17 0 1 51 2 
f98 0 8 -2 0 50 53
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 
  i2 0.000 2.000 -13 15000 0 3 0 0 0 0 0 0.920 0 0 0 1.600 0 180 0
  i2 0.505 0.416 4 1618 0 2 0 0 0 0 0 0.106 0 0 0 0.246 0 180 0
  i2 0.745 0.412 5 1153 0 1 0 0 0 0 0 0.319 0 0 0 0.483 0 180 0
  i2 1.476 0.580 -6 2521 0 2 0 0 0 0 0 0.378 0 0 0 0.305 0 180 0
  i2 1.649 0.456 5 3155 0 1 0 0 0 0 0 0.243 0 0 0 0.165 0 180 0
  i2 1.819 0.589 -4 1933 0 2 0 0 0 0 0 0.887 0 0 0 0.196 0 180 0
 ci2 1.966 0.492 0 2908 0 1 0 0 0 0 0 0.019 0 0 0 0.520 0 180 0 <rest>
  i2 2.449 0.590 -1 1379 0 2 0 0 0 0 0 0.806 0 0 0 0.419 0 180 0
  i2 2.559 0.517 -6 2885 0 1 0 0 0 0 0 0.339 0 0 0 0.139 0 180 0
  i2 2.639 0.562 0 1889 0 2 0 0 0 0 0 0.885 0 0 0 0.343 0 180 0
  i2 2.749 0.550 4 2450 0 1 0 0 0 0 0 0.955 0 0 0 0.582 0 180 0
  i2 2.845 0.584 5 3715 0 2 0 0 0 0 0 0.111 0 0 0 0.149 0 180 0
  i2 2.933 0.552 -1 1615 0 1 0 0 0 0 0 0.471 0 0 0 0.318 0 180 0
  i2 3.398 0.671 -4 2335 0 2 0 0 0 0 0 0.788 0 0 0 0.373 0 180 0
  i2 3.869 0.710 0 2560 0 2 0 0 0 0 0 0.282 0 0 0 0.190 0 180 0
  i2 4.105 0.732 5 2780 0 2 0 0 0 0 0 0.701 0 0 0 0.477 0 180 0
  i2 4.792 0.737 -1 1781 0 2 0 0 0 0 0 0.596 0 0 0 0.255 0 180 0
  i2 4.932 0.779 -4 4121 0 2 0 0 0 0 0 0.435 0 0 0 0.615 0 180 0
  i2 5.092 0.763 -6 2970 0 2 0 0 0 0 0 0.919 0 0 0 0.523 0 180 0
 ci2 5.228 0.763 -1 4251 0 2 0 0 0 0 0 0.923 0 0 0 0.420 0 180 0 <rest>
  i2 5.682 0.807 4 2339 0 2 0 0 0 0 0 0.189 0 0 0 0.357 0 180 0
  i2 5.783 0.826 5 2835 0 2 0 0 0 0 0 0.616 0 0 0 0.479 0 180 0
  i2 5.862 0.829 -4 4563 0 2 0 0 0 0 0 0.340 0 0 0 0.658 0 180 0
  i2 5.951 0.832 5 3360 0 2 0 0 0 0 0 0.848 0 0 0 0.479 0 180 0
  i2 6.026 0.855 4 2930 0 2 0 0 0 0 0 0.037 0 0 0 0.592 0 180 0
  i2 6.099 0.862 5 4364 0 2 0 0 0 0 0 0.507 0 0 0 0.488 0 180 0
  i2 6.540 0.892 4 2817 0 2 0 0 0 0 0 0.128 0 0 0 0.493 0 180 0
  i2 6.956 1.016 0 2344 0 1 0 0 0 0 0 0.488 0 0 0 0.583 0 180 0
  i2 7.174 1.026 -6 4312 0 1 0 0 0 0 0 0.530 0 0 0 0.366 0 180 0
  i2 7.803 1.056 -1 3557 0 1 0 0 0 0 0 0.131 0 0 0 0.608 0 180 0
  i2 7.950 1.063 -6 4304 0 1 0 0 0 0 0 0.150 0 0 0 0.385 0 180 0
  i2 8.084 1.069 0 4408 0 1 0 0 0 0 0 0.387 0 0 0 0.770 0 180 0
 ci2 8.229 1.076 4 2802 0 1 0 0 0 0 0 0.480 0 0 0 0.648 0 180 0 <rest>
  i2 8.621 1.096 0 4761 0 1 0 0 0 0 0 0.990 0 0 0 0.447 0 180 0
  i2 8.710 1.100 -6 6524 0 1 0 0 0 0 0 0.368 0 0 0 0.602 0 180 0
  i2 8.787 1.104 5 3930 0 1 0 0 0 0 0 0.516 0 0 0 0.607 0 180 0
  i2 8.851 1.108 4 3789 0 1 0 0 0 0 0 0.821 0 0 0 0.389 0 180 0
  i2 8.926 1.112 5 5670 0 1 0 0 0 0 0 0.670 0 0 0 0.452 0 180 0
  i2 9.003 1.116 4 5448 0 1 0 0 0 0 0 0.431 0 0 0 0.727 0 180 0
  i2 9.380 1.136 0 3383 0 2 0 0 0 0 0 0.447 0 0 0 0.694 0 180 0
  i2  9.760 1.156 -4 4105 0 2 0 0 0 0 0 0.269 0 0 0 0.411 0 180 0
  i2  9.934 1.166 0 5935 0 2 0 0 0 0 0 0.080 0 0 0 0.716 0 180 0
  i2 10.474 1.196 -6 6914 0 2 0 0 0 0 0 0.736 0 0 0 0.673 0 180 0
  i2 10.587 1.203 -4 7811 0 2 0 0 0 0 0 0.156 0 0 0 0.451 0 180 0
  i2 10.713 1.209 -6 6509 0 2 0 0 0 0 0 0.177 0 0 0 0.922 0 180 0
 ci2 10.842 1.216 -1 4470 0 2 0 0 0 0 0 0.676 0 0 0 0.472 0 180 0 <rest>
  i2 11.182 1.236 -4 7389 0 2 0 0 0 0 0 0.552 0 0 0 0.580 0 180 0
  i2 11.263 1.240 -1 8327 0 2 0 0 0 0 0 0.661 0 0 0 0.830 0 180 0
  i2 11.330 1.244 4 5015 0 2 0 0 0 0 0 0.881 0 0 0 0.847 0 180 0
  i2 11.391 1.248 -6 6991 0 2 0 0 0 0 0 0.109 0 0 0 0.867 0 180 0
  i2 11.463 1.252 -1 7729 0 2 0 0 0 0 0 0.184 0 0 0 0.495 0 180 0
  i2 11.526 1.256 -4 8231 0 2 0 0 0 0 0 0.261 0 0 0 0.608 0 180 0
  i2 11.866 1.276 -3 8252 0 2 0 0 0 0 0 0.540 0 0 0 0.553 0 180 0
  i2 12.273 1.296 -14 9895 0 4 0 0 0 0 0 0.332 0 0 0 1.035 0 180 0
  i2 12.472 1.306 1 8372 0 1 0 0 0 0 0 0.986 0 0 0 0.671 0 180 0
  i2 13.068 1.336 7 7887 0 4 0 0 0 0 0 0.909 0 0 0 0.713 0 180 0
  i2 13.207 1.343 -10 6982 0 1 0 0 0 0 0 0.468 0 0 0 1.019 0 180 0
  i2 13.321 1.349 1 9709 0 2 0 0 0 0 0 0.031 0 0 0 0.889 0 180 0
 ci2 13.434 1.356 4 7454 0 1 0 0 0 0 0 0.946 0 0 0 0.894 0 180 0 <rest>
  i2 13.813 1.376 -12 8157 0 3 0 0 0 0 0 0.639 0 0 0 0.976 0 180 0
  i2 13.899 1.380 4 10528 0 1 0 0 0 0 0 0.458 0 0 0 1.003 0 180 0
  i2 13.974 1.384 -7 10478 0 2 0 0 0 0 0 0.771 0 0 0 0.919 0 180 0
  i2 14.047 1.388 -14 11500 0 3 0 0 0 0 0 0.966 0 0 0 0.641 0 180 0
  i2 14.123 1.392 -7 9129 0 4 0 0 0 0 0 0.430 0 0 0 0.748 0 180 0
  i2 14.207 1.396 -3 10801 0 2 0 0 0 0 0 0.965 0 0 0 1.181 0 180 0
  i2 14.561 1.400 -12 12378 0 1 0 0 0 0 0 0.904 0 0 0 0.910 0 180 0
  i2 14.911 1.400 3 9699 0 3 0 0 0 0 0 0.804 0 0 0 1.144 0 180 0
  i2 15.070 1.400 -6 10842 0 4 0 0 0 0 0 0.387 0 0 0 0.988 0 180 0
  i2 15.539 1.400 -1 13081 0 1 0 0 0 0 0 0.509 0 0 0 1.415 0 180 0
  i2 15.640 1.400 -6 12783 0 3 0 0 0 0 0 0.672 0 0 0 1.096 0 180 0
  i2 15.749 1.400 -10 11483 0 2 0 0 0 0 0 0.976 0 0 0 1.132 0 180 0
 ci2 15.857 1.400 -3 12315 0 4 0 0 0 0 0 0.511 0 0 0 0.965 0 180 0 <rest>
  i2 16.134 1.400 -14 14446 0 3 0 0 0 0 0 0.055 0 0 0 1.344 0 180 0
  i2 16.190 1.400 -9 12727 0 4 0 0 0 0 0 0.321 0 0 0 1.546 0 180 0
  i2 16.256 1.400 -4 15378 0 2 0 0 0 0 0 0.377 0 0 0 0.925 0 180 0
  i2 16.303 1.400 1 13944 0 1 0 0 0 0 0 0.590 0 0 0 1.355 0 180 0
  i2 16.354 1.400 -9 14203 0 3 0 0 0 0 0 0.347 0 0 0 1.452 0 180 0
  i2 16.400 1.400 -3 15711 0 2 0 0 0 0 0 0.017 0 0 0 1.136 0 180 0
  i2 16.665 1.400 6 15810 0 3 0 0 0 0 0 0.945 0 0 0 1.018 0 180 0
  i2 16.948 1.400 3 16510 0 1 0 0 0 0 0 0.561 0 0 0 1.610 0 180 0
  i2 17.119 1.400 -4 16934 0 3 0 0 0 0 0 0.211 0 0 0 1.533 0 180 0
  i2 17.662 1.400 -6 18255 0 4 0 0 0 0 0 0.263 0 0 0 1.431 0 180 0
  i2 17.809 1.400 6 18183 0 2 0 0 0 0 0 0.104 0 0 0 1.715 0 180 0
  i2 17.945 1.400 -6 19105 0 1 0 0 0 0 0 0.103 0 0 0 1.764 0 180 0
 ci2 18.096 1.400 -9 19388 0 3 0 0 0 0 0 0.626 0 0 0 1.510 0 180 0 <rest>
  i2 18.557 1.400 4 20779 0 2 0 0 0 0 0 0.081 0 0 0 1.518 0 180 0
  i2 18.649 1.400 -4 20785 0 4 0 0 0 0 0 0.795 0 0 0 1.612 0 180 0
  i2 18.744 1.400 -1 20948 0 1 0 0 0 0 0 0.196 0 0 0 1.770 0 180 0
  i2 18.856 1.400 3 21431 0 3 0 0 0 0 0 0.808 0 0 0 1.859 0 180 0
  i2 18.957 1.400 -10 21467 0 2 0 0 0 0 0 0.865 0 0 0 1.656 0 180 0
  i2 19.069 1.400 -1 21813 0 4 0 0 0 0 0 0.681 0 0 0 1.502 0 180 0
e
</score>


