{-# LANGUAGE UnicodeSyntax #-} -- | Data types for WavPack codec. module Codec.Audio.WavPack.Types ( BlockHeader(..) ) where import Data.Binary import Data.Binary.Get import Data.Binary.Put -- | The preamble to every block in both the .wv and .wvc files. data BlockHeader = BlockHeader { -- | size of entire block (minus 8, of course) bhSize ∷ !Word32 -- | 0x402 to 0x410 are currently valid for decode , bhVersion ∷ !Word16 -- | track number (0 if not used, like now) , bhTrackNo ∷ !Word8 -- | track sub-index (0 if not used, like now) , bhIndexNo ∷ !Word8 -- | total samples for entire file, but this is only valid if -- 'bhBlockIndex' == 0 and a value of -1 indicates unknown length , bhTotalSamples ∷ !Word32 -- | index of first sample in block relative to beginning of -- file (normally this would start at 0 for the first block) , bhBlockIndex ∷ !Word32 -- | number of samples in this block (0 = no audio) , bhBlockSamples ∷ !Word32 -- | various flags for id and decoding , bhFlags ∷ !Word32 -- | crc for actual decoded data , 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 }