Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

FMOD Ex Audio Module Rewrite

FMOD Ex Audio
Version: 1.51

Introduction
A few years ago, Hiretsukan (Kevin Gadd) wrote an FMOD binding script for RGSS, which allowed RPG Maker XP to use the FMOD audio library for BGM playback, allowing access to many more file formats (including streamed OGG, AAC, WMA, IT, XM, MOD, etc.). It was a great script that could be easily extended. You could find his original script here. Still, the script was limited; it was focused on playing BGMs, and didn't support Music or Sound Effects, it also didn't support fading. Furthermore, some more features were needed such as remembering BGM position after battle and with the BGM/BGS memorize event command, and setting loop points for files other than MIDIs. With that in mind, I started modifying the script to add more and more features. The bulk of the script is still Hiretsukan's, but it's now much more accessible; I used it to rewrite the built-in Audio module. I also fully documented the script, fixed some bugs, and added position and loop point support.

Features
  • Aside from MIDIs, WAVs, and MP3s, the script supports many new formats: Streaming OGG, AAC, WMA, IT, XM, MOD, S3M.
  • Several layers of complexity with the highest being generally identical to the built-in Audio module and the lowest allowing direct access to FMOD's interface.
  • Remembers position of BGM with BGM/BGS memorize event command and after battle instead of starting over.
  • Ability to set loop points to any file type.
  • Source code provided and well-documented, so you could easily extend it farther to harness the power of FMOD.

Screenshots

It's an Audio script, so just try demo.

Demo

DEMO LINK

Check the script called 'FmodEx *' at the top of the script sections list for instructions on how to use it (also check 'Game_System *' and 'Other Classes *' at the bottom for the other classes)

Script

Just download the demo.

Instructions

Directly from demo:
Code:
 

# You need to copy the file fmodex.dll to your game folder (folder where

# your Game.exe and project file are). I've provided the DLL with the

# demo, and you can also get the latest version from FMOD's official

# website ([url=http://www.fmod.org/index.php/download]http://www.fmod.org/index.php/download[/url]).

#

# There are three scripts that could be used, the real script is only

# the first one, but the other scripts are provided for convenience:

#

# FModEx 

#           This includes the core functionality and the Audio module

#           rewrite. It's the main script and should be placed on

#           top of all scripts using it. Most people would just add a 

#           new section above the Game_System or Game_Temp section at 

#           the very top of the script editor and paste script there.

# Game_System

#           This script rewrites parts of the Game_System class to 

#           allow memorize_bgm to support remembering position,

#           and to allow the play methods to take an extra parameter

#           specifying position to start playing from. The last

#           addition is updating the Audio class every frame.

#           Add it anywhere under the Game_System script section.

#           If you don't need any of these features you don't need this

#           script, but you'll still need to at least call the Audio

#           update methods yourself.

# Other Classes

#           This is really an optional script that modifies the default

#           battle system to memorize map BGM and position instead of

#           starting over after the battle. Add it anywhere under

#           the Scene_Battle classes.

#

# Aside from integration with RMXP's default scripts, you can use

# this script the same way you used the old Audio class You could also

# access the FMod module for more options at a lower level, such as

# setting loop points (FMod.bgm_set_loop_points(first, second) in

# milliseconds) and getting current BGS position (FMod.bgs_position) to

# name a few.

 

FAQ

Feel free to ask any questions

Compatibility

Code:
 

# This script has different levels of compatibility depending on what

# scripts you use:

#

# FModEx 

#           This script overwrites the Audio module, but since

#           few if any other scripts would do that, it's pretty

#           much compatible with the majority of other scripts

#           without modifications.

# Game_System

#           The following methods of Game_System are redefined:

#             bgm_play, bgm_restore, bgs_play, bgs_restore

#           Any other script that redefines these methods may

#           not work well with this one. Most scripts wouldn't

#           do that, except ones dealing with audio as well.

#           I've marked the areas in the script where I made

#           changes to help you resolve any conflicts

#           The following methods of Game_System are aliased:

#             bgm_memorize, bgs_memorize, update

#           Other scripts that redefine these methods should

#           be placed above the Game_System script.

# Other Classes

#           The following methods of Scene_Battle are redefined:

#             judge, start_phase5, update_phase5

#           Any other script that redefines these methods may

#           not work well with this one. Custom battle system

#           scripts may do that, so you might consider not

#           including the Other Classes section and just

#           manually add position memorizing functionality.

#           I've marked the areas in the script where I made

#           changes to help you resolve any conflicts

#           The following methods of Game_Temp/Scene_Map are aliased:

#             Game_Temp#initialize, Scene_Map #call_battle

#           Other scripts that redefine these methods should

#           be placed above the Other Classes script.

#

# So in other words, FModEx is the most compatible, followed by

# Game_System, and finally the last and optional Other Classes. 

# If you use a custom battle system you probably shouldn't include

# Other Classes anyway. This isn't an SDK script and I never tested

# it with the SDK. It'll probably work, but refer to SDK documentation

# for more information.

 

Credits and Thanks

- Thanks to Hiretsukan (Kevin Gadd) for the original binding. If you'd like to credit it anyone, it's him!


Terms and Conditions

Code:
 

#   Use of this script is subject to the permissive BSD-like license below.

#   That basically means you could use it in any way you like as long

#   as you keep the following copyright and license unchanged and available,

#   and don't use name of copyright holder to promote products based on

#   this software. Note, however, that this license only applies to the

#   script, and not to the FMOD library. For more information about FMOD

#   licenses consult FMOD website: [url=http://www.fmod.org/index.php/sales]http://www.fmod.org/index.php/sales[/url]

#   It's free for non-commercial use, and they provide several types

#   of licenses for different types of developers.

#

# Copyright (c) 2005, Kevin Gadd

# All rights reserved.

#

# Redistribution and use in source and binary forms, with or without

# modification, are permitted provided that the following conditions are met:

#     * Redistributions of source code must retain the above copyright

#       notice, this list of conditions and the following disclaimer.

#     * Redistributions in binary form must reproduce the above copyright

#       notice, this list of conditions and the following disclaimer in the

#       documentation and/or other materials provided with the distribution.

#     * The name of the contributors may not be used to endorse or promote 

#       products derived from this software without specific prior written 

#       permission.

#

# THIS SOFTWARE IS PROVIDED BY Kevin Gadd ''AS IS'' AND ANY

# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED

# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE

# DISCLAIMED. IN NO EVENT SHALL Kevin Gadd BE LIABLE FOR ANY

# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES

# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;

# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND

# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT

# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS

# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

 
 
Hmm very useful indeed, I don't know if its possible stop the music when the window is inactive and resume it once the window is active again this is useful for making intro that sync with music or other DDR mock up mini games.  Other than that very nice script.
 

mawk

Sponsor

Very interesting! Does the FMOD audio library support Ogg looping? I recall that RMXP's limitations in that vein were a fairly major roadblock for me, since I'm a man who likes if at all possible to have an into to his songs, so if this drawback has been eliminated then I'm pretty much beside myself with joy right now.
 
Mimi Chan":13igm2o7 said:
Hmm very useful indeed, I don't know if its possible stop the music when the window is inactive and resume it once the window is active again this is useful for making intro that sync with music or other DDR mock up mini games.  Other than that very nice script.

Unfortunately, I doubt there's a simple way to do something like that. It'd require knowing when the game window loses focus, but since the Ruby interpreter is paused I'm not sure how you could detect that. If someone knows how to achieve something like that I wouldn't mind implementing it, but I personally don't have a clue.

Dr. Winston O'Boogie":13igm2o7 said:
Very interesting! Does the FMOD audio library support Ogg looping? I recall that RMXP's limitations in that vein were a fairly major roadblock for me, since I'm a man who likes if at all possible to have an into to his songs, so if this drawback has been eliminated then I'm pretty much beside myself with joy right now.

It does! The cool thing about FMOD is that if it works for one file format, it probably works for all other formats. BGM and BGS OGGs should loop by default. If you meant setting loop points and not just looping in general (for intros, etc.), then the answer is also yes (see instructions), but for now it's done manually. Future versions of the script will automatically read some tag to get the loop start and end values (like LOOPSTART and LOOPLENGTH OGG tags in VX).
 
Crikey, somebody actually got around to a proper rewrite of the Audio class. I believe something like this has been desired since the .net days! Good work, sir, good work. Actually makes the Memorise BGM command somewhat more useful...

I believe the only thing remaining is convincing the Audio module to use the base windows instruments for playing MIDI files (seeing as how they can sound totally different in Media Player compared to RMXP~ heck, one song I tried to use in RMXP once just ended up with the drumbeat...whilst it was a full piece before...haha...)
 
Hmm, but I don't how RMXP can pause everything (animation, sprite, etc.) when the window is inactive (with exception of the audio) maybe a script that detects when every script running is suddenly paused?  Hmm I cant explain well since I have zero script knowledge T.T
 
That's really interresting. I've tested a couple of Audio rewrites before but wasn't really happy with them.
I really like the "No more restarting BGM after battle" feature, I've been looking for this for a long time.
I'll take a look at this one as soon as possible.

Thanks for sharing it!
 
I just uploaded a new version of the script, it fixes some bugs and adds some minor stuff.

I believe the only thing remaining is convincing the Audio module to use the base windows instruments for playing MIDI files (seeing as how they can sound totally different in Media Player compared to RMXP~ heck, one song I tried to use in RMXP once just ended up with the drumbeat...whilst it was a full piece before...haha...)
Problem with the MIDIs and sound card instrument (not Windows) is that they are different on every PC, they might be pretty terrible on some PCs and great on others. If it sounds bad on RMXP you could be pretty sure it might sound that bad or worse on certain hardware. RMXP and FMOD standardize the way MIDIs are played across all platforms, so you can be sure it'd sound the same way on player's PC. If you really want the sound card instruments, you'll probably have to use a different API (Windows or Winamp or something), or figure out a way to supply your own sound font for FMOD instead of the default one. Alternatively, you could use another file format such as OGG or tracker formats.

Hmm, but I don't how RMXP can pause everything (animation, sprite, etc.) when the window is inactive (with exception of the audio) maybe a script that detects when every script running is suddenly paused?  Hmm I cant explain well since I have zero script knowledge T.T
Yeah but the script itself would be paused, so it can't detect that until after it's unpaused, and it'd be useless in that case. It's really not that simple. :(

Thanks for your replies~
 

Atoa

Member

I've had a hard time working to undestand poccil's audio module, in 2 days i was working Hard on it, i finished it today, and then i come and see this xD
I don't know if I thank you for this, or if i get angry for coming with this excactly after i finished my system...

Since your system is better, i'll thak you! =D
 
One would think that there would be a boolean status for whether or not the window was minimized, same as it is when its fullscreen.  That just doesn't make sense.
 

Atoa

Member

when i tested the demo i've got this error:

Line 293 'RuntimeErro' FMOD Ex returned error 23

I removed the line that caused the error
Code:
        raise "FMOD Ex returned error #{result}"
and i noticed one thing: only sounds in the game folder worked.
Musics on the RTP folder didn't work.

Is that normal?

EDIT.: i was looking the script, and it's not normal that the script can't detect my RTP.
And there's a strange sound before de BGM restarts after the victory ME
Too bad =/
 
Excuse me, will it be possible to rewrite audio module using BASS library like this?  I was always curious, and haven't seen one yet(though there's script which uses winamp plugin to play BGM).
 
Totti":2ph4c6ts said:
One would think that there would be a boolean status for whether or not the window was minimized, same as it is when its fullscreen.  That just doesn't make sense.
What usually happens is that Windows sends a message to the application telling it the window was minimized or lost focus, an application could choose to handle that message. It seems that when getting such a message, RMXP pauses the RGSS interpreter (and in effect pausing Graphics), but since sound is usually handled by a separate thread or by Windows, it's not paused. It has to do with the way the engine is designed internally, which is why there isn't a simple way to check if it happened, and even if you could, it'd have to be from a running program and not the paused RMXP.

When i tested the demo i've got this error:

Line 293 'RuntimeErro' FMOD Ex returned error 23

I removed the line that caused the error
Code:

        raise "FMOD Ex returned error #{result}"

and i noticed one thing: only sounds in the game folder worked.
Musics on the RTP folder didn't work.

Is that normal?

EDIT.: i was looking the script, and it's not normal that the script can't detect my RTP.
And there's a strange sound before de BGM restarts after the victory ME
Too bad =/
Error 23 means the file wasn't found, so you were right about it not detecting your RTP. I'd like to know the following things:
1. Do you use the standard RTP? (and not your own or some pirated RMXP version RTP)
2. From the start menu, either select Run in older Windows versions or type directly into the search box in Vista: regedit. With the Registry Editor open, browse to this location: HKEY_LOCAL_MACHINE\SOFTWARE\Enterbrain\RGSS\RTP (or anything similar) and tell me the values you see there -or better yet, take a screenshot.
3. Open the .ini file in the Game.exe directory and tell me the RTP values it lists.

As for the sound you hear when resuming BGMs, it seems to be an FMOD problem with setting the position in a MIDI file. I'll look more into it, but I doubt it'd be solved soon... it's a pretty minor annoyance as far as I'm concerned.

Landarma":2ph4c6ts said:
Excuse me, will it be possible to rewrite audio module using BASS library like this?  I was always curious, and haven't seen one yet(though there's script which uses winamp plugin to play BGM).
Well, you'd have to change the base classes to correspond to that library's structure, and figure out the DLL interface. In other words, it's possible, but you'll need to do some scripting of your own (or find someone to do it). The basics are the same though, whether you're using FMOD or Winamp or some other library: you map the interface of that library to RGSS, and then call the functions you need. Is there anything particular you require from BASS library that isn't in FMOD Ex?
 
I see. I think the problem is that I'm assuming that the RTP path ends with a \, after which I add the midi file name. For example:

C:\Program Files\Common Files\Enterbrain\RGSS\Standard\ + filename.mid = C:\Program Files\Common Files\Enterbrain\RGSS\Standard\filename.mid <- a valid file name

D:\Atoa\RPG Maker XP\RGSS-RTP + filename.mid = D:\Atoa\RPG Maker XP\RGSS-RTPfilename.mid <- not a valid file name!

I'll need to check for a \ at the end of the path and add one if it's not present. I'll fix it in the next version. Thanks for your help. :)
 
I just uploaded a new version that mainly deals with the issues raised by Atoa (RTP problem and BGM fading in after ME finishes playing). It also fixes several bugs and introduces some minor behavioral changes. Please download the new version and report any new bugs you might encounter.
 
Cowlol":3v4782yg said:
Landarma":3v4782yg said:
Excuse me, will it be possible to rewrite audio module using BASS library like this?  I was always curious, and haven't seen one yet(though there's script which uses winamp plugin to play BGM).
Well, you'd have to change the base classes to correspond to that library's structure, and figure out the DLL interface. In other words, it's possible, but you'll need to do some scripting of your own (or find someone to do it). The basics are the same though, whether you're using FMOD or Winamp or some other library: you map the interface of that library to RGSS, and then call the functions you need. Is there anything particular you require from BASS library that isn't in FMOD Ex?
I'm no programmer, but I can assume what BASS library does a bit.  Frankly, what I want is .mo3 support. 
 

Atoa

Member

Its just great now!

There's only a small (almost insignificant) bug, a small "tick" before Victory ME, but nothing really bad.

now i will study how to use the loop funcition =D
 
great script!, but I got an error in battle (even in the demo) it says 'FMOD Ex returned error 58' it seems to be related to the animation_process_timing method, I got the error just defending with all the battlers a few times.
there are also argument errors with some scripts when they say something like Audio.se_play('se_name'),
but you can fix it just changing the line 1257 of your script to
'def Audio.se_play(filename, volume = 100, pitch = 100) ', right?
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top