summaryrefslogtreecommitdiffstats
path: root/src/osc.c
diff options
context:
space:
mode:
authorgramanas <anastasis.gramm2@gmail.com>2023-11-27 01:03:38 +0200
committergramanas <anastasis.gramm2@gmail.com>2023-11-27 01:03:38 +0200
commitb0128e30840dff1e7db7bcfd69e6fa4f09ed5fbe (patch)
tree633be15d0e962db8fd7f2254df7a852f53b85ddc /src/osc.c
parentfb31c071fe835c5ffd1f70d3558acecee2ed7f17 (diff)
downloadsynth-project-b0128e30840dff1e7db7bcfd69e6fa4f09ed5fbe.tar.gz
synth-project-b0128e30840dff1e7db7bcfd69e6fa4f09ed5fbe.tar.bz2
synth-project-b0128e30840dff1e7db7bcfd69e6fa4f09ed5fbe.zip
wavetables
Diffstat (limited to 'src/osc.c')
-rw-r--r--src/osc.c10
1 files changed, 6 insertions, 4 deletions
diff --git a/src/osc.c b/src/osc.c
index 384f002..8ce915c 100644
--- a/src/osc.c
+++ b/src/osc.c
@@ -21,17 +21,19 @@ osc_interpolate(float offset, float start, float end) {
int
osc_next_index(osc_t * osc, float offset)
{
- if (offset >= osc->len) offset = 0;
+ if (offset >= osc->len) offset = fmodf(osc->start + offset, osc->len - osc->start);
+ if (offset < osc->start) offset = osc->start + fmodf(osc->start + offset, osc->len - osc->start);
int current_index = (int)offset;
- return current_index + 1 >= osc->len ? 0 : current_index + 1;
+ return current_index + 1 >= osc->len ? osc->start : current_index + 1;
}
float
osc_next_offset(osc_t * osc, float f, float offset)
{
- if (offset >= osc->len) offset = 0;
+ if (offset >= osc->len) offset = fmodf(osc->start + offset, osc->len - osc->start);
+ if (offset < osc->start) offset = osc->start + fmodf(osc->start + offset, osc->len - osc->start);
if (osc->type == SAMPLE) {
// this makes A2 be the base ???
@@ -40,7 +42,7 @@ osc_next_offset(osc_t * osc, float f, float offset)
f = f / (16.35160 * pow(2, (2 + 5 / 12.0)));
}
- float step = f * ((float)osc->len / SAMPLE_RATE);
+ float step = f * ((osc->len - osc->start) / (float)SAMPLE_RATE);
offset += step;
if (offset >= osc->len) {