From 4050d93e4747b5418379319e7216af6113ea23e5 Mon Sep 17 00:00:00 2001 From: Michael Bien Date: Mon, 29 Mar 2010 18:35:57 +0200 Subject: renamed package to com.jogamp.openal.* --- src/java/build.xml | 10 +- src/java/com/jogamp/openal/ALException.java | 62 +++ src/java/com/jogamp/openal/ALFactory.java | 91 ++++ src/java/com/jogamp/openal/eax/EAX.java | 140 ++++++ src/java/com/jogamp/openal/eax/EAXConstants.java | 350 ++++++++++++++ src/java/com/jogamp/openal/eax/EAXFactory.java | 54 +++ .../jogamp/openal/impl/ALProcAddressLookup.java | 162 +++++++ .../com/jogamp/openal/impl/NativeLibLoader.java | 114 +++++ .../com/jogamp/openal/sound3d/AudioSystem3D.java | 273 +++++++++++ src/java/com/jogamp/openal/sound3d/Buffer.java | 144 ++++++ src/java/com/jogamp/openal/sound3d/Context.java | 77 ++++ src/java/com/jogamp/openal/sound3d/Device.java | 59 +++ src/java/com/jogamp/openal/sound3d/Listener.java | 171 +++++++ src/java/com/jogamp/openal/sound3d/Source.java | 508 +++++++++++++++++++++ src/java/com/jogamp/openal/sound3d/Vec3f.java | 63 +++ src/java/com/jogamp/openal/util/ALut.java | 146 ++++++ src/java/com/jogamp/openal/util/BufferUtils.java | 266 +++++++++++ src/java/com/jogamp/openal/util/WAVData.java | 75 +++ src/java/com/jogamp/openal/util/WAVLoader.java | 135 ++++++ src/java/net/java/games/joal/ALException.java | 62 --- src/java/net/java/games/joal/ALFactory.java | 89 ---- src/java/net/java/games/joal/eax/EAX.java | 140 ------ src/java/net/java/games/joal/eax/EAXConstants.java | 350 -------------- src/java/net/java/games/joal/eax/EAXFactory.java | 54 --- .../java/games/joal/impl/ALProcAddressLookup.java | 159 ------- .../net/java/games/joal/impl/NativeLibLoader.java | 114 ----- src/java/net/java/games/joal/util/ALut.java | 146 ------ src/java/net/java/games/joal/util/BufferUtils.java | 266 ----------- src/java/net/java/games/joal/util/WAVData.java | 75 --- src/java/net/java/games/joal/util/WAVLoader.java | 135 ------ src/java/net/java/games/sound3d/AudioSystem3D.java | 273 ----------- src/java/net/java/games/sound3d/Buffer.java | 144 ------ src/java/net/java/games/sound3d/Context.java | 77 ---- src/java/net/java/games/sound3d/Device.java | 59 --- src/java/net/java/games/sound3d/Listener.java | 171 ------- src/java/net/java/games/sound3d/Source.java | 508 --------------------- src/java/net/java/games/sound3d/Vec3f.java | 63 --- 37 files changed, 2895 insertions(+), 2890 deletions(-) create mode 100755 src/java/com/jogamp/openal/ALException.java create mode 100644 src/java/com/jogamp/openal/ALFactory.java create mode 100644 src/java/com/jogamp/openal/eax/EAX.java create mode 100644 src/java/com/jogamp/openal/eax/EAXConstants.java create mode 100644 src/java/com/jogamp/openal/eax/EAXFactory.java create mode 100755 src/java/com/jogamp/openal/impl/ALProcAddressLookup.java create mode 100755 src/java/com/jogamp/openal/impl/NativeLibLoader.java create mode 100644 src/java/com/jogamp/openal/sound3d/AudioSystem3D.java create mode 100644 src/java/com/jogamp/openal/sound3d/Buffer.java create mode 100644 src/java/com/jogamp/openal/sound3d/Context.java create mode 100644 src/java/com/jogamp/openal/sound3d/Device.java create mode 100644 src/java/com/jogamp/openal/sound3d/Listener.java create mode 100644 src/java/com/jogamp/openal/sound3d/Source.java create mode 100644 src/java/com/jogamp/openal/sound3d/Vec3f.java create mode 100644 src/java/com/jogamp/openal/util/ALut.java create mode 100644 src/java/com/jogamp/openal/util/BufferUtils.java create mode 100644 src/java/com/jogamp/openal/util/WAVData.java create mode 100644 src/java/com/jogamp/openal/util/WAVLoader.java delete mode 100755 src/java/net/java/games/joal/ALException.java delete mode 100644 src/java/net/java/games/joal/ALFactory.java delete mode 100644 src/java/net/java/games/joal/eax/EAX.java delete mode 100644 src/java/net/java/games/joal/eax/EAXConstants.java delete mode 100644 src/java/net/java/games/joal/eax/EAXFactory.java delete mode 100755 src/java/net/java/games/joal/impl/ALProcAddressLookup.java delete mode 100755 src/java/net/java/games/joal/impl/NativeLibLoader.java delete mode 100644 src/java/net/java/games/joal/util/ALut.java delete mode 100644 src/java/net/java/games/joal/util/BufferUtils.java delete mode 100644 src/java/net/java/games/joal/util/WAVData.java delete mode 100644 src/java/net/java/games/joal/util/WAVLoader.java delete mode 100644 src/java/net/java/games/sound3d/AudioSystem3D.java delete mode 100644 src/java/net/java/games/sound3d/Buffer.java delete mode 100644 src/java/net/java/games/sound3d/Context.java delete mode 100644 src/java/net/java/games/sound3d/Device.java delete mode 100644 src/java/net/java/games/sound3d/Listener.java delete mode 100644 src/java/net/java/games/sound3d/Source.java delete mode 100644 src/java/net/java/games/sound3d/Vec3f.java (limited to 'src/java') diff --git a/src/java/build.xml b/src/java/build.xml index 44a11ae..9e11377 100644 --- a/src/java/build.xml +++ b/src/java/build.xml @@ -47,19 +47,19 @@ - - - - + + + - + diff --git a/src/java/com/jogamp/openal/ALException.java b/src/java/com/jogamp/openal/ALException.java new file mode 100755 index 0000000..7f0dcd3 --- /dev/null +++ b/src/java/com/jogamp/openal/ALException.java @@ -0,0 +1,62 @@ +/** + * Copyright (c) 2003-2005 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * -Redistribution of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * -Redistribution 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 Sun Microsystems, Inc. or the names of contributors may + * be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. + * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING + * ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR + * NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND ITS + * LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A + * RESULT OF USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. + * IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT + * OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR + * PUNITIVE DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF SUN HAS + * BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed or intended for use in the + * design, construction, operation or maintenance of any nuclear facility. + */ + +package com.jogamp.openal; + +/** A generic exception for OpenAL errors used throughout the binding + as a substitute for {@link RuntimeException}. */ + +public class ALException extends RuntimeException { + /** Constructs an ALException object. */ + public ALException() { + super(); + } + + /** Constructs an ALException object with the specified detail + message. */ + public ALException(String message) { + super(message); + } + + /** Constructs an ALException object with the specified detail + message and root cause. */ + public ALException(String message, Throwable cause) { + super(message, cause); + } + + /** Constructs an ALException object with the specified root + cause. */ + public ALException(Throwable cause) { + super(cause); + } +} diff --git a/src/java/com/jogamp/openal/ALFactory.java b/src/java/com/jogamp/openal/ALFactory.java new file mode 100644 index 0000000..f58fe4b --- /dev/null +++ b/src/java/com/jogamp/openal/ALFactory.java @@ -0,0 +1,91 @@ +/** + * Copyright (c) 2003-2005 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * -Redistribution of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * -Redistribution 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 Sun Microsystems, Inc. or the names of contributors may + * be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. + * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING + * ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR + * NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND ITS + * LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A + * RESULT OF USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. + * IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT + * OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR + * PUNITIVE DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF SUN HAS + * BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed or intended for use in the + * design, construction, operation or maintenance of any nuclear facility. + */ + +package com.jogamp.openal; + +import com.jogamp.openal.AL; +import com.jogamp.openal.ALC; +import com.jogamp.openal.impl.*; + +/** + * This class provides factory methods for generating AL and ALC objects. + * + * @author Athomas Goldberg + * @author Kenneth Russell + */ +public class ALFactory { + private static boolean initialized = false; + private static AL al; + private static ALC alc; + + private ALFactory() {} + + private static synchronized void initialize() throws ALException { + try { + if (!initialized) { + NativeLibLoader.load(); + initialized = true; + } + } catch (UnsatisfiedLinkError e) { + throw new ALException(e); + } + } + + /** + * Get the default AL object. This object is used to access most of the + * OpenAL functionality. + * + * @return the AL object + */ + public static AL getAL() throws ALException { + initialize(); + if (al == null) { + al = new ALImpl(); + } + return al; + } + + /** + * Get the default ALC object. This object is used to access most of the + * OpenAL context functionality. + * + * @return the ALC object + */ + public static ALC getALC() throws ALException{ + initialize(); + if (alc == null) { + alc = new ALCImpl(); + } + return alc; + } +} diff --git a/src/java/com/jogamp/openal/eax/EAX.java b/src/java/com/jogamp/openal/eax/EAX.java new file mode 100644 index 0000000..93af6bc --- /dev/null +++ b/src/java/com/jogamp/openal/eax/EAX.java @@ -0,0 +1,140 @@ +/** +* Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions are met: +* +* -Redistribution of source code must retain the above copyright notice, +* this list of conditions and the following disclaimer. +* +* -Redistribution 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 Sun Microsystems, Inc. or the names of contributors may +* be used to endorse or promote products derived from this software without +* specific prior written permission. +* +* This software is provided "AS IS," without a warranty of any kind. +* ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING +* ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR +* NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND ITS +* LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A +* RESULT OF USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. +* IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT +* OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR +* PUNITIVE DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, +* ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF SUN HAS +* BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. +* +* You acknowledge that this software is not designed or intended for use in the +* design, construction, operation or maintenance of any nuclear facility. +*/ + +package com.jogamp.openal.eax; + +import java.nio.Buffer; + + +/** + * @author Athomas Goldberg + * + */ +public class EAX implements EAXConstants { + static { + System.loadLibrary("joal_native"); + } + + public static final int SOURCE = 0; + public static final int LISTENER = 1; + + private final int sourceGUID = SOURCE; + private final int listenerGUID = LISTENER; + + /** + * @param sourceGUID + * @param listenerGUID + */ + EAX(int sourceGUID, int listenerGUID) { + // this.sourceGUID = sourceGUID; + // this.listenerGUID = listenerGUID; + } + + /** + * This method sets an EAX property value.
+ *
+ * Interface to C Language function: + *
ALenum EAXSet(const struct _GUID *propertySetID, ALuint property, ALuint source, ALvoid *value, ALuint size)
+ * + * @param objectFlag a flag indicating a LISTENER or a SOURCE + * @param pname the property being set + * @param source the ID of the source, or 0 for Listener properties + * @param value a direct Buffer to hold the value retrieved + * @param size the size of the Buffer + */ + public native void EAXSet( + int objectFlag, + int pname, + int source, + Buffer value, + int size + ); + + /** + * This method retrieves an EAX property value.
+ *
+ * Interface to C Language function: + *
ALenum EAXGet(const struct _GUID *propertySetID, ALuint property, ALuint source, ALvoid *value, ALuint size)
+ * + * @param objectFlag a flag indicating a LISTENER or a SOURCE + * @param pname the property being queried + * @param source the ID of the source, or 0 for Listener properties + * @param value a direct Buffer to hold the value retrieved + * @param size the size of the Buffer + */ + public native void EAXGet( + int objectFlag, + int pname, + int source, + Buffer value, + int size + ); + + /** + * This method sets a source property. + * @param sourceID the ID of the source whose property is being set. + * @param pname the name of the property being set + * @param value a direct Buffer containing the value to be set + */ + public void setSourceProperty(int sourceID, int pname, Buffer value) { + EAXSet(sourceGUID, pname, sourceID, value, value.capacity()); + } + + /** + * This method retrieves a source property. + * @param sourceID the ID of the source whose property is being retrieved. + * @param pname the name of the property being retrieved + * @param value a direct Buffer to hold the value to be retrieved + */ + public void getSourceProperty(int pname, int sourceID, Buffer value) { + EAXGet(sourceGUID, pname, sourceID, value, value.capacity()); + } + + /** + * This method sets a Listener property. + * @param pname the name of the property being set + * @param value a direct Buffer containing the value to be set + */ + public void setListenerProperty(int pname, Buffer value) { + EAXSet(listenerGUID, pname, 0, value, value.capacity()); + } + + /** + * This method retrieves a Listener property. + * @param pname the name of the property being retrieved + * @param value a direct Buffer to hold the value to be retrieved + */ + public void getListenerProperty(int pname, Buffer value) { + EAXGet(listenerGUID, pname, 0, value, value.capacity()); + } +} diff --git a/src/java/com/jogamp/openal/eax/EAXConstants.java b/src/java/com/jogamp/openal/eax/EAXConstants.java new file mode 100644 index 0000000..106932d --- /dev/null +++ b/src/java/com/jogamp/openal/eax/EAXConstants.java @@ -0,0 +1,350 @@ +/** +* Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions are met: +* +* -Redistribution of source code must retain the above copyright notice, +* this list of conditions and the following disclaimer. +* +* -Redistribution 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 Sun Microsystems, Inc. or the names of contributors may +* be used to endorse or promote products derived from this software without +* specific prior written permission. +* +* This software is provided "AS IS," without a warranty of any kind. +* ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING +* ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR +* NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND ITS +* LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A +* RESULT OF USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. +* IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT +* OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR +* PUNITIVE DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, +* ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF SUN HAS +* BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. +* +* You acknowledge that this software is not designed or intended for use in the +* design, construction, operation or maintenance of any nuclear facility. +*/ + +package com.jogamp.openal.eax; +/** + * + * This class implements the basic EAX extension constants. + * + * @author Athomas Goldberg + */ +public interface EAXConstants { + + public final static int DSPROPERTY_EAXLISTENER_NONE = 0; + public final static int DSPROPERTY_EAXLISTENER_ALLPARAMETERS = 1; + public final static int DSPROPERTY_EAXLISTENER_ROOM = 2; + public final static int DSPROPERTY_EAXLISTENER_ROOMHF = 3; + public final static int DSPROPERTY_EAXLISTENER_ROOMROLLOFFFACTOR = 4; + public final static int DSPROPERTY_EAXLISTENER_DECAYTIME = 5; + public final static int DSPROPERTY_EAXLISTENER_DECAYHFRATIO = 6; + public final static int DSPROPERTY_EAXLISTENER_REFLECTIONS = 7; + public final static int DSPROPERTY_EAXLISTENER_REFLECTIONSDELAY = 8; + public final static int DSPROPERTY_EAXLISTENER_REVERB = 9; + public final static int DSPROPERTY_EAXLISTENER_REVERBDELAY = 10; + public final static int DSPROPERTY_EAXLISTENER_ENVIRONMENT = 11; + public final static int DSPROPERTY_EAXLISTENER_ENVIRONMENTSIZE = 12; + public final static int DSPROPERTY_EAXLISTENER_ENVIRONMENTDIFFUSION = 13; + public final static int DSPROPERTY_EAXLISTENER_AIRABSORPTIONHF = 14; + public final static int DSPROPERTY_EAXLISTENER_FLAGS = 15; + +// OR these flags with property id // + /** changes take effect immediately */ + public static final int DSPROPERTY_EAXLISTENER_IMMEDIATE = 0x00000000; + + /** changes take effect later */ + public static final int DSPROPERTY_EAXLISTENER_DEFERRED = 0x80000000; + + public static final int DSPROPERTY_EAXLISTENER_COMMITDEFERREDSETTINGS = + DSPROPERTY_EAXLISTENER_NONE | + DSPROPERTY_EAXLISTENER_IMMEDIATE; + + /** used by DSPROPERTY_EAXLISTENER_ENVIRONMENT */ + public final static int EAX_ENVIRONMENT_GENERIC = 0; + /** used by DSPROPERTY_EAXLISTENER_ENVIRONMENT */ + public final static int EAX_ENVIRONMENT_PADDEDCELL = 1; + /** used by DSPROPERTY_EAXLISTENER_ENVIRONMENT */ + public final static int EAX_ENVIRONMENT_ROOM = 2; + /** used by DSPROPERTY_EAXLISTENER_ENVIRONMENT */ + public final static int EAX_ENVIRONMENT_BATHROOM = 3; + /** used by DSPROPERTY_EAXLISTENER_ENVIRONMENT */ + public final static int EAX_ENVIRONMENT_LIVINGROOM = 4; + /** used by DSPROPERTY_EAXLISTENER_ENVIRONMENT */ + public final static int EAX_ENVIRONMENT_STONEROOM = 5; + /** used by DSPROPERTY_EAXLISTENER_ENVIRONMENT */ + public final static int EAX_ENVIRONMENT_AUDITORIUM = 6; + /** used by DSPROPERTY_EAXLISTENER_ENVIRONMENT */ + public final static int EAX_ENVIRONMENT_CONCERTHALL = 7; + /** used by DSPROPERTY_EAXLISTENER_ENVIRONMENT */ + public final static int EAX_ENVIRONMENT_CAVE = 8; + /** used by DSPROPERTY_EAXLISTENER_ENVIRONMENT */ + public final static int EAX_ENVIRONMENT_ARENA = 9; + /** used by DSPROPERTY_EAXLISTENER_ENVIRONMENT */ + public final static int EAX_ENVIRONMENT_HANGAR = 10; + /** used by DSPROPERTY_EAXLISTENER_ENVIRONMENT */ + public final static int EAX_ENVIRONMENT_CARPETEDHALLWAY = 11; + /** used by DSPROPERTY_EAXLISTENER_ENVIRONMENT */ + public final static int EAX_ENVIRONMENT_HALLWAY = 12; + /** used by DSPROPERTY_EAXLISTENER_ENVIRONMENT */ + public final static int EAX_ENVIRONMENT_STONECORRIDOR = 13; + /** used by DSPROPERTY_EAXLISTENER_ENVIRONMENT */ + public final static int EAX_ENVIRONMENT_ALLEY = 14; + /** used by DSPROPERTY_EAXLISTENER_ENVIRONMENT */ + public final static int EAX_ENVIRONMENT_FOREST = 15; + /** used by DSPROPERTY_EAXLISTENER_ENVIRONMENT */ + public final static int EAX_ENVIRONMENT_CITY = 16; + /** used by DSPROPERTY_EAXLISTENER_ENVIRONMENT */ + public final static int EAX_ENVIRONMENT_MOUNTAINS = 17; + /** used by DSPROPERTY_EAXLISTENER_ENVIRONMENT */ + public final static int EAX_ENVIRONMENT_QUARRY = 18; + /** used by DSPROPERTY_EAXLISTENER_ENVIRONMENT */ + public final static int EAX_ENVIRONMENT_PLAIN = 19; + /** used by DSPROPERTY_EAXLISTENER_ENVIRONMENT */ + public final static int EAX_ENVIRONMENT_PARKINGLOT = 20; + /** used by DSPROPERTY_EAXLISTENER_ENVIRONMENT */ + public final static int EAX_ENVIRONMENT_SEWERPIPE = 21; + /** used by DSPROPERTY_EAXLISTENER_ENVIRONMENT */ + public final static int EAX_ENVIRONMENT_UNDERWATER = 22; + /** used by DSPROPERTY_EAXLISTENER_ENVIRONMENT */ + public final static int EAX_ENVIRONMENT_DRUGGED = 23; + /** used by DSPROPERTY_EAXLISTENER_ENVIRONMENT */ + public final static int EAX_ENVIRONMENT_DIZZY = 24; + /** used by DSPROPERTY_EAXLISTENER_ENVIRONMENT */ + public final static int EAX_ENVIRONMENT_PSYCHOTIC = 25; + /** used by DSPROPERTY_EAXLISTENER_ENVIRONMENT */ + public final static int EAX_ENVIRONMENT_COUNT = 26; + +// These flags determine what properties are affected by environment size. + /** reverberation decay time */ + public final static int EAXLISTENERFLAGS_DECAYTIMESCALE = 0x00000001; + /** reflection level */ + public final static int EAXLISTENERFLAGS_REFLECTIONSSCALE = 0x00000002; + /** initial reflection delay time */ + public final static int EAXLISTENERFLAGS_REFLECTIONSDELAYSCALE = 0x00000004; + /** reflections level */ + public final static int EAXLISTENERFLAGS_REVERBSCALE = 0x00000008; + /** late reverberation delay time */ + public final static int EAXLISTENERFLAGS_REVERBDELAYSCALE = 0x00000010; + + /** This flag limits high-frequency decay time according to air absorption.*/ + public final static int EAXLISTENERFLAGS_DECAYHFLIMIT = 0x00000020; + /** reserved future use */ + public final static int EAXLISTENERFLAGS_RESERVED = 0xFFFFFFC0; + +// property ranges and defaults: + + public final static int EAXLISTENER_MINROOM = -10000; + public final static int EAXLISTENER_MAXROOM = 0; + public final static int EAXLISTENER_DEFAULTROOM = -1000; + + public final static int EAXLISTENER_MINROOMHF = -10000; + public final static int EAXLISTENER_MAXROOMHF = 0; + public final static int EAXLISTENER_DEFAULTROOMHF = -100; + + public final static float EAXLISTENER_MINROOMROLLOFFFACTOR = 0.0f; + public final static float EAXLISTENER_MAXROOMROLLOFFFACTOR = 10.0f; + public final static float EAXLISTENER_DEFAULTROOMROLLOFFFACTOR = 0.0f; + + public final static float EAXLISTENER_MINDECAYTIME = 0.1f; + public final static float EAXLISTENER_MAXDECAYTIME = 20.0f; + public final static float EAXLISTENER_DEFAULTDECAYTIME = 1.49f; + + public final static float EAXLISTENER_MINDECAYHFRATIO = 0.1f; + public final static float EAXLISTENER_MAXDECAYHFRATIO = 2.0f; + public final static float EAXLISTENER_DEFAULTDECAYHFRATIO = 0.83f; + + public final static int EAXLISTENER_MINREFLECTIONS = -10000; + public final static int EAXLISTENER_MAXREFLECTIONS = 1000; + public final static int EAXLISTENER_DEFAULTREFLECTIONS = -2602; + + public final static float EAXLISTENER_MINREFLECTIONSDELAY = 0.0f; + public final static float EAXLISTENER_MAXREFLECTIONSDELAY = 0.3f; + public final static float EAXLISTENER_DEFAULTREFLECTIONSDELAY = 0.007f; + + public final static int EAXLISTENER_MINREVERB = -10000; + public final static int EAXLISTENER_MAXREVERB = 2000; + public final static int EAXLISTENER_DEFAULTREVERB = 200; + + public final static float EAXLISTENER_MINREVERBDELAY = 0.0f; + public final static float EAXLISTENER_MAXREVERBDELAY = 0.1f; + public final static float EAXLISTENER_DEFAULTREVERBDELAY = 0.011f; + + public final static int EAXLISTENER_MINENVIRONMENT = 0; + public final static int EAXLISTENER_MAXENVIRONMENT = EAX_ENVIRONMENT_COUNT-1; + public final static int EAXLISTENER_DEFAULTENVIRONMENT = EAX_ENVIRONMENT_GENERIC; + + public final static float EAXLISTENER_MINENVIRONMENTSIZE = 1.0f; + public final static float EAXLISTENER_MAXENVIRONMENTSIZE = 100.0f; + public final static float EAXLISTENER_DEFAULTENVIRONMENTSIZE = 7.5f; + + public final static float EAXLISTENER_MINENVIRONMENTDIFFUSION = 0.0f; + public final static float EAXLISTENER_MAXENVIRONMENTDIFFUSION = 1.0f; + public final static float EAXLISTENER_DEFAULTENVIRONMENTDIFFUSION = 1.0f; + + public final static float EAXLISTENER_MINAIRABSORPTIONHF = -100.0f; + public final static float EAXLISTENER_MAXAIRABSORPTIONHF = 0.0f; + public final static float EAXLISTENER_DEFAULTAIRABSORPTIONHF = -5.0f; + + public final static int EAXLISTENER_DEFAULTFLAGS = + EAXLISTENERFLAGS_DECAYTIMESCALE | + EAXLISTENERFLAGS_REFLECTIONSSCALE | + EAXLISTENERFLAGS_REFLECTIONSDELAYSCALE | + EAXLISTENERFLAGS_REVERBSCALE | + EAXLISTENERFLAGS_REVERBDELAYSCALE | + EAXLISTENERFLAGS_DECAYHFLIMIT; + + public final static int DSPROPERTY_EAXBUFFER_NONE = 0; + public final static int DSPROPERTY_EAXBUFFER_ALLPARAMETERS = 1; + public final static int DSPROPERTY_EAXBUFFER_DIRECT = 2; + public final static int DSPROPERTY_EAXBUFFER_DIRECTHF = 3; + public final static int DSPROPERTY_EAXBUFFER_ROOM = 4; + public final static int DSPROPERTY_EAXBUFFER_ROOMHF = 5; + public final static int DSPROPERTY_EAXBUFFER_ROOMROLLOFFFACTOR = 6; + public final static int DSPROPERTY_EAXBUFFER_OBSTRUCTION = 7; + public final static int DSPROPERTY_EAXBUFFER_OBSTRUCTIONLFRATIO = 8; + public final static int DSPROPERTY_EAXBUFFER_OCCLUSION = 9; + public final static int DSPROPERTY_EAXBUFFER_OCCLUSIONLFRATIO = 10; + public final static int DSPROPERTY_EAXBUFFER_OCCLUSIONROOMRATIO = 11; + public final static int DSPROPERTY_EAXBUFFER_OUTSIDEVOLUMEHF = 13; + public final static int DSPROPERTY_EAXBUFFER_AIRABSORPTIONFACTOR = 14; + public final static int DSPROPERTY_EAXBUFFER_FLAGS = 15; + +// OR these flags with property id + /** changes take effect immediately */ + public final static int DSPROPERTY_EAXBUFFER_IMMEDIATE = 0x00000000; + /** changes take effect later */ + public final static int DSPROPERTY_EAXBUFFER_DEFERRED = 0x80000000; + public final static int DSPROPERTY_EAXBUFFER_COMMITDEFERREDSETTINGS = + DSPROPERTY_EAXBUFFER_NONE | + DSPROPERTY_EAXBUFFER_IMMEDIATE; + + +// Used by DSPROPERTY_EAXBUFFER_FLAGS +// TRUE: value is computed automatically - property is an offset +// FALSE: value is used directly +// +// Note: The number and order of flags may change in future EAX versions. +// To insure future compatibility, use flag defines as follows: +// myFlags = EAXBUFFERFLAGS_DIRECTHFAUTO | EAXBUFFERFLAGS_ROOMAUTO; +// instead of: +// myFlags = 0x00000003; +// + /** affects DSPROPERTY_EAXBUFFER_DIRECTHF */ + public final static int EAXBUFFERFLAGS_DIRECTHFAUTO = 0x00000001; + /** affects DSPROPERTY_EAXBUFFER_ROOM */ + public final static int EAXBUFFERFLAGS_ROOMAUTO = 0x00000002; + /** affects DSPROPERTY_EAXBUFFER_ROOMHF */ + public final static int EAXBUFFERFLAGS_ROOMHFAUTO = 0x00000004; + /** reserved future use */ + public final static int EAXBUFFERFLAGS_RESERVED = 0xFFFFFFF8; + +// property ranges and defaults: + + public final static int EAXBUFFER_MINDIRECT = (-10000); + public final static int EAXBUFFER_MAXDIRECT = 1000; + public final static int EAXBUFFER_DEFAULTDIRECT = 0; + + public final static int EAXBUFFER_MINDIRECTHF = (-10000); + public final static int EAXBUFFER_MAXDIRECTHF = 0; + public final static int EAXBUFFER_DEFAULTDIRECTHF = 0; + + public final static int EAXBUFFER_MINROOM = (-10000); + public final static int EAXBUFFER_MAXROOM = 1000; + public final static int EAXBUFFER_DEFAULTROOM = 0; + + public final static int EAXBUFFER_MINROOMHF = (-10000); + public final static int EAXBUFFER_MAXROOMHF = 0; + public final static int EAXBUFFER_DEFAULTROOMHF = 0; + + public final static float EAXBUFFER_MINROOMROLLOFFFACTOR = 0.0f; + public final static float EAXBUFFER_MAXROOMROLLOFFFACTOR = 10.f; + public final static float EAXBUFFER_DEFAULTROOMROLLOFFFACTOR = 0.0f; + + public final static int EAXBUFFER_MINOBSTRUCTION = (-10000); + public final static int EAXBUFFER_MAXOBSTRUCTION = 0; + public final static int EAXBUFFER_DEFAULTOBSTRUCTION = 0; + + public final static float EAXBUFFER_MINOBSTRUCTIONLFRATIO = 0.0f; + public final static float EAXBUFFER_MAXOBSTRUCTIONLFRATIO = 1.0f; + public final static float EAXBUFFER_DEFAULTOBSTRUCTIONLFRATIO = 0.0f; + + public final static int EAXBUFFER_MINOCCLUSION = (-10000); + public final static int EAXBUFFER_MAXOCCLUSION = 0; + public final static int EAXBUFFER_DEFAULTOCCLUSION = 0; + + public final static float EAXBUFFER_MINOCCLUSIONLFRATIO = 0.0f; + public final static float EAXBUFFER_MAXOCCLUSIONLFRATIO = 1.0f; + public final static float EAXBUFFER_DEFAULTOCCLUSIONLFRATIO = 0.25f; + + public final static float EAXBUFFER_MINOCCLUSIONROOMRATIO = 0.0f; + public final static float EAXBUFFER_MAXOCCLUSIONROOMRATIO = 10.0f; + public final static float EAXBUFFER_DEFAULTOCCLUSIONROOMRATIO = 0.5f; + + public final static int EAXBUFFER_MINOUTSIDEVOLUMEHF = (-10000); + public final static int EAXBUFFER_MAXOUTSIDEVOLUMEHF = 0; + public final static int EAXBUFFER_DEFAULTOUTSIDEVOLUMEHF = 0; + + public final static float EAXBUFFER_MINAIRABSORPTIONFACTOR = 0.0f; + public final static float EAXBUFFER_MAXAIRABSORPTIONFACTOR = 10.0f; + public final static float EAXBUFFER_DEFAULTAIRABSORPTIONFACTOR = 1.0f; + + public final static int EAXBUFFER_DEFAULTFLAGS = + EAXBUFFERFLAGS_DIRECTHFAUTO | + EAXBUFFERFLAGS_ROOMAUTO | + EAXBUFFERFLAGS_ROOMHFAUTO; + +// Material transmission presets +// 3 values in this order: +// 1: occlusion (or obstruction) +// 2: occlusion LF Ratio (or obstruction LF Ratio) +// 3: occlusion Room Ratio + +// Single window material preset + public final static int EAX_MATERIAL_SINGLEWINDOW = (-2800); + public final static float EAX_MATERIAL_SINGLEWINDOWLF = 0.71f; + public final static float EAX_MATERIAL_SINGLEWINDOWROOMRATIO = 0.43f; + +// Double window material preset + public final static int EAX_MATERIAL_DOUBLEWINDOW = (-5000); + public final static float EAX_MATERIAL_DOUBLEWINDOWHF = 0.40f; + public final static float EAX_MATERIAL_DOUBLEWINDOWROOMRATIO = 0.24f; + +// Thin door material preset + public final static int EAX_MATERIAL_THINDOOR = (-1800); + public final static float EAX_MATERIAL_THINDOORLF = 0.66f; + public final static float EAX_MATERIAL_THINDOORROOMRATIO = 0.66f; + +// Thick door material preset + public final static int EAX_MATERIAL_THICKDOOR = (-4400); + public final static float EAX_MATERIAL_THICKDOORLF = 0.64f; + public final static float EAX_MATERIAL_THICKDOORROOMRTATION = 0.27f; + +// Wood wall material preset + public final static int EAX_MATERIAL_WOODWALL = (-4000); + public final static float EAX_MATERIAL_WOODWALLLF = 0.50f; + public final static float EAX_MATERIAL_WOODWALLROOMRATIO = 0.30f; + +// Brick wall material preset + public final static int EAX_MATERIAL_BRICKWALL = (-5000); + public final static float EAX_MATERIAL_BRICKWALLLF = 0.60f; + public final static float EAX_MATERIAL_BRICKWALLROOMRATIO = 0.24f; + +// Stone wall material preset + public final static int EAX_MATERIAL_STONEWALL = (-6000); + public final static float EAX_MATERIAL_STONEWALLLF = 0.68f; + public final static float EAX_MATERIAL_STONEWALLROOMRATIO = 0.20f; + +// Curtain material preset + public final static int EAX_MATERIAL_CURTAIN = (-1200); + public final static float EAX_MATERIAL_CURTAINLF = 0.15f; + public final static float EAX_MATERIAL_CURTAINROOMRATIO = 1.00f; +} \ No newline at end of file diff --git a/src/java/com/jogamp/openal/eax/EAXFactory.java b/src/java/com/jogamp/openal/eax/EAXFactory.java new file mode 100644 index 0000000..9aa2e9d --- /dev/null +++ b/src/java/com/jogamp/openal/eax/EAXFactory.java @@ -0,0 +1,54 @@ +/** +* Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions are met: +* +* -Redistribution of source code must retain the above copyright notice, +* this list of conditions and the following disclaimer. +* +* -Redistribution 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 Sun Microsystems, Inc. or the names of contributors may +* be used to endorse or promote products derived from this software without +* specific prior written permission. +* +* This software is provided "AS IS," without a warranty of any kind. +* ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING +* ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR +* NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND ITS +* LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A +* RESULT OF USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. +* IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT +* OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR +* PUNITIVE DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, +* ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF SUN HAS +* BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. +* +* You acknowledge that this software is not designed or intended for use in the +* design, construction, operation or maintenance of any nuclear facility. +*/ + +package com.jogamp.openal.eax; + +/** + * @author Athomas Goldberg + * + */ +public final class EAXFactory { + private static int SOURCE_GUID; + private static int LISTENER_GUID; + + private static EAX eax; + + private static native void init(); + public static EAX getEAX() { + if(eax == null) { + init(); + eax = new EAX(SOURCE_GUID, LISTENER_GUID); + } + return eax; + } +} diff --git a/src/java/com/jogamp/openal/impl/ALProcAddressLookup.java b/src/java/com/jogamp/openal/impl/ALProcAddressLookup.java new file mode 100755 index 0000000..1b6407a --- /dev/null +++ b/src/java/com/jogamp/openal/impl/ALProcAddressLookup.java @@ -0,0 +1,162 @@ +/** + * Copyright (c) 2003-2005 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * -Redistribution of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * -Redistribution 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 Sun Microsystems, Inc. or the names of contributors may + * be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. + * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING + * ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR + * NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND ITS + * LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A + * RESULT OF USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. + * IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT + * OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR + * PUNITIVE DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF SUN HAS + * BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed or intended for use in the + * design, construction, operation or maintenance of any nuclear facility. + */ + +package com.jogamp.openal.impl; + +import java.lang.reflect.Field; + +import com.jogamp.openal.*; +import com.jogamp.gluegen.runtime.*; +import com.jogamp.openal.impl.ALCProcAddressTable; +import com.jogamp.openal.impl.ALImpl; +import com.jogamp.openal.impl.ALProcAddressTable; + +/** Helper class for managing OpenAL-related proc address tables. */ + +public class ALProcAddressLookup { + private static final ALProcAddressTable alTable = new ALProcAddressTable(); + private static volatile boolean alTableInitialized = false; + private static final ALCProcAddressTable alcTable = new ALCProcAddressTable(); + private static volatile boolean alcTableInitialized = false; + private static final DynamicLookup lookup = new DynamicLookup(); + private static volatile NativeLibrary openAL = null; + + static class DynamicLookup implements DynamicLookupHelper { + public long dynamicLookupFunction(String functionName) { + // At some point this may require an OpenAL context to be + // current as we will actually use alGetProcAddress. Since + // this routine is currently broken and there are no + // per-context function pointers anyway we could actually do + // this work anywhere. + if (openAL == null) { + // We choose not to search the system path first because we + // bundle a very recent version of OpenAL which we would like + // to override existing installations + openAL = NativeLibrary.open("OpenAL32", "openal", "OpenAL", + false, + ALProcAddressLookup.class.getClassLoader()); + if (openAL == null) { + throw new RuntimeException("Unable to find and load OpenAL library"); + } + } + return openAL.dynamicLookupFunction(functionName); + } + } + + public static void resetALProcAddressTable() { + if (!alTableInitialized) { + synchronized (ALProcAddressLookup.class) { + if (!alTableInitialized) { + // At some point this may require an OpenAL context to be + // current as we will actually use alGetProcAddress. Since + // this routine is currently broken and there are no + // per-context function pointers anyway we could actually do + // this work anywhere. We should also in theory have + // per-ALcontext ALProcAddressTables and per-ALCdevice + // ALCProcAddressTables. + ProcAddressHelper.resetProcAddressTable(alTable, lookup); + + // The above only manages to find addresses for the core OpenAL + // functions. The below uses alGetProcAddress() to find the addresses + // of extensions such as EFX, just as in the C++ examples of the + // OpenAL 1.1 SDK. + useALGetProcAddress(); + + alTableInitialized = true; + } + } + } + } + + public static void resetALCProcAddressTable() { + if (!alcTableInitialized) { + synchronized (ALProcAddressLookup.class) { + if (!alcTableInitialized) { + // At some point this may require an OpenAL device to be + // created as we will actually use alcGetProcAddress. Since + // this routine is currently broken and there are no + // per-device function pointers anyway we could actually do + // this work anywhere. We should also in theory have + // per-ALcontext ALProcAddressTables and per-ALCdevice + // ALCProcAddressTables. + ProcAddressHelper.resetProcAddressTable(alcTable, lookup); + alcTableInitialized = true; + } + } + } + } + + public static ALProcAddressTable getALProcAddressTable() { + return alTable; + } + + public static ALCProcAddressTable getALCProcAddressTable() { + return alcTable; + } + + + /** + * Retrieves the values of the OpenAL functions using alGetProcAddress(). + */ + private static void useALGetProcAddress() { + String addrOfPrefix = "_addressof_"; + ALImpl al = (ALImpl) ALFactory.getAL(); + + Field[] fields = ALProcAddressTable.class.getFields(); + for (int i = 0; i < fields.length; i++) { + Field field = fields[i]; + + // Skip non-address fields + String fieldname = field.getName(); + if (!fieldname.startsWith(addrOfPrefix)) { + continue; + } + try { + String functionname = fieldname.substring(addrOfPrefix.length()); + long fieldval = field.getLong(alTable); + + // Skip fields which have already been valued + if (fieldval != 0) { + continue; + } + + // Get the address + long procAddressVal = al.alGetProcAddress(functionname); + field.setLong(alTable, procAddressVal); + } + catch (Exception ex) { + throw new RuntimeException("Unable to repopulate ALProcAddressTable values", ex); + } + } + } +} diff --git a/src/java/com/jogamp/openal/impl/NativeLibLoader.java b/src/java/com/jogamp/openal/impl/NativeLibLoader.java new file mode 100755 index 0000000..d4ac106 --- /dev/null +++ b/src/java/com/jogamp/openal/impl/NativeLibLoader.java @@ -0,0 +1,114 @@ +/* + * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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 Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed or intended for use + * in the design, construction, operation or maintenance of any nuclear + * facility. + */ + +package com.jogamp.openal.impl; + +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.security.*; + +import com.jogamp.gluegen.runtime.*; + +public class NativeLibLoader { + private static volatile boolean loadingEnabled = true; + private static volatile boolean didLoading; + + private NativeLibLoader() {} + + public static void disableLoading() { + loadingEnabled = false; + } + + public static void enableLoading() { + loadingEnabled = true; + } + + public static void load() { + if (!didLoading && loadingEnabled) { + synchronized (NativeLibLoader.class) { + if (!didLoading && loadingEnabled) { + didLoading = true; + AccessController.doPrivileged(new PrivilegedAction() { + public Object run() { + // Workaround for problem in OpenAL32.dll, which is actually + // the "wrapper" DLL which looks for real OpenAL + // implementations like nvopenal.dll and "*oal.dll". + // joal.dll matches this wildcard and a bug in OpenAL32.dll + // causes a call through a null function pointer. + loadLibraryInternal("joal_native"); + + // Workaround for 4845371. + // Make sure the first reference to the JNI GetDirectBufferAddress is done + // from a privileged context so the VM's internal class lookups will succeed. + // FIXME: need to figure out an appropriate entry point to call for JOAL + // JAWT jawt = new JAWT(); + // JAWTFactory.JAWT_GetAWT(jawt); + + return null; + } + }); + } + } + } + } + + private static void loadLibraryInternal(String libraryName) { + String sunAppletLauncher = System.getProperty("sun.jnlp.applet.launcher"); + boolean usingJNLPAppletLauncher = Boolean.valueOf(sunAppletLauncher).booleanValue(); + + if (usingJNLPAppletLauncher) { + try { + Class jnlpAppletLauncherClass = Class.forName("org.jdesktop.applet.util.JNLPAppletLauncher"); + Method jnlpLoadLibraryMethod = jnlpAppletLauncherClass.getDeclaredMethod("loadLibrary", new Class[] { String.class }); + jnlpLoadLibraryMethod.invoke(null, new Object[] { libraryName }); + } catch (Exception e) { + Throwable t = e; + if (t instanceof InvocationTargetException) { + t = ((InvocationTargetException) t).getTargetException(); + } + if (t instanceof Error) + throw (Error) t; + if (t instanceof RuntimeException) { + throw (RuntimeException) t; + } + // Throw UnsatisfiedLinkError for best compatibility with System.loadLibrary() + throw (UnsatisfiedLinkError) new UnsatisfiedLinkError().initCause(e); + } + } else { + System.loadLibrary(libraryName); + } + } +} diff --git a/src/java/com/jogamp/openal/sound3d/AudioSystem3D.java b/src/java/com/jogamp/openal/sound3d/AudioSystem3D.java new file mode 100644 index 0000000..1070d21 --- /dev/null +++ b/src/java/com/jogamp/openal/sound3d/AudioSystem3D.java @@ -0,0 +1,273 @@ +/** + * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * -Redistribution of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * -Redistribution 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 Sun Microsystems, Inc. or the names of contributors may + * be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. + * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING + * ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR + * NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND ITS + * LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A + * RESULT OF USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. + * IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT + * OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR + * PUNITIVE DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF SUN HAS + * BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed or intended for use in the + * design, construction, operation or maintenance of any nuclear facility. + */ + +package com.jogamp.openal.sound3d; + +import com.jogamp.openal.*; +import com.jogamp.openal.util.WAVData; +import com.jogamp.openal.util.WAVLoader; + +import java.io.*; + +import javax.sound.sampled.UnsupportedAudioFileException; + + +/** + * The AudioSystem3D class provides a set of methods for creating and + * manipulating a 3D audio environment. + * + * @author Athomas Goldberg + */ +public class AudioSystem3D { + private static AL al; + private static ALC alc; + private static Listener listener; + + /** + * Iniitalize the Sound3D environment. This must be called before + * other methods in the class can be used. + */ + public static void init() throws ALException { + al = ALFactory.getAL(); + alc = ALFactory.getALC(); + } + + /** + * Creates a new Sound3D Context for a specified device. + * + * @param device The device the Context is being created for. + * + * @return The new Sound3D context. + */ + public static Context createContext(Device device) { + Context result = null; + ALCcontext realContext = alc.alcCreateContext(device.realDevice, null); + result = new Context(alc, realContext, device); + return result; + } + + /** + * Makes the specified context the current context. + * + * @param context the context to make current. + */ + public static void makeContextCurrent(Context context) { + ALCcontext realContext = null; + + if (context != null) { + realContext = context.realContext; + } + + alc.alcMakeContextCurrent(realContext); + } + + /** + * Opens the specifified audio device. + * + * @param deviceName The specified device name, On windows this will be + * DirectSound3D. We will be automating device discovery in upcoming versions + * of this class. + * + * @return The device described by the specifed name. + */ + public static Device openDevice(String deviceName) { + Device result = null; + ALCdevice realDevice = alc.alcOpenDevice(deviceName); + result = new Device(alc, realDevice); + + return result; + } + + /** + * Generate an array of Sound3D buffers. + * + * @param numBuffers The number of Sound3D buffers to generate. + * + * @return an array of (initially enpty) Sound3D buffers. + */ + public static Buffer[] generateBuffers(int numBuffers) { + Buffer[] result = new Buffer[numBuffers]; + int[] arr = new int[numBuffers]; + al.alGenBuffers(numBuffers, arr, 0); + + for (int i = 0; i < numBuffers; i++) { + result[i] = new Buffer(al, arr[i]); + } + + return result; + } + + /** + * Loads a Sound3D buffer with the specified audio file. + * + * @param filename the name of the file to load. + * + * @return a new Sound3D buffer containing the audio data from the + * specified file. + * + * @throws IOException If the file cannot be found or some other IO error + * occurs. + * @throws UnsupportedAudioFileException If the format of the audio data is + * not supported + */ + public static Buffer loadBuffer(String filename) + throws IOException, UnsupportedAudioFileException { + Buffer result; + Buffer[] tmp = generateBuffers(1); + result = tmp[0]; + + WAVData wd = WAVLoader.loadFromFile(filename); + result.configure(wd.data, wd.format, wd.freq); + + return result; + } + + /** + * Loads a Sound3D buffer with the specified audio file. + * + * @param stream contains the stream associated with the audio file. + * + * @return a new Sound3D buffer containing the audio data from the + * passed stream. + * + * @throws IOException If the stream cannot be read or some other IO error + * occurs. + * @throws UnsupportedAudioFileException If the format of the audio data is + * not supported + */ + public static Buffer loadBuffer(InputStream stream) + throws IOException, UnsupportedAudioFileException { + Buffer result; + Buffer[] tmp = generateBuffers(1); + result = tmp[0]; + + if (!(stream instanceof BufferedInputStream)) { + stream = new BufferedInputStream(stream); + } + WAVData wd = WAVLoader.loadFromStream(stream); + + result.configure(wd.data, wd.format, wd.freq); + + return result; + } + + /** + * Loads a Sound3D Source with the specified audio file. This is + * functionally equivalent to generateSource(loadBuffer(fileName)); + * + * @param filename the name of the file to load. + * + * @return a new Sound3D Source containing the audio data from the + * specified file. + * + * @throws IOException If the file cannot be found or some other IO error + * occurs. + * @throws UnsupportedAudioFileException If the format of the audio data is + * not supported + */ + public static Source loadSource(String filename) + throws IOException, UnsupportedAudioFileException { + Buffer buffer = loadBuffer(filename); + + return generateSource(buffer); + } + + /** + * Loads a Sound3D Source with the specified audio stream. This is + * functionally equivalent to generateSource(loadBuffer(stream)); + * + * @param stream contains the stream associated with the audio file. + * + * @return a new Sound3D Source containing the audio data from the + * passed stream. + * + * @throws IOException If the file cannot be found or some other IO error + * occurs. + * @throws UnsupportedAudioFileException If the format of the audio data is + * not supported + */ + public static Source loadSource(InputStream stream) + throws IOException, UnsupportedAudioFileException { + Buffer buffer = loadBuffer(stream); + + return generateSource(buffer); + } + + /** + * Generates a set of uninitialized Source3D sources + * + * @param numSources the number of Sound3D sources to generate. + * + * @return an array of uninitialized sources. + */ + public static Source[] generateSources(int numSources) { + Source[] result = new Source[numSources]; + int[] arr = new int[numSources]; + al.alGenSources(numSources, arr, 0); + + for (int i = 0; i < numSources; i++) { + result[i] = new Source(al, arr[i]); + } + + return result; + } + + /** + * Generate a Sound3D source from an initialized Buffer. + * + * @param buff The buffer to generate the source from. + * + * @return the newly generated Source. + */ + public static Source generateSource(Buffer buff) { + Source result = null; + Source[] tmp = generateSources(1); + result = tmp[0]; + result.setBuffer(buff); + + return result; + } + + /** + * Get the listener object associated with this Sound3D environment. + * + * @return The listener object. + */ + public static Listener getListener() { + if (listener == null) { + listener = new Listener(al); + } + + return listener; + } +} diff --git a/src/java/com/jogamp/openal/sound3d/Buffer.java b/src/java/com/jogamp/openal/sound3d/Buffer.java new file mode 100644 index 0000000..54d120e --- /dev/null +++ b/src/java/com/jogamp/openal/sound3d/Buffer.java @@ -0,0 +1,144 @@ +/** +* Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions are met: +* +* -Redistribution of source code must retain the above copyright notice, +* this list of conditions and the following disclaimer. +* +* -Redistribution 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 Sun Microsystems, Inc. or the names of contributors may +* be used to endorse or promote products derived from this software without +* specific prior written permission. +* +* This software is provided "AS IS," without a warranty of any kind. +* ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING +* ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR +* NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND ITS +* LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A +* RESULT OF USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. +* IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT +* OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR +* PUNITIVE DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, +* ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF SUN HAS +* BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. +* +* You acknowledge that this software is not designed or intended for use in the +* design, construction, operation or maintenance of any nuclear facility. +*/ + +package com.jogamp.openal.sound3d; + +import com.jogamp.openal.AL; + +import java.nio.ByteBuffer; + + +/** + * The Sound3D Buffer is a container for audio data used in the Sound3D + * environment. + * + * @author Athomas Goldberg + */ +public class Buffer { + public final static int FORMAT_MONO8 = AL.AL_FORMAT_MONO8; + + public final static int FORMAT_MONO16 = AL.AL_FORMAT_MONO16; + + public final static int FORMAT_STEREO8 = AL.AL_FORMAT_STEREO8; + + public final static int FORMAT_STEREO16 = AL.AL_FORMAT_STEREO16; + final int bufferID; + private ByteBuffer data; + private boolean isConfigured = false; + private final AL al; + + Buffer(AL al, int bufferID) { + this.bufferID = bufferID; + this.al = al; + } + + /** + * Configure the Sound3D buffer + * + * @param data the raw audio data + * @param format the format of the data: FORMAT_MONO8, FORMAT_MONO16, + * FORMAT_STEREO8 and FORMAT_STEREO16 + * @param freq the frequency of the data + */ + public void configure(ByteBuffer data, int format, int freq) { + if (!isConfigured) { + this.data = data; + al.alBufferData(bufferID, format, data, data.capacity(), freq); + } + } + + /** + * Delete this buffer, and free its resources. + */ + public void delete() { + data = null; + al.alDeleteBuffers(1, new int[] { bufferID }, 0); + } + + /** + * Get the bit-depth of the data, (8 or 16) + * + * @return the bit-depth of the data + */ + public int getBitDepth() { + int[] i = new int[1]; + al.alGetBufferi(bufferID, AL.AL_BITS, i, 0); + + return i[0]; + } + + /** + * Get the number of channels of the data (1-Mono, 2-Stereo) + * + * @return the number of audio channels. + */ + public int getNumChannels() { + int[] i = new int[1]; + al.alGetBufferi(bufferID, AL.AL_CHANNELS, i, 0); + + return i[0]; + } + + /** + * Gets the raw data contained in this buffer. + * + * @return the raw buffer data. + */ + public ByteBuffer getData() { + return data; + } + + /** + * Gets the audio frequency of the data contained in this buffer. + * + * @return the frequency of the data + */ + public int getFrequency() { + int[] i = new int[1]; + al.alGetBufferi(bufferID, AL.AL_FREQUENCY, i, 0); + + return i[0]; + } + + /** + * Gets the size (in bytes) of the raw data containe in this buffer. + * + * @return the size of the data. + */ + public int getSize() { + int[] i = new int[1]; + al.alGetBufferi(bufferID, AL.AL_SIZE, i, 0); + + return i[0]; + } +} diff --git a/src/java/com/jogamp/openal/sound3d/Context.java b/src/java/com/jogamp/openal/sound3d/Context.java new file mode 100644 index 0000000..5562153 --- /dev/null +++ b/src/java/com/jogamp/openal/sound3d/Context.java @@ -0,0 +1,77 @@ +/** +* Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions are met: +* +* -Redistribution of source code must retain the above copyright notice, +* this list of conditions and the following disclaimer. +* +* -Redistribution 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 Sun Microsystems, Inc. or the names of contributors may +* be used to endorse or promote products derived from this software without +* specific prior written permission. +* +* This software is provided "AS IS," without a warranty of any kind. +* ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING +* ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR +* NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND ITS +* LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A +* RESULT OF USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. +* IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT +* OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR +* PUNITIVE DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, +* ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF SUN HAS +* BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. +* +* You acknowledge that this software is not designed or intended for use in the +* design, construction, operation or maintenance of any nuclear facility. +*/ + +package com.jogamp.openal.sound3d; + +import com.jogamp.openal.*; + + +/** + * This class provides a Sound3D Context associated with a specified device. + * + * @author Athomas Goldberg + */ +public class Context { + private final ALC alc; + final ALCcontext realContext; + final Device device; + + Context(ALC alc, ALCcontext realContext, Device device) { + this.alc = alc; + this.realContext = realContext; + this.device = device; + } + + /** + * Suspend this context + */ + public void suspend() { + alc.alcSuspendContext(realContext); + } + + /** + * destroys this context freeing its resources. + */ + public void destroy() { + alc.alcDestroyContext(realContext); + } + + /** + * Gets the device associated with this context. + * + * @return the device associated with this context. + */ + public Device getDevice() { + return device; + } +} diff --git a/src/java/com/jogamp/openal/sound3d/Device.java b/src/java/com/jogamp/openal/sound3d/Device.java new file mode 100644 index 0000000..086d3ad --- /dev/null +++ b/src/java/com/jogamp/openal/sound3d/Device.java @@ -0,0 +1,59 @@ +/** +* Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions are met: +* +* -Redistribution of source code must retain the above copyright notice, +* this list of conditions and the following disclaimer. +* +* -Redistribution 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 Sun Microsystems, Inc. or the names of contributors may +* be used to endorse or promote products derived from this software without +* specific prior written permission. +* +* This software is provided "AS IS," without a warranty of any kind. +* ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING +* ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR +* NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND ITS +* LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A +* RESULT OF USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. +* IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT +* OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR +* PUNITIVE DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, +* ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF SUN HAS +* BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. +* +* You acknowledge that this software is not designed or intended for use in the +* design, construction, operation or maintenance of any nuclear facility. +*/ + +package com.jogamp.openal.sound3d; + +import com.jogamp.openal.*; + + +/** + * This class provides a handle to a specific audio device. + * + * @author Athomas Goldberg + */ +public class Device { + private final ALC alc; + final ALCdevice realDevice; + + Device(ALC alc, ALCdevice realDevice) { + this.alc = alc; + this.realDevice = realDevice; + } + + /** + * closes the device, freeing its resources. + */ + public void close() { + alc.alcCloseDevice(realDevice); + } +} diff --git a/src/java/com/jogamp/openal/sound3d/Listener.java b/src/java/com/jogamp/openal/sound3d/Listener.java new file mode 100644 index 0000000..fe8b869 --- /dev/null +++ b/src/java/com/jogamp/openal/sound3d/Listener.java @@ -0,0 +1,171 @@ +/** +* Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions are met: +* +* -Redistribution of source code must retain the above copyright notice, +* this list of conditions and the following disclaimer. +* +* -Redistribution 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 Sun Microsystems, Inc. or the names of contributors may +* be used to endorse or promote products derived from this software without +* specific prior written permission. +* +* This software is provided "AS IS," without a warranty of any kind. +* ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING +* ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR +* NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND ITS +* LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A +* RESULT OF USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. +* IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT +* OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR +* PUNITIVE DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, +* ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF SUN HAS +* BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. +* +* You acknowledge that this software is not designed or intended for use in the +* design, construction, operation or maintenance of any nuclear facility. +*/ + +package com.jogamp.openal.sound3d; + +import com.jogamp.openal.AL; + + +/** + * This class represents the human listener in the Sound3D environment. It + * provides methods for controlling the position, orientation as well as other + * properties associated with the listener. + * + * @author Athomas Goldberg + */ +public class Listener { + private final AL al; + + Listener(AL al) { + this.al = al; + } + + /** + * Sets the Gain, or volume of the audio in the environment relative to the + * listener + * + * @param gain the gain, or volume + */ + public void setGain(float gain) { + al.alListenerf(AL.AL_GAIN, gain); + } + + /** + * Gets the value of the gain, or volume of the audio in the environment + * relative to the listener. + * + * @return the gain value. + */ + public float getGain() { + float[] f = new float[1]; + al.alGetListenerf(AL.AL_GAIN, f, 0); + + return f[0]; + } + + /** + * Sets the position in (x-y-z coordinates) of the Listener in the Sound3D + * environment. + * + * @param x The position of the listener along the X-axis in the Sound3D + * environment + * @param y The position of the listener along the Y-axis in the Sound3D + * environment + * @param z The position of the listener along the Z-axis in the Sound3D + * environment + */ + public void setPosition(float x, float y, float z) { + al.alListener3f(AL.AL_POSITION, x, y, z); + } + + /** + * Sets the position in (x-y-z coordinates) of the Listener in the Sound3D + * environment. + * + * @param position a Vec3f object containing the x,y and z coordinates of + * Listener. + */ + public void setPosition(Vec3f position) { + al.alListener3f(AL.AL_POSITION, position.v1, position.v2, position.v3); + } + + /** + * Gets the position in (x-y-z coordinates) of the Listener in the Sound3D + * environment. + * + * @return a Vec3f object containing the x,y and z coordinates of + * Listener. + */ + public Vec3f getPosition() { + Vec3f result = null; + float[] tmp = new float[3]; + al.alGetListenerfv(AL.AL_POSITION, tmp, 0); + result = new Vec3f(tmp[0], tmp[1], tmp[2]); + + return result; + } + + /** + * Sets the velocity in (x-y-z coordinates) of the Listener in the Sound3D + * environment. Used in determining doppler shift. + * + * @param velocity a Vec3f object containing the velicity in + * x,y and z coordinates of Listener. + */ + public void setVelocity(Vec3f velocity) { + al.alListener3f(AL.AL_VELOCITY, velocity.v1, velocity.v2, velocity.v3); + } + + /** + * Gets the velocity in (x-y-z coordinates) of the Listener in the Sound3D + * environment. Used in determining doppler shift. + * + * @return a Vec3f object containing the velicity in + * x,y and z coordinates of Listener. + */ + public Vec3f getVelocity() { + Vec3f result = null; + float[] tmp = new float[3]; + al.alGetListenerfv(AL.AL_VELOCITY, tmp, 0); + result = new Vec3f(tmp[0], tmp[1], tmp[2]); + + return result; + } + + /** + * Sets the orientation of the Listener in the Sound3D environment. + * Orientation is expressed as "up" and "at" vectors. + * + * @param orientation The first 3 elements of the array should contain + * the x,y,z up-vector, the second 3 elements should contain the x,z,z + * look-at vector. + */ + public void setOrientation(float[] orientation) { + al.alListenerfv(AL.AL_ORIENTATION, orientation, 0); + } + + /** + * Gets the orientation of the Listener in the Sound3D environment. + * Orientation is expressed as "up" and "at" vectors. + * + * @return an array containing the orientation of the listener. + * The first 3 elements of the array contain + * the x,y,z up-vector, the second 3 elements contain the x,z,z + * look-at vector. + */ + public float[] getOrientation() { + float[] tmp = new float[6]; + al.alGetListenerfv(AL.AL_ORIENTATION, tmp, 0); + return tmp; + } +} diff --git a/src/java/com/jogamp/openal/sound3d/Source.java b/src/java/com/jogamp/openal/sound3d/Source.java new file mode 100644 index 0000000..2e2f512 --- /dev/null +++ b/src/java/com/jogamp/openal/sound3d/Source.java @@ -0,0 +1,508 @@ +/** +* Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions are met: +* +* -Redistribution of source code must retain the above copyright notice, +* this list of conditions and the following disclaimer. +* +* -Redistribution 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 Sun Microsystems, Inc. or the names of contributors may +* be used to endorse or promote products derived from this software without +* specific prior written permission. +* +* This software is provided "AS IS," without a warranty of any kind. +* ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING +* ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR +* NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND ITS +* LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A +* RESULT OF USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. +* IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT +* OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR +* PUNITIVE DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, +* ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF SUN HAS +* BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. +* +* You acknowledge that this software is not designed or intended for use in the +* design, construction, operation or maintenance of any nuclear facility. +*/ + +package com.jogamp.openal.sound3d; + +import com.jogamp.openal.AL; + +/** + * This class is used to represent sound-producing objects in the Sound3D + * environment. It contains methods for setting the position, direction, pitch, + * gain and other properties along with methods for starting, pausing, rewinding + * and stopping sudio projecting from a source. + * + * @author Athomas Goldberg + */ +public final class Source { + private final AL al; + private final int sourceID; + private Buffer buffer; + + Source(AL al, int sourceID) { + this.al = al; + this.sourceID = sourceID; + } + + /** + * Beginning playing the audio in this source. + */ + public void play() { + al.alSourcePlay(sourceID); + } + + /** + * pauses the audio in this Source. + */ + public void pause() { + al.alSourcePause(sourceID); + } + + /** + * Stops the audio in this Source + */ + public void stop() { + al.alSourceStop(sourceID); + } + + /** + * Rewinds the audio in this source + */ + public void rewind() { + al.alSourceRewind(sourceID); + } + + /** + * Delete this source, freeing its resources. + */ + public void delete() { + al.alDeleteSources(1, new int[] { sourceID }, 0); + } + + /** + * Sets the pitch of the audio on this source. The pitch may be modified + * without altering the playback speed of the audio. + * + * @param pitch the pitch value of this source. + */ + public void setPitch(float pitch) { + al.alSourcef(sourceID, AL.AL_PITCH, pitch); + } + + /** + * Gets the pitch of the audio on this source. The pitch may be modified + * without altering the playback speed of the audio. + * + * @return the pitch value of this source. + */ + public float getPitch() { + float[] result = new float[1]; + al.alGetSourcef(sourceID, AL.AL_PITCH, result, 0); + + return result[0]; + } + + /** + * Sets the gain of the audio on this source. This can be used to contro + * the volume of the source. + * + * @param gain the gain of the audio on this source + */ + public void setGain(float gain) { + al.alSourcef(sourceID, AL.AL_GAIN, gain); + } + + /** + * Gets the gain of the audio on this source. This can be used to contro + * the volume of the source. + * + * @return the gain of the audio on this source + */ + public float getGain() { + float[] result = new float[1]; + al.alGetSourcef(sourceID, AL.AL_GAIN, result, 0); + + return result[0]; + } + + /** + * Sets the max distance where there will no longer be any attenuation of + * the source. + * + * @param maxDistance the max ditance for source attentuation. + */ + public void setMaxDistance(float maxDistance) { + al.alSourcef(sourceID, AL.AL_MAX_DISTANCE, maxDistance); + } + + /** + * Gets the max distance where there will no longer be any attenuation of + * the source. + * + * @return the max ditance for source attentuation. + */ + public float getMaxDistance() { + float[] result = new float[1]; + al.alGetSourcef(sourceID, AL.AL_MAX_DISTANCE, result, 0); + + return result[0]; + } + + /** + * Sets the rolloff rate of the source. The default value is 1.0 + * + * @param rolloffFactor the rolloff rate of the source. + */ + public void setRolloffFactor(float rolloffFactor) { + al.alSourcef(sourceID, AL.AL_ROLLOFF_FACTOR, rolloffFactor); + } + + /** + * Gets the rolloff rate of the source. The default value is 1.0 + * + * @return the rolloff rate of the source. + */ + public float getRolloffFactor() { + float[] result = new float[1]; + al.alGetSourcef(sourceID, AL.AL_ROLLOFF_FACTOR, result, 0); + + return result[0]; + } + + /** + * Sets the distance under which the volume for the source would normally + * drop by half, before being influenced by rolloff factor or max distance. + * + * @param referenceDistance the reference distance for the source. + */ + public void setReferenceDistance(float referenceDistance) { + al.alSourcef(sourceID, AL.AL_REFERENCE_DISTANCE, referenceDistance); + } + + /** + * Gets the distance under which the volume for the source would normally + * drop by half, before being influenced by rolloff factor or max distance. + * + * @return the reference distance for the source. + */ + public float getReferenceDistance() { + float[] result = new float[1]; + al.alGetSourcef(sourceID, AL.AL_REFERENCE_DISTANCE, result, 0); + + return result[0]; + } + + /** + * Sets the minimum gain for this source. + * + * @param minGain the minimum gain for this source. + */ + public void setMinGain(float minGain) { + al.alSourcef(sourceID, AL.AL_MIN_GAIN, minGain); + } + + /** + * Gets the minimum gain for this source. + * + * @return the minimum gain for this source. + */ + public float getMinGain() { + float[] result = new float[1]; + al.alGetSourcef(sourceID, AL.AL_MIN_GAIN, result, 0); + + return result[0]; + } + + /** + * Sets the maximum gain for this source. + * + * @param maxGain the maximum gain for this source + */ + public void setMaxGain(float maxGain) { + al.alSourcef(sourceID, AL.AL_MAX_GAIN, maxGain); + } + + /** + * SGets the maximum gain for this source. + * + * @return the maximum gain for this source + */ + public float getMaxGain() { + float[] result = new float[1]; + al.alGetSourcef(sourceID, AL.AL_MAX_GAIN, result, 0); + + return result[0]; + } + + /** + * Sets the gain when outside the oriented cone. + * + * @param coneOuterGain the gain when outside the oriented cone. + */ + public void setConeOuterGain(float coneOuterGain) { + al.alSourcef(sourceID, AL.AL_CONE_OUTER_GAIN, coneOuterGain); + } + + /** + * Gets the gain when outside the oriented cone. + * + * @return the gain when outside the oriented cone. + */ + public float getConeOuterGain() { + float[] result = new float[1]; + al.alGetSourcef(sourceID, AL.AL_CONE_OUTER_GAIN, result, 0); + + return result[0]; + } + + /** + * Sets the x,y,z position of the source. + * + * @param position a Vec3f object containing the x,y,z position of the + * source. + */ + public void setPosition(Vec3f position) { + al.alSource3f( + sourceID, + AL.AL_POSITION, + position.v1, + position.v2, + position.v3); + } + + /** + * Sets the x,y,z position of the source. + * + * @param x the x position of the source. + * @param y the y position of the source. + * @param z the z position of the source. + */ + public void setPosition(float x, float y, float z) { + al.alSource3f(sourceID, AL.AL_POSITION, x, y, z); + } + + /** + * Gets the x,y,z position of the source. + * + * @return a Vec3f object containing the x,y,z position of the + * source. + */ + public Vec3f getPosition() { + Vec3f result = null; + float[] pos = new float[3]; + al.alGetSourcefv(sourceID, AL.AL_POSITION, pos, 0); + result = new Vec3f(pos[0], pos[1], pos[2]); + + return result; + } + + /** + * Sets the velocity vector of the source. + * + * @param velocity the velocity vector of the source + */ + public void setVelocity(Vec3f velocity) { + al.alSource3f( + sourceID, + AL.AL_VELOCITY, + velocity.v1, + velocity.v2, + velocity.v3); + } + + /** + * Sets the velocity vector of the source. + * + * @param x the x velocity of the source. + * @param y the y velocity of the source. + * @param z the z velocity of the source. + */ + public void setVelocity(float x, float y, float z) { + al.alSource3f(sourceID, AL.AL_VELOCITY, x, y, z); + } + + /** + * Gets the velocity vector of the source. + * + * @return the velocity vector of the source + */ + public Vec3f getVelocity() { + Vec3f result = null; + float[] vel = new float[3]; + al.alGetSourcefv(sourceID, AL.AL_VELOCITY, vel, 0); + result = new Vec3f(vel[0], vel[1], vel[2]); + + return result; + } + + /** + * Sets the direction vector of the source. + * + * @param direction the direction vector of the source. + */ + public void setDirection(Vec3f direction) { + al.alSource3f( + sourceID, + AL.AL_DIRECTION, + direction.v1, + direction.v2, + direction.v3); + } + + /** + * Sets the direction vector of the source. + * + * @param x the x direction of the source. + * @param y the y direction of the source. + * @param z the z direction of the source. + */ + public void setDirection(float x, float y, float z) { + al.alSource3f(sourceID, AL.AL_DIRECTION, x, y, z); + } + + /** + * Gets the direction vector of the source. + * + * @return the direction vector of the source. + */ + public Vec3f getDirection() { + Vec3f result = null; + float[] dir = new float[3]; + al.alGetSourcefv(sourceID, AL.AL_DIRECTION, dir, 0); + result = new Vec3f(dir[0], dir[1], dir[2]); + + return result; + } + + /** + * Determines if the position of the source is relative to the listener. + * The default is false. + * @param isRelative true if the position of the source is relative + * to the listener, false if the position of the source is relative to the + * world. + */ + public void setSourceRelative(boolean isRelative) { + int rel = isRelative ? 1 : 0; + al.alSourcei(sourceID, AL.AL_SOURCE_RELATIVE, rel); + } + + /** + * Determines if the position of the source is relative to the listener. + * The default is false. + * @return true if the position of the source is relative + * to the listener, false if the position of the source is relative to the + * world. + */ + public boolean isSourceRelative() { + int[] result = new int[1]; + al.alGetSourcei(sourceID, AL.AL_SOURCE_RELATIVE, result, 0); + + return result[0] == 1; + } + + /** + * turns looping on or off. + * + * @param isLooping true-looping is on, false-looping is off + */ + public void setLooping(boolean isLooping) { + int loop = isLooping ? 1 : 0; + al.alSourcei(sourceID, AL.AL_LOOPING, loop); + } + + /** + * indicates whether looping is turned on or off. + * + * @return true-looping is on, false-looping is off + */ + public boolean getLooping() { + boolean result = false; + int[] tmp = new int[1]; + al.alGetSourcei(sourceID, AL.AL_LOOPING, tmp, 0); + return tmp[0] == AL.AL_TRUE; + } + + + /** + * Gets the number of buffers currently queued on this source. + * @return the number of buffers currently queued on this source. + */ + public int getBuffersQueued() { + int[] result = new int[1]; + al.alGetSourcei(sourceID, AL.AL_BUFFERS_QUEUED, result, 0); + + return result[0]; + } + + /** + * Gets the number of buffers already processed on this source. + * @return the number of buffers already processed on this source. + */ + public int getBuffersProcessed() { + int[] result = new int[1]; + al.alGetSourcei(sourceID, AL.AL_BUFFERS_PROCESSED, result, 0); + + return result[0]; + } + + /** + * Sets the buffer associated with this source. + * + * @param buffer the buffer associated with this source + */ + public void setBuffer(Buffer buffer) { + al.alSourcei(sourceID, AL.AL_BUFFER, buffer.bufferID); + this.buffer = buffer; + } + + /** + * Gets the buffer associated with this source. + * + * @return the buffer associated with this source + */ + public Buffer getBuffer() { + return buffer; + } + + /** + * Queues one or more buffers on a source. Useful for streaming audio, + * buffers will be played in the order they are queued. + * + * @param buffers a set of initialized (loaded) buffers. + */ + public void queueBuffers(Buffer[] buffers) { + int numBuffers = buffers.length; + int[] arr = new int[numBuffers]; + + for (int i = 0; i < numBuffers; i++) { + arr[i] = buffers[i].bufferID; + } + + al.alSourceQueueBuffers(sourceID, numBuffers, arr, 0); + } + + /** + * Unqueues one or more buffers on a source. + * + * @param buffers a set of previously queued buffers. + */ + public void unqueueBuffers(Buffer[] buffers) { + int numBuffers = buffers.length; + int[] arr = new int[numBuffers]; + + for (int i = 0; i < numBuffers; i++) { + arr[i] = buffers[i].bufferID; + } + + al.alSourceUnqueueBuffers(sourceID, numBuffers, arr, 0); + } +} diff --git a/src/java/com/jogamp/openal/sound3d/Vec3f.java b/src/java/com/jogamp/openal/sound3d/Vec3f.java new file mode 100644 index 0000000..3a5aea2 --- /dev/null +++ b/src/java/com/jogamp/openal/sound3d/Vec3f.java @@ -0,0 +1,63 @@ +/** +* Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions are met: +* +* -Redistribution of source code must retain the above copyright notice, +* this list of conditions and the following disclaimer. +* +* -Redistribution 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 Sun Microsystems, Inc. or the names of contributors may +* be used to endorse or promote products derived from this software without +* specific prior written permission. +* +* This software is provided "AS IS," without a warranty of any kind. +* ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING +* ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR +* NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND ITS +* LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A +* RESULT OF USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. +* IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT +* OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR +* PUNITIVE DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, +* ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF SUN HAS +* BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. +* +* You acknowledge that this software is not designed or intended for use in the +* design, construction, operation or maintenance of any nuclear facility. +*/ + +package com.jogamp.openal.sound3d; + +/** + * A onvenience class representing a 3-element float vector + * + * @author Athomas Goldberg + */ +public final class Vec3f { + /** the first element in the vector */ + public final float v1; + + /** the first element in the vector */ + public final float v2; + + /** the first element in the vector */ + public final float v3; + + /** + * Creates a new Vec3f object. + * + * @param v1 the first element in the vector + * @param v2 the second element in the vector + * @param v3 the third element in the vector + */ + public Vec3f(float v1, float v2, float v3) { + this.v1 = v1; + this.v2 = v2; + this.v3 = v3; + } +} diff --git a/src/java/com/jogamp/openal/util/ALut.java b/src/java/com/jogamp/openal/util/ALut.java new file mode 100644 index 0000000..2db47d0 --- /dev/null +++ b/src/java/com/jogamp/openal/util/ALut.java @@ -0,0 +1,146 @@ +/** +* Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions are met: +* +* -Redistribution of source code must retain the above copyright notice, +* this list of conditions and the following disclaimer. +* +* -Redistribution 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 Sun Microsystems, Inc. or the names of contributors may +* be used to endorse or promote products derived from this software without +* specific prior written permission. +* +* This software is provided "AS IS," without a warranty of any kind. +* ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING +* ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR +* NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND ITS +* LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A +* RESULT OF USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. +* IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT +* OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR +* PUNITIVE DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, +* ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF SUN HAS +* BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. +* +* You acknowledge that this software is not designed or intended for use in the +* design, construction, operation or maintenance of any nuclear facility. +* +* Created on Jun 27, 2003 +*/ + +package com.jogamp.openal.util; + +import java.io.*; +import java.nio.ByteBuffer; + +import javax.sound.sampled.UnsupportedAudioFileException; + +import com.jogamp.openal.*; + +/** + * @author Athomas Goldberg + * + */ +public final class ALut { + + private static ALC alc; + private static ALCdevice device; + private static ALCcontext context; + private static Thread initializingThread; + + private ALut() { } + + /** Initializes the OpenAL Utility Toolkit, creates an OpenAL + context and makes it current on the current thread. The ALut may + only be initialized on one thread at any given time. */ + public static synchronized void alutInit() throws ALException { + if (context != null) { + throw new ALException("Already initialized on thread " + initializingThread.getName()); + } + if (alc == null) { + alc = ALFactory.getALC(); + } + String deviceName = null; + ALCdevice d = alc.alcOpenDevice(deviceName); + if (d == null) { + throw new ALException("Error opening default OpenAL device"); + } + ALCcontext c = alc.alcCreateContext(d, null); + if (c == null) { + alc.alcCloseDevice(d); + throw new ALException("Error creating OpenAL context"); + } + alc.alcMakeContextCurrent(c); + if (alc.alcGetError(d) != 0) { + alc.alcDestroyContext(c); + alc.alcCloseDevice(d); + throw new ALException("Error making OpenAL context current"); + } + // Fully initialized; finish setup + device = d; + context = c; + initializingThread = Thread.currentThread(); + } + + /** Shuts down the OpenAL Utility Toolkit; releases and destroys the + internal OpenAL context and closes the output device. Must be + called from the same thread as alutInit(). Most applications + should not need to call this; only those which wish to toggle + sound on / off at run time by initializing and un-initializing + OpenAL need to call it. */ + public static synchronized void alutExit() throws ALException { + if (context == null) { + throw new ALException("Not initialized"); + } + alc.alcMakeContextCurrent(null); + alc.alcDestroyContext(context); + alc.alcCloseDevice(device); + context = null; + device = null; + initializingThread = null; + } + + public static void alutLoadWAVFile(String fileName, + int[] format, + ByteBuffer[] data, + int[] size, + int[] freq, + int[] loop) throws ALException { + try { + WAVData wd = WAVLoader.loadFromFile(fileName); + format[0] = wd.format; + data[0] = wd.data; + size[0] = wd.size; + freq[0] = wd.freq; + loop[0] = wd.loop ? AL.AL_TRUE : AL.AL_FALSE; + } catch (Exception e) { + throw new ALException(e); + } + } + + public static void alutLoadWAVFile(InputStream stream, + int[] format, + ByteBuffer[] data, + int[] size, + int[] freq, + int[] loop) throws ALException { + try { + if (!(stream instanceof BufferedInputStream)) { + stream = new BufferedInputStream(stream); + } + WAVData wd = WAVLoader.loadFromStream(stream); + format[0] = wd.format; + data[0] = wd.data; + size[0] = wd.size; + freq[0] = wd.freq; + loop[0] = wd.loop ? AL.AL_TRUE : AL.AL_FALSE; + } catch (Exception e) { + throw new ALException(e); + } + } +} diff --git a/src/java/com/jogamp/openal/util/BufferUtils.java b/src/java/com/jogamp/openal/util/BufferUtils.java new file mode 100644 index 0000000..74b0c78 --- /dev/null +++ b/src/java/com/jogamp/openal/util/BufferUtils.java @@ -0,0 +1,266 @@ +/* + * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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 Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed or intended for use + * in the design, construction, operation or maintenance of any nuclear + * facility. + * + * Sun gratefully acknowledges that this software was originally authored + * and developed by Kenneth Bradley Russell and Christopher John Kline. + */ + +package com.jogamp.openal.util; + +import java.nio.*; +import java.util.*; + +/** Utility routines for dealing with direct buffers. */ + +public class BufferUtils { + public static final int SIZEOF_BYTE = 1; + public static final int SIZEOF_SHORT = 2; + public static final int SIZEOF_INT = 4; + public static final int SIZEOF_FLOAT = 4; + public static final int SIZEOF_LONG = 8; + public static final int SIZEOF_DOUBLE = 8; + + //---------------------------------------------------------------------- + // Allocation routines + // + + /** Allocates a new direct ByteBuffer with the specified number of + elements. The returned buffer will have its byte order set to + the host platform's native byte order. */ + public static ByteBuffer newByteBuffer(int numElements) { + ByteBuffer bb = ByteBuffer.allocateDirect(numElements); + bb.order(ByteOrder.nativeOrder()); + return bb; + } + + /** Allocates a new direct DoubleBuffer with the specified number of + elements. The returned buffer will have its byte order set to + the host platform's native byte order. */ + public static DoubleBuffer newDoubleBuffer(int numElements) { + ByteBuffer bb = newByteBuffer(numElements * SIZEOF_DOUBLE); + return bb.asDoubleBuffer(); + } + + /** Allocates a new direct FloatBuffer with the specified number of + elements. The returned buffer will have its byte order set to + the host platform's native byte order. */ + public static FloatBuffer newFloatBuffer(int numElements) { + ByteBuffer bb = newByteBuffer(numElements * SIZEOF_FLOAT); + return bb.asFloatBuffer(); + } + + /** Allocates a new direct IntBuffer with the specified number of + elements. The returned buffer will have its byte order set to + the host platform's native byte order. */ + public static IntBuffer newIntBuffer(int numElements) { + ByteBuffer bb = newByteBuffer(numElements * SIZEOF_INT); + return bb.asIntBuffer(); + } + + /** Allocates a new direct LongBuffer with the specified number of + elements. The returned buffer will have its byte order set to + the host platform's native byte order. */ + public static LongBuffer newLongBuffer(int numElements) { + ByteBuffer bb = newByteBuffer(numElements * SIZEOF_LONG); + return bb.asLongBuffer(); + } + + /** Allocates a new direct ShortBuffer with the specified number of + elements. The returned buffer will have its byte order set to + the host platform's native byte order. */ + public static ShortBuffer newShortBuffer(int numElements) { + ByteBuffer bb = newByteBuffer(numElements * SIZEOF_SHORT); + return bb.asShortBuffer(); + } + + //---------------------------------------------------------------------- + // Copy routines (type-to-type) + // + + /** Copies the remaining elements (as defined by + limit() - position()) in the passed ByteBuffer into + a newly-allocated direct ByteBuffer. The returned buffer will + have its byte order set to the host platform's native byte + order. The position of the newly-allocated buffer will be zero, + and the position of the passed buffer is unchanged (though its + mark is changed). */ + public static ByteBuffer copyByteBuffer(ByteBuffer orig) { + ByteBuffer dest = newByteBuffer(orig.remaining()); + orig.mark(); + dest.put(orig); + orig.reset(); + dest.rewind(); + return dest; + } + + /** Copies the remaining elements (as defined by + limit() - position()) in the passed DoubleBuffer + into a newly-allocated direct DoubleBuffer. The returned buffer + will have its byte order set to the host platform's native byte + order. The position of the newly-allocated buffer will be zero, + and the position of the passed buffer is unchanged (though its + mark is changed). */ + public static DoubleBuffer copyDoubleBuffer(DoubleBuffer orig) { + return copyDoubleBufferAsByteBuffer(orig).asDoubleBuffer(); + } + + /** Copies the remaining elements (as defined by + limit() - position()) in the passed FloatBuffer + into a newly-allocated direct FloatBuffer. The returned buffer + will have its byte order set to the host platform's native byte + order. The position of the newly-allocated buffer will be zero, + and the position of the passed buffer is unchanged (though its + mark is changed). */ + public static FloatBuffer copyFloatBuffer(FloatBuffer orig) { + return copyFloatBufferAsByteBuffer(orig).asFloatBuffer(); + } + + /** Copies the remaining elements (as defined by + limit() - position()) in the passed IntBuffer + into a newly-allocated direct IntBuffer. The returned buffer + will have its byte order set to the host platform's native byte + order. The position of the newly-allocated buffer will be zero, + and the position of the passed buffer is unchanged (though its + mark is changed). */ + public static IntBuffer copyIntBuffer(IntBuffer orig) { + return copyIntBufferAsByteBuffer(orig).asIntBuffer(); + } + + /** Copies the remaining elements (as defined by + limit() - position()) in the passed LongBuffer + into a newly-allocated direct LongBuffer. The returned buffer + will have its byte order set to the host platform's native byte + order. The position of the newly-allocated buffer will be zero, + and the position of the passed buffer is unchanged (though its + mark is changed). */ + public static LongBuffer copyLongBuffer(LongBuffer orig) { + return copyLongBufferAsByteBuffer(orig).asLongBuffer(); + } + + /** Copies the remaining elements (as defined by + limit() - position()) in the passed ShortBuffer + into a newly-allocated direct ShortBuffer. The returned buffer + will have its byte order set to the host platform's native byte + order. The position of the newly-allocated buffer will be zero, + and the position of the passed buffer is unchanged (though its + mark is changed). */ + public static ShortBuffer copyShortBuffer(ShortBuffer orig) { + return copyShortBufferAsByteBuffer(orig).asShortBuffer(); + } + + //---------------------------------------------------------------------- + // Copy routines (type-to-ByteBuffer) + // + + /** Copies the remaining elements (as defined by + limit() - position()) in the passed DoubleBuffer + into a newly-allocated direct ByteBuffer. The returned buffer + will have its byte order set to the host platform's native byte + order. The position of the newly-allocated buffer will be zero, + and the position of the passed buffer is unchanged (though its + mark is changed). */ + public static ByteBuffer copyDoubleBufferAsByteBuffer(DoubleBuffer orig) { + ByteBuffer dest = newByteBuffer(orig.remaining() * SIZEOF_DOUBLE); + orig.mark(); + dest.asDoubleBuffer().put(orig); + orig.reset(); + dest.rewind(); + return dest; + } + + /** Copies the remaining elements (as defined by + limit() - position()) in the passed FloatBuffer + into a newly-allocated direct ByteBuffer. The returned buffer + will have its byte order set to the host platform's native byte + order. The position of the newly-allocated buffer will be zero, + and the position of the passed buffer is unchanged (though its + mark is changed). */ + public static ByteBuffer copyFloatBufferAsByteBuffer(FloatBuffer orig) { + ByteBuffer dest = newByteBuffer(orig.remaining() * SIZEOF_FLOAT); + orig.mark(); + dest.asFloatBuffer().put(orig); + orig.reset(); + dest.rewind(); + return dest; + } + + /** Copies the remaining elements (as defined by + limit() - position()) in the passed IntBuffer into + a newly-allocated direct ByteBuffer. The returned buffer will + have its byte order set to the host platform's native byte + order. The position of the newly-allocated buffer will be zero, + and the position of the passed buffer is unchanged (though its + mark is changed). */ + public static ByteBuffer copyIntBufferAsByteBuffer(IntBuffer orig) { + ByteBuffer dest = newByteBuffer(orig.remaining() * SIZEOF_INT); + orig.mark(); + dest.asIntBuffer().put(orig); + orig.reset(); + dest.rewind(); + return dest; + } + + /** Copies the remaining elements (as defined by + limit() - position()) in the passed LongBuffer into + a newly-allocated direct ByteBuffer. The returned buffer will + have its byte order set to the host platform's native byte + order. The position of the newly-allocated buffer will be zero, + and the position of the passed buffer is unchanged (though its + mark is changed). */ + public static ByteBuffer copyLongBufferAsByteBuffer(LongBuffer orig) { + ByteBuffer dest = newByteBuffer(orig.remaining() * SIZEOF_LONG); + orig.mark(); + dest.asLongBuffer().put(orig); + orig.reset(); + dest.rewind(); + return dest; + } + + /** Copies the remaining elements (as defined by + limit() - position()) in the passed ShortBuffer + into a newly-allocated direct ByteBuffer. The returned buffer + will have its byte order set to the host platform's native byte + order. The position of the newly-allocated buffer will be zero, + and the position of the passed buffer is unchanged (though its + mark is changed). */ + public static ByteBuffer copyShortBufferAsByteBuffer(ShortBuffer orig) { + ByteBuffer dest = newByteBuffer(orig.remaining() * SIZEOF_SHORT); + orig.mark(); + dest.asShortBuffer().put(orig); + orig.reset(); + dest.rewind(); + return dest; + } +} diff --git a/src/java/com/jogamp/openal/util/WAVData.java b/src/java/com/jogamp/openal/util/WAVData.java new file mode 100644 index 0000000..345c675 --- /dev/null +++ b/src/java/com/jogamp/openal/util/WAVData.java @@ -0,0 +1,75 @@ +/** +* Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions are met: +* +* -Redistribution of source code must retain the above copyright notice, +* this list of conditions and the following disclaimer. +* +* -Redistribution 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 Sun Microsystems, Inc. or the names of contributors may +* be used to endorse or promote products derived from this software without +* specific prior written permission. +* +* This software is provided "AS IS," without a warranty of any kind. +* ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING +* ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR +* NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND ITS +* LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A +* RESULT OF USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. +* IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT +* OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR +* PUNITIVE DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, +* ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF SUN HAS +* BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. +* +* You acknowledge that this software is not designed or intended for use in the +* design, construction, operation or maintenance of any nuclear facility. +*/ + +package com.jogamp.openal.util; + +import java.nio.ByteBuffer; + + +/** + * This class is a holder for WAV (.wav )file Data returned from the WavLoader + * + * @author Athomas Goldberg + */ +public final class WAVData { + /** The audio data */ + public final ByteBuffer data; + + /** the format of the Data. One of: + *
+     * AL.AL_FORMAT_MONO8
+     * AL.AL_FORMAT_MONO16
+     * AL.AL_FORMAT_STEREO8
+     * AL.AL_FORMAT_STEREO16
+     * 
+ * + */ + public final int format; + + /** Size (in bytes) of the data */ + public final int size; + + /** The frequency of the data */ + public final int freq; + + /** flag indicating whether or not the sound in the data should loop */ + public final boolean loop; + + WAVData(ByteBuffer data, int format, int size, int freq, boolean loop) { + this.data = data; + this.format = format; + this.size = size; + this.freq = freq; + this.loop = loop; + } +} diff --git a/src/java/com/jogamp/openal/util/WAVLoader.java b/src/java/com/jogamp/openal/util/WAVLoader.java new file mode 100644 index 0000000..4ee2305 --- /dev/null +++ b/src/java/com/jogamp/openal/util/WAVLoader.java @@ -0,0 +1,135 @@ +/** +* Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions are met: +* +* -Redistribution of source code must retain the above copyright notice, +* this list of conditions and the following disclaimer. +* +* -Redistribution 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 Sun Microsystems, Inc. or the names of contributors may +* be used to endorse or promote products derived from this software without +* specific prior written permission. +* +* This software is provided "AS IS," without a warranty of any kind. +* ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING +* ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR +* NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND ITS +* LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A +* RESULT OF USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. +* IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT +* OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR +* PUNITIVE DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, +* ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF SUN HAS +* BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. +* +* You acknowledge that this software is not designed or intended for use in the +* design, construction, operation or maintenance of any nuclear facility. +*/ + +package com.jogamp.openal.util; + +import java.io.*; +import java.nio.*; +import java.nio.channels.*; +import javax.sound.sampled.*; + +import com.jogamp.openal.*; + +/** + * A Loader utility for (.wav) files. Creates a WAVData object containing the + * data used by the AL.alBufferData method. + * + * @author Athomas Goldberg + */ +public class WAVLoader implements ALConstants { + private static final int BUFFER_SIZE = 128000; + + /** + * This method loads a (.wav) file into a WAVData object. + * + * @param filename The name of the (.wav) file + * + * @return a WAVData object containing the audio data + * + * @throws UnsupportedAudioFileException if the format of the audio if not + * supported. + * @throws IOException If the file can no be found or some other IO error + * occurs + */ + public static WAVData loadFromFile(String filename) + throws UnsupportedAudioFileException, IOException { + WAVData result = null; + File soundFile = new File(filename); + AudioInputStream aIn = AudioSystem.getAudioInputStream(soundFile); + return readFromStream(aIn); + } + + /** + * This method loads a (.wav) file into a WAVData object. + * + * @param stream An InputStream for the .WAV file. + * + * @return a WAVData object containing the audio data + * + * @throws UnsupportedAudioFileException if the format of the audio if not + * supported. + * @throws IOException If the file can no be found or some other IO error + * occurs + */ + public static WAVData loadFromStream(InputStream stream) + throws UnsupportedAudioFileException, IOException { + WAVData result = null; + AudioInputStream aIn = AudioSystem.getAudioInputStream(stream); + return readFromStream(aIn); + } + + + private static WAVData readFromStream(AudioInputStream aIn) + throws UnsupportedAudioFileException, IOException { + ReadableByteChannel aChannel = Channels.newChannel(aIn); + AudioFormat fmt = aIn.getFormat(); + int numChannels = fmt.getChannels(); + int bits = fmt.getSampleSizeInBits(); + int format = AL_FORMAT_MONO8; + + if ((bits == 8) && (numChannels == 1)) { + format = AL_FORMAT_MONO8; + } else if ((bits == 16) && (numChannels == 1)) { + format = AL_FORMAT_MONO16; + } else if ((bits == 8) && (numChannels == 2)) { + format = AL_FORMAT_STEREO8; + } else if ((bits == 16) && (numChannels == 2)) { + format = AL_FORMAT_STEREO16; + } + + int freq = Math.round(fmt.getSampleRate()); + int size = aIn.available(); + ByteBuffer buffer = ByteBuffer.allocateDirect(size); + while (buffer.remaining() > 0) { + aChannel.read(buffer); + } + buffer.rewind(); + + // Must byte swap on big endian platforms + // Thanks to swpalmer on javagaming.org forums for hint at fix + if ((bits == 16) && (ByteOrder.nativeOrder() == ByteOrder.BIG_ENDIAN)) { + int len = buffer.remaining(); + for (int i = 0; i < len; i += 2) { + byte a = buffer.get(i); + byte b = buffer.get(i+1); + buffer.put(i, b); + buffer.put(i+1, a); + } + } + + WAVData result = new WAVData(buffer, format, size, freq, false); + aIn.close(); + + return result; + } +} diff --git a/src/java/net/java/games/joal/ALException.java b/src/java/net/java/games/joal/ALException.java deleted file mode 100755 index 75c6944..0000000 --- a/src/java/net/java/games/joal/ALException.java +++ /dev/null @@ -1,62 +0,0 @@ -/** - * Copyright (c) 2003-2005 Sun Microsystems, Inc. All Rights Reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * -Redistribution of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - * -Redistribution 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 Sun Microsystems, Inc. or the names of contributors may - * be used to endorse or promote products derived from this software without - * specific prior written permission. - * - * This software is provided "AS IS," without a warranty of any kind. - * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING - * ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR - * NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND ITS - * LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A - * RESULT OF USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. - * IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT - * OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR - * PUNITIVE DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, - * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF SUN HAS - * BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. - * - * You acknowledge that this software is not designed or intended for use in the - * design, construction, operation or maintenance of any nuclear facility. - */ - -package net.java.games.joal; - -/** A generic exception for OpenAL errors used throughout the binding - as a substitute for {@link RuntimeException}. */ - -public class ALException extends RuntimeException { - /** Constructs an ALException object. */ - public ALException() { - super(); - } - - /** Constructs an ALException object with the specified detail - message. */ - public ALException(String message) { - super(message); - } - - /** Constructs an ALException object with the specified detail - message and root cause. */ - public ALException(String message, Throwable cause) { - super(message, cause); - } - - /** Constructs an ALException object with the specified root - cause. */ - public ALException(Throwable cause) { - super(cause); - } -} diff --git a/src/java/net/java/games/joal/ALFactory.java b/src/java/net/java/games/joal/ALFactory.java deleted file mode 100644 index 17a8c09..0000000 --- a/src/java/net/java/games/joal/ALFactory.java +++ /dev/null @@ -1,89 +0,0 @@ -/** - * Copyright (c) 2003-2005 Sun Microsystems, Inc. All Rights Reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * -Redistribution of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - * -Redistribution 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 Sun Microsystems, Inc. or the names of contributors may - * be used to endorse or promote products derived from this software without - * specific prior written permission. - * - * This software is provided "AS IS," without a warranty of any kind. - * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING - * ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR - * NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND ITS - * LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A - * RESULT OF USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. - * IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT - * OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR - * PUNITIVE DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, - * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF SUN HAS - * BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. - * - * You acknowledge that this software is not designed or intended for use in the - * design, construction, operation or maintenance of any nuclear facility. - */ - -package net.java.games.joal; - -import net.java.games.joal.impl.*; - -/** - * This class provides factory methods for generating AL and ALC objects. - * - * @author Athomas Goldberg - * @author Kenneth Russell - */ -public class ALFactory { - private static boolean initialized = false; - private static AL al; - private static ALC alc; - - private ALFactory() {} - - private static synchronized void initialize() throws ALException { - try { - if (!initialized) { - NativeLibLoader.load(); - initialized = true; - } - } catch (UnsatisfiedLinkError e) { - throw new ALException(e); - } - } - - /** - * Get the default AL object. This object is used to access most of the - * OpenAL functionality. - * - * @return the AL object - */ - public static AL getAL() throws ALException { - initialize(); - if (al == null) { - al = new ALImpl(); - } - return al; - } - - /** - * Get the default ALC object. This object is used to access most of the - * OpenAL context functionality. - * - * @return the ALC object - */ - public static ALC getALC() throws ALException{ - initialize(); - if (alc == null) { - alc = new ALCImpl(); - } - return alc; - } -} diff --git a/src/java/net/java/games/joal/eax/EAX.java b/src/java/net/java/games/joal/eax/EAX.java deleted file mode 100644 index 68cd191..0000000 --- a/src/java/net/java/games/joal/eax/EAX.java +++ /dev/null @@ -1,140 +0,0 @@ -/** -* Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. -* -* Redistribution and use in source and binary forms, with or without -* modification, are permitted provided that the following conditions are met: -* -* -Redistribution of source code must retain the above copyright notice, -* this list of conditions and the following disclaimer. -* -* -Redistribution 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 Sun Microsystems, Inc. or the names of contributors may -* be used to endorse or promote products derived from this software without -* specific prior written permission. -* -* This software is provided "AS IS," without a warranty of any kind. -* ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING -* ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR -* NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND ITS -* LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A -* RESULT OF USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. -* IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT -* OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR -* PUNITIVE DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, -* ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF SUN HAS -* BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. -* -* You acknowledge that this software is not designed or intended for use in the -* design, construction, operation or maintenance of any nuclear facility. -*/ - -package net.java.games.joal.eax; - -import java.nio.Buffer; - - -/** - * @author Athomas Goldberg - * - */ -public class EAX implements EAXConstants { - static { - System.loadLibrary("joal_native"); - } - - public static final int SOURCE = 0; - public static final int LISTENER = 1; - - private final int sourceGUID = SOURCE; - private final int listenerGUID = LISTENER; - - /** - * @param sourceGUID - * @param listenerGUID - */ - EAX(int sourceGUID, int listenerGUID) { - // this.sourceGUID = sourceGUID; - // this.listenerGUID = listenerGUID; - } - - /** - * This method sets an EAX property value.
- *
- * Interface to C Language function: - *
ALenum EAXSet(const struct _GUID *propertySetID, ALuint property, ALuint source, ALvoid *value, ALuint size)
- * - * @param objectFlag a flag indicating a LISTENER or a SOURCE - * @param pname the property being set - * @param source the ID of the source, or 0 for Listener properties - * @param value a direct Buffer to hold the value retrieved - * @param size the size of the Buffer - */ - public native void EAXSet( - int objectFlag, - int pname, - int source, - Buffer value, - int size - ); - - /** - * This method retrieves an EAX property value.
- *
- * Interface to C Language function: - *
ALenum EAXGet(const struct _GUID *propertySetID, ALuint property, ALuint source, ALvoid *value, ALuint size)
- * - * @param objectFlag a flag indicating a LISTENER or a SOURCE - * @param pname the property being queried - * @param source the ID of the source, or 0 for Listener properties - * @param value a direct Buffer to hold the value retrieved - * @param size the size of the Buffer - */ - public native void EAXGet( - int objectFlag, - int pname, - int source, - Buffer value, - int size - ); - - /** - * This method sets a source property. - * @param sourceID the ID of the source whose property is being set. - * @param pname the name of the property being set - * @param value a direct Buffer containing the value to be set - */ - public void setSourceProperty(int sourceID, int pname, Buffer value) { - EAXSet(sourceGUID, pname, sourceID, value, value.capacity()); - } - - /** - * This method retrieves a source property. - * @param sourceID the ID of the source whose property is being retrieved. - * @param pname the name of the property being retrieved - * @param value a direct Buffer to hold the value to be retrieved - */ - public void getSourceProperty(int pname, int sourceID, Buffer value) { - EAXGet(sourceGUID, pname, sourceID, value, value.capacity()); - } - - /** - * This method sets a Listener property. - * @param pname the name of the property being set - * @param value a direct Buffer containing the value to be set - */ - public void setListenerProperty(int pname, Buffer value) { - EAXSet(listenerGUID, pname, 0, value, value.capacity()); - } - - /** - * This method retrieves a Listener property. - * @param pname the name of the property being retrieved - * @param value a direct Buffer to hold the value to be retrieved - */ - public void getListenerProperty(int pname, Buffer value) { - EAXGet(listenerGUID, pname, 0, value, value.capacity()); - } -} diff --git a/src/java/net/java/games/joal/eax/EAXConstants.java b/src/java/net/java/games/joal/eax/EAXConstants.java deleted file mode 100644 index 44f1bee..0000000 --- a/src/java/net/java/games/joal/eax/EAXConstants.java +++ /dev/null @@ -1,350 +0,0 @@ -/** -* Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. -* -* Redistribution and use in source and binary forms, with or without -* modification, are permitted provided that the following conditions are met: -* -* -Redistribution of source code must retain the above copyright notice, -* this list of conditions and the following disclaimer. -* -* -Redistribution 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 Sun Microsystems, Inc. or the names of contributors may -* be used to endorse or promote products derived from this software without -* specific prior written permission. -* -* This software is provided "AS IS," without a warranty of any kind. -* ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING -* ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR -* NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND ITS -* LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A -* RESULT OF USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. -* IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT -* OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR -* PUNITIVE DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, -* ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF SUN HAS -* BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. -* -* You acknowledge that this software is not designed or intended for use in the -* design, construction, operation or maintenance of any nuclear facility. -*/ - -package net.java.games.joal.eax; -/** - * - * This class implements the basic EAX extension constants. - * - * @author Athomas Goldberg - */ -public interface EAXConstants { - - public final static int DSPROPERTY_EAXLISTENER_NONE = 0; - public final static int DSPROPERTY_EAXLISTENER_ALLPARAMETERS = 1; - public final static int DSPROPERTY_EAXLISTENER_ROOM = 2; - public final static int DSPROPERTY_EAXLISTENER_ROOMHF = 3; - public final static int DSPROPERTY_EAXLISTENER_ROOMROLLOFFFACTOR = 4; - public final static int DSPROPERTY_EAXLISTENER_DECAYTIME = 5; - public final static int DSPROPERTY_EAXLISTENER_DECAYHFRATIO = 6; - public final static int DSPROPERTY_EAXLISTENER_REFLECTIONS = 7; - public final static int DSPROPERTY_EAXLISTENER_REFLECTIONSDELAY = 8; - public final static int DSPROPERTY_EAXLISTENER_REVERB = 9; - public final static int DSPROPERTY_EAXLISTENER_REVERBDELAY = 10; - public final static int DSPROPERTY_EAXLISTENER_ENVIRONMENT = 11; - public final static int DSPROPERTY_EAXLISTENER_ENVIRONMENTSIZE = 12; - public final static int DSPROPERTY_EAXLISTENER_ENVIRONMENTDIFFUSION = 13; - public final static int DSPROPERTY_EAXLISTENER_AIRABSORPTIONHF = 14; - public final static int DSPROPERTY_EAXLISTENER_FLAGS = 15; - -// OR these flags with property id // - /** changes take effect immediately */ - public static final int DSPROPERTY_EAXLISTENER_IMMEDIATE = 0x00000000; - - /** changes take effect later */ - public static final int DSPROPERTY_EAXLISTENER_DEFERRED = 0x80000000; - - public static final int DSPROPERTY_EAXLISTENER_COMMITDEFERREDSETTINGS = - DSPROPERTY_EAXLISTENER_NONE | - DSPROPERTY_EAXLISTENER_IMMEDIATE; - - /** used by DSPROPERTY_EAXLISTENER_ENVIRONMENT */ - public final static int EAX_ENVIRONMENT_GENERIC = 0; - /** used by DSPROPERTY_EAXLISTENER_ENVIRONMENT */ - public final static int EAX_ENVIRONMENT_PADDEDCELL = 1; - /** used by DSPROPERTY_EAXLISTENER_ENVIRONMENT */ - public final static int EAX_ENVIRONMENT_ROOM = 2; - /** used by DSPROPERTY_EAXLISTENER_ENVIRONMENT */ - public final static int EAX_ENVIRONMENT_BATHROOM = 3; - /** used by DSPROPERTY_EAXLISTENER_ENVIRONMENT */ - public final static int EAX_ENVIRONMENT_LIVINGROOM = 4; - /** used by DSPROPERTY_EAXLISTENER_ENVIRONMENT */ - public final static int EAX_ENVIRONMENT_STONEROOM = 5; - /** used by DSPROPERTY_EAXLISTENER_ENVIRONMENT */ - public final static int EAX_ENVIRONMENT_AUDITORIUM = 6; - /** used by DSPROPERTY_EAXLISTENER_ENVIRONMENT */ - public final static int EAX_ENVIRONMENT_CONCERTHALL = 7; - /** used by DSPROPERTY_EAXLISTENER_ENVIRONMENT */ - public final static int EAX_ENVIRONMENT_CAVE = 8; - /** used by DSPROPERTY_EAXLISTENER_ENVIRONMENT */ - public final static int EAX_ENVIRONMENT_ARENA = 9; - /** used by DSPROPERTY_EAXLISTENER_ENVIRONMENT */ - public final static int EAX_ENVIRONMENT_HANGAR = 10; - /** used by DSPROPERTY_EAXLISTENER_ENVIRONMENT */ - public final static int EAX_ENVIRONMENT_CARPETEDHALLWAY = 11; - /** used by DSPROPERTY_EAXLISTENER_ENVIRONMENT */ - public final static int EAX_ENVIRONMENT_HALLWAY = 12; - /** used by DSPROPERTY_EAXLISTENER_ENVIRONMENT */ - public final static int EAX_ENVIRONMENT_STONECORRIDOR = 13; - /** used by DSPROPERTY_EAXLISTENER_ENVIRONMENT */ - public final static int EAX_ENVIRONMENT_ALLEY = 14; - /** used by DSPROPERTY_EAXLISTENER_ENVIRONMENT */ - public final static int EAX_ENVIRONMENT_FOREST = 15; - /** used by DSPROPERTY_EAXLISTENER_ENVIRONMENT */ - public final static int EAX_ENVIRONMENT_CITY = 16; - /** used by DSPROPERTY_EAXLISTENER_ENVIRONMENT */ - public final static int EAX_ENVIRONMENT_MOUNTAINS = 17; - /** used by DSPROPERTY_EAXLISTENER_ENVIRONMENT */ - public final static int EAX_ENVIRONMENT_QUARRY = 18; - /** used by DSPROPERTY_EAXLISTENER_ENVIRONMENT */ - public final static int EAX_ENVIRONMENT_PLAIN = 19; - /** used by DSPROPERTY_EAXLISTENER_ENVIRONMENT */ - public final static int EAX_ENVIRONMENT_PARKINGLOT = 20; - /** used by DSPROPERTY_EAXLISTENER_ENVIRONMENT */ - public final static int EAX_ENVIRONMENT_SEWERPIPE = 21; - /** used by DSPROPERTY_EAXLISTENER_ENVIRONMENT */ - public final static int EAX_ENVIRONMENT_UNDERWATER = 22; - /** used by DSPROPERTY_EAXLISTENER_ENVIRONMENT */ - public final static int EAX_ENVIRONMENT_DRUGGED = 23; - /** used by DSPROPERTY_EAXLISTENER_ENVIRONMENT */ - public final static int EAX_ENVIRONMENT_DIZZY = 24; - /** used by DSPROPERTY_EAXLISTENER_ENVIRONMENT */ - public final static int EAX_ENVIRONMENT_PSYCHOTIC = 25; - /** used by DSPROPERTY_EAXLISTENER_ENVIRONMENT */ - public final static int EAX_ENVIRONMENT_COUNT = 26; - -// These flags determine what properties are affected by environment size. - /** reverberation decay time */ - public final static int EAXLISTENERFLAGS_DECAYTIMESCALE = 0x00000001; - /** reflection level */ - public final static int EAXLISTENERFLAGS_REFLECTIONSSCALE = 0x00000002; - /** initial reflection delay time */ - public final static int EAXLISTENERFLAGS_REFLECTIONSDELAYSCALE = 0x00000004; - /** reflections level */ - public final static int EAXLISTENERFLAGS_REVERBSCALE = 0x00000008; - /** late reverberation delay time */ - public final static int EAXLISTENERFLAGS_REVERBDELAYSCALE = 0x00000010; - - /** This flag limits high-frequency decay time according to air absorption.*/ - public final static int EAXLISTENERFLAGS_DECAYHFLIMIT = 0x00000020; - /** reserved future use */ - public final static int EAXLISTENERFLAGS_RESERVED = 0xFFFFFFC0; - -// property ranges and defaults: - - public final static int EAXLISTENER_MINROOM = -10000; - public final static int EAXLISTENER_MAXROOM = 0; - public final static int EAXLISTENER_DEFAULTROOM = -1000; - - public final static int EAXLISTENER_MINROOMHF = -10000; - public final static int EAXLISTENER_MAXROOMHF = 0; - public final static int EAXLISTENER_DEFAULTROOMHF = -100; - - public final static float EAXLISTENER_MINROOMROLLOFFFACTOR = 0.0f; - public final static float EAXLISTENER_MAXROOMROLLOFFFACTOR = 10.0f; - public final static float EAXLISTENER_DEFAULTROOMROLLOFFFACTOR = 0.0f; - - public final static float EAXLISTENER_MINDECAYTIME = 0.1f; - public final static float EAXLISTENER_MAXDECAYTIME = 20.0f; - public final static float EAXLISTENER_DEFAULTDECAYTIME = 1.49f; - - public final static float EAXLISTENER_MINDECAYHFRATIO = 0.1f; - public final static float EAXLISTENER_MAXDECAYHFRATIO = 2.0f; - public final static float EAXLISTENER_DEFAULTDECAYHFRATIO = 0.83f; - - public final static int EAXLISTENER_MINREFLECTIONS = -10000; - public final static int EAXLISTENER_MAXREFLECTIONS = 1000; - public final static int EAXLISTENER_DEFAULTREFLECTIONS = -2602; - - public final static float EAXLISTENER_MINREFLECTIONSDELAY = 0.0f; - public final static float EAXLISTENER_MAXREFLECTIONSDELAY = 0.3f; - public final static float EAXLISTENER_DEFAULTREFLECTIONSDELAY = 0.007f; - - public final static int EAXLISTENER_MINREVERB = -10000; - public final static int EAXLISTENER_MAXREVERB = 2000; - public final static int EAXLISTENER_DEFAULTREVERB = 200; - - public final static float EAXLISTENER_MINREVERBDELAY = 0.0f; - public final static float EAXLISTENER_MAXREVERBDELAY = 0.1f; - public final static float EAXLISTENER_DEFAULTREVERBDELAY = 0.011f; - - public final static int EAXLISTENER_MINENVIRONMENT = 0; - public final static int EAXLISTENER_MAXENVIRONMENT = EAX_ENVIRONMENT_COUNT-1; - public final static int EAXLISTENER_DEFAULTENVIRONMENT = EAX_ENVIRONMENT_GENERIC; - - public final static float EAXLISTENER_MINENVIRONMENTSIZE = 1.0f; - public final static float EAXLISTENER_MAXENVIRONMENTSIZE = 100.0f; - public final static float EAXLISTENER_DEFAULTENVIRONMENTSIZE = 7.5f; - - public final static float EAXLISTENER_MINENVIRONMENTDIFFUSION = 0.0f; - public final static float EAXLISTENER_MAXENVIRONMENTDIFFUSION = 1.0f; - public final static float EAXLISTENER_DEFAULTENVIRONMENTDIFFUSION = 1.0f; - - public final static float EAXLISTENER_MINAIRABSORPTIONHF = -100.0f; - public final static float EAXLISTENER_MAXAIRABSORPTIONHF = 0.0f; - public final static float EAXLISTENER_DEFAULTAIRABSORPTIONHF = -5.0f; - - public final static int EAXLISTENER_DEFAULTFLAGS = - EAXLISTENERFLAGS_DECAYTIMESCALE | - EAXLISTENERFLAGS_REFLECTIONSSCALE | - EAXLISTENERFLAGS_REFLECTIONSDELAYSCALE | - EAXLISTENERFLAGS_REVERBSCALE | - EAXLISTENERFLAGS_REVERBDELAYSCALE | - EAXLISTENERFLAGS_DECAYHFLIMIT; - - public final static int DSPROPERTY_EAXBUFFER_NONE = 0; - public final static int DSPROPERTY_EAXBUFFER_ALLPARAMETERS = 1; - public final static int DSPROPERTY_EAXBUFFER_DIRECT = 2; - public final static int DSPROPERTY_EAXBUFFER_DIRECTHF = 3; - public final static int DSPROPERTY_EAXBUFFER_ROOM = 4; - public final static int DSPROPERTY_EAXBUFFER_ROOMHF = 5; - public final static int DSPROPERTY_EAXBUFFER_ROOMROLLOFFFACTOR = 6; - public final static int DSPROPERTY_EAXBUFFER_OBSTRUCTION = 7; - public final static int DSPROPERTY_EAXBUFFER_OBSTRUCTIONLFRATIO = 8; - public final static int DSPROPERTY_EAXBUFFER_OCCLUSION = 9; - public final static int DSPROPERTY_EAXBUFFER_OCCLUSIONLFRATIO = 10; - public final static int DSPROPERTY_EAXBUFFER_OCCLUSIONROOMRATIO = 11; - public final static int DSPROPERTY_EAXBUFFER_OUTSIDEVOLUMEHF = 13; - public final static int DSPROPERTY_EAXBUFFER_AIRABSORPTIONFACTOR = 14; - public final static int DSPROPERTY_EAXBUFFER_FLAGS = 15; - -// OR these flags with property id - /** changes take effect immediately */ - public final static int DSPROPERTY_EAXBUFFER_IMMEDIATE = 0x00000000; - /** changes take effect later */ - public final static int DSPROPERTY_EAXBUFFER_DEFERRED = 0x80000000; - public final static int DSPROPERTY_EAXBUFFER_COMMITDEFERREDSETTINGS = - DSPROPERTY_EAXBUFFER_NONE | - DSPROPERTY_EAXBUFFER_IMMEDIATE; - - -// Used by DSPROPERTY_EAXBUFFER_FLAGS -// TRUE: value is computed automatically - property is an offset -// FALSE: value is used directly -// -// Note: The number and order of flags may change in future EAX versions. -// To insure future compatibility, use flag defines as follows: -// myFlags = EAXBUFFERFLAGS_DIRECTHFAUTO | EAXBUFFERFLAGS_ROOMAUTO; -// instead of: -// myFlags = 0x00000003; -// - /** affects DSPROPERTY_EAXBUFFER_DIRECTHF */ - public final static int EAXBUFFERFLAGS_DIRECTHFAUTO = 0x00000001; - /** affects DSPROPERTY_EAXBUFFER_ROOM */ - public final static int EAXBUFFERFLAGS_ROOMAUTO = 0x00000002; - /** affects DSPROPERTY_EAXBUFFER_ROOMHF */ - public final static int EAXBUFFERFLAGS_ROOMHFAUTO = 0x00000004; - /** reserved future use */ - public final static int EAXBUFFERFLAGS_RESERVED = 0xFFFFFFF8; - -// property ranges and defaults: - - public final static int EAXBUFFER_MINDIRECT = (-10000); - public final static int EAXBUFFER_MAXDIRECT = 1000; - public final static int EAXBUFFER_DEFAULTDIRECT = 0; - - public final static int EAXBUFFER_MINDIRECTHF = (-10000); - public final static int EAXBUFFER_MAXDIRECTHF = 0; - public final static int EAXBUFFER_DEFAULTDIRECTHF = 0; - - public final static int EAXBUFFER_MINROOM = (-10000); - public final static int EAXBUFFER_MAXROOM = 1000; - public final static int EAXBUFFER_DEFAULTROOM = 0; - - public final static int EAXBUFFER_MINROOMHF = (-10000); - public final static int EAXBUFFER_MAXROOMHF = 0; - public final static int EAXBUFFER_DEFAULTROOMHF = 0; - - public final static float EAXBUFFER_MINROOMROLLOFFFACTOR = 0.0f; - public final static float EAXBUFFER_MAXROOMROLLOFFFACTOR = 10.f; - public final static float EAXBUFFER_DEFAULTROOMROLLOFFFACTOR = 0.0f; - - public final static int EAXBUFFER_MINOBSTRUCTION = (-10000); - public final static int EAXBUFFER_MAXOBSTRUCTION = 0; - public final static int EAXBUFFER_DEFAULTOBSTRUCTION = 0; - - public final static float EAXBUFFER_MINOBSTRUCTIONLFRATIO = 0.0f; - public final static float EAXBUFFER_MAXOBSTRUCTIONLFRATIO = 1.0f; - public final static float EAXBUFFER_DEFAULTOBSTRUCTIONLFRATIO = 0.0f; - - public final static int EAXBUFFER_MINOCCLUSION = (-10000); - public final static int EAXBUFFER_MAXOCCLUSION = 0; - public final static int EAXBUFFER_DEFAULTOCCLUSION = 0; - - public final static float EAXBUFFER_MINOCCLUSIONLFRATIO = 0.0f; - public final static float EAXBUFFER_MAXOCCLUSIONLFRATIO = 1.0f; - public final static float EAXBUFFER_DEFAULTOCCLUSIONLFRATIO = 0.25f; - - public final static float EAXBUFFER_MINOCCLUSIONROOMRATIO = 0.0f; - public final static float EAXBUFFER_MAXOCCLUSIONROOMRATIO = 10.0f; - public final static float EAXBUFFER_DEFAULTOCCLUSIONROOMRATIO = 0.5f; - - public final static int EAXBUFFER_MINOUTSIDEVOLUMEHF = (-10000); - public final static int EAXBUFFER_MAXOUTSIDEVOLUMEHF = 0; - public final static int EAXBUFFER_DEFAULTOUTSIDEVOLUMEHF = 0; - - public final static float EAXBUFFER_MINAIRABSORPTIONFACTOR = 0.0f; - public final static float EAXBUFFER_MAXAIRABSORPTIONFACTOR = 10.0f; - public final static float EAXBUFFER_DEFAULTAIRABSORPTIONFACTOR = 1.0f; - - public final static int EAXBUFFER_DEFAULTFLAGS = - EAXBUFFERFLAGS_DIRECTHFAUTO | - EAXBUFFERFLAGS_ROOMAUTO | - EAXBUFFERFLAGS_ROOMHFAUTO; - -// Material transmission presets -// 3 values in this order: -// 1: occlusion (or obstruction) -// 2: occlusion LF Ratio (or obstruction LF Ratio) -// 3: occlusion Room Ratio - -// Single window material preset - public final static int EAX_MATERIAL_SINGLEWINDOW = (-2800); - public final static float EAX_MATERIAL_SINGLEWINDOWLF = 0.71f; - public final static float EAX_MATERIAL_SINGLEWINDOWROOMRATIO = 0.43f; - -// Double window material preset - public final static int EAX_MATERIAL_DOUBLEWINDOW = (-5000); - public final static float EAX_MATERIAL_DOUBLEWINDOWHF = 0.40f; - public final static float EAX_MATERIAL_DOUBLEWINDOWROOMRATIO = 0.24f; - -// Thin door material preset - public final static int EAX_MATERIAL_THINDOOR = (-1800); - public final static float EAX_MATERIAL_THINDOORLF = 0.66f; - public final static float EAX_MATERIAL_THINDOORROOMRATIO = 0.66f; - -// Thick door material preset - public final static int EAX_MATERIAL_THICKDOOR = (-4400); - public final static float EAX_MATERIAL_THICKDOORLF = 0.64f; - public final static float EAX_MATERIAL_THICKDOORROOMRTATION = 0.27f; - -// Wood wall material preset - public final static int EAX_MATERIAL_WOODWALL = (-4000); - public final static float EAX_MATERIAL_WOODWALLLF = 0.50f; - public final static float EAX_MATERIAL_WOODWALLROOMRATIO = 0.30f; - -// Brick wall material preset - public final static int EAX_MATERIAL_BRICKWALL = (-5000); - public final static float EAX_MATERIAL_BRICKWALLLF = 0.60f; - public final static float EAX_MATERIAL_BRICKWALLROOMRATIO = 0.24f; - -// Stone wall material preset - public final static int EAX_MATERIAL_STONEWALL = (-6000); - public final static float EAX_MATERIAL_STONEWALLLF = 0.68f; - public final static float EAX_MATERIAL_STONEWALLROOMRATIO = 0.20f; - -// Curtain material preset - public final static int EAX_MATERIAL_CURTAIN = (-1200); - public final static float EAX_MATERIAL_CURTAINLF = 0.15f; - public final static float EAX_MATERIAL_CURTAINROOMRATIO = 1.00f; -} \ No newline at end of file diff --git a/src/java/net/java/games/joal/eax/EAXFactory.java b/src/java/net/java/games/joal/eax/EAXFactory.java deleted file mode 100644 index 0c47a2a..0000000 --- a/src/java/net/java/games/joal/eax/EAXFactory.java +++ /dev/null @@ -1,54 +0,0 @@ -/** -* Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. -* -* Redistribution and use in source and binary forms, with or without -* modification, are permitted provided that the following conditions are met: -* -* -Redistribution of source code must retain the above copyright notice, -* this list of conditions and the following disclaimer. -* -* -Redistribution 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 Sun Microsystems, Inc. or the names of contributors may -* be used to endorse or promote products derived from this software without -* specific prior written permission. -* -* This software is provided "AS IS," without a warranty of any kind. -* ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING -* ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR -* NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND ITS -* LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A -* RESULT OF USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. -* IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT -* OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR -* PUNITIVE DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, -* ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF SUN HAS -* BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. -* -* You acknowledge that this software is not designed or intended for use in the -* design, construction, operation or maintenance of any nuclear facility. -*/ - -package net.java.games.joal.eax; - -/** - * @author Athomas Goldberg - * - */ -public final class EAXFactory { - private static int SOURCE_GUID; - private static int LISTENER_GUID; - - private static EAX eax; - - private static native void init(); - public static EAX getEAX() { - if(eax == null) { - init(); - eax = new EAX(SOURCE_GUID, LISTENER_GUID); - } - return eax; - } -} diff --git a/src/java/net/java/games/joal/impl/ALProcAddressLookup.java b/src/java/net/java/games/joal/impl/ALProcAddressLookup.java deleted file mode 100755 index e2a6425..0000000 --- a/src/java/net/java/games/joal/impl/ALProcAddressLookup.java +++ /dev/null @@ -1,159 +0,0 @@ -/** - * Copyright (c) 2003-2005 Sun Microsystems, Inc. All Rights Reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * -Redistribution of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - * -Redistribution 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 Sun Microsystems, Inc. or the names of contributors may - * be used to endorse or promote products derived from this software without - * specific prior written permission. - * - * This software is provided "AS IS," without a warranty of any kind. - * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING - * ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR - * NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND ITS - * LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A - * RESULT OF USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. - * IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT - * OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR - * PUNITIVE DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, - * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF SUN HAS - * BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. - * - * You acknowledge that this software is not designed or intended for use in the - * design, construction, operation or maintenance of any nuclear facility. - */ - -package net.java.games.joal.impl; - -import java.lang.reflect.Field; - -import net.java.games.joal.*; -import com.jogamp.gluegen.runtime.*; - -/** Helper class for managing OpenAL-related proc address tables. */ - -public class ALProcAddressLookup { - private static final ALProcAddressTable alTable = new ALProcAddressTable(); - private static volatile boolean alTableInitialized = false; - private static final ALCProcAddressTable alcTable = new ALCProcAddressTable(); - private static volatile boolean alcTableInitialized = false; - private static final DynamicLookup lookup = new DynamicLookup(); - private static volatile NativeLibrary openAL = null; - - static class DynamicLookup implements DynamicLookupHelper { - public long dynamicLookupFunction(String functionName) { - // At some point this may require an OpenAL context to be - // current as we will actually use alGetProcAddress. Since - // this routine is currently broken and there are no - // per-context function pointers anyway we could actually do - // this work anywhere. - if (openAL == null) { - // We choose not to search the system path first because we - // bundle a very recent version of OpenAL which we would like - // to override existing installations - openAL = NativeLibrary.open("OpenAL32", "openal", "OpenAL", - false, - ALProcAddressLookup.class.getClassLoader()); - if (openAL == null) { - throw new RuntimeException("Unable to find and load OpenAL library"); - } - } - return openAL.dynamicLookupFunction(functionName); - } - } - - public static void resetALProcAddressTable() { - if (!alTableInitialized) { - synchronized (ALProcAddressLookup.class) { - if (!alTableInitialized) { - // At some point this may require an OpenAL context to be - // current as we will actually use alGetProcAddress. Since - // this routine is currently broken and there are no - // per-context function pointers anyway we could actually do - // this work anywhere. We should also in theory have - // per-ALcontext ALProcAddressTables and per-ALCdevice - // ALCProcAddressTables. - ProcAddressHelper.resetProcAddressTable(alTable, lookup); - - // The above only manages to find addresses for the core OpenAL - // functions. The below uses alGetProcAddress() to find the addresses - // of extensions such as EFX, just as in the C++ examples of the - // OpenAL 1.1 SDK. - useALGetProcAddress(); - - alTableInitialized = true; - } - } - } - } - - public static void resetALCProcAddressTable() { - if (!alcTableInitialized) { - synchronized (ALProcAddressLookup.class) { - if (!alcTableInitialized) { - // At some point this may require an OpenAL device to be - // created as we will actually use alcGetProcAddress. Since - // this routine is currently broken and there are no - // per-device function pointers anyway we could actually do - // this work anywhere. We should also in theory have - // per-ALcontext ALProcAddressTables and per-ALCdevice - // ALCProcAddressTables. - ProcAddressHelper.resetProcAddressTable(alcTable, lookup); - alcTableInitialized = true; - } - } - } - } - - public static ALProcAddressTable getALProcAddressTable() { - return alTable; - } - - public static ALCProcAddressTable getALCProcAddressTable() { - return alcTable; - } - - - /** - * Retrieves the values of the OpenAL functions using alGetProcAddress(). - */ - private static void useALGetProcAddress() { - String addrOfPrefix = "_addressof_"; - ALImpl al = (ALImpl) ALFactory.getAL(); - - Field[] fields = ALProcAddressTable.class.getFields(); - for (int i = 0; i < fields.length; i++) { - Field field = fields[i]; - - // Skip non-address fields - String fieldname = field.getName(); - if (!fieldname.startsWith(addrOfPrefix)) { - continue; - } - try { - String functionname = fieldname.substring(addrOfPrefix.length()); - long fieldval = field.getLong(alTable); - - // Skip fields which have already been valued - if (fieldval != 0) { - continue; - } - - // Get the address - long procAddressVal = al.alGetProcAddress(functionname); - field.setLong(alTable, procAddressVal); - } - catch (Exception ex) { - throw new RuntimeException("Unable to repopulate ALProcAddressTable values", ex); - } - } - } -} diff --git a/src/java/net/java/games/joal/impl/NativeLibLoader.java b/src/java/net/java/games/joal/impl/NativeLibLoader.java deleted file mode 100755 index 4b81794..0000000 --- a/src/java/net/java/games/joal/impl/NativeLibLoader.java +++ /dev/null @@ -1,114 +0,0 @@ -/* - * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * - Redistribution of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * - Redistribution 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 Sun Microsystems, Inc. or the names of - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * This software is provided "AS IS," without a warranty of any kind. ALL - * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, - * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A - * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN - * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR - * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR - * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR - * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR - * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE - * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, - * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF - * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. - * - * You acknowledge that this software is not designed or intended for use - * in the design, construction, operation or maintenance of any nuclear - * facility. - */ - -package net.java.games.joal.impl; - -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.security.*; - -import com.jogamp.gluegen.runtime.*; - -public class NativeLibLoader { - private static volatile boolean loadingEnabled = true; - private static volatile boolean didLoading; - - private NativeLibLoader() {} - - public static void disableLoading() { - loadingEnabled = false; - } - - public static void enableLoading() { - loadingEnabled = true; - } - - public static void load() { - if (!didLoading && loadingEnabled) { - synchronized (NativeLibLoader.class) { - if (!didLoading && loadingEnabled) { - didLoading = true; - AccessController.doPrivileged(new PrivilegedAction() { - public Object run() { - // Workaround for problem in OpenAL32.dll, which is actually - // the "wrapper" DLL which looks for real OpenAL - // implementations like nvopenal.dll and "*oal.dll". - // joal.dll matches this wildcard and a bug in OpenAL32.dll - // causes a call through a null function pointer. - loadLibraryInternal("joal_native"); - - // Workaround for 4845371. - // Make sure the first reference to the JNI GetDirectBufferAddress is done - // from a privileged context so the VM's internal class lookups will succeed. - // FIXME: need to figure out an appropriate entry point to call for JOAL - // JAWT jawt = new JAWT(); - // JAWTFactory.JAWT_GetAWT(jawt); - - return null; - } - }); - } - } - } - } - - private static void loadLibraryInternal(String libraryName) { - String sunAppletLauncher = System.getProperty("sun.jnlp.applet.launcher"); - boolean usingJNLPAppletLauncher = Boolean.valueOf(sunAppletLauncher).booleanValue(); - - if (usingJNLPAppletLauncher) { - try { - Class jnlpAppletLauncherClass = Class.forName("org.jdesktop.applet.util.JNLPAppletLauncher"); - Method jnlpLoadLibraryMethod = jnlpAppletLauncherClass.getDeclaredMethod("loadLibrary", new Class[] { String.class }); - jnlpLoadLibraryMethod.invoke(null, new Object[] { libraryName }); - } catch (Exception e) { - Throwable t = e; - if (t instanceof InvocationTargetException) { - t = ((InvocationTargetException) t).getTargetException(); - } - if (t instanceof Error) - throw (Error) t; - if (t instanceof RuntimeException) { - throw (RuntimeException) t; - } - // Throw UnsatisfiedLinkError for best compatibility with System.loadLibrary() - throw (UnsatisfiedLinkError) new UnsatisfiedLinkError().initCause(e); - } - } else { - System.loadLibrary(libraryName); - } - } -} diff --git a/src/java/net/java/games/joal/util/ALut.java b/src/java/net/java/games/joal/util/ALut.java deleted file mode 100644 index 5d1746f..0000000 --- a/src/java/net/java/games/joal/util/ALut.java +++ /dev/null @@ -1,146 +0,0 @@ -/** -* Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. -* -* Redistribution and use in source and binary forms, with or without -* modification, are permitted provided that the following conditions are met: -* -* -Redistribution of source code must retain the above copyright notice, -* this list of conditions and the following disclaimer. -* -* -Redistribution 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 Sun Microsystems, Inc. or the names of contributors may -* be used to endorse or promote products derived from this software without -* specific prior written permission. -* -* This software is provided "AS IS," without a warranty of any kind. -* ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING -* ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR -* NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND ITS -* LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A -* RESULT OF USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. -* IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT -* OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR -* PUNITIVE DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, -* ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF SUN HAS -* BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. -* -* You acknowledge that this software is not designed or intended for use in the -* design, construction, operation or maintenance of any nuclear facility. -* -* Created on Jun 27, 2003 -*/ - -package net.java.games.joal.util; - -import java.io.*; -import java.nio.ByteBuffer; - -import javax.sound.sampled.UnsupportedAudioFileException; - -import net.java.games.joal.*; - -/** - * @author Athomas Goldberg - * - */ -public final class ALut { - - private static ALC alc; - private static ALCdevice device; - private static ALCcontext context; - private static Thread initializingThread; - - private ALut() { } - - /** Initializes the OpenAL Utility Toolkit, creates an OpenAL - context and makes it current on the current thread. The ALut may - only be initialized on one thread at any given time. */ - public static synchronized void alutInit() throws ALException { - if (context != null) { - throw new ALException("Already initialized on thread " + initializingThread.getName()); - } - if (alc == null) { - alc = ALFactory.getALC(); - } - String deviceName = null; - ALCdevice d = alc.alcOpenDevice(deviceName); - if (d == null) { - throw new ALException("Error opening default OpenAL device"); - } - ALCcontext c = alc.alcCreateContext(d, null); - if (c == null) { - alc.alcCloseDevice(d); - throw new ALException("Error creating OpenAL context"); - } - alc.alcMakeContextCurrent(c); - if (alc.alcGetError(d) != 0) { - alc.alcDestroyContext(c); - alc.alcCloseDevice(d); - throw new ALException("Error making OpenAL context current"); - } - // Fully initialized; finish setup - device = d; - context = c; - initializingThread = Thread.currentThread(); - } - - /** Shuts down the OpenAL Utility Toolkit; releases and destroys the - internal OpenAL context and closes the output device. Must be - called from the same thread as alutInit(). Most applications - should not need to call this; only those which wish to toggle - sound on / off at run time by initializing and un-initializing - OpenAL need to call it. */ - public static synchronized void alutExit() throws ALException { - if (context == null) { - throw new ALException("Not initialized"); - } - alc.alcMakeContextCurrent(null); - alc.alcDestroyContext(context); - alc.alcCloseDevice(device); - context = null; - device = null; - initializingThread = null; - } - - public static void alutLoadWAVFile(String fileName, - int[] format, - ByteBuffer[] data, - int[] size, - int[] freq, - int[] loop) throws ALException { - try { - WAVData wd = WAVLoader.loadFromFile(fileName); - format[0] = wd.format; - data[0] = wd.data; - size[0] = wd.size; - freq[0] = wd.freq; - loop[0] = wd.loop ? AL.AL_TRUE : AL.AL_FALSE; - } catch (Exception e) { - throw new ALException(e); - } - } - - public static void alutLoadWAVFile(InputStream stream, - int[] format, - ByteBuffer[] data, - int[] size, - int[] freq, - int[] loop) throws ALException { - try { - if (!(stream instanceof BufferedInputStream)) { - stream = new BufferedInputStream(stream); - } - WAVData wd = WAVLoader.loadFromStream(stream); - format[0] = wd.format; - data[0] = wd.data; - size[0] = wd.size; - freq[0] = wd.freq; - loop[0] = wd.loop ? AL.AL_TRUE : AL.AL_FALSE; - } catch (Exception e) { - throw new ALException(e); - } - } -} diff --git a/src/java/net/java/games/joal/util/BufferUtils.java b/src/java/net/java/games/joal/util/BufferUtils.java deleted file mode 100644 index 05de65a..0000000 --- a/src/java/net/java/games/joal/util/BufferUtils.java +++ /dev/null @@ -1,266 +0,0 @@ -/* - * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * - Redistribution of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * - Redistribution 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 Sun Microsystems, Inc. or the names of - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * This software is provided "AS IS," without a warranty of any kind. ALL - * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, - * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A - * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN - * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR - * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR - * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR - * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR - * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE - * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, - * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF - * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. - * - * You acknowledge that this software is not designed or intended for use - * in the design, construction, operation or maintenance of any nuclear - * facility. - * - * Sun gratefully acknowledges that this software was originally authored - * and developed by Kenneth Bradley Russell and Christopher John Kline. - */ - -package net.java.games.joal.util; - -import java.nio.*; -import java.util.*; - -/** Utility routines for dealing with direct buffers. */ - -public class BufferUtils { - public static final int SIZEOF_BYTE = 1; - public static final int SIZEOF_SHORT = 2; - public static final int SIZEOF_INT = 4; - public static final int SIZEOF_FLOAT = 4; - public static final int SIZEOF_LONG = 8; - public static final int SIZEOF_DOUBLE = 8; - - //---------------------------------------------------------------------- - // Allocation routines - // - - /** Allocates a new direct ByteBuffer with the specified number of - elements. The returned buffer will have its byte order set to - the host platform's native byte order. */ - public static ByteBuffer newByteBuffer(int numElements) { - ByteBuffer bb = ByteBuffer.allocateDirect(numElements); - bb.order(ByteOrder.nativeOrder()); - return bb; - } - - /** Allocates a new direct DoubleBuffer with the specified number of - elements. The returned buffer will have its byte order set to - the host platform's native byte order. */ - public static DoubleBuffer newDoubleBuffer(int numElements) { - ByteBuffer bb = newByteBuffer(numElements * SIZEOF_DOUBLE); - return bb.asDoubleBuffer(); - } - - /** Allocates a new direct FloatBuffer with the specified number of - elements. The returned buffer will have its byte order set to - the host platform's native byte order. */ - public static FloatBuffer newFloatBuffer(int numElements) { - ByteBuffer bb = newByteBuffer(numElements * SIZEOF_FLOAT); - return bb.asFloatBuffer(); - } - - /** Allocates a new direct IntBuffer with the specified number of - elements. The returned buffer will have its byte order set to - the host platform's native byte order. */ - public static IntBuffer newIntBuffer(int numElements) { - ByteBuffer bb = newByteBuffer(numElements * SIZEOF_INT); - return bb.asIntBuffer(); - } - - /** Allocates a new direct LongBuffer with the specified number of - elements. The returned buffer will have its byte order set to - the host platform's native byte order. */ - public static LongBuffer newLongBuffer(int numElements) { - ByteBuffer bb = newByteBuffer(numElements * SIZEOF_LONG); - return bb.asLongBuffer(); - } - - /** Allocates a new direct ShortBuffer with the specified number of - elements. The returned buffer will have its byte order set to - the host platform's native byte order. */ - public static ShortBuffer newShortBuffer(int numElements) { - ByteBuffer bb = newByteBuffer(numElements * SIZEOF_SHORT); - return bb.asShortBuffer(); - } - - //---------------------------------------------------------------------- - // Copy routines (type-to-type) - // - - /** Copies the remaining elements (as defined by - limit() - position()) in the passed ByteBuffer into - a newly-allocated direct ByteBuffer. The returned buffer will - have its byte order set to the host platform's native byte - order. The position of the newly-allocated buffer will be zero, - and the position of the passed buffer is unchanged (though its - mark is changed). */ - public static ByteBuffer copyByteBuffer(ByteBuffer orig) { - ByteBuffer dest = newByteBuffer(orig.remaining()); - orig.mark(); - dest.put(orig); - orig.reset(); - dest.rewind(); - return dest; - } - - /** Copies the remaining elements (as defined by - limit() - position()) in the passed DoubleBuffer - into a newly-allocated direct DoubleBuffer. The returned buffer - will have its byte order set to the host platform's native byte - order. The position of the newly-allocated buffer will be zero, - and the position of the passed buffer is unchanged (though its - mark is changed). */ - public static DoubleBuffer copyDoubleBuffer(DoubleBuffer orig) { - return copyDoubleBufferAsByteBuffer(orig).asDoubleBuffer(); - } - - /** Copies the remaining elements (as defined by - limit() - position()) in the passed FloatBuffer - into a newly-allocated direct FloatBuffer. The returned buffer - will have its byte order set to the host platform's native byte - order. The position of the newly-allocated buffer will be zero, - and the position of the passed buffer is unchanged (though its - mark is changed). */ - public static FloatBuffer copyFloatBuffer(FloatBuffer orig) { - return copyFloatBufferAsByteBuffer(orig).asFloatBuffer(); - } - - /** Copies the remaining elements (as defined by - limit() - position()) in the passed IntBuffer - into a newly-allocated direct IntBuffer. The returned buffer - will have its byte order set to the host platform's native byte - order. The position of the newly-allocated buffer will be zero, - and the position of the passed buffer is unchanged (though its - mark is changed). */ - public static IntBuffer copyIntBuffer(IntBuffer orig) { - return copyIntBufferAsByteBuffer(orig).asIntBuffer(); - } - - /** Copies the remaining elements (as defined by - limit() - position()) in the passed LongBuffer - into a newly-allocated direct LongBuffer. The returned buffer - will have its byte order set to the host platform's native byte - order. The position of the newly-allocated buffer will be zero, - and the position of the passed buffer is unchanged (though its - mark is changed). */ - public static LongBuffer copyLongBuffer(LongBuffer orig) { - return copyLongBufferAsByteBuffer(orig).asLongBuffer(); - } - - /** Copies the remaining elements (as defined by - limit() - position()) in the passed ShortBuffer - into a newly-allocated direct ShortBuffer. The returned buffer - will have its byte order set to the host platform's native byte - order. The position of the newly-allocated buffer will be zero, - and the position of the passed buffer is unchanged (though its - mark is changed). */ - public static ShortBuffer copyShortBuffer(ShortBuffer orig) { - return copyShortBufferAsByteBuffer(orig).asShortBuffer(); - } - - //---------------------------------------------------------------------- - // Copy routines (type-to-ByteBuffer) - // - - /** Copies the remaining elements (as defined by - limit() - position()) in the passed DoubleBuffer - into a newly-allocated direct ByteBuffer. The returned buffer - will have its byte order set to the host platform's native byte - order. The position of the newly-allocated buffer will be zero, - and the position of the passed buffer is unchanged (though its - mark is changed). */ - public static ByteBuffer copyDoubleBufferAsByteBuffer(DoubleBuffer orig) { - ByteBuffer dest = newByteBuffer(orig.remaining() * SIZEOF_DOUBLE); - orig.mark(); - dest.asDoubleBuffer().put(orig); - orig.reset(); - dest.rewind(); - return dest; - } - - /** Copies the remaining elements (as defined by - limit() - position()) in the passed FloatBuffer - into a newly-allocated direct ByteBuffer. The returned buffer - will have its byte order set to the host platform's native byte - order. The position of the newly-allocated buffer will be zero, - and the position of the passed buffer is unchanged (though its - mark is changed). */ - public static ByteBuffer copyFloatBufferAsByteBuffer(FloatBuffer orig) { - ByteBuffer dest = newByteBuffer(orig.remaining() * SIZEOF_FLOAT); - orig.mark(); - dest.asFloatBuffer().put(orig); - orig.reset(); - dest.rewind(); - return dest; - } - - /** Copies the remaining elements (as defined by - limit() - position()) in the passed IntBuffer into - a newly-allocated direct ByteBuffer. The returned buffer will - have its byte order set to the host platform's native byte - order. The position of the newly-allocated buffer will be zero, - and the position of the passed buffer is unchanged (though its - mark is changed). */ - public static ByteBuffer copyIntBufferAsByteBuffer(IntBuffer orig) { - ByteBuffer dest = newByteBuffer(orig.remaining() * SIZEOF_INT); - orig.mark(); - dest.asIntBuffer().put(orig); - orig.reset(); - dest.rewind(); - return dest; - } - - /** Copies the remaining elements (as defined by - limit() - position()) in the passed LongBuffer into - a newly-allocated direct ByteBuffer. The returned buffer will - have its byte order set to the host platform's native byte - order. The position of the newly-allocated buffer will be zero, - and the position of the passed buffer is unchanged (though its - mark is changed). */ - public static ByteBuffer copyLongBufferAsByteBuffer(LongBuffer orig) { - ByteBuffer dest = newByteBuffer(orig.remaining() * SIZEOF_LONG); - orig.mark(); - dest.asLongBuffer().put(orig); - orig.reset(); - dest.rewind(); - return dest; - } - - /** Copies the remaining elements (as defined by - limit() - position()) in the passed ShortBuffer - into a newly-allocated direct ByteBuffer. The returned buffer - will have its byte order set to the host platform's native byte - order. The position of the newly-allocated buffer will be zero, - and the position of the passed buffer is unchanged (though its - mark is changed). */ - public static ByteBuffer copyShortBufferAsByteBuffer(ShortBuffer orig) { - ByteBuffer dest = newByteBuffer(orig.remaining() * SIZEOF_SHORT); - orig.mark(); - dest.asShortBuffer().put(orig); - orig.reset(); - dest.rewind(); - return dest; - } -} diff --git a/src/java/net/java/games/joal/util/WAVData.java b/src/java/net/java/games/joal/util/WAVData.java deleted file mode 100644 index c0584e9..0000000 --- a/src/java/net/java/games/joal/util/WAVData.java +++ /dev/null @@ -1,75 +0,0 @@ -/** -* Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. -* -* Redistribution and use in source and binary forms, with or without -* modification, are permitted provided that the following conditions are met: -* -* -Redistribution of source code must retain the above copyright notice, -* this list of conditions and the following disclaimer. -* -* -Redistribution 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 Sun Microsystems, Inc. or the names of contributors may -* be used to endorse or promote products derived from this software without -* specific prior written permission. -* -* This software is provided "AS IS," without a warranty of any kind. -* ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING -* ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR -* NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND ITS -* LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A -* RESULT OF USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. -* IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT -* OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR -* PUNITIVE DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, -* ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF SUN HAS -* BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. -* -* You acknowledge that this software is not designed or intended for use in the -* design, construction, operation or maintenance of any nuclear facility. -*/ - -package net.java.games.joal.util; - -import java.nio.ByteBuffer; - - -/** - * This class is a holder for WAV (.wav )file Data returned from the WavLoader - * - * @author Athomas Goldberg - */ -public final class WAVData { - /** The audio data */ - public final ByteBuffer data; - - /** the format of the Data. One of: - *
-     * AL.AL_FORMAT_MONO8
-     * AL.AL_FORMAT_MONO16
-     * AL.AL_FORMAT_STEREO8
-     * AL.AL_FORMAT_STEREO16
-     * 
- * - */ - public final int format; - - /** Size (in bytes) of the data */ - public final int size; - - /** The frequency of the data */ - public final int freq; - - /** flag indicating whether or not the sound in the data should loop */ - public final boolean loop; - - WAVData(ByteBuffer data, int format, int size, int freq, boolean loop) { - this.data = data; - this.format = format; - this.size = size; - this.freq = freq; - this.loop = loop; - } -} diff --git a/src/java/net/java/games/joal/util/WAVLoader.java b/src/java/net/java/games/joal/util/WAVLoader.java deleted file mode 100644 index e7a5257..0000000 --- a/src/java/net/java/games/joal/util/WAVLoader.java +++ /dev/null @@ -1,135 +0,0 @@ -/** -* Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. -* -* Redistribution and use in source and binary forms, with or without -* modification, are permitted provided that the following conditions are met: -* -* -Redistribution of source code must retain the above copyright notice, -* this list of conditions and the following disclaimer. -* -* -Redistribution 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 Sun Microsystems, Inc. or the names of contributors may -* be used to endorse or promote products derived from this software without -* specific prior written permission. -* -* This software is provided "AS IS," without a warranty of any kind. -* ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING -* ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR -* NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND ITS -* LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A -* RESULT OF USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. -* IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT -* OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR -* PUNITIVE DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, -* ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF SUN HAS -* BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. -* -* You acknowledge that this software is not designed or intended for use in the -* design, construction, operation or maintenance of any nuclear facility. -*/ - -package net.java.games.joal.util; - -import java.io.*; -import java.nio.*; -import java.nio.channels.*; -import javax.sound.sampled.*; - -import net.java.games.joal.*; - -/** - * A Loader utility for (.wav) files. Creates a WAVData object containing the - * data used by the AL.alBufferData method. - * - * @author Athomas Goldberg - */ -public class WAVLoader implements ALConstants { - private static final int BUFFER_SIZE = 128000; - - /** - * This method loads a (.wav) file into a WAVData object. - * - * @param filename The name of the (.wav) file - * - * @return a WAVData object containing the audio data - * - * @throws UnsupportedAudioFileException if the format of the audio if not - * supported. - * @throws IOException If the file can no be found or some other IO error - * occurs - */ - public static WAVData loadFromFile(String filename) - throws UnsupportedAudioFileException, IOException { - WAVData result = null; - File soundFile = new File(filename); - AudioInputStream aIn = AudioSystem.getAudioInputStream(soundFile); - return readFromStream(aIn); - } - - /** - * This method loads a (.wav) file into a WAVData object. - * - * @param stream An InputStream for the .WAV file. - * - * @return a WAVData object containing the audio data - * - * @throws UnsupportedAudioFileException if the format of the audio if not - * supported. - * @throws IOException If the file can no be found or some other IO error - * occurs - */ - public static WAVData loadFromStream(InputStream stream) - throws UnsupportedAudioFileException, IOException { - WAVData result = null; - AudioInputStream aIn = AudioSystem.getAudioInputStream(stream); - return readFromStream(aIn); - } - - - private static WAVData readFromStream(AudioInputStream aIn) - throws UnsupportedAudioFileException, IOException { - ReadableByteChannel aChannel = Channels.newChannel(aIn); - AudioFormat fmt = aIn.getFormat(); - int numChannels = fmt.getChannels(); - int bits = fmt.getSampleSizeInBits(); - int format = AL_FORMAT_MONO8; - - if ((bits == 8) && (numChannels == 1)) { - format = AL_FORMAT_MONO8; - } else if ((bits == 16) && (numChannels == 1)) { - format = AL_FORMAT_MONO16; - } else if ((bits == 8) && (numChannels == 2)) { - format = AL_FORMAT_STEREO8; - } else if ((bits == 16) && (numChannels == 2)) { - format = AL_FORMAT_STEREO16; - } - - int freq = Math.round(fmt.getSampleRate()); - int size = aIn.available(); - ByteBuffer buffer = ByteBuffer.allocateDirect(size); - while (buffer.remaining() > 0) { - aChannel.read(buffer); - } - buffer.rewind(); - - // Must byte swap on big endian platforms - // Thanks to swpalmer on javagaming.org forums for hint at fix - if ((bits == 16) && (ByteOrder.nativeOrder() == ByteOrder.BIG_ENDIAN)) { - int len = buffer.remaining(); - for (int i = 0; i < len; i += 2) { - byte a = buffer.get(i); - byte b = buffer.get(i+1); - buffer.put(i, b); - buffer.put(i+1, a); - } - } - - WAVData result = new WAVData(buffer, format, size, freq, false); - aIn.close(); - - return result; - } -} diff --git a/src/java/net/java/games/sound3d/AudioSystem3D.java b/src/java/net/java/games/sound3d/AudioSystem3D.java deleted file mode 100644 index 91fd45a..0000000 --- a/src/java/net/java/games/sound3d/AudioSystem3D.java +++ /dev/null @@ -1,273 +0,0 @@ -/** - * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * -Redistribution of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - * -Redistribution 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 Sun Microsystems, Inc. or the names of contributors may - * be used to endorse or promote products derived from this software without - * specific prior written permission. - * - * This software is provided "AS IS," without a warranty of any kind. - * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING - * ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR - * NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND ITS - * LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A - * RESULT OF USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. - * IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT - * OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR - * PUNITIVE DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, - * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF SUN HAS - * BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. - * - * You acknowledge that this software is not designed or intended for use in the - * design, construction, operation or maintenance of any nuclear facility. - */ - -package net.java.games.sound3d; - -import net.java.games.joal.*; -import net.java.games.joal.util.WAVData; -import net.java.games.joal.util.WAVLoader; - -import java.io.*; - -import javax.sound.sampled.UnsupportedAudioFileException; - - -/** - * The AudioSystem3D class provides a set of methods for creating and - * manipulating a 3D audio environment. - * - * @author Athomas Goldberg - */ -public class AudioSystem3D { - private static AL al; - private static ALC alc; - private static Listener listener; - - /** - * Iniitalize the Sound3D environment. This must be called before - * other methods in the class can be used. - */ - public static void init() throws ALException { - al = ALFactory.getAL(); - alc = ALFactory.getALC(); - } - - /** - * Creates a new Sound3D Context for a specified device. - * - * @param device The device the Context is being created for. - * - * @return The new Sound3D context. - */ - public static Context createContext(Device device) { - Context result = null; - ALCcontext realContext = alc.alcCreateContext(device.realDevice, null); - result = new Context(alc, realContext, device); - return result; - } - - /** - * Makes the specified context the current context. - * - * @param context the context to make current. - */ - public static void makeContextCurrent(Context context) { - ALCcontext realContext = null; - - if (context != null) { - realContext = context.realContext; - } - - alc.alcMakeContextCurrent(realContext); - } - - /** - * Opens the specifified audio device. - * - * @param deviceName The specified device name, On windows this will be - * DirectSound3D. We will be automating device discovery in upcoming versions - * of this class. - * - * @return The device described by the specifed name. - */ - public static Device openDevice(String deviceName) { - Device result = null; - ALCdevice realDevice = alc.alcOpenDevice(deviceName); - result = new Device(alc, realDevice); - - return result; - } - - /** - * Generate an array of Sound3D buffers. - * - * @param numBuffers The number of Sound3D buffers to generate. - * - * @return an array of (initially enpty) Sound3D buffers. - */ - public static Buffer[] generateBuffers(int numBuffers) { - Buffer[] result = new Buffer[numBuffers]; - int[] arr = new int[numBuffers]; - al.alGenBuffers(numBuffers, arr, 0); - - for (int i = 0; i < numBuffers; i++) { - result[i] = new Buffer(al, arr[i]); - } - - return result; - } - - /** - * Loads a Sound3D buffer with the specified audio file. - * - * @param filename the name of the file to load. - * - * @return a new Sound3D buffer containing the audio data from the - * specified file. - * - * @throws IOException If the file cannot be found or some other IO error - * occurs. - * @throws UnsupportedAudioFileException If the format of the audio data is - * not supported - */ - public static Buffer loadBuffer(String filename) - throws IOException, UnsupportedAudioFileException { - Buffer result; - Buffer[] tmp = generateBuffers(1); - result = tmp[0]; - - WAVData wd = WAVLoader.loadFromFile(filename); - result.configure(wd.data, wd.format, wd.freq); - - return result; - } - - /** - * Loads a Sound3D buffer with the specified audio file. - * - * @param stream contains the stream associated with the audio file. - * - * @return a new Sound3D buffer containing the audio data from the - * passed stream. - * - * @throws IOException If the stream cannot be read or some other IO error - * occurs. - * @throws UnsupportedAudioFileException If the format of the audio data is - * not supported - */ - public static Buffer loadBuffer(InputStream stream) - throws IOException, UnsupportedAudioFileException { - Buffer result; - Buffer[] tmp = generateBuffers(1); - result = tmp[0]; - - if (!(stream instanceof BufferedInputStream)) { - stream = new BufferedInputStream(stream); - } - WAVData wd = WAVLoader.loadFromStream(stream); - - result.configure(wd.data, wd.format, wd.freq); - - return result; - } - - /** - * Loads a Sound3D Source with the specified audio file. This is - * functionally equivalent to generateSource(loadBuffer(fileName)); - * - * @param filename the name of the file to load. - * - * @return a new Sound3D Source containing the audio data from the - * specified file. - * - * @throws IOException If the file cannot be found or some other IO error - * occurs. - * @throws UnsupportedAudioFileException If the format of the audio data is - * not supported - */ - public static Source loadSource(String filename) - throws IOException, UnsupportedAudioFileException { - Buffer buffer = loadBuffer(filename); - - return generateSource(buffer); - } - - /** - * Loads a Sound3D Source with the specified audio stream. This is - * functionally equivalent to generateSource(loadBuffer(stream)); - * - * @param stream contains the stream associated with the audio file. - * - * @return a new Sound3D Source containing the audio data from the - * passed stream. - * - * @throws IOException If the file cannot be found or some other IO error - * occurs. - * @throws UnsupportedAudioFileException If the format of the audio data is - * not supported - */ - public static Source loadSource(InputStream stream) - throws IOException, UnsupportedAudioFileException { - Buffer buffer = loadBuffer(stream); - - return generateSource(buffer); - } - - /** - * Generates a set of uninitialized Source3D sources - * - * @param numSources the number of Sound3D sources to generate. - * - * @return an array of uninitialized sources. - */ - public static Source[] generateSources(int numSources) { - Source[] result = new Source[numSources]; - int[] arr = new int[numSources]; - al.alGenSources(numSources, arr, 0); - - for (int i = 0; i < numSources; i++) { - result[i] = new Source(al, arr[i]); - } - - return result; - } - - /** - * Generate a Sound3D source from an initialized Buffer. - * - * @param buff The buffer to generate the source from. - * - * @return the newly generated Source. - */ - public static Source generateSource(Buffer buff) { - Source result = null; - Source[] tmp = generateSources(1); - result = tmp[0]; - result.setBuffer(buff); - - return result; - } - - /** - * Get the listener object associated with this Sound3D environment. - * - * @return The listener object. - */ - public static Listener getListener() { - if (listener == null) { - listener = new Listener(al); - } - - return listener; - } -} diff --git a/src/java/net/java/games/sound3d/Buffer.java b/src/java/net/java/games/sound3d/Buffer.java deleted file mode 100644 index 97f67d2..0000000 --- a/src/java/net/java/games/sound3d/Buffer.java +++ /dev/null @@ -1,144 +0,0 @@ -/** -* Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. -* -* Redistribution and use in source and binary forms, with or without -* modification, are permitted provided that the following conditions are met: -* -* -Redistribution of source code must retain the above copyright notice, -* this list of conditions and the following disclaimer. -* -* -Redistribution 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 Sun Microsystems, Inc. or the names of contributors may -* be used to endorse or promote products derived from this software without -* specific prior written permission. -* -* This software is provided "AS IS," without a warranty of any kind. -* ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING -* ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR -* NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND ITS -* LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A -* RESULT OF USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. -* IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT -* OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR -* PUNITIVE DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, -* ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF SUN HAS -* BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. -* -* You acknowledge that this software is not designed or intended for use in the -* design, construction, operation or maintenance of any nuclear facility. -*/ - -package net.java.games.sound3d; - -import net.java.games.joal.AL; - -import java.nio.ByteBuffer; - - -/** - * The Sound3D Buffer is a container for audio data used in the Sound3D - * environment. - * - * @author Athomas Goldberg - */ -public class Buffer { - public final static int FORMAT_MONO8 = AL.AL_FORMAT_MONO8; - - public final static int FORMAT_MONO16 = AL.AL_FORMAT_MONO16; - - public final static int FORMAT_STEREO8 = AL.AL_FORMAT_STEREO8; - - public final static int FORMAT_STEREO16 = AL.AL_FORMAT_STEREO16; - final int bufferID; - private ByteBuffer data; - private boolean isConfigured = false; - private final AL al; - - Buffer(AL al, int bufferID) { - this.bufferID = bufferID; - this.al = al; - } - - /** - * Configure the Sound3D buffer - * - * @param data the raw audio data - * @param format the format of the data: FORMAT_MONO8, FORMAT_MONO16, - * FORMAT_STEREO8 and FORMAT_STEREO16 - * @param freq the frequency of the data - */ - public void configure(ByteBuffer data, int format, int freq) { - if (!isConfigured) { - this.data = data; - al.alBufferData(bufferID, format, data, data.capacity(), freq); - } - } - - /** - * Delete this buffer, and free its resources. - */ - public void delete() { - data = null; - al.alDeleteBuffers(1, new int[] { bufferID }, 0); - } - - /** - * Get the bit-depth of the data, (8 or 16) - * - * @return the bit-depth of the data - */ - public int getBitDepth() { - int[] i = new int[1]; - al.alGetBufferi(bufferID, AL.AL_BITS, i, 0); - - return i[0]; - } - - /** - * Get the number of channels of the data (1-Mono, 2-Stereo) - * - * @return the number of audio channels. - */ - public int getNumChannels() { - int[] i = new int[1]; - al.alGetBufferi(bufferID, AL.AL_CHANNELS, i, 0); - - return i[0]; - } - - /** - * Gets the raw data contained in this buffer. - * - * @return the raw buffer data. - */ - public ByteBuffer getData() { - return data; - } - - /** - * Gets the audio frequency of the data contained in this buffer. - * - * @return the frequency of the data - */ - public int getFrequency() { - int[] i = new int[1]; - al.alGetBufferi(bufferID, AL.AL_FREQUENCY, i, 0); - - return i[0]; - } - - /** - * Gets the size (in bytes) of the raw data containe in this buffer. - * - * @return the size of the data. - */ - public int getSize() { - int[] i = new int[1]; - al.alGetBufferi(bufferID, AL.AL_SIZE, i, 0); - - return i[0]; - } -} diff --git a/src/java/net/java/games/sound3d/Context.java b/src/java/net/java/games/sound3d/Context.java deleted file mode 100644 index 49344cd..0000000 --- a/src/java/net/java/games/sound3d/Context.java +++ /dev/null @@ -1,77 +0,0 @@ -/** -* Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. -* -* Redistribution and use in source and binary forms, with or without -* modification, are permitted provided that the following conditions are met: -* -* -Redistribution of source code must retain the above copyright notice, -* this list of conditions and the following disclaimer. -* -* -Redistribution 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 Sun Microsystems, Inc. or the names of contributors may -* be used to endorse or promote products derived from this software without -* specific prior written permission. -* -* This software is provided "AS IS," without a warranty of any kind. -* ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING -* ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR -* NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND ITS -* LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A -* RESULT OF USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. -* IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT -* OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR -* PUNITIVE DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, -* ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF SUN HAS -* BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. -* -* You acknowledge that this software is not designed or intended for use in the -* design, construction, operation or maintenance of any nuclear facility. -*/ - -package net.java.games.sound3d; - -import net.java.games.joal.*; - - -/** - * This class provides a Sound3D Context associated with a specified device. - * - * @author Athomas Goldberg - */ -public class Context { - private final ALC alc; - final ALCcontext realContext; - final Device device; - - Context(ALC alc, ALCcontext realContext, Device device) { - this.alc = alc; - this.realContext = realContext; - this.device = device; - } - - /** - * Suspend this context - */ - public void suspend() { - alc.alcSuspendContext(realContext); - } - - /** - * destroys this context freeing its resources. - */ - public void destroy() { - alc.alcDestroyContext(realContext); - } - - /** - * Gets the device associated with this context. - * - * @return the device associated with this context. - */ - public Device getDevice() { - return device; - } -} diff --git a/src/java/net/java/games/sound3d/Device.java b/src/java/net/java/games/sound3d/Device.java deleted file mode 100644 index 96c352b..0000000 --- a/src/java/net/java/games/sound3d/Device.java +++ /dev/null @@ -1,59 +0,0 @@ -/** -* Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. -* -* Redistribution and use in source and binary forms, with or without -* modification, are permitted provided that the following conditions are met: -* -* -Redistribution of source code must retain the above copyright notice, -* this list of conditions and the following disclaimer. -* -* -Redistribution 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 Sun Microsystems, Inc. or the names of contributors may -* be used to endorse or promote products derived from this software without -* specific prior written permission. -* -* This software is provided "AS IS," without a warranty of any kind. -* ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING -* ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR -* NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND ITS -* LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A -* RESULT OF USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. -* IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT -* OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR -* PUNITIVE DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, -* ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF SUN HAS -* BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. -* -* You acknowledge that this software is not designed or intended for use in the -* design, construction, operation or maintenance of any nuclear facility. -*/ - -package net.java.games.sound3d; - -import net.java.games.joal.*; - - -/** - * This class provides a handle to a specific audio device. - * - * @author Athomas Goldberg - */ -public class Device { - private final ALC alc; - final ALCdevice realDevice; - - Device(ALC alc, ALCdevice realDevice) { - this.alc = alc; - this.realDevice = realDevice; - } - - /** - * closes the device, freeing its resources. - */ - public void close() { - alc.alcCloseDevice(realDevice); - } -} diff --git a/src/java/net/java/games/sound3d/Listener.java b/src/java/net/java/games/sound3d/Listener.java deleted file mode 100644 index b25320c..0000000 --- a/src/java/net/java/games/sound3d/Listener.java +++ /dev/null @@ -1,171 +0,0 @@ -/** -* Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. -* -* Redistribution and use in source and binary forms, with or without -* modification, are permitted provided that the following conditions are met: -* -* -Redistribution of source code must retain the above copyright notice, -* this list of conditions and the following disclaimer. -* -* -Redistribution 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 Sun Microsystems, Inc. or the names of contributors may -* be used to endorse or promote products derived from this software without -* specific prior written permission. -* -* This software is provided "AS IS," without a warranty of any kind. -* ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING -* ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR -* NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND ITS -* LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A -* RESULT OF USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. -* IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT -* OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR -* PUNITIVE DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, -* ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF SUN HAS -* BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. -* -* You acknowledge that this software is not designed or intended for use in the -* design, construction, operation or maintenance of any nuclear facility. -*/ - -package net.java.games.sound3d; - -import net.java.games.joal.AL; - - -/** - * This class represents the human listener in the Sound3D environment. It - * provides methods for controlling the position, orientation as well as other - * properties associated with the listener. - * - * @author Athomas Goldberg - */ -public class Listener { - private final AL al; - - Listener(AL al) { - this.al = al; - } - - /** - * Sets the Gain, or volume of the audio in the environment relative to the - * listener - * - * @param gain the gain, or volume - */ - public void setGain(float gain) { - al.alListenerf(AL.AL_GAIN, gain); - } - - /** - * Gets the value of the gain, or volume of the audio in the environment - * relative to the listener. - * - * @return the gain value. - */ - public float getGain() { - float[] f = new float[1]; - al.alGetListenerf(AL.AL_GAIN, f, 0); - - return f[0]; - } - - /** - * Sets the position in (x-y-z coordinates) of the Listener in the Sound3D - * environment. - * - * @param x The position of the listener along the X-axis in the Sound3D - * environment - * @param y The position of the listener along the Y-axis in the Sound3D - * environment - * @param z The position of the listener along the Z-axis in the Sound3D - * environment - */ - public void setPosition(float x, float y, float z) { - al.alListener3f(AL.AL_POSITION, x, y, z); - } - - /** - * Sets the position in (x-y-z coordinates) of the Listener in the Sound3D - * environment. - * - * @param position a Vec3f object containing the x,y and z coordinates of - * Listener. - */ - public void setPosition(Vec3f position) { - al.alListener3f(AL.AL_POSITION, position.v1, position.v2, position.v3); - } - - /** - * Gets the position in (x-y-z coordinates) of the Listener in the Sound3D - * environment. - * - * @return a Vec3f object containing the x,y and z coordinates of - * Listener. - */ - public Vec3f getPosition() { - Vec3f result = null; - float[] tmp = new float[3]; - al.alGetListenerfv(AL.AL_POSITION, tmp, 0); - result = new Vec3f(tmp[0], tmp[1], tmp[2]); - - return result; - } - - /** - * Sets the velocity in (x-y-z coordinates) of the Listener in the Sound3D - * environment. Used in determining doppler shift. - * - * @param velocity a Vec3f object containing the velicity in - * x,y and z coordinates of Listener. - */ - public void setVelocity(Vec3f velocity) { - al.alListener3f(AL.AL_VELOCITY, velocity.v1, velocity.v2, velocity.v3); - } - - /** - * Gets the velocity in (x-y-z coordinates) of the Listener in the Sound3D - * environment. Used in determining doppler shift. - * - * @return a Vec3f object containing the velicity in - * x,y and z coordinates of Listener. - */ - public Vec3f getVelocity() { - Vec3f result = null; - float[] tmp = new float[3]; - al.alGetListenerfv(AL.AL_VELOCITY, tmp, 0); - result = new Vec3f(tmp[0], tmp[1], tmp[2]); - - return result; - } - - /** - * Sets the orientation of the Listener in the Sound3D environment. - * Orientation is expressed as "up" and "at" vectors. - * - * @param orientation The first 3 elements of the array should contain - * the x,y,z up-vector, the second 3 elements should contain the x,z,z - * look-at vector. - */ - public void setOrientation(float[] orientation) { - al.alListenerfv(AL.AL_ORIENTATION, orientation, 0); - } - - /** - * Gets the orientation of the Listener in the Sound3D environment. - * Orientation is expressed as "up" and "at" vectors. - * - * @return an array containing the orientation of the listener. - * The first 3 elements of the array contain - * the x,y,z up-vector, the second 3 elements contain the x,z,z - * look-at vector. - */ - public float[] getOrientation() { - float[] tmp = new float[6]; - al.alGetListenerfv(AL.AL_ORIENTATION, tmp, 0); - return tmp; - } -} diff --git a/src/java/net/java/games/sound3d/Source.java b/src/java/net/java/games/sound3d/Source.java deleted file mode 100644 index f5655be..0000000 --- a/src/java/net/java/games/sound3d/Source.java +++ /dev/null @@ -1,508 +0,0 @@ -/** -* Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. -* -* Redistribution and use in source and binary forms, with or without -* modification, are permitted provided that the following conditions are met: -* -* -Redistribution of source code must retain the above copyright notice, -* this list of conditions and the following disclaimer. -* -* -Redistribution 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 Sun Microsystems, Inc. or the names of contributors may -* be used to endorse or promote products derived from this software without -* specific prior written permission. -* -* This software is provided "AS IS," without a warranty of any kind. -* ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING -* ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR -* NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND ITS -* LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A -* RESULT OF USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. -* IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT -* OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR -* PUNITIVE DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, -* ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF SUN HAS -* BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. -* -* You acknowledge that this software is not designed or intended for use in the -* design, construction, operation or maintenance of any nuclear facility. -*/ - -package net.java.games.sound3d; - -import net.java.games.joal.AL; - -/** - * This class is used to represent sound-producing objects in the Sound3D - * environment. It contains methods for setting the position, direction, pitch, - * gain and other properties along with methods for starting, pausing, rewinding - * and stopping sudio projecting from a source. - * - * @author Athomas Goldberg - */ -public final class Source { - private final AL al; - private final int sourceID; - private Buffer buffer; - - Source(AL al, int sourceID) { - this.al = al; - this.sourceID = sourceID; - } - - /** - * Beginning playing the audio in this source. - */ - public void play() { - al.alSourcePlay(sourceID); - } - - /** - * pauses the audio in this Source. - */ - public void pause() { - al.alSourcePause(sourceID); - } - - /** - * Stops the audio in this Source - */ - public void stop() { - al.alSourceStop(sourceID); - } - - /** - * Rewinds the audio in this source - */ - public void rewind() { - al.alSourceRewind(sourceID); - } - - /** - * Delete this source, freeing its resources. - */ - public void delete() { - al.alDeleteSources(1, new int[] { sourceID }, 0); - } - - /** - * Sets the pitch of the audio on this source. The pitch may be modified - * without altering the playback speed of the audio. - * - * @param pitch the pitch value of this source. - */ - public void setPitch(float pitch) { - al.alSourcef(sourceID, AL.AL_PITCH, pitch); - } - - /** - * Gets the pitch of the audio on this source. The pitch may be modified - * without altering the playback speed of the audio. - * - * @return the pitch value of this source. - */ - public float getPitch() { - float[] result = new float[1]; - al.alGetSourcef(sourceID, AL.AL_PITCH, result, 0); - - return result[0]; - } - - /** - * Sets the gain of the audio on this source. This can be used to contro - * the volume of the source. - * - * @param gain the gain of the audio on this source - */ - public void setGain(float gain) { - al.alSourcef(sourceID, AL.AL_GAIN, gain); - } - - /** - * Gets the gain of the audio on this source. This can be used to contro - * the volume of the source. - * - * @return the gain of the audio on this source - */ - public float getGain() { - float[] result = new float[1]; - al.alGetSourcef(sourceID, AL.AL_GAIN, result, 0); - - return result[0]; - } - - /** - * Sets the max distance where there will no longer be any attenuation of - * the source. - * - * @param maxDistance the max ditance for source attentuation. - */ - public void setMaxDistance(float maxDistance) { - al.alSourcef(sourceID, AL.AL_MAX_DISTANCE, maxDistance); - } - - /** - * Gets the max distance where there will no longer be any attenuation of - * the source. - * - * @return the max ditance for source attentuation. - */ - public float getMaxDistance() { - float[] result = new float[1]; - al.alGetSourcef(sourceID, AL.AL_MAX_DISTANCE, result, 0); - - return result[0]; - } - - /** - * Sets the rolloff rate of the source. The default value is 1.0 - * - * @param rolloffFactor the rolloff rate of the source. - */ - public void setRolloffFactor(float rolloffFactor) { - al.alSourcef(sourceID, AL.AL_ROLLOFF_FACTOR, rolloffFactor); - } - - /** - * Gets the rolloff rate of the source. The default value is 1.0 - * - * @return the rolloff rate of the source. - */ - public float getRolloffFactor() { - float[] result = new float[1]; - al.alGetSourcef(sourceID, AL.AL_ROLLOFF_FACTOR, result, 0); - - return result[0]; - } - - /** - * Sets the distance under which the volume for the source would normally - * drop by half, before being influenced by rolloff factor or max distance. - * - * @param referenceDistance the reference distance for the source. - */ - public void setReferenceDistance(float referenceDistance) { - al.alSourcef(sourceID, AL.AL_REFERENCE_DISTANCE, referenceDistance); - } - - /** - * Gets the distance under which the volume for the source would normally - * drop by half, before being influenced by rolloff factor or max distance. - * - * @return the reference distance for the source. - */ - public float getReferenceDistance() { - float[] result = new float[1]; - al.alGetSourcef(sourceID, AL.AL_REFERENCE_DISTANCE, result, 0); - - return result[0]; - } - - /** - * Sets the minimum gain for this source. - * - * @param minGain the minimum gain for this source. - */ - public void setMinGain(float minGain) { - al.alSourcef(sourceID, AL.AL_MIN_GAIN, minGain); - } - - /** - * Gets the minimum gain for this source. - * - * @return the minimum gain for this source. - */ - public float getMinGain() { - float[] result = new float[1]; - al.alGetSourcef(sourceID, AL.AL_MIN_GAIN, result, 0); - - return result[0]; - } - - /** - * Sets the maximum gain for this source. - * - * @param maxGain the maximum gain for this source - */ - public void setMaxGain(float maxGain) { - al.alSourcef(sourceID, AL.AL_MAX_GAIN, maxGain); - } - - /** - * SGets the maximum gain for this source. - * - * @return the maximum gain for this source - */ - public float getMaxGain() { - float[] result = new float[1]; - al.alGetSourcef(sourceID, AL.AL_MAX_GAIN, result, 0); - - return result[0]; - } - - /** - * Sets the gain when outside the oriented cone. - * - * @param coneOuterGain the gain when outside the oriented cone. - */ - public void setConeOuterGain(float coneOuterGain) { - al.alSourcef(sourceID, AL.AL_CONE_OUTER_GAIN, coneOuterGain); - } - - /** - * Gets the gain when outside the oriented cone. - * - * @return the gain when outside the oriented cone. - */ - public float getConeOuterGain() { - float[] result = new float[1]; - al.alGetSourcef(sourceID, AL.AL_CONE_OUTER_GAIN, result, 0); - - return result[0]; - } - - /** - * Sets the x,y,z position of the source. - * - * @param position a Vec3f object containing the x,y,z position of the - * source. - */ - public void setPosition(Vec3f position) { - al.alSource3f( - sourceID, - AL.AL_POSITION, - position.v1, - position.v2, - position.v3); - } - - /** - * Sets the x,y,z position of the source. - * - * @param x the x position of the source. - * @param y the y position of the source. - * @param z the z position of the source. - */ - public void setPosition(float x, float y, float z) { - al.alSource3f(sourceID, AL.AL_POSITION, x, y, z); - } - - /** - * Gets the x,y,z position of the source. - * - * @return a Vec3f object containing the x,y,z position of the - * source. - */ - public Vec3f getPosition() { - Vec3f result = null; - float[] pos = new float[3]; - al.alGetSourcefv(sourceID, AL.AL_POSITION, pos, 0); - result = new Vec3f(pos[0], pos[1], pos[2]); - - return result; - } - - /** - * Sets the velocity vector of the source. - * - * @param velocity the velocity vector of the source - */ - public void setVelocity(Vec3f velocity) { - al.alSource3f( - sourceID, - AL.AL_VELOCITY, - velocity.v1, - velocity.v2, - velocity.v3); - } - - /** - * Sets the velocity vector of the source. - * - * @param x the x velocity of the source. - * @param y the y velocity of the source. - * @param z the z velocity of the source. - */ - public void setVelocity(float x, float y, float z) { - al.alSource3f(sourceID, AL.AL_VELOCITY, x, y, z); - } - - /** - * Gets the velocity vector of the source. - * - * @return the velocity vector of the source - */ - public Vec3f getVelocity() { - Vec3f result = null; - float[] vel = new float[3]; - al.alGetSourcefv(sourceID, AL.AL_VELOCITY, vel, 0); - result = new Vec3f(vel[0], vel[1], vel[2]); - - return result; - } - - /** - * Sets the direction vector of the source. - * - * @param direction the direction vector of the source. - */ - public void setDirection(Vec3f direction) { - al.alSource3f( - sourceID, - AL.AL_DIRECTION, - direction.v1, - direction.v2, - direction.v3); - } - - /** - * Sets the direction vector of the source. - * - * @param x the x direction of the source. - * @param y the y direction of the source. - * @param z the z direction of the source. - */ - public void setDirection(float x, float y, float z) { - al.alSource3f(sourceID, AL.AL_DIRECTION, x, y, z); - } - - /** - * Gets the direction vector of the source. - * - * @return the direction vector of the source. - */ - public Vec3f getDirection() { - Vec3f result = null; - float[] dir = new float[3]; - al.alGetSourcefv(sourceID, AL.AL_DIRECTION, dir, 0); - result = new Vec3f(dir[0], dir[1], dir[2]); - - return result; - } - - /** - * Determines if the position of the source is relative to the listener. - * The default is false. - * @param isRelative true if the position of the source is relative - * to the listener, false if the position of the source is relative to the - * world. - */ - public void setSourceRelative(boolean isRelative) { - int rel = isRelative ? 1 : 0; - al.alSourcei(sourceID, AL.AL_SOURCE_RELATIVE, rel); - } - - /** - * Determines if the position of the source is relative to the listener. - * The default is false. - * @return true if the position of the source is relative - * to the listener, false if the position of the source is relative to the - * world. - */ - public boolean isSourceRelative() { - int[] result = new int[1]; - al.alGetSourcei(sourceID, AL.AL_SOURCE_RELATIVE, result, 0); - - return result[0] == 1; - } - - /** - * turns looping on or off. - * - * @param isLooping true-looping is on, false-looping is off - */ - public void setLooping(boolean isLooping) { - int loop = isLooping ? 1 : 0; - al.alSourcei(sourceID, AL.AL_LOOPING, loop); - } - - /** - * indicates whether looping is turned on or off. - * - * @return true-looping is on, false-looping is off - */ - public boolean getLooping() { - boolean result = false; - int[] tmp = new int[1]; - al.alGetSourcei(sourceID, AL.AL_LOOPING, tmp, 0); - return tmp[0] == AL.AL_TRUE; - } - - - /** - * Gets the number of buffers currently queued on this source. - * @return the number of buffers currently queued on this source. - */ - public int getBuffersQueued() { - int[] result = new int[1]; - al.alGetSourcei(sourceID, AL.AL_BUFFERS_QUEUED, result, 0); - - return result[0]; - } - - /** - * Gets the number of buffers already processed on this source. - * @return the number of buffers already processed on this source. - */ - public int getBuffersProcessed() { - int[] result = new int[1]; - al.alGetSourcei(sourceID, AL.AL_BUFFERS_PROCESSED, result, 0); - - return result[0]; - } - - /** - * Sets the buffer associated with this source. - * - * @param buffer the buffer associated with this source - */ - public void setBuffer(Buffer buffer) { - al.alSourcei(sourceID, AL.AL_BUFFER, buffer.bufferID); - this.buffer = buffer; - } - - /** - * Gets the buffer associated with this source. - * - * @return the buffer associated with this source - */ - public Buffer getBuffer() { - return buffer; - } - - /** - * Queues one or more buffers on a source. Useful for streaming audio, - * buffers will be played in the order they are queued. - * - * @param buffers a set of initialized (loaded) buffers. - */ - public void queueBuffers(Buffer[] buffers) { - int numBuffers = buffers.length; - int[] arr = new int[numBuffers]; - - for (int i = 0; i < numBuffers; i++) { - arr[i] = buffers[i].bufferID; - } - - al.alSourceQueueBuffers(sourceID, numBuffers, arr, 0); - } - - /** - * Unqueues one or more buffers on a source. - * - * @param buffers a set of previously queued buffers. - */ - public void unqueueBuffers(Buffer[] buffers) { - int numBuffers = buffers.length; - int[] arr = new int[numBuffers]; - - for (int i = 0; i < numBuffers; i++) { - arr[i] = buffers[i].bufferID; - } - - al.alSourceUnqueueBuffers(sourceID, numBuffers, arr, 0); - } -} diff --git a/src/java/net/java/games/sound3d/Vec3f.java b/src/java/net/java/games/sound3d/Vec3f.java deleted file mode 100644 index 71b1d92..0000000 --- a/src/java/net/java/games/sound3d/Vec3f.java +++ /dev/null @@ -1,63 +0,0 @@ -/** -* Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. -* -* Redistribution and use in source and binary forms, with or without -* modification, are permitted provided that the following conditions are met: -* -* -Redistribution of source code must retain the above copyright notice, -* this list of conditions and the following disclaimer. -* -* -Redistribution 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 Sun Microsystems, Inc. or the names of contributors may -* be used to endorse or promote products derived from this software without -* specific prior written permission. -* -* This software is provided "AS IS," without a warranty of any kind. -* ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING -* ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR -* NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND ITS -* LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A -* RESULT OF USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. -* IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT -* OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR -* PUNITIVE DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, -* ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF SUN HAS -* BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. -* -* You acknowledge that this software is not designed or intended for use in the -* design, construction, operation or maintenance of any nuclear facility. -*/ - -package net.java.games.sound3d; - -/** - * A onvenience class representing a 3-element float vector - * - * @author Athomas Goldberg - */ -public final class Vec3f { - /** the first element in the vector */ - public final float v1; - - /** the first element in the vector */ - public final float v2; - - /** the first element in the vector */ - public final float v3; - - /** - * Creates a new Vec3f object. - * - * @param v1 the first element in the vector - * @param v2 the second element in the vector - * @param v3 the third element in the vector - */ - public Vec3f(float v1, float v2, float v3) { - this.v1 = v1; - this.v2 = v2; - this.v3 = v3; - } -} -- cgit v1.2.3