1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 19:57:45 +00:00

Piano: Add triangle wave and noise

The squad is complete :^)

You can find the equation for the triangle wave here:
https://en.wikipedia.org/wiki/Triangle_wave
We're using this one:
|x mod 4 - 2| - 1
Modifications have been made to correct the frequency and phase:
|(4x + 1) mod 4 - 2| - 1

The white noise is generated by calling rand() and dividing it by
RAND_MAX to get a value from 0 to 1. Then it's adjusted to fit between
-1 and 1.
This commit is contained in:
William McPherson 2019-12-13 19:19:57 +11:00 committed by Andreas Kling
parent 091c783626
commit 69d05fbf44
3 changed files with 38 additions and 1 deletions

View file

@ -9,7 +9,7 @@ struct Sample {
i16 right;
};
enum WaveType { Sine, Saw, Square, InvalidWave };
enum WaveType { Sine, Saw, Square, Triangle, Noise, InvalidWave };
enum PianoKey {
K_None,