Using an SDL (Simple DirectMedia Layer) wrapper is one way to play sound and music with Ruby. I have tested this snippet with .MID .MOD and .WAV files and it performs well. There are several SDL wrappers for Ruby available, I picked RUDL because of its simplicity. RUDL is great for writing games.
# play a midi file or mod file using the SDL wrapper for Ruby # download RUDL from: http://sourceforge.net/projects/rudl/ # file: rudl-0.8-for-ruby-1.8.2-setup-releasebuild.zip # includes the needed SDL .dll files # run install-on-windows.rb and follow instructions # tested with Ruby182 and Windows XP vegaseat 17mar2006 (yeah Irish!) require "RUDL" # this gets rid of the namespace include RUDL # pick a midi file you have in the workfolder # or add the full path to the filename filename = "TeaFor2.mid" music = Music.new(filename) music.play # needed to play music to the end gets
About the Author