waveform (square, sin, saw, etc.)

Another of my simple questions.

How to generate cyclic values which have sinus shapes, squares shapes ? but not as sound signals but just float values ?

Have someone an idea or an addon to advice about it ?

Thx in advance.
Sebastien

there are a number of waveform libraries out there: if you just want a quick ready made solution a google search will do the trick :slight_smile:

on the other hand making waveforms on your own is really easy; something like this will do the trick:

  
  
float samples[nSamples];  
for(int i=0; i<nSamples;i++){  
   float a = TWO_PI/nSamples*i;  
   //sine wave  
   samples[i]=sin(a);  
   //square wave  
   samples[i]=sin(a)>0?1:-1;  
   //saw wave  
   samples[i]=fmod(i,TWO_PI);  
}