Torque 2D advanced sound
by Bruce Morick · in Torque 2D Beginner · 03/20/2016 (5:07 pm) · 19 replies
Does anyone have an example of using the Advanced API functions. Particularly the alxSource3f(handle, ALEnum, x, y, z) function. All I found was "beyond the scope of this guide".
(creating 2D overhead) I want to create a fire that as you get closer - it gets louder.
(creating 2D overhead) I want to create a fire that as you get closer - it gets louder.
About the author
#2
The changes I've made were integrated into the development branch so all you need to do is
- set the scenewindow to process audio listeners
- create an AudioDescription with the appropriate Max_DISTANCE value
- call "Myfire.playSound("MyAssets:MySound, MyFancyAudioDescription);
The "ancient" method as described by Richard is how OpenAL works natively; any OpenAL tutorial/code snippet will show you how to modify sources.
Be sure to ALWAYS choose alx____ instead of the al____ functions, where ____ is the name of the function. the al_____ are for internal use only.
03/21/2016 (8:25 pm)
Hey Bruce!The changes I've made were integrated into the development branch so all you need to do is
- set the scenewindow to process audio listeners
- create an AudioDescription with the appropriate Max_DISTANCE value
- call "Myfire.playSound("MyAssets:MySound, MyFancyAudioDescription);
The "ancient" method as described by Richard is how OpenAL works natively; any OpenAL tutorial/code snippet will show you how to modify sources.
Be sure to ALWAYS choose alx____ instead of the al____ functions, where ____ is the name of the function. the al_____ are for internal use only.
#3
I am currently working with (straight out of the box) 3.1 since 3.2 Android build and Android write file do not work. So I will wait... I have plenty of other areas to work on until then.
03/21/2016 (10:02 pm)
Thanks... I assume this will be coming out with version 3.3.I am currently working with (straight out of the box) 3.1 since 3.2 Android build and Android write file do not work. So I will wait... I have plenty of other areas to work on until then.
#5
03/21/2016 (10:34 pm)
Thanks... not that adventurous right now. I temporarily scripted a volume/distance to a x/y point (non-aural-directional) routine. I will revisit it when 3.3 is released.
#6
As for Eclipse/ADT I haven't updated since Google deprecated and stopped supporting that IDE and plugin 7 months ago.
03/22/2016 (11:26 am)
Are you using Android Studio or Eclipse with ADT? I fixed the Android Studio building myself which were merged into Development branch.As for Eclipse/ADT I haven't updated since Google deprecated and stopped supporting that IDE and plugin 7 months ago.
#7
03/22/2016 (2:03 pm)
Eclipse with ADT. I thought there were problems with Android Studio and Torque 2D. Do you have a step-by-step Studio install for Torque 2D utilization?
#8
04/02/2016 (7:13 pm)
Thank you very much for continuing to develop this. Can't wait to see what 3.3 brings :)
#9
new AudioDescription(AUDIO_LOOPING){
is3D = true;
isLooping = true;
ReferenceDistance = 5.0;
MaxDistance = 25.0;
volume = 0.5;
};
04/06/2016 (11:25 am)
@simon - I am now using 3.3. Is the volume supposed to change between ReferenceDistance and MaxDistance? I am getting the same level no matter the distance. It appears to be either on or off.new AudioDescription(AUDIO_LOOPING){
is3D = true;
isLooping = true;
ReferenceDistance = 5.0;
MaxDistance = 25.0;
volume = 0.5;
};
#10
The Distance Model
The distance model used in T2D is AL_INVERSE_DISTANCE, while the OpenAL documentation point out that the default mode is AL_INVERSE_DISTANCE_CLAMPED. I did not change this from stock T2D but I think a tiny pull request might help clarify matters.
Both algorithms (and the math behind them) are described in the
OpenAL 1.1 documentation.
Max_Distance
From the docs :
As such, Max_distance isn't taken into consideration with unClamped Distance models.
That being said, you can change the distance model in audio.cc, just search for AL_INVERSE_DISTANCE.
Reference_Distance
Once again from the docs :
04/06/2016 (12:25 pm)
@Bruce : The answer is a bit long but should help make it work for you. Make sure that you called MySceneWindow.setAudioListener(true); or 3d positioning simply won't work.The Distance Model
The distance model used in T2D is AL_INVERSE_DISTANCE, while the OpenAL documentation point out that the default mode is AL_INVERSE_DISTANCE_CLAMPED. I did not change this from stock T2D but I think a tiny pull request might help clarify matters.
Both algorithms (and the math behind them) are described in the
OpenAL 1.1 documentation.
Max_Distance
From the docs :
Quote:used with the Inverse Clamped Distance Model to set the distance where there will no longer be any attenuation of the source
As such, Max_distance isn't taken into consideration with unClamped Distance models.
That being said, you can change the distance model in audio.cc, just search for AL_INVERSE_DISTANCE.
Reference_Distance
Once again from the docs :
Quote:
the distance under which the volume for the source would normally drop by half (before being influenced by rolloff factor or AL_MAX_DISTANCE)
#11
I have tried all of the following to no avail:
alDistanceModel(AL_INVERSE_DISTANCE);
alDistanceModel(AL_INVERSE_DISTANCE_CLAMPED);
alDistanceModel(AL_LINEAR_DISTANCE);
The volume is the same from the object till MaxDistance in which the sound stops.
I did notice that the 3.3 that I downloaded reports V3.2
==>echo(getengineversion());
v3.2
Did the version number not get updated or is there a problem with the download?
04/06/2016 (4:28 pm)
@simon - I did have the mySceneWindow.setAudioListener(true);I have tried all of the following to no avail:
alDistanceModel(AL_INVERSE_DISTANCE);
alDistanceModel(AL_INVERSE_DISTANCE_CLAMPED);
alDistanceModel(AL_LINEAR_DISTANCE);
The volume is the same from the object till MaxDistance in which the sound stops.
I did notice that the 3.3 that I downloaded reports V3.2
==>echo(getengineversion());
v3.2
Did the version number not get updated or is there a problem with the download?
#12
I had made tests in this regard early on but the remaining work was mostly based on ensuring that panning works correctly.
Will have to test thoroughly.
I have no idea about the 3.2 engine version string.
04/06/2016 (5:08 pm)
I made some tests and you are right, with default settings, the sound doesn't seem to lower in volume as distance is increased.I had made tests in this regard early on but the remaining work was mostly based on ensuring that panning works correctly.
Will have to test thoroughly.
I have no idea about the 3.2 engine version string.
#13
04/06/2016 (5:12 pm)
thanks... thought I was going crazy (short trip....)
#15
1 - Your audio file MUST be MONO in order for it to be considered at all for distance attenuation.
2 - A simple sprite moving across the center of the screen works as expected with the following AudioDescription (i.e. attenuates with distance)
04/06/2016 (5:27 pm)
I've made some tests and it seems to work fine!1 - Your audio file MUST be MONO in order for it to be considered at all for distance attenuation.
2 - A simple sprite moving across the center of the screen works as expected with the following AudioDescription (i.e. attenuates with distance)
new AudioDescription(LOOPS_ADESC){
is3D = true;
ReferenceDistance = 15.0;
MaxDistance = 125.0;
isLooping = true;
};
#16
04/06/2016 (5:30 pm)
edit : works with inverse_linear_clamped and inverse_linear
#17
Great job on implementation.
04/06/2016 (6:52 pm)
works GREAT now - using out-of-box version and it was the STEREO .vs. MONO was causing the problem. Now to convert all my SFX to mono. Great job on implementation.
#18
04/06/2016 (7:01 pm)
Thanks Bruce! You're probably the only other user who has tested this extensively so do not hesitate to share your findings or suggest improvements.
#19
04/07/2016 (8:47 am)
And thanks for finding the version string. That would be my fault. I'll have to hunt it down and update it.
Torque Owner Richard Ranft
Roostertail Games
Looks like the old way was annoying - random untested whack:
%source = alxCreateSource("Assets:MySoundAssetID"); // the alxSource* functions set parameters, alxGetSource* get the values. // the AL_* enumerations are in source/audio/audio_ScriptBinding.cc near the top. alxSource3f(%source, AL_POSITION, %posX, %posY, 0.0); // pretty sure camera looks "down" alxSourceF(%source, AL_MAX_DISTANCE, %maxDist); alxSourceI(%source, AL_LOOPING, 1); // wild guess that 1 is "true" - might be "loop once" but that seems weird.