# How do I Make Waveforms Other than Sine?

Hi, I’m new to making vst plugins, and I would like to make the saw, triangle, and square waves but I don’t know which function to call other than sin(). Can someone help me?
This is my code so far for waveform generation:

``````Vst::Sample32* outL = data.outputs.channelBuffers32;
Vst::Sample32* outR = data.outputs.channelBuffers32;
for (int32 i = 0; i < data.numSamples; i++){
outL[i] = fOsc1 * sin(fOsc1Phase);
outL[i] += fOsc1 * sin(fOsc2Phase);
outL[i] *= fVolume;
outR[i] = outL[i];

fOsc1Phase += fDeltaAngle;
fOsc2Phase += fDeltaAngle * 2.f;
}
``````

I think the best would be to implement a wavetable, it’s a bit complicated but you can find examples on the net…
If you want to start simple you could write your own function… for example you could generate a square with something like this (pseudo code):

``````
int square(phase){
if (phase < 3.14) return 0;  //between 0 and 180 degrees, or 0 and pi if using radians
else  return 1; //between 180 and 360 degrees, or pi and 2pi if using radians
}
``````

A saw wave is growing linearly between 0 and 1 during a phase period…