User-Defined Opcode Database

LpPhsr

creates a time pointer for loops

Download UDO File

Description

creates a time pointer signal for typical loop applications, for instance in the mincer opcode, with optional backward playing

Syntax

atimpt LpPhsr kloopstart, kloopend, kspeed, kdir, irefdur

Initialization

irefdur - the overall duration. must be in the same scale as kloopstart and kloopend (e.g. seconds)

Performance

kloopstart - starting point of the loop (in the scale of irefdur)
kloopend - end point of the loop (in the scale of irefdur)
kspeed - 1 = normal speed, 0.5 = half speed, etc.
kdir - 1 = forward, -1 = backward

Code

  opcode LpPhsr, a, kkki
kloopstart, kloopend, kdir, irefdur xin
kstart01   =            kloopstart/irefdur ;start in 0-1 range
kend01	   =	        kloopend/irefdur ;end in 0-1 range
ifqbas	   =	        1 / irefdur ;phasor frequency for the whole irefdur range
kfqrel	   =            ifqbas / (kend01-kstart01) * kspeed ;phasor frequency for the selected section
andxrel    phasor       kfqrel*kdir ;phasor 0-1
atimpt     =	        andxrel * (kloopend-kloopstart) + kloopstart ;adjusted to start and end
           xout         atimpt
  endop

Examples

<CsoundSynthesizer>
<CsOptions>
-odac
</CsOptions>
<CsInstruments>
sr = 44100
ksmps = 32
nchnls = 1
0dbfs = 1

gSnd       =         "fox.wav" ;example in the csound manual
giftsnd    ftgen     0, 0, 0, 1, gSnd, 0, 0, 1
           seed      0

  opcode LpPhsr, a, kkkki
;creates a phasor for a typical time pointer signal (e.g. for the mincer opcode)

 ;kloopstart, kloopend, irefdur must be in the same scale (e.g. seconds)
 ;kspeed = 1 means normal speed
 ;kdir = 1 means forward, kdir = -1 means backward
kloopstart, kloopend, kspeed, kdir, irefdur xin

kstart01   =          kloopstart/irefdur ;start in 0-1 range
kend01     =	        kloopend/irefdur ;end in 0-1 range
ifqbas     =	        1 / irefdur ;phasor frequency for the whole irefdur range
kfqrel     =          ifqbas / (kend01-kstart01) * kspeed ;phasor frequency for the selected section
andxrel    phasor     kfqrel*kdir ;phasor 0-1 
atimpt     =	        andxrel * (kloopend-kloopstart) + kloopstart ;adjusted to start and end

           xout       atimpt
  
  endop
  
  
  instr 1 ;simple test instrument
kloopstart =          p4
kloopend   =          p5
kspeed     =          p6
kdir       =          p7
isndlen    filelen    gSnd
atimpt     LpPhsr     kloopstart, kloopend, kspeed, kdir, isndlen
asnd       mincer     atimpt, 1, 1, giftsnd, 1
           out        asnd
  endin

  instr 2 ;random choices
kloopstart randomi     0, 1, .5
kloopend   randomi     1, 2.5, .5
kspeed     randomi     0.5, 1.5, .5
kback      randomh     -1, 1, .3
kdir       =           (kback < 0 ? -1 : 1)

isndlen    filelen      gSnd
atimpt     LpPhsr       kloopstart, kloopend, kspeed, kdir, isndlen
asnd       mincer       atimpt, 1, 1, giftsnd, 1
           out          asnd
  endin


</CsInstruments>
<CsScore>
;          lstrt lend speed backw
i 1 0 4.5  .5    1.5  1     1
i 1 5 4.5  .5    1.5  1    -1
i 1 10 4.5 .5    1.5  .5    1
i 2 15 30
</CsScore>
</CsoundSynthesizer>

Credits

joachim heintz 2011


Previous Home Next
Y_x4p_k   GaussTrig