How can I adjust the volume of a sound in the OpenAL sound library?
How to adjust the volume of a sound in OpenAL?
float newVolume = 0.4f;
alSourcef(currentSourceID, AL_GAIN, newVolume);
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. –
Mimas
device 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); –
Pitiful
He said "of a sound". –
Christa
You can change the global volume by setting the gain of the listener.
void Listener::setVolume(float v)
{
alListenerf(AL_GAIN, v);
}
float Listener::getVolume()
{
ALfloat v;
alGetListenerf(AL_GAIN, &v);
return v;
}
Welcome 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 :) –
Objectivism
© 2022 - 2024 — McMap. All rights reserved.