Skip to content

Instantly share code, notes, and snippets.

@Munksgaard
Created February 8, 2023 20:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Munksgaard/8e03bf302d80936beae2045a5b72d5ae to your computer and use it in GitHub Desktop.
Save Munksgaard/8e03bf302d80936beae2045a5b72d5ae to your computer and use it in GitHub Desktop.
def cap [n] (xs: [n]f64) =
map (\x -> x / f64.maximum xs) xs
def comb' [n] (delay: i64) (intensity: f64) (xs: [n]f64): [n]f64 =
loop xs = copy xs for i in delay..<n do
let xs[i] = xs[i] + intensity * xs[i - delay]
in xs
entry comb delay intensity = map (cap <-< comb' delay intensity)
def allpass [n] (delay: i64) (intensity: f64) (xs: [n]f64): [n]f64 =
let combed = comb' delay intensity xs
in loop xs = copy xs for i < n do
let xs[i] = (-intensity) * xs[i] + (1 - intensity**2) * (if i < delay then 0 else combed[i-delay])
in xs
def reverb' [n] (xs: [n]f64) =
let cs1 = comb' 1931 0.7 xs
let cs2 = comb' 2213 0.7 xs
let cs3 = comb' 1747 0.7 xs
let cs4 = comb' 1559 0.7 xs
in map4 (\c1 c2 c3 c4 -> c1 + c2 + c3 + c4) cs1 cs2 cs3 cs4
|> allpass 167 0.7
|> allpass 191 0.7
|> cap
entry reverb = map reverb'
-- Original audio:
-- > :audio ($loadaudio "priorities.mp3")
-- With comb filter:
-- > :audio (comb 441i64 0.8f64 ($loadaudio "priorities.mp3"))
-- Reverb:
-- > :audio (reverb ($loadaudio "priorities.mp3"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment