Class: RbSDL2::Audio::AudioBuffer

Inherits:
Object
  • Object
show all
Includes:
AudioSpecReader
Defined in:
lib/rb_sdl2/audio/audio_buffer.rb

Defined Under Namespace

Classes: AudioBufferPointer

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ptr, size, spec) ⇒ AudioBuffer

Returns a new instance of AudioBuffer.



23
24
25
26
27
# File 'lib/rb_sdl2/audio/audio_buffer.rb', line 23

def initialize(ptr, size, spec)
  @ptr = ptr
  @size = size
  @spec = spec
end

Instance Attribute Details

#sizeObject (readonly) Also known as: length

Returns the value of attribute size.



29
30
31
# File 'lib/rb_sdl2/audio/audio_buffer.rb', line 29

def size
  @size
end

#specObject (readonly)

Returns the value of attribute spec.



32
33
34
# File 'lib/rb_sdl2/audio/audio_buffer.rb', line 32

def spec
  @spec
end

Class Method Details

.load(obj) ⇒ Object



11
12
13
14
15
16
17
18
19
20
# File 'lib/rb_sdl2/audio/audio_buffer.rb', line 11

def load(obj)
  RbSDL2.open_rw(obj) do |rw|
    spec = AudioSpec.new
    buf = ::FFI::MemoryPointer.new(:pointer)
    len = ::FFI::MemoryPointer.new(:uint32)
    err = ::SDL::LoadWAV_RW(rw, 0, spec, buf, len)
    raise RbSDL2Error if err.null?
    new(AudioBufferPointer.new(buf.read_pointer), len.read_uint32, spec)
  end
end

Instance Method Details

#to_ptrObject



37
# File 'lib/rb_sdl2/audio/audio_buffer.rb', line 37

def to_ptr = @ptr

#to_strObject



39
# File 'lib/rb_sdl2/audio/audio_buffer.rb', line 39

def to_str = @ptr.read_bytes(size)