c++g++fmod

How to use FMOD with C++?


I'm trying to create a simple mp3 player using FMOD:

#include "inc/fmod.h"

int main() 
{
    FSOUND_Init(44100, 32, 0);
    return 0;
}

Trying to compile the program I get the following error:

holle@x300:justmp3$ pwd
/media/daten/Entwicklung/C/justmp3
holle@x300:justmp3$ LD_LIBRARY_PATH=$(pwd)/lib
holle@x300:justmp3$ ls $LD_LIBRARY_PATH
libfmodex-4.34.02.so  libfmodexL-4.34.02.so
holle@x300:justmp3$ g++ -o mp3 mp3.cpp
mp3.cpp: In function ‘int main()’:
mp3.cpp:8: error: ‘FSOUND_Init’ was not declared in this scope

What's my mistake? How could I get g++ to compile the program?


Solution

  • FSOUND_Init is an FMOD 3 API function, you are using FMOD Ex so that function doesn't exist. To initialize FMOD Ex you should include "fmod.hpp" and use the functions:

    System_Create to create the FMOD system object, then

    System::init to initialize, followed by

    System::createStream to load your MP3, then

    System::playSound to play it.

    There are a bunch of useful examples that ship with FMOD that you could use as a reference, especially the playstream example for what you want to achieve. Also there is full documentation in CHM format. If you are porting code from FMOD 3 I would recommend reading the migration guide in the fmodex.chm docs.