[SOLVED] stop sound completely after some distance

deshan

14-01-2010 10:29:18

Hi sticky
I have this code
OgreOggSound::OgreOggISound* forkLiftSound = mSoundMngr->createSound("FORKLIFT_SOUND", "FORKLIFT.wav", false, true);
forkLiftNode->attachObject(forkLiftSound);
forkLiftSound->setReferenceDistance(25);
forkLiftSound->setVolume(0.5);
forkLiftSound->play();


The code works fine. But I do not know how to stop this sound completely after some distance. setMaxDistance does not works as i expected. Lets say I have to stop sound after distance of 30. But setMaxDistance(30) does not do this?. I can notice a sound level reduction when I move away from the object but at very long distace still i hear this sound at very low volume. How to stop this?

stickymango

15-01-2010 00:11:45

The easiest way is to use the linear distance model, otherwise you'll have to experiment with the max distance / roll off factor / reference distance values. The max distance value merely specifies the distance at which attenuation is no longer applied therefore the current volume at that point will remain no matter how far away you get...

See here: http://msdn.microsoft.com/en-us/library/bb318697%28VS.85%29.aspx

deshan

16-01-2010 04:47:00

hmmm... I can understand. That article is really useful. Thank you
And sticky I have done that experiment.
This is it
forkLiftSound->setRolloffFactor(1.0f);
forkLiftSound->setReferenceDistance(20);
forkLiftSound->setVolume(0.5f);


the rollofffactor make troubles. It has to be 1. If it 1.01 problem, if it 0.99 again problem Do not know why. But above is fine for my application.
Any way what is that linear model. I have searched all methods and forum. none found.

stickymango

17-01-2010 20:21:52

OpenAL has several algorithms for calculating attenuation, the default is AL_INVERSE_DISTANCE_CLAMPED. You can set another algorithm using OgreOggSoundManager::setDistanceModel() and pass AL_LINEAR_DISTANCE to use linear attenuation, this should fade the volume to min at maxDistance.

See the OpenAL programmers guide.pdf file for details..

deshan

26-01-2010 07:43:28

Sorry for late reply. I was bit busy.
You can set another algorithm using OgreOggSoundManager::setDistanceModel() and pass AL_LINEAR_DISTANCE to use linear attenuation, this should fade the volume to min at maxDistance.
That is good. Otherwise I have to adjust all the sounds in my project.

soundManager->setDistanceModel(AL_LINEAR_DISTANCE);
GameSoundManager::SoundManager::getSinglePointer()->getForkLiftSound()->setVolume(0.5);
GameSoundManager::SoundManager::getSinglePointer()->getForkLiftSound()->setReferenceDistance(8);

Is the final answer for my question

Thank you again stickymango :D

chaosavy

27-11-2010 17:00:14

first off thank you very much, I was able to install and get sound up and running. However I can't get past the same issue as the original poster (I hear the sound however it never falls silent).



mSoundManager->setDistanceModel(AL_LINEAR_DISTANCE); //Sounds become quiet after max distance

propulsionSys.propulsionSound->setMaxDistance(20.0f);
propulsionSys.propulsionSound->setReferenceDistance(10.0f);
propulsionSys.propulsionSound->setRolloffFactor(1.0f);


I'm using the linear model and tweaking the sound options but still no help, another post said to be sure to use stereo sounds so I tried to download some with no effect. I'm not sure if the code is the issue or if its the sound file. I tried using the 6chan.ogg file from the demo and the issue is the same, not sure where my problem is.

thanks again

deshan

27-11-2010 18:34:04

another post said to be sure to use stereo sounds

I think
another post said to be sure NOT to use stereo sounds

according to sticky

Stereo sounds cannot be positioned in 3D space, if you want spatialisation you MUST use MONO sounds only, open it in Sound recorder and try to change the properties, it will tell you its current properties...

chaosavy

27-11-2010 19:39:01

thanks, after a bit more searching (using your quote of sticky's about stereo versus mono) I found that the line below solved my problem, it works now. Yay! I thank you and my wife thanks you (less annoying sounds now).


mSoundManager->init("Generic Software");

stickymango

28-11-2010 01:11:53

Glad its sorted, although I have to admit I've found "Generic Software" to be the most reliable option when setting up 3d sounds, quite often it seems hardware implementations differ wildly in their final output. I use software by default in the majority of cases, and as there seems to be no noticeable performance difference, it seems a safer option.