aboutsummaryrefslogtreecommitdiffstats
path: root/Alc/panning.cpp
diff options
context:
space:
mode:
authorChris Robinson <chris.kcat@gmail.com>2019-06-08 01:39:28 -0700
committerChris Robinson <chris.kcat@gmail.com>2019-06-08 01:39:28 -0700
commit91b7e8142caf297b97d6b403ee79ba2dcbcda09f (patch)
tree5b6d15b3d37af929436a00fa772d4102fb719e73 /Alc/panning.cpp
parent7988bc6e91899179a71650bd2534d7749f2a68c3 (diff)
Simplify DistanceComp somewhat
Diffstat (limited to 'Alc/panning.cpp')
-rw-r--r--Alc/panning.cpp44
1 files changed, 20 insertions, 24 deletions
diff --git a/Alc/panning.cpp b/Alc/panning.cpp
index 714c3e98..4c899f66 100644
--- a/Alc/panning.cpp
+++ b/Alc/panning.cpp
@@ -251,17 +251,17 @@ void InitNearFieldCtrl(ALCdevice *device, ALfloat ctrl_dist, ALsizei order,
void InitDistanceComp(ALCdevice *device, const AmbDecConf *conf, const ALsizei (&speakermap)[MAX_OUTPUT_CHANNELS])
{
+ auto get_max = std::bind(maxf, _1,
+ std::bind(std::mem_fn(&AmbDecConf::SpeakerConf::Distance), _2));
const ALfloat maxdist{
- std::accumulate(conf->Speakers.begin(), conf->Speakers.end(), float{0.0f},
- std::bind(maxf, _1, std::bind(std::mem_fn(&AmbDecConf::SpeakerConf::Distance), _2))
- )
- };
+ std::accumulate(conf->Speakers.begin(), conf->Speakers.end(), float{0.0f}, get_max)};
const char *devname{device->DeviceName.c_str()};
if(!GetConfigValueBool(devname, "decoder", "distance-comp", 1) || !(maxdist > 0.0f))
return;
- auto srate = static_cast<ALfloat>(device->Frequency);
+ const auto distSampleScale = static_cast<ALfloat>(device->Frequency)/SPEEDOFSOUNDMETRESPERSEC;
+ const auto ChanDelay = device->ChannelDelay.as_span();
size_t total{0u};
for(size_t i{0u};i < conf->Speakers.size();i++)
{
@@ -274,40 +274,36 @@ void InitDistanceComp(ALCdevice *device, const AmbDecConf *conf, const ALsizei (
* phase offsets. This means at 48khz, for instance, the distance delay
* will be in steps of about 7 millimeters.
*/
- const ALfloat delay{
- std::floor((maxdist - speaker.Distance)/SPEEDOFSOUNDMETRESPERSEC*srate + 0.5f)
- };
- if(delay >= static_cast<ALfloat>(MAX_DELAY_LENGTH))
- ERR("Delay for speaker \"%s\" exceeds buffer length (%f >= %d)\n",
- speaker.Name.c_str(), delay, MAX_DELAY_LENGTH);
-
- device->ChannelDelay[chan].Length = static_cast<ALsizei>(clampf(
- delay, 0.0f, static_cast<ALfloat>(MAX_DELAY_LENGTH-1)
- ));
- device->ChannelDelay[chan].Gain = speaker.Distance / maxdist;
+ ALfloat delay{std::floor((maxdist - speaker.Distance)*distSampleScale + 0.5f)};
+ if(delay > ALfloat{MAX_DELAY_LENGTH-1})
+ {
+ ERR("Delay for speaker \"%s\" exceeds buffer length (%f > %d)\n",
+ speaker.Name.c_str(), delay, MAX_DELAY_LENGTH-1);
+ delay = ALfloat{MAX_DELAY_LENGTH-1};
+ }
+
+ ChanDelay[chan].Length = static_cast<ALsizei>(delay);
+ ChanDelay[chan].Gain = speaker.Distance / maxdist;
TRACE("Channel %u \"%s\" distance compensation: %d samples, %f gain\n", chan,
- speaker.Name.c_str(), device->ChannelDelay[chan].Length,
- device->ChannelDelay[chan].Gain
- );
+ speaker.Name.c_str(), ChanDelay[chan].Length, ChanDelay[chan].Gain);
/* Round up to the next 4th sample, so each channel buffer starts
* 16-byte aligned.
*/
- total += RoundUp(device->ChannelDelay[chan].Length, 4);
+ total += RoundUp(ChanDelay[chan].Length, 4);
}
if(total > 0)
{
- device->ChannelDelay.resize(total);
- device->ChannelDelay[0].Buffer = device->ChannelDelay.data();
+ device->ChannelDelay.setSampleCount(total);
+ ChanDelay[0].Buffer = device->ChannelDelay.getSamples();
auto set_bufptr = [](const DistanceComp::DistData &last, const DistanceComp::DistData &cur) -> DistanceComp::DistData
{
DistanceComp::DistData ret{cur};
ret.Buffer = last.Buffer + RoundUp(last.Length, 4);
return ret;
};
- std::partial_sum(device->ChannelDelay.begin(), device->ChannelDelay.end(),
- device->ChannelDelay.begin(), set_bufptr);
+ std::partial_sum(ChanDelay.begin(), ChanDelay.end(), ChanDelay.begin(), set_bufptr);
}
}