X-Git-Url: http://git.cielonegro.org/gitweb.cgi?p=wavpack.git;a=blobdiff_plain;f=Codec%2FAudio%2FWavPack%2FMetadata.hs;h=77901f445aedf505ab7e4ce117ae026ebdd147c7;hp=78a99fc5e232dd7e168c971d30d1209a80cd92de;hb=9128d47e1f753b82477535a1116b3a4f416243fc;hpb=e4b72f263a4fc1404ede73b8bbe62ce4e7e2209a diff --git a/Codec/Audio/WavPack/Metadata.hs b/Codec/Audio/WavPack/Metadata.hs index 78a99fc..77901f4 100644 --- a/Codec/Audio/WavPack/Metadata.hs +++ b/Codec/Audio/WavPack/Metadata.hs @@ -23,9 +23,11 @@ import Prelude.Unicode -- | Type class for every metadata sub-blocks. class (Binary α, Eq α, Show α, Typeable α) ⇒ Metadata α where - -- | Get the metadata ID (mandatory). + -- | Get the metadata ID without odd-size bit nor large-block bit + -- (mandatory). metaID ∷ α → Word8 - -- | Get the size of metadata (optional). + -- | Get the size of metadata, excluding the metadata header + -- (optional). metaSize ∷ α → Word32 metaSize = fromIntegral ∘ L.length ∘ runPut ∘ put -- | Cast a 'SubBlock' to this type of metadata (optional). @@ -48,18 +50,19 @@ instance Metadata SubBlock where instance Binary SubBlock where put (SubBlock a) = let size = metaSize a - oddBit = if odd size then 0x40 else 0 - largeBit = if size > 255 then 0x80 else 0 + size' = size + 1 + oddBit = if odd size then 0x40 else 0 + largeBit = if size > 0x1FE then 0x80 else 0 idWord = metaID a .|. oddBit .|. largeBit in do putWord8 idWord - if size > 255 then + if size > 0x1FE then -- Don't forget about the endianness. - do putWord8 $ fromIntegral $ (size `shiftR` 1) .&. 0xFF - putWord8 $ fromIntegral $ (size `shiftR` 9) .&. 0xFF - putWord8 $ fromIntegral $ (size `shiftR` 17) .&. 0xFF + do putWord8 $ fromIntegral $ (size' `shiftR` 1) .&. 0xFF + putWord8 $ fromIntegral $ (size' `shiftR` 9) .&. 0xFF + putWord8 $ fromIntegral $ (size' `shiftR` 17) .&. 0xFF else - putWord8 $ fromIntegral $ (size `shiftR` 1) .&. 0xFF + putWord8 $ fromIntegral $ (size' `shiftR` 1) .&. 0xFF put a when (odd size) $ putWord8 0 @@ -117,7 +120,8 @@ instance Binary Dummy where -- | Unknown but optional metadata found in the WavPack block. data Unknown = Unknown { - -- | The ID of this unknown metadata. + -- | The ID of this unknown metadata without odd-size bit nor + -- large-block bit. unkID ∷ Word8 -- | Raw data; must be less than 2^25 bytes long. , unkData ∷ L.ByteString