class SynthBlocks::Drum::SnareDrum
Simple snare drum generator
Public Class Methods
new(sfreq, preset = {})
click to toggle source
Parameters¶ ↑
- flt_frequency
-
Noise filter frequency
- flt_envmod
-
Noise filter frequency modulation by envelope
- flt_attack, flt_decay
-
Noise filter envelope params
- flt_Q
-
Noise filter Q/resonance
- noise_amp_attack, noise_amp_decay
-
Noise amp envelope params
- noise_vol, drum_vol
-
Noise and
Drum
body volumes - base_frequency
-
Drum
body base frequency (see KickDrum#initialize) - pitch_mod
-
Drum
body pitch mod (see KickDrum#initialize) - pitch_attack, pitch_decay
-
Drum
body pitch env params
Calls superclass method
SynthBlocks::Core::Sound::new
# File lib/synth_blocks/drum/snare_drum.rb, line 23 def initialize(sfreq, preset = {}) super(sfreq, mode: :polyphonic) @preset = { flt_attack: 0.001, noise_amp_attack: 0.001, noise_vol: 0.5, drum_vol: 0.3, base_frequency: 110, pitch_mod: 440, pitch_decay: 0.03, amp_decay: 0.15, flt_Q: 1.1, flt_envmod: 2000, flt_frequency: 7000, flt_decay: 0.1, noise_amp_decay: 0.2 }.merge(preset) @drum = SynthBlocks::Drum::KickDrum.new(sfreq, @preset) @filter = SynthBlocks::Core::StateVariableFilter.new(sfreq) @flt_env = SynthBlocks::Mod::Envelope.new(@preset[:flt_attack], @preset[:flt_decay]) @amp_env = SynthBlocks::Mod::Envelope.new(@preset[:noise_amp_attack], @preset[:noise_amp_decay]) end
Public Instance Methods
run(offset)
click to toggle source
run the generator
# File lib/synth_blocks/drum/snare_drum.rb, line 69 def run(offset) drum_out = @drum.run(offset) # time in seconds t = time(offset) events = active_events(t) if events.empty? 0.0 else event = events[events.keys.last] # lfo_out = (@lfo.run(@preset[:lfo_frequency], waveform: @preset[:lfo_waveform]) + 1) / 8 + 0.5 noise_out = rand * 2.0 - 1.0 local_started = t - event[:started] noise_out = @filter.run(noise_out, @preset[:flt_frequency] + @flt_env.run(local_started) * @preset[:flt_envmod], @preset[:flt_Q]) noise_out = 0.3 * noise_out * @amp_env.run(local_started) noise_out * @preset[:noise_vol] + drum_out * @preset[:drum_vol] end end
start(t, note = 36, velocity = 1.0)
click to toggle source
create a note on event
- t
-
time in seconds since song start
- note
-
MIDI note number
- velocity
-
velocity (currently unused)
Calls superclass method
SynthBlocks::Core::Sound#start
# File lib/synth_blocks/drum/snare_drum.rb, line 51 def start(t, note = 36, velocity = 1.0) super(t, note, velocity) @drum.start(t, note, velocity) end
stop(t, note = 36)
click to toggle source
create a note off event
- t
-
time in seconds since song start
- note
-
MIDI note number
Calls superclass method
SynthBlocks::Core::Sound#stop
# File lib/synth_blocks/drum/snare_drum.rb, line 59 def stop(t, note = 36) super(t, note) @drum.stop(t, note) end