Class: SynthBlocks::Drum::SnareDrum
- Inherits:
-
Core::Sound
- Object
- Core::Sound
- SynthBlocks::Drum::SnareDrum
- Defined in:
- lib/synth_blocks/drum/snare_drum.rb
Overview
Simple snare drum generator
Instance Attribute Summary
Attributes inherited from Core::Sound
Instance Method Summary collapse
-
#duration(t) ⇒ Object
:nodoc:.
-
#initialize(sfreq, preset = {}) ⇒ SnareDrum
constructor
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.
-
#run(offset) ⇒ Object
run the generator.
-
#start(t, note = 36, velocity = 1.0) ⇒ Object
create a note on event [t] time in seconds since song start [note] MIDI note number [velocity] velocity (currently unused).
-
#stop(t, note = 36) ⇒ Object
create a note off event [t] time in seconds since song start [note] MIDI note number.
Methods inherited from Core::Sound
#active_events, #get, #live_params, #release, #set
Constructor Details
#initialize(sfreq, preset = {}) ⇒ SnareDrum
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
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# 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 |
Instance Method Details
#duration(t) ⇒ Object
:nodoc:
64 65 66 |
# File 'lib/synth_blocks/drum/snare_drum.rb', line 64 def duration(t) # :nodoc: [@preset[:noise_amp_attack] + @preset[:noise_amp_decay], @drum.duration(t)].max end |
#run(offset) ⇒ Object
run the generator
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# 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) ⇒ Object
create a note on event
- t
-
time in seconds since song start
- note
-
MIDI note number
- velocity
-
velocity (currently unused)
51 52 53 54 |
# 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) ⇒ Object
create a note off event
- t
-
time in seconds since song start
- note
-
MIDI note number
59 60 61 62 |
# File 'lib/synth_blocks/drum/snare_drum.rb', line 59 def stop(t, note = 36) super(t, note) @drum.stop(t, note) end |