def play( options={} )
fade_in = (options[:fade_in] or 0)
repeats = (options[:repeats] or 0)
stop_after = (options[:stop_after] or nil)
fade_in =
if( fade_in < 0 )
raise ArgumentError, ":fade_in cannot be negative (got %.2f)"%fade_in
elsif( fade_in < 0.05 )
0
else
(fade_in * 1000).to_i
end
repeats =
if( repeats < -1 )
raise( ArgumentError,
":repeats cannot be negative, except -1 (got #{repeats})" )
else
repeats
end
stop_after =
if( stop_after.nil? )
-1
elsif( stop_after < 0 )
raise( ArgumentError,
":stop_after cannot be negative, (got %.2f)"%stop_after )
else
(stop_after * 1000).to_i
end
Rubygame.open_audio
if channel_active?
SDL::Mixer.HaltChannel( @channel )
end
@channel = SDL::Mixer.GroupAvailable(-1)
if @channel == -1
SDL::Mixer.AllocateChannels( SDL::Mixer.AllocateChannels(-1) + 1 )
@channel = SDL::Mixer.GroupAvailable(-1)
end
SDL::Mixer.Volume( @channel, (SDL::Mixer::MAX_VOLUME * @volume).to_i )
result =
if( fade_in <= 0 )
SDL::Mixer.PlayChannelTimed( @channel, @struct, repeats, stop_after )
else
SDL::Mixer.FadeInChannelTimed( @channel, @struct,
repeats, fade_in, stop_after )
end
if( result == -1 )
raise Rubygame::SDLError, "Could not play Sound: #{SDL.GetError()}"
end
return self
end