<info>
i is ex3-6
ECMC Csound Tutorial example ex3-6
</info>
<tk_interface>
</tk_interface>
<mono>
; ex3-6:
 ; p4 : gen1 function number
 ; p5 : amplitude  {.001 - 10. = multiplier ; 10.1 - 32767 = new raw amplitude}
 ; p6 = length of input soundfile, in seconds or samples
 ; p7 : skip time (if positive) OR (if negative, between -.001 & -.99) index
        ; into gen1 func
 ; p8 : OPTIONAL end time (if positive) OR (if negative, between -.001 & -.99) index
 ; p9 : pitch multiplier
 ; p10  flag: if -1, soundfile read backwards from p8 to p7
 ; p11 : stereo pan location {for stereo only}

instr 1
   ;  init values : --------------
; p9 specifies pitch transposition ratio of output to input pitch levels
itransp	 = (p9 = 0 ? 1. : p9 )
ilength = (p6 < 400 ? p6 * sr : p6)
iamp    =  (p5 = 0 ? 1. : p5) ; amplitude multiplier; 0 = no attenuation or boost

   isound   = p4  ; number of gen1 function table of source soundfile
   iphspeed  = sr/ilength  ; phasor speed to read soundfile at original pitch
   isfdur   = ilength/sr ; duration in seconds of input soundfile

 ; if p7 is negative, between -.001 and -1., it indicates % of soundfile skipped
 ; if positive, it indicates skip time in seconds
istart = (p7 < 0 ? abs(p7) *isfdur : p7) ; time in seconds to begin
                ; reading in samples from the input soundfile
index    =  (p7 < 0 ? abs(p7) : p7/isfdur)  ; beginning index into gen 1 table
iend = (p8 = 0 ? isfdur : p8)
iend = (iend < 0 ? abs(p8) * isfdur : iend)

ioutdur = (iend - istart) / itransp ; compute actual output duration
p3 = ioutdur ; change score p3 value to computed output duration for note
print istart, iend, itransp, ioutdur

if p10 = -1 goto backwards
 ; read soundfile forwards:
     apointer  phasor   iphspeed*itransp   ;transpose pitch by p9
     asound  tablei   (index + apointer)*ilength, isound  ;read the table at current phasor index 
          goto gotsound
 backwards:  ; read soundfile backwards beginning at p7 time
        ibacklength = p3 * itransp * sr
        ibackspeed = sr/ibacklength
        apointer  phasor  ibackspeed * itransp
        apointer = 1. - apointer
        iratio = ( ibacklength/ilength)
        apointer = apointer * iratio
        asound   tablei  (index + apointer) *ilength, isound 

gotsound:
; mono out:
out iamp * asound
; stereo out
;    outs sqrt(p11) * asound, sqrt(1. - p11) * asound
endin

</mono>
<stereo>
</stereo>
<score>

                  SCORE-11, Version 1.4
Copyright (C) 1982, 1990, 1992, 1995 by Alexander R. Brinkman
     Eastman School of Music, University of Rochester

f1 0 524288 -1 "/sflib/x/voicetest" 0 0 0 
  i1 0.000 1.000 1 0.150 7.297 0 0.885 1 0
  i1 2.000 1.000 1 0.400 320574 0.885 1.535 0.900 -1
  i1 4.000 1.000 1 0.650 7.297 1.535 2.460 1.122 0
  i1 6.000 1.000 1 0.900 320574 2.460 6.480 0.840 -1
e
</score>
