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>
|
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>
|
template <class Type>
|
||||||
|
|
@ -222,6 +228,9 @@ void ADSREnvelope<Type>::startRelease(int releaseDelay, bool fastRelease) noexce
|
||||||
shouldRelease = true;
|
shouldRelease = true;
|
||||||
this->releaseDelay = releaseDelay;
|
this->releaseDelay = releaseDelay;
|
||||||
|
|
||||||
|
if (releaseDelay == 0)
|
||||||
|
currentState = State::Release;
|
||||||
|
|
||||||
if (fastRelease)
|
if (fastRelease)
|
||||||
this->release = 0;
|
this->release = 0;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -58,7 +58,14 @@ public:
|
||||||
* @return true
|
* @return true
|
||||||
* @return false
|
* @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
|
* @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)) {
|
if (egEnvelope.getRemainingDelay() > std::max(0, delay - initialDelay)) {
|
||||||
reset();
|
reset();
|
||||||
} else {
|
} else {
|
||||||
state = State::release;
|
|
||||||
egEnvelope.startRelease(delay, fastRelease);
|
egEnvelope.startRelease(delay, fastRelease);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -382,8 +381,6 @@ void sfz::Voice::fillWithData(AudioSpan<float> buffer) noexcept
|
||||||
sfzInterpolationCast<float>(jumps, indices, leftCoeffs, rightCoeffs);
|
sfzInterpolationCast<float>(jumps, indices, leftCoeffs, rightCoeffs);
|
||||||
add<int>(sourcePosition, indices);
|
add<int>(sourcePosition, indices);
|
||||||
|
|
||||||
absl::optional<int> releaseAt {};
|
|
||||||
|
|
||||||
if (region->shouldLoop() && region->loopEnd(currentPromise->oversamplingFactor) <= source.getNumFrames()) {
|
if (region->shouldLoop() && region->loopEnd(currentPromise->oversamplingFactor) <= source.getNumFrames()) {
|
||||||
const auto loopEnd = static_cast<int>(region->loopEnd(currentPromise->oversamplingFactor));
|
const auto loopEnd = static_cast<int>(region->loopEnd(currentPromise->oversamplingFactor));
|
||||||
const auto offset = loopEnd - static_cast<int>(region->loopStart(currentPromise->oversamplingFactor)) + 1;
|
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;
|
) - 2;
|
||||||
for (auto* index = indices.begin(); index < indices.end(); ++index) {
|
for (auto* index = indices.begin(); index < indices.end(); ++index) {
|
||||||
if (*index >= sampleEnd) {
|
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()));
|
const auto remainingElements = static_cast<size_t>(std::distance(index, indices.end()));
|
||||||
if (source.getNumFrames() - 1 < region->trueSampleEnd(currentPromise->oversamplingFactor)) {
|
if (source.getNumFrames() - 1 < region->trueSampleEnd(currentPromise->oversamplingFactor)) {
|
||||||
DBG("[sfizz] Underflow: source available samples "
|
DBG("[sfizz] Underflow: source available samples "
|
||||||
|
|
@ -438,12 +435,6 @@ void sfz::Voice::fillWithData(AudioSpan<float> buffer) noexcept
|
||||||
|
|
||||||
sourcePosition = indices.back();
|
sourcePosition = indices.back();
|
||||||
floatPositionOffset = rightCoeffs.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
|
void sfz::Voice::fillWithGenerator(AudioSpan<float> buffer) noexcept
|
||||||
|
|
@ -535,7 +526,7 @@ float sfz::Voice::getMeanSquaredAverage() const noexcept
|
||||||
|
|
||||||
bool sfz::Voice::canBeStolen() 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
|
uint32_t sfz::Voice::getSourcePosition() const noexcept
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue