mirror of
https://github.com/overte-org/overte.git
synced 2025-08-05 17:53:49 +02:00
recalc on any attribute changes
This commit is contained in:
parent
60c6b27ab2
commit
57513610fd
2 changed files with 43 additions and 7 deletions
|
@ -32,7 +32,13 @@ AudioReflector::AudioReflector(QObject* parent) :
|
||||||
_diffusionFanout(DEFAULT_DIFFUSION_FANOUT),
|
_diffusionFanout(DEFAULT_DIFFUSION_FANOUT),
|
||||||
_absorptionRatio(DEFAULT_ABSORPTION_RATIO),
|
_absorptionRatio(DEFAULT_ABSORPTION_RATIO),
|
||||||
_diffusionRatio(DEFAULT_DIFFUSION_RATIO),
|
_diffusionRatio(DEFAULT_DIFFUSION_RATIO),
|
||||||
_withDiffusion(false)
|
_withDiffusion(false),
|
||||||
|
_lastPreDelay(DEFAULT_PRE_DELAY),
|
||||||
|
_lastSoundMsPerMeter(DEFAULT_MS_DELAY_PER_METER),
|
||||||
|
_lastDistanceAttenuationScalingFactor(DEFAULT_DISTANCE_SCALING_FACTOR),
|
||||||
|
_lastDiffusionFanout(DEFAULT_DIFFUSION_FANOUT),
|
||||||
|
_lastAbsorptionRatio(DEFAULT_ABSORPTION_RATIO),
|
||||||
|
_lastDiffusionRatio(DEFAULT_DIFFUSION_RATIO)
|
||||||
{
|
{
|
||||||
_reflections = 0;
|
_reflections = 0;
|
||||||
_diffusionPathCount = 0;
|
_diffusionPathCount = 0;
|
||||||
|
@ -44,6 +50,30 @@ AudioReflector::AudioReflector(QObject* parent) :
|
||||||
_minDelay = 0;
|
_minDelay = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool AudioReflector::haveAttributesChanged() {
|
||||||
|
bool withDiffusion = Menu::getInstance()->isOptionChecked(MenuOption::AudioSpatialProcessingWithDiffusions);
|
||||||
|
|
||||||
|
bool attributesChange = (_withDiffusion != withDiffusion
|
||||||
|
|| _lastPreDelay != _preDelay
|
||||||
|
|| _lastSoundMsPerMeter != _soundMsPerMeter
|
||||||
|
|| _lastDistanceAttenuationScalingFactor != _distanceAttenuationScalingFactor
|
||||||
|
|| _lastDiffusionFanout != _diffusionFanout
|
||||||
|
|| _lastAbsorptionRatio != _absorptionRatio
|
||||||
|
|| _lastDiffusionRatio != _diffusionRatio);
|
||||||
|
|
||||||
|
if (attributesChange) {
|
||||||
|
_withDiffusion = withDiffusion;
|
||||||
|
_lastPreDelay = _preDelay;
|
||||||
|
_lastSoundMsPerMeter = _soundMsPerMeter;
|
||||||
|
_lastDistanceAttenuationScalingFactor = _distanceAttenuationScalingFactor;
|
||||||
|
_lastDiffusionFanout = _diffusionFanout;
|
||||||
|
_lastAbsorptionRatio = _absorptionRatio;
|
||||||
|
_lastDiffusionRatio = _diffusionRatio;
|
||||||
|
}
|
||||||
|
|
||||||
|
return attributesChange;
|
||||||
|
}
|
||||||
|
|
||||||
void AudioReflector::render() {
|
void AudioReflector::render() {
|
||||||
|
|
||||||
// if we're not set up yet, or we're not processing spatial audio, then exit early
|
// if we're not set up yet, or we're not processing spatial audio, then exit early
|
||||||
|
@ -274,20 +304,18 @@ void AudioReflector::addSoundSource(const glm::vec3& origin, const glm::vec3& in
|
||||||
}
|
}
|
||||||
|
|
||||||
void AudioReflector::calculateAllReflections() {
|
void AudioReflector::calculateAllReflections() {
|
||||||
// only recalculate when we've moved...
|
// only recalculate when we've moved, or if the attributes have changed
|
||||||
// TODO: what about case where new voxels are added in front of us???
|
// TODO: what about case where new voxels are added in front of us???
|
||||||
bool wantHeadOrientation = Menu::getInstance()->isOptionChecked(MenuOption::AudioSpatialProcessingHeadOriented);
|
bool wantHeadOrientation = Menu::getInstance()->isOptionChecked(MenuOption::AudioSpatialProcessingHeadOriented);
|
||||||
glm::quat orientation = wantHeadOrientation ? _myAvatar->getHead()->getFinalOrientation() : _myAvatar->getOrientation();
|
glm::quat orientation = wantHeadOrientation ? _myAvatar->getHead()->getFinalOrientation() : _myAvatar->getOrientation();
|
||||||
glm::vec3 origin = _myAvatar->getHead()->getPosition();
|
glm::vec3 origin = _myAvatar->getHead()->getPosition();
|
||||||
glm::vec3 listenerPosition = _myAvatar->getHead()->getPosition();
|
glm::vec3 listenerPosition = _myAvatar->getHead()->getPosition();
|
||||||
|
|
||||||
bool withDiffusion = Menu::getInstance()->isOptionChecked(MenuOption::AudioSpatialProcessingWithDiffusions);
|
|
||||||
|
|
||||||
bool shouldRecalc = _reflections == 0
|
bool shouldRecalc = _reflections == 0
|
||||||
|| !isSimilarPosition(origin, _origin)
|
|| !isSimilarPosition(origin, _origin)
|
||||||
|| !isSimilarOrientation(orientation, _orientation)
|
|| !isSimilarOrientation(orientation, _orientation)
|
||||||
|| !isSimilarPosition(listenerPosition, _listenerPosition)
|
|| !isSimilarPosition(listenerPosition, _listenerPosition)
|
||||||
|| (withDiffusion != _withDiffusion);
|
|| haveAttributesChanged();
|
||||||
|
|
||||||
if (shouldRecalc) {
|
if (shouldRecalc) {
|
||||||
QMutexLocker locker(&_mutex);
|
QMutexLocker locker(&_mutex);
|
||||||
|
@ -295,7 +323,6 @@ void AudioReflector::calculateAllReflections() {
|
||||||
_origin = origin;
|
_origin = origin;
|
||||||
_orientation = orientation;
|
_orientation = orientation;
|
||||||
_listenerPosition = listenerPosition;
|
_listenerPosition = listenerPosition;
|
||||||
_withDiffusion = withDiffusion;
|
|
||||||
analyzePaths(); // actually does the work
|
analyzePaths(); // actually does the work
|
||||||
quint64 end = usecTimestampNow();
|
quint64 end = usecTimestampNow();
|
||||||
const bool wantDebugging = false;
|
const bool wantDebugging = false;
|
||||||
|
|
|
@ -171,8 +171,17 @@ private:
|
||||||
float _absorptionRatio;
|
float _absorptionRatio;
|
||||||
float _diffusionRatio;
|
float _diffusionRatio;
|
||||||
float _reflectiveRatio;
|
float _reflectiveRatio;
|
||||||
|
|
||||||
|
// remember the last known values at calculation
|
||||||
|
bool haveAttributesChanged();
|
||||||
|
|
||||||
bool _withDiffusion;
|
bool _withDiffusion;
|
||||||
|
float _lastPreDelay;
|
||||||
|
float _lastSoundMsPerMeter;
|
||||||
|
float _lastDistanceAttenuationScalingFactor;
|
||||||
|
int _lastDiffusionFanout;
|
||||||
|
float _lastAbsorptionRatio;
|
||||||
|
float _lastDiffusionRatio;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue