The voice state matches its envelope release state
This commit is contained in:
parent
e1c6c6c3de
commit
87c3cfaced
3 changed files with 21 additions and 14 deletions
|
|
@ -205,9 +205,15 @@ void ADSREnvelope<Type>::getBlock(absl::Span<Type> output) noexcept
|
|||
}
|
||||
}
|
||||
template <class Type>
|
||||
bool ADSREnvelope<Type>::isSmoothing() noexcept
|
||||
bool ADSREnvelope<Type>::isSmoothing() const noexcept
|
||||
{
|
||||
return currentState != State::Done;
|
||||
return (currentState != State::Done);
|
||||
}
|
||||
|
||||
template <class Type>
|
||||
bool ADSREnvelope<Type>::isReleased() const noexcept
|
||||
{
|
||||
return (currentState == State::Release);
|
||||
}
|
||||
|
||||
template <class Type>
|
||||
|
|
@ -222,6 +228,9 @@ void ADSREnvelope<Type>::startRelease(int releaseDelay, bool fastRelease) noexce
|
|||
shouldRelease = true;
|
||||
this->releaseDelay = releaseDelay;
|
||||
|
||||
if (releaseDelay == 0)
|
||||
currentState = State::Release;
|
||||
|
||||
if (fastRelease)
|
||||
this->release = 0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -58,7 +58,14 @@ public:
|
|||
* @return true
|
||||
* @return false
|
||||
*/
|
||||
bool isSmoothing() noexcept;
|
||||
bool isSmoothing() const noexcept;
|
||||
/**
|
||||
* @brief Is the envelope released?
|
||||
*
|
||||
* @return true
|
||||
* @return false
|
||||
*/
|
||||
bool isReleased() const noexcept;
|
||||
/**
|
||||
* @brief Get the remaining delay samples
|
||||
*
|
||||
|
|
|
|||
|
|
@ -125,7 +125,6 @@ void sfz::Voice::release(int delay, bool fastRelease) noexcept
|
|||
if (egEnvelope.getRemainingDelay() > std::max(0, delay - initialDelay)) {
|
||||
reset();
|
||||
} else {
|
||||
state = State::release;
|
||||
egEnvelope.startRelease(delay, fastRelease);
|
||||
}
|
||||
}
|
||||
|
|
@ -382,8 +381,6 @@ void sfz::Voice::fillWithData(AudioSpan<float> buffer) noexcept
|
|||
sfzInterpolationCast<float>(jumps, indices, leftCoeffs, rightCoeffs);
|
||||
add<int>(sourcePosition, indices);
|
||||
|
||||
absl::optional<int> releaseAt {};
|
||||
|
||||
if (region->shouldLoop() && region->loopEnd(currentPromise->oversamplingFactor) <= source.getNumFrames()) {
|
||||
const auto loopEnd = static_cast<int>(region->loopEnd(currentPromise->oversamplingFactor));
|
||||
const auto offset = loopEnd - static_cast<int>(region->loopStart(currentPromise->oversamplingFactor)) + 1;
|
||||
|
|
@ -400,7 +397,7 @@ void sfz::Voice::fillWithData(AudioSpan<float> buffer) noexcept
|
|||
) - 2;
|
||||
for (auto* index = indices.begin(); index < indices.end(); ++index) {
|
||||
if (*index >= sampleEnd) {
|
||||
releaseAt = static_cast<int>(std::distance(indices.begin(), index));
|
||||
release(static_cast<int>(std::distance(indices.begin(), index)));
|
||||
const auto remainingElements = static_cast<size_t>(std::distance(index, indices.end()));
|
||||
if (source.getNumFrames() - 1 < region->trueSampleEnd(currentPromise->oversamplingFactor)) {
|
||||
DBG("[sfizz] Underflow: source available samples "
|
||||
|
|
@ -438,12 +435,6 @@ void sfz::Voice::fillWithData(AudioSpan<float> buffer) noexcept
|
|||
|
||||
sourcePosition = indices.back();
|
||||
floatPositionOffset = rightCoeffs.back();
|
||||
|
||||
if (state != State::release && releaseAt) {
|
||||
release(*releaseAt);
|
||||
// TODO: not needed probably
|
||||
buffer.subspan(*releaseAt).fill(0.0f);
|
||||
}
|
||||
}
|
||||
|
||||
void sfz::Voice::fillWithGenerator(AudioSpan<float> buffer) noexcept
|
||||
|
|
@ -535,7 +526,7 @@ float sfz::Voice::getMeanSquaredAverage() const noexcept
|
|||
|
||||
bool sfz::Voice::canBeStolen() const noexcept
|
||||
{
|
||||
return state == State::release;
|
||||
return state == State::idle || egEnvelope.isReleased();
|
||||
}
|
||||
|
||||
uint32_t sfz::Voice::getSourcePosition() const noexcept
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue