class DXRubySDL::Sound::Wave

Public Class Methods

new(filename) click to toggle source
# File lib/dxruby_sdl/sound.rb, line 74
def initialize(filename)
  @wave = SDL::Mixer::Wave.load(filename)
  @last_played_channel = nil
  @_loop_count = 0
end

Public Instance Methods

loop_count=(n) click to toggle source
# File lib/dxruby_sdl/sound.rb, line 89
def loop_count=(n)
  @_loop_count = n
end
play() click to toggle source
# File lib/dxruby_sdl/sound.rb, line 80
def play
  @last_played_channel = SDL::Mixer.play_channel(-1, @wave, @_loop_count)
rescue SDL::Error => e
  if /No free channels available/ =~ e.message
    SDL::Mixer.halt(@last_played_channel == 0 ? 1 : 0)
    retry
  end
end
set_volume(volume, time = 0) click to toggle source
# File lib/dxruby_sdl/sound.rb, line 93
def set_volume(volume, time = 0)
  if time > 0
    raise NotImplementedError, 'Sound#set_volume(volume, time != 0)'
  end
  @wave.set_volume(dxruby_volume_to_sdl_volume(volume))
end
stop() click to toggle source
# File lib/dxruby_sdl/sound.rb, line 100
def stop
  SDL::Mixer.halt(@last_played_channel) if @last_played_channel
end