phase offset

This commit is contained in:
chriskiefer 2026-02-25 16:30:52 +00:00
parent 497f1c8dfb
commit 6707781b3b
2 changed files with 13 additions and 6 deletions

View file

@ -20,6 +20,7 @@ struct ratioSeqState {
std::array<float, 3> ratios{1.f}; std::array<float, 3> ratios{1.f};
float phasor=0.f; float phasor=0.f;
float phasorInc=0.f; float phasorInc=0.f;
float phaseOffset = 0.f;
bool lastTrig = false; bool lastTrig = false;
float phasorMul = 1.f; float phasorMul = 1.f;
float ratioSum=1.f; float ratioSum=1.f;
@ -30,7 +31,11 @@ struct ratioSeqState {
template<size_t seqLength> template<size_t seqLength>
inline bool __not_in_flash_func(ratioSeq)(ratioSeqState &seq) { inline bool __not_in_flash_func(ratioSeq)(ratioSeqState &seq) {
bool trig = 0; bool trig = 0;
float phaseAdj = seq.ratioSum * seq.phasor; float offsetPhase = seq.phaseOffset + seq.phasor;
if (offsetPhase >= 1.f) {
offsetPhase -= 1.f;
}
float phaseAdj = seq.ratioSum * offsetPhase;
float accumulatedSum = 0; float accumulatedSum = 0;
float lastAccumulatedSum = 0; float lastAccumulatedSum = 0;
for (size_t v : seq.ratios) for (size_t v : seq.ratios)
@ -39,7 +44,6 @@ inline bool __not_in_flash_func(ratioSeq)(ratioSeqState &seq) {
if (phaseAdj <= accumulatedSum) if (phaseAdj <= accumulatedSum)
{ {
// check pulse width // check pulse width
//TODO: could precalc acc-lastacc
float beatPhase = (phaseAdj - lastAccumulatedSum) / float beatPhase = (phaseAdj - lastAccumulatedSum) /
(accumulatedSum - lastAccumulatedSum); (accumulatedSum - lastAccumulatedSum);
trig = beatPhase <= seq.pulseWidth; trig = beatPhase <= seq.pulseWidth;
@ -133,9 +137,10 @@ public:
maxiSettings::sampleRate = sample_rate; maxiSettings::sampleRate = sample_rate;
sampleRatef = static_cast<float>(sample_rate); sampleRatef = static_cast<float>(sample_rate);
updateBPM(90.f); updateBPM(90.f);
size_t midiNote = 36; const size_t midiNotes[NSEQUENCES] = {36,37,38,39,40, 42,43,45,47,48};
size_t midiNote = 0;
for(auto &seq: ratioSeqStates) { for(auto &seq: ratioSeqStates) {
seq.midiNote = midiNote++; seq.midiNote = midiNotes[midiNote++];
} }
} }
@ -160,6 +165,7 @@ public:
} }
v.ratioSum = sum; v.ratioSum = sum;
v.phasorMul = ((float)(int)(params[paramIdx++] * 2.f) * 0.5f)+ 1.f; v.phasorMul = ((float)(int)(params[paramIdx++] * 2.f) * 0.5f)+ 1.f;
v.phaseOffset = ((int)(params[paramIdx++] * timeSigBeats)) * timeSigBeatsInv;
} }
} }
@ -190,9 +196,10 @@ protected:
float bpm=90.f; float bpm=90.f;
float timeSigBeats=4.f; float timeSigBeats=4.f;
float timeSigBeatsInv=1.f/timeSigBeats;
float timeSigDivision=4.f; float timeSigDivision=4.f;
size_t sequencingSampleDiv = 50; // How often the sequencer should update (in Hz) size_t sequencingSampleDiv = 50;
size_t sequencingSampleCounter = 0; size_t sequencingSampleCounter = 0;
std::array<ratioSeqState, NSEQUENCES> ratioSeqStates; std::array<ratioSeqState, NSEQUENCES> ratioSeqStates;

@ -1 +1 @@
Subproject commit 2eaef772c985e221e13c62676eaa293cf75d87e2 Subproject commit abbfdf90b47f90e7e02221f1b6df6c88f0f70ce5