View Full Version : look at // openAL
06-26-2010, 12:03 AM
I've a camera which always point to the center. Now how could I set openAl listener orientation?
//get current view matrix
//set listener orientation, first 3 numbers are for the forward vector, last three are for the up vector
This doesn't work. Any help?
06-26-2010, 11:52 AM
Short answer: yes your code appears to be correct.
Long answer below:
First ensure you are using OpenAL-Soft, so you'll know for sure that the OpenAL implementation you use is not full of bugs:
Then ensure your application is actually using the OpenAL-Soft software renderer by selecting the proper device.
I mention this because there are few hardware OpenAL drivers from Creative/Realtek that actually gets the listener orientation right (believe it or not). I have wasted weeks only to find out that nothing was wrong with my code. Always use software audio, hardware is long dead and highly unreliable.
OpenAL listener orientation requires two parameters stored in a single array; a forward facing vector and 'up-vector', both in world space orientation.
Pseudo code from our engine:
float m; // world space camera transform
vec3 position = vec3( m, m, m ); // world space position
vec3 up = vec3( m, m, m ); // world space up vector
vec3 front = vec3( -m, -m, -m ); // vector facing forward from camera/listener position
ori = fr.x;
ori = fr.y;
ori = fr.z;
ori = up.x;
ori = up.y;
ori = up.z;
Keep in mind that 'm' here, is a regular transformation matrix (e.g. the same you use to transform an entity to it's world space position).
So you have to take the inverse of GL_MODELVIEW_MATRIX (or the transpose if you are only interested in the rotation part, which is much much easier to compute).
For reference, this is how the view transform is set up in the same engine:
gluPerspective(camera->fov, asp, camera->nearplane, camera->farplane);
glMultMatrixf( camera->transform->GetInverse() );
Hope that helps.
06-28-2010, 12:08 PM
Many thanks for your answer. I'll try again tomorrow. I've spent over a week on this:
Still only a mess...But I'm on Linux, should I still use your link? Anyway later also on Mac & Win.
Any ideas on how to set sound positions using the above? Should move accordingly with the airplane. I also have a moving camera x,y,z and heading.
06-29-2010, 12:31 AM
As for now it looks like the sources are not moved. Do i need anything else as?
alSourcefv(Sources, AL_POSITION, SourcesPos);
PS: On Ubuntu I've the latest OpenAL
07-24-2010, 11:09 AM
Apologies for late response.
In the situation I posted above: in our engine we use Y=up, positive X-axis is to the right, and positive Z is pointing towards the rear of the viewer.
OpenAL source position is in world space if you set AL_SOURCE_RELATIVE to false:
alSourcei(source, AL_SOURCE_RELATIVE, AL_FALSE);
alSourcefv(source, AL_POSITION, pos);
To play local sounds (for example for GUI button clicks, music etc):
alSourcei(source, AL_SOURCE_RELATIVE, AL_TRUE);
alSourcefv(source, AL_POSITION, vec3(0,0,0) );
As for audio drivers, I haven't used Ubuntu in a while, but if your drivers are from Creative Labs, Realtek etc, I wouldn't trust it. I think OpenAL-Soft is distributed with some major distros (or at least readily available).
Think of OpenAL-Soft as reference implementation. Creative Labs' own reference implementation is depreciated by their own programmers (and thankfully no longer available). If you can get it to work with OpenAL-Soft, it should be correct.
Powered by vBulletin® Version 4.2.2 Copyright © 2016 vBulletin Solutions, Inc. All rights reserved.