OpenAL Implementation Fix for TGB : ALgetlistener3f
by Simon Love · 01/31/2007 (2:41 pm) · 0 comments
Greetings!
The ALgetlistener3f function simply returns the current position of the Listener in an OpenAL environment.
I could simply paste the revised working function, but I chose to comment all the changes, so that others might learn from this...I sure did. :)
Here is the function as it stands now in TGB,TGE and TGEA. Let's open up the file audiofunctions.cc in our audio folder. This is all in C++, if you must know.
On the first line of the function,argv[2] verifies if the parameter passed is a valid ALENUM.
Since only 1 argument is passed to the function, this will always return an error. Simply changing argv[2] to argv[1] fixes this problem.
Still on our first line, (Source|Get|Float) specifies what flags to look for in the selected ALEnum.
Since this function is about the Listener and not an audio Source, Source needs to be changed to Listener. This should also be modified in the functions alxgetlistenerf and alxgetlisteneri.
Same line again, Float needs to be changed to Float3.
Now, the function is fixed on the input side, making sure the right values are passed to it.
The final problem lies in the next-to-last line (the one that starts with dsprintf) which formats these values before returning them.
As it stands now, only the first value is returned, simply because f has not been added after those two last %7.3.
Here is the revised and working version of the same function.
Make the same changes (except for the source to listener ones) to the alxgetsourcefloat3 function in the same file as it is also non-working.
For more info on the audio functions of the Engine, feel free to consult this article on TDN tdn.garagegames.com/wiki/TorqueScript_Console_Functions
The ALgetlistener3f function simply returns the current position of the Listener in an OpenAL environment.
I could simply paste the revised working function, but I chose to comment all the changes, so that others might learn from this...I sure did. :)
Here is the function as it stands now in TGB,TGE and TGEA. Let's open up the file audiofunctions.cc in our audio folder. This is all in C++, if you must know.
ConsoleFunction(alGetListener3f, const char *, 2, 2, "alGetListener3f(Alenum)")
{
ALenum e = getEnum(argv[2], (Source|Get|Float));
if(e == AL_INVALID)
{
Con::errorf(ConsoleLogEntry::General, "alGetListener3f: invalid enum name '%s'", argv[1]);
return("0 0 0");
}
F32 value1, value2, value3;
alGetListener3f(e, &value1, &value2, &value3);
char * ret = Con::getReturnBuffer(64);
dSprintf(ret, 64, "%7.3f %7.3 %7.3", value1, value2, value3);
return(ret);
}On the first line of the function,argv[2] verifies if the parameter passed is a valid ALENUM.
Since only 1 argument is passed to the function, this will always return an error. Simply changing argv[2] to argv[1] fixes this problem.
Still on our first line, (Source|Get|Float) specifies what flags to look for in the selected ALEnum.
Since this function is about the Listener and not an audio Source, Source needs to be changed to Listener. This should also be modified in the functions alxgetlistenerf and alxgetlisteneri.
Same line again, Float needs to be changed to Float3.
Now, the function is fixed on the input side, making sure the right values are passed to it.
The final problem lies in the next-to-last line (the one that starts with dsprintf) which formats these values before returning them.
As it stands now, only the first value is returned, simply because f has not been added after those two last %7.3.
Here is the revised and working version of the same function.
ConsoleFunction(alGetListener3f, const char *, 2, 2, "alGetListener3f(Alenum)")
{
ALenum e = getEnum(argv[1], (Listener|Get|Float3));
if(e == AL_INVALID)
{
Con::errorf(ConsoleLogEntry::General, "alGetListener3f: invalid enum name '%s'", argv[1]);
return("0 0 0");
}
F32 value1, value2, value3;
alGetListener3f(e, &value1, &value2, &value3);
char * ret = Con::getReturnBuffer(64);
dSprintf(ret, 64, "%7.3f %7.3f %7.3f", value1, value2, value3);
return(ret);
}Make the same changes (except for the source to listener ones) to the alxgetsourcefloat3 function in the same file as it is also non-working.
For more info on the audio functions of the Engine, feel free to consult this article on TDN tdn.garagegames.com/wiki/TorqueScript_Console_Functions
About the author