]> gitweb @ CieloNegro.org - wavpack.git/blob - examples/WvInfo.hs
WVBitstream
[wavpack.git] / examples / WvInfo.hs
1 {-# LANGUAGE
2     UnboxedTuples
3   , UnicodeSyntax
4   #-}
5 module Main where
6 import Codec.Audio.WavPack.Block
7 import Codec.Audio.WavPack.Metadata
8 import qualified Data.ByteString.Lazy as L
9 import qualified Data.Strict as S
10 import Data.Maybe
11 import Prelude.Unicode
12 import System.Environment
13 import System.IO
14
15 main ∷ IO ()
16 main = do [wvFile] ← getArgs
17           wvData   ← L.readFile wvFile
18           hSetBuffering stdout NoBuffering
19           showWvInfo wvData
20
21 showWvInfo ∷ L.ByteString → IO ()
22 showWvInfo stream
23     = case findNextBlock stream of
24         (# S.Just block, _ #)
25             → printBlock block
26         (# S.Nothing   , _ #)
27             → fail "Can't find any WavPack block headers."
28
29 printBlock ∷ Block → IO ()
30 printBlock b
31     = do putStrLn "- Block header:"
32          print $ blockHeader b
33          putStrLn "- Block metadata sub-blocks:"
34          mapM_ printSub $ blockMetadata b
35     where
36       printSub ∷ SubBlock → IO ()
37       printSub sub
38           | isJust (fromSubBlock sub ∷ Maybe WVBitstream)
39               = putStrLn ( "(WV Bitstream omitted: " ⧺
40                            show (metaSize sub) ⧺
41                            " bytes)"
42                          )
43           | otherwise
44               = print sub