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
→ 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;