Class: Mfcc::Calculator
- Inherits:
-
Object
- Object
- Mfcc::Calculator
- Includes:
- Compressor, Dct, Dft, Frame, Hamming, Mel, Preemphasis
- Defined in:
- lib/mfcc.rb
Instance Attribute Summary collapse
-
#alpha ⇒ Object
readonly
Returns the value of attribute alpha.
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#dct_order ⇒ Object
readonly
Returns the value of attribute dct_order.
-
#emphasis ⇒ Object
readonly
Returns the value of attribute emphasis.
-
#fft_size ⇒ Object
readonly
Returns the value of attribute fft_size.
-
#frame_size ⇒ Object
readonly
Returns the value of attribute frame_size.
-
#frame_step ⇒ Object
readonly
Returns the value of attribute frame_step.
-
#mel_filters_length ⇒ Object
readonly
Returns the value of attribute mel_filters_length.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#sample_rate ⇒ Object
readonly
Returns the value of attribute sample_rate.
Instance Method Summary collapse
-
#initialize(data, options = {}) ⇒ Calculator
constructor
A new instance of Calculator.
- #map ⇒ Object
Methods included from Dct
Methods included from Compressor
Methods included from Mel
Methods included from Dft
Methods included from Hamming
Methods included from Frame
Methods included from Preemphasis
Constructor Details
#initialize(data, options = {}) ⇒ Calculator
Returns a new instance of Calculator.
32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/mfcc.rb', line 32 def initialize(data, = {}) @data = data @frame_size = .fetch(:frame_size, 400) @frame_step = .fetch(:frame_step, 160) @alpha = .fetch(:alpha, 0.46) @emphasis = .fetch(:emphasis, 0.97) @mel_filters_length = .fetch(:mel_filters_length, 20) @fft_size = .fetch(:fft_size, 512) @sample_rate = .fetch(:sample_rate, 16_000) @dct_order = .fetch(:dct_order, 13) end |
Instance Attribute Details
#alpha ⇒ Object (readonly)
Returns the value of attribute alpha.
29 30 31 |
# File 'lib/mfcc.rb', line 29 def alpha @alpha end |
#data ⇒ Object (readonly)
Returns the value of attribute data.
29 30 31 |
# File 'lib/mfcc.rb', line 29 def data @data end |
#dct_order ⇒ Object (readonly)
Returns the value of attribute dct_order.
29 30 31 |
# File 'lib/mfcc.rb', line 29 def dct_order @dct_order end |
#emphasis ⇒ Object (readonly)
Returns the value of attribute emphasis.
29 30 31 |
# File 'lib/mfcc.rb', line 29 def emphasis @emphasis end |
#fft_size ⇒ Object (readonly)
Returns the value of attribute fft_size.
29 30 31 |
# File 'lib/mfcc.rb', line 29 def fft_size @fft_size end |
#frame_size ⇒ Object (readonly)
Returns the value of attribute frame_size.
29 30 31 |
# File 'lib/mfcc.rb', line 29 def frame_size @frame_size end |
#frame_step ⇒ Object (readonly)
Returns the value of attribute frame_step.
29 30 31 |
# File 'lib/mfcc.rb', line 29 def frame_step @frame_step end |
#mel_filters_length ⇒ Object (readonly)
Returns the value of attribute mel_filters_length.
29 30 31 |
# File 'lib/mfcc.rb', line 29 def mel_filters_length @mel_filters_length end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
29 30 31 |
# File 'lib/mfcc.rb', line 29 def end |
#sample_rate ⇒ Object (readonly)
Returns the value of attribute sample_rate.
29 30 31 |
# File 'lib/mfcc.rb', line 29 def sample_rate @sample_rate end |
Instance Method Details
#map ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/mfcc.rb', line 44 def map return to_enum(:map) { self.data.size || Float::Infinity } unless block_given? data = preemphasis(self.data) data = frame(data) data = data.map do |frame| frame = hamming(frame) frame = dft(frame) frame = Mfcc.magnitude(frame) frame = compress(frame) frame = dct(frame) yield frame end end |