mirror of
https://github.com/mkxp-z/mkxp-z.git
synced 2025-09-10 12:02:53 +02:00
Add dB volume scale
This commit is contained in:
parent
1462dc9623
commit
aaf5d3c8bf
3 changed files with 21 additions and 4 deletions
|
@ -27,6 +27,8 @@
|
|||
|
||||
#include <SDL_audio.h>
|
||||
#include <assert.h>
|
||||
#include <cfloat>
|
||||
#include <cmath>
|
||||
|
||||
namespace AL
|
||||
{
|
||||
|
@ -166,8 +168,23 @@ namespace Source
|
|||
return value;
|
||||
}
|
||||
|
||||
inline void setVolume(Source::ID id, float value)
|
||||
enum VolumeScale
|
||||
{
|
||||
Linear,
|
||||
Db35,
|
||||
};
|
||||
|
||||
inline void setVolume(Source::ID id, float value, VolumeScale scale)
|
||||
{
|
||||
switch (scale) {
|
||||
case VolumeScale::Linear:
|
||||
break;
|
||||
case VolumeScale::Db35:
|
||||
if (value > FLT_EPSILON) {
|
||||
value = std::powf(10., -(35. / 20.) * (1. - value));
|
||||
}
|
||||
break;
|
||||
}
|
||||
alSourcef(id.al, AL_GAIN, value);
|
||||
}
|
||||
|
||||
|
|
|
@ -46,7 +46,7 @@ ALStream::ALStream(LoopMode loopMode,
|
|||
{
|
||||
alSrc = AL::Source::gen();
|
||||
|
||||
AL::Source::setVolume(alSrc, 1.0f);
|
||||
AL::Source::setVolume(alSrc, 1.0f, AL::Source::Linear);
|
||||
AL::Source::setPitch(alSrc, 1.0f);
|
||||
AL::Source::detachBuffer(alSrc);
|
||||
|
||||
|
@ -164,7 +164,7 @@ void ALStream::pause()
|
|||
|
||||
void ALStream::setVolume(float value)
|
||||
{
|
||||
AL::Source::setVolume(alSrc, value);
|
||||
AL::Source::setVolume(alSrc, value, AL::Source::Linear);
|
||||
}
|
||||
|
||||
void ALStream::setPitch(float value)
|
||||
|
|
|
@ -172,7 +172,7 @@ void SoundEmitter::play(const std::string &filename,
|
|||
if (switchBuffer)
|
||||
AL::Source::attachBuffer(src, buffer->alBuffer);
|
||||
|
||||
AL::Source::setVolume(src, _volume * GLOBAL_VOLUME);
|
||||
AL::Source::setVolume(src, _volume * GLOBAL_VOLUME, AL::Source::Linear);
|
||||
AL::Source::setPitch(src, _pitch);
|
||||
|
||||
AL::Source::play(src);
|
||||
|
|
Loading…
Add table
Reference in a new issue