Gen Sine

scotts1966's icon

Hi Max / Gen people,

I wonder if someone might answer a question that I have about the history operator in Gen. Specifically in relation to a patch that I have attached to this note. The patch in question contains a Gen instance with a codebox inside. The codebox has 2 little snippets of code that create sine waves (2 separate versions). One is the "standard" way that has been shown in these forums (it is in the form of a function in codebox but it is a replica of a Gen patch found elsewhere) and the second way makes use of 2 history operators assigned to incrementing the phase and then taking the sine of that value. My question is: how are the history operators functioning in the second example? To me it looks like they could just be floats..... Much appreciated if you can throw some light upon that...

sineGen1.zip
zip 4.61 KB

Graham Wakefield's icon

Yes, History declares a value that is preserved over time, and which you can update.

In a codebox you update it by assigning to its name. In a patcher the [history] object does the same thing, but imparts 1 sample of delay between inlet & outlet. This allows you to form feedback loops in the patcher.

History objects are also accessible and modifiable from outside the patcher. So, if nothing is connected to a [history] inlet, or nothing is assigned to the history in a codebox, then it effectively functions just like [param].

Christopher Dobrian's icon

With respect to your question about the use of History, the "phase" value is continually incrementing based on its previous value, so the previous value needs to be stored. However, I don't see any reason why the previous sample output needs to be stored. It does need to be put in a variable before incrementing the phase, as is done, but it doesn't rely on its previous value.

BTW, you may already be aware that for a wavetable-lookup method of generating a sine wave, a cycle object exists in gen~.

And here's another example of how to calculate a cosine waveform gen~, which is completely unneeded, but I did it anyway to illustrate the concept for a class. http://sites.uci.edu/camp2014/2014/04/10/generate-a-sinusoid-with-gen/

scotts1966's icon

Hi,

@Graham: ok thanks for that. I think that is the answer I am looking for. The History operator is just a value that can be utilized to preserve a value over time. That is why that second version works. You can probably tell that that is a port from C++ (without the for loop).

Following on from that I have one more question that my Gen experiments have revealed. I think (though I could be wrong) that one cannot use a loop of some kind to create an array of the oscillators in codebox. That is to say you must add them together one after the other - or is there a better way to do it using the Data object or some other array-like object?

@Chris: I think your point is why I asked the question in the first place. The incrementing value must of course be stored but the previous sample is not important in itself. Thanks for the link I will check that out.