#==============================================================================
# Modified Audio MP3 loop v1.0 for RMXP
# Original Script by Cogwheel (http://members.jcom.home.ne.jp/cogwheel/)
# Must provide credit to GubiD and Cogwheel for this script.
#==============================================================================
#==============================================================================
# â– RPG
#------------------------------------------------------------------------------
# Module RPG(The Game)
#==============================================================================
module RPG
#==============================================================================
# â– BGM
#------------------------------------------------------------------------------
# BGM Audio File additional methods
#==============================================================================
class AudioFile
#--------------------------------------------------------------------------
# â— Play audio file
#--------------------------------------------------------------------------
def play
if @name.empty?
Audio.bgm_stop
@@last = BGM.new
else
name = "Audio/BGM/"
start = 0
loop = 0
step = [0, 0]
fin = 0
case @name
when "whatever song"
type = "Dungeon"
start = 0
loop = 6704
fin = 97109
else
type = "Normal"
end
if type == "Normal"
name = @name
else
name = $game_audio.name?("Audio/BGM/" + @name)
end
$game_audio.bgm_play(name, @volume, @pitch, type, start, loop, fin)
@@last = self
end
end
#--------------------------------------------------------------------------
# â— BGM ã®æ¼”å¥åœæ¢
#--------------------------------------------------------------------------
def stop
$game_audio.bgm_stop
end
#--------------------------------------------------------------------------
# â— BGM ã®ãƒ•ã‚§ãƒ¼ãƒ‰ã‚¢ã‚¦ãƒˆ
#--------------------------------------------------------------------------
def fade(time)
$game_audio.fadeout_set(time)
end
end
end
class Game_Audio
#--------------------------------------------------------------------------
# â— Initialize method
#--------------------------------------------------------------------------
def initialize
@play = Win32API.new("winmm.dll", "mciSendString", ["p","p","l","l"], "i")
@play.call("Close all", "\\" * 255, 255, 0)
@type = "Normal"
@me_count = 0
fadein_set(0)
end
#--------------------------------------------------------------------------
# â— BGM ã®æ¼”å¥
# name : BGM filename
# vol : volume
# pitch : tone level
# type : battle/dungeon/normal, dungeon pauses when battle is called
# start : start position
# loop : loop position
# fin : finish position
#--------------------------------------------------------------------------
def bgm_play(name, vol, pitch, type, start, loop, fin)
fadein_set(0)
if type == "Normal"
bgm_stop(type) if @name != name
Audio.bgm_play("Audio/BGM/" + name, vol, 100) if name != ""
elsif @name != name
bgm_stop(type)
status = "\\" * 255
@play.call("Status " + type + " mode", status, 255, 0)
if status.unpack("A*")[0] == "paused"
@play.call("Setaudio " + type + " volume to 0", "\\" * 255, 255, 0)
@play.call("Play " + type, "\\" * 255, 255, 0)
fadein_set(1000)
else
@play.call("Open \"" + name + "\" alias " + type + " type MPEGVideo",
"\\" * 255, 255, 0)
@play.call("Setaudio " + type + " volume to " +
(vol ** 2 / 10).to_s, "\\" * 255, 255, 0)
@play.call("Play " + type + " from " +
start.to_s + " to " + fin.to_s, "\\" * 255, 255, 0)
end
if @me_count > 0
fadein_set(0)
@play.call("Setaudio " + type + " volume to 0", "\\" * 255, 255, 0)
end
else
if @me_count > 0
@play.call("Setaudio " + type + " volume to 0", "\\" * 255, 255, 0)
else
@play.call("Setaudio " + type + " volume to " +
(vol ** 2 / 10).to_s, "\\" * 255, 255, 0)
end
end
@name = name
@type = type
@vol = vol
@start = start
@loop = loop
@fin = fin
end
#--------------------------------------------------------------------------
# â— get filename extension
#--------------------------------------------------------------------------
def name?(name)
if FileTest.exist?(name + ".mp3")
return (name + ".mp3")
elsif FileTest.exist?(name + ".ogg")
return (name + ".ogg")
elsif FileTest.exist?(name + ".wav")
return (name + ".wav")
elsif FileTest.exist?(name + ".mid")
return (name + ".mid")
end
return "name"
end
#--------------------------------------------------------------------------
# â— fadein time
#--------------------------------------------------------------------------
def fadein(time)
fadein_set(time * 1000)
end
#--------------------------------------------------------------------------
# â— fadein Set counter
#--------------------------------------------------------------------------
def fadein_set(time)
@fade_max = @fade_count = time * Graphics.frame_rate / 1000
end
#--------------------------------------------------------------------------
# â— Fadeout time
#--------------------------------------------------------------------------
def fadeout_set(time)
if @type == "Normal"
Audio.bgm_fade(time)
else
if @fade_count == 0
@fade_max = time * Graphics.frame_rate / 1000
@fade_count = - time * Graphics.frame_rate / 1000
elsif @fade_count > 0
@fade_max = (time * @fade_max * Graphics.frame_rate) /
(1000 * (@fade_max - @fade_count))
@fade_count = - time * Graphics.frame_rate / 1000
else
@fade_max = - (time * @fade_max * Graphics.frame_rate) /
(1000 * @fade_count)
@fade_count = - time * Graphics.frame_rate / 1000
end
end
end
#--------------------------------------------------------------------------
# â— stop BGM
#--------------------------------------------------------------------------
def bgm_stop(type = "")
if @type == "Dungeon" and type == "Battle"
@play.call("Pause " + @type, "\\" * 255, 255, 0)
else
if @type == "Normal"
Audio.bgm_stop
else
@play.call("Stop " + @type, "\\" * 255, 255, 0)
@play.call("Close " + @type, "\\" * 255, 255, 0)
end
end
@type = "Normal"
end
#--------------------------------------------------------------------------
# â— Update process
#--------------------------------------------------------------------------
def update
if @type != "Normal"
code = "\\" * 255
@play.call("Status " + @type + " position", code, 255, 0)
if code.unpack("A*")[0].to_i >= @fin
@play.call("Seek " + @type + " to " + @loop.to_s, "\\" * 255, 255, 0)
@play.call("Play " + @type + " to " + @fin.to_s, "\\" * 255, 255, 0)
end
if @fade_count > 0
@fade_count -= 1
@play.call("Setaudio " + @type + " volume to " +
((@vol * (@fade_max - @fade_count) / @fade_max) ** 2 / 10).to_s,
"\\" * 255, 255, 0)
elsif @fade_count < 0
@fade_count += 1
@play.call("Setaudio " + @type + " volume to " +
((- @vol * @fade_count / @fade_max) ** 2 / 10).to_s,
"\\" * 255, 255, 0)
end
end
if @me_count > 0
@me_count -= 1
if @type != "Normal" and @me_count == 0
fadein_set(1000)
end
end
end
end
#==============================================================================
# â– initialize new audio module
#==============================================================================
if $game_audio == nil
$game_audio = Game_Audio.new
end
#==============================================================================
# â– Graphics
#------------------------------------------------------------------------------
# When graphics are updated.. update audio.
#==============================================================================
class << Graphics
alias :update_audio :update unless method_defined?("update_audio")
def update
update_audio
$game_audio.update
end
end
#==============================================================================
# â– System
#------------------------------------------------------------------------------
# Update bgm_play and bgm_Stop methods to use new audio module.
#==============================================================================
class Game_System
def bgm_play(bgm)
bgm.play unless bgm == nil
if bgm == nil
bgm_stop
end
@playing_bgm = bgm
end
def bgm_stop
@playing_bgm.stop unless @playing_bgm == nil
@playing_bgm = nil
Audio.bgm_stop
end
end