This tutorial is an introduction to FMOD Ex and 3D sound.
Some musics are placed in a 3D environment. All OpenGl related things are based
on OpenGl Tutorial 26 and
will not be explained here.
The music that reach your ears depends on your position in the '3D World'.
The first thing to do is to initialize FMOD Ex.
The camera used for moving in the scene is right handed (ie +X as left, +Y as up
and +Z as forwards). By default, FMOD Ex is left handed (ie +X = right, +Y = up,
+Z = forwards).
To use a right handed system, we need to specify this to FMOD Ex. For this, in
the initialization of our FMOD Ex system, we use
FMOD_INIT_3D_RIGHTHANDED flag.
The distance unit is the meter, this is specified with
DISTANCE_FACTOR (1 for meter, 3.28 for feet
...).
Initialization |
/* |
To create a 3D sound, use the
FMOD_3D flag when creation using
createSound/createStream.
Remark : If you want to use musics from a jar file, you have to load them
into the memory.
This is done here using a ByteBuffer in which the file is copied in, an
FMOD_CREATESOUNDEXINFO object specify the
length (in bytes) of the file and finally the
FMOD_OPENMEMORY flag.
Creating 3D sound |
//Load music into the memory |
Now, sounds are created. You can play and position
them everywhere you want.
Sound are start paused to modify the sound position without it being audible.
Positionning sounds |
FMOD_VECTOR position = FMOD_VECTOR.create(20.0f * DISTANCE_FACTOR, 0.0f,
0.0f); |
When the player move, you should have to update the
listener attributes (position, orientation and velocity).
This should be done at each frame.
Here we update the listener position, orientation and velocity (deplacement
speed).
The velocity is calculated in meter per second : velocity =
(currentPosition-lastPosition)/time
Update Listener(s) attributes |
private FMOD_VECTOR forward, up, vel, listenerpos, lastpos; |
Tutorial 03 - src : Jogl JSR-231 ( 862 ko)
|
Last modified on 01/07/2010 | |
Copyright © 2004-2010 Jérôme JOUVIE - All rights reserved. | http://jerome.jouvie.free.fr/ |