-- Oscillators for OAK. #USE "course.lib" #USE "snglmath.lib" #INCLUDE "mathvals.inc" #INCLUDE "oak.inc" #USE "basic" --{{{ PROC generate.sine (CHAN SIGNAL in?, CHAN SIGNAL out!) -- This is crap. -- Spent a while kludging around with this to prevent it overflowing. This now -- works, but it sounds *very* out of tune (because it's approximating the -- frequencies). Need something smarter. PROC generate.sine (CHAN SIGNAL in?, CHAN SIGNAL out!) INITIAL REAL32 count IS 0.0: WHILE TRUE SIGNAL sig: SEQ in ? sig SEQ i = 0 FOR BLOCK.SIZE INITIAL REAL32 freq IS sig[i]: IF freq < 0.01 sig[i] := 0.0 TRUE VAL REAL32 period IS SAMPLE.RATE / freq: SEQ VAL REAL32 pos IS ((2.0 * PI) * (REAL32 ROUND count)) / (REAL32 ROUND period): sig[i] := SIN (pos) count := count + 1.0 IF count > period count := count - period TRUE SKIP out ! sig : --}}} --{{{ PROC generate.square (CHAN SIGNAL in?, CHAN SIGNAL out!) --* Generate a square wave. PROC generate.square (CHAN SIGNAL in?, CHAN SIGNAL out!) INITIAL REAL32 value IS 0.0: INITIAL REAL32 count IS 0.0: WHILE TRUE SIGNAL sig: SEQ in ? sig SEQ i = 0 FOR BLOCK.SIZE INITIAL REAL32 freq IS sig[i]: SEQ sig[i] := value count := count + 1.0 IF freq < 0.01 value := 0.0 TRUE VAL REAL32 period IS SAMPLE.RATE / freq: IF count > period SEQ value := 1.0 count := count - period count > (period / 2.0) value := -1.0 TRUE SKIP out ! sig : --}}} --{{{ PROC vibrato (CHAN SIGNAL in?, out!, VAL REAL32 rate, depth) PROC vibrato (CHAN SIGNAL in?, out!, VAL REAL32 rate, depth) CHAN SIGNAL a, b: PAR constant (rate, a!) generate.sine (a?, b!) mixer ([in?, b?], [1.0 - depth, depth], out!) : --}}}