From 3555b2daa5d32b7f60406331b75cce28980c3589 Mon Sep 17 00:00:00 2001
From: Emilie Gillet
Date: Tue, 31 Mar 2020 13:01:42 +0200
Subject: [PATCH] Stages: gate delay in S&H mode ; waveform phase preservation
in sync'ed LFO mode
---
stages/segment_generator.cc | 16 +++++++++++-----
stages/segment_generator.h | 2 ++
2 files changed, 13 insertions(+), 5 deletions(-)
diff --git a/stages/segment_generator.cc b/stages/segment_generator.cc
index 06cc89e3..4ca27db0 100644
--- a/stages/segment_generator.cc
+++ b/stages/segment_generator.cc
@@ -48,6 +48,10 @@ using namespace segment;
// output is high.
const int kRetrigDelaySamples = 32;
+// S&H delay (for all those sequencers whose CV and GATE outputs are out of
+// sync).
+const size_t kSampleAndHoldDelay = kSampleRate * 2 / 1000; // 2 milliseconds
+
void SegmentGenerator::Init() {
process_fn_ = &SegmentGenerator::ProcessMultiSegment;
@@ -88,6 +92,7 @@ void SegmentGenerator::Init() {
1000.0f / kSampleRate);
ramp_division_quantizer_.Init();
delay_line_.Init();
+ gate_delay_.Init();
num_segments_ = 0;
}
@@ -247,10 +252,11 @@ void SegmentGenerator::ProcessSampleAndHold(
const float coefficient = PortamentoRateToLPCoefficient(
parameters_[0].secondary);
ParameterInterpolator primary(&primary_, parameters_[0].primary, size);
-
+
while (size--) {
const float p = primary.Next();
- if (*gate_flags & GATE_FLAG_RISING) {
+ gate_delay_.Write(*gate_flags);
+ if (gate_delay_.Read(kSampleAndHoldDelay) & GATE_FLAG_RISING) {
value_ = p;
}
active_segment_ = *gate_flags & GATE_FLAG_HIGH ? 0 : 1;
@@ -426,9 +432,9 @@ void SegmentGenerator::ShapeLFO(
const float phase_shift = plateau_width * 0.25f;
while (size--) {
- float phase = in_out->phase - phase_shift;
- if (phase < 0.0f) {
- phase += 1.0f;
+ float phase = in_out->phase + phase_shift;
+ if (phase > 1.0f) {
+ phase -= 1.0f;
}
float triangle = phase < slope
? slope_up * phase
diff --git a/stages/segment_generator.h b/stages/segment_generator.h
index bf8cfc6f..6e75daf5 100644
--- a/stages/segment_generator.h
+++ b/stages/segment_generator.h
@@ -29,6 +29,7 @@
#ifndef STAGES_SEGMENT_GENERATOR_H_
#define STAGES_SEGMENT_GENERATOR_H_
+#include "stmlib/dsp/delay_line.h"
#include "stmlib/dsp/hysteresis_quantizer.h"
#include "stmlib/utils/gate_flags.h"
@@ -194,6 +195,7 @@ class SegmentGenerator {
segment::Parameters parameters_[kMaxNumSegments];
DelayLine16Bits delay_line_;
+ stmlib::DelayLine gate_delay_;
static ProcessFn process_fn_table_[12];