soundgen (empty) → 0.1.0.0
raw patch · 5 files changed
+92/−0 lines, 5 filesdep +WAVEdep +basedep +splitsetup-changed
Dependencies added: WAVE, base, split
Files
- ChangeLog.md +5/−0
- LICENSE +30/−0
- Setup.hs +2/−0
- soundgen.cabal +24/−0
- src/Main.hs +31/−0
+ ChangeLog.md view
@@ -0,0 +1,5 @@+# Revision history for sound++## 0.1.0.0 -- YYYY-mm-dd++* First version. Released on an unsuspecting world.
+ LICENSE view
@@ -0,0 +1,30 @@+Copyright (c) 2017, Luca Ciciriello++All rights reserved.++Redistribution and use in source and binary forms, with or without+modification, are permitted provided that the following conditions are met:++ * Redistributions of source code must retain the above copyright+ notice, this list of conditions and the following disclaimer.++ * Redistributions in binary form must reproduce the above+ copyright notice, this list of conditions and the following+ disclaimer in the documentation and/or other materials provided+ with the distribution.++ * Neither the name of Luca Ciciriello nor the names of other+ contributors may be used to endorse or promote products derived+ from this software without specific prior written permission.++THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ soundgen.cabal view
@@ -0,0 +1,24 @@+-- Initial sound.cabal generated by cabal init. For further documentation,+-- see http://haskell.org/cabal/users-guide/++name: soundgen+version: 0.1.0.0+synopsis: sound generator+description: Simple tone generator. You can decide the tone frequency and duration+license: BSD3+license-file: LICENSE+author: Luca Ciciriello+maintainer: luca_ciciriello@hotmail.com+-- copyright: +category: Sound+build-type: Simple+extra-source-files: ChangeLog.md+cabal-version: >=1.10++executable sound+ main-is: Main.hs+ -- other-modules: + -- other-extensions: + build-depends: base >=4.5 && < 5.10, WAVE, split+ hs-source-dirs: src+ default-language: Haskell2010
+ src/Main.hs view
@@ -0,0 +1,31 @@+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 <frequency (Hz)> <duration (ms)>"