SFML community forums

Help => Audio => Topic started by: dk123 on October 04, 2014, 07:59:53 pm

Title: Playing sound at volume above 100
Post by: dk123 on October 04, 2014, 07:59:53 pm
The current implementation of sounds seems to limit
the volume at 100(%). It would be nice if sounds could
be played at higher volumes than they're original file volumes.

(ex. 250%, 500%, etc.)
Title: Re: Playing sound at volume above 100
Post by: zsbzsb on October 04, 2014, 08:12:07 pm
Correct me if I am wrong, but this is a limit of OpenAL, not SFML.
Title: Re: Playing sound at volume above 100
Post by: Laurent on October 04, 2014, 08:39:53 pm
The OpenAL specification says:

Quote
AL_GAIN larger than one (i.e. amplification) is permitted for source and listener.
However, the implementation is free to clamp the total gain (effective gain per-source
multiplied by the listener gain) to one to prevent overflow

So it depends on the OpenAL implementation. And there's nothing we can do in SFML.
Title: Re: Playing sound at volume above 100
Post by: Hapax on October 05, 2014, 02:41:16 am
Solution (http://audacity.sourceforge.net/). hehe
Title: Re: Playing sound at volume above 100
Post by: dmitry_t on May 30, 2022, 02:39:26 pm
I needed to amplify too quiet sounds without using the Audacity.
So just to conclude.

You CAN pass a volume value greater than 100.
The OpenAL implementation clips too high values forcing them to be in the int16 range obviously.
So if you don't want the sound to be overloaded, the actual max volume value for a specific sound depends on the max sample values. E.g. having max absolute sample value equal to 3276 you can pass volume value up to 32767 / 3276 * 100 = 1000 (where 32767 is the max positive int16).

There are many ways to check the sample values, e.g. you can use the sf::SoundBuffer class to get samples.
I personally used a Python script like that:

import pyogg

ogg_file = pyogg.VorbisFile(file_path)
buffer = ogg_file.as_array()
print(buffer.min(), buffer.max())


P.S. Sorry for posting into a thread which is several years old.