Skip to content

rotatearray

Permute an array.

Syntax

i/koutArr[] rotatearray i/kinArr[], ishift
koutArr[] rotatearray kinArr[],Sid,iincr
i/koutArr[] = rotatearray(i/kinArr[], ishift)
koutArr[] = rotatearray(kinArr[],Sid,iincr)

Usage

rotatearray shifts values in an array by the number of spaces in ishift. A positive ishift moves values to the right, negative values shift left. Values on the end wrap around. A variant of rotatearray shifts values on every call. A string Sid channel is used to save the state of the rotation.


Outputs and arguments

i/koutArr[] -- output array

i/kinArr[] -- input array

ishift -- number of places to move array values.

Sid -- String channel name to store state. Can be anything, but ideally is unique.

Example

See the example for patchspread.orc

rotatearray
instr clap
  ;; Sound source, like a hand clap.
  iamp = p4
  iignored = p5
  ipan = p6
  ifrq = random(1070, 870)
  iatt = 0.0021
  idec = 0.045
  ibw = 1255
  asigt1 bexprnd iamp * 4.0   
  asigt2 bexprnd iamp * 4.0   
  asigt3 bexprnd iamp * 4.0   
  asigt4 bexprnd iamp * 4.0   
  asigt5 bexprnd iamp * 4.0
  asigc1 mode asigt1, 4813, 8
  asigc2 mode asigt2, 1677, 9
  asigc3 mode asigt3, 1327, 29
  asigc4 mode asigt4, 1051, 5
  asigc5 mode asigt5, 733, 6

  asig = asigc1+asigc2+asigc3+asigc4+asigc5

  asig1 butbp asig, ifrq, ibw
  asig1 butbp asig1, ifrq, ibw    
  asig2 butbp asig, ifrq*3.5, ibw * 0.9
  asig2 butbp asig2, ifrq*2.3, ibw * 0.8    
  ares ntrpol asig1, asig2, 0.55   
  aenv transeg 0.0,  iatt, -19, 1.0,  idec, -4.5, 0.0, 0.1, 1, 0.0
  ares = ares * aenv
  aresL = ares*ipan
  aresR = ares*(1-ipan)
  send aresL, aresR
endin

loopcode fillarray(12*0.125 * 4), "codeloop",{{

ipattern[] = fillarray_i(1,1,1,-1,1,1,-1,1,-1,1,1,-1)
irotate counterChan "count1"

loopevent fillarray_i(n("clap"),0,0.1,0.1,0,0), fillarray_i(0), ipattern*0.125,1
loopevent fillarray_i(n("clap")+0.1,0,0.1,0.1,0,1), fillarray_i(0), rotatearray(ipattern*0.125, irotate), 1

}},1
;; Clapping Music, Steve Reich, 1972

EffectConstruct "Rvb", {{
ainL = ains[0]
ainR = ains[1]

aout1, aout2 freeverb ainL, ainR, 0.5, 0.6

aouts[] fillarray aout1, aout2
}},2,2,1
;; stereo reverb

patchspread "clap",fillarray("Rvb","outs")
;; split the signal between reverb and direct out

patchsig "Rvb", "outs",0.7
;; and connect the reverb to the output, reducing the level a bit.