2002-08-14 01:01:06 +02:00
|
|
|
package org.lwjgl.openal;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* $Id$
|
|
|
|
|
*
|
|
|
|
|
* This is the OpenAL Test.
|
|
|
|
|
* This class will eventually test *all* apects of OpenAL...
|
|
|
|
|
*
|
|
|
|
|
* @author Brian Matzon <brian@matzon.dk>
|
|
|
|
|
* @version $Revision$
|
|
|
|
|
*/
|
|
|
|
|
public class OpenALTest {
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Creates an instance of OpenALTest
|
|
|
|
|
*/
|
|
|
|
|
public OpenALTest() {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* main entry point
|
|
|
|
|
*
|
|
|
|
|
* @param args String array containing arguments
|
|
|
|
|
*/
|
|
|
|
|
public static void main(String[] args) {
|
|
|
|
|
//create OpenAL instance (and util lib)
|
|
|
|
|
AL al = new AL();
|
|
|
|
|
ALUT alut = new ALUT();
|
|
|
|
|
|
|
|
|
|
/* buffers */
|
|
|
|
|
int[] buffers = new int[1];
|
|
|
|
|
|
|
|
|
|
/* sources */
|
|
|
|
|
int[] sources = new int[1];
|
|
|
|
|
|
|
|
|
|
/* initialize */
|
2002-08-15 16:34:20 +02:00
|
|
|
alut.init(args);
|
2002-08-14 01:01:06 +02:00
|
|
|
|
|
|
|
|
/* create buffers and sources */
|
2002-08-15 16:34:20 +02:00
|
|
|
al.genBuffers(1, buffers);
|
|
|
|
|
al.genSources(1, sources);
|
2002-08-14 01:01:06 +02:00
|
|
|
|
|
|
|
|
/* load data */
|
2002-08-15 16:34:20 +02:00
|
|
|
ALUTLoadWAVFile file = alut.loadWAVFile("footsteps.wav");
|
2002-08-14 01:01:06 +02:00
|
|
|
|
|
|
|
|
/* copy to buffers */
|
2002-08-15 16:34:20 +02:00
|
|
|
al.bufferData(buffers[0], file.format, file.data, file.size, file.freq);
|
2002-08-14 01:01:06 +02:00
|
|
|
|
|
|
|
|
/* unload file again */
|
2002-08-15 16:34:20 +02:00
|
|
|
alut.unloadWAV(file.format, file.data, file.size, file.freq);
|
2002-08-14 01:01:06 +02:00
|
|
|
|
|
|
|
|
/* set up source input */
|
2002-08-15 16:34:20 +02:00
|
|
|
al.sourcei(sources[0], AL.BUFFER, buffers[0]);
|
2002-08-14 01:01:06 +02:00
|
|
|
|
|
|
|
|
/* lets loop the sound */
|
2002-08-15 16:34:20 +02:00
|
|
|
al.sourcei(sources[0], AL.LOOPING, AL.TRUE);
|
2002-08-14 01:01:06 +02:00
|
|
|
|
|
|
|
|
/* play source 0 */
|
2002-08-15 16:34:20 +02:00
|
|
|
al.sourcePlay(sources[0]);
|
2002-08-14 01:01:06 +02:00
|
|
|
|
|
|
|
|
System.out.println("will exit in 5 seconds (so we don't crash if weird stuff has happened with file...)\n");
|
|
|
|
|
for(int i=0; i<5; i++) {
|
|
|
|
|
try {
|
|
|
|
|
System.out.println(5-i);
|
|
|
|
|
Thread.sleep(1000);
|
|
|
|
|
} catch(InterruptedException inte) {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* stop source 0 */
|
2002-08-15 16:34:20 +02:00
|
|
|
al.sourceStop(sources[0]);
|
2002-08-14 01:01:06 +02:00
|
|
|
|
|
|
|
|
/* delete buffers and sources */
|
2002-08-15 16:34:20 +02:00
|
|
|
al.deleteSources(1, sources);
|
|
|
|
|
al.deleteBuffers(1, buffers);
|
2002-08-14 01:01:06 +02:00
|
|
|
|
|
|
|
|
/* shutdown */
|
2002-08-15 16:34:20 +02:00
|
|
|
alut.exit();
|
2002-08-14 01:01:06 +02:00
|
|
|
}
|
|
|
|
|
}
|