Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Envelope documentation #8

Open
JeffreyBenjaminBrown opened this issue Sep 7, 2020 · 0 comments
Open

Envelope documentation #8

JeffreyBenjaminBrown opened this issue Sep 7, 2020 · 0 comments

Comments

@JeffreyBenjaminBrown
Copy link

A million years ago on an extinct mailing list (Haskell Art), you gave me an example of how to use envelopes. Yesterday I discovered it works like a charm. I've tweaked it a little and added comments. It might make a good piece of documentation to add somewhere, maybe at the top of Vivid.Envelopes.

{-# LANGUAGE DataKinds, ExtendedDefaultRules #-}

import Vivid

main :: IO ()
main = do
   s <- synth foo ()
   wait 1
   putStrLn "Now we fade in!"
   set s (1 ::I "gate")
   wait 4 -- because the envelope below lasts 1+2+1 seconds
   free s

e :: EnvLiterally '["gate"]
e = env 0 -- The level to start at.
  [ -- These are (level, time in seconds to reach that level) pairs.
    (1, 1) 
  , (1, 2) -- Since the last level was also 1, this pair causes
  -- the envelope to stay at 1 for 2 seconds after reaching it.
  , (0, 1)]
  Curve_Lin

-- This has a default gate of 0, so the envelope doesn't trigger when
-- the voice is created; rather, the user must send a positive gate value
-- to trigger it. (If they then send another 0, they gain the opportunity
-- to retrigger it with another positive gate value.)
-- If instead the default was 1, then the user would not need to send
-- the initial gate value separately (but they could still send 0
-- to make it ready to retrigger).
foo :: SynthDef '["gate"]
foo = sd (0 ::I "gate") $ do
   e' <- envGen_wGate (V::V "gate") 1 e DoNothing
   s <- sinOsc (freq_ 440) ~* e'
   out 0 [s,s]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant