From 2e1a5b2bf820f0295b1ef31a89d82fc0ebe1d45c Mon Sep 17 00:00:00 2001 From: HiveBeats <38073817+HiveBeats@users.noreply.github.com> Date: Mon, 31 Oct 2022 00:42:35 +0400 Subject: [PATCH] feat: saturation --- SoundGen/Program.fs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/SoundGen/Program.fs b/SoundGen/Program.fs index fd6256b..39d6ced 100644 --- a/SoundGen/Program.fs +++ b/SoundGen/Program.fs @@ -37,6 +37,9 @@ let getSemitonesByNote (str: string) = (octave - defaultOctave - 1) * 12 + noteShift +let saturate x = + tanh (6. * x) + let toInt16Sample sample = sample |> (*) 32767. |> int16 let freq hz duration = @@ -62,7 +65,8 @@ let freq hz duration = x |> (*) (2. * System.Math.PI * hz / sampleRate) |> sin - |> (*) volume) + |> (*) volume + ) samples let adsrLength = Seq.length output @@ -73,7 +77,7 @@ let freq hz duration = let release = Seq.rev attackArray Seq.zip3 release attackArray output - |> Seq.map (fun (x, y, z) -> (x * y * z)) + |> Seq.map (fun (x, y, z) -> (x * y * z) |> saturate) let note semitone beats =