fix: saw and triangle waves
This commit is contained in:
@@ -1,33 +1,15 @@
|
|||||||
module SoundGen.Oscillator
|
module SoundGen.Oscillator
|
||||||
|
open System
|
||||||
open Settings
|
open Settings
|
||||||
|
|
||||||
|
let pos hz x = (hz * x / sampleRate) % 1.
|
||||||
|
|
||||||
let sineosc hz x =
|
let sineosc hz x =
|
||||||
x
|
x |> (*) (2. * Math.PI * hz / sampleRate) |> sin
|
||||||
|> (*) (2. * System.Math.PI * hz / sampleRate)
|
|
||||||
|> sin
|
|
||||||
|
|
||||||
let squareosc hz x =
|
let squareosc hz x =
|
||||||
let sign v : float = if v > 0.0 then 1. else -1.
|
let sign v : float = if v > 0.0 then 1. else -1.
|
||||||
x |> sineosc hz |> sign
|
x |> sineosc hz |> sign
|
||||||
|
let triangleosc (hz:float) (x:float) = 1. - Math.Abs((pos hz x) - 0.5) * 4.
|
||||||
let triangleosc hz x =
|
let sawosc hz x = (pos hz x) * 2. - 1.
|
||||||
let fullPeriodTime = 1.0 / hz
|
let sinesquareosc hz x = sawosc (hz / 4.) x + squareosc (hz/2.) x
|
||||||
let localTime = x % fullPeriodTime
|
|
||||||
let value = localTime / fullPeriodTime
|
|
||||||
|
|
||||||
if (value < 0.25) then
|
|
||||||
value * 4.
|
|
||||||
else if (value < 0.75) then
|
|
||||||
2.0 - (value * 4.0)
|
|
||||||
else
|
|
||||||
value * 4. - 4.0
|
|
||||||
|
|
||||||
let sawosc hz x =
|
|
||||||
let fullPeriodTime = 1.0 / hz;
|
|
||||||
let localTime = x % fullPeriodTime
|
|
||||||
|
|
||||||
((localTime / fullPeriodTime) * 2. - 1.0);
|
|
||||||
|
|
||||||
let sinesquareosc hz x =
|
|
||||||
sineosc (hz/4.) x + squareosc hz x
|
|
||||||
|
|||||||
Reference in New Issue
Block a user