Class: SynthBlocks::Drum::KickDrum
- Inherits:
-
Core::Sound
- Object
- Core::Sound
- SynthBlocks::Drum::KickDrum
- Defined in:
- lib/synth_blocks/drum/kick_drum.rb
Overview
A simple kick drum generator
Direct Known Subclasses
Instance Attribute Summary
Attributes inherited from Core::Sound
Instance Method Summary collapse
-
#duration(_) ⇒ Object
:nodoc:.
-
#initialize(sfreq, preset = {}) ⇒ KickDrum
constructor
Structure Pitch Env > Sine wave OSC >.
-
#run(offset) ⇒ Object
Run generator.
Methods inherited from Core::Sound
#active_events, #get, #live_params, #release, #set, #start, #stop
Constructor Details
#initialize(sfreq, preset = {}) ⇒ KickDrum
Structure
Pitch Env > Sine wave OSC >
parameter:
-
pitch_attack, pitch_decay - Pitch envelope params in s
-
amp_attack, amp_decay - Amp envelope params in s
-
base_frequency - base frequency in Hz
-
pitch_mod - frequency modulation amount in Hz
20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/synth_blocks/drum/kick_drum.rb', line 20 def initialize(sfreq, preset = {}) super(sfreq, mode: :polyphonic) @preset = { pitch_attack: 0.001, pitch_decay: 0.02, amp_attack: 0.001, amp_decay: 0.15, base_frequency: 55, pitch_mod: 200 }.merge(preset) @oscillator = SynthBlocks::Core::Oscillator.new(@sampling_frequency) @pitch_env = SynthBlocks::Mod::Envelope.new(@preset[:pitch_attack], @preset[:pitch_decay]) @amp_env = SynthBlocks::Mod::Envelope.new(@preset[:amp_attack], @preset[:amp_decay]) end |
Instance Method Details
#duration(_) ⇒ Object
:nodoc:
35 36 37 |
# File 'lib/synth_blocks/drum/kick_drum.rb', line 35 def duration(_) # :nodoc: @preset[:amp_attack] + @preset[:amp_decay] end |
#run(offset) ⇒ Object
Run generator
40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/synth_blocks/drum/kick_drum.rb', line 40 def run(offset) t = time(offset) events = active_events(t) if events.empty? 0.0 else event = events[events.keys.last] local_started = t - event[:started] osc_out = @oscillator.run(@preset[:base_frequency].to_f + @pitch_env.run(local_started) * @preset[:pitch_mod].to_f, waveform: :sine) osc_out = osc_out * 1.0 * @amp_env.run(local_started) end end |