Skip to content

Instantly share code, notes, and snippets.

@mjago
Last active March 30, 2017 05:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mjago/188964f13a39813afecea75a43372f67 to your computer and use it in GitHub Desktop.
Save mjago/188964f13a39813afecea75a43372f67 to your computer and use it in GitHub Desktop.
example of Mix_LoadWAV_RW
require "../src/sdl"
require "../src/mixer"
SDL.init(SDL::Init::VIDEO | SDL::Init::AUDIO); at_exit { SDL.quit }
SDL::Mixer.init(SDL::Mixer::Init::MP3); at_exit { SDL::Mixer.quit }
SDL::Mixer.open
chunk = {} of String => LibMixer::Mix_Chunk*
names = %w(high medium low scratch)
names.each do |name|
rwops = LibSDL.rw_from_file("samples/data/#{name}.wav", "rb")
chunk[name] = LibMixer.load_wav_rw(rwops, 1)
end
loop do
case event = SDL::Event.wait
when SDL::Event::Keyboard
case event.sym
when .key_1? then SDL::Mixer.play_wav(chunk["high"])
when .key_2? then SDL::Mixer.play_wav(chunk["medium"])
when .key_3? then SDL::Mixer.play_wav(chunk["low"])
when .key_4? then SDL::Mixer.play_wav(chunk["scratch"])
when .q?, SDL::Event::Quit then break
end if event.keyup?
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment