Class: SFML::SoundBuffer

Inherits:
Object
  • Object
show all
Defined in:
lib/sfml/audio/sound_buffer.rb

Overview

Decoded audio data held in memory. Use it to back one or more Sound instances. Loaded from .wav, .ogg, .flac, .mp3 (depends on CSFML build).

buffer = SFML::SoundBuffer.load("assets/blip.wav")
sound  = SFML::Sound.new(buffer)
sound.play

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#handleObject (readonly)

:nodoc:



30
31
32
# File 'lib/sfml/audio/sound_buffer.rb', line 30

def handle
  @handle
end

Class Method Details

.load(path) ⇒ Object

Raises:



9
10
11
12
13
14
15
# File 'lib/sfml/audio/sound_buffer.rb', line 9

def self.load(path)
  ptr = C::Audio.sfSoundBuffer_createFromFile(path.to_s)
  raise Error, "Could not load sound buffer from #{path.inspect}" if ptr.null?
  buf = allocate
  buf.send(:_take_ownership, ptr)
  buf
end

Instance Method Details

#channel_countObject



19
# File 'lib/sfml/audio/sound_buffer.rb', line 19

def channel_count = C::Audio.sfSoundBuffer_getChannelCount(@handle)

#durationObject



17
# File 'lib/sfml/audio/sound_buffer.rb', line 17

def duration      = Time.from_native(C::Audio.sfSoundBuffer_getDuration(@handle))

#sample_rateObject



18
# File 'lib/sfml/audio/sound_buffer.rb', line 18

def sample_rate   = C::Audio.sfSoundBuffer_getSampleRate(@handle)

#save(path) ⇒ Object

Write the buffer out to disk. Format is inferred from the file extension (.wav / .ogg / .flac, depends on what CSFML was built with).

Raises:



24
25
26
27
28
# File 'lib/sfml/audio/sound_buffer.rb', line 24

def save(path)
  ok = C::Audio.sfSoundBuffer_saveToFile(@handle, path.to_s)
  raise Error, "could not save SoundBuffer to #{path.inspect}" unless ok
  path
end