Simultaneous BGMs / Can I have two versions of the same song?

Lailia

Villager
Member
Joined
Sep 10, 2017
Messages
5
Reaction score
2
First Language
English
Primarily Uses
RMMV
Hello,

I have looked around for plugins or for answers to this but have had little success so far, maybe I'm just not describing it correctly. What I want to do is this: I have two versions of a BGM track, when the conversation is normal I have a version without drums, and when the conversation gets intense I want the version with drums to fade in and replace the music without drums in the same place that the track was already playing at. So, for example, if I'm 45 seconds into the no drums BGM and then things get intense in the conversation I would like to switch to the drums version at 45 seconds in. Basically the engine could play both tracks simultaneously but have one at 100% volume and the other at 0% until they need to switch over.

Is there a way to do this? I have a little coding knowledge but it's C#, I've got no Javascript knowledge.

I've tried messing with the fade in times, etc but nothing is doing what I want.

Thank you!
 

Ossra

Formerly Exhydra
Veteran
Joined
Aug 21, 2013
Messages
965
Reaction score
708
First Language
English
Primarily Uses
RMMV
Yes, you certainly can play more than one music file at once. I am not sure if there is a plugin that deals with that specifically, though.

The following is a very, very rough way to have two BGM playing at one time.

Code:
// Init Buffers
AudioManager._bgmBuffers = [];

// AudioManager.createBuffer(folderName, fileName)
AudioManager._bgmBuffers[1] = AudioManager.createBuffer('bgm', 'Battle1');
// audioBuffer.play(booleanLoop, intPosition);
AudioManager._bgmBuffers[1].play(true);

AudioManager._bgmBuffers[2] = AudioManager.createBuffer('bgm', 'Battle2');
// Set second BGM volume to zero ...
AudioManager._bgmBuffers[2].volume = 0;
AudioManager._bgmBuffers[2].play(true);




// Cross-Fade Buffers
// audioBuffer.fadeOut(intSeconds);
AudioManager._bgmBuffers[1].fadeOut(2);

// Set second BGM volume to 100%
AudioManager._bgmBuffers[2].volume = 1;
// audioBuffer.fadeIn(intSeconds);
AudioManager._bgmBuffers[2].fadeIn(2);
 

bhindi1224

NOT Indian Okra
Veteran
Joined
Sep 19, 2017
Messages
295
Reaction score
167
First Language
English
Primarily Uses
RMMV
I found something at this site which I believe is exactly what you're wanting. The problem is that it's written for VX. I have no idea how to program in Ruby OR javascript, so I can't help you at all. Assuming you can access the same types of methods in MV, I'd be willing to bet that someone could do it for you. Check out the demo project that was made and see if it's what you wanted.
#---------------------------------------------------
# Noyemi K's Dynamic Music System
#---------------------------------------------------
# Description:
# A dynamic music system that switches tracks on-the-fly
# without restarts. Useful for creating ambience that
# builds throughout various situations in an area.
#---------------------------------------------------
module DynamicMusicSystem

#---------------------------------------------------
# Editable Region
#---------------------------------------------------

# Specify the variable ID used to store the song variation variable.

SONG_VARIATION_ID = 1

# Specify the variation extensions
# "0", "1", "2", "3"], , etc. Can accomodate any
# number of variations up to the variable limit.
# ALSO: MAKE SURE YOUR FILENAMES CORRESPOND TO THIS ARRAY
# For example, for variations on "Forest.ogg", you might want to use
# "ForestNormal.ogg", "ForestCombat.ogg", or "ForestPuzzle.ogg"

VARIATION_EXTENSIONS =

end
#---------------------------------------------------
# Engine Region. DO NOT mess with anything beyond this point.
#---------------------------------------------------

class MusicVariations
def initialize
super
@extensions = DynamicMusicSystem::VARIATION_EXTENSIONS
#msgbox(@extensions) #DEBUG
end

def cache_BGM
@variationID = $game_variables
@songpos = Audio.bgm_pos
if @variationID == 0
$bgm_name = ('Audio/BGM/' + RPG::BGM.last.name)
end
end

def check_variations
if @extensions == nil
@play = @last
else
@play = $bgm_name + @extensions
@last = @play
end
Audio.bgm_play(@play, 100, 100, @songpos)
end
end


#---------------------------------------------------
# Starts the engine at the title
#---------------------------------------------------

class Scene_Title
#-------------------------------------------------------------------------
# * Alias Main to initialize the data class upon startup
#-------------------------------------------------------------------------
alias start_dms start
def start
start_dms
# Initialize
$dms = MusicVariations.new
end
end

class Game_Player

alias update_dms update
def update
update_dms
$dms.cache_BGM
$dms.check_variations
end
end
Edit: By the way, if I were a composer this would be amazing.
 
Last edited:

Lailia

Villager
Member
Joined
Sep 10, 2017
Messages
5
Reaction score
2
First Language
English
Primarily Uses
RMMV
Yes, you certainly can play more than one music file at once. I am not sure if there is a plugin that deals with that specifically, though.
Thank you thank you! This worked perfectly! It's awesome! And your code was easy enough for me to follow that I was able to create a fade out for the buffer at the end and return it to the overworld map music! It's great! <3

If you are interested here is a link to watch a clip of the script in action:
Thank you again!
I'll be sure to give you a special thanks in the credits!
 

Lailia

Villager
Member
Joined
Sep 10, 2017
Messages
5
Reaction score
2
First Language
English
Primarily Uses
RMMV
I found something at this site which I believe is exactly what you're wanting. The problem is that it's written for VX. I have no idea how to program in Ruby OR javascript, so I can't help you at all. Assuming you can access the same types of methods in MV, I'd be willing to bet that someone could do it for you. Check out the demo project that was made and see if it's what you wanted.

Edit: By the way, if I were a composer this would be amazing.
Thank you bhindi! I had already started working on using Ossra's code before I saw your response, this method looks good too! But if you are interested, Ossra's script worked very well in MV!
 

Lailia

Villager
Member
Joined
Sep 10, 2017
Messages
5
Reaction score
2
First Language
English
Primarily Uses
RMMV
If you are interested here is a link to watch a clip of the script in action
I don't mean to spam, but I forgot to mention that you can hear the songs slightly out of sync there, but that's because my two tracks aren't perfectly lined up I think, so that's not a problem with the script!

Thanks again!!
 

Ossra

Formerly Exhydra
Veteran
Joined
Aug 21, 2013
Messages
965
Reaction score
708
First Language
English
Primarily Uses
RMMV
Keep in mind that the above code fragment is most certainly not save friendly. If you have two or more music buffers running in the background and the player saves and then loads a game, both buffers will be cleared and no song will be playing. Without a proper plugin to add in a save functionality, I would only use the cross-fade code in places where the player cannot save and load. I would work on the plugin, but I am a bit preoccupied, at the moment.

For one buffer you can use the normal BGM Play option in the Event Commands list as that buffer is a part of the data that is saved. Then you can use AudioManager._bgmBuffer.fadeIn, AudioManager._bgmBuffer.fadeOut and so on to manipulate the normal BGM Play buffer.


Also, try not to double or triple post. Add any updates to your last post instead. (I am sure a moderator will slip in and say the same thing here shortly.) o;
 

Lailia

Villager
Member
Joined
Sep 10, 2017
Messages
5
Reaction score
2
First Language
English
Primarily Uses
RMMV
Keep in mind that the above code fragment is most certainly not save friendly. If you have two or more music buffers running in the background and the player saves and then loads a game, both buffers will be cleared and no song will be playing. Without a proper plugin to add in a save functionality, I would only use the cross-fade code in places where the player cannot save and load. I would work on the plugin, but I am a bit preoccupied, at the moment.

For one buffer you can use the normal BGM Play option in the Event Commands list as that buffer is a part of the data that is saved. Then you can use AudioManager._bgmBuffer.fadeIn, AudioManager._bgmBuffer.fadeOut and so on to manipulate the normal BGM Play buffer.


Also, try not to double or triple post. Add any updates to your last post instead. (I am sure a moderator will slip in and say the same thing here shortly.) o;
I had wondered about that. I think I found a way to work around that by fading out then turning off the buffers, and then having the system start up a BGM again in the normal way when returning back to the overworld map (which is where you'll always go after these encounters.)

Here's an image of how I've got it:
https://drive.google.com/open?id=0B3LlHTBbGu1hMEVzVk4zWUVIYk0

Sorry about the multiple posts! This is my first time posting on this forum, I wasn't sure how to do it. 0.o
 

Ossra

Formerly Exhydra
Veteran
Joined
Aug 21, 2013
Messages
965
Reaction score
708
First Language
English
Primarily Uses
RMMV
I just wanted you to be aware of the volatility of the code scrap. Players are very skilled at making things blow up. ;o If you have found a way to make it work, then that is great!
 

bhindi1224

NOT Indian Okra
Veteran
Joined
Sep 19, 2017
Messages
295
Reaction score
167
First Language
English
Primarily Uses
RMMV
Please don't laugh too hard at the inexperienced armchair scripter, but I've been looking around for this stuff too out of curiosity. I am still trying to find something. All I need is to figure out how to get the current position and populate the AudioManager._bgmBuffer.pos variable, then it would be easy to change tracks on the fly at the same exact point, or even to modify it slightly if they are out of sync.

Edit: P.S. I know about as much scripting as you can learn in a couple of hours by looking only at examples. So feel free not to take me seriously :p
 

Ossra

Formerly Exhydra
Veteran
Joined
Aug 21, 2013
Messages
965
Reaction score
708
First Language
English
Primarily Uses
RMMV
You can get the exact position in seconds by using AudioManager._bgmBuffer.seek()
 

bhindi1224

NOT Indian Okra
Veteran
Joined
Sep 19, 2017
Messages
295
Reaction score
167
First Language
English
Primarily Uses
RMMV
Ok. So I made events that switched the sound from one file to another while preserving the current position in the played file. I haven't tried it with a really long loop because the files aren't made to sync, but I think it will work.
Code:
var myBgm = {  name: "Battle1",  volume: 80,  pitch: 100,  pan: 100};
AudioManager.playBgm(myBgm,AudioManager._bgmBuffer.seek());
I'm sure it's probably wrong, but it works for me by changing the song from whatever is playing to the one listed in the script.

Edit: Lol, you told me that with less than a minute thinking I'm sure, but I've spent hours tinkering around to finally find it. I post all proud of myself and then find the code waiting right after I hit submit. :kaomad2:
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Posts

Latest Profile Posts

Out of sudden, snow. Everywhere.
Blech. I hate coming up with stories. Making gameplay is fun but coming up with lore and reasons for these areas/mechanics just makes me sleepy.
40 card deck size, the plugin seems more sluggish.
Village theme I composed for a commission!

Forum statistics

Threads
94,568
Messages
921,955
Members
124,435
Latest member
JamnRed1
Top