From: PHO Date: Tue, 4 Jan 2011 23:05:03 +0000 (+0900) Subject: a module for metadata sub-blocks X-Git-Url: https://git.cielonegro.org/gitweb.cgi?a=commitdiff_plain;h=44ad26d5207bc8b48892030345df73e208479db4;p=wavpack.git a module for metadata sub-blocks --- diff --git a/Codec/Audio/WavPack/Block.hs b/Codec/Audio/WavPack/Block.hs index db52706..fe32381 100644 --- a/Codec/Audio/WavPack/Block.hs +++ b/Codec/Audio/WavPack/Block.hs @@ -1,7 +1,7 @@ {-# LANGUAGE UnicodeSyntax #-} --- | Data types for WavPack codec. +-- | WavPack blocks module Codec.Audio.WavPack.Block ( BlockHeader(..) , BlockFlags(..) diff --git a/Codec/Audio/WavPack/Metadata.hs b/Codec/Audio/WavPack/Metadata.hs new file mode 100644 index 0000000..4f98703 --- /dev/null +++ b/Codec/Audio/WavPack/Metadata.hs @@ -0,0 +1,44 @@ +{-# LANGUAGE + ExistentialQuantification + , UnicodeSyntax + #-} +-- | WavPack metadata sub-blocks +module Codec.Audio.WavPack.Metadata + ( Metadata(..) + , SomeMetadata(..) + ) + where +import Data.Binary +import Data.Binary.Put +import Data.Bits +import qualified Data.ByteString.Lazy as L +import Data.Typeable +import Prelude.Unicode + +class (Binary α, Eq α, Show α, Typeable α) ⇒ Metadata α where + metaID ∷ α → Word8 + metaSize ∷ α → Word32 + + metaSize = fromIntegral ∘ L.length ∘ runPut ∘ put + +data SomeMetadata = ∀α. Metadata α ⇒ SomeMetadata α + +instance Binary SomeMetadata where + put (SomeMetadata a) + = let size = metaSize a + oddBit = if odd size then 0x40 else 0 + largeBit = if size > 255 then 0x80 else 0 + idWord = metaID a .|. oddBit .|. largeBit + in + do putWord8 idWord + fail "FIXME" + + get = fail "FIXME" + +instance Eq SomeMetadata where + (SomeMetadata a) == (SomeMetadata b) + = Just a ≡ cast b + +instance Show SomeMetadata where + show (SomeMetadata a) + = show a diff --git a/wavpack.cabal b/wavpack.cabal index 11100bc..bc30b77 100644 --- a/wavpack.cabal +++ b/wavpack.cabal @@ -35,6 +35,7 @@ Library Exposed-Modules: Codec.Audio.WavPack Codec.Audio.WavPack.Block + Codec.Audio.WavPack.Metadata GHC-Options: -Wall