Sign in to follow this  
FGFS

SDL Audio - Volume proportional

Recommended Posts

FGFS    345
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
mdias    823

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
FGFS    345

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

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