synth_blocks 1.0.3 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
 - data/lib/synth_blocks.rb +1 -0
 - data/lib/synth_blocks/mod/adsr.rb +25 -38
 - data/lib/synth_blocks/mod/adsr_old.rb +83 -0
 - metadata +4 -3
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA256:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: 3feea4e01983af0753f8fcc3c95d92a02d59af71ac8ac9c83373d4e150c0382d
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: d3cd62fa4294b4bb0ce334bc23439579316520f81493c93212af1c0fc6b8103e
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: 764c103a562dd360316176b555e4085f5b2ae4e9d636b6803b4e9bd797bd18512534383a88778aa1dd212d6606c6551c32c17e86df6a27ace5f4e269ceee090c
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: 7c50a642105d5bac45b205d5d1a2c0ea7d289b1796670bb136c4f7a18ff7e2fdd606fb04be0f38eea67b0db9e4f2658d494fb5edb1078875c751c6db9c80c6b9
         
     | 
    
        data/lib/synth_blocks.rb
    CHANGED
    
    
| 
         @@ -1,8 +1,5 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            module SynthBlocks
         
     | 
| 
       2 
2 
     | 
    
         
             
              module Mod
         
     | 
| 
       3 
     | 
    
         
            -
                ##
         
     | 
| 
       4 
     | 
    
         
            -
                # Implementation of a linear ADSR envelope generator with a tracking
         
     | 
| 
       5 
     | 
    
         
            -
                # value so that envelope restarts don't click
         
     | 
| 
       6 
3 
     | 
    
         
             
                class Adsr
         
     | 
| 
       7 
4 
     | 
    
         
             
                  ##
         
     | 
| 
       8 
5 
     | 
    
         
             
                  # attack time in seconds
         
     | 
| 
         @@ -27,6 +24,9 @@ module SynthBlocks 
     | 
|
| 
       27 
24 
     | 
    
         
             
                  # sustain should be between 0 and 1
         
     | 
| 
       28 
25 
     | 
    
         
             
                  def initialize(attack, decay, sustain, release)
         
     | 
| 
       29 
26 
     | 
    
         
             
                    @value = 0
         
     | 
| 
      
 27 
     | 
    
         
            +
                    @start_time = 0
         
     | 
| 
      
 28 
     | 
    
         
            +
                    @last_t = 0
         
     | 
| 
      
 29 
     | 
    
         
            +
                    @done = false
         
     | 
| 
       30 
30 
     | 
    
         
             
                    @start_value = 0
         
     | 
| 
       31 
31 
     | 
    
         
             
                    @attack = attack
         
     | 
| 
       32 
32 
     | 
    
         
             
                    @decay = decay
         
     | 
| 
         @@ -40,44 +40,31 @@ module SynthBlocks 
     | 
|
| 
       40 
40 
     | 
    
         
             
                  # if released is given (should be <= t), the envelope will enter the release stage
         
     | 
| 
       41 
41 
     | 
    
         
             
                  # returns the current value between 0 and 1
         
     | 
| 
       42 
42 
     | 
    
         
             
                  def run(t, released)
         
     | 
| 
       43 
     | 
    
         
            -
                     
     | 
| 
       44 
     | 
    
         
            -
                     
     | 
| 
       45 
     | 
    
         
            -
             
     | 
| 
       46 
     | 
    
         
            -
             
     | 
| 
       47 
     | 
    
         
            -
             
     | 
| 
       48 
     | 
    
         
            -
                       
     | 
| 
       49 
     | 
    
         
            -
             
     | 
| 
       50 
     | 
    
         
            -
                         
     | 
| 
       51 
     | 
    
         
            -
                      end
         
     | 
| 
       52 
     | 
    
         
            -
                      if t > attack && t < attack_decay # decay
         
     | 
| 
       53 
     | 
    
         
            -
                        return @value = linear(1.0, sustain, decay, t - attack)
         
     | 
| 
       54 
     | 
    
         
            -
                      end
         
     | 
| 
       55 
     | 
    
         
            -
                      if t >= attack + decay # sustain
         
     | 
| 
       56 
     | 
    
         
            -
                        return @value = sustain
         
     | 
| 
       57 
     | 
    
         
            -
                      end
         
     | 
| 
       58 
     | 
    
         
            -
                    else # release
         
     | 
| 
       59 
     | 
    
         
            -
                      if released <= attack # when released in attack phase
         
     | 
| 
       60 
     | 
    
         
            -
                        attack_level = linear(@start_value, 1, attack, released)
         
     | 
| 
       61 
     | 
    
         
            -
                        return [linear(attack_level, 0, release, t - released), 0].max
         
     | 
| 
      
 43 
     | 
    
         
            +
                    delta = t - @last_t
         
     | 
| 
      
 44 
     | 
    
         
            +
                    @last_t = t
         
     | 
| 
      
 45 
     | 
    
         
            +
                    if released
         
     | 
| 
      
 46 
     | 
    
         
            +
                      return 0 if @done
         
     | 
| 
      
 47 
     | 
    
         
            +
                      @value += -(@sustain/@release) * (delta)
         
     | 
| 
      
 48 
     | 
    
         
            +
                      if @value <= 0
         
     | 
| 
      
 49 
     | 
    
         
            +
                        @value = 0
         
     | 
| 
      
 50 
     | 
    
         
            +
                        @done = true
         
     | 
| 
       62 
51 
     | 
    
         
             
                      end
         
     | 
| 
       63 
     | 
    
         
            -
                       
     | 
| 
       64 
     | 
    
         
            -
             
     | 
| 
       65 
     | 
    
         
            -
             
     | 
| 
      
 52 
     | 
    
         
            +
                      return @value
         
     | 
| 
      
 53 
     | 
    
         
            +
                    else
         
     | 
| 
      
 54 
     | 
    
         
            +
                      if t < 0.0001 # initialize start value (slightly hacky, but works)
         
     | 
| 
      
 55 
     | 
    
         
            +
                        @start_time = t
         
     | 
| 
      
 56 
     | 
    
         
            +
                        return @value
         
     | 
| 
       66 
57 
     | 
    
         
             
                      end
         
     | 
| 
       67 
     | 
    
         
            -
                      if  
     | 
| 
       68 
     | 
    
         
            -
                        return @value  
     | 
| 
      
 58 
     | 
    
         
            +
                      if t <= @attack
         
     | 
| 
      
 59 
     | 
    
         
            +
                        return @value += 1/@attack * delta
         
     | 
| 
      
 60 
     | 
    
         
            +
                      elsif t <= @attack + @decay
         
     | 
| 
      
 61 
     | 
    
         
            +
                        return @value += -(1-@sustain)/@decay * delta
         
     | 
| 
      
 62 
     | 
    
         
            +
                      else
         
     | 
| 
      
 63 
     | 
    
         
            +
                        return @value = @sustain
         
     | 
| 
       69 
64 
     | 
    
         
             
                      end
         
     | 
| 
       70 
     | 
    
         
            -
                    end
         
     | 
| 
       71 
     | 
    
         
            -
                     
     | 
| 
       72 
     | 
    
         
            -
                  end
         
     | 
| 
       73 
     | 
    
         
            -
             
     | 
| 
       74 
     | 
    
         
            -
                  private
         
     | 
| 
       75 
     | 
    
         
            -
             
     | 
| 
       76 
     | 
    
         
            -
                  def linear(start, target, length, time)
         
     | 
| 
       77 
     | 
    
         
            -
                    return start if time == 0
         
     | 
| 
       78 
     | 
    
         
            -
                    return target if length == 0
         
     | 
| 
       79 
     | 
    
         
            -
                    (target - start) / length * time + start
         
     | 
| 
      
 65 
     | 
    
         
            +
                    end 
         
     | 
| 
      
 66 
     | 
    
         
            +
                    @a_s = 1 / @attack
         
     | 
| 
       80 
67 
     | 
    
         
             
                  end
         
     | 
| 
       81 
68 
     | 
    
         
             
                end
         
     | 
| 
       82 
69 
     | 
    
         
             
              end
         
     | 
| 
       83 
     | 
    
         
            -
            end
         
     | 
| 
      
 70 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -0,0 +1,83 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            module SynthBlocks
         
     | 
| 
      
 2 
     | 
    
         
            +
              module Mod
         
     | 
| 
      
 3 
     | 
    
         
            +
                ##
         
     | 
| 
      
 4 
     | 
    
         
            +
                # Implementation of a linear ADSR envelope generator with a tracking
         
     | 
| 
      
 5 
     | 
    
         
            +
                # value so that envelope restarts don't click
         
     | 
| 
      
 6 
     | 
    
         
            +
                class AdsrOld
         
     | 
| 
      
 7 
     | 
    
         
            +
                  ##
         
     | 
| 
      
 8 
     | 
    
         
            +
                  # attack time in seconds
         
     | 
| 
      
 9 
     | 
    
         
            +
                  attr_accessor :attack
         
     | 
| 
      
 10 
     | 
    
         
            +
             
     | 
| 
      
 11 
     | 
    
         
            +
                  ##
         
     | 
| 
      
 12 
     | 
    
         
            +
                  # decay time in seconds
         
     | 
| 
      
 13 
     | 
    
         
            +
                  attr_accessor :decay
         
     | 
| 
      
 14 
     | 
    
         
            +
                  ##
         
     | 
| 
      
 15 
     | 
    
         
            +
                  # sustain level (0.0-1.0)
         
     | 
| 
      
 16 
     | 
    
         
            +
                  attr_accessor :sustain
         
     | 
| 
      
 17 
     | 
    
         
            +
             
     | 
| 
      
 18 
     | 
    
         
            +
                  ##
         
     | 
| 
      
 19 
     | 
    
         
            +
                  # release time in seconds
         
     | 
| 
      
 20 
     | 
    
         
            +
                  attr_accessor :release
         
     | 
| 
      
 21 
     | 
    
         
            +
             
     | 
| 
      
 22 
     | 
    
         
            +
                  ##
         
     | 
| 
      
 23 
     | 
    
         
            +
                  # Creates new ADSR envelope
         
     | 
| 
      
 24 
     | 
    
         
            +
                  #
         
     | 
| 
      
 25 
     | 
    
         
            +
                  # attack, decay and release are times in seconds (as float)
         
     | 
| 
      
 26 
     | 
    
         
            +
                  #
         
     | 
| 
      
 27 
     | 
    
         
            +
                  # sustain should be between 0 and 1
         
     | 
| 
      
 28 
     | 
    
         
            +
                  def initialize(attack, decay, sustain, release)
         
     | 
| 
      
 29 
     | 
    
         
            +
                    @value = 0
         
     | 
| 
      
 30 
     | 
    
         
            +
                    @start_value = 0
         
     | 
| 
      
 31 
     | 
    
         
            +
                    @attack = attack
         
     | 
| 
      
 32 
     | 
    
         
            +
                    @decay = decay
         
     | 
| 
      
 33 
     | 
    
         
            +
                    @sustain = sustain
         
     | 
| 
      
 34 
     | 
    
         
            +
                    @release = release
         
     | 
| 
      
 35 
     | 
    
         
            +
                  end
         
     | 
| 
      
 36 
     | 
    
         
            +
             
     | 
| 
      
 37 
     | 
    
         
            +
                  ##
         
     | 
| 
      
 38 
     | 
    
         
            +
                  # run the envelope.
         
     | 
| 
      
 39 
     | 
    
         
            +
                  #
         
     | 
| 
      
 40 
     | 
    
         
            +
                  # if released is given (should be <= t), the envelope will enter the release stage
         
     | 
| 
      
 41 
     | 
    
         
            +
                  # returns the current value between 0 and 1
         
     | 
| 
      
 42 
     | 
    
         
            +
                  def run(t, released)
         
     | 
| 
      
 43 
     | 
    
         
            +
                    attack_decay = attack + decay
         
     | 
| 
      
 44 
     | 
    
         
            +
                    if !released
         
     | 
| 
      
 45 
     | 
    
         
            +
                      if t < 0.0001 # initialize start value (slightly hacky, but works)
         
     | 
| 
      
 46 
     | 
    
         
            +
                        @start_value = @value
         
     | 
| 
      
 47 
     | 
    
         
            +
                        return @start_value
         
     | 
| 
      
 48 
     | 
    
         
            +
                      end
         
     | 
| 
      
 49 
     | 
    
         
            +
                      if t <= attack # attack
         
     | 
| 
      
 50 
     | 
    
         
            +
                        return @value = linear(@start_value, 1, attack, t)
         
     | 
| 
      
 51 
     | 
    
         
            +
                      end
         
     | 
| 
      
 52 
     | 
    
         
            +
                      if t > attack && t < attack_decay # decay
         
     | 
| 
      
 53 
     | 
    
         
            +
                        return @value = linear(1.0, sustain, decay, t - attack)
         
     | 
| 
      
 54 
     | 
    
         
            +
                      end
         
     | 
| 
      
 55 
     | 
    
         
            +
                      if t >= attack + decay # sustain
         
     | 
| 
      
 56 
     | 
    
         
            +
                        return @value = sustain
         
     | 
| 
      
 57 
     | 
    
         
            +
                      end
         
     | 
| 
      
 58 
     | 
    
         
            +
                    else # release
         
     | 
| 
      
 59 
     | 
    
         
            +
                      if released <= attack # when released in attack phase
         
     | 
| 
      
 60 
     | 
    
         
            +
                        attack_level = linear(@start_value, 1, attack, released)
         
     | 
| 
      
 61 
     | 
    
         
            +
                        return [linear(attack_level, 0, release, t - released), 0].max
         
     | 
| 
      
 62 
     | 
    
         
            +
                      end
         
     | 
| 
      
 63 
     | 
    
         
            +
                      if released > attack && released <= attack_decay # when released in decay phase
         
     | 
| 
      
 64 
     | 
    
         
            +
                        decay_level = linear(1.0, sustain, decay, released - attack)
         
     | 
| 
      
 65 
     | 
    
         
            +
                        return @value = [linear(decay_level, 0, release, t - released), 0].max
         
     | 
| 
      
 66 
     | 
    
         
            +
                      end
         
     | 
| 
      
 67 
     | 
    
         
            +
                      if released > attack_decay  # normal release
         
     | 
| 
      
 68 
     | 
    
         
            +
                        return @value = [linear(sustain, 0, release, t - released), 0].max
         
     | 
| 
      
 69 
     | 
    
         
            +
                      end
         
     | 
| 
      
 70 
     | 
    
         
            +
                    end
         
     | 
| 
      
 71 
     | 
    
         
            +
                    0.0
         
     | 
| 
      
 72 
     | 
    
         
            +
                  end
         
     | 
| 
      
 73 
     | 
    
         
            +
             
     | 
| 
      
 74 
     | 
    
         
            +
                  private
         
     | 
| 
      
 75 
     | 
    
         
            +
             
     | 
| 
      
 76 
     | 
    
         
            +
                  def linear(start, target, length, time)
         
     | 
| 
      
 77 
     | 
    
         
            +
                    return start if time == 0
         
     | 
| 
      
 78 
     | 
    
         
            +
                    return target if length == 0
         
     | 
| 
      
 79 
     | 
    
         
            +
                    (target - start) / length * time + start
         
     | 
| 
      
 80 
     | 
    
         
            +
                  end
         
     | 
| 
      
 81 
     | 
    
         
            +
                end
         
     | 
| 
      
 82 
     | 
    
         
            +
              end
         
     | 
| 
      
 83 
     | 
    
         
            +
            end
         
     | 
    
        metadata
    CHANGED
    
    | 
         @@ -1,14 +1,14 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            --- !ruby/object:Gem::Specification
         
     | 
| 
       2 
2 
     | 
    
         
             
            name: synth_blocks
         
     | 
| 
       3 
3 
     | 
    
         
             
            version: !ruby/object:Gem::Version
         
     | 
| 
       4 
     | 
    
         
            -
              version:  
     | 
| 
      
 4 
     | 
    
         
            +
              version: 2.0.0
         
     | 
| 
       5 
5 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       6 
6 
     | 
    
         
             
            authors:
         
     | 
| 
       7 
7 
     | 
    
         
             
            - Jan Krutisch
         
     | 
| 
       8 
8 
     | 
    
         
             
            autorequire: 
         
     | 
| 
       9 
9 
     | 
    
         
             
            bindir: bin
         
     | 
| 
       10 
10 
     | 
    
         
             
            cert_chain: []
         
     | 
| 
       11 
     | 
    
         
            -
            date: 2020-07- 
     | 
| 
      
 11 
     | 
    
         
            +
            date: 2020-07-18 00:00:00.000000000 Z
         
     | 
| 
       12 
12 
     | 
    
         
             
            dependencies:
         
     | 
| 
       13 
13 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       14 
14 
     | 
    
         
             
              name: minitest
         
     | 
| 
         @@ -81,6 +81,7 @@ files: 
     | 
|
| 
       81 
81 
     | 
    
         
             
            - lib/synth_blocks/mixer/mixer_channel.rb
         
     | 
| 
       82 
82 
     | 
    
         
             
            - lib/synth_blocks/mixer/send_channel.rb
         
     | 
| 
       83 
83 
     | 
    
         
             
            - lib/synth_blocks/mod/adsr.rb
         
     | 
| 
      
 84 
     | 
    
         
            +
            - lib/synth_blocks/mod/adsr_old.rb
         
     | 
| 
       84 
85 
     | 
    
         
             
            - lib/synth_blocks/mod/envelope.rb
         
     | 
| 
       85 
86 
     | 
    
         
             
            - lib/synth_blocks/sequencer/sequencer_dsl.rb
         
     | 
| 
       86 
87 
     | 
    
         
             
            - lib/synth_blocks/synth/monosynth.rb
         
     | 
| 
         @@ -90,7 +91,7 @@ homepage: https://rubysynth.fun 
     | 
|
| 
       90 
91 
     | 
    
         
             
            licenses:
         
     | 
| 
       91 
92 
     | 
    
         
             
            - AGPL-3.0-only
         
     | 
| 
       92 
93 
     | 
    
         
             
            metadata:
         
     | 
| 
       93 
     | 
    
         
            -
              source_code_uri: https://github.com/halfbyte/ 
     | 
| 
      
 94 
     | 
    
         
            +
              source_code_uri: https://github.com/halfbyte/ruby_synth_blocks
         
     | 
| 
       94 
95 
     | 
    
         
             
            post_install_message: 
         
     | 
| 
       95 
96 
     | 
    
         
             
            rdoc_options: []
         
     | 
| 
       96 
97 
     | 
    
         
             
            require_paths:
         
     |