Create a buffer containing a square of dynamic fundamental period

Leo Sebal's icon

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!

Roman Thilenius's icon

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]

Floating Point's icon

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

Leo Sebal's icon

Thank you for your answers.

not sure if i get you: all you want to do is generate the waveform?

Actually, I want to work on frequency content, but basically, yes. So, basically, this should work, shouldn't it?
                    

rect_buffer.maxpat
text/plain 5.36 KB

Why doesn't the waveform display anything?

Floating Point's icon

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

Floating Point's icon

I tried to paste in a patch but not working...
so here's a screenshot

Roman Thilenius's icon

it is hard to see the waveform of a rect in waveform~ or buffer~ :)

Leo Sebal's icon

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 :)

Floating Point's icon

btw works better if the message box (size $1) is change to (sizeinsamps $1)

kLSDiz's icon

If you are interested in stuffing exact number of periods into given number of samples you can go this way:

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


I was surprised this version was actually faster (despite a modulo operator) than more straightforward stateful counter + flipflop.