Class: RAGE::Audio
- Inherits:
-
Object
- Object
- RAGE::Audio
- Defined in:
- lib/rage/audio.rb
Overview
Manages all audio operations. Currently uses SDL mixer to accomplish this
Constant Summary collapse
- NONSTOP =
pass in as the :times arg to specify continuous music
-1
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(args = {}) ⇒ Audio
constructor
A new instance of Audio.
- #play ⇒ Object
- #playing? ⇒ Boolean
- #stop ⇒ Object
Constructor Details
#initialize(args = {}) ⇒ Audio
Returns a new instance of Audio.
32 33 34 35 36 37 |
# File 'lib/rage/audio.rb', line 32 def initialize(args = {}) @times = 1 @wave = args[:wave] if args.has_key? :wave @times = args[:times] if args.has_key? :times end |
Class Method Details
.play(file, args = {}) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/rage/audio.rb', line 20 def self.play(file, args = {}) unless defined? @@audio_initialized @@audio_initialized = true # TODO allow different frequency / open options and channel allocations SDL::Mixer.open(22050 * 4) SDL::Mixer.allocate_channels(16) end audio = RAGE::Audio.new args.merge(:wave => SDL::Mixer::Wave.load(file)) audio.play end |
Instance Method Details
#play ⇒ Object
39 40 41 |
# File 'lib/rage/audio.rb', line 39 def play @channel = SDL::Mixer.play_channel(-1, @wave, @times) end |
#playing? ⇒ Boolean
43 44 45 |
# File 'lib/rage/audio.rb', line 43 def SDL::Mixer.play?(@channel) end |
#stop ⇒ Object
47 48 49 |
# File 'lib/rage/audio.rb', line 47 def stop SDL::Mixer.halt(@channel) end |