Skip to content

Instantly share code, notes, and snippets.

@relrod
Last active August 29, 2015 14:01
Show Gist options
  • Save relrod/0bfc4945749aad3e41ed to your computer and use it in GitHub Desktop.
Save relrod/0bfc4945749aad3e41ed to your computer and use it in GitHub Desktop.
Haskell audio using Data.Binary.Put
dist
cabal-dev
*.o
*.hi
*.chi
*.chs.h
.virtualenv
.hsenv
.cabal-sandbox/
cabal.sandbox.config
cabal.config
foohask.wav
-- Initial audiosweep.cabal generated by cabal init. For further
-- documentation, see http://haskell.org/cabal/users-guide/
name: audiosweep
version: 0.1.0.0
synopsis: Audio sweep generator
-- description:
license: PublicDomain
license-file: LICENSE
author: Ricky Elrod
maintainer: [email protected]
-- copyright:
category: Sound
build-type: Simple
-- extra-source-files:
cabal-version: >=1.10
executable audiosweep
main-is: Main.hs
-- other-modules:
-- other-extensions:
build-depends: base >= 4 && < 5
, binary >= 0.7.1.0
, bytestring >= 0.10
-- hs-source-dirs:
default-language: Haskell2010
ghc-options: -Wall
No Copyright
The person who associated a work with this deed has dedicated the work to the
public domain by waiving all of his or her rights to the work worldwide under
copyright law, including all related and neighboring rights,
to the extent allowed by law.
You can copy, modify, distribute and perform the work, even for commercial
purposes, all without asking permission. See Other Information below.
Other Information:
* In no way are the patent or trademark rights of any person affected
by CC0, nor are the rights that other persons may have in the work or in
how the work is used, such as publicity or privacy rights.
* Unless expressly stated otherwise, the person who associated a work with
this deed makes no warranties about the work, and disclaims liability for
all uses of the work, to the fullest extent permitted by applicable law.
* When using or citing the work, you should not imply endorsement
by the author or the affirmer.
http://creativecommons.org/publicdomain/zero/1.0/legalcode
module Main where
import qualified Data.ByteString.Lazy as BL
import Data.Binary.Put
import Data.Word (Word8)
{-createSweep :: [Char]
createSweep =
map (chr . f) [0..65000]
where
f t = 128 + (floor $ 127 * (sin $ 2 * pi * (1 / 20) * t * (t / 8000)))
-}
createSweep' :: Put
createSweep' = mapM_ (putWord8 . f) $ takeWhile ((<= 2000) . (/ 20)) [0..]
where
f :: Double -> Word8
f t = 128 + (floor $ 127 * (sin $ 2 * pi * (1 / 20) * t * (t / 8000)))
main :: IO ()
main = BL.writeFile "foohask.wav" $ runPut createSweep'
import Distribution.Simple
main = defaultMain
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment