Projects

JSyn - modular synthesis API for Java.
JMSL - Java Music Specification Language
PortAudio - cross platform audio I/O API for 'C'

JSyn Tutorial

Generating Other Waveforms from the Sawtooth

Let's take another look "under the hood" and see how JSyn generates some of the other waveforms.  It turns out that the sawtooth wave is the starting point for generating all the other waveforms.

Remember, you won't have to use these techniques in your programs. You just create a SquareOscillator, or some other oscillator, and use it. But this page will give you a better understanding of what you are getting.

Here we can see a square wave in red superimposed over a sawtooth wave. Notice that when the sawtooth wave is above zero that the square is high, and vice versa. So to make a square wave, JSyn first generates a sawtooth then does this:

if( saw > 0.0 ) square = 1.0;
else square = -1.0;
Here we can see a triangle wave in red superimposed over a sawtooth wave. Notice that when the sawtooth wave is above zero, that the triangle wave is descending from +1.0 to -1.0. Here is how JSyn generates a triangle wave from a sawtooth wave:
if( saw >= 0.0 ) triangle = 1.0 - ( 2.0 * saw );
else triangle = 1.0 + ( 2.0 * saw );
For the sine wave, JSyn simply applies the trigonometric function to the sawtooth value:
sineWave = sin( PI * saw );