From: PHO Date: Thu, 14 Jul 2011 09:18:08 +0000 (+0900) Subject: working on getWordsLossless... X-Git-Url: http://git.cielonegro.org/gitweb.cgi?p=wavpack.git;a=commitdiff_plain;h=880fbc6589f134369f5a3cbbcfa140da32c9a71c working on getWordsLossless... --- diff --git a/Codec/Audio/WavPack/Words.hs b/Codec/Audio/WavPack/Words.hs index 36471e1..fb08b5e 100644 --- a/Codec/Audio/WavPack/Words.hs +++ b/Codec/Audio/WavPack/Words.hs @@ -17,6 +17,9 @@ import Data.Bitstream.Generic (Bitstream) import qualified Data.Bitstream.Generic as B import Data.Int import qualified Data.Vector.Generic as GV +import qualified Data.Vector.Generic.Mutable as MV +import Data.Vector.Generic.New (New) +import qualified Data.Vector.Generic.New as New import Data.Word import Prelude.Unicode @@ -45,14 +48,35 @@ getWordsLossless ∷ ∀bs n v. (Bitstream bs, Integral n, GV.Vector v Int32) → n -- ^ Number of samples to get. → (# WordsData, bs, v Int32 #) {-# INLINEABLE getWordsLossless #-} -getWordsLossless isMono w bs nSamples0 - = error "FIXME" +getWordsLossless isMono w0 bs0 nSamples0 + = let v0 = New.create $ MV.new $ fromIntegral nSamples + (# w1, bs1, n1, v1 #) + = go w0 bs0 0 v0 + v2 = GV.new $ New.take (fromIntegral n1) v1 + in + (# w1, bs1, v2 #) where nSamples ∷ n + {-# INLINE nSamples #-} nSamples = if isMono then nSamples0 else nSamples0 ⋅ 2 + go ∷ WordsData + → bs + → n + → New v Int32 + → (# WordsData, bs, n, New v Int32 #) + {-# INLINE go #-} + go w bs n v + | n ≥ nSamples = (# w, bs, n, v #) + | otherwise + = error "FIXME" + where + c ∷ EntropyData + c | n `rem` 2 ≡ 0 = fst $ wdEntropyData w + | otherwise = snd $ wdEntropyData w + -- | 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;