Class: SynthBlocks::Fx::Compressor
- Inherits:
-
Object
- Object
- SynthBlocks::Fx::Compressor
- Defined in:
- lib/synth_blocks/fx/compressor.rb
Overview
simple compresor taken from www.musicdsp.org/en/latest/Effects/204-simple-compressor-class-c.html
Constant Summary collapse
- DC_OFFSET =
:nodoc:
1.0E-25- LOG_2_DB =
:nodoc:
8.6858896380650365530225783783321- DB_2_LOG =
:nodoc:
0.11512925464970228420089957273422
Instance Attribute Summary collapse
-
#ratio ⇒ Object
writeonly
:nodoc:.
-
#threshold ⇒ Object
writeonly
:nodoc:.
-
#window ⇒ Object
writeonly
:nodoc:.
Instance Method Summary collapse
-
#attack=(attack) ⇒ Object
set attack.
-
#initialize(srate, attack: 10.0, release: 100.0, ratio: 1.0, threshold: 0.0) ⇒ Compressor
constructor
Create compressor instance.
-
#release=(release) ⇒ Object
set release.
-
#run(input) ⇒ Object
run compressor.
Constructor Details
#initialize(srate, attack: 10.0, release: 100.0, ratio: 1.0, threshold: 0.0) ⇒ Compressor
Create compressor instance
attack is the attack time in ms
release is the release time in ms
ratio is the compresor ratio
threshold is the knee threshold
68 69 70 71 72 73 74 |
# File 'lib/synth_blocks/fx/compressor.rb', line 68 def initialize(srate, attack: 10.0, release: 100.0, ratio: 1.0, threshold: 0.0) @sample_rate = srate @envelope = AttRelEnvelope.new(srate, attack: attack, release: release) @env_db = DC_OFFSET @ratio = ratio @threshold = threshold end |
Instance Attribute Details
#ratio=(value) ⇒ Object (writeonly)
:nodoc:
57 58 59 |
# File 'lib/synth_blocks/fx/compressor.rb', line 57 def ratio=(value) @ratio = value end |
#threshold=(value) ⇒ Object (writeonly)
:nodoc:
57 58 59 |
# File 'lib/synth_blocks/fx/compressor.rb', line 57 def threshold=(value) @threshold = value end |
#window=(value) ⇒ Object (writeonly)
:nodoc:
57 58 59 |
# File 'lib/synth_blocks/fx/compressor.rb', line 57 def window=(value) @window = value end |
Instance Method Details
#attack=(attack) ⇒ Object
set attack
78 79 80 |
# File 'lib/synth_blocks/fx/compressor.rb', line 78 def attack=(attack) @envelope.attack = attack end |
#release=(release) ⇒ Object
set release
84 85 86 |
# File 'lib/synth_blocks/fx/compressor.rb', line 84 def release=(release) @envelope.release = release end |
#run(input) ⇒ Object
run compressor
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/synth_blocks/fx/compressor.rb', line 91 def run(input) rect = input.abs rect += DC_OFFSET key_db = lin2db(rect) over_db = key_db - @threshold over_db = 0.0 if over_db < 0.0 # attack/release over_db += DC_OFFSET @env_db = @envelope.run(over_db, @env_db) over_db = @env_db - DC_OFFSET gr = over_db * @ratio - 1.0 gr = db2lin(gr) input * gr end |