Cross Fade Audio Script

Neon Black

The Classy Prostitute
Mar 17, 2012
Reaction score
First Language
Primarily Uses
Cross Fade Audio V1.0

Created by Neon Black

What is it?

This is a script which allows you fade out one audio into another audio at the same spot. Sounds easy enough to do already I'm sure, however it works a little differently than you might imagine and actually requires a bit of modification and tweaking to work properly. Also note the "cross" part of "cross fade". This means that the old audio file continues playing while the new file begins (at least somewhat). Note that this script is not "perfect" but it's about as good as you're going to get without someone doing some serious modifications. I will also explain the issues with this script below.

How can I use it?

Place this script anywhere in the materials section above main. If you notice incompatibility with another script, place this script above that script. If you still experience incompatibility issues, please post what scripts you are using as well as what kind of error you are getting. This script is easy enough to use and just requires you to enable a single variable to begin using cross fade, however there are a few limitations you can use while actually using cross fade.

  • Turn the switch on and music will always cross fade. This means that while the switch is on, the music ending will fade out and the music starting will fade in, and attempt to be at the same spot in the song, even if the two musics are different. If you want to change music without a fade in effect, you must turn the switch off.
  • Playing a music effect (ME) will disable cross fade. Due to an issue related to how the script works, playing a ME will disable cross fade as well as revert background music and background sound to normal if they are currently "abnormal". This can actually be a good way to "repair" the music after using cross fade for a little while.
  • You cannot use background sounds (BGS) while cross fade is enabled. This script works by alternating music between background music and background sound. For this reason, while cross fade is enabled you will not be able to use BGS. Sorry. BGS should work while this is disabled.
  • Music to cross fade must be .OGG or .WAV. Not my rule. This is enterbrain's. MP3s do not work with positions. While the fade in and fade out will most likely work with .MP3s, the whole "starting at the same spot" thing will not. In my opinion .OGGs are better to work with due to being smaller and being able to loop. (Should I make a .OGG looping tutorial or is there already one?)

As I mentioned there are also certain issues with the script which I am unable to resolve (and most likely never will). The issues are as follows.

  • Stereo tracks do not properly work with track offset. To explain a little, the track does not quite play at the same position as the old track, so a "track offset" had to be added to have the new track play closer to the current position of the old track. For some reason stereo tracks like having a slight bit of static at the end of their track while they are the BGS if you have defined an offset. For those of you who still want to use stereo tracks with this, I have not yet tested how this problem works with looping tracks, so that might be a solution!
  • The tracks do not always fade in at the proper place. I was having a rather ridiculous problem with tracks not wanting to properly fade in without losing or gaining some of the beat, so I decided to write a quick script that would calculate the position of a track every frame to help me determine the best offset. The results were actually quite surprising and informative. The Audio module does not update the position every frame, or when you call the position check or anything like that. Rather it only updates every 8~12 frames (not sure what the variance is about). This means it is possible to have some variance in the position of the track by about 150~180 milliseconds. There's not a whole lot I can do about this, but it's not really that noticeable anyway. Sorry.

What does it work with?

It should work with most other scripts. It modifies the Audio module, so unless someone else decided to edit the audio module, you should be good.

Alias - Audio: bgm_play, bgm_stop, bgm_fade, bgm_pos, bgs_play, bgs_stop, bgs_fade, bgs_pos, me_play

New Objects - Audio: check_fades, stop_fades, cross_bgm, cross_bgs

How can I get the code?

Version 1.0 (base script, 6.4.2012) is available from my pastebin account here or from the demo on my mediafire account here.

I would like to use this code.

This work is licensed under a Creative Commons Attribution-NonCommercial 3.0 Unported License.

Permissions beyond the scope of this license may be available at http://cphouseset.wo...d-terms-of-use/.

Author's Disclaimer:

A while back Raven Blue approached me to create a script like this for VX. Sadly my meager Ruby skills are not enough to really do anything extraordinary, so I wasn't able to do it. Now with certain new things I am able to create the desired script with Ace. Also, I probably need some music credits. Windhollow Cavern was composed by Raven Blue for use with this script. Might be a good idea to track him down and ask him if you can use it before you do. Megaboss was composed by amkrogh89 and can be obtained from his thread here. Rigid Paradise was composed by ZUN and was used in Touhou Project. It was just the music I was testing with, so I don't really recommend stealing it, even though I kinda did "borrow" it....
Last edited by a moderator:


Jul 2, 2013
Reaction score
First Language
Primarily Uses
Is there a way to make it so when a song is already playing, and you have it set to play that same song again on another map, the song won't crossfade or attempt to load the song and end up looping its fade if the song is in a Parallel Process event?

Latest Threads

Latest Posts

Latest Profile Posts

I've started up Pillars of Eternity. It's interesting how the game does a "select choice" cutscene using still image art for dramatic flair. I wonder if that might work for my RPGMaker project.
The self-righteous indignation of family when you expect them to pay back money you've leant to them never ceases to amaze me.
Gamedev for relaxing? yes or no?
I've been having a rough couple of months and as such let down some friends of mine in the RPG Maker community. I still need time to get back to my normal self, but it's nice to be back, to read articles, and to design again (albeit at a slow pace). Hope to give updates on Kid Crescent soon.
Friendly reminder that you don't have to be able to do absolutely everything. It's okay to scale back features or assets if things are too much - especially if you're the only one working on the game! And you can always add things in later. <3

Forum statistics

Latest member