Load_wav Is Time Consuming... How To Play Music?


TrevorBradley

Active Member
Joined
Nov 6, 2007
Messages
732
load_wav() sure does take a while to load those files into memory. Is there any way around this, other that loading them all in a loading screen at the beginning of the game?

Is there any way to have looped background music (say>1minute) without excessive load times? The only thing I can think of is dropping the quality through the floor. Ruckage seems to do this very well in his games, and Ruck-man has 500kb oggs that seem to work seemlessly.
 
I've not noticed any extreme load time regarding music and wavs. You should really just use wavs for sound effects due to file size and ogg for music. Also you are just loading the sound/ music once and not each time you want to play them right?

The way I do it and I'm sure most people do something similar is to define some variables at the begining eg. music1, music2, sound1, sound2 or something else descriptive and before anything else in my code I load the wav/ogg using these variable to store the id. eg

music1=load_song("music1.ogg");
sound1=load_wav("sound1.wav");

Then to play you simply do:

play_song(music1,-1);

play_wav(sound1,0);

The second value in both these functions is the number of time the song/wav loops and setting it to -1 loops infinitely.

Hope this helps.
 
ruckage said:
The way I do it and I'm sure most people do something similar is to define some variables at the begining eg. music1, music2, sound1, sound2 or something else descriptive and before anything else in my code I load the wav/ogg using these variable to store the id. eg

music1=load_song("music1.ogg");
sound1=load_wav("sound1.wav");

Then to play you simply do:

play_song(music1,-1);

play_wav(sound1,0);

The second value in both these functions is the number of time the song/wav loops and setting it to -1 loops infinitely.
I'm noticing big lag times on my F200 if I load ogg files with load_wav... but let me actually make a simple program to test this, I'll get back to you.

Is there any difference between play_song and play_wav?

Thanks!!!
 
Last edited by a moderator:
Yes, play_wav is really just for sound effects as you can have multiple sounds playing at the same time, you can only ever have one song playing at a time with play_song. Also the volume of songs and wavs can be adjusted independently of one another using set_wav_volume and set_song_volume.
 
Trevor Bradley said:
I'm noticing big lag times on my F200 if I load ogg files with load_wav...
As Ruckage showed, you should load music with load_song. load_wav loads the entire OGG into RAM and decompresses it, which is what produces that long wait time at the beginning. load_song streams it instead, which is what you should use for large files.
 
Last edited by a moderator:
Alex. said:
Trevor Bradley said:
I'm noticing big lag times on my F200 if I load ogg files with load_wav...
As Ruckage showed, you should load music with load_song. load_wav loads the entire OGG into RAM and decompresses it, which is what produces that long wait time at the beginning. load_song streams it instead, which is what you should use for large files.


Excellent... this is what I was looking for. I was suspecting load_song streamed.

A bad ogg file that caused the F200 to crash wasn't helping either.

Is this why Ruckage said use wav files for sound? load_wav has to decompress the ogg file before starting, causing a longer load time. Interesting.

Thanks guys!
 
Last edited by a moderator:
Back
Top