// synchronize one tap with another at a given offset in seconds. // useful for delays void buffer_tap_sync(bufferTap* tap, bufferTap* target, fix16 offset) { fix32 sampsOff; // time_to_samps(&offset, &sampsOff, tap->buf->sr); sec_to_frames_fract(&offset, &sampsOff); tap->idx = target->idx; sub_fix32(&(tap->idx), &sampsOff); fix32_wrap_range(&(tap->idx), tap->loop); }
// wrap a 32.32 value to a positive integer range extern void fix32_wrap_range(fix32* a, u32 upperBound) { static fix32 upFix; upFix.i = upperBound; upFix.fr = 0; // u8 wrapCount = 0; while (a->i < 0) { //a->i += upperBound; add_fix32(a, &upFix); // wrapCount++; } // if(wrapCount) { // a->fr = sub_fr1x32(FR32_MAX, a->fr); // } while(a->i > (upperBound-1)) { // a->i -= upperBound; sub_fix32(a, &upFix); } }