Compare commits
2 Commits
b3d227dc71
...
269648e021
| Author | SHA1 | Date | |
|---|---|---|---|
| 269648e021 | |||
| 41f7499c23 |
18
src/ParameterStore.cpp
Normal file
18
src/ParameterStore.cpp
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
|
||||||
|
#include "ParameterStore.hpp"
|
||||||
|
|
||||||
|
ParameterStore::ParameterStore() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// set parameter value
|
||||||
|
void ParameterStore::set(ParamId id, float value) {
|
||||||
|
Param oldParam = values_[static_cast<size_t>(id)].load(std::memory_order_relaxed);
|
||||||
|
Param updatedParam = { value, oldParam.min, oldParam.max };
|
||||||
|
values_[static_cast<size_t>(id)].store(updatedParam, std::memory_order_relaxed);
|
||||||
|
}
|
||||||
|
|
||||||
|
// get a single parameter
|
||||||
|
float ParameterStore::get(ParamId id) const {
|
||||||
|
return values_[static_cast<size_t>(id)].load(std::memory_order_relaxed).val;
|
||||||
|
}
|
||||||
37
src/ParameterStore.hpp
Normal file
37
src/ParameterStore.hpp
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
#include <cstdint>
|
||||||
|
|
||||||
|
enum class ParamId : uint8_t {
|
||||||
|
MasterGain,
|
||||||
|
Count
|
||||||
|
};
|
||||||
|
|
||||||
|
struct Param {
|
||||||
|
float val;
|
||||||
|
float min;
|
||||||
|
float max;
|
||||||
|
};
|
||||||
|
|
||||||
|
constexpr size_t PARAM_COUNT = static_cast<size_t>(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<float>(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<int32_t>(get(id)); }
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
std::array<std::atomic<Param>, PARAM_COUNT> values_;
|
||||||
|
|
||||||
|
};
|
||||||
@@ -13,7 +13,7 @@ PianoString::PianoString(ConfigService* config, LoggerService* logger) : Instrum
|
|||||||
void PianoString::noteOn(float frequency, float velocity) {
|
void PianoString::noteOn(float frequency, float velocity) {
|
||||||
|
|
||||||
active_ = true;
|
active_ = true;
|
||||||
frequency_ = frequency;
|
frequency_ = frequency / 1.03746174945f; // empirical adjustment (original was 83 cents sharp)
|
||||||
|
|
||||||
damping_ = 0.5f;
|
damping_ = 0.5f;
|
||||||
rms_ = 5.0f;
|
rms_ = 5.0f;
|
||||||
@@ -84,9 +84,9 @@ float PianoString::process(bool& scopeTrigger) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
phaseTracker_ += frequency_ / sampleRate_;
|
phaseTracker_ += frequency_ / sampleRate_;
|
||||||
if(phaseTracker_ > 1.0f) {
|
if(phaseTracker_ > 2.0f) {
|
||||||
phaseTracker_ -= 1.0f;
|
phaseTracker_ -= 2.0f;
|
||||||
scopeTrigger = true;
|
if(!scopeTrigger) scopeTrigger = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
float sampleOut = stringY_next_[static_cast<size_t>(samplePosition_*segmentCount_)];
|
float sampleOut = stringY_next_[static_cast<size_t>(samplePosition_*segmentCount_)];
|
||||||
|
|||||||
Reference in New Issue
Block a user