packages feed

lambdasound-1.0.0: example/Example1.hs

import Data.Coerce (coerce)
import LambdaSound

main :: IO ()
main = play 44100 0.4 $ simpleReverb 0.1 $ applyIIRFilter (highPassFilter 600 1) sound

sound :: Sound T Pulse
sound = melody <> background

background :: Sound T Pulse
background =
  repeatSound 3 $
    sequentially $
      fmap
        (setDuration 0.5)
        [ note c3,
          parallel $ note <$> [e3, g3],
          parallel $ note <$> [e3, g3],
          parallel $ note <$> [e3, g3]
        ]

melody :: Sound T Pulse
melody =
  let mel =
        repeatSound
          3
          ( sequentially $
              fmap
                (setDuration 0.5)
                [ note c4,
                  note e4,
                  note g4,
                  note e4
                ]
          )
          >>> end
      end = setDuration 2 $ parallel [note c4, note c3, note g3]
   in mel

note :: Semitone -> Sound T Pulse
note st =
  applyEnvelope (Envelope 0.2 0.1 0.2 0.8) $
    setDuration 1 $
      asNote (harmonic sineWave) st

-- Further examples

metronome :: Sound T Pulse
metronome = repeatSound 10 $ setDuration 1 $ note c4 >>> setDuration 2 silence

upSound :: Sound T Pulse
upSound =
  zipSoundWith (*) ((\p -> 1 - coerce p) <$> progress) $
    speedUp $
      upwards >>> takeSound 2 (raiseSemitones 12 upwards) >>> setDuration 1 (note g5)

upwards :: Sound T Pulse
upwards = setDuration 3.5 $ sequentially $ note <$> [c4, d4, e4, f4, g4, a4, b4]

speedUp :: Sound T Pulse -> Sound T Pulse
speedUp = changeTempo $ \p -> p ** 2