Master volume via Listener GAIN- Quick Question

Started by coderguy22296, August 06, 2014, 03:13:54

Previous topic - Next topic

coderguy22296

I cannot find it anywhere how to adjust the AL_GAIN



FloatBuffer fb = <Im not quite sure how to set the gain>;
alListener(AL_GAIN, fb);

thanks,
coderguy

quew8

LWJGL provides a utility class for creating direct java.nio.Buffers (which is the sort required for OpenGL, OpenAL and OpenCL).

FloatBuffer fb = org.lwjgl.BufferUtils.createFloatBuffer(1);
fb.put(gain);
fb.flip(); //OpenAL will start reading values from the buffer's position until it's limit, so the buffer must be flipped.

coderguy22296

im kind of new to Open GL/AL , could you explain .flip() ?

quew8

java.nio.* like FloatBuffer, IntBuffer, ByteBuffer etc. are all part of the Java standard library. But I do find beginners tend to not know about them.

So a buffer is a lot like a regular Java array, it stores primitive data but it has a couple of important properties which differentiate it from an array: position and limit which are both indices in the buffer which determine how read/write methods work. position tells the buffer where to read or write to and it's initial value is 0. limit is like an imposed limit on the size of the buffer (It's actual size is called it's capacity) and it's initial value is the buffer's capacity.

So the read/write methods are put() and get(). There are indexed versions of these methods but I will explain the non-indexed versions. put() replaces the value at position with the one you pass to the method and then increments the position. get() works in a similar way, returning the value at position and then incrementing the position.

What flip() does is set the limit to the position and the position to 0. The idea is that you do a series of put()s, then flip() and the buffer is ready to read from with get().

When you pass data to OpenGL/OpenAL/OpenCL in a buffer, data starts to be read from the buffer's position until either it has enough data or it reaches the buffer's limit.

I hope that explains it.