]> gitweb @ CieloNegro.org - wavpack.git/commitdiff
BlockHeader
authorPHO <pho@cielonegro.org>
Mon, 3 Jan 2011 03:25:34 +0000 (12:25 +0900)
committerPHO <pho@cielonegro.org>
Mon, 3 Jan 2011 03:25:34 +0000 (12:25 +0900)
.gitignore
Codec/Audio/WavPack/Types.hs [new file with mode: 0644]
wavpack.cabal

index f76a6e2a7f7392f19b980e3631e4f9c62b79fae6..15068ebb8566c3b603450be5b0b3e0e238b245cf 100644 (file)
@@ -3,3 +3,5 @@
 
 Setup
 dist
+
+01.wv
diff --git a/Codec/Audio/WavPack/Types.hs b/Codec/Audio/WavPack/Types.hs
new file mode 100644 (file)
index 0000000..2e1446a
--- /dev/null
@@ -0,0 +1,81 @@
+{-# LANGUAGE
+    UnicodeSyntax
+  #-}
+module Codec.Audio.WavPack.Types
+    ( BlockHeader(..)
+    )
+    where
+import Data.Binary
+import Data.Binary.Get
+import Data.Binary.Put
+
+data BlockHeader
+    = BlockHeader {
+        bhSize         ∷ !Word32
+      , bhVersion      ∷ !Word16
+      , bhTrackNo      ∷ !Word8
+      , bhIndexNo      ∷ !Word8
+      , bhTotalSamples ∷ !Word32
+      , bhBlockIndex   ∷ !Word32
+      , bhBlockSamples ∷ !Word32
+      , bhFlags        ∷ !Word32
+      , bhCRC          ∷ !Word32
+      }
+    deriving (Show, Eq)
+
+instance Binary BlockHeader where
+    put bh
+        = do putWord8 119 -- 'w'
+             putWord8 118 -- 'v'
+             putWord8 112 -- 'p'
+             putWord8 107 -- 'k'
+             putWord32le $ bhSize         bh
+             putWord16le $ bhVersion      bh
+             putWord8    $ bhTrackNo      bh
+             putWord8    $ bhIndexNo      bh
+             putWord32le $ bhTotalSamples bh
+             putWord32le $ bhBlockIndex   bh
+             putWord32le $ bhBlockSamples bh
+             putWord32le $ bhFlags        bh
+             putWord32le $ bhCRC          bh
+
+    get = do skip 4 -- "wvpk"
+             size         ← getWord32le
+             version      ← getWord16le
+             trackNo      ← getWord8
+             indexNo      ← getWord8
+             totalSamples ← getWord32le
+             blockIndex   ← getWord32le
+             blockSamples ← getWord32le
+             flags        ← getWord32le
+             crc          ← getWord32le
+             return BlockHeader {
+                              bhSize         = size
+                            , bhVersion      = version
+                            , bhTrackNo      = trackNo
+                            , bhIndexNo      = indexNo
+                            , bhTotalSamples = totalSamples
+                            , bhBlockIndex   = blockIndex
+                            , bhBlockSamples = blockSamples
+                            , bhFlags        = flags
+                            , bhCRC          = crc
+                            }
+
+{-
+typedef struct {
+    char ckID [4];              // "wvpk"
+    uint32_t ckSize;            // size of entire block (minus 8, of course)
+    uint16_t version;           // 0x402 to 0x410 are currently valid for decode
+    uchar track_no;             // track number (0 if not used, like now)
+    uchar index_no;             // track sub-index (0 if not used, like now)
+    uint32_t total_samples;     // total samples for entire file, but this is
+                                // only valid if block_index == 0 and a value of
+                                // -1 indicates unknown length
+    uint32_t block_index;       // index of first sample in block relative to
+                                // beginning of file (normally this would start
+                                // at 0 for the first block)
+    uint32_t block_samples;     // number of samples in this block (0 = no audio)
+    uint32_t flags;             // various flags for id and decoding
+    uint32_t crc;               // crc for actual decoded data
+} WavpackHeader;
+-}
index bd32cfef927dcdb9cf514d19fbf80311dcf1857b..239e4e9dc998ad2078df084a1ff12929dac5f211 100644 (file)
@@ -24,10 +24,12 @@ Library
     Build-Depends:
         base                 == 4.*,
         base-unicode-symbols == 0.2.*,
-        binary               == 0.5.*
+        binary               == 0.5.*,
+        bytestring           == 0.9.*
 
     Exposed-Modules:
         Codec.Audio.WavPack
+        Codec.Audio.WavPack.Types
 
     GHC-Options:
         -Wall