]> gitweb @ CieloNegro.org - wavpack.git/blobdiff - Codec/Audio/WavPack/Block.hs
readBlocks
[wavpack.git] / Codec / Audio / WavPack / Block.hs
index 7879cf1147f584164061b747d69ce9770a0d93f7..4ecdb7d8d40e5530f6e8e8846d8ef776320a104a 100644 (file)
@@ -9,7 +9,7 @@ module Codec.Audio.WavPack.Block
     , BlockHeader(..)
     , BlockFlags(..)
 
-    , findNextBlock
+    , readBlocks
     )
     where
 import Codec.Audio.WavPack.Metadata
@@ -17,8 +17,8 @@ import Data.Binary
 import Data.Binary.BitPut (putBit, putNBits, runBitPut)
 import Data.Binary.Get
 import Data.Binary.Put
-import qualified Data.Binary.Strict.BitGet as BG
 import Data.Binary.Strict.BitGet (getBit, getAsWord8, runBitGet)
+import qualified Data.Binary.Strict.BitGet as BG
 import qualified Data.ByteString as S
 import qualified Data.ByteString.Lazy as L
 import qualified Data.Strict as S
@@ -286,10 +286,17 @@ decodeSamplingRate 0x0D = S.Just  96000
 decodeSamplingRate 0x0E = S.Just 192000
 decodeSamplingRate    _ =     S.Nothing
 
--- | Find a WavPack block in a given stream. Returns 'S.Nothing' if no
--- blocks are found.
-findNextBlock ∷ L.ByteString -- ^ the input
-              → (# S.Maybe Block, L.ByteString #) -- ^ the rest of input
+-- | Read WavPack blocks in a given stream lazily.
+readBlocks ∷ L.ByteString → [Block]
+readBlocks src
+    = case findNextBlock src of
+        (# S.Just block, src' #)
+            → block : readBlocks src'
+        (# S.Nothing, _ #)
+            → []
+
+findNextBlock ∷ L.ByteString
+              → (# S.Maybe Block, L.ByteString #)
 findNextBlock src
     = case L.uncons src of
         Nothing