Module: Audio

Defined in:
lib/openrgss/audio.rb

Overview

The module that carries out music and sound processing.

Class Method Summary collapse

Class Method Details

.bgm_fade(time) ⇒ Object

Starts BGM fadeout. time is the length of the fadeout in milliseconds.



33
34
35
# File 'lib/openrgss/audio.rb', line 33

def bgm_fade(time)
  SDL::Mixer.fade_out_music(time)
end

.bgm_play(filename, volume = 100, pitch = 100, pos = 0) ⇒ Object

Starts BGM playback. Specifies the file name, volume, pitch, and playback starting position in that order.

The playback starting position (RGSS3) is only valid for ogg or wav files.

Also automatically searches files included in RGSS-RTP. File extensions may be omitted.



21
22
23
# File 'lib/openrgss/audio.rb', line 21

def bgm_play(filename, volume=100, pitch=100, pos=0)
  SDL::Mixer.play_music SDL::Mixer::Music.load(RGSS.get_file(filename)), -1 rescue puts($!)
end

.bgm_posObject

Gets the playback position of the BGM. Only valid for ogg or wav files. Returns 0 when not valid.



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

def bgm_pos

end

.bgm_stopObject

Stops BGM playback.



27
28
29
# File 'lib/openrgss/audio.rb', line 27

def bgm_stop
  SDL::Mixer.halt_music
end

.bgs_fade(time) ⇒ Object

Starts BGS fadeout. time is the length of the fadeout in milliseconds.



61
62
63
# File 'lib/openrgss/audio.rb', line 61

def bgs_fade(time)
  SDL::Mixer.fade_out(@bgs_channel, time) if @bgs_channel
end

.bgs_play(filename, volume = 100, pitch = 100, pos = 0) ⇒ Object

Starts BGS playback. Specifies the file name, volume, pitch, and playback starting position in that order.

The playback starting position (RGSS3) is only valid for ogg or wav files.

Also automatically searches files included in RGSS-RTP. File extensions may be omitted.



49
50
51
# File 'lib/openrgss/audio.rb', line 49

def bgs_play(filename, volume=100, pitch=100, pos=0)
  @bgs_channel = SDL::Mixer.play_channel(-1, SDL::Mixer::Wave.load(RGSS.get_file(filename)), -1) rescue puts($!)
end

.bgs_posObject

Gets the playback position of the BGS. Only valid for ogg or wav files. Returns 0 when not valid.



67
68
69
# File 'lib/openrgss/audio.rb', line 67

def bgs_pos

end

.bgs_stopObject

Stops BGS playback.



55
56
57
# File 'lib/openrgss/audio.rb', line 55

def bgs_stop
  SDL::Mixer.halt(@bgs_channel) if @bgs_channel
end

.me_fade(time) ⇒ Object

Starts ME fadeout. time is the length of the fadeout in milliseconds.



89
90
91
# File 'lib/openrgss/audio.rb', line 89

def me_fade(time)
  SDL::Mixer.fade_out(@me_channel, time) if @me_channel
end

.me_play(filename, volume = 100, pitch = 100) ⇒ Object

Starts ME playback. Sets the file name, volume, and pitch in turn.

Also automatically searches files included in RGSS-RTP. File extensions may be omitted.

When ME is playing, the BGM will temporarily stop. The timing of when the BGM restarts is slightly different from RGSS1.



77
78
79
# File 'lib/openrgss/audio.rb', line 77

def me_play(filename, volume=100, pitch=100)
  @me_channel = SDL::Mixer.play_channel(-1, SDL::Mixer::Wave.load(RGSS.get_file(filename)), 0) rescue puts($!)
end

.me_stopObject

Stops ME playback.



83
84
85
# File 'lib/openrgss/audio.rb', line 83

def me_stop
  SDL::Mixer.halt(@me_channel) if @me_channel
end

.se_play(filename, volume = 100, pitch = 100) ⇒ Object

Starts SE playback. Sets the file name, volume, and pitch in turn.

Also automatically searches files included in RGSS-RTP. File extensions may be omitted.

When attempting to play the same SE more than once in a very short period, they will automatically be filtered to prevent choppy playback



99
100
101
# File 'lib/openrgss/audio.rb', line 99

def se_play(filename, volume=100, pitch=100)
  @se_channel = SDL::Mixer.play_channel(-1, SDL::Mixer::Wave.load(RGSS.get_file(filename)), 0) rescue puts($!)
end

.se_stopObject

Stops all SE playback.



105
106
107
# File 'lib/openrgss/audio.rb', line 105

def se_stop
  SDL::Mixer.halt(@se_channel) if @me_channel
end

.setup_mdiObject

Prepares MIDI playback by DirectMusic.

A method of the processing at startup in RGSS2 for enabling execution at any time.

MIDI playback is possible without calling this method, but in Windows Vista or later, a delay of 1 to 2 seconds will result at playback.



11
12
13
# File 'lib/openrgss/audio.rb', line 11

def setup_mdi

end