How does the osc sync function in shruthi source code

Hallo pichenettes

how does the osc sync function in shruthi source code. I can not find that in the oscillator.cc.

In my code i sync osc1 before fill the buffer for osc1. The problem is two buffer for osc1 and osc2.

Thanks for your help :slight_smile:

Your code doesn’t work because you render samples by blocks of several (buffer_fill) samples.

If oscillator 2’s phase wraps around when buffer_fill is equal to 14, then oscillator 1’s phase must be reset to 0 when buffer_fill reaches 14 during oscillator 1’s rendering loop. This is not the case with your code - your code is such that whenever there is a wrap around of oscillator 2’s phase in a block, there will be a single phase reset of oscillator 1 at the beginning of the next block.

To avoid this situation, I fill a temporary buffer that stores, for each sample, the value 0 when there is no wrap around, and the value 1 when there is a wrap around. Then I use this buffer to reset the phase of the other oscillator.

Let’s say we want to sync oscillator 2 to oscillator 1 (you seem to do the opposite, sync oscillator 1 to 2, I don’t know why…).

For oscillator 1:

syncbuffer[i] = phase < phase_increment ? 1 : 0;

For oscillator 2:

if (syncbuffer[i]) phase = 0;

Ok… Thank you very much. you have helped me a lot :)))

I`m happy… its function now. See osc render code with sync in appendix,

Here’s a small video from Oscillator with sync

The sound quality is not good because I have recording with smart smartphone.

Greetings Rolf.