How can I adjust the volume of a sound in the OpenAL sound library?
Asked
Active
Viewed 9,683 times
2 Answers
17
float newVolume = 0.4f;
alSourcef(currentSourceID, AL_GAIN, newVolume);

Jay
- 4,480
- 3
- 25
- 22
-
I believe he meant adjusting the device volume rather than the sound source gain. At least that's what **I** was hoping for when I found this question. – cregox Feb 21 '11 at 04:43
-
12device volume? Maybe you should look into the listener object? Then you can easily set the listener's AL_GAIN with: alListenerf(currentSourceID, AL_GAIN, newVolume); – Jay Feb 21 '11 at 05:29
-
3
You can change the global volume by setting the gain of the listener.
void Listener::setVolume(float v)
{
Assert::isTrue(0 <= v && v <= 1);
alListenerf(AL_GAIN, v);
}
float Listener::getVolume()
{
ALfloat v;
alGetListenerf(AL_GAIN, &v);
return v;
}

ShenMian
- 61
- 5
-
1Welcome to StackOverflow! Thank you for your contribution, but it would be great if you could add some comments or notes about your code too! Will still upvote :) – Haris Nadeem Aug 05 '21 at 15:54