Class: CoreAudio::AudioBufferList

Inherits:
FFI::Struct
  • Object
show all
Defined in:
lib/macos/core_audio/audio_types.rb

Class Method Summary collapse

Instance Method Summary collapse

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

#buffersArray

Returns the buffers.

Returns:

  • (Array)

    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

#bytesString

Returns the raw bytes.

Returns:

  • (String)

    the raw bytes



52
53
54
# File 'lib/macos/core_audio/audio_types.rb', line 52

def bytes
    buffers.map(&:bytes).join
end

#bytesizeNumber

Returns the total number of bytes in the buffer list.

Returns:

  • (Number)

    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

Parameters:

  • type (Symbol)

    :float or :int. Convert the samples to the given type.

  • bytes_per_channel (Number)

    the number of bytes for each sample

Returns:

  • (Array<Float,Integer>)

    an array of samples, converted to Float or Integer



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