设为首页收藏本站同能贴吧 切换语言 繁体中文
开启辅助访问 切换到窄版
扫描二维码关注官方公众号
返回列表
+ 发新帖
查看: 114|回复: 0

[转载发布] Extended Music Script 3.5

[复制链接]
累计送礼:
0 个
累计收礼:
1 个
  • TA的每日心情
    开心
    2026-7-12 04:10
  • 签到天数: 209 天

    连续签到: 2 天

    [LV.7]常住居民III

    9071

    主题

    864

    回帖

    6万

    积分

    管理员

    Rank: 9Rank: 9Rank: 9

    VIP
    7
    卡币
    58883
    OK点
    16
    推广点
    0
    同能卷
    50
    积分
    68848

    灌水之王

    发表于 2026-8-1 22:23:06 | 显示全部楼层 |阅读模式
    Extended Music Script 3.5



    Introduction

    This script allows you to play music formats like psf, spc, mod, it, etc in your game, just like mp3 or midi.

    Features

    New Features:

      - Script compatible with RPG Maker VX Ace

    I mostly rewrote the code that's indented. Everything else was written by either Mooshykris or Guillaume777 years ago.

    Credit us if you want in your game. Please report any bugs you may encounter to zhek.pvm@gmail.com and I'll try to fix them.

    Script allows you to play unusual formats ( .psf, .gym, .spc, it, mod, etc. ) if there is a winamp dll for it

    Script works with multiple format/dlls and doesn't require a 'call script' ( just make it play like any BGM )

    Script won't give error unless there is a music file requiring dll and dll is not there

    How to Use

    Make sure Winamp.dll, out_wave.dll and the music dlls are in a folder called 'DLL' in your game folder

    If you use in_bass.dll you need to have bass.dll in your game folder.

    Copy your music files to the BGM folder ( you can't import them via RPG VX/Ace )

    If you use .minipsf don't forget to include the psflib !!

    Just use an event to play the music like any regular BGM

    The music files won't play in Sound Test, only in the real game

    If you want loop music files you need to edit dlls in winamp and copy the configure files to the DLL folder

    Script

    Spoiler                Code:       
    1. #==============================================================================
    2. # Extended Music Script Version 3.5
    3. #------------------------------------------------------------------------------
    4. # Edited by Zhek
    5. # May 28, 2012
    6. #
    7. # New Features:
    8. #   - Script compatible with RPG Maker VX Ace
    9. #
    10. # I mostly rewrote the code that's indented. Everything else was written by
    11. # either Mooshykris or Guillaume777 years ago.
    12. # Credit us if you want in your game.
    13. # Please report any bugs you may encounter to zhek.pvm@gmail.com and I'll try to
    14. # fix them.
    15. #------------------------------------------------------------------------------
    16. # Edited by Mooshykris
    17. # March 6, 2007
    18. #==============================================================================
    19. # Version 2.0 Features:
    20. # The Ability to play USF, MINIUSF, and all In_Cube Files
    21. #==============================================================================
    22. #Original Script:
    23. #------------------------------------------------------------------------------
    24. #Audio formats extension script
    25. #------------------------------------------------------------------------------
    26. # Guillaume777
    27. # 3.1
    28. # 2006/04/28
    29. #==============================================================================
    30. # Version 3.0 :
    31. # -New support for in_bass dll ! You can now play those formats :
    32. # '.XM', '.IT', '.S3M', '.MOD', '.MTM', '.UMX', '.MO3'
    33. # -New support for fading !
    34. # -Improved code, now script is really fast
    35. #
    36. #
    37. # Great improvement of Andreas21 'WimAmp plugins', by Guillaume777 ( 2005 )
    38. # Script allows you to play unusual formats ( .psf, .gym, .spc, it, mod, etc. ) if there is a winamp dll for it
    39. # Script works with multiple format/dlls and doesn't require a 'call script' ( just make it play like any BGM )
    40. # Script won't give error unless there is a music file requiring dll and dll is not there
    41. # Instructions
    42. #
    43. # Make sure Winamp.dll, out_wave.dll and the music dlls are in a folder called 'DLL' in your game folder
    44. # If you use in_bass.dll you need to have bass.dll in your game folder.
    45. # Copy your music files to the BGM folder ( you can't import them via RPG VX/Ace)
    46. # If you use .minipsf don't forget to include the psflib !!
    47. # Just use an event to play the music like any regular BGM
    48. # The music files won't play in Sound Test, only in the real game
    49. # If you want loop music files you need to edit dlls in winamp and copy the configure files to the DLL folder
    50. #
    51. #
    52. # Credits for Winamp class and Winamp.dll to Andreas21 (C) 2004
    53. module G7_AFES_MOD
    54. BGM_DIRECTORY = 'Audio/BGM/' # directory of BGMs
    55. DLL_DIRECTORY = 'DLL/' #directory of dll
    56. OUT_DLL = 'out_wave.dll' #output dll, default = 'out_wave.dll'
    57. WIN_DLL = 'WinAmp.dll' #winamp dll, default = 'winamp.dll'
    58. BGM_EXT = ['.mp3', '.mid', '.ogg', '.wma', '.wave'] #normal extension
    59. PSF_EXT = ['.psf', '.minipsf', '.psf2', '.minipsf2']
    60. GSF_EXT = ['.gsf', '.minigsf']
    61. USF_EXT = ['.usf', '.miniusf']
    62. CUBE_EXT = ['.hps', '.dsp']
    63. SNES_EXT = ['.spc']
    64. GEN_EXT = ['.gym', '.cym']
    65. MOD_EXT = ['.XM', '.IT', '.S3M', '.MOD', '.MTM', '.UMX', '.MO3']
    66. PSF_DLL = 'in_psf.dll'
    67. GSF_DLL = 'in_gsf.dll'
    68. USF_DLL = 'in_usf.dll'
    69. CUBE_DLL = 'in_cube.dll'
    70. SNES_DLL= 'in_snes.dll'
    71. GEN_DLL = 'in_ym.dll'
    72. MOD_DLL = 'in_bass.dll'
    73. end
    74. module RPG
    75. class AudioFile
    76. attr_accessor :file_extension #stores the extension of file
    77. attr_accessor :file_name #stores the real file name
    78. attr_accessor :file_dll #store dll required to play it
    79. end
    80. end
    81. module Audio
    82. @winamp = nil #stores audio player
    83. @winamp_volume = nil #stores volume value
    84. @winamp_playing_bgm = nil #stores music played by winamp
    85. @winamp_bgm_fading = nil #stores if bgm is currently fading or not
    86. @winamp_current_dll = nil # stores current dll used by winamp
    87. @fade_dec = nil #stores how much the volume decrease per frame while fading
    88. def Audio.winamp_bgm_fading
    89. return @winamp_bgm_fading
    90. end
    91. #==============================================================================
    92. # Create winamp system, play music file with winamp, set volume
    93. #==============================================================================
    94. def self.winamp_bgm_play(file_name, volume = 100.0, dll = nil)
    95. if @winamp_current_dll != dll then
    96.   @winamp_current_dll = dll
    97.   @winamp = WinAmp_Plugin_System.new(dll) #new winamp with new dll
    98. end
    99. volume = 255 #convert volume from rmxp to winamp
    100. if volume > 255.0 then volume = 255.0 end
    101. @winamp_playing_bgm = file_name
    102. @winamp.play(file_name)
    103. @winamp_volume = volume
    104. @winamp.setvolume(volume)
    105. end #end def
    106. #==============================================================================
    107. # Initiate the fading, calculates @fade_dec
    108. #==============================================================================
    109. def self.winamp_bgm_fade_init(frames)
    110. if @winamp_playing_bgm != nil then
    111. @fade_dec = @winamp_volume / frames
    112. @winamp_bgm_fading = true
    113. self.winamp_bgm_fade
    114. end
    115. end
    116. #==============================================================================
    117. # Fade volume by @fade_dec
    118. #==============================================================================
    119. def self.winamp_bgm_fade
    120. @winamp_volume += -@fade_dec
    121. @winamp.setvolume(@winamp_volume) #drop in volume for a fade
    122. if @winamp_volume <= 0
    123. self.winamp_bgm_stop
    124. end
    125. end
    126. #==============================================================================
    127. # Stops playing music
    128. #==============================================================================
    129. def self.winamp_bgm_stop
    130. if @winamp_playing_bgm != nil then
    131. @winamp.setvolume(255)
    132. @winamp.stop #stop winamp
    133. end
    134. @winamp_bgm_fading = false
    135. @fade_dec = false
    136. @winamp_volume = nil
    137. @winamp_playing_bgm = nil
    138. end
    139. #==============================================================================
    140. # Uses Win32API and WinAmp.dll to add winamp functions
    141. #==============================================================================
    142. class WinAmp_Plugin_System #This part was done by Andreas21
    143. def initialize(in_dll)
    144. # DLL Pfaht festlegen
    145. dll_directory = G7_AFES_MOD::DLL_DIRECTORY
    146. in_dll = dll_directory + in_dll
    147. out_dll = dll_directory + G7_AFES_MOD::OUT_DLL
    148. winamp_dll = dll_directory + G7_AFES_MOD::WIN_DLL
    149. # 2 API Funktionen die gebraucht werden für das Fenster Handel
    150. @ReadIni = Win32API.new 'kernel32', 'GetPrivateProfileStringA', %w(p p p p l p), 'l'
    151. @FindWindow = Win32API.new 'user32', 'FindWindowA', %w(p p), 'l'
    152. # Benötigte DLL Funktionen Laden
    153. @Init_Winamp = Win32API.new winamp_dll, 'Init_Winamp', %w(p p l), 'l'
    154. @Quit_Winamp = Win32API.new winamp_dll, 'Quit_Winamp', '', ''
    155. @Winamp_Play = Win32API.new winamp_dll, 'Winamp_Play', 'p', 'l'
    156. @Winamp_Pause = Win32API.new winamp_dll, 'Winamp_Pause', '', ''
    157. @Winamp_Stop = Win32API.new winamp_dll, 'Winamp_Stop', '', 'l'
    158. @Winamp_OnlyExtensions = Win32API.new winamp_dll, 'Winamp_OnlyExtensions', '', 'p'
    159. @Winamp_OutName = Win32API.new winamp_dll, 'Winamp_OutName', '', 'p'
    160. @Winamp_OutConfig = Win32API.new winamp_dll, 'Winamp_OutConfig', 'l', ''
    161. @Winamp_OutAbout = Win32API.new winamp_dll, 'Winamp_OutAbout', 'l', ''
    162. @Winamp_IsPlaying = Win32API.new winamp_dll, 'Winamp_IsPlaying', '', 'l'
    163. @Winamp_InName = Win32API.new winamp_dll, 'Winamp_InName', '', 'p'
    164. @Winamp_Extensions = Win32API.new winamp_dll, 'Winamp_Extensions', '', 'p'
    165. @Winamp_InConfig = Win32API.new winamp_dll, 'Winamp_InConfig', 'l', ''
    166. @Winamp_InAbout = Win32API.new winamp_dll, 'Winamp_InAbout', 'l', ''
    167. @Winamp_GetFileInfo = Win32API.new winamp_dll, 'Winamp_GetFileInfo', %w(p l), 'p'
    168. @Winamp_InfoBox = Win32API.new winamp_dll, 'Winamp_InfoBox', %w(p l), 'l'
    169. @Winamp_GetLength = Win32API.new winamp_dll, 'Winamp_GetLength', '', 'l'
    170. @Winamp_LengthStr = Win32API.new winamp_dll, 'Winamp_LengthStr', 'l', 'p'
    171. @Winamp_GetOutputTime = Win32API.new winamp_dll, 'Winamp_GetOutputTime', '', 'l'
    172. @Winamp_SetVolume = Win32API.new winamp_dll, 'Winamp_SetVolume', 'l', ''
    173. @Winamp_SetPan = Win32API.new winamp_dll, 'Winamp_SetPan', 'l', ''
    174. @Winamp_setoutputtime = Win32API.new winamp_dll, 'winamp_setoutputtime', 'l', ''
    175. @Winamp_IsPaused = Win32API.new winamp_dll, 'Winamp_IsPaused', '', 'l'
    176. # Winamp Plugin Systen Start
    177. @Init_Winamp.call(in_dll, out_dll, handel)
    178. end
    179. # Play the file. Return 0 if no error happend.
    180. def play(file)
    181. return @Winamp_Play.call(file)
    182. end
    183. # First call pause the sound and the second call unpause it.
    184. def pause
    185. @Winamp_Pause.call()
    186. end
    187. # Stop playing.
    188. def stop
    189. return @Winamp_Stop.call()
    190. end
    191. # Quit WinAmp
    192. def quit
    193. @Quit_Winamp.call()
    194. end
    195. # Return all the supported mediafiles.
    196. def onlyextensions
    197. return @Winamp_OnlyExtensions.call()
    198. end
    199. # Out_DLL Infos
    200. def outname
    201. return @Winamp_OutName.call()
    202. end
    203. # Open the config-dialog of the out-plugin.
    204. def outconfig
    205. @Winamp_OutConfig.call(handel)
    206. end
    207. # Open the about-dialog of the out-plugin
    208. def outabout
    209. @Winamp_OutAbout.call(handel)
    210. end
    211. # Return <>0 if a sound is playing, but doesn't work if in-plugin don't need the out-plugin
    212. def isplaying
    213. return @Winamp_IsPlaying.call()
    214. end
    215. # Return the name of the in-plugin.
    216. def inname
    217. return @Winamp_InName.call()
    218. end
    219. # Return the extentions and the type name of all supported mediafiles
    220. def extensions
    221. return @Winamp_Extensions.call()
    222. end
    223. # Open the config-dialog of the in-plugin.
    224. def inconfig
    225. @Winamp_InConfig.call(handel)
    226. end
    227. # Open the about-dialog of the in-plugin.
    228. def inabout
    229. @Winamp_InAbout.call(handel)
    230. end
    231. # return the title of a file and the length in ms.
    232. def getfileinfo(playfile,length_adr)
    233. return @Winamp_GetFileInfo.call(playfile,length_adr)
    234. end
    235. # Open the file-info-dialog of the in-plugin. Not supported of all pluggins (=the will do nothing)
    236. def infobox(playfile)
    237. return @Winamp_InfoBox.call(playfile,handel)
    238. end
    239. # Returns the length of the playing file in ms.
    240. def getlength
    241. return @Winamp_GetLength.call()
    242. end
    243. # Convert the length to a string. Format: "h:mm:ss".
    244. def lengthstr(length)
    245. return @Winamp_LengthStr.call(length)
    246. end
    247. # Return the current playing position.
    248. def getoutputtime
    249. return @Winamp_GetOutputTime.call()
    250. end
    251. # Set the volume (0 to 255)
    252. def setvolume(volume)
    253. @Winamp_SetVolume.call(volume)
    254. end
    255. # Set the pan (left=-127 to 127=right)
    256. def setpan(pan)
    257. @Winamp_SetPan.call(pan)
    258. end
    259. # Set the playing position position. Not supported of all in-plugins. Can be very slow.
    260. def setoutputtime(time)
    261. @Winamp_setoutputtime.call(time)
    262. end
    263. # Return <>0 if paused.
    264. def ispaused
    265. return @Winamp_IsPaused.call()
    266. end
    267. def handel
    268. game_name = 0.chr * 255
    269. zeichen = @ReadIni.call('Game','Title','',game_name,255,'.\Game.ini')
    270. return @FindWindow.call('RGSS Player',game_name.slice!(0,zeichen))
    271. end #end of init
    272. end #end of class
    273. end #end of module
    274. class RPG::BGM < RPG::AudioFile
    275. #--------------------------------------------------------------------------
    276. # ? Play BGM either normally or by using winamp plugin
    277. #--------------------------------------------------------------------------
    278. def play(pos = 0)
    279.   if @name.empty?
    280.         Audio.bgm_stop
    281.         Audio.winamp_bgm_stop
    282.         @@last = RPG::BGM.new
    283.   else
    284.         @@last = self.clone
    285.         if @file_extension == nil then #stores extension of file
    286.           @file_extension = self.get_file_extension(@name)
    287.         end
    288.         if @file_name == nil then #stores path and name of file
    289.           @file_name = G7_AFES_MOD::BGM_DIRECTORY + @name + @file_extension
    290.         end
    291.          if @file_extension.empty? or G7_AFES_MOD::BGM_EXT.include?(@file_extension) #normal music file
    292.            Audio.winamp_bgm_stop
    293.            Audio.bgm_play( @file_name, @volume, @pitch, pos)
    294.          else #if file required winamp plugin to play
    295.            Audio.winamp_bgm_stop
    296.            Audio.bgm_stop
    297.            if @file_dll == nil then
    298.                  @file_dll = self.get_dll(@file_extension) # get dll required to play file
    299.            end
    300.            Audio.winamp_bgm_play(@file_name, @volume, @file_dll) #Play the new audio format
    301.          end
    302.   end
    303.   Graphics.frame_reset
    304. end
    305. def self.fade(time)
    306.   Audio.bgm_fade(time)
    307.   Audio.winamp_bgm_fade_init(time * (60.0/1000.0)) #line added
    308.   @@last = RPG::BGM.new
    309. end
    310. def self.stop
    311.   Audio.bgm_stop
    312.   Audio.winamp_bgm_stop #line added
    313.   @@last = RPG::BGM.new
    314. end
    315. #--------------------------------------------------------------------------
    316. # ? Returns correct extension of file
    317. #--------------------------------------------------------------------------
    318. def get_file_extension(bgm_name)
    319. file_name= G7_AFES_MOD::BGM_DIRECTORY + bgm_name
    320. extensions = G7_AFES_MOD::BGM_EXT + G7_AFES_MOD::PSF_EXT + G7_AFES_MOD::GSF_EXT + G7_AFES_MOD::USF_EXT + G7_AFES_MOD::CUBE_EXT + G7_AFES_MOD::SNES_EXT + G7_AFES_MOD::GEN_EXT + G7_AFES_MOD::MOD_EXT
    321. file_extension = "" #nil by default
    322. for extension in extensions
    323. if FileTest.exist?(file_name + extension) #if it found extension
    324. file_extension = extension # remember extension
    325. break
    326. end
    327. end
    328. return file_extension
    329. end
    330. #--------------------------------------------------------------------------
    331. # ? Returns dll required to play file with winamp system
    332. #--------------------------------------------------------------------------
    333. def get_dll(file_extension)
    334.   if G7_AFES_MOD::PSF_EXT.include?(file_extension)
    335.         dll = G7_AFES_MOD::PSF_DLL
    336.   elsif G7_AFES_MOD::GSF_EXT.include?(file_extension)
    337.         dll = G7_AFES_MOD::GSF_DLL
    338.   elsif G7_AFES_MOD::USF_EXT.include?(file_extension)
    339.         dll = G7_AFES_MOD::USF_DLL
    340.   elsif G7_AFES_MOD::CUBE_EXT.include?(file_extension)
    341.         dll = G7_AFES_MOD::CUBE_DLL
    342.   elsif G7_AFES_MOD::MOD_EXT.include?(file_extension)
    343.         dll = G7_AFES_MOD::MOD_DLL
    344.   elsif G7_AFES_MOD::SNES_EXT.include?(file_extension)
    345.         dll = G7_AFES_MOD::SNES_DLL
    346.   elsif G7_AFES_MOD::GEN_EXT.include?(file_extension)
    347.         dll = G7_AFES_MOD::GEN_DLL
    348.   else
    349.         dll = nil
    350.   end
    351. return dll
    352. end
    353. end #end class
    354. class Scene_Base
    355. #--------------------------------------------------------------------------
    356. # ? Update the sound level if fading
    357. #--------------------------------------------------------------------------
    358. alias g7_afes_scene_base_update update
    359. def update
    360.   g7_afes_scene_base_update #update normally
    361.   if Audio.winamp_bgm_fading
    362.   Audio.winamp_bgm_fade #lower volume for the frame
    363.   end
    364. end
    365. end
    复制代码





    FAQ

    I'll be adding questions here as you guys ask them.

    Credit and Thanks

    - Zhek (me, VX Ace rewrite)

    - Mooshykris (Improvements over original version)

    - Guillaume777 (Original Script)

    Author's Notes

    This script has been tested with RPG Maker VX Ace. It might work in VX too, but I haven't tried it yet. Let me know if you use it successfully there!

    Dlls needed to make this work are available to download here. I have already included in_psf.dll which is needed to play PSX (.psf, .minipsf) music files. If you want to play other files such as SNES', you need to download in_spc.dll and so on.


    本贴来自国际rpgmaker官方论坛作者:Zhek处,因国际论坛即将永久关站,为了存档多年珍贵资料,署名转载到本论坛存档,由于官方帖子为英文原帖,需要中文翻译请点击论坛顶部切换语言为中文就可以将帖子翻译成中文浏览,方便大家随时查看,原文地址:https://forums.rpgmakerweb.com/threads/extended-music-script-3-5.2235/
    天天去同能,天天有童年!
    回复 送礼论坛版权

    使用道具 举报

    文明发言,和谐互动
    文明发言,和谐互动
    高级模式
    您需要登录后才可以回帖 登录 | 立即注册

    本版积分规则

    简体中文
    繁體中文
    English(英语)
    日本語(日语)
    Deutsch(德语)
    Русский язык(俄语)
    بالعربية(阿拉伯语)
    Türkçe(土耳其语)
    Português(葡萄牙语)
    ภาษาไทย(泰国语)
    한어(朝鲜语/韩语)
    Français(法语)
    关闭

    幸运抽奖

    社区每日抽奖来袭,快来试试你是欧皇还是非酋~

    立即查看

    聊天机器人
    Loading...

    QQ|Archiver|手机版|小黑屋|同能RPG制作大师 ( 沪ICP备12027754号-3 )

    GMT+8, 2026-8-17 13:34 , Processed in 0.088309 second(s), 55 queries .

    Powered by Discuz! X3.4

    Copyright © 2001-2020, Tencent Cloud.

    快速回复 返回顶部 返回列表