]> gitweb @ CieloNegro.org - wavpack.git/commitdiff
slightly changed the type of findNextHeader
authorPHO <pho@cielonegro.org>
Tue, 4 Jan 2011 15:24:37 +0000 (00:24 +0900)
committerPHO <pho@cielonegro.org>
Tue, 4 Jan 2011 15:24:37 +0000 (00:24 +0900)
Codec/Audio/WavPack/Block.hs
examples/WvInfo.hs

index 0ca454ada59fb2b3f224655d73d3817baabbd698..ac3ef802dd663c6f427e2b4cad6efbcf548533ed 100644 (file)
@@ -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'
index 78588ab29d3e3f6e5cdf12f09f3a9124eacc824f..4c5cf88cf6b6c895021382b9617459467faae16a 100644 (file)
@@ -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."