Scrolling Game Development Kit Forum
Welcome, Guest. Please login or register.
2010-09-08, 07:20:36 PM

Login with username, password and session length
Search:     Advanced search
8920 Posts in 1007 Topics by 168 Members
Latest Member: mogzdogz
* Home Help Search Login Register
+  Scrolling Game Development Kit Forum
|-+  SGDK Version 2
| |-+  Help, Errors, FAQ
| | |-+  Preloading Sound Files
« previous next »
Pages: [1] Print
Author Topic: Preloading Sound Files  (Read 701 times)
Jam0864
Contributor
Fanatic
**
Posts: 742


marmalade0864@hotmail.com
View Profile WWW Email
« on: 2009-04-10, 09:40:54 PM »

The first time a sound is played it is delayed since it's not preloaded. For the project I'm working on, it's crucial that it is preloaded.

I tried preloading all the sounds at startup by playing them all at once, but that crashed the project.

Is there something I can do the preload the sounds?
Logged
bluemonkmn
SGDK Author
Administrator
Fanatic
*****
Posts: 2146


2678251 BlueMonkMN@gmail.com
View Profile WWW Email
« Reply #1 on: 2009-04-11, 10:40:17 AM »

Did you try the LoadSound function?  It should be an option not far from PlaySound.
Logged

Jam0864
Contributor
Fanatic
**
Posts: 742


marmalade0864@hotmail.com
View Profile WWW Email
« Reply #2 on: 2009-04-11, 08:45:53 PM »

Didn't see that.  Embarrassed

Thanks. Wink
Logged
Vincent
Clever
Fanatic
***
Posts: 343


Working on a Legacy of Kain fangame.


View Profile Email
« Reply #3 on: 2010-01-12, 01:00:04 PM »

Hey guys, I know I'm late on this topic, but maybe you can help me out.

In my game, it's not 100% necessary to preload the sounds, but it sure would be nice if the game didn't stop each time a new music is loaded.  So I did like Jam0864 and I called LoadSound() for each music I have.  The thing is, I've got 12 mp3 and all together they weight around 45 megs.  I compressed them as much as I could usign Audacity and the Lame mp3 encoder.  It used to be 75 megs, so I'm pretty happy it dropped to 45 but it's still huge. 

I was wondering if there was a way to load the music asynchronously, so when the game starts, I would load every music and they will play when they are loaded without any freeze.  If a music is supposed to be played when it is not loaded, the game would go on without music until it is loaded or it would stop until this precise music is loaded, whichever is easier to do.

Any suggestions?  Can someone help me out with this?

Thanks!  Grin
« Last Edit: 2010-01-12, 03:29:59 PM by Vincent » Logged
bluemonkmn
SGDK Author
Administrator
Fanatic
*****
Posts: 2146


2678251 BlueMonkMN@gmail.com
View Profile WWW Email
« Reply #4 on: 2010-01-12, 03:31:17 PM »

So what's the problem with using LoadSound on your current project's sounds?  Does it take too long with 45 MB of sounds, or does it take too much memory or what?
Logged

Vincent
Clever
Fanatic
***
Posts: 343


Working on a Legacy of Kain fangame.


View Profile Email
« Reply #5 on: 2010-01-12, 03:39:22 PM »

It's very long.  It was already taking quite long before I added the music, but now it's over the top.   At least it doesn't crash or freeze.
« Last Edit: 2010-01-12, 07:16:11 PM by Vincent » Logged
bluemonkmn
SGDK Author
Administrator
Fanatic
*****
Posts: 2146


2678251 BlueMonkMN@gmail.com
View Profile WWW Email
« Reply #6 on: 2010-01-13, 06:12:25 AM »

You could try creating functions "StartLoadSound" and "EndLoadSound" which would be similar to many asynchronous functions in the .NET framework.  The "Start" function begins a background thread to run the process, but returns immediately after the thread is started.  The "EndLoadSound" returns the final result of the thread when it is complete.  StartLoadSound would return an object which can be passed to EndLoadSound so that EndLoadSound knows which sound/thread you are referring to.  This object can also be used to check whether the thread is ready to finish yet.  Hm, it looks like .NET even provides a generic way to call a function asynchronously.  See http://msdn.microsoft.com/en-us/magazine/cc301332.aspx.  You may want to start with the conclusion and work your way backwards until you find what you need Smiley.  (There's a lot of introduction)

I guess the key is knowing how to use BeginInvoke and EndInvoke.  http://shiman.wordpress.com/2008/09/10/c-net-delegates-asynchronous-invocation-begininvoke-method/
Logged

Vincent
Clever
Fanatic
***
Posts: 343


Working on a Legacy of Kain fangame.


View Profile Email
« Reply #7 on: 2010-01-13, 08:13:03 AM »

Hey, thanks a lot for pointing this out for me! Smiley
Logged
Pages: [1] Print 
« previous next »
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.11 | SMF © 2006-2009, Simple Machines LLC Valid XHTML 1.0! Valid CSS!