Class: Shazamio::FrequencyPeak

Inherits:
Object
  • Object
show all
Defined in:
lib/shazamio/signature.rb

Overview

A single detected FFT peak: which frequency band, at what time offset, magnitude and (corrected) frequency bin. Ported from signature.py.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(fft_pass_number, peak_magnitude, corrected_peak_frequency_bin, sample_rate_hz) ⇒ FrequencyPeak

Returns a new instance of FrequencyPeak.



16
17
18
19
20
21
# File 'lib/shazamio/signature.rb', line 16

def initialize(fft_pass_number, peak_magnitude, corrected_peak_frequency_bin, sample_rate_hz)
  @fft_pass_number = fft_pass_number
  @peak_magnitude = peak_magnitude
  @corrected_peak_frequency_bin = corrected_peak_frequency_bin
  @sample_rate_hz = sample_rate_hz
end

Instance Attribute Details

#corrected_peak_frequency_binObject

Returns the value of attribute corrected_peak_frequency_bin.



14
15
16
# File 'lib/shazamio/signature.rb', line 14

def corrected_peak_frequency_bin
  @corrected_peak_frequency_bin
end

#fft_pass_numberObject

Returns the value of attribute fft_pass_number.



14
15
16
# File 'lib/shazamio/signature.rb', line 14

def fft_pass_number
  @fft_pass_number
end

#peak_magnitudeObject

Returns the value of attribute peak_magnitude.



14
15
16
# File 'lib/shazamio/signature.rb', line 14

def peak_magnitude
  @peak_magnitude
end

#sample_rate_hzObject

Returns the value of attribute sample_rate_hz.



14
15
16
# File 'lib/shazamio/signature.rb', line 14

def sample_rate_hz
  @sample_rate_hz
end

Instance Method Details

#amplitude_pcmObject



27
28
29
# File 'lib/shazamio/signature.rb', line 27

def amplitude_pcm
  Math.sqrt(Math.exp((peak_magnitude - 6144) / 1477.3) * (1 << 17) / 2) / 1024
end

#frequency_hzObject



23
24
25
# File 'lib/shazamio/signature.rb', line 23

def frequency_hz
  corrected_peak_frequency_bin * (sample_rate_hz / 2.0 / 1024 / 64)
end

#secondsObject



31
32
33
# File 'lib/shazamio/signature.rb', line 31

def seconds
  (fft_pass_number * 128).to_f / sample_rate_hz
end