+
+-- | Decorrelation samples
+data DecorrSamples
+ = DecorrSamples {
+ -- | The decorrelation sample vector stored in the metadata
+ -- as-is. Actual interpretation of the vector depends on the
+ -- number of channels and each corresponding decorrelation
+ -- terms.
+ decsVec ∷ !(UV.Vector Int32)
+ }
+ deriving (Eq, Show, Typeable)
+
+instance Metadata DecorrSamples where
+ metaID _ = 0x04
+ metaSize = fromIntegral ∘ (⋅ 2) ∘ UV.length ∘ decsVec
+
+instance Binary DecorrSamples where
+ put = UV.mapM_ (putWord16le ∘ fromIntegral ∘ log2s) ∘ decsVec
+ get = do n ← remaining
+ vec ← UV.replicateM (fromIntegral $ n `div` 2)
+ $ fmap (exp2s ∘ fromIntegral) getWord16le
+ return $ DecorrSamples vec
+
+-- | Median log2 values.
+data EntropyVars
+ = EntropyVars {
+ -- | Median log2 values for channel A, which always exists.
+ entVarA ∷ !(Word32, Word32, Word32)
+ -- | Median log2 values for channel B, which is absent when it's
+ -- mono.
+ , entVarB ∷ !(S.Maybe (Word32, Word32, Word32))
+ }
+ deriving (Eq, Show, Typeable)
+
+instance Metadata EntropyVars where
+ metaID _ = 0x05
+ metaSize ev
+ | S.isNothing $ entVarB ev = 6
+ | otherwise = 12
+
+instance Binary EntropyVars where
+ put ev
+ = do putMedians $ entVarA ev
+ case entVarB ev of
+ S.Nothing → return ()
+ S.Just medsB → putMedians medsB