Skip to content

truncarray

Shorten or extend an array.

Syntax

i/koutArr[] truncarray i/knArr[],i/klen [,iinc]
i/koutArr[] = truncarray(i/knArr[],i/klen [,iinc])

Usage

truncarray outputs a copy of an input array but either shorten or extends the values to match i/klen in length.

When the output array is shorter than the input array, then only the head of the array up to the 'i/klen index is returned.

If the output array is longer than the input array, then the values in the input array are repeated until i/klen is reached.

The optional argument iinc sums an increment to each element, which can produce interesting variations when extending.

--

Outputs and arguments

i/koutArr[] -- output array

i/kinArr[] -- input array

i/klen -- length of the output array

iinc -- an increment value to add to each output value.

Example

See the example for truncarray.orc

truncarray
gi_altfm ftgen 0, 0, 17, 2, 0, .2, .3, 0.8, 1.0, 0.8, 0.5, 0.2, 0, -0.3, -0.5, -0.8, -1.0, -0.9, -0.7, -0.3, 0 ;casio

instr Sound104
  ;sound source
  idur = p3
  iamp = p4
  ipit = p5
  iintensity = cosr(24)*3000
  ichannel = p8                               

  kamp linseg iamp, 0.3, iamp * 0.15, idur * 0.5, iamp*.15, idur * 0.3, iamp*0.7, idur*0.2, 0
  k1 linseg 0, idur-0.07, 1, 0.07, 0
  a1 oscili kamp*iintensity, ipit, gi_altfm, -1           
  ares oscili kamp, ipit+(a1*k1), gi_altfm, -1
  ares declickr ares
  send ares
endin

patchsig "Sound104", "outs"

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

icount counterChan "Schan",1,8,1 ;; create a counter.
ipattern[] = fillarray_i(-2,0,2,3,7,6,5,2) ;; set up a pitch sequence
isegment[] = truncarray(ipattern, icount, randint(-1,2)) ;; grow a segment of the pitch sequence using icount.

arpi fillarray_i(n("Sound104"),0,1/8,0.5,p5), isegment, fillarray_i(1/8),6 - 0.01
;;play the sequence.

}},1