From 5f113a044d1a17a7313124802b58c91819bc54eb Mon Sep 17 00:00:00 2001 From: PHO Date: Sun, 10 Jul 2011 17:49:01 +0900 Subject: [PATCH] some data types --- Codec/Audio/WavPack/Entropy.hs | 21 ++++++++++++ Codec/Audio/WavPack/Unpack.hs | 36 -------------------- Codec/Audio/WavPack/Words.hs | 62 ++++++++++++++++++++++++++++++++++ wavpack.cabal | 2 ++ 4 files changed, 85 insertions(+), 36 deletions(-) create mode 100644 Codec/Audio/WavPack/Entropy.hs create mode 100644 Codec/Audio/WavPack/Words.hs diff --git a/Codec/Audio/WavPack/Entropy.hs b/Codec/Audio/WavPack/Entropy.hs new file mode 100644 index 0000000..444fc17 --- /dev/null +++ b/Codec/Audio/WavPack/Entropy.hs @@ -0,0 +1,21 @@ +{-# LANGUAGE + UnicodeSyntax + #-} +-- | FIXME +module Codec.Audio.WavPack.Entropy + ( EntropyData(..) + ) + where +import Data.Word + +-- | FIXME +data EntropyData + = EntropyData { + -- | Median log2 values for a channel. + edMedian ∷ !(Word32, Word32, Word32) + -- | FIXME + , edSlowLevel ∷ !Word32 + -- | FIXME + , edErrorLimit ∷ !Word32 + } + deriving (Eq, Show) diff --git a/Codec/Audio/WavPack/Unpack.hs b/Codec/Audio/WavPack/Unpack.hs index f816657..264072c 100644 --- a/Codec/Audio/WavPack/Unpack.hs +++ b/Codec/Audio/WavPack/Unpack.hs @@ -1,40 +1,4 @@ -{-# LANGUAGE - BangPatterns - , UnboxedTuples - , 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 -import Prelude.Unicode - --- 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 = bit bitCount - maxCode - 1 - !code = B.toBits (B.take (bitCount - 1) bs) - (# code', bitCount' #) - = if code ≥ extras then - (# (code `shiftL` 1) - - extras - + b2n (bs B.!! bitCount) - , bitCount #) - else - (# code, bitCount - 1 #) - !bs' = B.drop bitCount' bs - in - (# code', bs' #) diff --git a/Codec/Audio/WavPack/Words.hs b/Codec/Audio/WavPack/Words.hs new file mode 100644 index 0000000..0923547 --- /dev/null +++ b/Codec/Audio/WavPack/Words.hs @@ -0,0 +1,62 @@ +{-# LANGUAGE + BangPatterns + , UnboxedTuples + , UnicodeSyntax + #-} +-- | FIXME +module Codec.Audio.WavPack.Words + ( WordsData(..) + ) + where +import Codec.Audio.WavPack.Entropy +import Codec.Audio.WavPack.Internal +import Data.Bits +import Data.Bitstream.Generic (Bitstream) +import qualified Data.Bitstream.Generic as B +import Data.Word +import Prelude.Unicode + +-- | FIXME +data WordsData + = WordsData { + wdBitrateDelta ∷ !(Word32, Word32) + , wdBitrateAcc ∷ !(Word32, Word32) + , wdPendingData ∷ !Word32 + , wdHoldingOne ∷ !Word32 + , wdZeroesAcc ∷ !Word32 + , wdHoldingZero ∷ !Bool + , wdPendingCount ∷ !Int + , wdEntropyData ∷ !(EntropyData, EntropyData) + } + deriving (Eq, Show) + +-- 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 ∷ + +-- 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 = bit bitCount - maxCode - 1 + !code = B.toBits (B.take (bitCount - 1) bs) + (# code', bitCount' #) + = if code ≥ extras then + (# (code `shiftL` 1) + - extras + + b2n (bs B.!! bitCount) + , bitCount #) + else + (# code, bitCount - 1 #) + !bs' = B.drop bitCount' bs + in + (# code', bs' #) diff --git a/wavpack.cabal b/wavpack.cabal index e635c8f..c4eb301 100644 --- a/wavpack.cabal +++ b/wavpack.cabal @@ -44,8 +44,10 @@ Library Codec.Audio.WavPack Codec.Audio.WavPack.Block Codec.Audio.WavPack.Decorrelation + Codec.Audio.WavPack.Entropy Codec.Audio.WavPack.Internal Codec.Audio.WavPack.Metadata + Codec.Audio.WavPack.Words Codec.Audio.WavPack.Unpack GHC-Options: -- 2.40.0