Class: Wavify::DSP::Effects::Bitcrusher
- Inherits:
-
EffectBase
- Object
- EffectBase
- Wavify::DSP::Effects::Bitcrusher
- Defined in:
- lib/wavify/dsp/effects/bitcrusher.rb,
sig/effects.rbs
Overview
Bit-depth reduction and sample-rate hold effect.
Constant Summary
Constants inherited from EffectBase
Instance Method Summary collapse
-
#initialize(bit_depth: 8, downsample: 1, mix: 1.0) ⇒ Bitcrusher
constructor
A new instance of Bitcrusher.
-
#process_sample(sample, channel:, sample_rate:) ⇒ Float
Processes a single sample for one channel.
Methods inherited from EffectBase
#apply, #build_runtime, #flush, #latency, #lookahead, #process, #reset, #tail_duration
Constructor Details
#initialize(bit_depth: 8, downsample: 1, mix: 1.0) ⇒ Bitcrusher
Returns a new instance of Bitcrusher.
8 9 10 11 12 13 14 |
# File 'lib/wavify/dsp/effects/bitcrusher.rb', line 8 def initialize(bit_depth: 8, downsample: 1, mix: 1.0) super() @bit_depth = validate_bit_depth!(bit_depth) @downsample = validate_downsample!(downsample) @mix = validate_unit!(mix, :mix) reset end |
Instance Method Details
#process_sample(sample, channel:, sample_rate:) ⇒ Float
Processes a single sample for one channel.
22 23 24 25 26 27 28 29 30 31 |
# File 'lib/wavify/dsp/effects/bitcrusher.rb', line 22 def process_sample(sample, channel:, sample_rate:) dry = sample.to_f if (@counters.fetch(channel) % @downsample).zero? @held_samples[channel] = quantize(dry) end @counters[channel] += 1 wet = @held_samples.fetch(channel) (dry * (1.0 - @mix)) + (wet * @mix) end |