Skip to content

Commit

Permalink
voice arrangement (#7)
Browse files Browse the repository at this point in the history
* better arrangement

* minor fixes
  • Loading branch information
connorlbark authored Dec 24, 2024
1 parent 484bc57 commit 0034d48
Show file tree
Hide file tree
Showing 7 changed files with 170 additions and 132 deletions.
3 changes: 3 additions & 0 deletions siderialib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ add_library (siderialib STATIC
include/effects/resample/Decimate.h
include/effects/resample/Upsample.h
include/effects/resample/VariableResample.h
src/effects/disperse/DisperseParallelVoice.cpp
include/effects/disperse/DisperseParallelVoice.h
include/effects/disperse/DisperseConstants.h
)

target_include_directories(siderialib PUBLIC include)
Expand Down
34 changes: 12 additions & 22 deletions siderialib/include/effects/Disperse.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@
#include "../siderialib.h"
#include "delay/ModulatedDelay.h"
#include "effects/resample/VariableResample.h"
#include "effects/disperse/DisperseConstants.h"
#include "effects/disperse/DisperseParallelVoice.h"

namespace siderialib {
enum class DisperseArrangement {
FULL_PARALLEL = 0,
FULL_SERIAL = 1,
};

enum class DispersePingPong {
Expand All @@ -15,23 +18,14 @@ namespace siderialib {
RANDOM = 2
};

// maximum dispersion, as a function of the time param
constexpr sfloat maxTimeDisperse = 0.5f;
constexpr sfloat maxModRateDisperse = 0.2f;
constexpr sfloat maxDelayMs = 5000.0f;
constexpr sfloat minDelayMs = 100.0f;

class Disperse {
private:
sfloat _sampleRate;

// voice1: special, always-centered voice
ModulatedDelay _voice1;
ModulatedDelay _voice2;
ModulatedDelay _voice3;
ModulatedDelay _voice4;
ModulatedDelay _voice5;
ModulatedDelay _voice6;
// delay lines
ModulatedDelay _delays[DISPERSE_NUM_VOICES];
// arrangement of delay lines
DisperseParallelVoice _voices[DISPERSE_NUM_VOICES];

VariableResample _resampleL;
VariableResample _resampleR;
Expand All @@ -47,13 +41,10 @@ namespace siderialib {
sfloat _tone = 0.5;

DispersePingPong _pingPong = DispersePingPong::OFF;
DisperseArrangement _arrangement = DisperseArrangement::FULL_PARALLEL;

sfloat _modRateHz = 1.0;
sfloat _modDepth = 0.0;

int _clockTick = 0;

sfloat _lastOutL = 0.f;
sfloat _lastOutR = 0.f;

Expand All @@ -68,15 +59,12 @@ namespace siderialib {
void updateMod();
void updatePingPong();

void applyVoices(sfloat L, sfloat R);
void applyWetFX();

void clearVoices();
public:
void initialize(sfloat *voice1Buf,
sfloat *voice2Buf,
sfloat *voice3Buf,
sfloat *voice4Buf,
sfloat *voice5Buf,
sfloat *voice6Buf,
void initialize(sfloat *voiceBufs[DISPERSE_NUM_VOICES],
int bufLength,
sfloat *upsampleBufL,
sfloat *upsampleBufR,
Expand Down Expand Up @@ -112,5 +100,7 @@ namespace siderialib {

inline sfloat getResampleFactor() const { return _resampleFactor; }
void setResampleFactor(sfloat ratio);

void setArrangement(DisperseArrangement arrangement);
};
}
11 changes: 11 additions & 0 deletions siderialib/include/effects/disperse/DisperseConstants.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#pragma once

namespace siderialib {
constexpr int DISPERSE_NUM_VOICES = 6;

constexpr sfloat DISPERSE_MAX_TIME = 0.5f;
constexpr sfloat DISPERSE_MAX_MOD_RATE = 0.2f;
constexpr sfloat DISPERSE_MAX_DELAY_MS = 5000.0f;
constexpr sfloat DISPERSE_MIN_DELAY_MS = 100.0f;

}
64 changes: 64 additions & 0 deletions siderialib/include/effects/disperse/DisperseParallelVoice.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#pragma once


#include <cstdarg>
#include "effects/delay/ModulatedDelay.h"
#include "DisperseConstants.h"

namespace siderialib {
class DisperseParallelVoice {
private:
ModulatedDelay* _delays[DISPERSE_NUM_VOICES] = {
nullptr, nullptr, nullptr, nullptr, nullptr, nullptr
};
int _numActiveVoices = 0;

sfloat _lastOutL = 0.0;
sfloat _lastOutR = 0.0;
public:
DisperseParallelVoice() = default;

void addVoice(ModulatedDelay* delay) {
if (_numActiveVoices >= DISPERSE_NUM_VOICES) {
return;
}

_delays[_numActiveVoices] = delay;
_numActiveVoices++;
}

void clearVoices() {
for (int i = 0; i < _numActiveVoices; i++) {
_delays[i] = nullptr;
}

_numActiveVoices = 0;
}

void initialize() {
}

void tick(sfloat L, sfloat R) {
sfloat parallelL = L;
sfloat parallelR = R;

for (int i = 0; i < _numActiveVoices; i++) {
_delays[i]->tick(L, R);
parallelL = _delays[i]->lastOutL();
parallelR = _delays[i]->lastOutR();
}

_lastOutL = parallelL;
_lastOutR = parallelR;
}

sfloat lastOutL() const {
return _lastOutL;
}

sfloat lastOutR() const {
return _lastOutR;
}
};
}

Loading

0 comments on commit 0034d48

Please sign in to comment.