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/.
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: