Jump to content
  • Advertisement
Sign in to follow this  
FGFS

SDL Audio - Volume proportional

This topic is 1456 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi
  I want the sound to have more audible difference:

                    if (veN1 >= 65){
                    alListenerf(AL_GAIN, (veN1/100)*2);
                    } else{
                        alListenerf(AL_GAIN, (veN1/100)*0.5);
                    }

Is not nicely linear. Any idea on how to improve the above? veN1 only goes from 50 to 80.

Many thanks

Share this post


Link to post
Share on other sites
Advertisement

Your problem occurs because humans don't perceive sound linearly.

 

try:

float lin_volume = (float)(veN-50) / 30.f;
alListenerf( AL_GAIN, powf(lin_volume, exp) );

where "exp" try E or some other value (>0.0f) that sounds better to you.

Edited by mdias

Share this post


Link to post
Share on other sites

PS: never mind after changing sound format all is fine.

 

 

 

Works fine but one more thing. I want to fade out sound with distance. I've tried alike but I don't understand powf:

                    float lin_volume = (float)(veN1-50) / 30.f;
                    if (disZ <= 8){
                    alListenerf( AL_GAIN, powf(lin_volume, 0.7) );
                    }else{
                    alListenerf( AL_GAIN, lin_volume-((disX+disY+disZ/3)/100) );
                    }

 

disY etc is distance in x, y and z. So sound should fade out from ca. 8 till 20. But with the above I get weird results while cycling around the source.

Thanks again

Edited by FGFS

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!