Question

I'm creating a VST for a project, and trying to create an oscillator produces sawtooth, pulse, sin and triangle wave forms. I've looked everywhere and cannot seem to find anything useful (for me), essentially because I'm struggling to understand it.

so far I have...

 for (i=0;i<KWaveSize;i++)
 {
      sawtooth[i] = (float)(-1. + (2. * ((double)i / (double)kWaveSize)));
      pulse[i] = (i < wh) ? -1.f : 1.f;
      sine [i] (float)sin(twoPi * ((float)i /kWaveSize));
      triangle[i] = ....
 }

I'm just struggling on how to create the correct waveform using this.

I tried doing:

 triangle[i] = (float)(1 -((twoPi / KWaveSize) * i));

this was an educated guess based on the book I was following, but produces a distorted sound.

If anyone has done anything like this that can help, or point me to a newbie tutorial for all things sound synthesis where wave table generation etc is covered it would be greatly appreciated.

Thanks.

Was it helpful?

Solution

You need a wave that switches direction - it goes positive from 0 to kWaveSize/2 and negative from there to kWaveSize.

triangle[i] = i < kWaveSize/2 ? -1.0 + 2.0 * i / (kWaveSize*0.5) : 1.0 - 2.0 * i / (kWaveSize*0.5);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top