Hello Guest

Master volume via Listener GAIN- Quick Question

  • 3 Replies
  • 10783 Views
Master volume via Listener GAIN- Quick Question
« on: August 06, 2014, 03:13:54 »
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

*

Offline quew8

  • *****
  • 569
  • Because Square Eyes Look More Real
Re: Master volume via Listener GAIN- Quick Question
« Reply #1 on: August 06, 2014, 15:21:59 »
LWJGL provides a utility class for creating direct java.nio.Buffers (which is the sort required for OpenGL, OpenAL and OpenCL).

Code: [Select]
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.

Re: Master volume via Listener GAIN- Quick Question
« Reply #2 on: August 06, 2014, 15:29:59 »
im kind of new to Open GL/AL , could you explain .flip() ?

*

Offline quew8

  • *****
  • 569
  • Because Square Eyes Look More Real
Re: Master volume via Listener GAIN- Quick Question
« Reply #3 on: August 06, 2014, 16:10:21 »
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.