Last active
December 26, 2015 07:09
-
-
Save Heimdell/7112965 to your computer and use it in GitHub Desktop.
Sinus-generator
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
ghc -O3 sin-gen && ./sin-gen && aplay -f S16_LE -r 8000 test.wav |
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
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