-- | maximum magnitude of decoded data (number of bits integers
-- require minus 1)
, bfMaxMagnitude ∷ !Word8
- -- | sampling rate (0x1111 = unknown/custom) (THINKME)
+ -- | sampling rate ('Nothing' = unknown/custom)
, bfSamplingRate ∷ !(Maybe Int)
-- | 'True' = use IIR for negative hybrid noise shaping
, bfIIRShaping ∷ !Bool
decodeSamplingRate 0x0E = Just 192000
decodeSamplingRate _ = Nothing
-findNextHeader ∷ L.ByteString → (Maybe BlockHeader, L.ByteString)
+-- | Find a WavPack header in a given stream. Returns 'Nothing' if no
+-- headers are found.
+findNextHeader ∷ L.ByteString -- ^ the input
+ → Maybe (BlockHeader, L.ByteString) -- ^ a header and the rest of input
findNextHeader src
= case L.uncons src of
Nothing
- → (Nothing, L.empty)
-
+ → Nothing
Just (119, src') -- 'w'
→ let (header, rest) = L.splitAt 32 src
in
case L.length header ≡ 32 of
False
- → (Nothing, L.empty)
-
+ → Nothing
True
→ let Just (magicW, header' ) = L.uncons header
Just (magicV, header'' ) = L.uncons header'
-- Found the magic 'wvpk'.
let bh = runGet get header
in
- (Just bh, rest)
+ Just (bh, rest)
else
findNextHeader src'
-
Just (_, src')
→ findNextHeader src'
showWvInfo ∷ L.ByteString → IO ()
showWvInfo stream
= case findNextHeader stream of
- (Just bh, _)
+ Just (bh, _)
→ print bh
- _ → fail "Can't find any WavPack block headers."
+ Nothing
+ → fail "Can't find any WavPack block headers."