From f14e76ab8f090bd50500909addf58509c2f987ed Mon Sep 17 00:00:00 2001 From: Brian Matzon Date: Sat, 5 Jul 2003 23:13:09 +0000 Subject: [PATCH] fix: using type specific buffers --- src/java/org/lwjgl/openal/CoreAL.java | 56 ++++++++++++---------- src/java/org/lwjgl/test/openal/ALTest.java | 30 ++++++------ 2 files changed, 45 insertions(+), 41 deletions(-) diff --git a/src/java/org/lwjgl/openal/CoreAL.java b/src/java/org/lwjgl/openal/CoreAL.java index 69e311a5..31859c83 100644 --- a/src/java/org/lwjgl/openal/CoreAL.java +++ b/src/java/org/lwjgl/openal/CoreAL.java @@ -31,7 +31,11 @@ */ package org.lwjgl.openal; -import java.nio.Buffer; +import java.nio.ByteBuffer; +import java.nio.IntBuffer; +import java.nio.FloatBuffer; +import java.nio.DoubleBuffer; + /** * $Id$ @@ -109,7 +113,7 @@ public class CoreAL extends BaseAL implements BaseALConstants { * @param pname state to be queried * @param data Buffer to place the booleans in */ - public static native void alGetBooleanv(int pname, Buffer data); + public static native void alGetBooleanv(int pname, ByteBuffer data); /** * Returns an integer OpenAL state. @@ -117,7 +121,7 @@ public class CoreAL extends BaseAL implements BaseALConstants { * @param pname state to be queried * @param data Buffer to place the integers in */ - public static native void alGetIntegerv(int pname, Buffer data); + public static native void alGetIntegerv(int pname, IntBuffer data); /** * Returns a floating point OpenAL state. @@ -125,7 +129,7 @@ public class CoreAL extends BaseAL implements BaseALConstants { * @param pname state to be queried * @param data Buffer to place the floats in */ - public static native void alGetFloatv(int pname, Buffer data); + public static native void alGetFloatv(int pname, FloatBuffer data); /** * Returns a double OpenAL state. @@ -133,7 +137,7 @@ public class CoreAL extends BaseAL implements BaseALConstants { * @param pname state to be queried * @param data Buffer to place the floats in */ - public static native void alGetDoublev(int pname, Buffer data); + public static native void alGetDoublev(int pname, DoubleBuffer data); /** * Retrieve an OpenAL string property. @@ -199,7 +203,7 @@ public class CoreAL extends BaseAL implements BaseALConstants { * @param pname name of the attribute to be set * @param floatdata Buffer to read floats from */ - public static native void alListenerfv(int pname, Buffer floatdata); + public static native void alListenerfv(int pname, FloatBuffer floatdata); /** * Gets an integer property of the listener. @@ -207,7 +211,7 @@ public class CoreAL extends BaseAL implements BaseALConstants { * @param pname name of the attribute to be retrieved * @param integerdata Buffer to write integer to */ - public static native void alGetListeneri(int pname, Buffer integerdata); + public static native void alGetListeneri(int pname, IntBuffer integerdata); /** * Gets a floating point property of the listener. @@ -215,7 +219,7 @@ public class CoreAL extends BaseAL implements BaseALConstants { * @param pname name of the attribute to be retrieved * @param floatdata Buffer to write float to */ - public static native void alGetListenerf(int pname, Buffer floatdata); + public static native void alGetListenerf(int pname, FloatBuffer floatdata); /** * Retrieves a floating point vector property of the listener. @@ -223,7 +227,7 @@ public class CoreAL extends BaseAL implements BaseALConstants { * @param pname name of the attribute to be retrieved * @param floatdata Buffer to write floats to */ - public static native void alGetListenerfv(int pname, Buffer floatdata); + public static native void alGetListenerfv(int pname, FloatBuffer floatdata); /** * Generate one or more sources. @@ -231,7 +235,7 @@ public class CoreAL extends BaseAL implements BaseALConstants { * @param n number of sources to generate * @param sources array holding sources */ - public static native void alGenSources(int n, Buffer sources); + public static native void alGenSources(int n, IntBuffer sources); /** * Delete one or more sources. @@ -239,7 +243,7 @@ public class CoreAL extends BaseAL implements BaseALConstants { * @param n Number of sources to delete * @param source Source array to delete from */ - public static native void alDeleteSources(int n, Buffer source); + public static native void alDeleteSources(int n, IntBuffer source); /** * Tests if a source is valid. @@ -291,7 +295,7 @@ public class CoreAL extends BaseAL implements BaseALConstants { * @param pname name of the attribute being set * @param floatdata Buffer to read floats from */ - public static native void alSourcefv(int source, int pname, Buffer floatdata); + public static native void alSourcefv(int source, int pname, FloatBuffer floatdata); /** * Retrieves an integer property of a source. @@ -300,7 +304,7 @@ public class CoreAL extends BaseAL implements BaseALConstants { * @param pname name of property * @param integerdata Buffer to write integer to */ - public static native void alGetSourcei(int source, int pname, Buffer integerdata); + public static native void alGetSourcei(int source, int pname, IntBuffer integerdata); /** * Retrieves a floating point property of a source. @@ -309,7 +313,7 @@ public class CoreAL extends BaseAL implements BaseALConstants { * @param pname name of property * @param floatdata Buffer to write float to */ - public static native void alGetSourcef(int source, int pname, Buffer floatdata); + public static native void alGetSourcef(int source, int pname, FloatBuffer floatdata); /** * Gets a floating point vector property from a Source object. @@ -318,7 +322,7 @@ public class CoreAL extends BaseAL implements BaseALConstants { * @param pname property to get * @param floatdata Buffer to write floats to */ - public static native void alGetSourcefv(int source, int pname, Buffer floatdata); + public static native void alGetSourcefv(int source, int pname, FloatBuffer floatdata); /** * Plays a set of sources. @@ -326,7 +330,7 @@ public class CoreAL extends BaseAL implements BaseALConstants { * @param n number of sources to play * @param sources array of sources to play */ - public static native void alSourcePlayv(int n, Buffer sources); + public static native void alSourcePlayv(int n, IntBuffer sources); /** * Pauses a set of sources. @@ -334,7 +338,7 @@ public class CoreAL extends BaseAL implements BaseALConstants { * @param n number of sources to pause * @param sources array of sources to pause */ - public static native void alSourcePausev(int n, Buffer sources); + public static native void alSourcePausev(int n, IntBuffer sources); /** * Stops a set of sources. @@ -342,7 +346,7 @@ public class CoreAL extends BaseAL implements BaseALConstants { * @param n number of sources to stop * @param sources array of sources to stop */ - public static native void alSourceStopv(int n, Buffer sources); + public static native void alSourceStopv(int n, IntBuffer sources); /** * Rewinds a set of sources. @@ -350,7 +354,7 @@ public class CoreAL extends BaseAL implements BaseALConstants { * @param n number of sources to rewind * @param sources array of sources to rewind */ - public static native void alSourceRewindv(int n, Buffer sources); + public static native void alSourceRewindv(int n, IntBuffer sources); /** * Play a source. @@ -386,7 +390,7 @@ public class CoreAL extends BaseAL implements BaseALConstants { * @param n number of buffers to generate * @param buffers holding buffers */ - public static native void alGenBuffers(int n, Buffer buffers); + public static native void alGenBuffers(int n, IntBuffer buffers); /** * Delete one or more buffers. @@ -394,7 +398,7 @@ public class CoreAL extends BaseAL implements BaseALConstants { * @param n Number of buffers to delete * @param buffers Buffer to delete from */ - public static native void alDeleteBuffers(int n, Buffer buffers); + public static native void alDeleteBuffers(int n, IntBuffer buffers); /** * Tests if buffer is valid. @@ -416,7 +420,7 @@ public class CoreAL extends BaseAL implements BaseALConstants { public static native void alBufferData( int buffer, int format, - Buffer data, + ByteBuffer data, int size, int freq); @@ -427,7 +431,7 @@ public class CoreAL extends BaseAL implements BaseALConstants { * @param pname name of property to retrieve * @param integerdata Buffer to write integer to */ - public static native void alGetBufferi(int buffer, int pname, Buffer integerdata); + public static native void alGetBufferi(int buffer, int pname, IntBuffer integerdata); /** * Retrieves a floating point property from a buffer. @@ -436,7 +440,7 @@ public class CoreAL extends BaseAL implements BaseALConstants { * @param pname name of property to retrieve * @param floatdata Buffer to write float to */ - public static native void alGetBufferf(int buffer, int pname, Buffer floatdata); + public static native void alGetBufferf(int buffer, int pname, FloatBuffer floatdata); /** * Queues a set of buffers on a source. @@ -445,7 +449,7 @@ public class CoreAL extends BaseAL implements BaseALConstants { * @param n number of buffers to be queued * @param buffers buffers to be queued */ - public static native void alSourceQueueBuffers(int source, int n, Buffer buffers); + public static native void alSourceQueueBuffers(int source, int n, IntBuffer buffers); /** * Unqueues a set of buffers attached to a source. @@ -454,7 +458,7 @@ public class CoreAL extends BaseAL implements BaseALConstants { * @param n number of buffers to be unqueued * @param buffers buffers to be unqueued */ - public static native void alSourceUnqueueBuffers(int source, int n, Buffer buffers); + public static native void alSourceUnqueueBuffers(int source, int n, IntBuffer buffers); /** * Selects the OpenAL distance model. diff --git a/src/java/org/lwjgl/test/openal/ALTest.java b/src/java/org/lwjgl/test/openal/ALTest.java index 04e3fba5..d4ec1e0c 100644 --- a/src/java/org/lwjgl/test/openal/ALTest.java +++ b/src/java/org/lwjgl/test/openal/ALTest.java @@ -834,10 +834,10 @@ public class ALTest extends BasicTest { } protected void fA_GetBufferProperties() { - ByteBuffer freq = createByteBuffer(16); - ByteBuffer bits = ((ByteBuffer) freq.position(4)).slice().order(ByteOrder.nativeOrder()); - ByteBuffer chan = ((ByteBuffer) freq.position(8)).slice().order(ByteOrder.nativeOrder()); - ByteBuffer size = ((ByteBuffer) freq.position(12)).slice().order(ByteOrder.nativeOrder()); + IntBuffer freq = createByteBuffer(16).asIntBuffer(); + IntBuffer bits = ((IntBuffer) freq.position(4)).slice(); + IntBuffer chan = ((IntBuffer) freq.position(8)).slice(); + IntBuffer size = ((IntBuffer) freq.position(12)).slice(); boolean passNULL; System.out.print("\nGet Buffer Properties Test. "); @@ -849,7 +849,7 @@ public class ALTest extends BasicTest { passNULL = !(AL.alIsBuffer(0)); // the NULL buffer should cause alIsBuffer to be FALSE // FREQ BITS CH SIZE - if ((freq.getInt(0) == 44100) && (bits.getInt(0) == 16) && (chan.getInt(0) == 1) && (size.getInt(0) == 282626) && (passNULL == true)) { + if ((freq.get(0) == 44100) && (bits.get(0) == 16) && (chan.get(0) == 1) && (size.get(0) == 282626) && (passNULL == true)) { System.out.print("PASSED."); } else { System.out.print("FAILED."); @@ -1639,10 +1639,10 @@ public class ALTest extends BasicTest { AL.alSourcei(testSources.get(0), AL.AL_LOOPING, AL.AL_FALSE); if ((error = AL.alGetError()) != AL.AL_NO_ERROR) displayALError("Init error : ", error); - AL.alSourceQueueBuffers(testSources.get(0), 1, ((ByteBuffer)buffers.position(4*6)).slice().order(ByteOrder.nativeOrder())); + AL.alSourceQueueBuffers(testSources.get(0), 1, ((ByteBuffer)buffers.position(4*6)).slice().asIntBuffer()); if ((error = AL.alGetError()) != AL.AL_NO_ERROR) displayALError("alSourceQueueBuffers 1 (stereo) : ", error); - AL.alSourceQueueBuffers(testSources.get(0), 1, ((ByteBuffer)buffers.position(4*6)).slice().order(ByteOrder.nativeOrder())); + AL.alSourceQueueBuffers(testSources.get(0), 1, ((ByteBuffer)buffers.position(4*6)).slice().asIntBuffer()); if ((error = AL.alGetError()) != AL.AL_NO_ERROR) displayALError("alSourceQueueBuffers 1 (stereo) : ", error); AL.alSourcePlay(testSources.get(0)); @@ -1685,7 +1685,7 @@ public class ALTest extends BasicTest { AL.alSourcei(testSources.get(0), AL.AL_LOOPING, AL.AL_FALSE); if ((error = AL.alGetError()) != AL.AL_NO_ERROR) displayALError("Init error : ", error); - AL.alSourceQueueBuffers(testSources.get(0), 1, ((ByteBuffer)buffers.position(4*6)).slice().order(ByteOrder.nativeOrder())); + AL.alSourceQueueBuffers(testSources.get(0), 1, ((ByteBuffer)buffers.position(4*6)).slice().asIntBuffer()); if ((error = AL.alGetError()) != AL.AL_NO_ERROR) displayALError("alSourceQueueBuffers 1 (stereo) : ", error); AL.alSourcePlay(testSources.get(0)); @@ -1699,14 +1699,14 @@ public class ALTest extends BasicTest { } else { AL.alSourceUnqueueBuffers(testSources.get(0), tempInt.get(0), bufferName); } - AL.alSourceQueueBuffers(testSources.get(0), 1, ((ByteBuffer)buffers.position(4*6)).slice().order(ByteOrder.nativeOrder())); + AL.alSourceQueueBuffers(testSources.get(0), 1, ((ByteBuffer)buffers.position(4*6)).slice().asIntBuffer()); if ((error = AL.alGetError()) != AL.AL_NO_ERROR) displayALError("alSourceQueueBuffers 1 (stereo) : ", error); AL.alSourcePlay(testSources.get(0)); delay_ms(3000); System.out.print("The stereo buffer will now play twice with no pause (Press Return):\n"); CRToContinue(); - AL.alSourceQueueBuffers(testSources.get(0), 1, ((ByteBuffer)buffers.position(4*6)).slice().order(ByteOrder.nativeOrder())); + AL.alSourceQueueBuffers(testSources.get(0), 1, ((ByteBuffer)buffers.position(4*6)).slice().asIntBuffer()); AL.alSourcePlay(testSources.get(0)); delay_ms(4000); CRForNextTest(); @@ -2352,28 +2352,28 @@ public class ALTest extends BasicTest { displayALError("alSourceQueueBuffers 4 : ", error); break; case '5': - AL.alSourceQueueBuffers(source.get(0), 1, ((ByteBuffer)buffers.position(4*0)).slice().order(ByteOrder.nativeOrder())); + AL.alSourceQueueBuffers(source.get(0), 1, ((ByteBuffer)buffers.position(4*0)).slice().asIntBuffer()); if ((error = AL.alGetError()) != AL.AL_NO_ERROR) displayALError("alSourceQueueBuffers 1 : ", error); break; case '6': - AL.alSourceQueueBuffers(source.get(0), 1, ((ByteBuffer)buffers.position(4*1)).slice().order(ByteOrder.nativeOrder())); + AL.alSourceQueueBuffers(source.get(0), 1, ((ByteBuffer)buffers.position(4*1)).slice().asIntBuffer()); if ((error = AL.alGetError()) != AL.AL_NO_ERROR) displayALError("alSourceQueueBuffers 1 : ", error); break; case '7': - AL.alSourceQueueBuffers(source.get(0), 1, ((ByteBuffer)buffers.position(4*2)).slice().order(ByteOrder.nativeOrder())); + AL.alSourceQueueBuffers(source.get(0), 1, ((ByteBuffer)buffers.position(4*2)).slice().asIntBuffer()); if ((error = AL.alGetError()) != AL.AL_NO_ERROR) displayALError("alSourceQueueBuffers 1 : ", error); break; case '8': - AL.alSourceQueueBuffers(source.get(0), 1, ((ByteBuffer)buffers.position(4*3)).slice().order(ByteOrder.nativeOrder())); + AL.alSourceQueueBuffers(source.get(0), 1, ((ByteBuffer)buffers.position(4*3)).slice().asIntBuffer()); if ((error = AL.alGetError()) != AL.AL_NO_ERROR) displayALError("alSourceQueueBuffers 1 : ", error); break; case '9': // Queue buffer 0 - AL.alSourceQueueBuffers(source.get(0), 1, ((ByteBuffer)buffers.position(4*4)).slice().order(ByteOrder.nativeOrder())); + AL.alSourceQueueBuffers(source.get(0), 1, ((ByteBuffer)buffers.position(4*4)).slice().asIntBuffer()); if ((error = AL.alGetError()) != AL.AL_NO_ERROR) displayALError("alSourceQueueBuffers 1 (buffer 0) : ", error); break;