René Nyffenegger's collection of things on the web
René Nyffenegger on Oracle - Most wanted - Feedback
 

Random note

This template is based on the Frequency in Table template.
The first five parameters that are passed to the instrument are the usual ones: instrument number, start time, length, amplitude, note.
The note is an index into the values fillecdint o table 55.
p6 is the (relative to the sum of all probabilites) probabilty of note p5.
p7 is the distance of notes to p5.
p8 is the (relative to the sum of all probabilites) probabilty of note p7
and so on.
sr=44100
kr=4410
nchnls=1

instr 1

  igoto start

  goto no_start

start:

  ilen   = p3
  iampl  = p4

  inote1 = p5
  inote2 = inote1 + p7
  inote3 = inote1 + p9
  inote4 = inote1 + p11
  inote5 = inote1 + p13

  iprob1 = p6
  iprob2 = iprob1 + p8
  iprob3 = iprob2 + p10
  iprob4 = iprob3 + p12
  iprob5 = iprob4 + p14

  iprob_sum = iprob5

  irnd    init rnd (iprob_sum)

  if irnd < iprob1 igoto f1
  if irnd < iprob2 igoto f2
  if irnd < iprob3 igoto f3
  if irnd < iprob4 igoto f4
  if irnd < iprob5 igoto f5


f1:
  inote table inote1, 50
  igoto found_note

f2:
  inote table inote2, 50
  igoto found_note

f3:
  inote table inote3, 50
  igoto found_note
  
f4:
  inote table inote4, 50
  igoto found_note

f5:
  inote table inote5, 50


found_note:
  ;inote = 6.00
  ifrq = cpspch(inote)
  ;iampl = 10000

no_start:

  ;printk ifrq

  kenv  linen iampl, 0.02, ilen, 0.04
  asig oscili kenv, ifrq, 1
  out asig


endin

The following score plays an a minor 7-9 (45, 3, 7, 10,14) chord with random notes.
As the sum of 4+1+2+2+2 = 11, the probablity for the note a is 4/11, for c: 1/11, for e: 2/11, for g: 2/11 and for b: 2/11
f1 0 2048   10   1; sine

f50 0 128  -2	
		 3.00  3.01  3.02  3.03  3.04  3.05  3.06  3.07  3.08  3.09  3.10  3.11
		 4.00  4.01  4.02  4.03  4.04  4.05  4.06  4.07  4.08  4.09  4.10  4.11
		 5.00  5.01  5.02  5.03  5.04  5.05  5.06  5.07  5.08  5.09  5.10  5.11
		 6.00  6.01  6.02  6.03  6.04  6.05  6.06  6.07  6.08  6.09  6.10  6.11
		 7.00  7.01  7.02  7.03  7.04  7.05  7.06  7.07  7.08  7.09  7.10  7.11
		 8.00  8.01  8.02  8.03  8.04  8.05  8.06  8.07  8.08  8.09  8.10  8.11
		 9.00  9.01  9.02  9.03  9.04  9.05  9.06  9.07  9.08  9.09  9.10  9.11
		10.00 10.01 10.02 10.03 10.04 10.05 10.06 10.07 10.08 10.09 10.10 10.11
		11.00 11.01 11.02 11.03 11.04 11.05 11.06 11.07 11.08 11.09 11.10 11.11
		12.00 12.01 12.02 12.03 12.04 12.05 12.06 12.07 12.08 12.09 12.10 12.11

i1 0 0.2 10000    45 4   3  1    7 2   10 2  14 2
i1 + 0.2 10000    .  .   .  .    . .    . .   . .
i1 + 0.2 10000    .  .   .  .    . .    . .   . .
i1 + 0.2 10000    .  .   .  .    . .    . .   . .
i1 + 0.2 10000    .  .   .  .    . .    . .   . .
i1 + 0.2 10000    .  .   .  .    . .    . .   . .
i1 + 0.2 10000    .  .   .  .    . .    . .   . .
i1 + 0.2 10000    .  .   .  .    . .    . .   . .
i1 + 0.2 10000    .  .   .  .    . .    . .   . .
i1 + 0.2 10000    .  .   .  .    . .    . .   . .
i1 + 0.2 10000    .  .   .  .    . .    . .   . .
i1 + 0.2 10000    .  .   .  .    . .    . .   . .
i1 + 0.2 10000    .  .   .  .    . .    . .   . .
i1 + 0.2 10000    .  .   .  .    . .    . .   . .
i1 + 0.2 10000    .  .   .  .    . .    . .   . .
i1 + 0.2 10000    .  .   .  .    . .    . .   . .
i1 + 0.2 10000    .  .   .  .    . .    . .   . .
i1 + 0.2 10000    .  .   .  .    . .    . .   . .
i1 + 0.2 10000    .  .   .  .    . .    . .   . .
i1 + 0.2 10000    .  .   .  .    . .    . .   . .
i1 + 0.2 10000    .  .   .  .    . .    . .   . .
i1 + 0.2 10000    .  .   .  .    . .    . .   . .
i1 + 0.2 10000    .  .   .  .    . .    . .   . .
i1 + 0.2 10000    .  .   .  .    . .    . .   . .
i1 + 0.2 10000    .  .   .  .    . .    . .   . .
i1 + 0.2 10000    .  .   .  .    . .    . .   . .
i1 + 0.2 10000    .  .   .  .    . .    . .   . .
i1 + 0.2 10000    .  .   .  .    . .    . .   . .
i1 + 0.2 10000    .  .   .  .    . .    . .   . .
i1 + 0.2 10000    .  .   .  .    . .    . .   . .
i1 + 0.2 10000    .  .   .  .    . .    . .   . .
i1 + 0.2 10000    .  .   .  .    . .    . .   . .
i1 + 0.2 10000    .  .   .  .    . .    . .   . .
i1 + 0.2 10000    .  .   .  .    . .    . .   . .
i1 + 0.2 10000    .  .   .  .    . .    . .   . .
i1 + 0.2 10000    .  .   .  .    . .    . .   . .
i1 + 0.2 10000    .  .   .  .    . .    . .   . .
i1 + 0.2 10000    .  .   .  .    . .    . .   . .
i1 + 0.2 10000    .  .   .  .    . .    . .   . .
i1 + 0.2 10000    .  .   .  .    . .    . .   . .
i1 + 0.2 10000    .  .   .  .    . .    . .   . .
i1 + 0.2 10000    .  .   .  .    . .    . .   . .
i1 + 0.2 10000    .  .   .  .    . .    . .   . .
i1 + 0.2 10000    .  .   .  .    . .    . .   . .
i1 + 0.2 10000    .  .   .  .    . .    . .   . .
i1 + 0.2 10000    .  .   .  .    . .    . .   . .
i1 + 0.2 10000    .  .   .  .    . .    . .   . .
i1 + 0.2 10000    .  .   .  .    . .    . .   . .
i1 + 0.2 10000    .  .   .  .    . .    . .   . .
i1 + 0.2 10000    .  .   .  .    . .    . .   . .
i1 + 0.2 10000    .  .   .  .    . .    . .   . .
i1 + 0.2 10000    .  .   .  .    . .    . .   . .
i1 + 0.2 10000    .  .   .  .    . .    . .   . .
i1 + 0.2 10000    .  .   .  .    . .    . .   . .
		13.00 13.01 13.02 13.03 13.04 13.05 13.06 13.07