Update method present during all Scenes?

Status
Not open for further replies.

Hero_Claive

(Phoenix Ember)
Veteran
Joined
Jan 5, 2016
Messages
149
Reaction score
88
First Language
English
Primarily Uses
RMVXA
Bit of an odd question, but I'm not sure where to begin.

Basically I'm trying to insert a line of code into a frame update that tracks the BGM timestamp. In other words, the update method activates after a global boolean in Audio.play_bgm is made true and it increases +1 every frame update while the song is active. With a little bit of math and whatnot, you could theoretically calculate the position of the song at any time, assuming it loops properly. This could be used for several really interesting things but I won't go into that now.

This frame update method needs to be present during every scene, however, since BGM plays during any scene unless specified otherwise. So where would I insert this code? Scene_Base? SceneManager? I'm not sure about either because Scene_Base is only a superclass and when other Scene classes get created/erased, there's a bit of update lag - meaning the BGM tracker will be off. Is there a class that's just constantly present that always updates every frame without lag? Or should I just create one?

Any help is greatly appreciated!
 

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
40,098
Reaction score
13,704
First Language
English
Primarily Uses
RMMV
I'd probably put it in Scene_Base.update_basic which is where graphics and input are updated on each frame, and all other scenes should call this, by default. I don't understand what you mean by update lag when classes get created/erased. Only one scene should be active at a time. Scene_Base.scene_changing? might be useful as well, in case there could be two active while they are in the process of swapping over. So maybe only increment if !scene_changing? so only the "incoming" scene will do the update.

Note however, this will also run in Scene_Title, when you don't actually have a game in progress.
 

TheoAllen

Self-proclaimed jack of all trades
Veteran
Joined
Mar 16, 2012
Messages
5,592
Reaction score
6,522
First Language
Indonesian
Primarily Uses
RMVXA
With a little bit of math and whatnot, you could theoretically calculate the position of the song at any time, assuming it loops properly
Code:
Audio.bgm_pos (RGSS3)
Gets the playback position of the BGM. Only valid for ogg or wav files. Returns 0 when not valid.
;)

Remember, update stops when the window unfocused. So, checking the bgm position by using frame update is not advisable imo.
 

Hero_Claive

(Phoenix Ember)
Veteran
Joined
Jan 5, 2016
Messages
149
Reaction score
88
First Language
English
Primarily Uses
RMVXA
Code:
Audio.bgm_pos (RGSS3)
Gets the playback position of the BGM. Only valid for ogg or wav files. Returns 0 when not valid.
;)

Remember, update stops when the window unfocused. So, checking the bgm position by using frame update is not advisable imo.
What does this return? Samples, milliseconds? I didn’t find this attribute when I looked up the Audio class, but this is literally exactly what I need.

Edit: So this is getting extremely confusing. Clearly the game returns some sort of sample quantity, but the bitrate is totally off. The bitrate for all my music is 48000hz, but the game seems to have a much faster bitrate that I can't figure out. For example, playing an SE when the Audio.bgm_pos returns 526000 (48000 * 12) plays the SE long before the BGM reaches 12 seconds. Might start a new thread for this because I have no idea what the game is doing exactly.
 
Last edited:

TheoAllen

Self-proclaimed jack of all trades
Veteran
Joined
Mar 16, 2012
Messages
5,592
Reaction score
6,522
First Language
Indonesian
Primarily Uses
RMVXA
That I have no idea either. My guess is it's a sample. But I never really thought about it because I don't need it.
You know, because of the metadata that required for a BGM to loop uses a sample. If it isn't a sample, it can be a millisecond too, because BGM fadeout is also using millisecond.
 

gstv87

Veteran
Veteran
Joined
Oct 20, 2015
Messages
2,248
Reaction score
1,250
First Language
Spanish
Primarily Uses
RMVXA
seeing that position requires pitch to be specified when using bgm_play, I'd say the pitch might be affecting the sampling rate.
it's a common procedure to just resample the playback rate to alter pitch.... if you have a 48k file and you play it at 32k that gives you lower pitch without altering the wave itself.

"position" has to be samples, because the loop positions in the file itself are specified in samples.
if it doesn't coincide with what you're specifying, then the lot of samples is being altered..... closest guess, it's the pitch modifier.
 

Hero_Claive

(Phoenix Ember)
Veteran
Joined
Jan 5, 2016
Messages
149
Reaction score
88
First Language
English
Primarily Uses
RMVXA
seeing that position requires pitch to be specified when using bgm_play, I'd say the pitch might be affecting the sampling rate.
it's a common procedure to just resample the playback rate to alter pitch.... if you have a 48k file and you play it at 32k that gives you lower pitch without altering the wave itself.

"position" has to be samples, because the loop positions in the file itself are specified in samples.
if it doesn't coincide with what you're specifying, then the lot of samples is being altered..... closest guess, it's the pitch modifier.
Well the topic is rather useless if I can’t return an accurate sample position. The goal was to play a new BGM when the current one reaches a certain point during its loop. After hours of testing, it’s definitely impossible to determine with how the program cryptically treats bitrate.

Time to check out FMOD, I guess.
 

gstv87

Veteran
Veteran
Joined
Oct 20, 2015
Messages
2,248
Reaction score
1,250
First Language
Spanish
Primarily Uses
RMVXA
I made a constant print of bmg_pos during play, and the figures ramp up to several tens of millions, when the file itself, when opened in an audio program, only goes to less than five million.
the same time index in samples seems to return the same starting point (same second from the start) over different audio files, but the audio files themselves have different sampling rates, and I can't make sense of the numbers.
 

Patt-Ytto

I make pixel art and music for games.
Member
Joined
Aug 5, 2017
Messages
9
Reaction score
12
First Language
Spanish
Primarily Uses
RMVXA
Hello. Long time lurker.

I'm not sure if this will help you head in the right direction, but Superstroke's "THE HOUSE OF SNAKES" game, which he kindly left decrypted, had a neat playlist event inside his snakes and ladders game which somehow waits until the tracks are finished and then plays the next track in the list.

 

bgillisp

Global Moderators
Global Mod
Joined
Jul 2, 2014
Messages
13,522
Reaction score
14,255
First Language
English
Primarily Uses
RMVXA
That would require knowing though the length of the piece in advance (else the Audi.bgm_pos check will fail), and all pieces must be the same length.

Personally it would work just as well to blend them together into one track and put a small gap in them. That's how Heroes of Might and Magic 4 did it with their grassland theme, which you can hear here:


As far as the player is concerned that is a bunch of different tracks.

BTW, we do usually ask to not post on threads with no replies on the last thirty days, as usually by them the poster has moved on. Exceptions are for project pages, script threads, and resource files, and any thread you start. But since this is an old thread I'm going to close it out for now, if the original poster still needs help on this please report this post and state so and we'll reopen it.
 
Status
Not open for further replies.

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

Latest Threads

Latest Posts

Latest Profile Posts

People3_5 and People3_8 added!

so hopefully tomorrow i get to go home from the hospital i've been here for 5 days already and it's driving me mad. I miss my family like crazy but at least I get to use my own toiletries and my own clothes. My mom is coming to visit soon i can't wait to see her cause i miss her the most. :kaojoy:
Couple hours of work. Might use in my game as a secret find or something. Not sure. Fancy though no? :D
Holy stink, where have I been? Well, I started my temporary job this week. So less time to spend on game design... :(
Cartoonier cloud cover that better fits the art style, as well as (slightly) improved blending/fading... fading clouds when there are larger patterns is still somewhat abrupt for some reason.

Forum statistics

Threads
105,868
Messages
1,017,085
Members
137,584
Latest member
Faustus2501
Top