Setting up a precompiled library (FMOD) with Visual Studio Win32 and Visual Studio Android

Hope this post helps anyone trying to add a precompiled lib to its project. I’m not Visual Studio nor Android expert but been fighting with this for a few days, guess there are better ways to do this but haven’t seen any tutorial on integrating precomplied libraries with cocos.

For win32 has been easy, for Android with visual studio not so much.

Needed an advanced sound engine and finally decided for FMOD, BASS should be fine too. FMOD it’s free if your development consts are below 100.000$.

Have no Mac / iOS right now but sooner or later will port to iOS and update the thread but this is many months from now unless someone does it before :sweat_smile:

Win32

1.- Add FMOD headers to the project search path. Open project properties page (right click in the project in the solution explorer). Go to VC++ Directories and add the path to the headers.

2.- Add the precompiled visual studio win32 libraries. Go to linker > input. Select additional dependencies, add the libraries with full path. I added these two lines:
D:\soft\fmod108\windows\api\lowlevel\lib\fmodL_vc.lib
D:\soft\fmod108\windows\api\studio\lib\fmodstudioL_vc.lib

3.- Also fmod.dll and fmodstudio.dll should be available in runtime. Copy them to your windows directory or modify windows path to make them visible, remember to deploy them with your app.

4.- Test:

#include "fmod_studio.hpp"
....
const int NUMCHANNELS = 64;
FMOD::System* FMOD_system;
FMOD_RESULT r = FMOD::System_Create(&FMOD_system);
assert(r == FMOD_OK);

r = FMOD_system->init(NUMCHANNELS, FMOD_INIT_NORMAL, 0);
assert(r == FMOD_OK);

FMOD::Sound* sound; 
r = G_sfxC->FMOD_system->createSound("sfx/soundeffect.ogg", FMOD_DEFAULT, 0, &sound);
assert(r == FMOD_OK);

FMOD::Channel* channel;
r = FMOD_system->playSound(sound, nullptr, false, &channel);
assert(r == FMOD_OK);

Android:

You need a cocos2dx visual studio android project up and running. You can code, deploy and remote debug from there. Check this thread:

http://discuss.cocos2d-x.org/t/android-developers-use-visual-studio/

I had to modify the directories of Android Visual Studio options. Tools > Options > Cross Platform > Android. Once you have your project up and running you can try to add the library.

1.- As for win32 add FMOD headers to the project search path. Right click on your project [Cocos2dcpp (android-xx)] properties. Go to VC++ Directories and add the path to the headers.

2.- Go to Linker > General > Additional Library Directories. Copy the FMOD libraries to your project directory or use a full path to the FMOD installation. Add the corresponding library. For ARM added the followind line:
$(ProjectDir)\..\..\fmod\lib\armeabi-v7a

3.- Linker > Input > Additional Dependencies. Add the library. Added the following lines for ARM configuration:
$(ProjectDir)\..\..\fmod\bin\armeabi-v7a\libfmodL.so
$(ProjectDir)\..\..\fmod\bin\armeabi-v7a\libfmodstudioL.so

4.- In solution explorer right click on your project [Cocos2dcpp (android-xx)] and select Add > Existing item. Look for libfmodL.so and libfmodstudioL.so or libfmod.so and libfmodstudio.so (L versions are for debug) and add them. The libs should be in the project root, below the jni directory.

5.- Select the newly added libs in solution explorer. Right click and select properties. Item type should be already set to Library. Set Content to YES. This will add the .so files to the .apk for deployment as there is no Android.mk or Application.mk in the Visual Studio Adroid project, or at least i could not find it.

6.- Ad the .jar library. Go to solution explorer, Cocos2d > libs, right click, add > existing item. Add fmod.jar

7.- Open file Cocos2dxActivity.java in projectDir\cocos2d\cocos\platform\android\java\src\org\cocos2dx\lib.

Add org.fmod.FMOD.init(this); in protected void onCreate(final Bundle savedInstanceState)

Add System.loadLibrary("fmod"); in protected void onLoadNativeLibraries(), after System.loadLibrary(libName);.

Add org.fmod.FMOD.close(); in protected void onDestroy(), after super.onDestroy();.

8.- Finally, to use a file you need to prepend your paths with file:///android_asset'/ so sfx/soundeffect.ogg should be file:///android_asset/sfx/soundeffec't.ogg. If you try to open this file from Cocos will give you a file not found error but FMOD will find it.

That’s it, deploy and test, cross fingers, should work :headphones:

2 Likes