User-Defined Opcode Database

stereoGrain

Granular synthesis similar to granule but in stereo with control rate parameters and unlimited transpositions.

Download UDO File

Description

Granular synthesis similar to granule but in stereo with control rate parameters and unlimited transpositions. Uses rnd31 with control of random distribution for frequency, pan, and amplitude.
GEN01 function tables with zero size are ok.

Syntax

al, ar stereoGrain kamp, kampoff, kgrain, kgrainoff, kgap, kgapoff, kmaxskip, kcenterpan, kampr, kfreqr, kpanr, katt, kdec, kpoint, knumfreq, ifreqfn, ifn, idens

Initialization

ifreqfn -- function table with frequencies. for granulating samples, 1=no change, 2=one octave up, etc.
ifn -- function table to be granulated. can be GEN01 with zero size.
idens -- number of voices/simultaneous grains.

Performance

kamp -- amplitude
kgrain -- grain size in seconds
kgap -- gap size in seconds
kampoff/kgrainoff/kgapoff -- random offset, generally a value from 0-1, one being the largest offset.
kmaxskip -- maximum skip time from the grain pointer in seconds.
kcenterpan -- values from -1 (left) to 1 (right). random pan centers around this value.
kampr, kfreqr, kpanr -- random distribution for amplitude, frequency, and pan -- see rnd31
katt, kdec -- attack and decay of grain in relation to grain size; i.e. katt=.1 means the attack is .1 * kgrain. katt+kdec should not exceed 1.
kpoint -- the grain pointer. similar to the pointer in fog, except that it refers to the samples in the function table and should be scaled to reflect this (so, a pointer that reads from the beginning to the end of a one-second sample with a 44100 sr should output values from 0-44100). see linearPointer and boomerangPointer for examples of udo pointers.
knumfreq -- the number of frequencies to be read from ifreqfn

Code

	opcode stereoGrain, aa, kkkkkkkkkkkkkkkiiip
kamp, kampoff, kgrain, kgrainoff, kgap, kgapoff, kmaxskip, kcenterpan, kampr, kfreqr, kpanr, katt, kdec, kpoint, knumfreq, ifreqfn, ifn, idens, icount xin

ainl init 0
ainr init 0

if (icount > idens) goto out

loop:
ainl, ainr stereoGrain kamp, kampoff, kgrain, kgrainoff, kgap, kgapoff, kmaxskip, kcenterpan, kampr, kfreqr, kpanr, katt, kdec, kpoint, knumfreq, ifreqfn, ifn, idens, icount + 1

out:
isamps = ftlen(ifn)
kdec limit kdec, .05, 1-katt
katt limit katt, .05, 1-kdec
kgrainmin = kgrain - kgrain * kgrainoff
kgrainmax = kgrain + kgrain * kgrainoff
kgapmin = kgap - kgap * kgapoff
kgapmax = kgap + kgap * kgapoff

redo:
ipan rnd31 1, i(kpanr)
ipan limit ipan + i(kcenterpan), -1, 1
ifreq rnd31 1, i(kfreqr)
ifreq = abs(ifreq * (i(knumfreq)-.001))
ifreq table ifreq, ifreqfn

iamp rnd31 i(kamp) * i(kampoff), i(kampr)
iamp = abs(iamp) + (i(kamp) - i(kamp) * i(kampoff))

igrain random i(kgrainmin), i(kgrainmax)
igap random i(kgapmin), i(kgapmax)
iskip random 0, i(kmaxskip)
iskip = iskip * sr
ipoint limit i(kpoint) + iskip, 0, isamps-(((igrain + igap) * sr) * ifreq)

timout 0, igrain + igap, continue
reinit redo

continue:
kl = sqrt(2)/2 * cos(ipan) - sin(ipan)
kri = sqrt(2)/2 * cos(ipan) + sin(ipan)
aline linseg 0, i(katt) * igrain, 1, (1-i(katt)-i(kdec)) * igrain, 1, i(kdec) * igrain, 0
asig lposcil3 iamp, ifreq, 0, isamps, ifn, ipoint
rireturn
asig = asig * aline
al = ainl + asig * kl
ar = ainr + asig * kri

xout al, ar
	endop

Examples

/* .orc */
nchnls = 2

	opcode stereoGrain, aa, kkkkkkkkkkkkkkkiiip
;amp, off 0-1, grain, off, gap, off, skip (secs), pan -1 1, distributions, att % of grain, dec, pointer, numfreqs, freq ft, samp ft, density
kamp, kampoff, kgrain, kgrainoff, kgap, kgapoff, kmaxskip, kcenterpan, kampr, kfreqr, kpanr, katt, kdec, kpoint, knumfreq, ifreqfn, ifn, idens, icount xin

ainl init 0
ainr init 0

if (icount > idens) goto out

loop:
ainl, ainr stereoGrain kamp, kampoff, kgrain, kgrainoff, kgap, kgapoff, kmaxskip, kcenterpan, kampr, kfreqr, kpanr, katt, kdec, kpoint, knumfreq, ifreqfn, ifn, idens, icount + 1

out:
isamps = ftlen(ifn)
kdec limit kdec, .05, 1-katt
katt limit katt, .05, 1-kdec
kgrainmin = kgrain - kgrain * kgrainoff
kgrainmax = kgrain + kgrain * kgrainoff
kgapmin = kgap - kgap * kgapoff
kgapmax = kgap + kgap * kgapoff

redo:
ipan rnd31 1, i(kpanr)
ipan limit ipan + i(kcenterpan), -1, 1
ifreq rnd31 1, i(kfreqr)
ifreq = abs(ifreq * (i(knumfreq)-.001))
ifreq table ifreq, ifreqfn

iamp rnd31 i(kamp) * i(kampoff), i(kampr)
iamp = abs(iamp) + (i(kamp) - i(kamp) * i(kampoff))

igrain random i(kgrainmin), i(kgrainmax)
igap random i(kgapmin), i(kgapmax)
iskip random 0, i(kmaxskip)
iskip = iskip * sr
ipoint limit i(kpoint) + iskip, 0, isamps-(((igrain + igap) * sr) * ifreq)

timout 0, igrain + igap, continue
reinit redo

continue:
kl = sqrt(2)/2 * cos(ipan) - sin(ipan)
kri = sqrt(2)/2 * cos(ipan) + sin(ipan)
aline linseg 0, i(katt) * igrain, 1, (1-i(katt)-i(kdec)) * igrain, 1, i(kdec) * igrain, 0
asig lposcil3 iamp, ifreq, 0, isamps, ifn, ipoint
rireturn
asig = asig * aline
al = ainl + asig * kl
ar = ainr + asig * kri

xout al, ar
	endop

	opcode linearPointer, k, kkkip
kspeed, kbeg, kend, ifn, imode xin
kend limit kend, kbeg + .001, 1
kbeg limit kbeg, 0, kend
isamps = ftlen(ifn)
ilength = (isamps/sr)
kcps = kspeed/ilength
kpoint phasor kcps
kpoint = (imode == -1?kpoint * -1 + 1:kpoint)
kpoint = (kpoint * (kend-kbeg)) * isamps + kbeg * isamps
xout kpoint
	endop

instr 1
ifn = 1
ifreqfn = 10
kspeed = .5
kbeg = 0
kend = 1
kamp = 5000
kampoff = .1
kgrain = .05
kgrainoff = .1
kgap = .001
kgapoff = .1
kmaxskip = .2
kcenterpan = 0
kampr = 6
kfreqr = .5
kpanr = -.5
katt = .1
kdec = .1
knumfreq = 8
idens = 30

kpoint linearPointer kspeed, kbeg, kend, ifn
al, ar stereoGrain kamp, kampoff, kgrain, kgrainoff, kgap, kgapoff, kmaxskip, kcenterpan, kampr, kfreqr, kpanr, katt, kdec, kpoint, knumfreq, ifreqfn, ifn, idens
outs al, ar
endin

/* .sco */
f1 0 0 1 "soundfile.aif" 0 0 0
f10 0 8 -2 .33333 .49 .6 .713 1.2 1.707 2.12 2.8
i1 0 60

Credits

bhob rainey


Previous Home Next
sampleSlicer   linearPointer