X-Git-Url: http://git.cielonegro.org/gitweb.cgi?p=wavpack.git;a=blobdiff_plain;f=examples%2FWvInfo.hs;h=6631c7b47fcf9ebc6f864b0ef66c33b3d8044c25;hp=5e0b86fbe62bdbd020e6dc76bbbbcf78752808a3;hb=98a1dd78c7bb73c5d66f4773b63bbc5b94e7e618;hpb=79fe8094594b6b25d7d9c44bc128418d69f1da95 diff --git a/examples/WvInfo.hs b/examples/WvInfo.hs index 5e0b86f..6631c7b 100644 --- a/examples/WvInfo.hs +++ b/examples/WvInfo.hs @@ -1,24 +1,51 @@ {-# LANGUAGE - UnboxedTuples - , UnicodeSyntax + UnicodeSyntax #-} module Main where import Codec.Audio.WavPack.Block +import Codec.Audio.WavPack.Metadata import qualified Data.ByteString.Lazy as L -import qualified Data.Strict as S +import Data.Maybe +import Prelude.Unicode import System.Environment import System.IO main ∷ IO () main = do [wvFile] ← getArgs - wvStream ← L.readFile wvFile + wvData ← L.readFile wvFile hSetBuffering stdout NoBuffering - showWvInfo wvStream + mapM_ printBlock $ readBlocks wvData + putStrLn "* End of WavPack blocks" -showWvInfo ∷ L.ByteString → IO () -showWvInfo stream - = case findNextBlock stream of - (# S.Just block, _ #) - → print block - (# S.Nothing , _ #) - → fail "Can't find any WavPack block headers." +printBlock ∷ Block → IO () +printBlock b + = do putStrLn "* WavPack Block" + putStrLn "- Block header:" + print $ blockHeader b + putStrLn "- Block metadata sub-blocks:" + mapM_ printSub $ blockMetadata b + where + printSub ∷ SubBlock → IO () + printSub sub + | isJust (fromSubBlock sub ∷ Maybe WVBitstream) + = putStrLn ( "(WV Bitstream omitted: " ⧺ + show (metaSize sub) ⧺ + " bytes)" + ) + | otherwise + = print sub + +{- % du -sh 01.wv + 15716 + + When compiled with -O0: + % time ./dist/build/hs-wvinfo/hs-wvinfo 01.wv > /dev/null + 1.49s user 2.12s system 98% cpu 3.664 total + + When compiled with -O2: + % time ./dist/build/hs-wvinfo/hs-wvinfo 01.wv > /dev/null + 1.35s user 2.09s system 97% cpu 3.520 total + + Hmm... quite disappointing... The stringification is the + bottleneck? If so, I can live with that. +-}