/*
* arngment - random music generator
*
* Written in 2020 by Lucas
*
* To the extent possible under law, the author(s) have dedicated all
* copyright and related and neighboring rights to this software to the
* public domain worldwide. This software is distributed without any
* warranty.
*
* You should have received a copy of the CC0 Public Domain Dedication
* along with this software. If not, see
* .
*/
#include
#define CLAMP(x, a, b) ((x) < (a) ? (a) : (x) > (b) ? (b) : (x))
double
synth_distortion(double gain, double x)
{
double xg = CLAMP(x * gain, -1.0, 1.0);
return (x + xg) / 2.0;
}
double
synth_sinewave(double t, double a)
{
return sin(2.0 * M_PI * t * a);
}
double
synth_trianglewave(double t, double a)
{
double x = t * a;
return 2.0 * fabs(2.0 * (x - floor(0.5 + x))) - 1.0;
}