Class: CoreAudio::AudioBufferList
- Inherits:
-
FFI::Struct
- Object
- FFI::Struct
- CoreAudio::AudioBufferList
- Defined in:
- lib/macos/core_audio/audio_types.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#buffers ⇒ Array
The buffers.
-
#bytes ⇒ String
The raw bytes.
-
#bytesize ⇒ Number
The total number of bytes in the buffer list.
-
#samples(type, bytes_per_channel) ⇒ Array<Float,Integer>
Retrieve the samples as an Array, after converting to the requested type.
Class Method Details
.buffer_list(channels: 1, size: nil) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/macos/core_audio/audio_types.rb', line 31 def self.buffer_list(channels:1, size:nil) self.new.tap do |list| list[:mNumberBuffers] = 1 list[:mBuffers][:mNumberChannels] = channels if( size ) list[:mBuffers][:mData] = FFI::MemoryPointer.new(size) list[:mBuffers][:mDataByteSize] = size else list[:mBuffers][:mDataByteSize] = 0 end end end |
Instance Method Details
#buffers ⇒ Array
Returns the buffers.
46 47 48 49 |
# File 'lib/macos/core_audio/audio_types.rb', line 46 def buffers raise("Can't handle multiple buffers yet") if self[:mNumberBuffers] > 1 [self[:mBuffers]] end |
#bytes ⇒ String
Returns the raw bytes.
52 53 54 |
# File 'lib/macos/core_audio/audio_types.rb', line 52 def bytes buffers.map(&:bytes).join end |
#bytesize ⇒ Number
Returns the total number of bytes in the buffer list.
57 58 59 |
# File 'lib/macos/core_audio/audio_types.rb', line 57 def bytesize buffers.map(&:bytesize).reduce(&:+) end |
#samples(type, bytes_per_channel) ⇒ Array<Float,Integer>
Retrieve the samples as an Array, after converting to the requested type
65 66 67 68 69 70 71 |
# File 'lib/macos/core_audio/audio_types.rb', line 65 def samples(type, bytes_per_channel) if type == :float buffers.map {|buffer| buffer.samples_float(bytes_per_channel)}.flatten else buffers.map {|buffer| buffer.samples_int(bytes_per_channel)}.flatten end end |