diff --git a/src/java/org/lwjgl/Display.java b/src/java/org/lwjgl/Display.java index 5ace57a8..91d5e05f 100644 --- a/src/java/org/lwjgl/Display.java +++ b/src/java/org/lwjgl/Display.java @@ -75,7 +75,7 @@ public final class Display { public static final int PLATFORM_AGL = 2; static { - System.loadLibrary(Sys.getLibraryName()); + Sys.initialize(); init(); Sys.log("Adapter: "+getAdapter()+" Version: "+getVersion()); } diff --git a/src/java/org/lwjgl/Sys.java b/src/java/org/lwjgl/Sys.java index 0b0705cc..7d446484 100644 --- a/src/java/org/lwjgl/Sys.java +++ b/src/java/org/lwjgl/Sys.java @@ -87,6 +87,8 @@ public final class Sys { */ public static final boolean DEBUG = Boolean.getBoolean("org.lwjgl.Sys.debug"); + private static boolean initialized = false; + static { initialize(); @@ -123,7 +125,10 @@ public final class Sys { /** * Initialization. */ - private static void initialize() { + public static void initialize() { + if (initialized) + return; + initialized = true; System.loadLibrary(LIBRARY_NAME); setDebug(DEBUG); setTime(0); diff --git a/src/java/org/lwjgl/input/Controller.java b/src/java/org/lwjgl/input/Controller.java index 8d5c4af7..709c36c3 100644 --- a/src/java/org/lwjgl/input/Controller.java +++ b/src/java/org/lwjgl/input/Controller.java @@ -146,7 +146,9 @@ public class Controller { * Static initialization */ private static void initialize() { - System.loadLibrary(Sys.getLibraryName()); + if (initialized) + return; + Sys.initialize(); initIDs(); // Assign names to all the buttons @@ -166,9 +168,7 @@ public class Controller { public static void create() throws Exception { if (!Window.isCreated()) throw new IllegalStateException("Window must be created before you can create Controller"); - if (!initialized) { - initialize(); - } + initialize(); if (created) { return; diff --git a/src/java/org/lwjgl/input/Cursor.java b/src/java/org/lwjgl/input/Cursor.java index 5977ef2d..5a4a5901 100644 --- a/src/java/org/lwjgl/input/Cursor.java +++ b/src/java/org/lwjgl/input/Cursor.java @@ -49,10 +49,6 @@ import org.lwjgl.Sys; */ public class Cursor { - - /** Lazy initialization */ - private static boolean initialized = false; - /** First element to display */ private CursorElement[] cursors = null; @@ -86,10 +82,7 @@ public class Cursor { if (yHotspot >= height || yHotspot < 0) throw new IllegalArgumentException("yHotspot > height || yHotspot < 0"); - // initialize - if (!initialized) { - initialize(); - } + Sys.initialize(); // Hmm yHotspot = height - 1 - yHotspot; @@ -98,14 +91,6 @@ public class Cursor { createCursors(width, height, xHotspot, yHotspot, numImages, images, delays); } - /** - * Initializes the cursor class - */ - private static void initialize() { - System.loadLibrary(Sys.getLibraryName()); - initialized = true; - } - /** * Creates the actual cursor, using a platform specific class */ diff --git a/src/java/org/lwjgl/input/Keyboard.java b/src/java/org/lwjgl/input/Keyboard.java index e739635b..f789af8d 100644 --- a/src/java/org/lwjgl/input/Keyboard.java +++ b/src/java/org/lwjgl/input/Keyboard.java @@ -268,7 +268,9 @@ public class Keyboard { * Static initialization */ private static void initialize() { - System.loadLibrary(Sys.getLibraryName()); + if (initialized) + return; + Sys.initialize(); initIDs(); initialized = true; } diff --git a/src/java/org/lwjgl/input/Mouse.java b/src/java/org/lwjgl/input/Mouse.java index ba075e4b..480b7ae6 100644 --- a/src/java/org/lwjgl/input/Mouse.java +++ b/src/java/org/lwjgl/input/Mouse.java @@ -217,7 +217,7 @@ public class Mouse { * Static initialization */ private static void initialize() { - System.loadLibrary(Sys.getLibraryName()); + Sys.initialize(); initIDs(); // Assign names to all the buttons @@ -245,9 +245,7 @@ public class Mouse { if (!Window.isCreated()) throw new IllegalStateException("Window must be created prior to creating mouse"); - if (!initialized) { - initialize(); - } + initialize(); if (created) { return; } diff --git a/src/java/org/lwjgl/openal/AL.java b/src/java/org/lwjgl/openal/AL.java index 5b20eb59..bd35b2d7 100644 --- a/src/java/org/lwjgl/openal/AL.java +++ b/src/java/org/lwjgl/openal/AL.java @@ -77,14 +77,7 @@ public abstract class AL { protected static boolean created; static { - initialize(); - } - - /** - * Static initialization - */ - private static void initialize() { - System.loadLibrary(org.lwjgl.Sys.getLibraryName()); + Sys.initialize(); } /** diff --git a/src/java/org/lwjgl/openal/ALC.java b/src/java/org/lwjgl/openal/ALC.java index 984b767e..4ef44d3a 100644 --- a/src/java/org/lwjgl/openal/ALC.java +++ b/src/java/org/lwjgl/openal/ALC.java @@ -34,6 +34,8 @@ package org.lwjgl.openal; import java.nio.Buffer; import java.nio.IntBuffer; +import org.lwjgl.Sys; + /** * $Id$ * @@ -140,7 +142,7 @@ public class ALC { public static final int ALC_OUT_OF_MEMORY = 0xA005; static { - initialize(); + Sys.initialize(); } /** Creates a new instance of ALC */ @@ -153,13 +155,6 @@ public class ALC { protected static void init() { } - /** - * Static initialization - */ - private static void initialize() { - System.loadLibrary(org.lwjgl.Sys.getLibraryName()); - } - /** * Creates the ALC instance * diff --git a/src/java/org/lwjgl/openal/eax/EAX.java b/src/java/org/lwjgl/openal/eax/EAX.java index 91d6ba5c..fe17837a 100644 --- a/src/java/org/lwjgl/openal/eax/EAX.java +++ b/src/java/org/lwjgl/openal/eax/EAX.java @@ -29,7 +29,10 @@ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ - package org.lwjgl.openal.eax; + +package org.lwjgl.openal.eax; + +import org.lwjgl.Sys; /** * $Id$ @@ -40,65 +43,57 @@ * @version $Revision$ */ public class EAX { + /** Has the EAX object been created? */ + protected static boolean created; + + static { + Sys.initialize(); + } - /** Has the EAX object been created? */ - protected static boolean created; - - static { - initialize(); - } + /** + * Loads the EAX functions + * + * @throws Exception if the EAX extensions couldn't be loaded + */ + public static void create() throws Exception { + if (created) { + return; + } - /** - * Static initialization - */ - private static void initialize() { - System.loadLibrary(org.lwjgl.Sys.getLibraryName()); - } + if (!nCreate()) { + throw new Exception("EAX instance could not be created."); + } + EAX20.init(); + created = true; + } - /** - * Loads the EAX functions - * - * @throws Exception if the EAX extensions couldn't be loaded - */ - public static void create() throws Exception { - if (created) { - return; - } + /** + * Native method to create EAX instance + * + * @return true if the EAX extensions could be found + */ + protected static native boolean nCreate(); - if (!nCreate()) { - throw new Exception("EAX instance could not be created."); - } - EAX20.init(); - created = true; - } + /** + * "Destroy" the EAX object + */ + public static void destroy() { + if (!created) { + return; + } + created = false; + nDestroy(); + } - /** - * Native method to create EAX instance - * - * @return true if the EAX extensions could be found - */ - protected static native boolean nCreate(); - - /** - * "Destroy" the EAX object - */ - public static void destroy() { - if (!created) { - return; - } - created = false; - nDestroy(); - } - - /** - * Native method the destroy the EAX - */ - protected static native void nDestroy(); - - /** - * @return true if EAX has been created - */ - public static boolean isCreated() { - return created; - } -} \ No newline at end of file + /** + * Native method the destroy the EAX + */ + protected static native void nDestroy(); + + /** + * @return true if EAX has been created + */ + public static boolean isCreated() { + return created; + } +} diff --git a/src/java/org/lwjgl/openal/eax/EAXBufferProperties.java b/src/java/org/lwjgl/openal/eax/EAXBufferProperties.java index e9f1c9fb..e400ec86 100644 --- a/src/java/org/lwjgl/openal/eax/EAXBufferProperties.java +++ b/src/java/org/lwjgl/openal/eax/EAXBufferProperties.java @@ -34,6 +34,8 @@ package org.lwjgl.openal.eax; import java.nio.ByteBuffer; import java.nio.ByteOrder; +import org.lwjgl.Sys; + /** * $Id$ * @@ -45,594 +47,594 @@ import java.nio.ByteOrder; * @version $Revision$ */ public class EAXBufferProperties { - - /** Whether auto commit has been anabled */ - private boolean autoCommit = true; - - /** Current source being operated on */ - private int currentSource = -1; + + /** Whether auto commit has been anabled */ + private boolean autoCommit = true; + + /** Current source being operated on */ + private int currentSource = -1; - /** ByteBuffer representing EAXBUFFERPROPERTIES */ - protected ByteBuffer eaxBufferProperties; + /** ByteBuffer representing EAXBUFFERPROPERTIES */ + protected ByteBuffer eaxBufferProperties; - /** size needed by ByteBuffer to contain EAXBUFFERPROPERTIES */ - protected static int EAXBUFFERPROPERTIES_SIZE; - - // EAX values and offsets - // ======================================================== + /** size needed by ByteBuffer to contain EAXBUFFERPROPERTIES */ + protected static int EAXBUFFERPROPERTIES_SIZE; + + // EAX values and offsets + // ======================================================== - /** direct path level offset */ - protected static int direct_offset; + /** direct path level offset */ + protected static int direct_offset; - /** direct path level at high frequencies offset */ - protected static int directHF_offset; + /** direct path level at high frequencies offset */ + protected static int directHF_offset; - /** room effect level offset */ - protected static int room_offset; + /** room effect level offset */ + protected static int room_offset; - /** room effect level at high frequencies offset */ - protected static int roomHF_offset; + /** room effect level at high frequencies offset */ + protected static int roomHF_offset; - /** like DS3D flRolloffFactor but for room effect offset */ - protected static int roomRolloffFactor_offset; + /** like DS3D flRolloffFactor but for room effect offset */ + protected static int roomRolloffFactor_offset; - /** main obstruction control (attenuation at high frequencies) offset */ - protected static int obstruction_offset; + /** main obstruction control (attenuation at high frequencies) offset */ + protected static int obstruction_offset; - /** obstruction low-frequency level re. main control offset */ - protected static int obstructionLFRatio_offset; + /** obstruction low-frequency level re. main control offset */ + protected static int obstructionLFRatio_offset; - /** main occlusion control (attenuation at high frequencies) offset */ - protected static int occlusion_offset; + /** main occlusion control (attenuation at high frequencies) offset */ + protected static int occlusion_offset; - /** occlusion low-frequency level re. main control offset */ - protected static int occlusionLFRatio_offset; + /** occlusion low-frequency level re. main control offset */ + protected static int occlusionLFRatio_offset; - /** occlusion room effect level re. main control offset */ - protected static int occlusionRoomRatio_offset; + /** occlusion room effect level re. main control offset */ + protected static int occlusionRoomRatio_offset; - /** outside sound cone level at high frequencies offset */ - protected static int outsideVolumeHF_offset; + /** outside sound cone level at high frequencies offset */ + protected static int outsideVolumeHF_offset; - /** multiplies DSPROPERTY_EAXLISTENER_AIRABSORPTIONHF offset */ - protected static int airAbsorptionFactor_offset; - - /** modifies the behavior of properties offset */ - protected static int flags_offset; - - public static final int EAXBUFFER_NONE = 0; - public static final int EAXBUFFER_ALLPARAMETERS = 1; - public static final int EAXBUFFER_DIRECT = 2; - public static final int EAXBUFFER_DIRECTHF = 3; - public static final int EAXBUFFER_ROOM = 4; - public static final int EAXBUFFER_ROOMHF = 5; - public static final int EAXBUFFER_ROOMROLLOFFFACTOR = 6; - public static final int EAXBUFFER_OBSTRUCTION = 7; - public static final int EAXBUFFER_OBSTRUCTIONLFRATIO = 8; - public static final int EAXBUFFER_OCCLUSION = 9; - public static final int EAXBUFFER_OCCLUSIONLFRATIO = 10; - public static final int EAXBUFFER_OCCLUSIONROOMRATIO = 11; - public static final int EAXBUFFER_OUTSIDEVOLUMEHF = 12; - public static final int EAXBUFFER_AIRABSORPTIONFACTOR = 13; - public static final int EAXBUFFER_FLAGS = 14; - - /** changes take effect immediately */ - public static final int EAXBUFFER_IMMEDIATE = 0x00000000; - - /** changes take effect later */ - public static final int EAXBUFFER_DEFERRED = 0x80000000; - public static final int EAXBUFFER_COMMITDEFERREDSETTINGS = - (EAXBUFFER_NONE | EAXBUFFER_IMMEDIATE); - - /** affects DSPROPERTY_EAXBUFFER_DIRECTHF */ - public static final int EAXBUFFER_FLAGS_DIRECTHFAUTO = 0x00000001; - - /** affects DSPROPERTY_EAXBUFFER_ROOM */ - public static final int EAXBUFFER_FLAGS_ROOMAUTO = 0x00000002; - - /** affects DSPROPERTY_EAXBUFFER_ROOMHF */ - public static final int EAXBUFFER_FLAGS_ROOMHFAUTO = 0x00000004; - - /** reserved future use */ - public static final int EAXBUFFER_FLAGS_RESERVED = 0xFFFFFFF8; - - // property ranges and defaults: - - public static final int EAXBUFFER_MINDIRECT = -10000; - public static final int EAXBUFFER_MAXDIRECT = 1000; - public static final int EAXBUFFER_DEFAULTDIRECT = 0; - - public static final int EAXBUFFER_MINDIRECTHF = -10000; - public static final int EAXBUFFER_MAXDIRECTHF = 0; - public static final int EAXBUFFER_DEFAULTDIRECTHF = 0; - - public static final int EAXBUFFER_MINROOM = -10000; - public static final int EAXBUFFER_MAXROOM = 1000; - public static final int EAXBUFFER_DEFAULTROOM = 0; - - public static final int EAXBUFFER_MINROOMHF = -10000; - public static final int EAXBUFFER_MAXROOMHF = 0; - public static final int EAXBUFFER_DEFAULTROOMHF = 0; - - public static final float EAXBUFFER_MINROOMROLLOFFFACTOR = 0.0f; - public static final float EAXBUFFER_MAXROOMROLLOFFFACTOR = 10.f; - public static final float EAXBUFFER_DEFAULTROOMROLLOFFFACTOR = 0.0f; - - public static final int EAXBUFFER_MINOBSTRUCTION = -10000; - public static final int EAXBUFFER_MAXOBSTRUCTION = 0; - public static final int EAXBUFFER_DEFAULTOBSTRUCTION = 0; - - public static final float EAXBUFFER_MINOBSTRUCTIONLFRATIO = 0.0f; - public static final float EAXBUFFER_MAXOBSTRUCTIONLFRATIO = 1.0f; - public static final float EAXBUFFER_DEFAULTOBSTRUCTIONLFRATIO = 0.0f; - - public static final int EAXBUFFER_MINOCCLUSION = -10000; - public static final int EAXBUFFER_MAXOCCLUSION = 0; - public static final int EAXBUFFER_DEFAULTOCCLUSION = 0; - - public static final float EAXBUFFER_MINOCCLUSIONLFRATIO = 0.0f; - public static final float EAXBUFFER_MAXOCCLUSIONLFRATIO = 1.0f; - public static final float EAXBUFFER_DEFAULTOCCLUSIONLFRATIO = 0.25f; - - public static final float EAXBUFFER_MINOCCLUSIONROOMRATIO = 0.0f; - public static final float EAXBUFFER_MAXOCCLUSIONROOMRATIO = 10.0f; - public static final float EAXBUFFER_DEFAULTOCCLUSIONROOMRATIO = 0.5f; - - public static final int EAXBUFFER_MINOUTSIDEVOLUMEHF = -10000; - public static final int EAXBUFFER_MAXOUTSIDEVOLUMEHF = 0; - public static final int EAXBUFFER_DEFAULTOUTSIDEVOLUMEHF = 0; - - public static final float EAXBUFFER_MINAIRABSORPTIONFACTOR = 0.0f; - public static final float EAXBUFFER_MAXAIRABSORPTIONFACTOR = 10.0f; - public static final float EAXBUFFER_DEFAULTAIRABSORPTIONFACTOR = 1.0f; - - public static final int EAXBUFFER_DEFAULTFLAGS = - (EAXBUFFER_FLAGS_DIRECTHFAUTO - | EAXBUFFER_FLAGS_ROOMAUTO - | EAXBUFFER_FLAGS_ROOMHFAUTO); - - // ------------------------------------------------------- - - static { - System.loadLibrary(org.lwjgl.Sys.getLibraryName()); - EAXBUFFERPROPERTIES_SIZE = sizeOfEaxBufferProperties(); - assignOffsets(); - } - - /** - * Creates a new EAXBufferProperties object - */ - public EAXBufferProperties() { - eaxBufferProperties = ByteBuffer.allocateDirect(EAXBUFFERPROPERTIES_SIZE); - eaxBufferProperties.order(ByteOrder.nativeOrder()); - } - - /** - * Sets the current source on which to perform effects - * - * @param source Source on which to perform effects - */ - public void setCurrentSource(int source) { - currentSource = source; - } - - /** - * Retrieves the current source - * - * @return Source on which effects are being performed - */ - public int getCurrentSource() { - return currentSource; - } - - /** - * Loads current EAX values from current source - */ - public void loadEAXValues() { - EAX20.eaxGet( - EAX20.BUFFER_GUID, - EAXBUFFER_ALLPARAMETERS, - currentSource, - eaxBufferProperties, - EAXBUFFERPROPERTIES_SIZE); - } - - /** - * Resets this buffer property to default values - */ - public void reset() { - boolean commitValue = autoCommit; - - // disable autocommit - autoCommit = false; - - // set values - setDirect(EAXBUFFER_DEFAULTDIRECT); - setDirectHF(EAXBUFFER_DEFAULTDIRECTHF); - setRoom(EAXBUFFER_DEFAULTROOM); - setRoomHF(EAXBUFFER_DEFAULTROOMHF); - setRoomRolloffFactor(EAXBUFFER_DEFAULTROOMROLLOFFFACTOR); - setObstruction(EAXBUFFER_DEFAULTOBSTRUCTION); - setObstructionLFRatio(EAXBUFFER_DEFAULTOBSTRUCTIONLFRATIO); - setOcclusion(EAXBUFFER_DEFAULTOCCLUSION); - setOcclusionLFRatio(EAXBUFFER_DEFAULTOCCLUSIONLFRATIO); - setOcclusionRoomRatio(EAXBUFFER_DEFAULTOCCLUSIONROOMRATIO); - setOutsideVolumeHF(EAXBUFFER_DEFAULTOUTSIDEVOLUMEHF); - setAirAbsorptionFactor(EAXBUFFER_DEFAULTAIRABSORPTIONFACTOR); - setFlags(EAXBUFFER_DEFAULTFLAGS); - - // reset auto commit - autoCommit = commitValue; - } - - - /** - * Commits any changes - */ - public void commit() { - // call eaxSet with Buffer guid, setting all parameters - EAX20.eaxSet( - EAX20.BUFFER_GUID, EAXBUFFER_ALLPARAMETERS, - currentSource, eaxBufferProperties, EAXBUFFERPROPERTIES_SIZE); - } - - /** - * Tests whether auto commit is enabled or not - * - * @return true if auto commit is inabled - */ - public boolean isAutoCommitEnabled() { - return autoCommit; - } - - /** - * Enabled or disables auto commit - * - * @param enabled True to enable, false to disable - */ - public void setAutoCommit(boolean enabled) { - autoCommit = enabled; - } - - /** - * Performs auto commit, if enabled - */ - private final void autoCommit() { - if(autoCommit) { - commit(); - } - } - - /** - * Retrieves the size of the containing ByteBuffer - */ - public static int getSize() { - return EAXBUFFERPROPERTIES_SIZE; - } - - /** - * Returns a String representation of the EAXBufferProperties object - * - * @return String representation of the EAXBufferProperties object - */ - public String toString() { - StringBuffer sb = new StringBuffer(); - sb.append("EAXBufferProperties ["); - - sb.append("lDirect = "); - sb.append(getDirect()); - sb.append(", "); - - sb.append("lDirectHF = "); - sb.append(getDirectHF()); - sb.append(", "); - - sb.append("lRoom = "); - sb.append(getRoom()); - sb.append(", "); - - sb.append("lRoomHF = "); - sb.append(getRoomHF()); - sb.append(", "); - - sb.append("flRoomRolloffFactor = "); - sb.append(getRoomRolloffFactor()); - sb.append(", "); - - sb.append("lObstruction = "); - sb.append(getObstruction()); - sb.append(", "); - - sb.append("flObstructionLFRatio = "); - sb.append(getObstructionLFRatio()); - sb.append(", "); - - sb.append("lOcclusion = "); - sb.append(getOcclusion()); - sb.append(", "); - - sb.append("flOcclusionLFRatio = "); - sb.append(getOcclusionLFRatio()); - sb.append(", "); - - sb.append("flOcclusionRoomRatio = "); - sb.append(getOcclusionRoomRatio()); - sb.append(", "); - - sb.append("lOutsideVolumeHF = "); - sb.append(getOutsideVolumeHF()); - sb.append(", "); - - sb.append("flAirAbsorptionFactor = "); - sb.append(getAirAbsorptionFactor()); - sb.append(", "); - - sb.append("dwFlags = "); - sb.append(getFlags()); - - sb.append("]"); - return sb.toString(); - } - - // Getters and Setters of struct - // ========================================================================== - - /** - * Retireves the direct path level - * - * @return direct path level - */ - public int getDirect() { - return eaxBufferProperties.getInt(direct_offset); - } - - /** - * Sets the direct path level - * - * @param direct direct path level to set to - */ - public void setDirect(int direct) { - eaxBufferProperties.putInt(direct_offset, direct); - autoCommit(); - } - - /** - * Retireves the direct path level at high frequencies - * - * @return direct path level at high frequencies - */ - public int getDirectHF() { - return eaxBufferProperties.getInt(directHF_offset); - } - - /** - * Sets the direct path level at high frequencies - * - * @param directHF direct path level at high frequencies to set to - */ - public void setDirectHF(int directHF) { - eaxBufferProperties.putInt(directHF_offset, directHF); - autoCommit(); - } - - /** - * Retireves the room effect level - * - * @return room effect level - */ - public int getRoom() { - return eaxBufferProperties.getInt(room_offset); - } - - /** - * Sets the room effect level - * - * @param room room effect level to set to - */ - public void setRoom(int room) { - eaxBufferProperties.putInt(room_offset, room); - autoCommit(); - } - - /** - * Retireves the room effect level at high frequencies - * - * @return room effect level at high frequencies - */ - public int getRoomHF() { - return eaxBufferProperties.getInt(roomHF_offset); - } - - /** - * Sets the room effect level at high frequencies - * - * @param roomHF room effect level at high frequencies to set to - */ - public void setRoomHF(int roomHF) { - eaxBufferProperties.putInt(roomHF_offset, roomHF); - autoCommit(); - } - - /** - * Retireves the DS3D flRolloffFactor for room effect - * - * @return DS3D flRolloffFactor for room effect - */ - public float getRoomRolloffFactor() { - return eaxBufferProperties.getFloat(roomRolloffFactor_offset); - } - - /** - * Sets the DS3D flRolloffFactor for room effect - * - * @param roomRolloffFactor DS3D flRolloffFactor for room effect to set to - */ - public void setRoomRolloffFactor(float roomRolloffFactor) { - eaxBufferProperties.putFloat(roomRolloffFactor_offset, roomRolloffFactor); - autoCommit(); - } - - /** - * Retireves the main obstruction control (attenuation at high frequencies) - * - * @return main obstruction control (attenuation at high frequencies) - */ - public int getObstruction() { - return eaxBufferProperties.getInt(obstruction_offset); - } - - /** - * Sets the main obstruction control (attenuation at high frequencies) - * - * @param obstruction main obstruction control (attenuation at high frequencies) to set to - */ - public void setObstruction(int obstruction) { - eaxBufferProperties.putInt(obstruction_offset, obstruction); - autoCommit(); - } - - /** - * Retireves the obstruction low-frequency level re. main control - * - * @return obstruction low-frequency level re. main control - */ - public float getObstructionLFRatio() { - return eaxBufferProperties.getFloat(obstructionLFRatio_offset); - } - - /** - * Sets the obstruction low-frequency level re. main control - * - * @param obstructionLFRatio obstruction low-frequency level re. main control to set to - */ - public void setObstructionLFRatio(float obstructionLFRatio) { - eaxBufferProperties.putFloat(obstructionLFRatio_offset, obstructionLFRatio); - autoCommit(); - } - - /** - * Retireves the main occlusion control (attenuation at high frequencies) - * - * @return main occlusion control (attenuation at high frequencies) - */ - public int getOcclusion() { - return eaxBufferProperties.getInt(occlusion_offset); - } - - /** - * Sets the main occlusion control (attenuation at high frequencies) - * - * @param occlusion main occlusion control (attenuation at high frequencies) to set to - */ - public void setOcclusion(int occlusion) { - eaxBufferProperties.putInt(occlusion_offset, occlusion); - autoCommit(); - } - - /** - * Retireves the occlusion low-frequency level re. main control - * - * @return occlusion low-frequency level re. main control - */ - public float getOcclusionLFRatio() { - return eaxBufferProperties.getFloat(occlusionLFRatio_offset); - } - - /** - * Sets the occlusion low-frequency level re. main control - * - * @param occlusionLFRatio occlusion low-frequency level re. main control to set to - */ - public void setOcclusionLFRatio(float occlusionLFRatio) { - eaxBufferProperties.putFloat(occlusionLFRatio_offset, occlusionLFRatio); - autoCommit(); - } - - /** - * Retireves the occlusion room effect level re. main control - * - * @return occlusion room effect level re. main control - */ - public float getOcclusionRoomRatio() { - return eaxBufferProperties.getFloat(occlusionRoomRatio_offset); - } - - /** - * Sets the OcclusionRoomRatio - * - * @param occlusionRoomRatio OcclusionRoomRatio to set to - */ - public void setOcclusionRoomRatio(float occlusionRoomRatio) { - eaxBufferProperties.putFloat(occlusionRoomRatio_offset, occlusionRoomRatio); - autoCommit(); - } - - /** - * Retireves the OutsideVolumeHF - * - * @return OutsideVolumeHF - */ - public int getOutsideVolumeHF() { - return eaxBufferProperties.getInt(outsideVolumeHF_offset); - } - - /** - * Sets the OutsideVolumeHF - * - * @param outsideVolumeHF OutsideVolumeHF to set to - */ - public void setOutsideVolumeHF(int outsideVolumeHF) { - eaxBufferProperties.putInt(outsideVolumeHF_offset, outsideVolumeHF); - autoCommit(); - } - - /** - * Retireves the multiplier for DSPROPERTY_EAXLISTENER_AIRABSORPTIONHF - * - * @return multiplier for DSPROPERTY_EAXLISTENER_AIRABSORPTIONHF - */ - public float getAirAbsorptionFactor() { - return eaxBufferProperties.getFloat(airAbsorptionFactor_offset); - } - - /** - * Sets the multiplier for DSPROPERTY_EAXLISTENER_AIRABSORPTIONHF - * - * @param airAbsorptionFactor multiplier for DSPROPERTY_EAXLISTENER_AIRABSORPTIONHF to set to - */ - public void setAirAbsorptionFactor(float airAbsorptionFactor) { - eaxBufferProperties.putFloat(airAbsorptionFactor_offset, airAbsorptionFactor); - autoCommit(); - } - - /** - * Retireves the modifier for behavior of properties - * - * @return modifier for behavior of properties - */ - public int getFlags() { - return eaxBufferProperties.getInt(flags_offset); - } - - /** - * Sets the modifier for behavior of properties - * - * @param flags modifier for behavior of properties to set to - */ - public void setFlags(int flags) { - eaxBufferProperties.putInt(flags_offset, flags); - autoCommit(); - } - - // -------------------------------------------------------------------------- - - /** - * Retrieves the size of the EAXBUFFERPROPERTIES - */ - protected static native int sizeOfEaxBufferProperties(); - - /** - * Sets the offsets to the fields - */ - protected static native void assignOffsets(); -} \ No newline at end of file + /** multiplies DSPROPERTY_EAXLISTENER_AIRABSORPTIONHF offset */ + protected static int airAbsorptionFactor_offset; + + /** modifies the behavior of properties offset */ + protected static int flags_offset; + + public static final int EAXBUFFER_NONE = 0; + public static final int EAXBUFFER_ALLPARAMETERS = 1; + public static final int EAXBUFFER_DIRECT = 2; + public static final int EAXBUFFER_DIRECTHF = 3; + public static final int EAXBUFFER_ROOM = 4; + public static final int EAXBUFFER_ROOMHF = 5; + public static final int EAXBUFFER_ROOMROLLOFFFACTOR = 6; + public static final int EAXBUFFER_OBSTRUCTION = 7; + public static final int EAXBUFFER_OBSTRUCTIONLFRATIO = 8; + public static final int EAXBUFFER_OCCLUSION = 9; + public static final int EAXBUFFER_OCCLUSIONLFRATIO = 10; + public static final int EAXBUFFER_OCCLUSIONROOMRATIO = 11; + public static final int EAXBUFFER_OUTSIDEVOLUMEHF = 12; + public static final int EAXBUFFER_AIRABSORPTIONFACTOR = 13; + public static final int EAXBUFFER_FLAGS = 14; + + /** changes take effect immediately */ + public static final int EAXBUFFER_IMMEDIATE = 0x00000000; + + /** changes take effect later */ + public static final int EAXBUFFER_DEFERRED = 0x80000000; + public static final int EAXBUFFER_COMMITDEFERREDSETTINGS = + (EAXBUFFER_NONE | EAXBUFFER_IMMEDIATE); + + /** affects DSPROPERTY_EAXBUFFER_DIRECTHF */ + public static final int EAXBUFFER_FLAGS_DIRECTHFAUTO = 0x00000001; + + /** affects DSPROPERTY_EAXBUFFER_ROOM */ + public static final int EAXBUFFER_FLAGS_ROOMAUTO = 0x00000002; + + /** affects DSPROPERTY_EAXBUFFER_ROOMHF */ + public static final int EAXBUFFER_FLAGS_ROOMHFAUTO = 0x00000004; + + /** reserved future use */ + public static final int EAXBUFFER_FLAGS_RESERVED = 0xFFFFFFF8; + + // property ranges and defaults: + + public static final int EAXBUFFER_MINDIRECT = -10000; + public static final int EAXBUFFER_MAXDIRECT = 1000; + public static final int EAXBUFFER_DEFAULTDIRECT = 0; + + public static final int EAXBUFFER_MINDIRECTHF = -10000; + public static final int EAXBUFFER_MAXDIRECTHF = 0; + public static final int EAXBUFFER_DEFAULTDIRECTHF = 0; + + public static final int EAXBUFFER_MINROOM = -10000; + public static final int EAXBUFFER_MAXROOM = 1000; + public static final int EAXBUFFER_DEFAULTROOM = 0; + + public static final int EAXBUFFER_MINROOMHF = -10000; + public static final int EAXBUFFER_MAXROOMHF = 0; + public static final int EAXBUFFER_DEFAULTROOMHF = 0; + + public static final float EAXBUFFER_MINROOMROLLOFFFACTOR = 0.0f; + public static final float EAXBUFFER_MAXROOMROLLOFFFACTOR = 10.f; + public static final float EAXBUFFER_DEFAULTROOMROLLOFFFACTOR = 0.0f; + + public static final int EAXBUFFER_MINOBSTRUCTION = -10000; + public static final int EAXBUFFER_MAXOBSTRUCTION = 0; + public static final int EAXBUFFER_DEFAULTOBSTRUCTION = 0; + + public static final float EAXBUFFER_MINOBSTRUCTIONLFRATIO = 0.0f; + public static final float EAXBUFFER_MAXOBSTRUCTIONLFRATIO = 1.0f; + public static final float EAXBUFFER_DEFAULTOBSTRUCTIONLFRATIO = 0.0f; + + public static final int EAXBUFFER_MINOCCLUSION = -10000; + public static final int EAXBUFFER_MAXOCCLUSION = 0; + public static final int EAXBUFFER_DEFAULTOCCLUSION = 0; + + public static final float EAXBUFFER_MINOCCLUSIONLFRATIO = 0.0f; + public static final float EAXBUFFER_MAXOCCLUSIONLFRATIO = 1.0f; + public static final float EAXBUFFER_DEFAULTOCCLUSIONLFRATIO = 0.25f; + + public static final float EAXBUFFER_MINOCCLUSIONROOMRATIO = 0.0f; + public static final float EAXBUFFER_MAXOCCLUSIONROOMRATIO = 10.0f; + public static final float EAXBUFFER_DEFAULTOCCLUSIONROOMRATIO = 0.5f; + + public static final int EAXBUFFER_MINOUTSIDEVOLUMEHF = -10000; + public static final int EAXBUFFER_MAXOUTSIDEVOLUMEHF = 0; + public static final int EAXBUFFER_DEFAULTOUTSIDEVOLUMEHF = 0; + + public static final float EAXBUFFER_MINAIRABSORPTIONFACTOR = 0.0f; + public static final float EAXBUFFER_MAXAIRABSORPTIONFACTOR = 10.0f; + public static final float EAXBUFFER_DEFAULTAIRABSORPTIONFACTOR = 1.0f; + + public static final int EAXBUFFER_DEFAULTFLAGS = + (EAXBUFFER_FLAGS_DIRECTHFAUTO + | EAXBUFFER_FLAGS_ROOMAUTO + | EAXBUFFER_FLAGS_ROOMHFAUTO); + + // ------------------------------------------------------- + + static { + Sys.initialize(); + EAXBUFFERPROPERTIES_SIZE = sizeOfEaxBufferProperties(); + assignOffsets(); + } + + /** + * Creates a new EAXBufferProperties object + */ + public EAXBufferProperties() { + eaxBufferProperties = ByteBuffer.allocateDirect(EAXBUFFERPROPERTIES_SIZE); + eaxBufferProperties.order(ByteOrder.nativeOrder()); + } + + /** + * Sets the current source on which to perform effects + * + * @param source Source on which to perform effects + */ + public void setCurrentSource(int source) { + currentSource = source; + } + + /** + * Retrieves the current source + * + * @return Source on which effects are being performed + */ + public int getCurrentSource() { + return currentSource; + } + + /** + * Loads current EAX values from current source + */ + public void loadEAXValues() { + EAX20.eaxGet( + EAX20.BUFFER_GUID, + EAXBUFFER_ALLPARAMETERS, + currentSource, + eaxBufferProperties, + EAXBUFFERPROPERTIES_SIZE); + } + + /** + * Resets this buffer property to default values + */ + public void reset() { + boolean commitValue = autoCommit; + + // disable autocommit + autoCommit = false; + + // set values + setDirect(EAXBUFFER_DEFAULTDIRECT); + setDirectHF(EAXBUFFER_DEFAULTDIRECTHF); + setRoom(EAXBUFFER_DEFAULTROOM); + setRoomHF(EAXBUFFER_DEFAULTROOMHF); + setRoomRolloffFactor(EAXBUFFER_DEFAULTROOMROLLOFFFACTOR); + setObstruction(EAXBUFFER_DEFAULTOBSTRUCTION); + setObstructionLFRatio(EAXBUFFER_DEFAULTOBSTRUCTIONLFRATIO); + setOcclusion(EAXBUFFER_DEFAULTOCCLUSION); + setOcclusionLFRatio(EAXBUFFER_DEFAULTOCCLUSIONLFRATIO); + setOcclusionRoomRatio(EAXBUFFER_DEFAULTOCCLUSIONROOMRATIO); + setOutsideVolumeHF(EAXBUFFER_DEFAULTOUTSIDEVOLUMEHF); + setAirAbsorptionFactor(EAXBUFFER_DEFAULTAIRABSORPTIONFACTOR); + setFlags(EAXBUFFER_DEFAULTFLAGS); + + // reset auto commit + autoCommit = commitValue; + } + + + /** + * Commits any changes + */ + public void commit() { + // call eaxSet with Buffer guid, setting all parameters + EAX20.eaxSet( + EAX20.BUFFER_GUID, EAXBUFFER_ALLPARAMETERS, + currentSource, eaxBufferProperties, EAXBUFFERPROPERTIES_SIZE); + } + + /** + * Tests whether auto commit is enabled or not + * + * @return true if auto commit is inabled + */ + public boolean isAutoCommitEnabled() { + return autoCommit; + } + + /** + * Enabled or disables auto commit + * + * @param enabled True to enable, false to disable + */ + public void setAutoCommit(boolean enabled) { + autoCommit = enabled; + } + + /** + * Performs auto commit, if enabled + */ + private final void autoCommit() { + if(autoCommit) { + commit(); + } + } + + /** + * Retrieves the size of the containing ByteBuffer + */ + public static int getSize() { + return EAXBUFFERPROPERTIES_SIZE; + } + + /** + * Returns a String representation of the EAXBufferProperties object + * + * @return String representation of the EAXBufferProperties object + */ + public String toString() { + StringBuffer sb = new StringBuffer(); + sb.append("EAXBufferProperties ["); + + sb.append("lDirect = "); + sb.append(getDirect()); + sb.append(", "); + + sb.append("lDirectHF = "); + sb.append(getDirectHF()); + sb.append(", "); + + sb.append("lRoom = "); + sb.append(getRoom()); + sb.append(", "); + + sb.append("lRoomHF = "); + sb.append(getRoomHF()); + sb.append(", "); + + sb.append("flRoomRolloffFactor = "); + sb.append(getRoomRolloffFactor()); + sb.append(", "); + + sb.append("lObstruction = "); + sb.append(getObstruction()); + sb.append(", "); + + sb.append("flObstructionLFRatio = "); + sb.append(getObstructionLFRatio()); + sb.append(", "); + + sb.append("lOcclusion = "); + sb.append(getOcclusion()); + sb.append(", "); + + sb.append("flOcclusionLFRatio = "); + sb.append(getOcclusionLFRatio()); + sb.append(", "); + + sb.append("flOcclusionRoomRatio = "); + sb.append(getOcclusionRoomRatio()); + sb.append(", "); + + sb.append("lOutsideVolumeHF = "); + sb.append(getOutsideVolumeHF()); + sb.append(", "); + + sb.append("flAirAbsorptionFactor = "); + sb.append(getAirAbsorptionFactor()); + sb.append(", "); + + sb.append("dwFlags = "); + sb.append(getFlags()); + + sb.append("]"); + return sb.toString(); + } + + // Getters and Setters of struct + // ========================================================================== + + /** + * Retireves the direct path level + * + * @return direct path level + */ + public int getDirect() { + return eaxBufferProperties.getInt(direct_offset); + } + + /** + * Sets the direct path level + * + * @param direct direct path level to set to + */ + public void setDirect(int direct) { + eaxBufferProperties.putInt(direct_offset, direct); + autoCommit(); + } + + /** + * Retireves the direct path level at high frequencies + * + * @return direct path level at high frequencies + */ + public int getDirectHF() { + return eaxBufferProperties.getInt(directHF_offset); + } + + /** + * Sets the direct path level at high frequencies + * + * @param directHF direct path level at high frequencies to set to + */ + public void setDirectHF(int directHF) { + eaxBufferProperties.putInt(directHF_offset, directHF); + autoCommit(); + } + + /** + * Retireves the room effect level + * + * @return room effect level + */ + public int getRoom() { + return eaxBufferProperties.getInt(room_offset); + } + + /** + * Sets the room effect level + * + * @param room room effect level to set to + */ + public void setRoom(int room) { + eaxBufferProperties.putInt(room_offset, room); + autoCommit(); + } + + /** + * Retireves the room effect level at high frequencies + * + * @return room effect level at high frequencies + */ + public int getRoomHF() { + return eaxBufferProperties.getInt(roomHF_offset); + } + + /** + * Sets the room effect level at high frequencies + * + * @param roomHF room effect level at high frequencies to set to + */ + public void setRoomHF(int roomHF) { + eaxBufferProperties.putInt(roomHF_offset, roomHF); + autoCommit(); + } + + /** + * Retireves the DS3D flRolloffFactor for room effect + * + * @return DS3D flRolloffFactor for room effect + */ + public float getRoomRolloffFactor() { + return eaxBufferProperties.getFloat(roomRolloffFactor_offset); + } + + /** + * Sets the DS3D flRolloffFactor for room effect + * + * @param roomRolloffFactor DS3D flRolloffFactor for room effect to set to + */ + public void setRoomRolloffFactor(float roomRolloffFactor) { + eaxBufferProperties.putFloat(roomRolloffFactor_offset, roomRolloffFactor); + autoCommit(); + } + + /** + * Retireves the main obstruction control (attenuation at high frequencies) + * + * @return main obstruction control (attenuation at high frequencies) + */ + public int getObstruction() { + return eaxBufferProperties.getInt(obstruction_offset); + } + + /** + * Sets the main obstruction control (attenuation at high frequencies) + * + * @param obstruction main obstruction control (attenuation at high frequencies) to set to + */ + public void setObstruction(int obstruction) { + eaxBufferProperties.putInt(obstruction_offset, obstruction); + autoCommit(); + } + + /** + * Retireves the obstruction low-frequency level re. main control + * + * @return obstruction low-frequency level re. main control + */ + public float getObstructionLFRatio() { + return eaxBufferProperties.getFloat(obstructionLFRatio_offset); + } + + /** + * Sets the obstruction low-frequency level re. main control + * + * @param obstructionLFRatio obstruction low-frequency level re. main control to set to + */ + public void setObstructionLFRatio(float obstructionLFRatio) { + eaxBufferProperties.putFloat(obstructionLFRatio_offset, obstructionLFRatio); + autoCommit(); + } + + /** + * Retireves the main occlusion control (attenuation at high frequencies) + * + * @return main occlusion control (attenuation at high frequencies) + */ + public int getOcclusion() { + return eaxBufferProperties.getInt(occlusion_offset); + } + + /** + * Sets the main occlusion control (attenuation at high frequencies) + * + * @param occlusion main occlusion control (attenuation at high frequencies) to set to + */ + public void setOcclusion(int occlusion) { + eaxBufferProperties.putInt(occlusion_offset, occlusion); + autoCommit(); + } + + /** + * Retireves the occlusion low-frequency level re. main control + * + * @return occlusion low-frequency level re. main control + */ + public float getOcclusionLFRatio() { + return eaxBufferProperties.getFloat(occlusionLFRatio_offset); + } + + /** + * Sets the occlusion low-frequency level re. main control + * + * @param occlusionLFRatio occlusion low-frequency level re. main control to set to + */ + public void setOcclusionLFRatio(float occlusionLFRatio) { + eaxBufferProperties.putFloat(occlusionLFRatio_offset, occlusionLFRatio); + autoCommit(); + } + + /** + * Retireves the occlusion room effect level re. main control + * + * @return occlusion room effect level re. main control + */ + public float getOcclusionRoomRatio() { + return eaxBufferProperties.getFloat(occlusionRoomRatio_offset); + } + + /** + * Sets the OcclusionRoomRatio + * + * @param occlusionRoomRatio OcclusionRoomRatio to set to + */ + public void setOcclusionRoomRatio(float occlusionRoomRatio) { + eaxBufferProperties.putFloat(occlusionRoomRatio_offset, occlusionRoomRatio); + autoCommit(); + } + + /** + * Retireves the OutsideVolumeHF + * + * @return OutsideVolumeHF + */ + public int getOutsideVolumeHF() { + return eaxBufferProperties.getInt(outsideVolumeHF_offset); + } + + /** + * Sets the OutsideVolumeHF + * + * @param outsideVolumeHF OutsideVolumeHF to set to + */ + public void setOutsideVolumeHF(int outsideVolumeHF) { + eaxBufferProperties.putInt(outsideVolumeHF_offset, outsideVolumeHF); + autoCommit(); + } + + /** + * Retireves the multiplier for DSPROPERTY_EAXLISTENER_AIRABSORPTIONHF + * + * @return multiplier for DSPROPERTY_EAXLISTENER_AIRABSORPTIONHF + */ + public float getAirAbsorptionFactor() { + return eaxBufferProperties.getFloat(airAbsorptionFactor_offset); + } + + /** + * Sets the multiplier for DSPROPERTY_EAXLISTENER_AIRABSORPTIONHF + * + * @param airAbsorptionFactor multiplier for DSPROPERTY_EAXLISTENER_AIRABSORPTIONHF to set to + */ + public void setAirAbsorptionFactor(float airAbsorptionFactor) { + eaxBufferProperties.putFloat(airAbsorptionFactor_offset, airAbsorptionFactor); + autoCommit(); + } + + /** + * Retireves the modifier for behavior of properties + * + * @return modifier for behavior of properties + */ + public int getFlags() { + return eaxBufferProperties.getInt(flags_offset); + } + + /** + * Sets the modifier for behavior of properties + * + * @param flags modifier for behavior of properties to set to + */ + public void setFlags(int flags) { + eaxBufferProperties.putInt(flags_offset, flags); + autoCommit(); + } + + // -------------------------------------------------------------------------- + + /** + * Retrieves the size of the EAXBUFFERPROPERTIES + */ + protected static native int sizeOfEaxBufferProperties(); + + /** + * Sets the offsets to the fields + */ + protected static native void assignOffsets(); +} diff --git a/src/java/org/lwjgl/openal/eax/EAXListenerProperties.java b/src/java/org/lwjgl/openal/eax/EAXListenerProperties.java index f825c1ae..961be057 100644 --- a/src/java/org/lwjgl/openal/eax/EAXListenerProperties.java +++ b/src/java/org/lwjgl/openal/eax/EAXListenerProperties.java @@ -34,6 +34,8 @@ package org.lwjgl.openal.eax; import java.nio.ByteBuffer; import java.nio.ByteOrder; +import org.lwjgl.Sys; + /** * $Id$ * @@ -43,647 +45,647 @@ import java.nio.ByteOrder; * @version $Revision$ */ public class EAXListenerProperties { - - /** Whether auto commit has been anabled */ - private boolean autoCommit = true; + + /** Whether auto commit has been anabled */ + private boolean autoCommit = true; - /** ByteBuffer representing EAXLISTENERPROPERTIES */ - protected ByteBuffer eaxListenerProperties; + /** ByteBuffer representing EAXLISTENERPROPERTIES */ + protected ByteBuffer eaxListenerProperties; - /** size needed by ByteBuffer to contain EAXLISTENERPROPERTIES */ - protected static int EAXLISTENERPROPERTIES_SIZE; - - // EAX values and offsets - // ======================================================== + /** size needed by ByteBuffer to contain EAXLISTENERPROPERTIES */ + protected static int EAXLISTENERPROPERTIES_SIZE; + + // EAX values and offsets + // ======================================================== - /** room effect level offset */ - protected static int room_offset; + /** room effect level offset */ + protected static int room_offset; - /** room effect level at high frequencies offset */ - protected static int roomHF_offset; + /** room effect level at high frequencies offset */ + protected static int roomHF_offset; - /**like DS3D flRolloffFactor but for room effect offset */ - protected static int roomRolloffFactor_offset; + /**like DS3D flRolloffFactor but for room effect offset */ + protected static int roomRolloffFactor_offset; - /** reverberation decay time at low frequencies offset */ - protected static int decayTime_offset; + /** reverberation decay time at low frequencies offset */ + protected static int decayTime_offset; - /** high-frequency to low-frequency decay time ratio offset */ - protected static int decayHFRatio_offset; + /** high-frequency to low-frequency decay time ratio offset */ + protected static int decayHFRatio_offset; - /** early reflections level relative to room effect offset */ - protected static int reflections_offset; + /** early reflections level relative to room effect offset */ + protected static int reflections_offset; - /** initial reflection delay time offset */ - protected static int reflectionsDelay_offset; + /** initial reflection delay time offset */ + protected static int reflectionsDelay_offset; - /** late reverberation level relative to room effect offset */ - protected static int reverb_offset; + /** late reverberation level relative to room effect offset */ + protected static int reverb_offset; - /** late reverberation delay time relative to initial reflection offset */ - protected static int reverbDelay_offset; + /** late reverberation delay time relative to initial reflection offset */ + protected static int reverbDelay_offset; - /** sets all listener properties offset */ - protected static int environment_offset; + /** sets all listener properties offset */ + protected static int environment_offset; - /** environment size in meters offset */ - protected static int environmentSize_offset; + /** environment size in meters offset */ + protected static int environmentSize_offset; - /** environment diffusion offset */ - protected static int environmentDiffusion_offset; + /** environment diffusion offset */ + protected static int environmentDiffusion_offset; - /** change in level per meter at 5 kHz offset */ - protected static int airAbsorptionHF_offset; + /** change in level per meter at 5 kHz offset */ + protected static int airAbsorptionHF_offset; - /** modifies the behavior of properties offset */ - protected static int flags_offset; + /** modifies the behavior of properties offset */ + protected static int flags_offset; - public static final int EAXLISTENER_NONE = 0; - public static final int EAXLISTENER_ALLPARAMETERS = 1; - public static final int EAXLISTENER_ROOM = 2; - public static final int EAXLISTENER_ROOMHF = 3; - public static final int EAXLISTENER_ROOMROLLOFFFACTOR = 4; - public static final int EAXLISTENER_DECAYTIME = 5; - public static final int EAXLISTENER_DECAYHFRATIO = 6; - public static final int EAXLISTENER_REFLECTIONS = 7; - public static final int EAXLISTENER_REFLECTIONSDELAY = 8; - public static final int EAXLISTENER_REVERB = 9; - public static final int EAXLISTENER_REVERBDELAY = 10; - public static final int EAXLISTENER_ENVIRONMENT = 11; - public static final int EAXLISTENER_ENVIRONMENTSIZE = 12; - public static final int EAXLISTENER_ENVIRONMENTDIFFUSION = 13; - public static final int EAXLISTENER_AIRABSORPTIONHF = 14; - public static final int EAXLISTENER_FLAGS = 15; - - /** changes take effect immediately */ - public static final int EAXLISTENER_IMMEDIATE = 0x00000000; - - /** changes take effect later */ - public static final int EAXLISTENER_DEFERRED = 0x80000000; - - public static final int EAXLISTENER_COMMITDEFERREDSETTINGS = - (EAXLISTENER_NONE | EAXLISTENER_IMMEDIATE); - - /** reverberation decay time */ - public static final int EAXLISTENERFLAGS_DECAYTIMESCALE = 0x00000001; - - /** reflection level */ - public static final int EAXLISTENERFLAGS_REFLECTIONSSCALE = 0x00000002; - - /** initial reflection delay time */ - public static final int EAXLISTENERFLAGS_REFLECTIONSDELAYSCALE = 0x00000004; - - /** reflections level */ - public static final int EAXLISTENERFLAGS_REVERBSCALE = 0x00000008; - - /** late reverberation delay time */ - public static final int EAXLISTENERFLAGS_REVERBDELAYSCALE = 0x00000010; - - /** This flag limits high-frequency decay time according to air absorption. */ - public static final int EAXLISTENERFLAGS_DECAYHFLIMIT = 0x00000020; - - /** reserved future use */ - public static final int EAXLISTENERFLAGS_RESERVED = 0xFFFFFFC0; - - // property ranges and defaults: - public static final int EAXLISTENER_MINROOM = -10000; - public static final int EAXLISTENER_MAXROOM = 0; - public static final int EAXLISTENER_DEFAULTROOM = -1000; - - public static final int EAXLISTENER_MINROOMHF = -10000; - public static final int EAXLISTENER_MAXROOMHF = 0; - public static final int EAXLISTENER_DEFAULTROOMHF = -100; - - public static final float EAXLISTENER_MINROOMROLLOFFFACTOR = 0.0f; - public static final float EAXLISTENER_MAXROOMROLLOFFFACTOR = 10.0f; - public static final float EAXLISTENER_DEFAULTROOMROLLOFFFACTOR = 0.0f; - - public static final float EAXLISTENER_MINDECAYTIME = 0.1f; - public static final float EAXLISTENER_MAXDECAYTIME = 20.0f; - public static final float EAXLISTENER_DEFAULTDECAYTIME = 1.49f; - - public static final float EAXLISTENER_MINDECAYHFRATIO = 0.1f; - public static final float EAXLISTENER_MAXDECAYHFRATIO = 2.0f; - public static final float EAXLISTENER_DEFAULTDECAYHFRATIO = 0.83f; - - public static final int EAXLISTENER_MINREFLECTIONS = -10000; - public static final int EAXLISTENER_MAXREFLECTIONS = 1000; - public static final int EAXLISTENER_DEFAULTREFLECTIONS = -2602; - - public static final float EAXLISTENER_MINREFLECTIONSDELAY = 0.0f; - public static final float EAXLISTENER_MAXREFLECTIONSDELAY = 0.3f; - public static final float EAXLISTENER_DEFAULTREFLECTIONSDELAY = 0.007f; - - public static final int EAXLISTENER_MINREVERB = -10000; - public static final int EAXLISTENER_MAXREVERB = 2000; - public static final int EAXLISTENER_DEFAULTREVERB = 200; - - public static final float EAXLISTENER_MINREVERBDELAY = 0.0f; - public static final float EAXLISTENER_MAXREVERBDELAY = 0.1f; - public static final float EAXLISTENER_DEFAULTREVERBDELAY = 0.011f; - - public static final int EAXLISTENER_MINENVIRONMENT = 0; - public static final int EAXLISTENER_MAXENVIRONMENT = - (EAX20.EAX_ENVIRONMENT_COUNT - 1); - public static final int EAXLISTENER_DEFAULTENVIRONMENT = - EAX20.EAX_ENVIRONMENT_GENERIC; - - public static final float EAXLISTENER_MINENVIRONMENTSIZE = 1.0f; - public static final float EAXLISTENER_MAXENVIRONMENTSIZE = 100.0f; - public static final float EAXLISTENER_DEFAULTENVIRONMENTSIZE = 7.5f; - - public static final float EAXLISTENER_MINENVIRONMENTDIFFUSION = 0.0f; - public static final float EAXLISTENER_MAXENVIRONMENTDIFFUSION = 1.0f; - public static final float EAXLISTENER_DEFAULTENVIRONMENTDIFFUSION = 1.0f; - - public static final float EAXLISTENER_MINAIRABSORPTIONHF = -100.0f; - public static final float EAXLISTENER_MAXAIRABSORPTIONHF = 0.0f; - public static final float EAXLISTENER_DEFAULTAIRABSORPTIONHF = -5.0f; - - public static final int EAXLISTENER_DEFAULTFLAGS = - (EAXLISTENERFLAGS_DECAYTIMESCALE - | EAXLISTENERFLAGS_REFLECTIONSSCALE - | EAXLISTENERFLAGS_REFLECTIONSDELAYSCALE - | EAXLISTENERFLAGS_REVERBSCALE - | EAXLISTENERFLAGS_REVERBDELAYSCALE - | EAXLISTENERFLAGS_DECAYHFLIMIT); - - // ------------------------------------------------------- - - static { - System.loadLibrary(org.lwjgl.Sys.getLibraryName()); - EAXLISTENERPROPERTIES_SIZE = sizeOfEaxListenerProperties(); - assignOffsets(); - } - - public EAXListenerProperties() { - eaxListenerProperties = - ByteBuffer.allocateDirect(EAXLISTENERPROPERTIES_SIZE); - eaxListenerProperties.order(ByteOrder.nativeOrder()); - } - - /** - * Loads current EAX values - */ - public void loadEAXValues() { - EAX20.eaxGet( - EAX20.LISTENER_GUID, - EAXLISTENER_ALLPARAMETERS, - 0, - eaxListenerProperties, - EAXLISTENERPROPERTIES_SIZE ); - } - - /** - * Resets this buffer property to default values - */ - public void reset() { - boolean commitValue = autoCommit; - - // disable autocommit - autoCommit = false; - - // set values - setRoom(EAXLISTENER_DEFAULTROOM); - setRoomHF(EAXLISTENER_DEFAULTROOMHF); - setRoomRolloffFactor(EAXLISTENER_DEFAULTROOMROLLOFFFACTOR); - setDecayTime(EAXLISTENER_DEFAULTDECAYTIME); - setDecayTimeHFRatio(EAXLISTENER_DEFAULTDECAYHFRATIO); - setReflections(EAXLISTENER_DEFAULTREFLECTIONS); - setReflectionsDelay(EAXLISTENER_DEFAULTREFLECTIONSDELAY); - setReverb(EAXLISTENER_DEFAULTREVERB); - setReverbDelay(EAXLISTENER_DEFAULTREVERBDELAY); - setEnvironment(EAXLISTENER_DEFAULTENVIRONMENT); - setEnvironmentSize(EAXLISTENER_DEFAULTENVIRONMENTSIZE); - setEnvironmentDiffusion(EAXLISTENER_DEFAULTENVIRONMENTDIFFUSION); - setAirAbsorptionFactor(EAXLISTENER_DEFAULTAIRABSORPTIONHF); - setFlags(EAXLISTENER_DEFAULTFLAGS); - - // reset auto commit - autoCommit = commitValue; - } - - - /** - * Commits any changes - */ - public void commit() { - // call eaxSet with Listener guid, setting all parameters - EAX20.eaxSet( - EAX20.LISTENER_GUID, EAXLISTENER_ALLPARAMETERS | EAXLISTENER_IMMEDIATE, - 0, eaxListenerProperties, EAXLISTENERPROPERTIES_SIZE); - } - - /** - * Tests whether auto commit is enabled or not - * - * @return true if auto commit is inabled - */ - public boolean isAutoCommitEnabled() { - return autoCommit; - } - - /** - * Enabled or disables auto commit - * - * @param enabled True to enable, false to disable - */ - public void setAutoCommit(boolean enabled) { - autoCommit = enabled; - } - - /** - * Performs auto commit, if enabled - */ - private final void autoCommit() { - if(autoCommit) { - commit(); - } - } - - /** - * Retrieves the size of the containing ByteBuffer - */ - public int getSize() { - return EAXLISTENERPROPERTIES_SIZE; - } - - /** - * Returns a String representation of the EAXBufferProperties object - * - * @return String representation of the EAXBufferProperties object - */ - public String toString() { - StringBuffer sb = new StringBuffer(); - sb.append("EAXListenerProperties ["); - - sb.append("lRoom = "); - sb.append(getRoom()); - sb.append(", "); - - sb.append("lRoomHF = "); - sb.append(getRoomHF()); - sb.append(", "); - - sb.append("flRoomRolloffFactor = "); - sb.append(getRoomRolloffFactor()); - sb.append(", "); - - sb.append("flDecayTime = "); - sb.append(getDecayTime()); - sb.append(", "); - - sb.append("flDecayHFRatio = "); - sb.append(getDecayTimeHFRatio()); - sb.append(", "); - - sb.append("lReflections = "); - sb.append(getReflections()); - sb.append(", "); - - sb.append("flReflectionsDelay = "); - sb.append(getReflectionsDelay()); - sb.append(", "); - - sb.append("lReverb = "); - sb.append(getReverb()); - sb.append(", "); - - sb.append("flReverbDelay = "); - sb.append(getReverbDelay()); - sb.append(", "); - - sb.append("dwEnvironment = "); - sb.append(getEnvironment()); - sb.append(", "); - - sb.append("flEnvironmentSize = "); - sb.append(getEnvironmentSize()); - sb.append(", "); - - sb.append("flEnvironmentDiffusion = "); - sb.append(getEnvironmentDiffusion()); - sb.append(", "); - - sb.append("flAirAbsorptionHF = "); - sb.append(getAirAbsorptionHF()); - sb.append(", "); - - sb.append("dwFlags = "); - sb.append(getFlags()); - - sb.append("]"); - return sb.toString(); - } - - // Getters and Setters of struct - // ========================================================================== - - /** - * Retireves the room effect level - * - * @return room effect level - */ - public int getRoom() { - return eaxListenerProperties.getInt(room_offset); - } - - /** - * Sets the room effect level - * - * @param room room effect level to set to - */ - public void setRoom(int room) { - eaxListenerProperties.putInt(room_offset, room); - autoCommit(); - } - - /** - * Retireves the room effect level at high frequencies - * - * @return room effect level at high frequencies - */ - public int getRoomHF() { - return eaxListenerProperties.getInt(roomHF_offset); - } - - /** - * Sets the room effect level at high frequencies - * - * @param roomHF room effect level at high frequencies to set to - */ - public void setRoomHF(int roomHF) { - eaxListenerProperties.putInt(roomHF_offset, roomHF); - autoCommit(); - } - - /** - * Retireves the DS3D flRolloffFactor for room effect - * - * @return DS3D flRolloffFactor for room effect - */ - public float getRoomRolloffFactor() { - return eaxListenerProperties.getFloat(roomRolloffFactor_offset); - } - - /** - * Sets the DS3D flRolloffFactor for room effect - * - * @param roomRolloffFactor DS3D flRolloffFactor for room effect to set to - */ - public void setRoomRolloffFactor(float roomRolloffFactor) { - eaxListenerProperties.putFloat(roomRolloffFactor_offset, roomRolloffFactor); - autoCommit(); - } - - /** - * Retireves the reverberation decay time at low frequencies - * - * @return reverberation decay time at low frequencies - */ - public float getDecayTime() { - return eaxListenerProperties.getFloat(decayTime_offset); - } - - /** - * Sets the reverberation decay time at low frequencies - * - * @param decayTime reverberation decay time at low frequencies to set to - */ - public void setDecayTime(float decayTime) { - eaxListenerProperties.putFloat(decayTime_offset, decayTime); - autoCommit(); - } - - /** - * Retireves the high-frequency to low-frequency decay time ratio - * - * @return high-frequency to low-frequency decay time ratio - */ - public float getDecayTimeHFRatio() { - return eaxListenerProperties.getFloat(decayHFRatio_offset); - } - - /** - * Sets the high-frequency to low-frequency decay time ratio - * - * @param decayTimeHFRatio high-frequency to low-frequency decay time ratio to set to - */ - public void setDecayTimeHFRatio(float decayTimeHFRatio) { - eaxListenerProperties.putFloat(decayHFRatio_offset, decayTimeHFRatio); - autoCommit(); - } - - /** - * Retireves the early reflections level relative to room effect - * - * @return early reflections level relative to room effect - */ - public int getReflections() { - return eaxListenerProperties.getInt(reflections_offset); - } - - /** - * Sets the early reflections level relative to room effect - * - * @param reflections early reflections level relative to room effect to set to - */ - public void setReflections(int reflections) { - eaxListenerProperties.putInt(reflections_offset, reflections); - autoCommit(); - } - - /** - * Retireves the initial reflection delay time - * - * @return initial reflection delay time - */ - public float getReflectionsDelay() { - return eaxListenerProperties.getFloat(reflectionsDelay_offset); - } - - /** - * Sets the initial reflection delay time - * - * @param reflectionsDelay initial reflection delay time to set to - */ - public void setReflectionsDelay(float reflectionsDelay) { - eaxListenerProperties.putFloat(reflectionsDelay_offset, reflectionsDelay); - autoCommit(); - } - - /** - * Retireves the late reverberation level relative to room effect - * - * @return late reverberation level relative to room effect - */ - public int getReverb() { - return eaxListenerProperties.getInt(reverb_offset); - } - - /** - * Sets the late reverberation level relative to room effect - * - * @param reverb late reverberation level relative to room effect to set to - */ - public void setReverb(int reverb) { - eaxListenerProperties.putInt(reverb_offset, reverb); - autoCommit(); - } - - /** - * Retireves the late reverberation delay time relative to initial reflection - * - * @return late reverberation delay time relative to initial reflection - */ - public float getReverbDelay() { - return eaxListenerProperties.getFloat(reverbDelay_offset); - } - - /** - * Sets the late reverberation delay time relative to initial reflection - * - * @param reverbDelay late reverberation delay time relative to initial reflection - */ - public void setReverbDelay(float reverbDelay) { - eaxListenerProperties.putFloat(reverbDelay_offset, reverbDelay); - autoCommit(); - } - - /** - * Retireves the listener properties - * - * @return listener properties - */ - public int getEnvironment() { - return eaxListenerProperties.getInt(environment_offset); - } - - /** - * Sets the listener properties - * - * @param environment listener properties to set to - */ - public void setEnvironment(int environment) { - eaxListenerProperties.putInt(environment_offset, environment); - - // we need to handle environment differently than all other - // values on auto commit, since it cannot be single handely set - // using ALLPARAMETERS - // - // To set the environment specifically we need to pass - // only the environment value and its size. Also pass the - // EAXLISTENER_ENVIRONMENT value (and since we're committing IMMEDIATE too) - if (autoCommit) { - EAX20.eaxSet( - EAX20.LISTENER_GUID, EAXLISTENER_ENVIRONMENT | EAXLISTENER_IMMEDIATE, - 0, eaxListenerProperties.position(environment_offset), 4); - - // rewind buffer - eaxListenerProperties.rewind(); - } - } - - /** - * Retireves the environment size in meters - * - * @return environment size in meters - */ - public float getEnvironmentSize() { - return eaxListenerProperties.getFloat(environmentSize_offset); - } - - /** - * Sets the environment size in meters - * - * @param environmentSize environment size in meters to set to - */ - public void setEnvironmentSize(float environmentSize) { - eaxListenerProperties.putFloat(environmentSize_offset, environmentSize); - - // we need to handle environment size differently than all other - // values on auto commit, since it cannot be single handely set - // using ALLPARAMETERS - // - // To set the environment size specifically we need to pass - // only the environment size value and its size. Also pass the - // EAXLISTENER_ENVIRONMENTSIZE value (and since we're committing IMMEDIATE too) - if (autoCommit) { - EAX20.eaxSet( - EAX20.LISTENER_GUID, EAXLISTENER_ENVIRONMENTSIZE | EAXLISTENER_IMMEDIATE, - 0, eaxListenerProperties.position(environmentSize_offset), 4); - - // rewind buffer - eaxListenerProperties.rewind(); - } - } - - /** - * Retireves the environment diffusion - * - * @return environment diffusion - */ - public float getEnvironmentDiffusion() { - return eaxListenerProperties.getFloat(environmentDiffusion_offset); - } - - /** - * Sets the environment diffusion - * - * @param environmentDiffusion environment diffusion to set to - */ - public void setEnvironmentDiffusion(float environmentDiffusion) { - eaxListenerProperties.putFloat(environmentDiffusion_offset, environmentDiffusion); - autoCommit(); - } - - /** - * Retireves the change in level per meter at 5 kHz - * - * @return change in level per meter at 5 kHz - */ - public float getAirAbsorptionHF() { - return eaxListenerProperties.getFloat(airAbsorptionHF_offset); - } - - /** - * Sets the change in level per meter at 5 kHz - * - * @param airAbsorptionHF change in level per meter at 5 kHz to set to - */ - public void setAirAbsorptionFactor(float airAbsorptionHF) { - eaxListenerProperties.putFloat(airAbsorptionHF_offset, airAbsorptionHF); - autoCommit(); - } - - /** - * Retireves the modifier for behavior of properties - * - * @return modifier for behavior of properties - */ - public int getFlags() { - return eaxListenerProperties.getInt(flags_offset); - } - - /** - * Sets the modifier for behavior of properties - * - * @param flags modifier for behavior of properties to set to - */ - public void setFlags(int flags) { - eaxListenerProperties.putInt(flags_offset, flags); - autoCommit(); - } - - // -------------------------------------------------------------------------- - - /** - * Retrieves the size of the EAXLISTENERPROPERTIES - */ - protected static native int sizeOfEaxListenerProperties(); - - /** - * Sets the offsets to the fields - */ - protected static native void assignOffsets(); -} \ No newline at end of file + public static final int EAXLISTENER_NONE = 0; + public static final int EAXLISTENER_ALLPARAMETERS = 1; + public static final int EAXLISTENER_ROOM = 2; + public static final int EAXLISTENER_ROOMHF = 3; + public static final int EAXLISTENER_ROOMROLLOFFFACTOR = 4; + public static final int EAXLISTENER_DECAYTIME = 5; + public static final int EAXLISTENER_DECAYHFRATIO = 6; + public static final int EAXLISTENER_REFLECTIONS = 7; + public static final int EAXLISTENER_REFLECTIONSDELAY = 8; + public static final int EAXLISTENER_REVERB = 9; + public static final int EAXLISTENER_REVERBDELAY = 10; + public static final int EAXLISTENER_ENVIRONMENT = 11; + public static final int EAXLISTENER_ENVIRONMENTSIZE = 12; + public static final int EAXLISTENER_ENVIRONMENTDIFFUSION = 13; + public static final int EAXLISTENER_AIRABSORPTIONHF = 14; + public static final int EAXLISTENER_FLAGS = 15; + + /** changes take effect immediately */ + public static final int EAXLISTENER_IMMEDIATE = 0x00000000; + + /** changes take effect later */ + public static final int EAXLISTENER_DEFERRED = 0x80000000; + + public static final int EAXLISTENER_COMMITDEFERREDSETTINGS = + (EAXLISTENER_NONE | EAXLISTENER_IMMEDIATE); + + /** reverberation decay time */ + public static final int EAXLISTENERFLAGS_DECAYTIMESCALE = 0x00000001; + + /** reflection level */ + public static final int EAXLISTENERFLAGS_REFLECTIONSSCALE = 0x00000002; + + /** initial reflection delay time */ + public static final int EAXLISTENERFLAGS_REFLECTIONSDELAYSCALE = 0x00000004; + + /** reflections level */ + public static final int EAXLISTENERFLAGS_REVERBSCALE = 0x00000008; + + /** late reverberation delay time */ + public static final int EAXLISTENERFLAGS_REVERBDELAYSCALE = 0x00000010; + + /** This flag limits high-frequency decay time according to air absorption. */ + public static final int EAXLISTENERFLAGS_DECAYHFLIMIT = 0x00000020; + + /** reserved future use */ + public static final int EAXLISTENERFLAGS_RESERVED = 0xFFFFFFC0; + + // property ranges and defaults: + public static final int EAXLISTENER_MINROOM = -10000; + public static final int EAXLISTENER_MAXROOM = 0; + public static final int EAXLISTENER_DEFAULTROOM = -1000; + + public static final int EAXLISTENER_MINROOMHF = -10000; + public static final int EAXLISTENER_MAXROOMHF = 0; + public static final int EAXLISTENER_DEFAULTROOMHF = -100; + + public static final float EAXLISTENER_MINROOMROLLOFFFACTOR = 0.0f; + public static final float EAXLISTENER_MAXROOMROLLOFFFACTOR = 10.0f; + public static final float EAXLISTENER_DEFAULTROOMROLLOFFFACTOR = 0.0f; + + public static final float EAXLISTENER_MINDECAYTIME = 0.1f; + public static final float EAXLISTENER_MAXDECAYTIME = 20.0f; + public static final float EAXLISTENER_DEFAULTDECAYTIME = 1.49f; + + public static final float EAXLISTENER_MINDECAYHFRATIO = 0.1f; + public static final float EAXLISTENER_MAXDECAYHFRATIO = 2.0f; + public static final float EAXLISTENER_DEFAULTDECAYHFRATIO = 0.83f; + + public static final int EAXLISTENER_MINREFLECTIONS = -10000; + public static final int EAXLISTENER_MAXREFLECTIONS = 1000; + public static final int EAXLISTENER_DEFAULTREFLECTIONS = -2602; + + public static final float EAXLISTENER_MINREFLECTIONSDELAY = 0.0f; + public static final float EAXLISTENER_MAXREFLECTIONSDELAY = 0.3f; + public static final float EAXLISTENER_DEFAULTREFLECTIONSDELAY = 0.007f; + + public static final int EAXLISTENER_MINREVERB = -10000; + public static final int EAXLISTENER_MAXREVERB = 2000; + public static final int EAXLISTENER_DEFAULTREVERB = 200; + + public static final float EAXLISTENER_MINREVERBDELAY = 0.0f; + public static final float EAXLISTENER_MAXREVERBDELAY = 0.1f; + public static final float EAXLISTENER_DEFAULTREVERBDELAY = 0.011f; + + public static final int EAXLISTENER_MINENVIRONMENT = 0; + public static final int EAXLISTENER_MAXENVIRONMENT = + (EAX20.EAX_ENVIRONMENT_COUNT - 1); + public static final int EAXLISTENER_DEFAULTENVIRONMENT = + EAX20.EAX_ENVIRONMENT_GENERIC; + + public static final float EAXLISTENER_MINENVIRONMENTSIZE = 1.0f; + public static final float EAXLISTENER_MAXENVIRONMENTSIZE = 100.0f; + public static final float EAXLISTENER_DEFAULTENVIRONMENTSIZE = 7.5f; + + public static final float EAXLISTENER_MINENVIRONMENTDIFFUSION = 0.0f; + public static final float EAXLISTENER_MAXENVIRONMENTDIFFUSION = 1.0f; + public static final float EAXLISTENER_DEFAULTENVIRONMENTDIFFUSION = 1.0f; + + public static final float EAXLISTENER_MINAIRABSORPTIONHF = -100.0f; + public static final float EAXLISTENER_MAXAIRABSORPTIONHF = 0.0f; + public static final float EAXLISTENER_DEFAULTAIRABSORPTIONHF = -5.0f; + + public static final int EAXLISTENER_DEFAULTFLAGS = + (EAXLISTENERFLAGS_DECAYTIMESCALE + | EAXLISTENERFLAGS_REFLECTIONSSCALE + | EAXLISTENERFLAGS_REFLECTIONSDELAYSCALE + | EAXLISTENERFLAGS_REVERBSCALE + | EAXLISTENERFLAGS_REVERBDELAYSCALE + | EAXLISTENERFLAGS_DECAYHFLIMIT); + + // ------------------------------------------------------- + + static { + Sys.initialize(); + EAXLISTENERPROPERTIES_SIZE = sizeOfEaxListenerProperties(); + assignOffsets(); + } + + public EAXListenerProperties() { + eaxListenerProperties = + ByteBuffer.allocateDirect(EAXLISTENERPROPERTIES_SIZE); + eaxListenerProperties.order(ByteOrder.nativeOrder()); + } + + /** + * Loads current EAX values + */ + public void loadEAXValues() { + EAX20.eaxGet( + EAX20.LISTENER_GUID, + EAXLISTENER_ALLPARAMETERS, + 0, + eaxListenerProperties, + EAXLISTENERPROPERTIES_SIZE ); + } + + /** + * Resets this buffer property to default values + */ + public void reset() { + boolean commitValue = autoCommit; + + // disable autocommit + autoCommit = false; + + // set values + setRoom(EAXLISTENER_DEFAULTROOM); + setRoomHF(EAXLISTENER_DEFAULTROOMHF); + setRoomRolloffFactor(EAXLISTENER_DEFAULTROOMROLLOFFFACTOR); + setDecayTime(EAXLISTENER_DEFAULTDECAYTIME); + setDecayTimeHFRatio(EAXLISTENER_DEFAULTDECAYHFRATIO); + setReflections(EAXLISTENER_DEFAULTREFLECTIONS); + setReflectionsDelay(EAXLISTENER_DEFAULTREFLECTIONSDELAY); + setReverb(EAXLISTENER_DEFAULTREVERB); + setReverbDelay(EAXLISTENER_DEFAULTREVERBDELAY); + setEnvironment(EAXLISTENER_DEFAULTENVIRONMENT); + setEnvironmentSize(EAXLISTENER_DEFAULTENVIRONMENTSIZE); + setEnvironmentDiffusion(EAXLISTENER_DEFAULTENVIRONMENTDIFFUSION); + setAirAbsorptionFactor(EAXLISTENER_DEFAULTAIRABSORPTIONHF); + setFlags(EAXLISTENER_DEFAULTFLAGS); + + // reset auto commit + autoCommit = commitValue; + } + + + /** + * Commits any changes + */ + public void commit() { + // call eaxSet with Listener guid, setting all parameters + EAX20.eaxSet( + EAX20.LISTENER_GUID, EAXLISTENER_ALLPARAMETERS | EAXLISTENER_IMMEDIATE, + 0, eaxListenerProperties, EAXLISTENERPROPERTIES_SIZE); + } + + /** + * Tests whether auto commit is enabled or not + * + * @return true if auto commit is inabled + */ + public boolean isAutoCommitEnabled() { + return autoCommit; + } + + /** + * Enabled or disables auto commit + * + * @param enabled True to enable, false to disable + */ + public void setAutoCommit(boolean enabled) { + autoCommit = enabled; + } + + /** + * Performs auto commit, if enabled + */ + private final void autoCommit() { + if(autoCommit) { + commit(); + } + } + + /** + * Retrieves the size of the containing ByteBuffer + */ + public int getSize() { + return EAXLISTENERPROPERTIES_SIZE; + } + + /** + * Returns a String representation of the EAXBufferProperties object + * + * @return String representation of the EAXBufferProperties object + */ + public String toString() { + StringBuffer sb = new StringBuffer(); + sb.append("EAXListenerProperties ["); + + sb.append("lRoom = "); + sb.append(getRoom()); + sb.append(", "); + + sb.append("lRoomHF = "); + sb.append(getRoomHF()); + sb.append(", "); + + sb.append("flRoomRolloffFactor = "); + sb.append(getRoomRolloffFactor()); + sb.append(", "); + + sb.append("flDecayTime = "); + sb.append(getDecayTime()); + sb.append(", "); + + sb.append("flDecayHFRatio = "); + sb.append(getDecayTimeHFRatio()); + sb.append(", "); + + sb.append("lReflections = "); + sb.append(getReflections()); + sb.append(", "); + + sb.append("flReflectionsDelay = "); + sb.append(getReflectionsDelay()); + sb.append(", "); + + sb.append("lReverb = "); + sb.append(getReverb()); + sb.append(", "); + + sb.append("flReverbDelay = "); + sb.append(getReverbDelay()); + sb.append(", "); + + sb.append("dwEnvironment = "); + sb.append(getEnvironment()); + sb.append(", "); + + sb.append("flEnvironmentSize = "); + sb.append(getEnvironmentSize()); + sb.append(", "); + + sb.append("flEnvironmentDiffusion = "); + sb.append(getEnvironmentDiffusion()); + sb.append(", "); + + sb.append("flAirAbsorptionHF = "); + sb.append(getAirAbsorptionHF()); + sb.append(", "); + + sb.append("dwFlags = "); + sb.append(getFlags()); + + sb.append("]"); + return sb.toString(); + } + + // Getters and Setters of struct + // ========================================================================== + + /** + * Retireves the room effect level + * + * @return room effect level + */ + public int getRoom() { + return eaxListenerProperties.getInt(room_offset); + } + + /** + * Sets the room effect level + * + * @param room room effect level to set to + */ + public void setRoom(int room) { + eaxListenerProperties.putInt(room_offset, room); + autoCommit(); + } + + /** + * Retireves the room effect level at high frequencies + * + * @return room effect level at high frequencies + */ + public int getRoomHF() { + return eaxListenerProperties.getInt(roomHF_offset); + } + + /** + * Sets the room effect level at high frequencies + * + * @param roomHF room effect level at high frequencies to set to + */ + public void setRoomHF(int roomHF) { + eaxListenerProperties.putInt(roomHF_offset, roomHF); + autoCommit(); + } + + /** + * Retireves the DS3D flRolloffFactor for room effect + * + * @return DS3D flRolloffFactor for room effect + */ + public float getRoomRolloffFactor() { + return eaxListenerProperties.getFloat(roomRolloffFactor_offset); + } + + /** + * Sets the DS3D flRolloffFactor for room effect + * + * @param roomRolloffFactor DS3D flRolloffFactor for room effect to set to + */ + public void setRoomRolloffFactor(float roomRolloffFactor) { + eaxListenerProperties.putFloat(roomRolloffFactor_offset, roomRolloffFactor); + autoCommit(); + } + + /** + * Retireves the reverberation decay time at low frequencies + * + * @return reverberation decay time at low frequencies + */ + public float getDecayTime() { + return eaxListenerProperties.getFloat(decayTime_offset); + } + + /** + * Sets the reverberation decay time at low frequencies + * + * @param decayTime reverberation decay time at low frequencies to set to + */ + public void setDecayTime(float decayTime) { + eaxListenerProperties.putFloat(decayTime_offset, decayTime); + autoCommit(); + } + + /** + * Retireves the high-frequency to low-frequency decay time ratio + * + * @return high-frequency to low-frequency decay time ratio + */ + public float getDecayTimeHFRatio() { + return eaxListenerProperties.getFloat(decayHFRatio_offset); + } + + /** + * Sets the high-frequency to low-frequency decay time ratio + * + * @param decayTimeHFRatio high-frequency to low-frequency decay time ratio to set to + */ + public void setDecayTimeHFRatio(float decayTimeHFRatio) { + eaxListenerProperties.putFloat(decayHFRatio_offset, decayTimeHFRatio); + autoCommit(); + } + + /** + * Retireves the early reflections level relative to room effect + * + * @return early reflections level relative to room effect + */ + public int getReflections() { + return eaxListenerProperties.getInt(reflections_offset); + } + + /** + * Sets the early reflections level relative to room effect + * + * @param reflections early reflections level relative to room effect to set to + */ + public void setReflections(int reflections) { + eaxListenerProperties.putInt(reflections_offset, reflections); + autoCommit(); + } + + /** + * Retireves the initial reflection delay time + * + * @return initial reflection delay time + */ + public float getReflectionsDelay() { + return eaxListenerProperties.getFloat(reflectionsDelay_offset); + } + + /** + * Sets the initial reflection delay time + * + * @param reflectionsDelay initial reflection delay time to set to + */ + public void setReflectionsDelay(float reflectionsDelay) { + eaxListenerProperties.putFloat(reflectionsDelay_offset, reflectionsDelay); + autoCommit(); + } + + /** + * Retireves the late reverberation level relative to room effect + * + * @return late reverberation level relative to room effect + */ + public int getReverb() { + return eaxListenerProperties.getInt(reverb_offset); + } + + /** + * Sets the late reverberation level relative to room effect + * + * @param reverb late reverberation level relative to room effect to set to + */ + public void setReverb(int reverb) { + eaxListenerProperties.putInt(reverb_offset, reverb); + autoCommit(); + } + + /** + * Retireves the late reverberation delay time relative to initial reflection + * + * @return late reverberation delay time relative to initial reflection + */ + public float getReverbDelay() { + return eaxListenerProperties.getFloat(reverbDelay_offset); + } + + /** + * Sets the late reverberation delay time relative to initial reflection + * + * @param reverbDelay late reverberation delay time relative to initial reflection + */ + public void setReverbDelay(float reverbDelay) { + eaxListenerProperties.putFloat(reverbDelay_offset, reverbDelay); + autoCommit(); + } + + /** + * Retireves the listener properties + * + * @return listener properties + */ + public int getEnvironment() { + return eaxListenerProperties.getInt(environment_offset); + } + + /** + * Sets the listener properties + * + * @param environment listener properties to set to + */ + public void setEnvironment(int environment) { + eaxListenerProperties.putInt(environment_offset, environment); + + // we need to handle environment differently than all other + // values on auto commit, since it cannot be single handely set + // using ALLPARAMETERS + // + // To set the environment specifically we need to pass + // only the environment value and its size. Also pass the + // EAXLISTENER_ENVIRONMENT value (and since we're committing IMMEDIATE too) + if (autoCommit) { + EAX20.eaxSet( + EAX20.LISTENER_GUID, EAXLISTENER_ENVIRONMENT | EAXLISTENER_IMMEDIATE, + 0, eaxListenerProperties.position(environment_offset), 4); + + // rewind buffer + eaxListenerProperties.rewind(); + } + } + + /** + * Retireves the environment size in meters + * + * @return environment size in meters + */ + public float getEnvironmentSize() { + return eaxListenerProperties.getFloat(environmentSize_offset); + } + + /** + * Sets the environment size in meters + * + * @param environmentSize environment size in meters to set to + */ + public void setEnvironmentSize(float environmentSize) { + eaxListenerProperties.putFloat(environmentSize_offset, environmentSize); + + // we need to handle environment size differently than all other + // values on auto commit, since it cannot be single handely set + // using ALLPARAMETERS + // + // To set the environment size specifically we need to pass + // only the environment size value and its size. Also pass the + // EAXLISTENER_ENVIRONMENTSIZE value (and since we're committing IMMEDIATE too) + if (autoCommit) { + EAX20.eaxSet( + EAX20.LISTENER_GUID, EAXLISTENER_ENVIRONMENTSIZE | EAXLISTENER_IMMEDIATE, + 0, eaxListenerProperties.position(environmentSize_offset), 4); + + // rewind buffer + eaxListenerProperties.rewind(); + } + } + + /** + * Retireves the environment diffusion + * + * @return environment diffusion + */ + public float getEnvironmentDiffusion() { + return eaxListenerProperties.getFloat(environmentDiffusion_offset); + } + + /** + * Sets the environment diffusion + * + * @param environmentDiffusion environment diffusion to set to + */ + public void setEnvironmentDiffusion(float environmentDiffusion) { + eaxListenerProperties.putFloat(environmentDiffusion_offset, environmentDiffusion); + autoCommit(); + } + + /** + * Retireves the change in level per meter at 5 kHz + * + * @return change in level per meter at 5 kHz + */ + public float getAirAbsorptionHF() { + return eaxListenerProperties.getFloat(airAbsorptionHF_offset); + } + + /** + * Sets the change in level per meter at 5 kHz + * + * @param airAbsorptionHF change in level per meter at 5 kHz to set to + */ + public void setAirAbsorptionFactor(float airAbsorptionHF) { + eaxListenerProperties.putFloat(airAbsorptionHF_offset, airAbsorptionHF); + autoCommit(); + } + + /** + * Retireves the modifier for behavior of properties + * + * @return modifier for behavior of properties + */ + public int getFlags() { + return eaxListenerProperties.getInt(flags_offset); + } + + /** + * Sets the modifier for behavior of properties + * + * @param flags modifier for behavior of properties to set to + */ + public void setFlags(int flags) { + eaxListenerProperties.putInt(flags_offset, flags); + autoCommit(); + } + + // -------------------------------------------------------------------------- + + /** + * Retrieves the size of the EAXLISTENERPROPERTIES + */ + protected static native int sizeOfEaxListenerProperties(); + + /** + * Sets the offsets to the fields + */ + protected static native void assignOffsets(); +} diff --git a/src/java/org/lwjgl/opengl/GLContext.java b/src/java/org/lwjgl/opengl/GLContext.java index 58f465f9..56306525 100644 --- a/src/java/org/lwjgl/opengl/GLContext.java +++ b/src/java/org/lwjgl/opengl/GLContext.java @@ -167,7 +167,7 @@ public final class GLContext { public static boolean OpenGL15; static { - System.loadLibrary(Sys.getLibraryName()); + Sys.initialize(); } /** diff --git a/src/java/org/lwjgl/opengl/Pbuffer.java b/src/java/org/lwjgl/opengl/Pbuffer.java index 6df0fcc9..16896397 100644 --- a/src/java/org/lwjgl/opengl/Pbuffer.java +++ b/src/java/org/lwjgl/opengl/Pbuffer.java @@ -155,7 +155,7 @@ public final class Pbuffer { private final int height; static { - System.loadLibrary(Sys.getLibraryName()); + Sys.initialize(); } /** diff --git a/src/java/org/lwjgl/opengl/Window.java b/src/java/org/lwjgl/opengl/Window.java index a60cc47a..eb20fa8b 100644 --- a/src/java/org/lwjgl/opengl/Window.java +++ b/src/java/org/lwjgl/opengl/Window.java @@ -56,7 +56,7 @@ import org.lwjgl.input.Mouse; public final class Window { static { - System.loadLibrary(Sys.getLibraryName()); + Sys.initialize(); } /** X coordinate of the window */