I've been searching for an answer around this forum, but I can't find anything. Is this possible? For example, I want the ability to lower the pitch of a current BGM track mid-gameplay. Instead of restarting the track (which is what it does right now), I want it to continue where it left off seamlessly.
Is there a way to change the pitch of BGM during gameplay without having to replay the track?
RPG Maker MV SupportSure!
I've done this before, but it depends how you are structuring it.
The way I did it once was that I had a BMG playing at 90% volume on a parallel event, page 1.
However, when a certain switch was triggered, that same parallel event would switch to page 2, which was also a parallel event that played the same BMG at 10% instead of 90%.
It still played where it left right off without issues on my end, but I'm not sure how you're coding it.
By any chance could you show your current code section for the BMG?
I'm sure there's others ways to do so, but as far as I'm aware, if you tell RPG Maker to play a BMG, then command it to play BMG again (even if its different pitches/tones), it should still continue right where it left off.
I've done this before, but it depends how you are structuring it.
The way I did it once was that I had a BMG playing at 90% volume on a parallel event, page 1.
However, when a certain switch was triggered, that same parallel event would switch to page 2, which was also a parallel event that played the same BMG at 10% instead of 90%.
It still played where it left right off without issues on my end, but I'm not sure how you're coding it.
By any chance could you show your current code section for the BMG?
I'm sure there's others ways to do so, but as far as I'm aware, if you tell RPG Maker to play a BMG, then command it to play BMG again (even if its different pitches/tones), it should still continue right where it left off.
This seemed to work for me in a Script command:
Just change the value on the first line. Note that
Not sure what @PoptartPresident used (a plugin, or maybe older core scripts?) but by default when you change the pitch, RMMV replays the track from the start.
That's what I saw just now when I tested it, too. Simply changing
Edit - I've since realised that this won't save the pitch change, and can have timing problems, e.g. for BGM loops. I recommend something like this instead:
Replace
var newPitch = 0.8;
AudioManager._bgmBuffer._sourceNode.playbackRate.setValueAtTime(newPitch, WebAudio._context.currentTime);Just change the value on the first line. Note that
0.8 means 80% pitch. 👋Not sure what @PoptartPresident used (a plugin, or maybe older core scripts?) but by default when you change the pitch, RMMV replays the track from the start.
JavaScript:
Object.defineProperty(WebAudio.prototype, 'pitch', {
get: function() {
return this._pitch;
},
set: function(value) {
if (this._pitch !== value) {
this._pitch = value;
if (this.isPlaying()) {
this.play(this._sourceNode.loop, 0);
}
}
},
configurable: true
});
_pitch does nothing, since that's just a value. play recreates the buffer's audio nodes and resets the playback rate (used for pitch adjustment).Edit - I've since realised that this won't save the pitch change, and can have timing problems, e.g. for BGM loops. I recommend something like this instead:
if (AudioManager._currentBgm) {
var b = AudioManager._bgmBuffer;
// Set new pitch directly to avoid restarting from 0
b._pitch = (AudioManager._currentBgm.pitch = 80) / 100;
// Directly adjust source playback rate (perceived pitch)
b._sourceNode.playbackRate.setValueAtTime(
b._pitch, WebAudio._context.currentTime
);
// Recreate end timer structure
b._startTime = WebAudio._context.currentTime - b.seek() / b._pitch;
b._removeEndTimer(); b._createEndTimer();
}Replace
80 with the new pitch value. This (and its MZ equivalent) have been added to the MV / MZ Script Call List ("Change BGM Pitch"). 👋Oh wow really? I dunno how I did it then since I made it a while ago. I don't believe I used plugins for audio.
I actually looked back and I'll show you what I have:
In the first 2 screenshots, this is my parallel event on the maze map, so it's playing the BMG constantly. And when a Switch "Cutscene Silence" is OFF/ON, it plays the same BMG at different volumes.
When the switch is OFF, it plays the louder version. If Switch is ON, it plays the quieter version.
The last 2 screenshots show my events in the maze where if the player walks on it, it triggers the "Cutscene Silence" switch to turn on/off as you step away or step on them (and even play other audio).
Since the parallel event is always running, that BMG is always somewhere in the background even if it's quieter. But it doesn't "jump cut" or anything like that, it just continues the audio like normal.
I think it has to do with how I evented it in my particular game scenario, but I'm fairly certain I never needed plugins or script calls.
Volume and pitch aren't the same thing 😉
Omg XD
Aight well that explains it. Nevermind then!
Works perfectly! You're a life saver. I saw a bunch of threads asking the same question and no one had an answer. Thank you.
Great, you're welcome!
This thread is being closed, due to being solved. If for some reason you would like this thread re-opened, please report this post and leave a message why. Thank you.
Original thread: https://forums.rpgmakerweb.com/threads/is-there-a-way-to-change-the-pitch-of-bgm-during-gameplay-without-having-to-replay-the-track.148039/