-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTriangleWaveform.cpp
More file actions
19 lines (15 loc) · 849 Bytes
/
Copy pathTriangleWaveform.cpp
File metadata and controls
19 lines (15 loc) · 849 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
/* Dependencies */
#include "TriangleWaveform.h"
namespace CheapTune {
Sample_t TriangleWaveform::getSample(WavetableIndex_t index) {
/* Triangle wave algorithm */
if (index < (WAVETABLE_SAMPLES_COUNT / 4))
return ((Sample_t) index) * SAMPLE_VMAX / (WAVETABLE_INDEX_BITMASK / 4);
else if (index >= (WAVETABLE_SAMPLES_COUNT / 4) && index < (WAVETABLE_SAMPLES_COUNT / 4 * 2))
return ((Sample_t) index - (WAVETABLE_SAMPLES_COUNT / 4)) * SAMPLE_VMIN / (WAVETABLE_INDEX_BITMASK / 4) + SAMPLE_VMAX;
else if (index >= (WAVETABLE_SAMPLES_COUNT / 4 * 2) && index < (WAVETABLE_SAMPLES_COUNT / 4 * 3))
return ((Sample_t) index - (WAVETABLE_SAMPLES_COUNT / 4 * 2)) * SAMPLE_VMIN / (WAVETABLE_INDEX_BITMASK / 4);
else
return ((Sample_t) index - (WAVETABLE_SAMPLES_COUNT / 4 * 3)) * SAMPLE_VMAX / (WAVETABLE_INDEX_BITMASK / 4) + SAMPLE_VMIN;
}
}