I was thinking it may be possible to sync a songs BPM with the game ticks by simply knowing how long a game tick is in seconds, then doing the math conversion to convert it in to BPM.
I'd like to know if this is plausible or if some sort of loading delays in the game would make the song and the ticks go out of sync?
I just thought it could be neat to have a game where the NPCs, animations, blinking, etc... is synced to the tempo of the music. This could especially be fun for games that require player input to be timed to an instruments beats in the music.
⊕ P E R S O N A L M U S I C: https://open.spotify.com/album/6fEo3fCm5C3XhtFRflfANr
⍠ C O L L A B M U S I C: https://dustpuppets.bandcamp.com/releases
Years ago I had written two cutscenes for Powerstick Man that required game ticks to match with the beat of the MIDI song for every play. Because the speed of a tick is dependent on the speed of the computer, this had the potential (and likelihood) of screwing up the sync for many players, even if it remained mostly consistent for me.
TMC helped me with this problem by including "milliseconds" into the scripting dictionary.
Here are the scripts he wrote to get music syncing working for me:
Note 1: "waitsecs start" is necessary for beginning the sync. This should be called in the script first (as a function) before you begin the syncing process.
Note 2: The two lines in "waitsecs, ticks" (one of them pounded out) determine the sync speed. I forget which one is which, but I used one line for dialogue speed and the other for action speed. You'll have to play with the numbers a bit until you find a speed that works best for your situation. The numbers should never be far off from what they are in the script I've posted. As you can see, I have two versions of "waitsecs" in my game: one for dialogue and the other for action.
Note 3: "waitsecs (ticks)" should take the place of "wait (ticks)" when you actually script your waits. This will keep them consistent with real time rather than computer speed time.
So, the whole thing might look like this:
Note 4: The script doesn't autodetect the song, so you'll have to manually adjust the numbers as you test. Going by experience, I can tell you this is no fast project. Allow yourself a long time to get it right. But once you get it right, it'll stay right.
Let me know if that helps.
Place Obligatory Signature Here
TMC helped me with this problem by including "milliseconds" into the scripting dictionary.
Here are the scripts he wrote to get music syncing working for me:
Code:
global variable (1,waitsecs counter)
script, waitsecs start, begin
waitsecs counter := milliseconds
end
script, waitsecs, ticks, begin
#waitsecs counter += ticks * 56 + 12
waitsecs counter += ticks * 57
while (milliseconds <= waitsecs counter) do (wait)
end
script, waitsecs2, ticks, begin
waitsecs counter += ticks * 56 + 12
#waitsecs counter += ticks * 57
while (milliseconds <= waitsecs counter) do (wait)
end
script, waitsecs start, begin
waitsecs counter := milliseconds
end
script, waitsecs, ticks, begin
#waitsecs counter += ticks * 56 + 12
waitsecs counter += ticks * 57
while (milliseconds <= waitsecs counter) do (wait)
end
script, waitsecs2, ticks, begin
waitsecs counter += ticks * 56 + 12
#waitsecs counter += ticks * 57
while (milliseconds <= waitsecs counter) do (wait)
end
Note 1: "waitsecs start" is necessary for beginning the sync. This should be called in the script first (as a function) before you begin the syncing process.
Note 2: The two lines in "waitsecs, ticks" (one of them pounded out) determine the sync speed. I forget which one is which, but I used one line for dialogue speed and the other for action speed. You'll have to play with the numbers a bit until you find a speed that works best for your situation. The numbers should never be far off from what they are in the script I've posted. As you can see, I have two versions of "waitsecs" in my game: one for dialogue and the other for action.
Note 3: "waitsecs (ticks)" should take the place of "wait (ticks)" when you actually script your waits. This will keep them consistent with real time rather than computer speed time.
So, the whole thing might look like this:
Code:
plotscript, Gonna Make You Dance, begin
suspend player
suspend box advance
waitsecs start #you have to call this first, or else the sync won't work
play song (5)
waitsecs (50) #wait for the opportune time to bring up the action or dialogue
show text box (1000) #"Listen to the beat"
waitsecs (25) #wait for beat change
show text box (1001) #"Listen to that fat beat"
waitsecs (32) #wait for the fat beat
advance text box
set hero direction (0,east) #hero begins dancing to the beat
waitsecs2 (5)
set hero direction (0,south)
waitsecs2 (7)
set hero direction (0,east)
waitsecs2 (5)
show text box (1002) #"That's a big dancin' fool"
waitsecs (35)
show text box (1003) #"He ain't that cool."
waitsecs (31)
advance text box
resume box advance
resume player
end
suspend player
suspend box advance
waitsecs start #you have to call this first, or else the sync won't work
play song (5)
waitsecs (50) #wait for the opportune time to bring up the action or dialogue
show text box (1000) #"Listen to the beat"
waitsecs (25) #wait for beat change
show text box (1001) #"Listen to that fat beat"
waitsecs (32) #wait for the fat beat
advance text box
set hero direction (0,east) #hero begins dancing to the beat
waitsecs2 (5)
set hero direction (0,south)
waitsecs2 (7)
set hero direction (0,east)
waitsecs2 (5)
show text box (1002) #"That's a big dancin' fool"
waitsecs (35)
show text box (1003) #"He ain't that cool."
waitsecs (31)
advance text box
resume box advance
resume player
end
Note 4: The script doesn't autodetect the song, so you'll have to manually adjust the numbers as you test. Going by experience, I can tell you this is no fast project. Allow yourself a long time to get it right. But once you get it right, it'll stay right.
Let me know if that helps.
Place Obligatory Signature Here
Hey that's awesome. Ill be bookmarking this. I wasn't exactly planning on using this for my own game but was more or less curious. I'm glad I asked though. Doesn't look too hard to pull off.
So does this require using MIDI, or can any filetype be used?
⊕ P E R S O N A L M U S I C: https://open.spotify.com/album/6fEo3fCm5C3XhtFRflfANr
⍠ C O L L A B M U S I C: https://dustpuppets.bandcamp.com/releases
So does this require using MIDI, or can any filetype be used?
⊕ P E R S O N A L M U S I C: https://open.spotify.com/album/6fEo3fCm5C3XhtFRflfANr
⍠ C O L L A B M U S I C: https://dustpuppets.bandcamp.com/releases
That's up to you. The scripts match ticks to real-time milliseconds, so you can use them however you want. The difference between waits and waitsecs is that waitsecs will keep consistent with real time, whereas waits will change depending on computer speed. So, waitsecs will work with BAMs, MIDIs, OGGs, your watch, or whatever time needs you wish to keep consistently the same for all users, not just for you.
Place Obligatory Signature Here
Place Obligatory Signature Here
Excellent.
⊕ P E R S O N A L M U S I C: https://open.spotify.com/album/6fEo3fCm5C3XhtFRflfANr
⍠ C O L L A B M U S I C: https://dustpuppets.bandcamp.com/releases
⊕ P E R S O N A L M U S I C: https://open.spotify.com/album/6fEo3fCm5C3XhtFRflfANr
⍠ C O L L A B M U S I C: https://dustpuppets.bandcamp.com/releases
A couple notes:
The reason for the strange numbers in those waitsecs scripts is that PR had long existing scripts which made use of 'wait', and we tried to find some numbers that matched the frame rate that the engine was running on his computer and caused that particular script to sync up. You could just change the script to take an argument in milliseconds instead.
Also, it's better to write:
rather than the other way around, because playsong may cause a small random delay before the music starts (rather than after).
I have no idea how stable and consistent MIDI timing is on different OSes.
The reason for the strange numbers in those waitsecs scripts is that PR had long existing scripts which made use of 'wait', and we tried to find some numbers that matched the frame rate that the engine was running on his computer and caused that particular script to sync up. You could just change the script to take an argument in milliseconds instead.
Also, it's better to write:
Code:
play song (...)
waitsecs start
waitsecs start
rather than the other way around, because playsong may cause a small random delay before the music starts (rather than after).
I have no idea how stable and consistent MIDI timing is on different OSes.
INTERESTING.
I had actually thought of scoring my game so that the sections flowed smoothly back and forth like different parts of the same song (or at very least transition semi-smoothly). This knowledge could potentially be useful in attempting to pull this off, though I may be biting off more than I can chew here.
Cody Gaisser
I had actually thought of scoring my game so that the sections flowed smoothly back and forth like different parts of the same song (or at very least transition semi-smoothly). This knowledge could potentially be useful in attempting to pull this off, though I may be biting off more than I can chew here.
Cody Gaisser



