a module for metadata sub-blocks
authorPHO <pho@cielonegro.org>
Tue, 4 Jan 2011 23:05:03 +0000 (08:05 +0900)
committerPHO <pho@cielonegro.org>
Tue, 4 Jan 2011 23:05:03 +0000 (08:05 +0900)
Codec/Audio/WavPack/Block.hs
Codec/Audio/WavPack/Metadata.hs [new file with mode: 0644]
wavpack.cabal

index db527064654a261705ac8a2e458323ecdf138943..fe3238163e3badbb9693f2eb5f9f6289f3dff280 100644 (file)
@@ -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 (file)
index 0000000..4f98703
--- /dev/null
@@ -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
index 11100bc8a0c92602fbc3a5fb34c4d0d66cf8246b..bc30b7721a7da901f415f9149a1e429ad0b35c65 100644 (file)
@@ -35,6 +35,7 @@ Library
     Exposed-Modules:
         Codec.Audio.WavPack
         Codec.Audio.WavPack.Block
+        Codec.Audio.WavPack.Metadata
 
     GHC-Options:
         -Wall