
Quake2 MP3
Playback
|
Copyright
info |
|
All
code in this tutorial is protected by the [GPL License]. |
|
Tutorial
by: Heffo |
||||||||||||
|
Mailto: heffobomber@hotmail.com This tutorial
will show you how to add MP3 audio playback to the Quake2 executable. It is
based on the LGPL mpglib libary from the MPG123 commandline mp3 player for
linux. Since it
mpglib libary is LGPL there are no legal reasons for not using it in the Quake2
source, but the MP3 format itself does have some issues regarding the
pattented compression technology, basically if you aren't selling your
modified Quake2 engine you won't have any problems, but if you are making
money off it then you have to pay a royalty for the use of the compression
algorithms. For more details on this check out http://www.quakesrc.org/www.mp3licencing.com My next
project will be to add playback of the OGG Vorbis format to the exe for those
of you who would rather steer clear of the patent issues, and if you don't
know what OGG Vorbis is then check out http://www.quakesrc.org/www.vorbis.com
to find out all about it After all
that, on to adding MP3 playback! First, open
the zip file entitled 'mpglib.zip'
you will see it contains two header files and a lib file as such.. mpg123.h -
4.9Kb these are the
files you will need to actually handle the decoding of the MP3, extract them
into the 'client' folder of your source release. If you want to edit the source
of the lib, you can find it in the optional 'mpglibsrc.zip'
file. You will need
to include the lib file in the quake2 exe's build settings, so to do this
under Visual C++ 6 you go to 'Project->Settings' then click the 'quake2'
mini-icon in the tree box below it. Over to the right the settings will
change to reflect the exe's project settings, You will need to do this for
both the 'WIN32 Release' and 'WIN32 Debug' configurations, which you can
select with the 'Settings For' listbox at the top left of the window. On the
options at the right of the screen, click the 'link' tab, then set the
'Category' listbox to 'General', you will then see a textbox labeled
'Object/libary modules', add to the end of the list of libs in the box
'client\mpglib.lib'. Don't forget to do that for both the Debug and Release
configurations. We need to
define a new structure to hold the MP3 data, so open the header file
'snd_loc.h' and scroll down it untill you find the type declration for the
'wavinfo_t' structure, then below it add...
The next step
is to actually start including some new code to the engine, so open up the
file 'snd_mem.c' and scroll right to the top of the file and locate the
lines..
You now add
below them these lines...
What the two
'#include' lines do is include the header files for the mpglib libary into
the source so the compiler knows what functions and variables the lib is
providing. the 3rd line is a declaration of the MP3 loader function we will
be adding shortly. You will now
need to be in the function 'S_LoadSound' which you will find if you scroll
down a little bit. What we need to do here is to allow it to tell if it's an
MP3 we are trying to load, and load it instead of a WAV file. Since this
function is rather messy, I opted to write a seperate loader function for
MP3s and call it from this one if an MP3 was requested, instead of making
this function load both formats itself. Find the code
section that reads...
and below it
put this..
What it does
is checks to see if the filename requested is an MP3 file by comparing the
last four characters of the requested filename with '.mp3' and if it is, it
calls the new MP3 loading function which we declared earlier, and returns
it's result. If it's not an MP3, then the function just passes into the
standard WAV loading code. Now to add the
bulk of the new MP3 playback code, I won't explain how it works here, because
I have heavily commented the source so you can see how I was thinking when I
wrote it. Immediately under the S_LoadSound function add all this...
Okay, now that
you have added all that, you hopefully should be able to put an MP3 in the
baseq2/sound folder, compile your exe, and when you run it, in the console
type 'play Have Fun! |
Tutorial Originally found at: