]> gitweb @ CieloNegro.org - wavpack.git/blob - Codec/Audio/WavPack/Types.hs
haddock comments
[wavpack.git] / Codec / Audio / WavPack / Types.hs
1 {-# LANGUAGE
2     UnicodeSyntax
3   #-}
4 -- | Data types for WavPack codec.
5 module Codec.Audio.WavPack.Types
6     ( BlockHeader(..)
7     )
8     where
9 import Data.Binary
10 import Data.Binary.Get
11 import Data.Binary.Put
12
13 -- | The preamble to every block in both the .wv and .wvc files.
14 data BlockHeader
15     = BlockHeader {
16       -- | size of entire block (minus 8, of course)
17         bhSize         ∷ !Word32
18       -- | 0x402 to 0x410 are currently valid for decode
19       , bhVersion      ∷ !Word16
20       -- | track number (0 if not used, like now)
21       , bhTrackNo      ∷ !Word8
22       -- | track sub-index (0 if not used, like now)
23       , bhIndexNo      ∷ !Word8
24       -- | total samples for entire file, but this is only valid if
25       -- 'bhBlockIndex' == 0 and a value of -1 indicates unknown length
26       , bhTotalSamples ∷ !Word32
27       -- | index of first sample in block relative to beginning of
28       -- file (normally this would start at 0 for the first block)
29       , bhBlockIndex   ∷ !Word32
30       -- | number of samples in this block (0 = no audio)
31       , bhBlockSamples ∷ !Word32
32       -- | various flags for id and decoding
33       , bhFlags        ∷ !Word32
34       -- | crc for actual decoded data
35       , bhCRC          ∷ !Word32
36       }
37     deriving (Show, Eq)
38
39 instance Binary BlockHeader where
40     put bh
41         = do putWord8 119 -- 'w'
42              putWord8 118 -- 'v'
43              putWord8 112 -- 'p'
44              putWord8 107 -- 'k'
45              putWord32le $ bhSize         bh
46              putWord16le $ bhVersion      bh
47              putWord8    $ bhTrackNo      bh
48              putWord8    $ bhIndexNo      bh
49              putWord32le $ bhTotalSamples bh
50              putWord32le $ bhBlockIndex   bh
51              putWord32le $ bhBlockSamples bh
52              putWord32le $ bhFlags        bh
53              putWord32le $ bhCRC          bh
54
55     get = do skip 4 -- "wvpk"
56              size         ← getWord32le
57              version      ← getWord16le
58              trackNo      ← getWord8
59              indexNo      ← getWord8
60              totalSamples ← getWord32le
61              blockIndex   ← getWord32le
62              blockSamples ← getWord32le
63              flags        ← getWord32le
64              crc          ← getWord32le
65              return BlockHeader {
66                               bhSize         = size
67                             , bhVersion      = version
68                             , bhTrackNo      = trackNo
69                             , bhIndexNo      = indexNo
70                             , bhTotalSamples = totalSamples
71                             , bhBlockIndex   = blockIndex
72                             , bhBlockSamples = blockSamples
73                             , bhFlags        = flags
74                             , bhCRC          = crc
75                             }