Skip to content

Commit 16f2115

Browse files
committed
Add depth and phase shift to Richter::WaveViewer
1 parent a6b9a6f commit 16f2115

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

WECore/RichterLFO/UI/RichterWaveViewer.h

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ namespace WECore::Richter {
3030

3131
class WaveViewer : public Component {
3232
public:
33-
WaveViewer() : _waveArrayPointer(nullptr), _isInverted(false) {}
33+
WaveViewer() : _waveArrayPointer(nullptr), _depth(0), _phaseShift(0), _isInverted(false) {}
3434

35-
inline void setWave(const double* pointer, bool isInverted);
35+
inline void setWave(const double* pointer, double depth, int phaseShift, bool isInverted);
3636

3737
inline virtual void paint(Graphics& g);
3838

@@ -45,11 +45,15 @@ namespace WECore::Richter {
4545

4646
private:
4747
const double* _waveArrayPointer;
48+
double _depth;
49+
int _phaseShift;
4850
bool _isInverted;
4951
};
5052

51-
void WaveViewer::setWave(const double* pointer, bool isInverted) {
53+
void WaveViewer::setWave(const double* pointer, double depth, int phaseShift, bool isInverted) {
5254
_waveArrayPointer = pointer;
55+
_depth = depth;
56+
_phaseShift = phaseShift;
5357
_isInverted = isInverted;
5458
}
5559

@@ -65,10 +69,13 @@ namespace WECore::Richter {
6569
Path p;
6670

6771
for (size_t idx {0}; idx < NUM_SAMPLES; idx++) {
72+
// Calculate the index of the sample accounting for downsampling and phase shift
73+
const int sampleIdx {(
74+
(static_cast<int>(idx * INCREMENT + _phaseShift) % Wavetables::SIZE)
75+
)};
76+
6877
// Get the sample for this value
69-
const double sample {
70-
_waveArrayPointer[static_cast<int>(idx * INCREMENT)] * (_isInverted ? -1 : 1)
71-
};
78+
const double sample {_waveArrayPointer[sampleIdx] * _depth * (_isInverted ? -1 : 1)};
7279

7380
// Invert the wave and scale to the height of this component
7481
const double sampleX {(static_cast<double>(idx) / NUM_SAMPLES) * getWidth()};

0 commit comments

Comments
 (0)