Added the amplitude envelope
This commit is contained in:
parent
db45224e79
commit
fad715559f
5 changed files with 26 additions and 11 deletions
2
external/abseil-cpp
vendored
2
external/abseil-cpp
vendored
|
|
@ -1 +1 @@
|
||||||
Subproject commit a0d1e098c2f99694fa399b175a7ccf920762030e
|
Subproject commit 83c1d65c90a92aa49632b9ac5a793214bb0768bc
|
||||||
|
|
@ -74,3 +74,5 @@ template <class Type>
|
||||||
constexpr Type twoPi { 2 * pi<Type> };
|
constexpr Type twoPi { 2 * pi<Type> };
|
||||||
template <class Type>
|
template <class Type>
|
||||||
constexpr Type piTwo { pi<Type> / 2 };
|
constexpr Type piTwo { pi<Type> / 2 };
|
||||||
|
template <class Type>
|
||||||
|
constexpr Type piFour { pi<Type> / 4 };
|
||||||
|
|
@ -31,8 +31,7 @@
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
|
|
||||||
enum class Channel { left,
|
enum class Channel { left, right };
|
||||||
right };
|
|
||||||
|
|
||||||
template <class Type, unsigned int Alignment = SIMDConfig::defaultAlignment>
|
template <class Type, unsigned int Alignment = SIMDConfig::defaultAlignment>
|
||||||
class StereoBuffer {
|
class StereoBuffer {
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,7 @@
|
||||||
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
#include "Voice.h"
|
#include "Voice.h"
|
||||||
#include "Voice.h"
|
#include "Defaults.h"
|
||||||
#include "SIMDHelpers.h"
|
#include "SIMDHelpers.h"
|
||||||
#include "SfzHelpers.h"
|
#include "SfzHelpers.h"
|
||||||
#include "absl/algorithm/container.h"
|
#include "absl/algorithm/container.h"
|
||||||
|
|
@ -53,12 +53,13 @@ void sfz::Voice::startVoice(Region* region, int delay, int channel, int number,
|
||||||
baseGain = region->getBaseGain();
|
baseGain = region->getBaseGain();
|
||||||
if (triggerType != TriggerType::CC)
|
if (triggerType != TriggerType::CC)
|
||||||
baseGain *= region->getNoteGain(number, value);
|
baseGain *= region->getNoteGain(number, value);
|
||||||
DBG("Voice base gain with note crossfades: " << baseGain);
|
|
||||||
baseGain *= region->getCCGain(ccState);
|
baseGain *= region->getCCGain(ccState);
|
||||||
DBG("Voice base gain with CC crossfades: " << baseGain);
|
if (region->amplitudeCC)
|
||||||
|
baseGain *= normalizeCC(ccState[region->amplitudeCC->first]) * normalizePercents(region->amplitudeCC->second);
|
||||||
|
amplitudeEnvelope.reset(baseGain);
|
||||||
|
|
||||||
sourcePosition = region->getOffset();
|
sourcePosition = region->getOffset();
|
||||||
initialDelay = delay + region->getDelay();
|
initialDelay = delay + region->getDelay();
|
||||||
DBG("Voice initial delay: " << initialDelay);
|
|
||||||
baseFrequency = midiNoteFrequency(number) * pitchRatio;
|
baseFrequency = midiNoteFrequency(number) * pitchRatio;
|
||||||
prepareEGEnvelope(delay, value);
|
prepareEGEnvelope(delay, value);
|
||||||
}
|
}
|
||||||
|
|
@ -90,7 +91,6 @@ bool sfz::Voice::isFree() const noexcept
|
||||||
return (region == nullptr);
|
return (region == nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void sfz::Voice::release(int delay) noexcept
|
void sfz::Voice::release(int delay) noexcept
|
||||||
{
|
{
|
||||||
if (state == State::playing) {
|
if (state == State::playing) {
|
||||||
|
|
@ -123,18 +123,26 @@ void sfz::Voice::registerCC(int delay, int channel [[maybe_unused]], int ccNumbe
|
||||||
{
|
{
|
||||||
if (ccNumber == 64 && noteIsOff && ccValue < 63)
|
if (ccNumber == 64 && noteIsOff && ccValue < 63)
|
||||||
release(delay);
|
release(delay);
|
||||||
|
|
||||||
|
if (region->amplitudeCC && ccNumber == region->amplitudeCC->first) {
|
||||||
|
const float newGain { normalizeCC(ccValue) * normalizePercents(region->amplitudeCC->second) * baseGain };
|
||||||
|
amplitudeEnvelope.registerEvent(delay, newGain);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void sfz::Voice::registerPitchWheel(int delay [[maybe_unused]], int channel [[maybe_unused]], int pitch [[maybe_unused]]) noexcept
|
void sfz::Voice::registerPitchWheel(int delay [[maybe_unused]], int channel [[maybe_unused]], int pitch [[maybe_unused]]) noexcept
|
||||||
{
|
{
|
||||||
|
// TODO
|
||||||
}
|
}
|
||||||
|
|
||||||
void sfz::Voice::registerAftertouch(int delay [[maybe_unused]], int channel [[maybe_unused]], uint8_t aftertouch [[maybe_unused]]) noexcept
|
void sfz::Voice::registerAftertouch(int delay [[maybe_unused]], int channel [[maybe_unused]], uint8_t aftertouch [[maybe_unused]]) noexcept
|
||||||
{
|
{
|
||||||
|
// TODO
|
||||||
}
|
}
|
||||||
|
|
||||||
void sfz::Voice::registerTempo(int delay [[maybe_unused]], float secondsPerQuarter [[maybe_unused]]) noexcept
|
void sfz::Voice::registerTempo(int delay [[maybe_unused]], float secondsPerQuarter [[maybe_unused]]) noexcept
|
||||||
{
|
{
|
||||||
|
// TODO
|
||||||
}
|
}
|
||||||
|
|
||||||
void sfz::Voice::setSampleRate(float sampleRate) noexcept
|
void sfz::Voice::setSampleRate(float sampleRate) noexcept
|
||||||
|
|
@ -167,9 +175,10 @@ void sfz::Voice::renderBlock(StereoSpan<float> buffer) noexcept
|
||||||
else
|
else
|
||||||
fillWithData(buffer);
|
fillWithData(buffer);
|
||||||
|
|
||||||
buffer.applyGain(baseGain);
|
|
||||||
|
|
||||||
auto envelopeSpan = tempSpan1.first(numSamples);
|
auto envelopeSpan = tempSpan1.first(numSamples);
|
||||||
|
amplitudeEnvelope.getBlock(envelopeSpan);
|
||||||
|
buffer.applyGain(envelopeSpan);
|
||||||
|
|
||||||
egEnvelope.getBlock(envelopeSpan);
|
egEnvelope.getBlock(envelopeSpan);
|
||||||
buffer.applyGain(envelopeSpan);
|
buffer.applyGain(envelopeSpan);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,7 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
#include "ADSREnvelope.h"
|
#include "ADSREnvelope.h"
|
||||||
#include "Config.h"
|
#include "Config.h"
|
||||||
|
#include "LinearEnvelope.h"
|
||||||
#include "Region.h"
|
#include "Region.h"
|
||||||
#include "StereoBuffer.h"
|
#include "StereoBuffer.h"
|
||||||
#include "StereoSpan.h"
|
#include "StereoSpan.h"
|
||||||
|
|
@ -109,6 +110,10 @@ private:
|
||||||
|
|
||||||
const CCValueArray& ccState;
|
const CCValueArray& ccState;
|
||||||
ADSREnvelope<float> egEnvelope;
|
ADSREnvelope<float> egEnvelope;
|
||||||
|
LinearEnvelope<float> amplitudeEnvelope;
|
||||||
|
LinearEnvelope<float> leftPanEnvelope;
|
||||||
|
LinearEnvelope<float> rightPanEnvelope;
|
||||||
|
|
||||||
LEAK_DETECTOR(Voice);
|
LEAK_DETECTOR(Voice);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue