Class: Mfcc::Calculator

Inherits:
Object
  • Object
show all
Includes:
Compressor, Dct, Dft, Frame, Hamming, Mel, Preemphasis
Defined in:
lib/mfcc.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Dct

#dct

Methods included from Compressor

#compress

Methods included from Mel

#filter_banks, #mel

Methods included from Dft

#dft

Methods included from Hamming

#hamming

Methods included from Frame

#frame

Methods included from Preemphasis

#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, options = {})
  @data = data
  @frame_size = options.fetch(:frame_size, 400)
  @frame_step = options.fetch(:frame_step, 160)
  @alpha = options.fetch(:alpha, 0.46)
  @emphasis = options.fetch(:emphasis, 0.97)
  @mel_filters_length = options.fetch(:mel_filters_length, 20)
  @fft_size = options.fetch(:fft_size, 512)
  @sample_rate = options.fetch(:sample_rate, 16_000)
  @dct_order = options.fetch(:dct_order, 13)
end

Instance Attribute Details

#alphaObject (readonly)

Returns the value of attribute alpha.



29
30
31
# File 'lib/mfcc.rb', line 29

def alpha
  @alpha
end

#dataObject (readonly)

Returns the value of attribute data.



29
30
31
# File 'lib/mfcc.rb', line 29

def data
  @data
end

#dct_orderObject (readonly)

Returns the value of attribute dct_order.



29
30
31
# File 'lib/mfcc.rb', line 29

def dct_order
  @dct_order
end

#emphasisObject (readonly)

Returns the value of attribute emphasis.



29
30
31
# File 'lib/mfcc.rb', line 29

def emphasis
  @emphasis
end

#fft_sizeObject (readonly)

Returns the value of attribute fft_size.



29
30
31
# File 'lib/mfcc.rb', line 29

def fft_size
  @fft_size
end

#frame_sizeObject (readonly)

Returns the value of attribute frame_size.



29
30
31
# File 'lib/mfcc.rb', line 29

def frame_size
  @frame_size
end

#frame_stepObject (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_lengthObject (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

#optionsObject (readonly)

Returns the value of attribute options.



29
30
31
# File 'lib/mfcc.rb', line 29

def options
  @options
end

#sample_rateObject (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

#mapObject



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