--- This is an optimized version of 'getWord' that is used for lossless
--- only (error_limit ≡ 0). Also, rather than obtaining a single
--- sample, it can be used to obtain an entire buffer of either mono or
--- stereo samples.
---getWordsLossless ∷
+-- | This is an optimized version of 'getWord' that is used for
+-- lossless only ('edErrorLimit' ≡ 0). Also, rather than obtaining a
+-- single sample, it can be used to obtain an entire buffer of either
+-- mono or stereo samples.
+getWordsLossless ∷ ∀bs n v. (Bitstream bs, Integral n, GV.Vector v Int32)
+ ⇒ Bool -- ^ Is the stream monaural?
+ → WordsData
+ → bs -- ^ WV bitstream.
+ → n -- ^ Number of samples to get.
+ → (# WordsData, bs, v Int32 #)
+{-# INLINEABLE getWordsLossless #-}
+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
+ entropy ∷ EntropyData
+ entropy
+ | isMono = fst $ wdEntropyData w
+ | n `rem` 2 ≡ 0 = fst $ wdEntropyData w
+ | otherwise = snd $ wdEntropyData w