Tutorial 01 :
FMOD/NativeFmod Introduction

NativeFmodEx version

This tutorial an introduction to FMOD audio system in Java using NativeFmod, and how to install and use them.

FMOD is an audio system library to play music and creates sound effects.
To have more informations on it, visit FMOD web site :


FMOD Ex API can be used with C, C++, C#, VB and Delphi programming languages.

 But what about for the Java language ?

FMOD API does not have a support for the java programming language. That's why I've create this project : use the great FMOD audio system in Java. NativeFmod is a link between Java language and FMOD (C/C++ library).

With a lot of search on the net, I've find that it is was possible, with JNI (the Java Native Interface), to use a library in Java. I've starten a little project that make the link with about 20 basic methods of FMOD (play/pause/stop musics). All of this has taken me about 2 months at the end of the year 2003 (just a little compared to the time I've passed for both NativeFmod & NativeFmodEx projects).
This was NativeFmod 1.0, a non public realease just for my own use :-).

Half a year later, I've find on FMOD Ex forum some request for a Java support of FMOD library. That's when I've starten the public NativeFmod 2.0.
SWIG helps me a lot to make the first public version of NativeFmod with now practically all FMOD functions available (May 2004, NativeFmod 2.0). SWIG don't generate a clean code and it is difficult to work with this utility, so I continue the project by hand. But, SWIG is a really cool utility. Great work of all developpers of the SWIG project.

I start learning JNI in the same time of writting NativeFmod. I was having no skills on JNI and C++ at the start of the project (requiered by JNI for writting the native code).
NativeFmod have suffered long time due to this lack of knowledge. NativeFmod have changed a lot from version to version. It is now in a stable state and in final version, until a bug is found or FMOD is updated.

First download the last NativeFmod API and FMOD API. If it is the first time you use NativeFmod, I advice you to download NativeFmod Sdk (Runtime + examples).
Extract NativeFmod and FMOD in any folder you want.

Here are files needed for the installation :
   NATIVEFMOD_FOLDER/lib/NativeFmod.dll         [Windows only]
   NATIVEFMOD_FOLDER/lib/libNativeFmod.so       [Linux only]
   NATIVEFMOD_FOLDER/lib/libNativeFmod.jnilib   [Mac only]
   FMOD_FOLDER/api/fmod.dll                     [Windows only]
   FMOD_FOLDER/api/libfmod-3.75.so              [Linux only]

If you have choosed to use NativeFmod SDK, copy fmod.dll and/or libfmod-3.75.so in the folder :
(this is requuiered to run the examples included in the SDK).

There is two ways for installing NativeFmod : in your JDK/JRE or directly with your application.
The advantage of the second way is that we don't need to have access to JDK/JRE (ie don't need administrator rights), so this will works everywhere (ie every computer and platforms supported).

JRE_FOLDER point towards jre folder of JDK (Java Development Kit) or JRE (Java Runtime Environment).
For example, on Windows platform, this can be :
  C:\Java\jdk1.4.2_09\jre\    [JDK]
or :
  C:\Java\jre1.4.2_09\        [JRE]

Copy all jars into the folder :

Copy the libraries (dll/so/jnilib) for your platform here :
  JRE_FOLDER/bin/             [Windows - dll]
  JRE_FOLDER/lib/i386/        [Linux   - so]
  JRE_FOLDER/***/             [Mac     - jnilib]

Now, you're ready to use FMOD with Java !

You can also install NativeFmodEx outside Java SDK/JRE.
This is usefull if you don't have access to the JDK/JRE, for deploying your application on another station, for including NativeFmod directly with your application ...

For this put all jars and libraries in a folder (refered by LIB_FOLDER).
At runtime, you will have to indicates where NativeFmod is. This can be done using java.library.path and classpath like this :

Linking NativeFmod at runtime

    java -Djava.library.path=LIB_FOLDER -classpath LIB_FOLDER/NativeFmod.jar main

Note : Replace ';' by ':' under Linux & Mac

This way is also easier for multi-platform deployment. Simply put all files mentionned above and NativeFmod will choose the right file.
At start, NativeFmod will search the library in java.library.path folder and system dependant library folder.

If you use a development environment like Eclipse or NetBeans, NativeFmod jars and libraries can be specified internaly to the project.

Now, you have installed NativeFmod and you probably want to use/try it.

To begin we will see how to run examples included in NativeFmodEx SDK. Then, we will see how to creates a project under Eclipse et NetBean IDE.

[Read Linux version]

To run an examples, just double click on one Batch file from SDK distribution (*.bat). To know what is the java command used to run the example, just open the file with a text editor.

If the example don't run and you have a similar error (I don't know exactly the error displayed under an english system) :

Java not found

    "java" is not a known command ...
or (In French)
    "java" n'est pas reconnu en tant que commande interne ou externe, ...

Read Installation of Java.

You can also execute them using a DOS terminal ("Invite de commande" in french) with Start/Execute/cmd.exe.
Go to the NativeFmod examples folder using CD command.
Then execute an example using this script :
   java -Djava.library.path=../lib -classpath NativeFmod-Examples.jar;../lib/NativeFmod.jar org.jouvieje.Fmod.Examples.<example_name>
Replace <example_name> by the name of the examples ie Simple, 3d, CDDA, NetStream ...

Ex :

Example script

    CD C:/NativeFmod/Examples/
    java -Djava.library.path=../lib -classpath NativeFmod-Examples.jar;../lib/NativeFmod.jar org.jouvieje.Fmod.Examples.Simple

Note : A similar screen capture (made for NativeFmodEx) is available here.

Warning :
Some examples like Stream and NetStream needs extras parameter :
   java ... .Examples.Stream Media/jbtennis.wav
   java ... .Examples.NetStream http://jerome.jouvie.free.fr/downloads/NativeFmod/jules.mp3

[Read Linux version]

This article is writen here for NativeFmodEx.
This can be easily done with NativeFmod, with the jars and libraries mentionned previously.

This article is writen here for NativeFmodEx.
This can be easily done with NativeFmod, with the jars and libraries mentionned previously.



Next turorial

Last modified on 01/07/2010
Copyright © 2004-2010 Jérôme JOUVIE - All rights reserved. http://jerome.jouvie.free.fr/