From: PHO Date: Tue, 4 Jan 2011 15:24:37 +0000 (+0900) Subject: slightly changed the type of findNextHeader X-Git-Url: http://git.cielonegro.org/gitweb.cgi?p=wavpack.git;a=commitdiff_plain;h=3468573980f7eabcd652bcff8c2f803ca4b944d6 slightly changed the type of findNextHeader --- diff --git a/Codec/Audio/WavPack/Block.hs b/Codec/Audio/WavPack/Block.hs index 0ca454a..ac3ef80 100644 --- a/Codec/Audio/WavPack/Block.hs +++ b/Codec/Audio/WavPack/Block.hs @@ -120,7 +120,7 @@ data BlockFlags -- | 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 @@ -234,19 +234,20 @@ decodeSamplingRate 0x0D = Just 96000 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' @@ -257,9 +258,8 @@ findNextHeader src -- Found the magic 'wvpk'. let bh = runGet get header in - (Just bh, rest) + Just (bh, rest) else findNextHeader src' - Just (_, src') → findNextHeader src' diff --git a/examples/WvInfo.hs b/examples/WvInfo.hs index 78588ab..4c5cf88 100644 --- a/examples/WvInfo.hs +++ b/examples/WvInfo.hs @@ -14,6 +14,7 @@ main = do [wvFile] ← getArgs 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."