Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to adjust the volume of a sound in OpenAL?

Tags:

iphone

openal

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

like image 451
openfrog Avatar asked Sep 28 '10 15:09

openfrog


2 Answers

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;
}
like image 113
ShenMian Avatar answered Nov 08 '22 18:11

ShenMian


float newVolume = 0.4f;
alSourcef(currentSourceID, AL_GAIN, newVolume);
like image 17
Jay Avatar answered Nov 08 '22 18:11

Jay