module Main where import Data.WAVE import Data.Int (Int32) import Data.List.Split (splitOn) import System.Environment (getArgs) samplesPS = 16000 bitrate = 32 header = WAVEHeader 1 samplesPS bitrate Nothing sound :: Double -- | Frequency -> Int -- | Samples per second -> Double -- | Lenght of sound in seconds -> Int32 -- | Volume, (maxBound :: Int32) for highest, 0 for lowest -> [Int32] sound freq samples len volume = take (round $ len * (fromIntegral samples)) $ map (round . (* fromIntegral volume)) $ map sin [0.0, (freq * 2 * pi / (fromIntegral samples))..] samples :: Double -> Double ->[[Int32]] samples f d = map (:[]) $ sound f samplesPS d (maxBound `div` 2) waveData f d = WAVE header (samples f d) makeWavFile :: WAVE -> IO () makeWavFile wav = putWAVEFile "sound.wav" wav main = do args <- getArgs case args of [f,d] -> (makeWavFile (waveData (read f) (read d))) >> putStrLn "Done" _ -> putStrLn "USAGE: sound "