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.jar
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 :
NATIVE_FMOD_FOLDER/lib/
(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 :
JRE_FOLDER/lib/ext
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 |
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 Windows version]
To run an example under Linux platform, start a new Terminal and go to NativeFmod examples folder using CD command.
A similar scren capture can be found
here.
With 'ls' command (list all files/folders), you should find
lots of sh files. To
run an
example, use its associated sh file ie
sh <example_name>.sh.
You can also run the example with the following :
FMOD example script |
java -Djava.library.path=../lib -classpath NativeFmod-Examples.jar:../lib/NativeFmod.jar org.jouvieje.Fmod.Examples.<example_name> |
Replace <example_name> by the example name ie Simple, 3d, CDDA, NetStream ...
Ex :
Example script |
cd /hda1/NativeFmod/Examples/ |
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 Windows 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.
|
Last modified on 01/07/2010 | |
Copyright © 2004-2010 Jérôme JOUVIE - All rights reserved. | http://jerome.jouvie.free.fr/ |