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 Professional Discussion / Sound Frequency Vs Program Speed

Author
Message
Grumpy Jedi
16
Years of Service
User Offline
Joined: 16th Jan 2010
Location:
Posted: 30th Jul 2010 12:15
I have a project that matches up sound/music events in time with screen events.

The music is loaded using the load sound command as either .wav or .ogg

Since the program relies on synchronization of some events to music, its easy to notice if the music isn't playing at the correct speed.

My question is this - can the program loop affect the speed at which sounds playback using the play sound command.

In a test program with just the sound, and no other operations going on I timed the length of the playtime in milliseconds, then did the same within my large program.

The large program came in at just under 3 percent longer to play the same piece of music.

The music in my large program does not keep pace.

Using the set sound speed command to adjust the frequency does not solve the problem, as it appears the sound does not play at a steady 3 percent slower, but instead 3 percent slower is the average.

Anyone know if the speed of played back sounds can be affected by a program? I need to keep my sound format as ogg or wav, so mp3's and the play music command won't help.
Van B
Moderator
23
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 30th Jul 2010 12:26
One thing that might be causing the delay, is loading. When you load a sound, it doesn't really load (as far as I know) until you actually try to play it. So... try loading your sound, then play it, then give it 5 seconds or however long it needs to load up then stop it, then try timing it again to see if it's any better.

I noticed that the first time I played a sound, it would sometimes be distorted - I'm not sure if this got resolved with an update, so I might be talking rubbish, but worth a try.

Health, Ammo, and bacon and eggs!
Grumpy Jedi
16
Years of Service
User Offline
Joined: 16th Jan 2010
Location:
Posted: 30th Jul 2010 19:02
I found the cause of the delay by accident, and it's baffling.

Apparently if I have my web browser open to thegamecreators website, the sound speed is perfect and the program runs spot on.

However, if I have my browser closed, the sound timing is off.

I also tried another web page (wikipedia) to see if it made a difference....and apparently it DOES matter what web page I have open....

Having my browser open to wikipedia did not help, the sound speed was still off.

The sound speed in my program is only correct when my web browser is open to a page that has some shared quality on it, that thegamecreators website has.

Is anyone else as confused as me?
Neuro Fuzzy
19
Years of Service
User Offline
Joined: 11th Jun 2007
Location:
Posted: 17th Aug 2010 09:57
Sorry for the big bump, but I just read this, and processor usage might be your problem. Try creating another program that uses IanM's nice sleep function (that doesn't use a crapload of processor power) and DBPro's wait function (that does usue a crapload of processor power) to vary your processor usage while the program is playing.

If this is the problem, I have no idea how to solve it.


Is't life, I ask, is't even prudence, to bore thyself and bore thy students?
Grumpy Jedi
16
Years of Service
User Offline
Joined: 16th Jan 2010
Location:
Posted: 17th Aug 2010 10:09
I fixed this problem with the "load music" trick that I found after some digging in the forums.

(which consists of nothing more than loading a music file into memory at the start of your program that does not even have to be played)

I'm not quite sure what the problem is or why loading a music file fixes it, but I can assure you that it does.

Most programs probably wouldn't notice the timing error. It just so happened I was programming something that was extremely sensitive to timing fluctuations.

I'm still puzzled by it.
luskos
19
Years of Service
User Offline
Joined: 28th Jun 2007
Location:
Posted: 17th Aug 2010 12:18
Sound commands are somehow problematic, i've accidently found that any sound loaded with load sound won't really gone when you use delete sound, it doesn't free virtual memory so i think best use of sounds is to load them all in the game and leave them, there is no need to bother deleting them once you don't need them because there is no resources realesed after deleting them.

Coding is My Kung Fu!
And My Kung Fu is better than Yours!

Login to post a reply

Server time is: 2026-07-25 12:05:22
Your offset time is: 2026-07-25 12:05:22