Game Development Reference
In-Depth Information
After the memory buffer is double-checked to be big enough to handle the decom-
pressed OGG stream, the ov_read function is called in a loop to decompress it.
If you feel sufficiently energetic one weekend, this is where you
'
ll want to play
around if you
d like to implement decompression of the OGG stream in real time.
Instead of decompressing the entire buffer, you
'
ll decompress a part of it, save the
stream where you left off, and let DirectSound play the buffer. Before DirectSound
finishes playing the buffer, you
'
ll run the decompression loop again into a different
buffer. If your timing is right, DirectSound will be playing from one buffer while you
are decompressing into another. If you think this is touchy work, you are right; it is
for this reason that sound systems were typically fraught with weird bugs and insta-
bility. Imagine what would happen if the source OGG stream were thrown out of the
resource cache, causing a cache miss and a huge delay in providing DirectSound with
the data it needs to create the illusion of a continuous sound from a single uncom-
pressed stream.
'
Always Show Something Moving
Any time you have a while loop that might
take some time, such as
decompressing a large OGG file, it
s a good idea to create a callback function
that your game can use to monitor the progress of the routine. This might be
important for creating a progress bar or some other animation that will give
your players something to look at other than a completely stalled screen.
Console games are usually required to have on-screen animations during
loads, but this is a good idea for PC games, too.
'
If you are just lifting this OGG code into your game and ignoring the rest of this
chapter, don ' t forget to link the Vorbis libraries into your project. Since there ' sno
encoding going on here, you can just link the following libraries:
libvorbisfile_static.lib, libvorbis_static.lib, and libogg_static.lib. If you are compiling
your code under Visual Studio, you can add the following lines of code to one of
your CPP files. In the GameCode4 source, they are in GameCode4.cpp, where all of
the other #pragma comment() statements are.
#pragma comment(lib,
libogg_static.lib
)
#pragma comment(lib,
libvorbis_static.lib
)
#pragma comment(lib,
)
To learn more about the OGG format, go to www.xiph.org/. The technology is open
source, the sound is every bit as good as MP3, and you don
libvorbisfile_static.lib
t have to worry about
paying expensive license fees. In other words, unless you have money to burn, use
OGG for sound data compression. Lots of audio tools support OGG, too. You can
go to the Xiph website to find out which ones.
'
 
Search WWH ::




Custom Search