Class: SRC::Resample
- Inherits:
-
Object
- Object
- SRC::Resample
- Defined in:
- lib/ruby-libsamplerate/resample.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
- #destroy ⇒ Object
-
#initialize(input_rate, output_rate, channels = 1, type = SRC_SINC_FASTEST) ⇒ Resample
constructor
A new instance of Resample.
- #process(data) ⇒ Object
- #reset ⇒ Object
- #src_ratio ⇒ Object
Constructor Details
#initialize(input_rate, output_rate, channels = 1, type = SRC_SINC_FASTEST) ⇒ Resample
Returns a new instance of Resample.
5 6 7 8 9 10 11 12 |
# File 'lib/ruby-libsamplerate/resample.rb', line 5 def initialize(input_rate, output_rate, channels=1, type=SRC_SINC_FASTEST) @input_rate = input_rate @output_rate = output_rate @channels = channels error = FFI::MemoryPointer.new :int, 1 @state = SRC.src_new type, channels, error end |
Instance Attribute Details
#channels ⇒ Object
Returns the value of attribute channels.
3 4 5 |
# File 'lib/ruby-libsamplerate/resample.rb', line 3 def channels @channels end |
#input_rate ⇒ Object
Returns the value of attribute input_rate.
3 4 5 |
# File 'lib/ruby-libsamplerate/resample.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/resample.rb', line 3 def output_rate @output_rate end |
Instance Method Details
#destroy ⇒ Object
48 49 50 |
# File 'lib/ruby-libsamplerate/resample.rb', line 48 def destroy SRC.src_delete @state end |
#process(data) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/ruby-libsamplerate/resample.rb', line 18 def process(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 = Data.new src_data[:data_in] = input src_data[:input_frames] = frames src_data[:data_out] = output src_data[:output_frames] = rs_frames src_data[:src_ratio] = src_ratio src_data[:end_of_input] = 0 res = SRC.src_process @state, src_data raise SRCError.from_int res unless res == 0 frames_written = src_data[:output_frames_gen] src_data[:data_out].read_array_of_float frames_written * @channels end |
#reset ⇒ Object
44 45 46 |
# File 'lib/ruby-libsamplerate/resample.rb', line 44 def reset SRC.src_reset @state end |
#src_ratio ⇒ Object
14 15 16 |
# File 'lib/ruby-libsamplerate/resample.rb', line 14 def src_ratio @output_rate.to_f / @input_rate.to_f end |