]> gitweb @ CieloNegro.org - wavpack.git/blob - Codec/Audio/WavPack/Unpack.hs
8d2790619f2f5440511b54a95b9c035cfd9256f7
[wavpack.git] / Codec / Audio / WavPack / Unpack.hs
1 {-# LANGUAGE
2     BangPatterns
3   , UnicodeSyntax
4   #-}
5 module Codec.Audio.WavPack.Unpack
6     (
7     )
8     where
9 import Codec.Audio.WavPack.Internal
10 import Data.Bits
11 import Data.Bitstream.Generic (Bitstream)
12 import qualified Data.Bitstream.Generic as B
13 import Data.Word
14
15 -- Read a single unsigned value from the specified bitstream with a
16 -- value from 0 to maxCode. If there are exactly a power of two number
17 -- of possible codes then this will read a fixed number of bits;
18 -- otherwise it reads the minimum number of bits and then determines
19 -- whether another bit is needed to define the code.
20 readCode ∷ Bitstream bs ⇒ bs → Word32 → (Word32, bs)
21 {-# INLINEABLE readCode #-}
22 readCode bs 0       = (0, bs)
23 readCode bs 1       = (b2n $ B.head bs, B.tail bs)
24 readCode bs maxCode
25     = let !bitCount = countBits maxCode
26           !extras   = (1 `shiftL` bitCount) - maxCode - 1
27       in
28         error "unk"