Loading .OGG files

Blitz3D Forums/Blitz3D Programming/Loading .OGG files

semar(Posted 2005) [#1]
All,
if I convert a quite big audio .WAV file in .OGG format, the LoadSound command needs some second to load the file, while if I load the .WAV file instead, the same command is performed in few millisecs.

I wonder, is that the normal behaviour ? I guess it is due to the compressed format. Does it happens to you too ? I've tryed with .MP3, and it's the same story.

If you want to try by yourself, choose a rather big audio file. With smaller file size, the loading time difference between .wav and .ogg is not noticeable.

Unfortunately I can't solve this problem by loading all the sounds at the very beginning of the game, because they would require lots of memory (and would also freeze the program for quite a long time, since the sounds are quite long).

That's why I load one audio file each time a new match is started from within the game, but in this way if I use .OGG audio files, the game freezes for some second. Again, .WAV files don't give this problem.

I could use .WAV files, but it would require more space on the HD, while the .OGG are nice small..

Is there any workaround ? Any help would be greatly appreciated.

Sergio.


WolRon(Posted 2005) [#2]
I wonder, is that the normal behaviour ?
Sounds correct to me.

Define a 'big' file. 100KB? 1MB? 10MB?

Maybe you could try loading (in the background) between matches?

Maybe divide up the audio file into smaller parts?

Is the audio file used as a game sound or is it used as music?

You didn't give any insight into what kind of game it is.


jfk EO-11110(Posted 2005) [#3]
sounds like it has something to do with memory allocation and unpacking the ogg. Maybe you should convert it to wav during installation of the game.


jhocking(Posted 2005) [#4]
It is normal for ogg to take time to load. That's the tradeoff; ogg files are smaller but need time to decode, while wavs are faster but larger. I normally balance this by using ogg for music and wav for sound effects, but obviously this is going to vary by the specific application.

Do note that players are used to load times between, and increasingly even during, levels. They don't like it, but they are used to it.


big10p(Posted 2005) [#5]
Are OGG files decoded once on loading, and so use the same amount of mem as a WAV? (Probably true since you're saying they take longer to load).

or

Are OGG files decoded on-the-fly each time they're played, and so use less mem that WAVs?

Sorry to hijack! :)


WolRon(Posted 2005) [#6]
They take up the same amount of memory.


VP(Posted 2005) [#7]
Decode to wav the first time the game starts and save the wav back to disk (replacing the ogg).


JazzieB(Posted 2005) [#8]
Decoding to WAV when the game is first run and re-saving them to disk doesn't get over the disk usage issue. You might say that using OGG helps with the download size, but WAV files compress quite will in ZIPs or installers too, so you won't really be saving anything.

This means two options...

1. Load the new music track during a natural pause in the game, for example between levels.

2. Use the PlayMusic command and stream the music from disk instead.

Incidentally, all compressed file formats for music/sound and graphics are decompressed when loaded into memory, so memory usage is equal to that of a WAV or BMP.


VP(Posted 2005) [#9]
semar asked for workarounds, I offered one. Other people offered other workarounds.

I would normally try to keep the distributable size down to save on bandwidth usage, both to save the end user's time and and to keep my monthly website usage limit as low as possible (if I go over it, I get charged).


JazzieB(Posted 2005) [#10]
I'm not sure what your point is there. Basically, he has two issues:

1. Disk usage
2. Memory usage

Options as follows.

To save disk space, after installation, use OGG.

To lessen the distributable size (ZIP or installer) you could also use OGG, but even WAV files get compressed in the distributable. Not sure to what level, but I can't imagine there being much difference between the final size if a comparison was made.

As for memory, it doesn't matter what format they are stored on disk, as they will get decompressed on loading them. So, the options are to either make use of LoadSound/FreeSound and only load them when needed at an appropriate place in the game, or use PlaySound where the memory usage will be down to a minimum and the music is streamed from the hard disk, which starts instantaneously.


semar(Posted 2005) [#11]
Thanks all for the replies so far.

I prefere to use .OGG because they are smaller than .WAV files; but I don't like the the loading time.

Unfortunately there are not 'pause moments' where I can load an .ogg file without the player notice that... there are not levels, only a menu and the game itself. But each time the player choose to play, I would like to change the background music from a random .ogg file list.

I could pre-load all the .ogg files at the very beginning of the game, but I would like to keep the used memory as low as possible.

I have not tryed the PlayMusic command, I didn't know it streams the music from the HD. Thanks for the hint JazzieB.
Perhaps that's the solution..

Sergio.