2007-03-15 19:52:28 +00:00
|
|
|
package ei.engine.sound;
|
|
|
|
|
|
2007-03-29 23:21:00 +00:00
|
|
|
import java.awt.Rectangle;
|
|
|
|
|
|
2007-03-27 17:51:02 +00:00
|
|
|
import ei.engine.math.Vector3f;
|
2007-03-15 19:52:28 +00:00
|
|
|
import ei.engine.scene.Entity;
|
2007-04-08 15:57:10 +00:00
|
|
|
import ei.engine.texture.Texture;
|
2007-03-15 19:52:28 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* A sound that can be played through OpenAL
|
|
|
|
|
*
|
2007-03-29 23:21:00 +00:00
|
|
|
* @author Ziver Koc
|
2007-03-15 19:52:28 +00:00
|
|
|
*/
|
|
|
|
|
public class Sound extends Entity{
|
2007-03-18 15:17:39 +00:00
|
|
|
private static int soundId = 1;
|
2007-03-15 19:52:28 +00:00
|
|
|
/** The buffer containing the sound */
|
|
|
|
|
private int buffer;
|
2007-03-18 15:17:39 +00:00
|
|
|
private int sourceId;
|
|
|
|
|
private int id;
|
2007-03-27 17:51:02 +00:00
|
|
|
private Vector3f velocity;
|
2007-03-16 19:16:00 +00:00
|
|
|
|
2007-03-15 19:52:28 +00:00
|
|
|
/**
|
|
|
|
|
* Create a new sound
|
|
|
|
|
*
|
|
|
|
|
* @param name The name of the sound
|
|
|
|
|
* @param ref the path to the sound file
|
|
|
|
|
*/
|
|
|
|
|
public Sound(String name, String ref) {
|
|
|
|
|
super(name);
|
2007-03-18 15:17:39 +00:00
|
|
|
id = soundId;
|
|
|
|
|
soundId++;
|
2007-03-27 17:51:02 +00:00
|
|
|
velocity = new Vector3f();
|
2007-03-18 15:17:39 +00:00
|
|
|
this.buffer = SoundLoader.getInstnace().loadSound(ref);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns the unique id of the object
|
|
|
|
|
*
|
|
|
|
|
* @return The id of the object
|
|
|
|
|
*/
|
|
|
|
|
public int getSoundId(){
|
|
|
|
|
return id;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns the source this object uses
|
|
|
|
|
*
|
|
|
|
|
* @return The id of the source
|
|
|
|
|
*/
|
|
|
|
|
public int getSourceId(){
|
|
|
|
|
return sourceId;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns the buffer of this object
|
|
|
|
|
*
|
|
|
|
|
* @return The buffer
|
|
|
|
|
*/
|
|
|
|
|
public int getBuffer(){
|
|
|
|
|
return buffer;
|
2007-03-15 19:52:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Play this sound as a sound effect
|
2007-03-18 15:17:39 +00:00
|
|
|
*
|
2007-03-15 19:52:28 +00:00
|
|
|
*/
|
2007-03-15 23:29:55 +00:00
|
|
|
public void play() {
|
2007-03-18 15:17:39 +00:00
|
|
|
sourceId = SoundManager.getInstnace().playSound(this, false);
|
2007-03-16 19:16:00 +00:00
|
|
|
update();
|
2007-03-15 23:29:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Loop this sound
|
2007-03-18 15:17:39 +00:00
|
|
|
*
|
2007-03-15 23:29:55 +00:00
|
|
|
*/
|
|
|
|
|
public void loop() {
|
2007-03-18 15:17:39 +00:00
|
|
|
SoundManager.getInstnace().playSound(this, true);
|
2007-03-16 19:16:00 +00:00
|
|
|
update();
|
2007-03-15 19:52:28 +00:00
|
|
|
}
|
|
|
|
|
|
2007-03-27 22:51:23 +00:00
|
|
|
/**
|
|
|
|
|
* Updates the sound
|
|
|
|
|
*/
|
2007-03-15 19:52:28 +00:00
|
|
|
public void update() {
|
|
|
|
|
//AL10.alSource(source.get(0), AL10.AL_POSITION, sourcePos);
|
2007-03-27 22:51:23 +00:00
|
|
|
SoundManager.getInstnace().setSoundLocation(this,
|
|
|
|
|
getLocation().getX(),
|
|
|
|
|
getLocation().getY(),
|
|
|
|
|
getLocation().getZ());
|
2007-03-16 19:16:00 +00:00
|
|
|
|
2007-03-15 19:52:28 +00:00
|
|
|
}
|
|
|
|
|
|
2007-03-27 17:51:02 +00:00
|
|
|
public Vector3f getVelocity(){
|
|
|
|
|
return velocity;
|
|
|
|
|
}
|
|
|
|
|
|
2007-03-29 23:21:00 +00:00
|
|
|
/**
|
|
|
|
|
* Returns the bound of this class
|
2007-03-15 19:52:28 +00:00
|
|
|
*/
|
2007-03-29 23:21:00 +00:00
|
|
|
public Rectangle getBound() {
|
|
|
|
|
return new Rectangle(
|
|
|
|
|
(int)getLocation().getX(),
|
|
|
|
|
(int)getLocation().getY(),
|
|
|
|
|
10, 10);
|
|
|
|
|
}
|
|
|
|
|
|
2007-04-08 15:57:10 +00:00
|
|
|
@Override
|
|
|
|
|
public Texture getTexture() {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2007-03-15 19:52:28 +00:00
|
|
|
}
|