soxlib 0.0.1.1 → 0.0.1.2
raw patch · 3 files changed
+78/−4 lines, 3 filesdep +soxlibdep ~storablevectornew-component:exe:soxlib-demo
Dependencies added: soxlib
Dependency ranges changed: storablevector
Files
- demo/Demo.hs +54/−0
- soxlib.cabal +19/−4
- src/Sound/SoxLib.hs +5/−0
+ demo/Demo.hs view
@@ -0,0 +1,54 @@+module Main where++import qualified Sound.SoxLib as SoxLib++import qualified Data.StorableVector as SV+import Foreign.Storable (peek, )+++writerInfo :: Int -> SoxLib.WriterInfo+writerInfo numChans =+ SoxLib.defaultWriterInfo {+ SoxLib.writerSignalInfo = Just $+ SoxLib.defaultSignalInfo {+ SoxLib.rate = Just 44100,+ SoxLib.channels = Just numChans,+ SoxLib.precision = Just 16+ }+ }++writeMono :: FilePath -> IO ()+writeMono filename =+ SoxLib.withWrite (writerInfo 1) filename $ \fmt ->+ let chunk = SV.iterateN 256 (128*256*256+) 0+ in do SoxLib.writeStorableVector fmt chunk+ SoxLib.writeStorableVector fmt (SV.reverse chunk)++writeStereo :: FilePath -> IO ()+writeStereo filename =+ SoxLib.withWrite (writerInfo 2) filename $ \fmt ->+ let chunk = SV.iterateN 256 (128*256*256+) 0+ in SoxLib.writeStorableVector fmt $+ SV.interleave [chunk, SV.reverse chunk]++readInfo :: FilePath -> IO ()+readInfo filename =+ SoxLib.withRead SoxLib.defaultReaderInfo filename $ \fmtPtr -> do+ fmt <- peek fmtPtr+ print $ SoxLib.encodingInfo fmt+ let si = SoxLib.signalInfo fmt+ print si+ case SoxLib.length si of+ Nothing -> putStrLn "unknown length"+ Just n ->+ print . SV.map (flip div (256*256*256)) =<<+ SoxLib.readStorableVector fmtPtr n++main :: IO ()+main = SoxLib.formatWith $ do+ let monoName = "mono.wav"+ let stereoName = "stereo.wav"+ writeMono monoName+ writeStereo stereoName+ readInfo monoName+ readInfo stereoName
soxlib.cabal view
@@ -1,5 +1,5 @@ Name: soxlib-Version: 0.0.1.1+Version: 0.0.1.2 License: BSD3 License-File: LICENSE Author: Henning Thielemann <haskell@henning-thielemann.de>@@ -16,13 +16,13 @@ The package @sox@ has similar functionality but calls the @sox@ shell command. Tested-With: GHC==6.12.3, GHC==7.4.1-Cabal-Version: >=1.6+Cabal-Version: >=1.8 Build-Type: Simple Extra-Source-Files: src/Sound/SoxLib/Template.h Source-Repository this- Tag: 0.0.1.1+ Tag: 0.0.1.2 Type: darcs Location: http://code.haskell.org/~thielema/soxlib/ @@ -30,10 +30,14 @@ Type: darcs Location: http://code.haskell.org/~thielema/soxlib/ +Flag buildExamples+ description: Build example executables+ default: False+ Library Build-Depends: sample-frame >=0.0.1 && <0.1,- storablevector >=0.2.7 && <0.3,+ storablevector >=0.2.10 && <0.3, explicit-exception >=0.1.3 && < 0.2, -- that's the way to get compatibility between GHC 6.10 and 6.12 extensible-exceptions >=0.1.1 && <0.2,@@ -52,3 +56,14 @@ Sound.SoxLib.FFI PkgConfig-Depends: sox >=14.3 && <14.4++Executable soxlib-demo+ Main-Is: demo/Demo.hs+ If flag(buildExamples)+ Build-Depends:+ soxlib,+ storablevector,+ base >=4 && <5+ Else+ Buildable: False+ GHC-Options: -Wall
src/Sound/SoxLib.hs view
@@ -39,9 +39,14 @@ import Data.Int (Int32, ) +{-# DEPRECATED with "I found no documentation for it and thus think that it is deprecated. Use formatWith instead." #-} with :: IO a -> IO a with = bracket_ FFI.init FFI.quit +{- |+All SoxLib operations must be enclosed in 'formatWith'.+You must only call it once per program.+-} formatWith :: IO a -> IO a formatWith = bracket_ FFI.formatInit FFI.formatQuit