Skip to content

Instantly share code, notes, and snippets.

@jbpotonnier
Created October 16, 2012 21:08
Show Gist options
  • Save jbpotonnier/3902075 to your computer and use it in GitHub Desktop.
Save jbpotonnier/3902075 to your computer and use it in GitHub Desktop.
Morse code base in Haskell
mport Sound.Tomato.Speakers
sound freq duration = withSpeakers sampleRate 128 $ \s -> playSamples s sound
where
sampleRate = 22050
dt = 1 / sampleRate -- time in seconds of a single sample
sound = take (ceiling $ duration / dt)
$ map (0.3*) $ sine freq
sine freq = [sin (2*pi*freq*dt*fromIntegral t) | t <- [0..]]
beep duration = sound 1000 duration
short = beep 0.2
long = beep 0.3
letter 'S' = [short, short, short]
letter 'O' = [long, long, long]
sentence = sequence_ . concatMap letter
main = sentence "SOS"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment