Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Calculate time in the song (e.g. in seconds) from a given beat and bpm of Ultrastar file #39

Closed
achimmihca opened this issue Aug 28, 2019 · 9 comments

Comments

@achimmihca
Copy link
Collaborator

achimmihca commented Aug 28, 2019

Issue type: Development discussion

I try to calculate note positions based on the BPM and beat in the song that is given in Ultrastar files.
My problem is that the values I calculate are not matching the speed when playing the file in USDX.

Example

I create a simple song file. It has 120 BPM and a single note with a duration of 10 beats:

#TITLE:EmptyTitle
#ARTIST:EmptyArtist
#MP3:EmptyArtist - EmptyTitle.mp3
#BPM:120
#GAP:1000
: 0 10 5 bla
- 15
E

The note of this file when viewed in Yass (or played in USDX) has a duration of 1.25 seconds.
However, with 120 beats per minute, it holds that
1 beat has a duration of 60 [s] / 120 [b] = 0.5 [s/b],
thus 10 beats have a duration of 5 [s] .
This is obviously different from the 1.25 seconds the note has in Ultrastar.

So, what is happening here? Did I make a mistake or is BPM in Ultrastar not "beats per minute"?

@basisbit
Copy link
Member

Best practice for BPM values in usdx files is to always use a multiple of the actual song BPM, so that it is between 200 and 400.
: 0 10 5 bla means the syllable bla with a pitch of 5 starts at beat 0 of the current sentence and ends at beat 10 of the current sentence.

@basisbit
Copy link
Member

the mp3 file you are using, is that maybe encoded in variable bitrate?

@achimmihca
Copy link
Collaborator Author

achimmihca commented Aug 28, 2019

The MP3 is irrelevant.
It's a file with 30 seconds of silence. You could also use any other mp3. The notes that are displayed in USDX will be the same because this only depends on the description of the notes in the Ultrastar txt file.

@basisbit
Copy link
Member

time is relative in usdx and YASS. So, if you use a file with variable bitrate instead of coded bitrate, depending on ffmpeg version used, the pointers->timestamp conversion is off. In USDX, the current playback position of the played audio frame is what tells the code what the "current beat" in game is.

@basisbit
Copy link
Member

basisbit commented Aug 28, 2019

I am just trying to understand why the values are off there. I quickly checked the relevant code in usdx and yes, your calculation should be correct.

@achimmihca
Copy link
Collaborator Author

Found the answer: http://yass-along.com/beats/

@achimmihca
Copy link
Collaborator Author

achimmihca commented Aug 28, 2019

You can think of BPM in Ultrastar files not as "beats per minute" but "bars per minute" in four-four time (Viervierteltakt).
Thus, one has to multiply with 4, to get what is commonly known as "beats per minute".

Anyway, the position of notes in Ultrastar files is then given in "beats per minutes".

This fixes the mismatch I had in my calculation: 5 [s] / 4 = 1.25 [s]

@basisbit
Copy link
Member

basisbit commented Aug 28, 2019

lol, never realized that before. Anyways, found that now in the code of USDX: https://github.com/UltraStar-Deluxe/USDX/blob/916a35c408214a35022e70b9e9629145f62803a2/src/base/USong.pas#L1742

@achimmihca
Copy link
Collaborator Author

achimmihca commented Aug 28, 2019

Yeah, you have to know this to get it right...

Anyway, displying the lyrics is now in sync with the music in my prototype. Last important thing missing now is recording notes and giving points. Yay!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants