Update of /cvsroot/java-game-lib/LWJGL/src/java/org/lwjgl/test/openal In directory sc8-pr-cvs1:/tmp/cvs-serv3465/openal Added Files: ALCTest.java ALTest.java ALUTTest.java BasicTest.java EAXTest.java PlayTest.java PlayTestMemory.java Log Message: moved tests to org.lwjgl.test for easier seperation --- NEW FILE: ALCTest.java --- CVS Browser: http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/java-game-lib/LWJGL/src/java/org/lwjgl/test/openal/ALCTest.java /* * Copyright (c) 2002 Light Weight Java Game Library Project * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of 'Light Weight Java Game Library' nor the names of * its contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package org.lwjgl.test.openal; import org.lwjgl.openal.AL; import org.lwjgl.openal.ALC; import org.lwjgl.openal.ALCcontext; import org.lwjgl.openal.ALCdevice; import org.lwjgl.Sys; import java.nio.IntBuffer; /** * $Id: ALCTest.java,v 1.1 2002/11/19 16:48:25 matzon Exp $ * * This is a test for the ALC part of OpenAL * * @author Brian Matzon <br...@ma...> * @version $Revision: 1.1 $ */ public class ALCTest extends BasicTest { /** * Creates an instance of ALCTest */ public ALCTest() { super(); } /** * Runs the actual test, using supplied arguments */ protected void execute(String[] args) { //error stuff int lastError = ALC.NO_ERROR; //create a device device = alc.openDevice(null); if(device == null) { System.out.println("Unable to create device"); System.exit(-1); } //create attribute list for context creation IntBuffer buffer = createIntBuffer(7); buffer.put(ALC.FREQUENCY); buffer.put(44100); buffer.put(ALC.REFRESH); buffer.put(15); buffer.put(ALC.SYNC); buffer.put(ALC.FALSE); buffer.put(0); //terminating int //create a context, using above attributes context = alc.createContext(device, Sys.getDirectBufferAddress(buffer)); if(context == null) { System.out.println("Unable to create context"); System.exit(-1); } if((lastError = alc.getError(device)) != ALC.NO_ERROR) { System.out.println("ALC Error: " + alc.getString(device, lastError)); System.exit(-1); } //make current alc.makeContextCurrent(context); //process alc.processContext(context); //suspend alc.suspendContext(context); //query System.out.println("DEFAULT_DEVICE_SPECIFIER: " + alc.getString(device, ALC.DEFAULT_DEVICE_SPECIFIER)); System.out.println("DEVICE_SPECIFIER: " + alc.getString(device, ALC.DEVICE_SPECIFIER)); System.out.println("EXTENSIONS: " + alc.getString(device, ALC.EXTENSIONS)); //mo query buffer.rewind(); alc.getIntegerv(device, ALC.MAJOR_VERSION, 4, Sys.getDirectBufferAddress(buffer)); alc.getIntegerv(device, ALC.MINOR_VERSION, 4, Sys.getDirectBufferAddress(buffer)+4); System.out.println("ALC_MAJOR_VERSION: " + buffer.get(0)); System.out.println("ALC_MINOR_VERSION: " + buffer.get(1)); //no check for ALC_ALL_ATTRIBUTES / ALC_ATTRIBUTES_SIZE since it //is buggy on win32 - my dev platform //check current context ALCcontext currentContext = alc.getCurrentContext(); if(context.context != currentContext.context) { System.out.println("Serious error! - context copy != current context"); System.exit(-1); } //check contexts device ALCdevice currentDevice = alc.getContextsDevice(context); if(device.device != currentDevice.device) { System.out.println("Serious error! - device copy != current contexts device"); System.exit(-1); } //get an enumerstion value System.out.println("Value of ALC_MAJOR_VERSION: " + alc.getEnumValue(device, "ALC_MAJOR_VERSION")); //close context again alc.destroyContext(context); //close it alc.closeDevice(device); } /** * main entry point * * @param args String array containing arguments */ public static void main(String[] args) { ALCTest alcTest = new ALCTest(); alcTest.execute(args); } } --- NEW FILE: ALTest.java --- CVS Browser: http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/java-game-lib/LWJGL/src/java/org/lwjgl/test/openal/ALTest.java /* * Copyright (c) 2002 Light Weight Java Game Library Project * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of 'Light Weight Java Game Library' nor the names of * its contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * [...3243 lines suppressed...] if ((error = al.getError()) != AL.NO_ERROR) displayALError("alSourceStopv : ", error); break; } } while (ch != 'Q'); // Delete the Sources al.deleteSources(numSources, Sys.getDirectBufferAddress(Sources)); } /** * main entry point * * @param args String array containing arguments */ public static void main(String[] args) { ALTest alTest = new ALTest(); alTest.execute(args); } } --- NEW FILE: ALUTTest.java --- CVS Browser: http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/java-game-lib/LWJGL/src/java/org/lwjgl/test/openal/ALUTTest.java /* * Copyright (c) 2002 Light Weight Java Game Library Project * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of 'Light Weight Java Game Library' nor the names of * its contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package org.lwjgl.test.openal; import org.lwjgl.Sys; import org.lwjgl.openal.AL; import org.lwjgl.openal.ALUTLoadWAVData; import java.nio.ByteBuffer; import java.nio.ByteOrder; /** * $Id: ALUTTest.java,v 1.1 2002/11/19 16:48:25 matzon Exp $ * * This is a basic play test using ALUT * Yes, over zealous use of getError ;) * * @author Brian Matzon <br...@ma...> * @version $Revision: 1.1 $ */ public class ALUTTest extends BasicTest { /** * Creates an instance of ALUTTest */ public ALUTTest() { super(); } /** * Runs the actual test, using supplied arguments */ protected void execute(String[] args) { if(args.length < 1) { System.out.println("please specify filename to play"); return; } int lastError; //initialize AL, using ALUT alut.init(args); //create 1 buffer and 1 source ByteBuffer buffers = ByteBuffer.allocateDirect(4); buffers.order(ByteOrder.nativeOrder()); ByteBuffer sources = ByteBuffer.allocateDirect(4); sources.order(ByteOrder.nativeOrder()); // al generate buffers and sources al.genBuffers(1, Sys.getDirectBufferAddress(buffers)); if((lastError = al.getError()) != AL.NO_ERROR) { exit(lastError); } al.genSources(1, Sys.getDirectBufferAddress(sources)); if((lastError = al.getError()) != AL.NO_ERROR) { exit(lastError); } //load wave data ALUTLoadWAVData file = alut.loadWAVFile(args[0]); if((lastError = al.getError()) != AL.NO_ERROR) { exit(lastError); } //copy to buffers al.bufferData(buffers.getInt(0), file.format, file.data, file.size, file.freq); if((lastError = al.getError()) != AL.NO_ERROR) { exit(lastError); } //unload file again alut.unloadWAV(file.format, file.data, file.size, file.freq); if((lastError = al.getError()) != AL.NO_ERROR) { exit(lastError); } //set up source input al.sourcei(sources.getInt(0), AL.BUFFER, buffers.getInt(0)); if((lastError = al.getError()) != AL.NO_ERROR) { exit(lastError); } //lets loop the sound al.sourcei(sources.getInt(0), AL.LOOPING, AL.TRUE); if((lastError = al.getError()) != AL.NO_ERROR) { exit(lastError); } //play source 0 al.sourcePlay(sources.getInt(0)); if((lastError = al.getError()) != AL.NO_ERROR) { exit(lastError); } //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.getInt(0)); if((lastError = al.getError()) != AL.NO_ERROR) { exit(lastError); } //delete buffers and sources al.deleteSources(1, Sys.getDirectBufferAddress(sources)); if((lastError = al.getError()) != AL.NO_ERROR) { exit(lastError); } al.deleteBuffers(1, Sys.getDirectBufferAddress(buffers)); if((lastError = al.getError()) != AL.NO_ERROR) { exit(lastError); } //shutdown using ALUT alut.exit(); } /** * main entry point * * @param args String array containing arguments */ public static void main(String[] args) { ALUTTest alutTest = new ALUTTest(); alutTest.execute(args); } } --- NEW FILE: BasicTest.java --- CVS Browser: http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/java-game-lib/LWJGL/src/java/org/lwjgl/test/openal/BasicTest.java /* * Copyright (c) 2002 Light Weight Java Game Library Project * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of 'Light Weight Java Game Library' nor the names of * its contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package org.lwjgl.test.openal; 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; import java.nio.ByteBuffer; import java.nio.ByteOrder; import java.nio.IntBuffer; /** * $Id: BasicTest.java,v 1.1 2002/11/19 16:48:25 matzon Exp $ * * This is a basic test, which contains the most used stuff * * @author Brian Matzon <br...@ma...> * @version $Revision: 1.1 $ */ public abstract class BasicTest { /** 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 BasicTest() { al = new AL(); try { al.create(); } catch (Exception e) { e.printStackTrace(); return; } alc = new ALC(); try { alc.create(); } catch (Exception e) { e.printStackTrace(); return; } alut = new ALUT(); try { alut.create(); } catch (Exception e) { e.printStackTrace(); return; } } /** * Initializes OpenAL */ protected void alInitialize() { //get default device device = alc.openDevice(null); if(device == null) { throw new RuntimeException("Error creating device"); } //create context (no attributes specified) context = alc.createContext(device, 0); if(context == null) { throw new RuntimeException("Error creating context"); } //make context current alc.makeContextCurrent(context); if(alc.getError(device) != ALC.NO_ERROR) { throw new RuntimeException("An error occurred while making context current"); } } /** * Creates an integer buffer to hold specified ints * - strictly a utility method * * @param size how many int to contain * @return created IntBuffer */ protected IntBuffer createIntBuffer(int size) { ByteBuffer temp = ByteBuffer.allocateDirect(4*size); temp.order(ByteOrder.nativeOrder()); return temp.asIntBuffer(); } /** * Exits the test NOW, printing errorcode to stdout * * @param error Error code causing exit */ protected void exit(int error) { System.out.println("OpenAL Error: " + al.getString(error)); alut.exit(); System.exit(-1); } } --- NEW FILE: EAXTest.java --- CVS Browser: http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/java-game-lib/LWJGL/src/java/org/lwjgl/test/openal/EAXTest.java /* * Copyright (c) 2002 Light Weight Java Game Library Project * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of 'Light Weight Java Game Library' nor the names of * its contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package org.lwjgl.test.openal; import org.lwjgl.openal.eax.EAX; import org.lwjgl.openal.eax.EAXBufferProperties; import java.nio.IntBuffer; import org.lwjgl.Sys; import org.lwjgl.openal.AL; import org.lwjgl.openal.ALUTLoadWAVData; /** * $Id: EAXTest.java,v 1.1 2002/11/19 16:48:25 matzon Exp $ * * This test initializes EAX and tries to get and set some EAX values * * @author Brian Matzon <br...@ma...> * @version $Revision: 1.1 $ */ public class EAXTest extends BasicTest { /** * Creates an instance of EAXTest */ public EAXTest() { super(); } /** * Runs the actual test, using supplied arguments */ protected void execute(String[] args) { alInitialize(); EAX eax = new EAX(); try { eax.create(); } catch (Exception e) { e.printStackTrace(); return; } System.out.print("EAX supported..."); //no errorchecking from now on, since our context is gone. //shutdown alc.makeContextCurrent(null); alc.destroyContext(context); alc.closeDevice(device); System.out.println("test done."); } /** * main entry point * * @param args String array containing arguments */ public static void main(String[] args) { EAXTest eaxTest = new EAXTest(); eaxTest.execute(args); } } --- NEW FILE: PlayTest.java --- CVS Browser: http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/java-game-lib/LWJGL/src/java/org/lwjgl/test/openal/PlayTest.java /* * Copyright (c) 2002 Light Weight Java Game Library Project * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of 'Light Weight Java Game Library' nor the names of * its contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package org.lwjgl.test.openal; import org.lwjgl.Sys; import org.lwjgl.openal.AL; import org.lwjgl.openal.ALUTLoadWAVData; import java.nio.IntBuffer; /** * $Id: PlayTest.java,v 1.1 2002/11/19 16:48:25 matzon Exp $ * * This is a basic play test * Yes, over zealous use of getError ;) * * @author Brian Matzon <br...@ma...> * @version $Revision: 1.1 $ */ public class PlayTest extends BasicTest { /** * Creates an instance of PlayTest */ public PlayTest() { super(); } /** * Runs the actual test, using supplied arguments */ protected void execute(String[] args) { if(args.length < 1) { System.out.println("please specify filename to play"); return; } int lastError; //initialize AL, using ALC alInitialize(); //create 1 buffer and 1 source IntBuffer buffers = createIntBuffer(1); IntBuffer sources = createIntBuffer(1); // al generate buffers and sources al.genBuffers(1, Sys.getDirectBufferAddress(buffers)); if((lastError = al.getError()) != AL.NO_ERROR) { exit(lastError); } al.genSources(1, Sys.getDirectBufferAddress(sources)); if((lastError = al.getError()) != AL.NO_ERROR) { exit(lastError); } //load wave data ALUTLoadWAVData file = alut.loadWAVFile(args[0]); if((lastError = al.getError()) != AL.NO_ERROR) { exit(lastError); } //copy to buffers al.bufferData(buffers.get(0), file.format, file.data, file.size, file.freq); if((lastError = al.getError()) != AL.NO_ERROR) { exit(lastError); } //unload file again alut.unloadWAV(file.format, file.data, file.size, file.freq); if((lastError = al.getError()) != AL.NO_ERROR) { exit(lastError); } //set up source input al.sourcei(sources.get(0), AL.BUFFER, buffers.get(0)); if((lastError = al.getError()) != AL.NO_ERROR) { exit(lastError); } //lets loop the sound al.sourcei(sources.get(0), AL.LOOPING, AL.TRUE); if((lastError = al.getError()) != AL.NO_ERROR) { exit(lastError); } //play source 0 al.sourcePlay(sources.get(0)); if((lastError = al.getError()) != AL.NO_ERROR) { exit(lastError); } //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)); if((lastError = al.getError()) != AL.NO_ERROR) { exit(lastError); } //delete buffers and sources al.deleteSources(1, Sys.getDirectBufferAddress(sources)); if((lastError = al.getError()) != AL.NO_ERROR) { exit(lastError); } al.deleteBuffers(1, Sys.getDirectBufferAddress(buffers)); if((lastError = al.getError()) != AL.NO_ERROR) { exit(lastError); } //no errorchecking from now on, since our context is gone. //shutdown alc.makeContextCurrent(null); alc.destroyContext(context); alc.closeDevice(device); } /** * main entry point * * @param args String array containing arguments */ public static void main(String[] args) { PlayTest playTest = new PlayTest(); playTest.execute(args); } } --- NEW FILE: PlayTestMemory.java --- CVS Browser: http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/java-game-lib/LWJGL/src/java/org/lwjgl/test/openal/PlayTestMemory.java /* * Copyright (c) 2002 Light Weight Java Game Library Project * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of 'Light Weight Java Game Library' nor the names of * its contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package org.lwjgl.test.openal; import org.lwjgl.Sys; import org.lwjgl.openal.AL; import org.lwjgl.openal.ALUTLoadWAVData; import java.io.BufferedInputStream; import java.io.ByteArrayOutputStream; import java.net.MalformedURLException; import java.net.URL; import java.nio.ByteBuffer; import java.nio.ByteOrder; import java.nio.IntBuffer; /** * $Id: PlayTestMemory.java,v 1.1 2002/11/19 16:48:25 matzon Exp $ * * This is a basic play test * Yes, over zealous use of getError ;) * * @author Brian Matzon <br...@ma...> * @version $Revision: 1.1 $ */ public class PlayTestMemory extends BasicTest { /** * Creates an instance of PlayTestMemory */ public PlayTestMemory() { super(); } /** * Runs the actual test, using supplied arguments */ protected void execute(String[] args) { if(args.length < 1) { System.out.println("please specify filename to play"); return; } int lastError; //initialize AL, using ALC alInitialize(); //create 1 buffer and 1 source IntBuffer buffers = createIntBuffer(1); IntBuffer sources = createIntBuffer(1); // al generate buffers and sources al.genBuffers(1, Sys.getDirectBufferAddress(buffers)); if((lastError = al.getError()) != AL.NO_ERROR) { exit(lastError); } al.genSources(1, Sys.getDirectBufferAddress(sources)); if((lastError = al.getError()) != AL.NO_ERROR) { exit(lastError); } //load wave data ByteBuffer filebuffer = getData(args[0]); if(filebuffer == null) { System.out.println("Error loading file: " + args[0]); System.exit(-1); } ALUTLoadWAVData file = alut.loadWAVMemory(Sys.getDirectBufferAddress(filebuffer)); if((lastError = al.getError()) != AL.NO_ERROR) { exit(lastError); } //copy to buffers al.bufferData(buffers.get(0), file.format, file.data, file.size, file.freq); if((lastError = al.getError()) != AL.NO_ERROR) { exit(lastError); } //unload file again alut.unloadWAV(file.format, file.data, file.size, file.freq); if((lastError = al.getError()) != AL.NO_ERROR) { exit(lastError); } //set up source input al.sourcei(sources.get(0), AL.BUFFER, buffers.get(0)); if((lastError = al.getError()) != AL.NO_ERROR) { exit(lastError); } //lets loop the sound al.sourcei(sources.get(0), AL.LOOPING, AL.TRUE); if((lastError = al.getError()) != AL.NO_ERROR) { exit(lastError); } //play source 0 al.sourcePlay(sources.get(0)); if((lastError = al.getError()) != AL.NO_ERROR) { exit(lastError); } //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)); if((lastError = al.getError()) != AL.NO_ERROR) { exit(lastError); } //delete buffers and sources al.deleteSources(1, Sys.getDirectBufferAddress(sources)); if((lastError = al.getError()) != AL.NO_ERROR) { exit(lastError); } al.deleteBuffers(1, Sys.getDirectBufferAddress(buffers)); if((lastError = al.getError()) != AL.NO_ERROR) { exit(lastError); } //no errorchecking from now on, since our context is gone. //shutdown alc.makeContextCurrent(null); alc.destroyContext(context); alc.closeDevice(device); } /** * Reads the file into a ByteBuffer * * @param filename Name of file to load * @return ByteBuffer containing file data */ protected ByteBuffer getData(String filename) { ByteBuffer buffer = null; URL url = null; String cwd = System.getProperty("user.dir"); try { url = new URL("file:///" + cwd + "/" + filename); } catch (MalformedURLException mue) { mue.printStackTrace(); } System.out.println("Attempting to load: " + url); try { BufferedInputStream bis = new BufferedInputStream(url.openStream()); ByteArrayOutputStream baos = new ByteArrayOutputStream(); int bufferLength = 4096; byte[] readBuffer = new byte[bufferLength]; int read = -1; while((read = bis.read(readBuffer, 0, bufferLength)) != -1) { baos.write(readBuffer, 0, read); } //done reading, close bis.close(); buffer = ByteBuffer.allocateDirect(baos.size()); buffer.order(ByteOrder.nativeOrder()); buffer.put(baos.toByteArray()); } catch (Exception ioe) { ioe.printStackTrace(); } return buffer; } /** * main entry point * * @param args String array containing arguments */ public static void main(String[] args) { PlayTestMemory playTestMemory = new PlayTestMemory(); playTestMemory.execute(args); } } |