diff --git a/SoundGen/Oscillator.fs b/SoundGen/Oscillator.fs index b26d006..fd9f3b3 100644 --- a/SoundGen/Oscillator.fs +++ b/SoundGen/Oscillator.fs @@ -1,33 +1,15 @@ module SoundGen.Oscillator - +open System open Settings +let pos hz x = (hz * x / sampleRate) % 1. + let sineosc hz x = - x - |> (*) (2. * System.Math.PI * hz / sampleRate) - |> sin + x |> (*) (2. * Math.PI * hz / sampleRate) |> sin let squareosc hz x = let sign v : float = if v > 0.0 then 1. else -1. x |> sineosc hz |> sign - -let triangleosc hz x = - let fullPeriodTime = 1.0 / hz - 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 \ No newline at end of file +let triangleosc (hz:float) (x:float) = 1. - Math.Abs((pos hz x) - 0.5) * 4. +let sawosc hz x = (pos hz x) * 2. - 1. +let sinesquareosc hz x = sawosc (hz / 4.) x + squareosc (hz/2.) x