randomh

randomh — Generates random numbers with a user-defined limit and holds them for a period of time.

Description

Generates random numbers with a user-defined limit and holds them for a period of time.

Syntax

ares randomh kmin, kmax, xcps [,imode] [,ifirstval]
kres randomh kmin, kmax, kcps [,imode] [,ifirstval]

Initialization

imode (optional, default=0) -- generation mode of the first output value (see below)

ifirstval (optional, default=0) -- first output value

Performance

kmin -- minimum range limit

kmax -- maximum range limit

kcps, xcps -- rate of random break-point generation

The randomh opcode is similar to randh but allows the user to set arbitrary minimum and maximum values.

When imode = 0 (the default), the kmin argument value is outputted during 1/kcps (resp. 1/xcps) seconds at the beginning of the note. Then, the normal process takes place with a new random number generated and held every 1/kcps (resp. 1/xcps) seconds.

When imode = 2, the ifirstval argument value is outputted during 1/kcps (resp. 1/xcps) seconds at the beginning of the note. Then, the normal process takes place with a new random number generated and held every 1/kcps (resp. 1/xcps) seconds.

When imode = 3, the generation process begins with a random value from the initialization time.

Examples

Here is an example of the randomh opcode. It uses the file randomh.csd.

Example 715. Example of the randomh opcode.

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
; Audio out   Audio in
-odac           -iadc    ;;;RT audio I/O
; For Non-realtime ouput leave only the line below:
; -o randomh.wav -W ;;; for file output any platform
</CsOptions>
<CsInstruments>

; Initialize the global variables.
sr = 44100
kr = 4410
ksmps = 10
nchnls = 1

     seed 0
     
; Instrument #1.
instr 1
  ; Choose a random frequency between 220 and 440 Hz.
  ; Generate new random numbers at 10 Hz.
  kmin    init 220
  kmax    init 440
  kcps    init 10
  imode   =    p4
  ifstval =    p5
  
     printf_i "\nMode: %d\n", 1, imode
  k1 randomh kmin, kmax, kcps, imode, ifstval
     printk2 k1
endin

</CsInstruments>
<CsScore>

; Play Instrument #1 for one second,
; each time with a different mode.
i 1 0 1
i 1 1 1 2 330
i 1 2 1 3
e

</CsScore>
</CsoundSynthesizer>


Its output should include lines like this:

Mode: 0
 i1   220.00000
 i1   396.26079
 i1   240.75446
 i1   364.24577
    ...

Mode: 2
 i1   330.00000
 i1   416.50935
 i1   356.11619
 i1   433.59324
    ...

Mode: 3
 i1   261.17741
 i1   402.00891
 i1   393.86592
 i1   307.19839
    ...

See Also

randh, random, randomi

Credits

Author: Gabriel Maldonado

Arguments imode and ifirstval added by François Pinot, Jan. 2011, after a discussion with Peiman Khosravi on the csnd list.

Example written by Kevin Conder, adapted for new args by François Pinot.