A new sound system based on OpenAL. Only supports sound effects at the
moment, but OpenAL has the necessary business to later integrate "streams" of audio (music). git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@3669 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -0,0 +1,69 @@
|
||||
//
|
||||
// $Id$
|
||||
|
||||
package com.threerings.openal;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.lwjgl.util.WaveData;
|
||||
|
||||
import com.samskivert.util.Interval;
|
||||
import com.samskivert.util.Queue;
|
||||
import com.samskivert.util.RunQueue;
|
||||
|
||||
/**
|
||||
* Tests the OpenAL sound system.
|
||||
*/
|
||||
public class TestSoundManager
|
||||
{
|
||||
public static void main (String[] args)
|
||||
{
|
||||
if (args.length == 0) {
|
||||
System.err.println("Usage: TestSoundManager sound.wav");
|
||||
System.exit(-1);
|
||||
}
|
||||
|
||||
final Thread current = Thread.currentThread();
|
||||
RunQueue rqueue = new RunQueue() {
|
||||
public void postRunnable (Runnable r) {
|
||||
_queue.append(r);
|
||||
}
|
||||
public boolean isDispatchThread () {
|
||||
return (current == Thread.currentThread());
|
||||
}
|
||||
};
|
||||
|
||||
SoundManager smgr = SoundManager.createSoundManager(rqueue);
|
||||
ClipProvider provider = new ClipProvider() {
|
||||
public Clip loadClip (String path) throws IOException {
|
||||
Clip clip = new Clip();
|
||||
WaveData file = WaveData.create(path);
|
||||
if (file == null) {
|
||||
throw new IOException("Error loading " + path);
|
||||
}
|
||||
clip.format = file.format;
|
||||
clip.frequency = file.samplerate;
|
||||
clip.data = file.data;
|
||||
return clip;
|
||||
}
|
||||
};
|
||||
final SoundGroup group = smgr.createGroup(provider, 5);
|
||||
final String path = args[0];
|
||||
|
||||
// queue up an interval to play a sound over and over
|
||||
Interval i = new Interval(rqueue) {
|
||||
public void expired () {
|
||||
Sound sound = group.getSound(path);
|
||||
sound.play(true);
|
||||
}
|
||||
};
|
||||
i.schedule(100L, true);
|
||||
|
||||
while (true) {
|
||||
Runnable r = (Runnable)_queue.get();
|
||||
r.run();
|
||||
}
|
||||
}
|
||||
|
||||
protected static Queue _queue = new Queue();
|
||||
}
|
||||
Reference in New Issue
Block a user