Forums » General Questions » Change Music Rate Mid Song

1
Is it actually possible to change the music rate while playing?
I got it sort of to work on OpenITG with a little bit of Lua. The game even recognizes that it has been changes but the music stays at the current music rate.

Example: I start the song with a song rate of 1.0 (aka normal speed) and set it during the song to a rate of 0.1 (aka really slow.)
At the first glance nothing happend. But I did this in HAVOX (Galactic Gladiators Extra Stage) and I actually did something.
So the animations are playing like at a rate of (1.0/0.1=) 10.
I think that something withing the game has to be updated to change the gamespeed from 1.0 to 0.1 but I just don't know where.
Reply
Changing the music rate mid song can actually be done very simply with lua, and the music plays right afterwards too.

GAMESTATE:GetSongOptionsObject("ModsLevel_Song"):MusicRate(.5, 1)

This makes the music rate change from where it is to .5 at a speed of 1. A speed of 1 means that if it is currently at 1.5, it will take one second to reach .5. If it's currently at 1, it'll take half a second to reach .5.

Song animations go out of sync because the tweening and mod systems are not tied to the music timing. Mods that are changing have a speed field that controls how fast they move from the value in ModsLevel_Current to the value in ModsLevel_Song. A speed of 1 means a change of 1 unit per second. Percentages are normal numbers internally, with 100% being 1. So when Drunk gets set to 100%, it takes 1 second to go from 0% to 100% unless the speed it set to something else. Then when Drunk gets turned up to 1000%, it takes 9 seconds to go from 100% to 1000%. Music rate is completely ignored by the mod system. Unless the script author does a lot of extra work to calculate the music rate into the speed they use when changing mods, mods don't work right if you play the song at a different rate. Even if they decide to fetch the music rate every time they change a mod, to handle mid-song changes, it'll still be thrown off when the change occurs in the middle of a mod changing. The same problem is in the tweening system used to move actors around.

You can change the music rate mid song just fine and have it work on normal songs, but if you do it on a song with scripted animations, things will break and not play out right.
< cybik> til Kyzentun fixes bugs for breakfast
--
< maxvg1> shakesoda: then why do i still play lol
<@shakesoda> because you're an ITG player. And thus, a masochist
--
<@shakesoda> Kyzentun: I think you might need to put down the meshes for a bit
Reply
Okay, i now understand the concept behind changing mods.
I also know about the calculation work of adjusting the animations and all that. I planned to do just that.
The code worked in SM5 but I might not want to approach to understand the work behind that code to make it work in OITG/SM 3.95.
It seams way to high for my standards since I basicly just started working a little bit in lua (more like understanding others works and experimenting).

Yet I still have one question:
I did the following which gave me the result I had in my example from before:
GAMESTATE:ApplyGameCommand('mod,0.5x­music')

My rate-reader picked up the now active 0.5 rate mod but the game still plays everything as 1.0
It might be that I did the wrong thing here or something else has to be done for the game to notice the change.
Reply
I looked through openitg's code a bit, and it looks like it only ever sets the song playback rate at the beginning of the song, instead of updating it every frame. So it looks like it doesn't work because OpenITG doesn't support it.

The code I posted won't work in oitg at all because it uses functions I added to SM5 less than 2 years ago. The functions are based on the idea that dealing directly with numbers is easier than being forced to convert to and from strings, especially when you're trying to figure out what mods are already active.
< cybik> til Kyzentun fixes bugs for breakfast
--
< maxvg1> shakesoda: then why do i still play lol
<@shakesoda> because you're an ITG player. And thus, a masochist
--
<@shakesoda> Kyzentun: I think you might need to put down the meshes for a bit
Reply
Well, that explains why the rate didn't change for the song. This also explains why (some of) the animations where so fast since they picked it up just like normal.
Sadly it is unfortunate that I can't do what I wanted to do. Would have been fun playing around with it.
Still, thank you for the informations, Kyzentun. It helped a lot.
Reply