Skip to content

Instantly share code, notes, and snippets.

@windy1
Last active December 10, 2015 08:08
Show Gist options
  • Save windy1/4405243 to your computer and use it in GitHub Desktop.
Save windy1/4405243 to your computer and use it in GitHub Desktop.
interface SoundListener {
void setPosition(Point pos);
Point getPosition();
void setVelocity(Vector3 vec);
Vector3 getVelocity();
void setOrientation(Matrix o);
Matrix getOrientation();
}
class SpoutSoundListener implements SoundListener {
World world;
void setPosition(Point pos) {
world = pos.getWorld();
setVector3(AL10.AL_POSITION, pos);
}
Point getPosition() {
Vector3 v = getVector3(AL10.AL_POSITION);
return new Point(world, v.getX(), v.getY(), v.getZ());
}
void setVelocity(Vector3 vec) {
setVector3(AL10.AL_VELOCITY, vec);
}
Vector3 getVelocity() {
return getVector3(AL10.AL_VELOCITY);
}
// TODO: Orientation
void setVector3(int prop, Vector3 vec) {
FloatBuffer buffer = BufferUtils.createFloatBuffer(3).put(vec.toArray());
buffer.flip();
AL10.alListener(prop, buffer);
}
Vector3 getVector3(int prop) {
FloatBuffer buffer = BufferUtils.createFloatBuffer(3);
AL10.alGetListener(prop, buffer);
return new Vector3(buffer.get(0), buffer.get(1), buffer.get(2));
}
}
// TODO: SoundSource should be protected
// TODO: Clean up SoundSource
// TODO: Clean up SoundState
class SpoutSoundManager implements SoundManager {
List<SoundSource> sources = new ArrayList<SoundSource>();
SoundListener activeListener = new SpoutSoundListener();
SoundSource createSource(Sound sound) {
SoundSource source = new SpoutSoundSource();
source.setSound(sound);
sources.add(source);
return source;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment