summaryrefslogtreecommitdiffstats
path: root/src/osc.c
diff options
context:
space:
mode:
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) {