-- Synthesised organ voice for OAK. #USE "snglmath.lib" #INCLUDE "mathvals.inc" #INCLUDE "oak.inc" #USE "basic" #USE "osc" --{{{ PROC generate.organ (CHAN SIGNAL in?, VAL INT num.harmonics, CHAN SIGNAL out!) -- Mix together a load of sine waves of frequencies N, 2N, 4N, 8N... to produce -- a bog-standard synthesised organ noise. VAL INT max.num.harmonics IS 20: PROC generate.organ (CHAN SIGNAL in?, VAL INT num.harmonics, CHAN SIGNAL out!) PROC stage (CHAN SIGNAL f.in?, f.out!, a.out!) CHAN SIGNAL a, b: PAR da (f.in?, [a!, b!]) amp (a?, 2.0, f.out!) generate.sine (b?, a.out!) : [max.num.harmonics + 1]CHAN SIGNAL f: [max.num.harmonics]CHAN SIGNAL a: VAL [max.num.harmonics]REAL32 levels IS [i = 0 FOR max.num.harmonics | POWER (0.5, REAL32 ROUND (i + 1))]: PAR join (in?, f[0]!) PAR i = 0 FOR num.harmonics stage (f[i]?, f[i + 1]!, a[i]!) sink (f[num.harmonics]?) mixer ([a? FOR num.harmonics], [levels FOR num.harmonics], out!) : --}}}