How to adjust the volume of a sound in OpenAL?
Asked Answered
N

2

9

How can I adjust the volume of a sound in the OpenAL sound library?

Nemeth answered 28/9, 2010 at 15:46 Comment(1)
related: #3983223Mimas
P
18
float newVolume = 0.4f;
alSourcef(currentSourceID, AL_GAIN, newVolume);
Pitiful answered 20/2, 2011 at 17:2 Comment(3)
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
R
3

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;
}
Rosenquist answered 5/8, 2021 at 9:0 Comment(1)
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.