Class: Awaaz::Utils::Soundread
- Inherits:
-
Object
- Object
- Awaaz::Utils::Soundread
- Defined in:
- lib/awaaz/utils/soundread.rb
Overview
A helper that mimics librosa.load using libsndfile via FFI.
-
Always returns Float32 samples normalized in [-1.0, 1.0]
-
Preserves channel structure (returns shape ‘[channels, frames]`)
-
Returns ‘[data, channels, sr]` where:
-
‘data` = Numo::SFloat array (2D, shape: channels x frames)
-
‘channels` = Integer number of channels
-
‘sr` = sample rate (Integer)
-
Instance Method Summary collapse
-
#initialize(filename, **resampling_options) ⇒ Soundread
constructor
Initializes a Soundread instance.
-
#read ⇒ Array<(Numo::SFloat, Integer, Integer)>
Reads the audio file, returning samples, number of channels, and sample rate.
Constructor Details
#initialize(filename, **resampling_options) ⇒ Soundread
Initializes a Soundread instance.
26 27 28 29 |
# File 'lib/awaaz/utils/soundread.rb', line 26 def initialize(filename, **) @filename = filename @resampling_options = end |
Instance Method Details
#read ⇒ Array<(Numo::SFloat, Integer, Integer)>
Reads the audio file, returning samples, number of channels, and sample rate.
41 42 43 44 45 46 47 48 49 50 |
# File 'lib/awaaz/utils/soundread.rb', line 41 def read info, sndfile = open_file frames, channels, sr = extract_info(info) buffer, read_frames = read_buffer(sndfile, frames, channels) close_file(sndfile) data = process_data(buffer, read_frames, channels) [resample(data, sr, channels), channels, sr] end |