Skip to content

Commit

Permalink
Stages: gate delay in S&H mode ; waveform phase preservation in sync'…
Browse files Browse the repository at this point in the history
…ed LFO mode
  • Loading branch information
Emilie Gillet committed Mar 31, 2020
1 parent b9aac44 commit 3555b2d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
16 changes: 11 additions & 5 deletions stages/segment_generator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -88,6 +92,7 @@ void SegmentGenerator::Init() {
1000.0f / kSampleRate);
ramp_division_quantizer_.Init();
delay_line_.Init();
gate_delay_.Init();

num_segments_ = 0;
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions stages/segment_generator.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -194,6 +195,7 @@ class SegmentGenerator {
segment::Parameters parameters_[kMaxNumSegments];

DelayLine16Bits<kMaxDelay> delay_line_;
stmlib::DelayLine<stmlib::GateFlags, 128> gate_delay_;

static ProcessFn process_fn_table_[12];

Expand Down

0 comments on commit 3555b2d

Please sign in to comment.