| 
 
| 赞 | 1 |  
| VIP | 0 |  
| 好人卡 | 85 |  
| 积分 | 1 |  
| 经验 | 41098 |  
| 最后登录 | 2015-3-17 |  
| 在线时间 | 1071 小时 |  
 Lv1.梦旅人 
	梦石0 星屑50 在线时间1071 小时注册时间2011-5-12帖子2317 
 | 
| 本帖最后由 月夜神音 于 2011-11-11 10:52 编辑 
 修改33~55行复制代码# MP3ループ演奏 Ver VX_1.00
# 配布元・サポートURL
# http://members.jcom.home.ne.jp/cogwheel/
#==============================================================================
# ■ RPG
#------------------------------------------------------------------------------
#  RPG全体のモジュールです。
#==============================================================================
module RPG
#==============================================================================
# ■ BGM
#------------------------------------------------------------------------------
#  BGM を管理・制御するクラスです。
#==============================================================================
  class BGM < AudioFile
    @@last = BGM.new
    #--------------------------------------------------------------------------
    # ● BGM の演奏
    #--------------------------------------------------------------------------
    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 "satoc-boss09-2"
          type = "Battle"
          start = 0
          loop = 96040
          fin = 202680
        when "satoc-town07-2"
          type = "Dungeon"
          start = 0
          loop = 31980
          fin = 100000
        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 self.stop
      $game_audio.bgm_stop
      @@last = BGM.new
    end
    #--------------------------------------------------------------------------
    # ● BGM のフェードアウト
    #--------------------------------------------------------------------------
    def self.fade(time)
      $game_audio.fadeout_set(time)
      @@last = BGM.new
    end
  end
#==============================================================================
# ■ ME
#------------------------------------------------------------------------------
#  ME を管理・制御するクラスです。
#==============================================================================
  class ME < AudioFile
    #--------------------------------------------------------------------------
    # ● ME の演奏
    #--------------------------------------------------------------------------
    def play
      if @name.empty?
        Audio.me_stop
      else
        Audio.me_play("Audio/ME/" + @name, @volume, @pitch)
      end
      $game_audio.me_set("Audio/ME/" + @name)
    end
    #--------------------------------------------------------------------------
    # ● ME の演奏停止
    #--------------------------------------------------------------------------
    def self.stop
      Audio.me_stop
      $game_audio.mecount_set(1)
    end
    #--------------------------------------------------------------------------
    # ● ME のフェードアウト
    #--------------------------------------------------------------------------
    def self.fade(time)
      Audio.me_fade(time)
      $game_audio.mecount_set(time * Graphics.frame_rate / 1000)
    end
  end
end
#==============================================================================
# ■ Scene_Map
#------------------------------------------------------------------------------
#  マップ画面の処理を行うクラスです。
#==============================================================================
class Scene_Map < Scene_Base
  #--------------------------------------------------------------------------
  # ● バトル画面への切り替え
  #--------------------------------------------------------------------------
  def call_battle
    @spriteset.update
    Graphics.update
    $game_player.make_encounter_count
    $game_player.straighten
    $game_temp.map_bgm = RPG::BGM.last
    $game_temp.map_bgs = RPG::BGS.last
    # RPG::BGM.stop
    RPG::BGS.stop
    Sound.play_battle_start
    $game_system.battle_bgm.play
    $game_temp.next_scene = nil
    $scene = Scene_Battle.new
  end
end
#==============================================================================
# ■ Game_Audio
#------------------------------------------------------------------------------
#  MP3の演奏・その他BGMの演奏全般を司るクラスです。
# MP3の途中ループ等に対応します。
#==============================================================================
class Game_Audio
  #--------------------------------------------------------------------------
  # ● オブジェクト初期化
  #--------------------------------------------------------------------------
  def initialize
    @play = Win32API.new("winmm.dll", "mciSendString", ["p","p","l","l"], "i")
    @play.call("Close all", "\0" * 255, 255, 0)
    @type = "Normal"
    @me_count = 0
    fadein_set(0)
  end
  #--------------------------------------------------------------------------
  # ● BGM の演奏
  #     name       : BGM ネーム
  #     vol        : ボリューム
  #     pitch      : ピッチ
  #     type       : BGM タイプ
  #     start      : 演奏開始位置
  #     loop       : 演奏ループ時開始位置
  #     fin        : 演奏ループ終了位置
  #--------------------------------------------------------------------------
  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 = "\0" * 255
      @play.call("Status " + type + " mode", status, 255, 0)
      if status.unpack("A*")[0] == "paused"
        @play.call("Setaudio " + type + " volume to 0", "\0" * 255, 255, 0)
        @play.call("Play " + type, "\0" * 255, 255, 0)
        fadein_set(1000)
      else
        @play.call("Open " + name + " alias " + type + " type MPEGVideo",
          "\0" * 255, 255, 0)
        @play.call("Setaudio " + type + " volume to " +
          (vol ** 2 / 10).to_s, "\0" * 255, 255, 0)
        @play.call("Play " + type + " from " +
          start.to_s + " to " + fin.to_s, "\0" * 255, 255, 0)
      end
      if @me_count > 0
        fadein_set(0)
        @play.call("Setaudio " + type + " volume to 0", "\0" * 255, 255, 0)
      end
    else
      if @me_count > 0
        @play.call("Setaudio " + type + " volume to 0", "\0" * 255, 255, 0)
      else
        @play.call("Setaudio " + type + " volume to " +
          (vol ** 2 / 10).to_s, "\0" * 255, 255, 0)
      end
    end
    @name = name
    @type = type
    @vol = vol
    @start = start
    @loop = loop
    @fin = fin
  end
  #--------------------------------------------------------------------------
  # ● ファイルネームの取得
  #--------------------------------------------------------------------------
  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
  #--------------------------------------------------------------------------
  # ● フェードイン
  #--------------------------------------------------------------------------
  def fadein(time)
    fadein_set(time * 1000)
  end
  #--------------------------------------------------------------------------
  # ● フェードインの設定
  #--------------------------------------------------------------------------
  def fadein_set(time)
    @fade_max = @fade_count = time * Graphics.frame_rate / 1000
  end
  #--------------------------------------------------------------------------
  # ● フェードアウトの設定
  #--------------------------------------------------------------------------
  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
  #--------------------------------------------------------------------------
  # ● 演奏の停止
  #--------------------------------------------------------------------------
  def bgm_stop(type = "")
    if @type == "Dungeon" and type == "Battle"
      @play.call("Pause " + @type, "\0" * 255, 255, 0)
    else
      if @type == "Normal"
        Audio.bgm_stop
      else
        @play.call("Stop " + @type, "\0" * 255, 255, 0)
        @play.call("Close " + @type, "\0" * 255, 255, 0)
      end
    end
    @type = "Normal"
  end
  #--------------------------------------------------------------------------
  # ● ME 演奏の設定
  #--------------------------------------------------------------------------
  def me_set(name)
    # 現在のBGMが Normal でないのなら
    if @type != "Normal"
      # BGM 演奏の停止
      @play.call("Setaudio " + @type + " volume to 0", "\0" * 255, 255, 0)
    end
    # ME 演奏長の取得
    @play.call("Open " + name?(name) + " alias me type MPEGVideo",
       "\0" * 255, 255, 0)
    length = "\0" * 255
    @play.call("Status me length", length, 255, 0)
    # ME カウントの設定
    @me_count = length.unpack("A*")[0].to_i * 60 / 1000 - 90
  end
  #--------------------------------------------------------------------------
  # ● ME 演奏の直接指定
  #--------------------------------------------------------------------------
  def mecount_set(time)
    @me_count = time
  end
  #--------------------------------------------------------------------------
  # ● フレーム更新
  #--------------------------------------------------------------------------
  def update
    if @type != "Normal"
      code = "\0" * 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, "\0" * 255, 255, 0)
        @play.call("Play " + @type + " to " + @fin.to_s, "\0" * 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,
          "\0" * 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,
          "\0" * 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
#==============================================================================
# ■ オーディオクラスの強制作成
#==============================================================================
if $game_audio == nil
  $game_audio = Game_Audio.new
end
#==============================================================================
# ■ Graphics
#------------------------------------------------------------------------------
#  グラフィック全般の処理を行うクラスです。
#==============================================================================
class << Graphics
  #--------------------------------------------------------------------------
  # ● フレーム更新
  #--------------------------------------------------------------------------
  alias :update_audio :update unless method_defined?("update_audio")
  def update
    update_audio
    $game_audio.update
  end
end
when后面为音乐名称,目前好像只对mp3,ogg,wav,mid有效
 type为类型,分别是"Normal","Dungeon"和"Battle"
 start为开始时音乐桢数
 loop为开始循环音乐桢数
 fin为结束时音乐桢数
 演奏方法是:"start"~"fin"→"loop"~"fin"→"loop"~…持续下去
 就这样……
 脚本作者:ショウ - 月夜に響くノクターン Rebirth
 出处:http://members.jcom.home.ne.jp/cogwheel/
 | 
 |