diff --git a/src/ParameterStore.cpp b/src/ParameterStore.cpp new file mode 100644 index 0000000..b85bffc --- /dev/null +++ b/src/ParameterStore.cpp @@ -0,0 +1,18 @@ + +#include "ParameterStore.hpp" + +ParameterStore::ParameterStore() { + +} + +// set parameter value +void ParameterStore::set(ParamId id, float value) { + Param oldParam = values_[static_cast(id)].load(std::memory_order_relaxed); + Param updatedParam = { value, oldParam.min, oldParam.max }; + values_[static_cast(id)].store(updatedParam, std::memory_order_relaxed); +} + +// get a single parameter +float ParameterStore::get(ParamId id) const { + return values_[static_cast(id)].load(std::memory_order_relaxed).val; +} diff --git a/src/ParameterStore.hpp b/src/ParameterStore.hpp new file mode 100644 index 0000000..0def272 --- /dev/null +++ b/src/ParameterStore.hpp @@ -0,0 +1,37 @@ + +#pragma once + +#include +#include + +enum class ParamId : uint8_t { + MasterGain, + Count +}; + +struct Param { + float val; + float min; + float max; +}; + +constexpr size_t PARAM_COUNT = static_cast(ParamId::Count); + +class ParameterStore { + +public: + + ParameterStore(); + ~ParameterStore() = default; + + void set(ParamId id, float value); + void set(ParamId id, int32_t value) { set(id, static_cast(value)); } + void set(EnvelopeId id, float depth, float a, float d, float s, float r); + float get(ParamId id) const; + int32_t getInt(ParamId id) const { return static_cast(get(id)); } + +private: + + std::array, PARAM_COUNT> values_; + +}; \ No newline at end of file diff --git a/src/synth/Instruments/PianoString.cpp b/src/synth/Instruments/PianoString.cpp index 583ed89..79daa1a 100644 --- a/src/synth/Instruments/PianoString.cpp +++ b/src/synth/Instruments/PianoString.cpp @@ -13,7 +13,7 @@ PianoString::PianoString(ConfigService* config, LoggerService* logger) : Instrum void PianoString::noteOn(float frequency, float velocity) { active_ = true; - frequency_ = frequency; + frequency_ = frequency / 1.03746174945f; // empirical adjustment (original was 83 cents sharp) damping_ = 0.5f; rms_ = 5.0f; @@ -84,9 +84,9 @@ float PianoString::process(bool& scopeTrigger) { } phaseTracker_ += frequency_ / sampleRate_; - if(phaseTracker_ > 1.0f) { - phaseTracker_ -= 1.0f; - scopeTrigger = true; + if(phaseTracker_ > 2.0f) { + phaseTracker_ -= 2.0f; + if(!scopeTrigger) scopeTrigger = true; } float sampleOut = stringY_next_[static_cast(samplePosition_*segmentCount_)];