Class: STFTSpectrogram::AudioFile
- Inherits:
-
Object
- Object
- STFTSpectrogram::AudioFile
- Includes:
- WaveFile
- Defined in:
- lib/audio/audio_file.rb
Overview
Represents wave file
Constant Summary collapse
- SAMPLE_RATE =
441_00
Instance Attribute Summary collapse
-
#window_overlap ⇒ Object
Returns the value of attribute window_overlap.
-
#window_size ⇒ Object
Returns the value of attribute window_size.
Class Method Summary collapse
Instance Method Summary collapse
-
#current_time ⇒ Object
Gets the time corresponding to the window pointers location.
-
#end? ⇒ Boolean
Checks if the window pointer is at the end of the file.
-
#initialize(path, wsize = 1, woverlap = 0) ⇒ AudioFile
constructor
A new instance of AudioFile.
-
#next_window ⇒ Object
Gets window_size of data from audio samples and moves the window pointer.
-
#reset ⇒ Object
Resets the window pointer.
Constructor Details
#initialize(path, wsize = 1, woverlap = 0) ⇒ AudioFile
Returns a new instance of AudioFile.
13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/audio/audio_file.rb', line 13 def initialize(path, wsize = 1, woverlap = 0) unless File.file?(path) raise IOError, "File '" + path + "' does not exist!" end @samples = [] self.window_size = wsize self.window_overlap = woverlap @window_overlap = @window_size / 2 if @window_size <= @window_overlap @window_pos = 0 read_data(path) end |
Instance Attribute Details
#window_overlap ⇒ Object
Returns the value of attribute window_overlap.
8 9 10 |
# File 'lib/audio/audio_file.rb', line 8 def window_overlap @window_overlap end |
#window_size ⇒ Object
Returns the value of attribute window_size.
9 10 11 |
# File 'lib/audio/audio_file.rb', line 9 def window_size @window_size end |
Class Method Details
.sample_rate ⇒ Object
58 59 60 |
# File 'lib/audio/audio_file.rb', line 58 def self.sample_rate SAMPLE_RATE end |
Instance Method Details
#current_time ⇒ Object
Gets the time corresponding to the window pointers location
68 69 70 |
# File 'lib/audio/audio_file.rb', line 68 def current_time (@window_pos + @window_size / 2) / (SAMPLE_RATE / 1000) end |
#end? ⇒ Boolean
Checks if the window pointer is at the end of the file
73 74 75 |
# File 'lib/audio/audio_file.rb', line 73 def end? @window_pos + @window_size >= @samples.length end |
#next_window ⇒ Object
Gets window_size of data from audio samples and moves the window pointer
48 49 50 51 52 53 54 55 56 |
# File 'lib/audio/audio_file.rb', line 48 def next_window return [] if end? slice = @samples[@window_pos, @window_size] slice.fill(0, slice.length..@window_size - 1) @window_pos += @window_size - @window_overlap slice end |
#reset ⇒ Object
Resets the window pointer
63 64 65 |
# File 'lib/audio/audio_file.rb', line 63 def reset @window_pos = 0 end |