Discrete frequency change of the phasor~ object at the ramp transition (1-0)

radiotonga's icon

Hello everybody,

I would like to feed frequencies to the phasor~ object but only whenever it completes its present cycle (1-0 at the ramp transition). So it would be a discrete change, instead of continuous. I have tried to use sah~ along with the delta~ and

I need this to be done with just one phasor~ because otherwise I get a result identical to the rate~ object at "sync cycle", whereas you do get a change in frequency when the ramp ends, but since the feeding phasor~ has to necessarily be out sync to the receiving rate~ object (because you're changing the frequency at different times), this method is pointless.

Max Patch
Copy patch and select New From Clipboard in Max.

Any ideas ? Thank you very much for your help. Here's an example patch:

Floating Point's icon

Have you seen this? mr raja posted what could be solution to your problem here:

i dont know if it addresses exactly what you need, but it might provide some clues

radiotonga's icon
Max Patch
Copy patch and select New From Clipboard in Max.

Ok, thanks Sir Floating Point and Mr. Raja. I reworked the patch in gen and here's my reasonable, 1-sample delayed solution for posterity:

Roman Thilenius's icon

"at the ramp time position" means at a certain sample (if not subsample).

so without gen - no chance.

radiotonga's icon

Hmmm, "subsample level", yeah, so now I will have to go back and read up on my DSP basics. Thanks Roman. Now, this is just a technical musing, but should I assume these subsample values are the product of interpolation on the time axis and not actually a further level of quanta to the DSP realm?

Peter McCulloch's icon

Yes. It means wrapping to x % 1 instead of just resetting to 0.

Otherwise, you could never represent frequencies that were not integer subdivisions of the samplerate. (100 Hz would work, 100.1 would not).

A quick way to determine if a problem needs gen~:
1. Does the output affect how the input works?
2. Does time precision matter?

If yes on both, use gen~.

radiotonga's icon

Thanks Peter. Now I'm beginning to understand such intricacies; for some reason I always assumed that sample rate dictated the finest grain of detail in the time-domain, but now I can see there's has to be a "master clock" (probably derived from the CPU?) providing further interpolation (i.e. filling the blanks in time). This becomes obvious once you start zooming in on any DAW to do some micro-editing.

Peter McCulloch's icon

No faster master clock needed! That's what interpolation does for you. Those subsample fractions add up over time. (e.g. 1.2+1.2+1.2+1.2+1.2 = 6 in the time of 5)

Conceptually...rather than as a repeating pattern, it may be helpful to imagine a phasor as a line moving towards infinity at a constant rate (e.g. sample increases by 0.07), and you're just wrapping its value into a 0-1 range (which is much easier to work with than 0-twopi).

Alternatively, you can think about it as a unit vector rotating around the unit circle and the sample increment is the amount of change in theta per sample (* twopi). This model is useful with the FFT, since after Cartopol~ on the FFT data, you have your radius and your theta position. By tracking changes in theta you can locate a frequency with sub-bin accuracy. Again, just interpolation!

(Exclamation marks used because I find this stuff fascinating.)

radiotonga's icon

Thanks again Peter for further explaining this (and I thought I was getting close!)... I also find this stuff fascinating, so I really appreciate that there's places like this where you can learn from far more experienced, yet like-minded individuals. It really opens up whole new worlds to explore, much to the chagrin of more earthly preoccupations – I will have to keep on researching this topic of interpolation, dammit!

Peter McCulloch's icon

Happy to help. The good thing about interpolation in Max is that most of the places you need it, Max takes care of it for you. (This is really useful in gen~)