[SOLVED] Binaural 3D OpenAL - LWJGL3

Started by hekk000, December 07, 2015, 14:53:36

Previous topic - Next topic

hekk000

Hi guys!

I've run into a problem, and now I feel totally retarded, but I just cannot figure out what is wrong, I've even go as far as thinking that this function might not even get integrated into the project yet, so I'm gonna ask now.

I'm trying to make 3D sound using the LWJGL3's OpenAL libs, I've already loaded the files, it's playing, looping, I can change the volume, pitch, but I cannot set it's position.
Well, I can, but nothing changes actually...

So I have this:

public void setPosition(float x, float y, float z)
{
	AL10.alSource3f(source, AL10.AL_POSITION, x, y, z);
	checkALError();
	AL10.alSource3f(source, AL10.AL_VELOCITY, 0, 0, 0);
	checkALError();
}

public void setListenerPosition(float x, float y, float z)
{
	FloatBuffer listenerOri = (FloatBuffer)BufferUtils.createFloatBuffer(6).put(new float[] { 0.0f, 0.0f, -1.0f, 0.0f, 1.0f, 0.0f }).rewind();

	AL10.alListener3f(AL10.AL_POSITION, x, y, z);
	checkALError();
	AL10.alListener3f(AL10.AL_VELOCITY, 0, 0, 0);
	checkALError();
	AL10.alListenerfv(AL10.AL_ORIENTATION, listenerOri);
	checkALError();
}


I call setPosition (with 0, 0, 0) once, when the music starts to play, then call setListenerPosition periodically in my game loop (with the position of the camera). It should make the sound coming from the set direction, shouldn't it? (Except for the rotation of course, I didn't wanted to mess with that until this works) Am I missing something? Should I call some magic code that activates this?

Thanks for the help in in advance.  :)




As for the solution (Credit goes to abcdef):

Use mono files, also change the settings then:

alBufferData(buffer, AL_FORMAT_MONO16, pcm, info.sample_rate());

abcdef

Is your sound stereo?

If so then calculation of which channel the sound comes in is already computed by the PCM data. If its mono then openal does the calculation itself.

So if you aren't using mono sounds then try with mono sounds.

hekk000

Oh wow, yeah, now it's working. Haha, didn't thought of that. Thank you!

Then there is no way to use stereo files? I mean without messing around with it. Hmm, interesting, I might split the stereo buffer then and place two different sources, it should be easy enough.

Thank you again!

abcdef

Sorry there isn't, stereo is already localised. You need an unlocalised source for it to work