Game Development Community

dev|Pro Game Development Curriculum

FMod for torque

by Zachary McMaster · 03/06/2002 (11:47 am) · 16 comments

Download Code File

Alright here it is my Fmod snd engine implementation for torque.

for more info:
http://www.fmod.org/

Fmod stats:
Works on Linux, Windows, and the new
code works with XBOX and PS2
Supporting 3d sound, midi, mods, mp3,
ogg vorbis, wma, recording, geometry processing, cd playback, mmx, internet streaming, dsp effects, spectrum analysis, user created samples and streams,
synchronization support, EAX 2&3, A3D 3.0, C/C++/VB/Delphi/MASM, + more.

Its free unless u want to use it in a commercial product:
1. One shareware title for individuals/hobbyists. $100
2. Multiple shareware titles for individuals/hobbyists $250
2. One product $1,250
3. One site / unlimited products $3,200
4. Engine resale Contact Sales
(ouch)

I have not tested it in Linux yet and also there is a problem with client/ghost connections not playing the songs should be an easy fix

well on with it...

First get the zip file attached
extract the FMSoundEngine.h and
FMSoundEngine.cc to the engine/audio folder
and then add then to you project.

then go get the free download of fmod at:
http://www.fmod.org/files/fmodapi350.zip

find the files:
fmod.h
fmod_errors.h
fmod.dll
libfmod-V-V.so for Linux users

put fmod.h and fmod_errors.h in the engine/audio folder
put fmod.dll in the example folder

now in engine/game/game.cc
add:
#include "audio/FMSoundEngine.h"
and in:
"void clientProcess(U32 timeDelta)"
in :
"if((realTime - lastAudioUpdate) >= AudioUpdatePeriod)"
add : FMSoundEngineUpdate();

And for the song names iv just hacked em into mission area:
\engine\game\missionArea.h
in the private section add:
StringTableEntry mSongNames;
in the public section add:
StringTableEntry getSongNames()const{return mSongNames;}
\engine\game\missionArea.cc
in the constructor add:
mSongNames = NULL;
in void MissionArea::initPersistFields()
add:
addField("SongNames", TypeString, Offset(mSongNames, MissionArea));
unpackUpdate add:
stream->read((unsigned char*)&mSongNames);
packUpdate add:
stream->write(mSongNames);


Ok on to the scripts:
in file /example/mod/client/init.cs
in :
function initClient()
add:
if(InitFMSndEngine()==true)
{
echo("FMSoundEngine Started up.");
}
else
{
echo("ERROR FMSoundEngine Startup FAILED.");
}

in: file /example/mod/client/scripts/serverConnection.cs
in:
function disconnectedCleanup()
add:
echo("FMSoundEngine Closing all Open Streams");
CloseAllSongs();

Now in a mission file in the section
new MissionArea(MissionArea)
add (all on one line):
SongNames = "DavesHouse.mp3 Beepers.mp3 Homicide.mp3 M87HomeAgain.mp3 Structure08.mp3 USS.mp3";

use your own song names...;) hehe

also in FMSoundEngine.cc
int FMSoundEngine::LoadStream(const char *filename)
change to the right path for u:
dStrcpy(sPath,"./mod/data/mp3/");

#1
03/06/2002 (6:02 pm)
Hey looks nice but it is my understanding that OpenAL already supports the playback of the mp3 format.
#2
03/06/2002 (6:05 pm)
Nodnod i've heard its ogg support? im gonna be checking on that soon here...
#3
03/08/2002 (10:09 pm)
OpenAL does not support MP3 or Ogg natively but it does have a very nice streaming interface. Our plan is to add an Ogg stream to the torque Audio Layer.
#4
03/10/2002 (8:36 am)
Need to add the library file to the project, look at the fmod readme.

However, now I have a problem with the music actually PLAYING on mission load. I can get music to play with loadstreamlist() and playstream() thru the console, but the mis file's not doing something right :(

Have I missed a typo?
#5
03/10/2002 (12:20 pm)
Ok, we cooked up a fix for it to work ( we couldnt get a song playing when you started a mission)

in function clientCmdMissionStart(%seq)
i added

%a = loadstreamlist(missionarea.songnames);
if(%a!=-1)
{
playstream();
}


thats located in common/client/mission.cs

Thanks to ed garder for helping out
ryan
#6
03/11/2002 (6:16 am)
I also found that simply calling loadlevelsongs() works as well, with a similar check for null values in case the mission doesn't have a soundtrack (that crashes the engine if you try to play a stream without defining it :)).

Need to build play lists and what not, but I have a simple GUI based on the HEAD build demo recording/p;layback gui that plays and stops MP3's in game and at the main menu.

Cool stuff. Great thing for us freeware makers ;)
#7
03/11/2002 (7:24 pm)
Thanks for the tips so far, still some problems though. I still can't get PlayStream() to work from anywhere in the scripts, it crashes the program. I was able to call it from the console once and have it work, however even that seems to have given up the ghost for no reason and crashes the game. Any suggestions you guys might have would be appreciated
Thanks
#8
03/13/2002 (6:30 am)
I suggest debug to cursor in the PlayStream Function on the c++ end ..
then when the stream plays ..and crash's
you can see what is invalid causing the crash :)
heh sorry ...
#9
03/15/2002 (6:25 am)
There's some info about Ogg at this site:
http://www.xiph.org/ogg/vorbis/
#10
03/21/2002 (10:46 am)
You need to have a loaded stream before playstream will work.

Yo ucan do this one of 2 ways:

1) manually load it in scripts with the loadstreamlist() command, load one file at a time like this:

loadstreamlist(song.mp3);

you'll get some feedback sayin it was successful int he console.

Then typoe in the console, playstream();

alternatively, you can put a songnames field in you mission, and simply call loadlevelsongs(); to play that list.

I made a gui that lets me have play lists where I set missionarea.songnames to a new value and then issue the loadlevelsongs(); command to play that list.
#11
06/13/2002 (8:54 am)
This is capable of ALL fmod capabilities, or just MP3 playback?
#12
07/22/2002 (12:02 pm)
it can do it all... Im not sure if I included the wave playback.. but its real easy to add.. And i mean REAL EASY!!.. Just look at some fmod examples.
#13
09/26/2002 (11:39 am)
I`m looking for info how to add a dll with functions that can be called from the Torque script.
Where I can read about it in detail?

Thank you!
#14
01/15/2003 (2:19 pm)
I've an error in Visual C++ with your code :
--------------------Configuration: Torque Demo - Win32 Release--------------------
Compiling...
game.cc
FMSoundEngine.cc
Linking...
FMSoundEngine.obj : error LNK2001: unresolved external symbol _FSOUND_Init
FMSoundEngine.obj : error LNK2001: unresolved external symbol _FSOUND_SetDriver
FMSoundEngine.obj : error LNK2001: unresolved external symbol _FSOUND_SetOutput
FMSoundEngine.obj : error LNK2001: unresolved external symbol _FSOUND_GetError
FMSoundEngine.obj : error LNK2001: unresolved external symbol _FSOUND_Stream_OpenFile
FMSoundEngine.obj : error LNK2001: unresolved external symbol _FSOUND_SetLoopMode
FMSoundEngine.obj : error LNK2001: unresolved external symbol _FSOUND_Stream_Play
FMSoundEngine.obj : error LNK2001: unresolved external symbol _FSOUND_Stream_Stop
FMSoundEngine.obj : error LNK2001: unresolved external symbol _FSOUND_SetPaused
FMSoundEngine.obj : error LNK2001: unresolved external symbol _FSOUND_SetVolume
FMSoundEngine.obj : error LNK2001: unresolved external symbol _FSOUND_GetVolume
FMSoundEngine.obj : error LNK2001: unresolved external symbol _FSOUND_IsPlaying
FMSoundEngine.obj : error LNK2001: unresolved external symbol _FSOUND_Stream_Close
../mfg/MFGDemo.exe : fatal error LNK1120: 13 unresolved externals
Error executing link.exe.
Creating browse info file...

MFGDemo.exe - 14 error(s), 0 warning(s)


My library is correctly loaded, if delete it I'v egot another error..

Do you have an idea ?
#15
08/13/2005 (12:50 pm)
For info, this still works fine with TGE 1.3

Get the FMODAPI374WIN.zip from the fmod link download section,

Follow the instructions in the resource posting and the comments in the other postings.

Change line 74 in FMSoundengine.cc to :
stream = FSOUND_Stream_Open(sPath, FSOUND_NORMAL | FSOUND_2D | FSOUND_MPEGACCURATE, 0 , 0);

Add the correct fmod lib to your additional lib section for your linker (see the readme in the api zipfile)
#16
03/26/2007 (1:52 pm)
Has anyone used FMOD to play MIDI tracks. I want to know if you can create a callback for each MIDI event. I checked the documentation, and didn't find it. I want to be able to control MIDI events on the fly.

Also does anyone have any experience with the FMOD soft synth? Does it use DLS? Is the resampling algorithm any good? I have been using SampleTank which has a killer resampling algorithm. It makes all your instruments clean and realistic sounding no matter how much you stretch a sample. How does FMODs synth compare??

Thanks