waves
A block that implements some waves with a specific frequency and normalized output. It provides a (co)sine wave, (reverse) sawtooth, triangle and rectangular wave. Two blocks can be added or combined and rescaled in any other way to make new waves. One waves block connected to another one gives quadratic waves.version
sin~ [pd]v1.0: built with Pd v0.40-2 [pd] [pdf]
v1.1: adapted with Pd v0.40-2 [pd] [pdf]
sine wave added, RESET knob added
v2.0: built with Pd v0.40-2 [pd] [pdf]
new control logic
reverse sawtooth added
interface
Input 1: A value for the frequency of the wave. It is expressed in Hertz and thus must be positive.Input 2: Reset knob. When it is pressed, the wave is restarted from the beginning. For a sine wave, square and sawtooth this is 0, for a cosine, reverse sawtooth and triangle it is 1
Input 3: MIDI control change number. This is used to select the wave: when MIDI control change message 52 sends a value of 127 (aka is pressed in), the different waveforms are cycled.
Output 1: A waveform with a specified frequency, specified form and an amplitude that ranges between 0 and 1.
implementation
fig: respectively prints of a reverse sawtooth, sine or cosine, sawtooth, triangle and quadratic wave
The frequency value one inputs is turned into a signal type with sig~. You get a signal with constant amplitude equal to the value specified. Then a phasor~ object runs through every value starting from 0 to 1 and again at a frequency specified. This already is a ready-made sawtooth signal.The sine block is based on the relationship between sine and cosine function. Read more in documentation of sin~
The sawtooth wave is also used as table lookup signal for the other waves. The cos~ block calculates for each sample the cosine value. This sine is raised above 0 and normalized by dividing with two, or less expensive: multiplying with a half.
The triangle is calculated by shifting the sawtooth so it lies around zero, then taking the absolute value so that the negative part is mirrored to the positive side. This triangle wave has to be scaled by multiplying it with two.
To obtain a reverse sawtooth, the sawtooth is multiplied with -1 which results in a mirroring of the wave around the x-axis. To rescale the wave to a range of 0 to 1, a shift is performed by adding 1 to the wave.
The rectangular wave is made by selectively choosing a 1 or a 0 to output. This is done by the moses block. Because it takes only control lines or values, one has to add a snapshot~ block before it that is banged after each DSP cycle with the bang~ block. The sig~ block transforms this control signal into an audio signal again.
All waves can be seen in the graph when banged on the knob that is located next to the select block on top. It isn't automatically rewritten because that would slow down calculations. Every time a new wave is selected it will be drawn once.
The control logic is simple. When a specific MIDI control change number is received with a value of 127 a counter adds up. This addition is modulo the number of waveforms. An extra select block is added to select a number from the counter and then bang the right message. Each output in this patch has a multiplication with one or zero to turn it on or off.
-ronny 4/14/07 6:59 PM
No comments:
Post a Comment