Class: DSP::Waveform
- Inherits:
-
Data
- Object
- Data
- DSP::Waveform
- Defined in:
- lib/dsprb/waveform.rb,
sig/dsprb.rbs
Instance Attribute Summary collapse
-
#sample_rate ⇒ Object
readonly
Returns the value of attribute sample_rate.
-
#samples ⇒ Object
readonly
Returns the value of attribute samples.
Class Method Summary collapse
Instance Method Summary collapse
- #duration ⇒ ::Float
- #empty? ⇒ Boolean
- #frames(window:, hop:) ⇒ ::Array[frame]
-
#initialize(samples:, sample_rate:) ⇒ Waveform
constructor
A new instance of Waveform.
- #length ⇒ ::Integer
- #nyquist ⇒ ::Float
- #seconds_to_samples(seconds) ⇒ ::Integer
- #to_h ⇒ ::Hash[::Symbol, untyped]
- #with ⇒ Waveform
Constructor Details
#initialize(samples:, sample_rate:) ⇒ Waveform
Returns a new instance of Waveform.
5 6 7 8 9 10 |
# File 'lib/dsprb/waveform.rb', line 5 def initialize(samples:, sample_rate:) rate = Float(sample_rate) raise ArgumentError, "sample rate must be positive, got #{rate}" unless rate.positive? super(samples: samples, sample_rate: rate) end |
Instance Attribute Details
#sample_rate ⇒ Object (readonly)
Returns the value of attribute sample_rate
4 5 6 |
# File 'lib/dsprb/waveform.rb', line 4 def sample_rate @sample_rate end |
#samples ⇒ Object (readonly)
Returns the value of attribute samples
4 5 6 |
# File 'lib/dsprb/waveform.rb', line 4 def samples @samples end |
Class Method Details
.new ⇒ Waveform
60 |
# File 'sig/dsprb.rbs', line 60
def self.new: (samples: samples, sample_rate: ::Numeric) -> Waveform
|
Instance Method Details
#duration ⇒ ::Float
14 |
# File 'lib/dsprb/waveform.rb', line 14 def duration = samples.length / sample_rate |
#empty? ⇒ Boolean
18 |
# File 'lib/dsprb/waveform.rb', line 18 def empty? = samples.empty? |
#frames(window:, hop:) ⇒ ::Array[frame]
20 |
# File 'lib/dsprb/waveform.rb', line 20 def frames(window:, hop:) = Framing.frames(samples, window: window, hop: hop) |
#length ⇒ ::Integer
12 |
# File 'lib/dsprb/waveform.rb', line 12 def length = samples.length |
#nyquist ⇒ ::Float
16 |
# File 'lib/dsprb/waveform.rb', line 16 def nyquist = sample_rate / 2.0 |
#seconds_to_samples(seconds) ⇒ ::Integer
22 |
# File 'lib/dsprb/waveform.rb', line 22 def seconds_to_samples(seconds) = (seconds * sample_rate).round |
#to_h ⇒ ::Hash[::Symbol, untyped]
68 |
# File 'sig/dsprb.rbs', line 68
def to_h: () -> ::Hash[::Symbol, untyped]
|