]> gitweb @ CieloNegro.org - wavpack.git/blob - examples/WvInfo.hs
Hey... getWordsLossless is done... Not tested at all...... Hope it works... or......
[wavpack.git] / examples / WvInfo.hs
1 {-# LANGUAGE
2     UnicodeSyntax
3   #-}
4 module Main where
5 import Codec.Audio.WavPack.Block
6 import Codec.Audio.WavPack.Metadata
7 import qualified Data.ByteString.Lazy as L
8 import Data.Maybe
9 import Prelude.Unicode
10 import System.Environment
11 import System.IO
12
13 main ∷ IO ()
14 main = do [wvFile] ← getArgs
15           wvData   ← L.readFile wvFile
16           hSetBuffering stdout NoBuffering
17           mapM_ printBlock $ readBlocks wvData
18           putStrLn "* End of WavPack blocks"
19
20 printBlock ∷ Block → IO ()
21 printBlock b
22     = do putStrLn "* WavPack Block"
23          putStrLn "- Block header:"
24          print $ blockHeader b
25          putStrLn "- Block metadata sub-blocks:"
26          mapM_ printSub $ blockMetadata b
27     where
28       printSub ∷ SubBlock → IO ()
29       printSub sub
30           | isJust (fromSubBlock sub ∷ Maybe WVBitstream)
31               = putStrLn ( "(WV Bitstream omitted: " ⧺
32                            show (metaSize sub) ⧺
33                            " bytes)"
34                          )
35           | otherwise
36               = print sub
37
38 {- % du -sh 01.wv
39    15716
40
41    When compiled with -O0:
42    % time ./dist/build/hs-wvinfo/hs-wvinfo 01.wv > /dev/null
43    1.49s user 2.12s system 98% cpu 3.664 total
44
45    When compiled with -O2:
46    % time ./dist/build/hs-wvinfo/hs-wvinfo 01.wv > /dev/null
47    1.35s user 2.09s system 97% cpu 3.520 total
48
49    Hmm... quite disappointing...  The stringification is the
50    bottleneck? If so, I can live with that.
51 -}