class SynthBlocks::Synth::Polysynth
A simple polyphonic synthesizer
OSC > Filter > Amp
Public Class Methods
new(sfreq, preset = {})
click to toggle source
Parameters¶ ↑
-
amp_attack, _decay, _sustain, _release - Amp Envelope params
-
flt_attack, _decay, _sustain, _release - Filter Envelope params
-
flt_envmod - filter envelope modulation amount in Hz
-
flt_frequency, flt_Q - filter params
-
osc_waveform - waveform to generate (see Oscillator class)
Calls superclass method
SynthBlocks::Core::Sound::new
# File lib/synth_blocks/synth/polysynth.rb, line 40 def initialize(sfreq, preset = {}) @preset = { osc_waveform: :sawtooth, amp_env_attack: 0.2, amp_env_decay: 0.2, amp_env_sustain: 0.8, amp_env_release: 0.5, flt_env_attack: 0.5, flt_env_decay: 0.7, flt_env_sustain: 0.4, flt_env_release: 0.5, flt_frequency: 1000, flt_envmod: 2000, flt_Q: 3 }.merge(preset) super(sfreq, mode: :polyphonic) @active_voices = {} end
Public Instance Methods
run(offset)
click to toggle source
run sound generator
# File lib/synth_blocks/synth/polysynth.rb, line 69 def run(offset) t = time(offset) events = active_events(t) voice_results = [] events.each do |note, event| local_started = t - event[:started] next if local_started < 0 local_stopped = event[:stopped] && event[:stopped] - event[:started] note_key = "#{note}:#{event[:started]}" if @active_voices[note_key].nil? @active_voices[note_key] = PolyVoice.new(@sampling_frequency, self, @preset) end if @active_voices[note_key] voice_results << @active_voices[note_key].run(local_started, local_stopped, frequency(note), event[:velocity]) end end 0.3 * voice_results.inject(0) {|sum, result| sum + result} end