Class: SynthBlocks::Drum::Hihat
- Inherits:
-
Core::Sound
- Object
- Core::Sound
- SynthBlocks::Drum::Hihat
- Defined in:
- lib/synth_blocks/drum/hihat.rb
Overview
Simple Hihat generator Nois > Filter > Amp
Instance Attribute Summary
Attributes inherited from Core::Sound
Instance Method Summary collapse
-
#duration(_) ⇒ Object
:nodoc:.
-
#initialize(sfreq, preset = {}) ⇒ Hihat
constructor
parameters flt_frequency - center frequency of the bandpass filter.
-
#run(offset) ⇒ Object
Run the generator (offset is given in samples).
Methods inherited from Core::Sound
#active_events, #get, #live_params, #release, #set, #start, #stop
Constructor Details
#initialize(sfreq, preset = {}) ⇒ Hihat
parameters
flt_frequency - center frequency of the bandpass filter
flt_Q - Q (resonance) value of the bandpass filter
amp_attack - attack time in seconds
amp_decay - decay time in seconds
20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/synth_blocks/drum/hihat.rb', line 20 def initialize(sfreq, preset = {}) super(sfreq, mode: :polyphonic) @filter = SynthBlocks::Core::StateVariableFilter.new(sfreq) @preset = { flt_frequency: 10000, flt_Q: 2, amp_attack: 0.001, amp_decay: 0.1, }.merge(preset) @amp_env = SynthBlocks::Mod::Envelope.new(@preset[:amp_attack], @preset[:amp_decay]) end |
Instance Method Details
#duration(_) ⇒ Object
:nodoc:
32 33 34 |
# File 'lib/synth_blocks/drum/hihat.rb', line 32 def duration(_) # :nodoc: @preset[:amp_attack] + @preset[:amp_decay] end |
#run(offset) ⇒ Object
Run the generator (offset is given in samples)
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/synth_blocks/drum/hihat.rb', line 37 def 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 local_started = t - event[:started] noise_out = rand * 2.0 - 1.0 noise_out = @filter.run(noise_out, @preset[:flt_frequency], @preset[:flt_Q], type: :bandpass) 0.3 * noise_out * @amp_env.run(local_started) end end |