]> gitweb @ CieloNegro.org - wavpack.git/blobdiff - Codec/Audio/WavPack/Unpack.hs
started implementing readCode
[wavpack.git] / Codec / Audio / WavPack / Unpack.hs
diff --git a/Codec/Audio/WavPack/Unpack.hs b/Codec/Audio/WavPack/Unpack.hs
new file mode 100644 (file)
index 0000000..8d27906
--- /dev/null
@@ -0,0 +1,28 @@
+{-# LANGUAGE
+    BangPatterns
+  , UnicodeSyntax
+  #-}
+module Codec.Audio.WavPack.Unpack
+    (
+    )
+    where
+import Codec.Audio.WavPack.Internal
+import Data.Bits
+import Data.Bitstream.Generic (Bitstream)
+import qualified Data.Bitstream.Generic as B
+import Data.Word
+
+-- Read a single unsigned value from the specified bitstream with a
+-- value from 0 to maxCode. If there are exactly a power of two number
+-- of possible codes then this will read a fixed number of bits;
+-- otherwise it reads the minimum number of bits and then determines
+-- whether another bit is needed to define the code.
+readCode ∷ Bitstream bs ⇒ bs → Word32 → (Word32, bs)
+{-# INLINEABLE readCode #-}
+readCode bs 0       = (0, bs)
+readCode bs 1       = (b2n $ B.head bs, B.tail bs)
+readCode bs maxCode
+    = let !bitCount = countBits maxCode
+          !extras   = (1 `shiftL` bitCount) - maxCode - 1
+      in
+        error "unk"
\ No newline at end of file