Class: SDL2::Mixer::Chunk

Inherits:
Struct
  • Object
show all
Defined in:
lib/sdl2/mixer/chunk.rb

Overview

The internal format for an audio chunk

* allocated - :int
* abuf - :pointer of :uint8
* alen - :uint32
* volume - :uint8 "Per-sample volume, 0-128"

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Struct

#==, cast, create, #free, #initialize, #to_s, #update_members

Methods included from StructHelper

#member_readers, #member_writers

Constructor Details

This class inherits a constructor from SDL2::Struct

Class Method Details

.load_wav(filepath) ⇒ Object

Load a chunk from a wave file path (string)



26
27
28
# File 'lib/sdl2/mixer/chunk.rb', line 26

def self.load_wav(filepath)
  Mixer.load_wav!(filepath)
end

.playing?Boolean

Check if anything is playing?

Returns:

  • (Boolean)


44
45
46
# File 'lib/sdl2/mixer/chunk.rb', line 44

def self.playing?
  Mixer::playing?(-1)
end

.release(pointer) ⇒ Object

Release this structure with Mixer::free_chunk



50
51
52
# File 'lib/sdl2/mixer/chunk.rb', line 50

def self.release(pointer)
  Mixer::free_chunk(pointer)
end

Instance Method Details

#play(opts = {}) ⇒ Object

Plays chunk

opts[:channel]: defaults to -1
opts[:loop]: defaults to 0
opts[:ms]: defaults to -1


35
36
37
38
39
40
# File 'lib/sdl2/mixer/chunk.rb', line 35

def play(opts = {})
  channel = opts[:channel] || -1
  loop = opts[:loop] || 0
  ms = opts[:ms] || -1
  Mixer::play_channel_timed(channel, self, loop, ms)
end