GEN42

GEN42 — Generates a random distribution of discrete ranges of values.

Description

Generates a random distribution function of discrete ranges of values by giving a list of groups of three numbers.

Syntax

f # time size -42  min1 max1 prob1 min2 max2 prob2 min3 max3 prob3 ...  minN maxN probN

Performance

The first number of each group is a the minimum value of the range, the second is the maximum value and the third is the probability of that an element belonging to that range of values can be chosen by a random algorithm. Probabilities for a range should be a fraction of 1, and the sum of the probabilities for all the ranges should total 1.0.

This subroutine is designed to be used together with duserrnd and urd opcodes (see duserrnd for more information). Since both duserrnd and urd do not use any interpolation, it is suggested to give a size reasonably big.

Examples

Here is an example of the GEN42 generator. It uses the file gen42.csd.

Example 1309. Example of the GEN42 generator.

See the sections Real-time Audio and Command Line Flags for more information on using command line flags.

<CsoundSynthesizer>
<CsOptions>
; Select audio/midi flags here according to platform
-odac   ;;;realtime audio out
;-iadc    ;;;uncomment -iadc if realtime audio input is needed too
; For Non-realtime ouput leave only the line below:
; -o GEN42.wav -W ;;; for file output any platform
</CsOptions>
<CsInstruments>

sr = 44100
ksmps = 32
nchnls = 2
0dbfs  = 1

instr 1 

ktab  = 1			;ftable 1
kurd  = urd(ktab) 
ktrig metro 5			;triggers 5 times per second
kres  samphold kurd, ktrig	;sample and hold value of kurd
      printk2 kres		;print it
asig  poscil .5, 220+kres, 2
      outs asig, asig
endin

instr 2

seed 0	;every run new values

ktab  = 1 			;ftable 1
kurd  = urd(ktab) 
ktrig metro 5			;triggers 5 times per second
kres  samphold kurd, ktrig	;sample and hold value of kurd
      printk2 kres		;print it
asig  poscil .5, 220+kres, 2
      outs asig, asig

endin
</CsInstruments>
<CsScore>
f1 0 -20 -42  10 20 .3 100 200 .7 ;30% choose between 10 and 20 and 70% between 100 and 200
f2 0 8192 10 1			  ;sine wave

i 1 0 5
i 2 6 5
e
</CsScore>
</CsoundSynthesizer>


Its output should include lines like these:

 i1   184.61538
 i1   130.76923
 i1   169.23077
 i1    12.00000
.......

WARNING: Seeding from current time 3751086165

 i2   138.46154
 i2    12.00000
 i2   123.07692
 i2   161.53846
 i2   123.07692
 i2   153.84615
......
      

This is the diagram of the waveform of the GEN42 routine, as used in the example:

f 1 0 -20 -42 10 20 .3 100 200 .7

f 1 0 -20 -42 10 20 .3 100 200 .7

Credits

Author: Gabriel Maldonado