Class: SRC::Simple
- Inherits:
-
Object
- Object
- SRC::Simple
- Defined in:
- lib/ruby-libsamplerate/simple.rb
Instance Attribute Summary collapse
-
#channels ⇒ Object
Returns the value of attribute channels.
-
#input_rate ⇒ Object
Returns the value of attribute input_rate.
-
#output_rate ⇒ Object
Returns the value of attribute output_rate.
Instance Method Summary collapse
-
#initialize(input_rate, output_rate, channels) ⇒ Simple
constructor
A new instance of Simple.
- #resample(data) ⇒ Object
- #src_ratio ⇒ Object
Constructor Details
#initialize(input_rate, output_rate, channels) ⇒ Simple
Returns a new instance of Simple.
5 6 7 8 9 |
# File 'lib/ruby-libsamplerate/simple.rb', line 5 def initialize(input_rate, output_rate, channels) @input_rate = input_rate @output_rate = output_rate @channels = channels end |
Instance Attribute Details
#channels ⇒ Object
Returns the value of attribute channels.
3 4 5 |
# File 'lib/ruby-libsamplerate/simple.rb', line 3 def channels @channels end |
#input_rate ⇒ Object
Returns the value of attribute input_rate.
3 4 5 |
# File 'lib/ruby-libsamplerate/simple.rb', line 3 def input_rate @input_rate end |
#output_rate ⇒ Object
Returns the value of attribute output_rate.
3 4 5 |
# File 'lib/ruby-libsamplerate/simple.rb', line 3 def output_rate @output_rate end |
Instance Method Details
#resample(data) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/ruby-libsamplerate/simple.rb', line 15 def resample(data) size = data.size frames = size / @channels rs_frames = (frames * src_ratio).to_i rs_size = rs_frames * @channels input = FFI::MemoryPointer.new :float, size output = FFI::MemoryPointer.new :float, rs_size input.write_array_of_float data src = Data.new src[:data_in] = input src[:input_frames] = frames src[:data_out] = output src[:output_frames] = rs_frames src[:src_ratio] = src_ratio res = SRC.src_simple src, SRC::SRC_SINC_FASTEST, @channels raise SRCError.from_int res unless res == 0 frames_written = src[:output_frames_gen] src[:data_out].read_array_of_float frames_written * @channels end |
#src_ratio ⇒ Object
11 12 13 |
# File 'lib/ruby-libsamplerate/simple.rb', line 11 def src_ratio @output_rate.to_f / @input_rate.to_f end |