Skip to content

Commit

Permalink
Add saturation operator
Browse files Browse the repository at this point in the history
  • Loading branch information
gridbugs committed Jul 28, 2023
1 parent 0150b66 commit 17ea609
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 0 deletions.
1 change: 1 addition & 0 deletions examples/demo.ml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ let signal =
~cutoff_hz:((const 1.0 -.. preset) *.. const 5000.0)
|> map ~f:(fun x -> x *. 2.0 |> Float.clamp_sym ~mag:1.0)
|> echo ~f:(scale 0.5) ~delay_s:(const 0.4)
|> saturate ~boost:(const 2.0) ~threshold:(const 1.0)

let () =
with_window (fun window ->
Expand Down
4 changes: 4 additions & 0 deletions src/core/dsl.ml
Original file line number Diff line number Diff line change
Expand Up @@ -134,3 +134,7 @@ let echo ~f ~delay_s =

let lazy_amplifier signal_ ~volume =
Lazy_amplifier.(signal { signal = signal_; volume })

let saturate signal_ ~boost ~threshold =
map3 signal_ boost threshold ~f:(fun x boost threshold ->
x *. boost |> Float.clamp_sym ~mag:threshold)
1 change: 1 addition & 0 deletions src/core/dsl.mli
Original file line number Diff line number Diff line change
Expand Up @@ -99,3 +99,4 @@ val echo : f:(float t -> float t) -> delay_s:float t -> float t -> float t
after a delay of [delay_s] seconds. *)

val lazy_amplifier : float t -> volume:float t -> float t
val saturate : float t -> boost:float t -> threshold:float t -> float t

0 comments on commit 17ea609

Please sign in to comment.