sox 0.0.1 → 0.1
raw patch · 9 files changed
+60/−111 lines, 9 filesdep +sample-framedep +special-functors
Dependencies added: sample-frame, special-functors
Files
- sox.cabal +8/−4
- src/Sound/Sox/Convert.hs +1/−1
- src/Sound/Sox/Format.hs +14/−7
- src/Sound/Sox/Frame.hs +31/−15
- src/Sound/Sox/Frame/Stereo.hs +3/−39
- src/Sound/Sox/Play.hs +1/−1
- src/Sound/Sox/Signal/List.hs +1/−0
- src/Sound/Sox/StorableUtility.hs +0/−43
- src/Sound/Sox/Write.hs +1/−1
sox.cabal view
@@ -1,5 +1,5 @@ Name: sox-Version: 0.0.1+Version: 0.1 License: GPL License-File: LICENSE Author: Henning Thielemann <haskell@henning-thielemann.de>@@ -35,11 +35,14 @@ description: Choose the new smaller, split-up base package. Flag executeShell- description: use ShellPipe package instead of process, preserved for historical reasons+ description:+ Use ShellPipe package instead of process, preserved for historical reasons.+ Files are available in the darcs repository but currently not in the cabal package. default: False Library Build-Depends:+ sample-frame >= 0.0.1 && <0.1, explicit-exception >= 0.1.3 && < 0.2, transformers >= 0.0.1 && <0.2 If flag(splitBase)@@ -48,7 +51,9 @@ process >= 1.0 && < 1.1, containers >= 0.1 && <0.3 Else- Build-Depends: base >= 1.0 && < 2+ Build-Depends:+ special-functors >= 1.0 && <1.1,+ base >= 1.0 && < 2 Hs-Source-Dirs: src If os(windows)@@ -74,5 +79,4 @@ Sound.Sox.Private.Arguments Sound.Sox.Private.Format -- Sound.Sox.Private.Information- Sound.Sox.StorableUtility Sound.Sox.System
src/Sound/Sox/Convert.hs view
@@ -13,7 +13,7 @@ {- | > :load Sound.Sox.Convert >-> generic Option.none "test.aiff" Option.none "test.wav"+> simple Option.none "test.aiff" Option.none "test.wav" -} simple :: Option.T {- ^ source options -} ->
src/Sound/Sox/Format.hs view
@@ -24,15 +24,22 @@ iff8svx :: T iff8svx = custom "8svx" +muLaw :: T+muLaw = custom "ul" + signedByte, unsignedByte :: T-signedByte = custom "sb"-unsignedByte = custom "ub"+signedByte = custom "s8"+unsignedByte = custom "u8" signedWord, unsignedWord :: T-signedWord = custom "sw"-unsignedWord = custom "uw"+signedWord = custom "s16"+unsignedWord = custom "u16" -signedLong {-, unsignedLong-} :: T-signedLong = custom "sl"--- unsignedLong = custom "ul"+signedLong, unsignedLong :: T+signedLong = custom "s32"+unsignedLong = custom "u32"++ieeeSinglePrecision, ieeeDoublePrecision :: T+ieeeSinglePrecision = custom "f32"+ieeeDoublePrecision = custom "f64"
src/Sound/Sox/Frame.hs view
@@ -1,42 +1,58 @@-module Sound.Sox.Frame where+module Sound.Sox.Frame (C(..), Frame.withSignal, Frame.numberOfChannels, ) where +import qualified Sound.Frame as Frame+import qualified Sound.Frame.Stereo as Stereo+import qualified Sound.Frame.MuLaw as MuLaw+ import qualified Sound.Sox.Format as Format -import Data.Word (Word8, Word16, )+import Data.Word (Word8, Word16, Word32, ) import Data.Int (Int8, Int16, Int32, ) -class C y where- {- | The argument is not touched and can be undefined -}- numberOfChannels :: y -> Int+class Frame.C y => C y where format :: y -> Format.T + instance C Word8 where- numberOfChannels _ = 1 format _ = Format.unsignedByte instance C Int8 where- numberOfChannels _ = 1 format _ = Format.signedByte instance C Word16 where- numberOfChannels _ = 1 format _ = Format.unsignedWord instance C Int16 where- numberOfChannels _ = 1 format _ = Format.signedWord -{- instance C Word32 where- numberOfChannels _ = 1 format _ = Format.unsignedLong--} instance C Int32 where- numberOfChannels _ = 1 format _ = Format.signedLong +{- |+The floating point instances are dangerous,+because Storable Float may not use IEEE format+that sox uses according to its man page.+This is strange since sox uses the host's endianess for multi-byte values.+So, why does it not use the machine's floating point format?+-}+instance C Float where+ format _ = Format.ieeeSinglePrecision -withSignal :: (y -> a) -> (sig y -> a)-withSignal f _ = f undefined+instance C Double where+ format _ = Format.ieeeDoublePrecision++instance C MuLaw.T where+ format _ = Format.muLaw++{-+Shall we add instances for Float and Double?+Sox requires floating point numbers in IEEE formats,+but we cannot warrant that the Storable instances uses those formats.+-}++instance C a => C (Stereo.T a) where+ format y = format (Stereo.left y)
src/Sound/Sox/Frame/Stereo.hs view
@@ -1,42 +1,6 @@-{--This data type can be used as sample type for stereo signals.+{- |+We just re-export the type from sample-frame:Sound.Frame.Stereo. -} module Sound.Sox.Frame.Stereo (T, left, right, cons, ) where -import qualified Sound.Sox.Frame as Frame--import Control.Monad (liftM2, )--import Foreign.Storable (Storable (..), )-import qualified Sound.Sox.StorableUtility as Store---data T a = Cons {left, right :: !a}---{-# INLINE cons #-}-cons :: a -> a -> T a-cons = Cons--instance Functor T where- {-# INLINE fmap #-}- fmap f (Cons l r) = Cons (f l) (f r)----- cf. StorableInstances-instance (Storable a) => Storable (T a) where- sizeOf y = Store.sizeOfArray 2 $ left y- alignment y = alignment $ left y- peek ptr =- Store.run ptr $- liftM2 Cons- Store.peekNext- Store.peekNext- poke ptr (Cons l r) =- Store.run ptr $- do Store.pokeNext l- Store.pokeNext r--instance Frame.C a => Frame.C (T a) where- numberOfChannels y = 2 * Frame.numberOfChannels (left y)- format y = Frame.format (left y)+import Sound.Frame.Stereo
src/Sound/Sox/Play.hs view
@@ -18,7 +18,7 @@ {- | > :load Sound.Sox.Play Sound.Sox.Signal.List >-> generic Sound.Sox.Signal.List.put Option.none 11025 (iterate (1000+) (0::Data.Int.Int16))+> simple Sound.Sox.Signal.List.put Option.none 11025 (iterate (1000+) (0::Data.Int.Int16)) -} simple :: (Frame.C y) =>
src/Sound/Sox/Signal/List.hs view
@@ -66,6 +66,7 @@ getContents h = alloca $ \p ->+-- Async.eatNothingT $ liftM (\(Async.Exceptional (Just e) a) -> Async.Exceptional e a) $ Async.manySynchronousT unsafeInterleaveIO
− src/Sound/Sox/StorableUtility.hs
@@ -1,43 +0,0 @@-{- |-support for Storable instances--Cf. synthesizer package--}-module Sound.Sox.StorableUtility where--import Control.Monad.Trans.State (StateT, evalStateT, get, put, )-import Control.Monad.Trans (lift, )--import Foreign.Ptr (Ptr, castPtr, )-import Foreign.Storable (Storable(..))-import Foreign.Marshal.Array (advancePtr, )---{-# INLINE roundUp #-}-roundUp :: Int -> Int -> Int-roundUp m x = x + mod (-x) m--{-# INLINE sizeOfArray #-}-sizeOfArray :: Storable a => Int -> a -> Int-sizeOfArray n x =- n * roundUp (alignment x) (sizeOf x)--{-# INLINE pokeNext #-}-pokeNext :: (Storable a) => a -> StateT (Ptr a) IO ()-pokeNext x =- do ptr <- get- lift $ poke ptr x- put (ptr `advancePtr` 1)--- put (ptr `plusPtr` size x + div (- size x) (alignment x))--{-# INLINE peekNext #-}-peekNext :: (Storable a) => StateT (Ptr a) IO a-peekNext =- do ptr <- get- a <- lift $ peek ptr- put (ptr `advancePtr` 1)- return a--run :: Ptr (t a) -> StateT (Ptr a) IO c -> IO c-run ptr act =- evalStateT act (castPtr ptr)
src/Sound/Sox/Write.hs view
@@ -21,7 +21,7 @@ > :load Sound.Sox.Write Sound.Sox.Signal.List >-> generic Sound.Sox.Signal.List.put Option.none "test.aiff" 11025 (take 100 $ iterate (1000+) (0::Data.Int.Int16))+> simple Sound.Sox.Signal.List.put Option.none "test.aiff" 11025 (take 100 $ iterate (1000+) (0::Data.Int.Int16)) -} simple :: (Frame.C y) =>