The question is basically: What would a C++ equivalent be to phasor? I know it takes in a frequency and outputs a 0 to 1 sawtooth waveform, but I don't know how it does that without a phase or time reference.
I don't know any C++, so I'll just speak to what its doing in gen, as I understand it.
You can use a counter, or accumulator to simulate a phasor in gen, by taking into account sample rate, and wrapping the count at the appropriate value basd on the frequency value.
Here's a very crude gen~ phasor with nothing but arithmetic in codebox:
frequency = in1;
length = samplerate/frequency;
count = count + 1;
out1 = (count % length)/length;
I am not overthinking this. After implementing the suggested code by Evan, I got results that differ from Max/MSP/Gen.
In Max/MSP/Gen, each call to phasor is indeed a unique oscillator. With Evan's code, changing frequency also changes phase, because there is no memory of phase in Evan's code. In Max/MSP/Gen, increasing frequency simply makes the phasor run faster rather than jerk around like Evan's code (jerking is result of changing phase).
I guess you'd need to keep track of phase separate to freq, with a phase variable expressed as a float between 0 and 1, so if freq is changed, you reset the count according to the current phase fraction
looks eloquent, when frequency changes you alter the increment (phase_inc), while keeping the current accumulation (phase), and your phase is between zero and 2pi which is perhaps more useful than between 0 and 1
Was away for the weekend - sorry I missed the developments. I didn't include any phase handling, because I didn't want to take all the fun ;).
Although it seems you've already got it sorted rather well. my two ideas for handling phase would be to (1)only update at the end of a cycle ( less flexible, but more syncable), or (2) sample the phase when the frequency changes, and then reset the count with the new frequency, while adding an offset equal to the previous phase.