feat: waveshaper contains softclipping

This commit is contained in:
HiveBeats
2022-11-01 12:39:07 +04:00
parent 4edafbe664
commit 71927731d3
2 changed files with 135 additions and 47 deletions

View File

@@ -1,15 +1,20 @@
module SoundGen.Fx module SoundGen.Fx
open Settings open Settings
type Effect = type Effect =
| Saturator | Saturator
| Reverb | Reverb
type Reverb = { Wet: float; Room: float } type ReverbParam = { Wet: float; Room: float }
type Saturator = { Gain: float } type SaturatorParam = { Gain: float }
type WaveshaperParam = {Gain: float; Factor: float;}
let saturate (param: Saturator, x: float) = tanh (param.Gain * x) let saturator (param: SaturatorParam) (x: float) = tanh (param.Gain * x)
let sineWaveShape gain factor x = x + gain * sin (factor * x) let waveshaper (param: WaveshaperParam) x =
(x + param.Gain * sin (param.Factor * x))
|> saturator { Gain = 1.0 }
let reverb (buffer: float seq) = let reverb (buffer: float seq) =
let delayMilliseconds = 500. //((1./8.) * beatDuration) // 500 is half a second let delayMilliseconds = 500. //((1./8.) * beatDuration) // 500 is half a second

View File

@@ -6,45 +6,130 @@ open SoundGen.Fx
open Synth open Synth
let song = let song =
[ note 3 0.5 [ //
note 0 0.25;
note 0 0.25;
note 0 0.25;
note 0 0.25;
note 0 0.5
note 0 0.25;
note 0 0.25;
note 0 0.25;
note 0 0.25;
note 0 0.25
note 0 0.25;
note 0 0.5;
note 5 0.25;
note 5 0.25;
note 5 0.25;
note 5 0.25;
note 5 0.25
note 5 0.25;
note 5 0.5;
note 3 0.25;
note 3 0.25;
note 3 0.25;
note 3 0.25;
note 3 0.25
note 3 0.25;
note 3 0.5 note 3 0.5
note 15 0.5
note 15 0.5
note 6 0.5
note 18 0.5
note 3 0.5
note 15 0.5
note (-1) 0.5
note (-1) 0.5
note 11 0.5
note 15 0.5
note (-2) 0.5 note (-2) 0.5
note (-2) 0.5
note 10 0.5
note 15 0.5
// //
note 3 0.5 //
note 3 0.5 note 0 0.25;
note 15 0.5 note 0 0.25;
note 15 0.5 note 0 0.25;
note 0 0.25;
note 0 0.5
note 0 0.25;
note 0 0.25;
note 0 0.25;
note 0 0.25;
note 0 0.25
note 0 0.25;
note 0 0.5;
note 6 0.5 note 5 0.25;
note 18 0.5 note 5 0.25;
note 5 0.25;
note 5 0.25;
note 5 0.25
note 5 0.25;
note 5 0.5;
note 3 0.25;
note 3 0.25;
note 3 0.25;
note 3 0.25;
note 3 0.25
note 3 0.25;
note 3 0.5 note 3 0.5
note 15 0.5
note (-1) 0.5
note (-1) 0.5
note 11 0.5
note 15 0.5
note (-2) 0.5 note (-2) 0.5
//
//
note 0 0.25;
note 0 0.25;
note 0 0.25;
note 0 0.25;
note 0 0.5
note 0 0.25;
note 0 0.25;
note 0 0.25;
note 0 0.25;
note 0 0.25
note 0 0.25;
note 0 0.5;
note 5 0.25;
note 5 0.25;
note 5 0.25;
note 5 0.25;
note 5 0.25
note 5 0.25;
note 5 0.5;
note 3 0.25;
note 3 0.25;
note 3 0.25;
note 3 0.25;
note 3 0.25
note 3 0.25;
note 3 0.5
note (-2) 0.5 note (-2) 0.5
note 10 0.5 //
note 15 0.5 ] //
note 0 0.25;
note 0 0.25;
note 0 0.25;
note 0 0.25;
note 0 0.5
note 0 0.25;
note 0 0.25;
note 0 0.25;
note 0 0.25;
note 0 0.25
note 0 0.25;
note 0 0.5;
note 5 0.25;
note 5 0.25;
note 5 0.25;
note 5 0.25;
note 5 0.25
note 5 0.25;
note 5 0.5;
note 3 0.25;
note 3 0.25;
note 3 0.25;
note 3 0.25;
note 3 0.25
note 3 0.25;
note 3 0.5
note (-2) 0.5
]
|> Seq.concat |> Seq.concat
@@ -56,8 +141,6 @@ let writeToFile (ms: MemoryStream) =
song song
//|> reverb //|> reverb
|> Seq.map (fun x -> |> Seq.map (waveshaper {Gain=1.5; Factor=2.5})
let x1 = sineWaveShape 1.5 2.5 x
saturate ({ Gain = 1.0 }, x1))
|> createWAV |> createWAV
|> writeToFile |> writeToFile