Create a buffer containing a square of dynamic fundamental period
Hello,
My current issue is a problem that should be quite simple: I'd like to create a buffer containing a square wave, of which I can choose the fundamental period. I've tried several ways, none of which worked:
* Creating a square wave with `rect~` and recording the output with `record~`,
* Using `uzi~` with messages activated depending on the value of the output of `uzi~`, and putting that into a `peek~` buffer,
* Using directly the `buffer~` gen functions, but there doesn't seem to be an option to do specifically that.
Any help will be greatly appreciated!
not sure if i get you: all you want to do is generate the waveform?
then uzi and peek~ is not bad approach. i do this for all kind of waveforms.
[uzi 999]
[if $i1<=500 then -1. else 1.]
[peek~ foo]
use roman's approach , except for periods other than 1 use modulus, for example:
[uzi 999]
[% 500]
[if $i1<=250 then -1. else 1.]
[peek~ foo]
will give a base freq of 2
i think you need to specify floats in the if object, but more important is to specify the address to poke into, hence the two inputs used and the trigger object
I tried to paste in a patch but not working...
so here's a screenshot

it is hard to see the waveform of a rect in waveform~ or buffer~ :)
Aaah, thank you Floating Point, now it's working :) I just have to understand what the things you changed did.
it is hard to see the waveform of a rect in waveform~ or buffer~ :)
Actually, no! See Floating Point's screenshot: Max/MSP doesn't draw a single line, but fills the space between the waveform and the y=0 axis :)
btw works better if the message box (size $1) is change to (sizeinsamps $1)
If you are interested in stuffing exact number of periods into given number of samples you can go this way:
I was surprised this version was actually faster (despite a modulo operator) than more straightforward stateful counter + flipflop.