Created
October 16, 2012 21:08
-
-
Save jbpotonnier/3902075 to your computer and use it in GitHub Desktop.
Morse code base in Haskell
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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