• FEATURED

View more

View more

View more

### Image of the Day Submit

IOTD | Top Screenshots

### The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.

# SDL Audio - Volume proportional

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

3 replies to this topic

### #1FGFS  Members

Posted 26 June 2014 - 01:11 AM

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

### #2mdias  Members

Posted 26 June 2014 - 03:52 AM

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, 26 June 2014 - 03:54 AM.

### #3FGFS  Members

Posted 26 June 2014 - 04:42 AM

Clever solution, Many thanks.

### #4FGFS  Members

Posted 26 June 2014 - 10:47 AM

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, 27 June 2014 - 03:26 AM.

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.