Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Discussion / syncing game with music - a few issues...

Author
Message
TheComet
16
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 22nd Jul 2009 19:52
Hello there!

OK, I have a level in TombStone where you roll down in a mining kart deep into the ground, and I want the game music to sync with the game. So I made my frame regulator. What it does is it takes the system time before the loop. Then there is a variable in the game loop that counts the loops. Then I compare the two and skip or add extra frames in a spread out fashion to keep the two at level.

Here are the issues:

1) If a player pauses, and resumes, I will have to grab a new system time in order to continue syncing correctly. This however erases the last difference, and the game may be out of sync by a few loops. If you do that regularly, you may start to notice something. How can I approach this so that can't happen?

2) A question about midnight. If I get the system time, then 60 loops later get the system time and subtract the two, and the 60 loops go over midnight, won't the timer reset and I will get a ridiculously large number?

3) On a few computers with low specs, the music may not run at the desired speed. This means that my technique will fail on these machines, because the music runs slower than usual. How can I approach this so that can't happen as well?

Many thanks to any answers,

TheComet


Make the path of your enemies easier with Waypoint Pro!
Latch
17
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 22nd Jul 2009 21:09
This is one of the reasons why developing good game music is much more difficult than may be assumed. Anyway, instead of using the system time, you should use the timer(). It keeps an ongoing upward count from when the machine was turned on. And it's precision is in 1/1000 of a second so that should give you more flexibility than the system time.

If you use the looping (iterations) and the sync rate is 0 as your music syncronization, then the timing could be anywhere on any machine so that brings us back to using the timer() again to manage the syncing. There should already be contingencies in the game to keep it at the same speed no matter what computer it is on.

As far as the actual music, a technique to use is to break a long piece of music into small modules. The design of the music should be such that almost any module can lead into or follow another. So if there was a character walking, there could be a general them and a set of modules follow a certain order. If the character suddenly falls through a hole, then on a trigger play that particular action module on top of or instead of the currently playing module. If the music is written properly, then they can blend. If not, the modules have to be small enough to fit into certain timing thresholds. If the character is walking then starts to run, you can fade out the general theme and fade in the running module.

Most of the modules can be controlled by events such as keys pressed or the appearance of an enemy or the position in the world the character moves to. Control the music very much like you would control sound effects, just make sure that the small sections of music can blend well with each other so it sounds like a dynamic piece all under the same theme.

For the mining cart, say you have way points or markers along the track. When the cart reaches a certain point, new music plays or stops. Again this ties in with the modularization of the music.

Say it was a classical based piece of music. Perhaps there is an underlying simple repeat of low violins with sort of a quick looping series of 3 or 4 notes with a sense or urgency. As the cart was rolling along, say it hit a bump, at that point you could have an orchestral hit of all the instruments (as a separate sound) that's triggered by the collision. It's in the same key as the droning repeat, but it's a small module of an orchestra blast that emphasizes the event and seems like the orchestra is coordinated with the game.

The short version, make small modules of the music that can be used interchangably, trigger the music by game events/character positions/triggers, and use the timer() for any timing coordinated syncronization including the overall game speed.

Enjoy your day.
TheComet
16
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 22nd Jul 2009 22:19 Edited at: 23rd Jul 2009 00:10
What a clever idea to use modules. Thanks a lot!

Another question : In games made by RareWare on the N64 the music changes instruments according to where you are on the map. I think they took apart the music into separate instruments (1. track is drums, 2. track is flute, 3. track is violin...) and blended them together again accordingly in the game.

Leading to my question, if I did this with Dark Basic, is there any chance that the sounds will get out of sync? Is it possible for one track to play a bit faster suddenly when the processor is doing some hard work?

TheComet


Make the path of your enemies easier with Waypoint Pro!
Latch
17
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 23rd Jul 2009 00:30
Quote: "Is it possible for one track to play a bit faster suddenly when the processor is doing some hard work?"

Possibly, I suppose. Though I would think everything would slow down at the same rate?? That's an absolute guess!

This is where midi can be useful. Using a sample file type called SoundFont (.sf2), you can have real sounding instruments that are played by midi. Now there are definate problems with DBC and it's built in midi so a possible solution would be to use an external player or dll that you could package with your game - maybe something like SynthFont. Midi was designed for electronic instrument syncing and playing and it's already designed to have multiple tracks and a series of controls for each track including instrument switching, effects processing, volume, envelope, and expression controls, tempo and key change.

Another possibility when using recorded sound, would be to use SMPTE syncronization. SMPTE is a standard that was developed for recording studios so recording machines could be synced with other electronic devices and film could be synced with sound. I wonder if there is a VST plugin around that would allow you to use SMPTE controls for the playback of your music? I don't even know how it would be implemented with DarkBASIC unless it was also through a DLL or something.

Off hand, I can't think of any monitoring tools that would allow you to know what position your audio is playing at at any given time. There's probably a VST plugin for that as well or some other type of DLL (maybe even winmm.dll).

Enjoy your day.
That1Smart Guy
15
Years of Service
User Offline
Joined: 26th Feb 2009
Location: Somewhere...... yep
Posted: 23rd Jul 2009 00:53
wow latch, ur not a forum member, ur a living computer manual library!!

also i think its a new record, latch's 2 posts had a combined total of 746 words, and 3413 non-space characters, WOW!

Dark Dragon
16
Years of Service
User Offline
Joined: 22nd Jun 2007
Location: In the ring, Kickin\' *donkeybutt*.
Posted: 23rd Jul 2009 17:04
Quote: "wow latch, ur not a forum member, ur a living computer manual library!!"


LOL!................True.
\



Anyhoo, back on topic......

This is very interesting. I gotta play with these ideas.
Will get back if i find out/discover anything.

Your signature has been erased by a mod because it was too big.CHANGE IT OR DIE!!!!!

Login to post a reply

Server time is: 2024-05-20 06:41:14
Your offset time is: 2024-05-20 06:41:14