60 for (uint8_t i = 0; i < segment_count_; ++i) {
61 segments_[i] = segments[i];
63 sustain_index_ = sustain_index;
74 if (segment_count_ == 0)
return;
84 if (sustain_index_ < 0)
return;
86 uint8_t release_index =
static_cast<uint8_t
>(sustain_index_ + 1);
87 if (release_index >= segment_count_)
return;
91 start_level_ = level_;
93 begin_segment(release_index);
99 if (segment_count_ == 0)
return;
100 start_level_ = level_;
109 for (uint16_t i = 0; i < frames; ++i) {
111 float next_phase = phase_ + phase_increment_;
112 if (next_phase >= 1.0f) {
114 level_ = segments_[current_index_].
target;
115 start_level_ = level_;
119 level_ = compute_level(phase_);
128 float level()
const {
return level_; }
140 uint8_t segment_count_ = 0;
141 int8_t sustain_index_ = -1;
144 uint8_t current_index_ = 0;
147 float start_level_ = 0.0f;
149 float phase_increment_ = 0.0f;
150 float sample_rate_ = 48000.0f;
160 phase_increment_ = 0.0f;
163 void begin_segment(uint8_t index) {
164 current_index_ = index;
168 if (segments_[index].time_ms <= 0.0f) {
169 level_ = segments_[index].
target;
170 start_level_ = level_;
175 float time_samples = segments_[index].
time_ms * 0.001f * sample_rate_;
176 phase_increment_ = 1.0f / time_samples;
179 void advance_to_next() {
181 if (current_index_ == sustain_index_) {
187 uint8_t next = current_index_ + 1;
188 if (next >= segment_count_) {
196 float compute_level(
float phase)
const {
197 float warped = CurveEngine::warp(phase, segments_[current_index_].curve);
198 return start_level_ + (segments_[current_index_].
target - start_level_) * warped;