From dd70ce725a67d32096ea3fc48950d0752ee386d5 Mon Sep 17 00:00:00 2001 From: Maxim Lihachev Date: Fri, 14 Oct 2016 12:08:51 +0500 Subject: [PATCH] =?UTF-8?q?=D0=90=D0=BB=D0=B3=D0=BE=D1=80=D0=B8=D1=82?= =?UTF-8?q?=D0=BC=20=D1=80=D0=B0=D1=81=D1=87=D1=91=D1=82=D0=B0=20=D1=83?= =?UTF-8?q?=D1=80=D0=BE=D0=B2=D0=BD=D1=8F=20=D1=81=D0=B8=D0=B3=D0=BD=D0=B0?= =?UTF-8?q?=D0=BB=D0=B0=20Db:=20=D1=84=D0=B8=D0=BD=D0=B0=D0=BB=D1=8C=D0=BD?= =?UTF-8?q?=D1=8B=D0=B9=20=D0=B2=D0=B0=D1=80=D0=B8=D0=B0=D0=BD=D1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- level.hs | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/level.hs b/level.hs index 2a0805b..cca792e 100644 --- a/level.hs +++ b/level.hs @@ -1,7 +1,7 @@ {-# LANGUAGE DeriveDataTypeable, RecordWildCards #-} -- Создан: Ср 28 сен 2016 10:18:53 --- Изменен: Пт 14 окт 2016 11:45:06 +-- Изменен: Пт 14 окт 2016 12:07:33 import System.Console.CmdArgs import System.Environment @@ -47,8 +47,13 @@ getChannel ch (xs) = map selectChannel xs where -- k десятичных логарифмов float2db :: (RealFloat a, Integral b) => b -> a -> a float2db k x - | not (isNaN x) = fromIntegral k * (logBase 10 x) - | otherwise = 0 + | isNaN x = 0 + | otherwise = fromIntegral k * (logBase 10 x) + +-- Пиковое значение уровня сигнала на отрезке +peak :: (Ord a, Floating a) => [a] -> a +peak [] = acos(2) -- NaN +peak xs = maximum xs -- Вычисление уровня сигнала calcLevel :: [Char] -> Int -> [Double] -> Int @@ -62,9 +67,8 @@ calcLevelDb fs samples = case dd of [] -> -52 -- Неслышимый звук _ -> round (median dd) where - dd = [x | x <- map (float2db 20 . maximum) slices, not (isNaN x), x /= 0] - slices = chunksOf ms $ take fs samples - ms = fs `div` 2 + dd = [x | x <- map (float2db 20 . peak) slices, not (isNaN x), x /= 0] + slices = splitWhen (== 0) $ take fs samples; -- Вычисление уровня сигнала / LUFS calcLevelLUFS :: Int -> [Double] -> Int @@ -113,6 +117,7 @@ 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