diff --git a/doc/tutorial/OpenAL_Tutoral.html b/doc/tutorial/OpenAL_Tutoral.html new file mode 100644 index 00000000..cd365535 --- /dev/null +++ b/doc/tutorial/OpenAL_Tutoral.html @@ -0,0 +1,208 @@ + + +
+import
+org.lwjgl.openal.AL;
+import org.lwjgl.openal.ALC;
+import org.lwjgl.openal.ALCcontext;
+import org.lwjgl.openal.ALCdevice;
+import org.lwjgl.openal.ALUT;
+
+public class PlayTest {
+
+ /** OpenAL instance */
+ protected AL al;
+
+ /** OpenAL Context instance */
+ protected ALC alc;
+
+ /** OpenAL Util library instance */
+ protected ALUT alut;
+
+ /** OpenAL context */
+ protected ALCcontext context;
+
+ /** OpenAL device */
+ protected ALCdevice device;
+
+ /**
+ * Creates an instance of PlayTest
+ */
+ public PlayTest() {
+ try {
+ al = new AL();
+ alc = new ALC();
+ alut = new ALUT();
+
+ al.create();
+ alc.create();
+ alut.create();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+}
+/**
+ * Initializes OpenAL
+ */
+ protected void alInitialize() {
+ //get default device
+ device = alc.openDevice(null);
+
+ //create context (no attributes specified)
+ context = alc.createContext(device, 0);
+
+ //make context current
+ alc.makeContextCurrent(context);
+ }
+
1.4 Buffer and Source creation
+Now that we have opened a device and gotten a context, we need to create
+two things to actually get some sound. We need to create a buffer to hold
+sounddata, and a source that is to play the sounddata.
+Lets start of by creating one source, and one buffer:
+//create one IntBuffer as buffer and one as source
+ IntBuffer buffers = createIntBuffer(1);
+ IntBuffer sources = createIntBuffer(1);
+
+ //generate buffers and sources
+ al.genBuffers(1, Sys.getDirectBufferAddress(buffers));
+ al.genSources(1, Sys.getDirectBufferAddress(sources));
There, all set for actually loading some sounddata into the buffer.
+
+//load wave data
+ ALUTLoadWAVData file = alut.loadWAVFile("myfile.wav");
+
+ //copy to buffer
+ al.bufferData(buffers.get(0), file.format, file.data, file.size, file.freq);
+
+ //unload file again
+ alut.unloadWAV(file.format, file.data, file.size, file.freq);
+
+//set up source input
+ al.sourcei(sources.get(0), AL.BUFFER, buffers.get(0));
+
+//loop source
+ al.sourcei(sources.get(0), AL.LOOPING, AL.TRUE);
+
+//play source 0
+ al.sourcePlay(sources.get(0));
+
+ //wait 5 secs
+ try {
+ System.out.println("Waiting 5 seconds for sound to complete");
+ Thread.sleep(5000);
+ } catch (InterruptedException inte) {
+ }
+
+ //stop source 0
+ al.sourceStop(sources.get(0));
+//delete buffers and sources
+ al.deleteSources(1, Sys.getDirectBufferAddress(sources));
+ al.deleteBuffers(1, Sys.getDirectBufferAddress(buffers));
+
+ //shutdown
+ alc.makeContextCurrent(null);
+ alc.destroyContext(context);
+ alc.closeDevice(device);