Table of Contents:


Square Waves

$$ SquareWave(x) = \frac{2}{\pi}\arctan(\tan(\frac{\pi x}2))+\frac{2}\pi\arctan(\cot(\frac{\pi x}2)) $$

#define float_pi 3.14159

float SquareWave( float x, float Frequency ) {
	float value1 = (2.f / float_pi) * arctan(tan(float_pi * x * Frequency / 2));
	float value2 = (2.f / float_pi) * arctan(cot(float_pi * x * Frequency / 2));
	return value1 + value2;
}

Saw Waves

$$ SawWave(x) = x\mod{2}-1 $$

float SawWave( float x, float Frequency ) {
	float value = ((x * Frequency) % 2) - 1;
	return value;
}

Pulse Waves (8 bit)

$$ PulseWave(x)= \frac{order}{4}+\sum^\infin_{n=1}{\frac{2}{\pi n}\sin(\frac{\pi n * order}{4})}\cos(\frac{2\pi n}{4}(x-\frac{1}2)) $$

#define float_pi 3.14159

float PulseWave( float x, float order, int quality ) {
	float Summation = order / 4.f; //initial value of the summation
	
	for (int n = 1; n < quality; n++) {
		Summation += (2.f / (float_pi * n)) * sin((float_pi * n * order)/4.f) * cos((2.f * float_pi * n)/4.f * (x - 0.5));
	}
	
	return Summation;
}

Adding Waves

Super Saw Waves

https://www.desmos.com/calculator/wlgnzulcpc