Skip to content

Commit

Permalink
Remove an undesireable cast
Browse files Browse the repository at this point in the history
  • Loading branch information
kcat committed Apr 20, 2024
1 parent 16d7413 commit 37f9dbc
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions core/voice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -899,17 +899,16 @@ void Voice::mix(const State vstate, ContextBase *Context, const nanoseconds devi
{
const uint avail{std::min(srcBufferSize, MaxResamplerEdge)};
const uint tofill{std::max(srcBufferSize, MaxResamplerEdge)};
const auto srcbuf = resampleBuffer.first(tofill);

/* When loading from a voice that ended prematurely, only take
* the samples that get closest to 0 amplitude. This helps
* certain sounds fade out better.
*/
auto abs_lt = [](const float lhs, const float rhs) noexcept -> bool
{ return std::abs(lhs) < std::abs(rhs); };
auto srciter = std::min_element(resampleBuffer.begin(),
resampleBuffer.begin()+ptrdiff_t(avail), abs_lt);
auto srciter = std::min_element(srcbuf.begin(), srcbuf.begin()+ptrdiff_t(avail),
[](const float l, const float r) { return std::abs(l) < std::abs(r); });

std::fill(srciter+1, resampleBuffer.begin()+ptrdiff_t(tofill), *srciter);
std::fill(srciter+1, srcbuf.end(), *srciter);
}
else if(mFlags.test(VoiceIsStatic))
{
Expand Down

0 comments on commit 37f9dbc

Please sign in to comment.