@@ -30,9 +30,9 @@ namespace WECore::Richter {
30
30
31
31
class WaveViewer : public Component {
32
32
public:
33
- WaveViewer () : _waveArrayPointer(nullptr ), _isInverted(false ) {}
33
+ WaveViewer () : _waveArrayPointer(nullptr ), _depth( 0 ), _phaseShift( 0 ), _isInverted(false ) {}
34
34
35
- inline void setWave (const double * pointer, bool isInverted);
35
+ inline void setWave (const double * pointer, double depth, int phaseShift, bool isInverted);
36
36
37
37
inline virtual void paint (Graphics& g);
38
38
@@ -45,11 +45,15 @@ namespace WECore::Richter {
45
45
46
46
private:
47
47
const double * _waveArrayPointer;
48
+ double _depth;
49
+ int _phaseShift;
48
50
bool _isInverted;
49
51
};
50
52
51
- void WaveViewer::setWave (const double * pointer, bool isInverted) {
53
+ void WaveViewer::setWave (const double * pointer, double depth, int phaseShift, bool isInverted) {
52
54
_waveArrayPointer = pointer;
55
+ _depth = depth;
56
+ _phaseShift = phaseShift;
53
57
_isInverted = isInverted;
54
58
}
55
59
@@ -65,10 +69,13 @@ namespace WECore::Richter {
65
69
Path p;
66
70
67
71
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
+
68
77
// 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 )};
72
79
73
80
// Invert the wave and scale to the height of this component
74
81
const double sampleX {(static_cast <double >(idx) / NUM_SAMPLES) * getWidth ()};
0 commit comments