[RMVX ACE] MUSIC / EVENT SYNCH

Posts

Pages: 1
I want to know how precisely I can synch a BGM music and events.

Like...

I start playing a song, and at the same time a second-counting parallel event starts to run. When the second count reaches, for example, 45, something happens... and this event is supposed to happen exactly at 00:45 of the song.

How precise can it be? Are there ways to make it more precise?

I know there was a strange variation in RM2K3. I had a phase that lasted exactly 5 minutes and a mp3 that lasted exactly 5 minutes as well, but sometimes the song looped, and sometimes the phase ended before the song ending.
Wouldn't you just use a wait command in the parallel process for 2700 frames (which should equate 45 seconds) and then just adjust from there to fine tune it? The only problem would be players potentially tabbing out of the game, in which case the music would continue to play but the wait command would stop.
Well, that's the plan, I'm just wondering if it would work with precision. And if not, if there are other ways to do it.
You can see the sample number the BGM/BGS is on with... Audio.bgm_pos and Audio.bgs_pos? You'll have to know the sample rate ahead of time to convert that sample number into a time index though. For example if your music file has a sampling rate of 44.1KHz that's 44100 samples per second, times that by the # of seconds. Use a conditional branch to capture when the music position is about where you want it (I don't think you'll ever get it on a specific sample number but I haven't tested this) with something like:

Audio.bgm_pos > 1962450 and Audio.bgm_pos < 2006550


Which will trigger when the audio position is about between 44.5 and 45.5 seconds in. Experiment with it and get a feel for it, I don't have much experience with it and used it more for pausing/resuming music than timing anything on.

And as Housekeeping said if the window isn't active the music will keep playing but event code won't execute which can screw up timings but this method will hopefully make things execute on the right music cues.
Wow, I didn't know RMVXACe could do such thing!

Fact is, I don't even have the engine yet, so I can't experiment right now. But the game I'm planning depends heavily on that, and I want to know if it's possible before I go ahead with planning. Apparently it is! Thanks a bunch.

(let me know if you gave it a shot at testing yourself)
Sure, I can play with it a bit and make a helper script to make it easier to work with. Ideally the range you'd have to check is just 735 samples per frame (44.1KHz / 60 FPS) but I don't think I've ever seen the last two digits of the Audio.bgm_pos change from 00. In any case I'll experiment a bit and post results with a test project that does something at certain time intervals of the music playing. The helper script will probably be something like a call you can make in a conditional branch that'll deal in milliseconds so handling samples nor the range of samples isn't needed. Something like:

# Return true if the bgm position is ~45s in (or 45000 milliseconds)
Audio.bgm_pos_is? 45000

# If you need a specific sampling rate, like 22050Hz here. A script can't access the sampling rate afaik
# The default will be 44.1KHz with a way to change it
Audio.bgm_pos_is?(45000, 22050)
What I have in mind is a game with mechanics that are a liiiiiiiittle like Guitar Hero. That sort of code you're telling me should work, right?
Experimentation turned out to be a bust. Audio.bgm_pos is not the sample it is on (looping OGGs requires specifying what sample to loop to which is where I got that idea), although it still correlates in some way to what part of the music is playing. The documentation doesn't say what it is. The update interval of the Audio.bgm_pos is about 4.4 times a second, or every 0.22 seconds, or every ~15 frames. I had an event and a script print the Audio.bgm_pos every frame and it would show one value multiple times before jumping ahead by 33076. I can't think of a way to make it more precise than this so I think trying to time inputs to any specific part of the music track isn't going to work.

I think the Wait event command Housekeeping would be the better way to go than messing with the Audio.bgm_pos. I should've experimented before I opened my big dumb mouth, sorry.
It's alright. The wait command should work in theory, but for some reason unknown to me, it's subject to some random variation. I was just wondering if it would be better in vxace.
GreatRedSpirit can you send me this script? I suck at scripts, so I wouldn't even know what to do with the code you showed be... I know that's the conditional, but I don't know how to make it have an effect (like turn on a switch or something). I want to experiment with its numbers a little.

---edit---

So with the help from Sailerius I experimented with assigning the value of Audio.bgm_pos to a variable. The exact variable is just a big number which I can't understand, but the important thing is that it seems reliable... which means a certain number will always be associated with a certain part of the song, which is exactly what I needed. Which makes my next game possible and now I have a new reason to live.

In case anyone's wondering, the code is just:
$game_variables = Audio.bgm_pos
Sorry, I missed this post. That's what I was using (Audio.bgm_pos) writing to console every frame to see when the value updated. I thought you needed it more precise than what it gives and hence was useless. Glad to hear it does work well enough for your needs though!
Pages: 1