From d4c386f61c360192af0c0298d018bd2cce85d036 Mon Sep 17 00:00:00 2001 From: grm Date: Sat, 16 Aug 2025 12:12:33 +0300 Subject: Some initial docu and small ui updates --- src/osc.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) (limited to 'src/osc.c') diff --git a/src/osc.c b/src/osc.c index 28e35b4..70e7c32 100644 --- a/src/osc.c +++ b/src/osc.c @@ -18,6 +18,12 @@ osc_interpolate(float offset, float start, float end) { return m * x + b; } +/** + * Takes a floating-point position (offset) in the oscillator/buffer. + * Wraps it so it stays between osc->start and osc->len - 1 (cyclically). + * Converts it to an integer index. + * Returns the next index, wrapping back to osc->start if it reaches the end. + */ int osc_next_index(osc_t * osc, float offset) { @@ -27,7 +33,18 @@ osc_next_index(osc_t * osc, float offset) int current_index = (int)offset; return current_index + 1 >= osc->len ? osc->start : current_index + 1; } +// TODO same from AI: check it +/* int */ +/* osc_next_index(osc_t *osc, float offset) { */ +/* float range = osc->len - osc->start; */ +/* // Wrap offset into the [start, len) range */ +/* offset = osc->start + fmodf(offset - osc->start + range, range); */ + +/* // Get integer index and advance */ +/* int next = (int)offset + 1; */ +/* return (next >= osc->len) ? osc->start : next; */ +/* } */ float osc_next_offset(osc_t * osc, float f, float offset) @@ -52,6 +69,40 @@ osc_next_offset(osc_t * osc, float f, float offset) return offset; } +/* static inline float wrap_offset(float x, float start, float len) { */ +/* float range = len - start; */ +/* x -= start; */ +/* x -= range * floorf(x / range); // efficient wrap to [0, range) */ +/* return start + x; */ +/* } */ + +/* float osc_next_offset(osc_t * osc, float f, float offset) */ +/* { */ +/* // Wrap once at the start */ +/* if (offset < osc->start || offset >= osc->len) { */ +/* offset = wrap_offset(offset, osc->start, osc->len); */ +/* } */ + +/* if (osc->type == SAMPLE) { */ +/* // Precomputed constant for (16.35160 * 2^(2 + 5/12)) */ +/* // = base frequency for A2 mapping */ +/* #define BASE_A2_FACTOR 220.00000f */ +/* f /= BASE_A2_FACTOR; */ +/* } */ + +/* // Precompute conversion factor */ +/* float step = f * ((osc->len - osc->start) / (float)SAMPLE_RATE); */ + +/* offset += step; */ + +/* // Single wrap without fmodf (branchless for most cases) */ +/* if (offset >= osc->len) { */ +/* offset -= osc->len; */ +/* } */ + +/* return offset; */ +/* } */ + int osc_load_wav(osc_t * osc, const char * path) { -- cgit v1.2.3