Advertisement

SDL Audio - Volume proportional

Started by June 26, 2014 07:11 AM
2 comments, last by FGFS 10 years, 5 months ago
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

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.

Advertisement

Clever solution, Many thanks.

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

This topic is closed to new replies.

Advertisement