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