OpenAL and FloatBuffer problem

Started by curmoISU, April 16, 2005, 17:44:19

Previous topic - Next topic

curmoISU

I'm copying the sample code almost exactly but I'm having a problem.  When trying to set any sort of position I get the following error:

java.lang.IllegalArgumentException: Number of remaining buffer elements is 0, must be at least 1
   at org.lwjgl.BufferChecks.checkBufferSize(BufferChecks.java:177)
   at org.lwjgl.BufferChecks.checkBuffer(BufferChecks.java:197)
   at org.lwjgl.openal.AL10.alListener(AL10.java:1014)


Here's the code where its failing:

   FloatBuffer sourcePos = BufferUtils.createFloatBuffer(3).put(new float[] { 0.0f, 0.0f, 0.0f });

   /** Velocity of the source sound. */
   FloatBuffer sourceVel = BufferUtils.createFloatBuffer(3).put(new float[] { 0.0f, 0.0f, 0.0f });

   /** Position of the listener. */
   FloatBuffer listenerPos = BufferUtils.createFloatBuffer(3).put(new float[] { 0.0f, 0.0f, 0.0f });

   /** Velocity of the listener. */
   FloatBuffer listenerVel = BufferUtils.createFloatBuffer(3).put(new float[] { 0.0f, 0.0f, 0.0f });

   /** Orientation of the listener. (first 3 elements are "at", second 3 are "up") */
   FloatBuffer listenerOri =
       BufferUtils.createFloatBuffer(6).put(new float[] { 0.0f, 0.0f, -1.0f,  0.0f, 1.0f, 0.0f });
   
   public void play3DSound(Sound sound, Vector3F sourcePosition, Vector3F sourceVelocityScaledDirection)
   {
       
       AL10.alListener(AL10.AL_POSITION,    listenerPos); //FAILS
       AL10.alListener(AL10.AL_VELOCITY,    listenerVel); //FAILS
       AL10.alListener(AL10.AL_ORIENTATION, listenerOri);   //FAILS
       
       AL10.alSourcei(sound.getAlSourceID(), AL10.AL_BUFFER,   sound.getAlSoundID());
       AL10.alSourcef(sound.getAlSourceID(), AL10.AL_PITCH,    1.0f          );
       AL10.alSourcef(sound.getAlSourceID(), AL10.AL_GAIN,     1.0f          );
       AL10.alSource (sound.getAlSourceID(), AL10.AL_POSITION, sourcePos     ); //FAILS
       AL10.alSource (sound.getAlSourceID(), AL10.AL_VELOCITY, sourceVel     ); //FAILS

       AL10.alSourcePlay(sound.getAlSourceID());
}

All of the lines marked //FAIL above will fail if put first with that buffer error.  What am I doing wrong???  I've tried in 0.95 and 0.96 with the same result.  Its like its expecting there to be 4 elements for each vector., but if I set the size of the buffers to 4, the error goes away but the sound doesnt' work.  Please help!

curmoISU

I discovered that if I .rewind() t he buffers, that error goes away.  However, I still don't hear the sound being played... ??

curmoISU

I fixed it.. When I was loading the sound file into a ByteBuffer I was forgetting to rewind it as well!  Its all fixed now!