Skip to content

Instantly share code, notes, and snippets.

@Heimdell
Last active December 26, 2015 07:09
Show Gist options
  • Save Heimdell/7112965 to your computer and use it in GitHub Desktop.
Save Heimdell/7112965 to your computer and use it in GitHub Desktop.
Sinus-generator
ghc -O3 sin-gen && ./sin-gen && aplay -f S16_LE -r 8000 test.wav
import Data.Word
import qualified Data.ByteString as B
play f = map f [0..]
cosinusoid = breakWordLittleEndian =<< play (fromIntegral . unsignify . round . (* max_word) . cos . accelerate)
where
accelerate x = x + 0.0001 * (x ^ 2)
max_word = 2^15 - 1
unsignify x | x < 0 = 2^16 + x
unsignify x = x
breakWordLittleEndian :: Word16 -> [Word8]
breakWordLittleEndian x = map fromIntegral [x `mod` 256, x `div` 256]
main = do
let piu = B.pack $ take 200000 cosinusoid
B.writeFile "test.wav" piu
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment