1
0
forked from 0ad/0ad

Tweak sound distance attenuation & add configurability

Following D3108 / 876f6d5e50, sounds are attenuated by their actual
distance. However, as noted by players on A24, the dropoff is stark and,
when zoomed out, can easily result in not hearing things that are
happening in the middle of the screen.

The new default settings almost double the max-range, change the minimum
range to have greater dynamic range, and reduce the stereo depth
slightly to better match the default camera FOV.

These are stored per sound-grounp, possibly allowing future tweaks on a
per-soundgroup basis, and are configurable.

Tested by: Imarok
Discussed over mail with: Samulis, Porru

Differential Revision: https://code.wildfiregames.com/D3612
This was SVN commit r25547.
This commit is contained in:
wraitii 2021-05-25 06:19:25 +00:00
parent 498f0d420b
commit 863ef0f88a
6 changed files with 31 additions and 11 deletions

View File

@ -514,6 +514,9 @@ musicgain = 0.2
ambientgain = 0.6
actiongain = 0.7
uigain = 0.7
mindistance = 1
maxdistance = 350
maxstereoangle = 0.62 ; About PI/5 radians
[sound.notify]
nick = true ; Play a sound when someone mentions your name in the lobby or game

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2019 Wildfire Games.
/* Copyright (C) 2021 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@ -127,14 +127,14 @@ void CSoundBase::SetGain(ALfloat gain)
}
}
void CSoundBase::SetRollOff(ALfloat rolls)
void CSoundBase::SetRollOff(float rolls, float minDist, float maxDist)
{
if ( m_ALSource )
{
std::lock_guard<std::mutex> lock(m_ItemMutex);
alSourcef(m_ALSource, AL_REFERENCE_DISTANCE, 70.0f);
alSourcef(m_ALSource, AL_REFERENCE_DISTANCE, minDist);
AL_CHECK;
alSourcef(m_ALSource, AL_MAX_DISTANCE, 200.0);
alSourcef(m_ALSource, AL_MAX_DISTANCE, maxDist);
AL_CHECK;
alSourcef(m_ALSource, AL_ROLLOFF_FACTOR, rolls);
AL_CHECK;

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2019 Wildfire Games.
/* Copyright (C) 2021 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@ -58,7 +58,7 @@ public:
void EnsurePlay();
void SetGain(ALfloat gain);
void SetRollOff(ALfloat gain);
void SetRollOff(ALfloat gain, float minDist, float maxDist);
void SetPitch(ALfloat pitch);
void SetDirection(const CVector3D& direction);
void SetCone(ALfloat innerCone, ALfloat outerCone, ALfloat coneGain);

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2015 Wildfire Games.
/* Copyright (C) 2021 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@ -59,7 +59,7 @@ public:
virtual void SetPitch(float pitch) = 0;
virtual void SetGain(float gain) = 0;
virtual void SetLocation(const CVector3D& position) = 0;
virtual void SetRollOff(float gain) = 0;
virtual void SetRollOff(float gain, float minDist, float maxDist) = 0;
virtual void Pause() = 0;
virtual void Resume() = 0;

View File

@ -22,6 +22,7 @@
#include "graphics/GameView.h"
#include "lib/rand.h"
#include "ps/CLogger.h"
#include "ps/ConfigDB.h"
#include "ps/CStr.h"
#include "ps/Filesystem.h"
#include "ps/Game.h"
@ -102,6 +103,17 @@ void CSoundGroup::SetDefaultValues()
m_Decay = 3.f;
m_Seed = 0;
m_IntensityThreshold = 3.f;
m_MinDist = 1.f;
m_MaxDist = 350.f;
// This is more than the default camera FOV: for now, our soundscape is not realistic anyways.
m_MaxStereoAngle = static_cast<float>(M_PI / 6);
if (CConfigDB::IsInitialised())
{
CFG_GET_VAL("sound.mindistance", m_MinDist);
CFG_GET_VAL("sound.maxdistance", m_MaxDist);
CFG_GET_VAL("sound.maxstereoangle", m_MaxStereoAngle);
}
}
CSoundGroup::CSoundGroup()
@ -133,7 +145,7 @@ float CSoundGroup::RadiansOffCenter(const CVector3D& position, bool& onScreen, f
const int screenHeight = g_Game->GetView()->GetCamera()->GetViewPort().m_Height;
const float xBufferSize = screenWidth * 0.1f;
const float yBufferSize = 15.f;
const float radianCap = static_cast<float>(M_PI / 3);
const float radianCap = m_MaxStereoAngle;
float x, y;
g_Game->GetView()->GetCamera()->GetScreenCoordinates(position, x, y);
@ -218,7 +230,7 @@ void CSoundGroup::UploadPropertiesAndPlay(size_t index, const CVector3D& positio
LOGWARNING("OpenAL: stereo sounds can't be positioned: %s", sndData->GetFileName().string8());
hSound->SetLocation(CVector3D(itemDist * sin(offset), 0, -itemDist * cos(offset)));
hSound->SetRollOff(itemRollOff);
hSound->SetRollOff(itemRollOff, m_MinDist, m_MaxDist);
}
CmpPtr<ICmpVisual> cmpVisual(*g_Game->GetSimulation2(), source);

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2020 Wildfire Games.
/* Copyright (C) 2021 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@ -99,6 +99,11 @@ private:
float m_Gain;
float m_GainUpper;
float m_GainLower;
// Distance attenuation settings
float m_MinDist;
float m_MaxDist;
// How much stereo separation to apply to sounds based on L-R position relative to the camera.
float m_MaxStereoAngle;
// The allowable intensity before a sound switch
float m_IntensityThreshold;
float m_Pitch;