Class: SPCore::DelayLine
- Inherits:
-
Object
- Object
- SPCore::DelayLine
- Includes:
- Hashmake::HashMakeable
- Defined in:
- lib/spcore/core/delay_line.rb
Overview
Constant Summary collapse
- ARG_SPECS =
Used to process hashed arguments in #initialize.
{ :sample_rate => arg_spec(:reqd => true, :type => Fixnum, :validator => ->(a){ a > 0.0 } ), :max_delay_seconds => arg_spec(:reqd => true, :type => Float, :validator => ->(a){ (a > 0.0) } ), :delay_seconds => arg_spec(:reqd => false, :type => Float, :default => 0.0, :validator => ->(a){ a >= 0.0 } ), }
Instance Attribute Summary collapse
-
#delay_samples ⇒ Object
readonly
Returns the value of attribute delay_samples.
-
#delay_seconds ⇒ Object
Returns the value of attribute delay_seconds.
-
#max_delay_seconds ⇒ Object
readonly
Returns the value of attribute max_delay_seconds.
-
#sample_rate ⇒ Object
readonly
Returns the value of attribute sample_rate.
Instance Method Summary collapse
-
#delayed_sample ⇒ Object
Get the sample which is delayed by the number of samples that equates to the set delay in seconds.
-
#initialize(args) ⇒ DelayLine
constructor
A new instance of DelayLine.
-
#push_sample(sample) ⇒ Object
Push a new sample through the circular buffer, overriding the oldest.
Constructor Details
#initialize(args) ⇒ DelayLine
A new instance of DelayLine. The circular buffer is filled by pushing an array of zeros.
22 23 24 25 26 27 28 |
# File 'lib/spcore/core/delay_line.rb', line 22 def initialize args hash_make args, DelayLine::ARG_SPECS raise ArgumentError, "delay_seconds #{delay_seconds} is greater than max_delay_seconds #{max_delay_seconds}" if @delay_seconds > @max_delay_seconds @buffer = CircularBuffer.new((@sample_rate * @max_delay_seconds) + 1, :override_when_full => true) @buffer.push_ary Array.new(@buffer.size, 0.0) self.delay_seconds=(@delay_seconds) end |
Instance Attribute Details
#delay_samples ⇒ Object (readonly)
Returns the value of attribute delay_samples.
8 9 10 |
# File 'lib/spcore/core/delay_line.rb', line 8 def delay_samples @delay_samples end |
#delay_seconds ⇒ Object
Returns the value of attribute delay_seconds.
8 9 10 |
# File 'lib/spcore/core/delay_line.rb', line 8 def delay_seconds @delay_seconds end |
#max_delay_seconds ⇒ Object (readonly)
Returns the value of attribute max_delay_seconds.
8 9 10 |
# File 'lib/spcore/core/delay_line.rb', line 8 def max_delay_seconds @max_delay_seconds end |
#sample_rate ⇒ Object (readonly)
Returns the value of attribute sample_rate.
8 9 10 |
# File 'lib/spcore/core/delay_line.rb', line 8 def sample_rate @sample_rate end |
Instance Method Details
#delayed_sample ⇒ Object
Get the sample which is delayed by the number of samples that equates to the set delay in seconds.
45 46 47 |
# File 'lib/spcore/core/delay_line.rb', line 45 def delayed_sample return @buffer.newest(@delay_samples) end |
#push_sample(sample) ⇒ Object
Push a new sample through the circular buffer, overriding the oldest.
39 40 41 |
# File 'lib/spcore/core/delay_line.rb', line 39 def push_sample sample @buffer.push sample end |