Class: RAGE::Audio

Inherits:
Object
  • Object
show all
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

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

#playObject



39
40
41
# File 'lib/rage/audio.rb', line 39

def play
  @channel = SDL::Mixer.play_channel(-1, @wave, @times)
end

#playing?Boolean

Returns:

  • (Boolean)


43
44
45
# File 'lib/rage/audio.rb', line 43

def playing?
  SDL::Mixer.play?(@channel)
end

#stopObject



47
48
49
# File 'lib/rage/audio.rb', line 47

def stop
  SDL::Mixer.halt(@channel)
end