@ -1,7 +1,7 @@
@@ -1,7 +1,7 @@
{- # LANGUAGE DeriveDataTypeable, RecordWildCards # -}
-- Создан: Ср 28 сен 2016 10:18:53
-- Изменен: Чт 13 окт 2016 18:30:52
-- Изменен: Пт 14 окт 2016 11:45:06
import System.Console.CmdArgs
import System.Environment
@ -26,6 +26,10 @@ everyN n list = [take (n + n) $ drop (x-1) list | x <- [1, n..length list]]
@@ -26,6 +26,10 @@ everyN n list = [take (n + n) $ drop (x-1) list | x <- [1, n..length list]]
convert :: ( Show a , Read c ) => a -> c
convert = read . show
-- Проверка на пустую строку
notEmpty :: String -> Bool
notEmpty = ( /= ) ( show " " )
-- =============================================================================
-- Чтение данных аудиофайла
@ -46,6 +50,12 @@ float2db k x
@@ -46,6 +50,12 @@ float2db k x
| not ( isNaN x ) = fromIntegral k * ( logBase 10 x )
| otherwise = 0
-- Вычисление уровня сигнала
calcLevel :: [ Char ] -> Int -> [ Double ] -> Int
calcLevel vu = case ( map toLower vu ) of
" lufs " -> calcLevelLUFS
" db " -> calcLevelDb
-- Вычисление уровня сигнала / Db
calcLevelDb :: Int -> [ Double ] -> Int
calcLevelDb fs samples = case dd of
@ -103,6 +113,13 @@ defaultOptions = cmdArgs $ Audioread {
@@ -103,6 +113,13 @@ defaultOptions = cmdArgs $ Audioread {
vu = " db " &= typ " db/lufs " &= help " Type of vu scale "
} &= summary " audioread v0.2: information about audiofiles "
describe :: ( Show s ) => Int -> String -> s -> String -> IO ()
describe o p ms s = let message = show ms in do
when ( o == 1 ) $ putStr $ p
when ( notEmpty message ) $ putStr message
when ( o == 1 ) $ putStr $ s
putStrLn " "
main :: IO ()
main = do
args <- getArgs
@ -113,16 +130,15 @@ main = do
@@ -113,16 +130,15 @@ main = do
let w = take ( samples cmd ) ( audioread d )
let exec fx = do
when ( ( title cmd ) == 1 ) $ putStrLn $ " \ n ---[ " ++ fx ++ " ]: "
describe ( title cmd ) ( " \ n ---[ " ++ fx ) " " ( " ]: " )
case fx of
" samples " -> mapM_ print $ getChannel ( map toUpper $ channel cmd ) w
" phase " -> print $ calcPhase w
" db " -> do
print $ calcLevelDb ( samples cmd ) ( getChannel " L " w )
print $ calcLevelDb ( samples cmd ) ( getChannel " R " w )
" lufs " -> do
print $ calcLevelLUFS ( samples cmd ) ( getChannel " L " w )
print $ calcLevelLUFS ( samples cmd ) ( getChannel " R " w )
" level " -> do
describe ( title cmd ) " L: "
( calcLevel ( vu cmd ) ( samples cmd ) ( getChannel " L " w ) ) ( vu cmd )
describe ( title cmd ) " R: "
( calcLevel ( vu cmd ) ( samples cmd ) ( getChannel " R " w ) ) ( vu cmd )
_ -> putStrLn $ " WARNING: Unknown type of information: " ++ fx ++ " \ n "
mapM_ exec ( splitOn " , " $ info cmd )