Sign in to follow this  

SDL Audio - Volume proportional

This topic is 1264 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

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

This topic is 1264 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this