Correlating note with game frames on famitracker

Are you new to 6502, NES, or even programming in general? Post any of your questions here. Remember - the only dumb question is the question that remains unasked.

Moderator: Moderators

Post Reply
vnsbr
Posts: 22
Joined: Sun Feb 17, 2019 5:18 pm

Correlating note with game frames on famitracker

Post by vnsbr » Fri Sep 04, 2020 6:34 am

Hello all!

given a note(row?) and BPM of a song on famitracker how would I go to calculate in which frame that note will play(NTSC or PAL would do)?

scenario: I'm trying to do a rhythm game.

thanks!

none
Posts: 38
Joined: Thu Sep 03, 2020 12:56 am

Re: Correlating note with game frames on famitracker

Post by none » Fri Sep 04, 2020 8:04 am

Probably you wouldn't want to directly calculate the frame, but rather have an event handler that gets triggered by the music engine.

tepples
Posts: 22047
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Re: Correlating note with game frames on famitracker

Post by tepples » Fri Sep 04, 2020 8:55 am

If you're using the Pently sound driver, try pently_get_beat_fraction in its "BPM math" module. It returns a beat fraction from 0/96 to 95/96 calculated from the tempo and the declared time signature. Your code can use this to determine how far to move the arrows. Pently also supports callbacks that run on each row (pently_row_callback) or when the music loops (pently_dalsegno_callback).

vnsbr
Posts: 22
Joined: Sun Feb 17, 2019 5:18 pm

Re: Correlating note with game frames on famitracker

Post by vnsbr » Fri Sep 04, 2020 10:46 am

none wrote:
Fri Sep 04, 2020 8:04 am
Probably you wouldn't want to directly calculate the frame, but rather have an event handler that gets triggered by the music engine.
I have used famitone, havent looked deeply into it though.
tepples wrote:
Fri Sep 04, 2020 8:55 am
If you're using the Pently sound driver, try pently_get_beat_fraction in its "BPM math" module. It returns a beat fraction from 0/96 to 95/96 calculated from the tempo and the declared time signature. Your code can use this to determine how far to move the arrows. Pently also supports callbacks that run on each row (pently_row_callback) or when the music loops (pently_dalsegno_callback).
Interesting, I always used famitone for my pet projects, will take a look at Pently!

User avatar
rainwarrior
Posts: 7836
Joined: Sun Jan 22, 2012 12:03 pm
Location: Canada
Contact:

Re: Correlating note with game frames on famitracker

Post by rainwarrior » Fri Sep 04, 2020 2:18 pm

vnsbr wrote:
Fri Sep 04, 2020 6:34 am
Hello all!

given a note(row?) and BPM of a song on famitracker how would I go to calculate in which frame that note will play(NTSC or PAL would do)?

scenario: I'm trying to do a rhythm game.

thanks!
If the "tempo" is 150 BPM, the "speed" is how many frames per row of the pattern. The default speed of 6 results in 4 rows per beat:

6 frames/row × 4 rows/beat = 24 frames/beat

60 frames/second × 60 seconds/minute ÷ 24 frames/beat = 150 beats/minute

(For PAL we'd use 50 frames/second instead of 60.)


With the tempo set to 150 and otherwise only adjusting the speed, it's easy to make sure there is a whole number of frames per row. If the tempo is not 150 BMP then it has to approximate, sometimes having 1 extra or 1 less frame in a row to adjust the speed to match. Because of this approximation the precise rhythm of playback gets a bit uneven when the tempo is not 150, so you will probably want to keep your tempo locked to 150 for the purpose of a rhythm game, and only adjust the speed. (For PAL, you would use a tempo of 125 instead of 150 to ensure this.)

Your rows per beat could be anything you want, and the frames per row (speed) can be anything you want, but the simplest way to ensure a precise frame-locked rhythm is to use tempo 150 only (125 for PAL).

vnsbr
Posts: 22
Joined: Sun Feb 17, 2019 5:18 pm

Re: Correlating note with game frames on famitracker

Post by vnsbr » Sun Sep 06, 2020 2:21 pm

rainwarrior wrote:
Fri Sep 04, 2020 2:18 pm
vnsbr wrote:
Fri Sep 04, 2020 6:34 am
Hello all!

given a note(row?) and BPM of a song on famitracker how would I go to calculate in which frame that note will play(NTSC or PAL would do)?

scenario: I'm trying to do a rhythm game.

thanks!
If the "tempo" is 150 BPM, the "speed" is how many frames per row of the pattern. The default speed of 6 results in 4 rows per beat:

6 frames/row × 4 rows/beat = 24 frames/beat

60 frames/second × 60 seconds/minute ÷ 24 frames/beat = 150 beats/minute

(For PAL we'd use 50 frames/second instead of 60.)


With the tempo set to 150 and otherwise only adjusting the speed, it's easy to make sure there is a whole number of frames per row. If the tempo is not 150 BMP then it has to approximate, sometimes having 1 extra or 1 less frame in a row to adjust the speed to match. Because of this approximation the precise rhythm of playback gets a bit uneven when the tempo is not 150, so you will probably want to keep your tempo locked to 150 for the purpose of a rhythm game, and only adjust the speed. (For PAL, you would use a tempo of 125 instead of 150 to ensure this.)

Your rows per beat could be anything you want, and the frames per row (speed) can be anything you want, but the simplest way to ensure a precise frame-locked rhythm is to use tempo 150 only (125 for PAL).
thanks! i am still confused though...

i just checked and the music I have to sync speed is "11", the BPM is 150 which i think is a good start from what you said :)

the part that gets me:
*The default speed of 6 results in 4 rows per beat*

that scalated quickly =p maybe im confused about notation. How would that relate to a speed of 11 for example?

edit:
would that be 11x4 = 44frames per beat?

ye just tested thats it, thanks again :)
Last edited by vnsbr on Sun Sep 06, 2020 2:34 pm, edited 1 time in total.

lidnariq
Posts: 9655
Joined: Sun Apr 13, 2008 11:12 am
Location: Seattle

Re: Correlating note with game frames on famitracker

Post by lidnariq » Sun Sep 06, 2020 2:31 pm

As rainwarrior said, the standard convention in tracker formats is:
64 rows represents four measures of 4/4 where each quarter note is four rows.

However, as the speed gets further away from 6, the less likely this is true. At a speed of 11, that could mean that each pattern is four measures of ♩=82, or eight measures of ♩=164. Because this is a matter of interpretation, there isn't is a singular correct answer, and it comes down to how you choose to describe what's going on.

User avatar
rainwarrior
Posts: 7836
Joined: Sun Jan 22, 2012 12:03 pm
Location: Canada
Contact:

Re: Correlating note with game frames on famitracker

Post by rainwarrior » Mon Sep 07, 2020 4:58 pm

vnsbr wrote:
Sun Sep 06, 2020 2:21 pm
The default speed of 6 results in 4 rows per beat
Sorry, I should have said that differently.

The default tempo of 150 BPM and speed 6 gives you 4 rows per beat. That's just the built-in meaning of these in Famitracker. If you leave speed at 6, any tempo you give is the BPM of 4 rows at a time.

If you change speed, tempo BPM no longer matches 4 rows. E.g. speed 4 is 3/2x faster (6/4), or 6 rows per beat. Speed 12 would be 1/2x (6/12) as fast, or 2 rows per beat. Speed 3 is 2x faster (6/3), or 8 rows per beat. etc.

There is a visual highlight on every 4th row by default to mark the beat, but you can change this with a setting in the corner. This is a visual indicator only, though, and can be set any way you want.

Post Reply