def self.open_audio( options={} )
return false if audio_open?
unless options.kind_of? Hash
raise TypeError, "invalid options Hash: #{options.inspect}"
end
buff = (options[:buffer] or 1024)
chan = (options[:channels] or 2)
freq = (options[:frequency] or SDL::Mixer::DEFAULT_FREQUENCY)
frmt = SDL::Mixer::DEFAULT_FORMAT
buff = if( buff <= 0 )
raise ArgumentError, "buffer size must be positive (got #{buff})"
elsif( buff & (buff - 1) != 0 )
raise( ArgumentError, "buffer size must be a power of 2 "+
"(e.g. 512, 1024) (got #{buff})" )
else
buff.to_i
end
chan = if( chan != 1 && chan != 2 )
raise( ArgumentError,
"channels must be 1 (mono) or 2 (stereo) (got #{chan})" )
else
chan.to_i
end
freq = if( freq <= 0 )
raise ArgumentError, "frequency must be positive (got #{freq})"
else
freq.to_i
end
result = SDL::Mixer.OpenAudio(freq, frmt, chan, buff)
if( result < 0 )
raise Rubygame::SDLError, "Could not open audio: #{SDL.GetError()}"
end
return true
end