7 module Codec.Audio.WavPack.Words
11 import Codec.Audio.WavPack.Entropy
12 import Codec.Audio.WavPack.Internal
14 import Data.Bitstream.Generic (Bitstream)
15 import qualified Data.Bitstream.Generic as B
17 import Prelude.Unicode
22 wdBitrateDelta ∷ !(Word32, Word32)
23 , wdBitrateAcc ∷ !(Word32, Word32)
24 , wdPendingData ∷ !Word32
25 , wdHoldingOne ∷ !Word32
26 , wdZeroesAcc ∷ !Word32
27 , wdHoldingZero ∷ !Bool
28 , wdPendingCount ∷ !Int
29 , wdEntropyData ∷ !(EntropyData, EntropyData)
33 -- This is an optimized version of 'getWord' that is used for lossless
34 -- only (error_limit ≡ 0). Also, rather than obtaining a single
35 -- sample, it can be used to obtain an entire buffer of either mono or
39 -- Read a single unsigned value from the specified bitstream with a
40 -- value from 0 to maxCode. If there are exactly a power of two number
41 -- of possible codes then this will read a fixed number of bits;
42 -- otherwise it reads the minimum number of bits and then determines
43 -- whether another bit is needed to define the code.
44 readCode ∷ Bitstream bs ⇒ bs → Word32 → (# Word32, bs #)
45 {-# INLINEABLE readCode #-}
46 readCode bs 0 = (# 0, bs #)
47 readCode bs 1 = (# b2n (B.head bs), B.tail bs #)
49 = let !bitCount = countBits maxCode
50 !extras = bit bitCount - maxCode - 1
51 !code = B.toBits (B.take (bitCount - 1) bs)
52 (# code', bitCount' #)
53 = if code ≥ extras then
56 + b2n (bs B.!! bitCount)
59 (# code, bitCount - 1 #)
60 !bs' = B.drop bitCount' bs