Class: Shazamio::FrequencyPeak
- Inherits:
-
Object
- Object
- Shazamio::FrequencyPeak
- 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
-
#corrected_peak_frequency_bin ⇒ Object
Returns the value of attribute corrected_peak_frequency_bin.
-
#fft_pass_number ⇒ Object
Returns the value of attribute fft_pass_number.
-
#peak_magnitude ⇒ Object
Returns the value of attribute peak_magnitude.
-
#sample_rate_hz ⇒ Object
Returns the value of attribute sample_rate_hz.
Instance Method Summary collapse
- #amplitude_pcm ⇒ Object
- #frequency_hz ⇒ Object
-
#initialize(fft_pass_number, peak_magnitude, corrected_peak_frequency_bin, sample_rate_hz) ⇒ FrequencyPeak
constructor
A new instance of FrequencyPeak.
- #seconds ⇒ Object
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_bin ⇒ Object
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_number ⇒ Object
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_magnitude ⇒ Object
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_hz ⇒ Object
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_pcm ⇒ Object
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_hz ⇒ Object
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 |
#seconds ⇒ Object
31 32 33 |
# File 'lib/shazamio/signature.rb', line 31 def seconds (fft_pass_number * 128).to_f / sample_rate_hz end |