{-# OPTIONS_GHC -threaded #-}
module DobutokO.Sound.DIS5G6G (
syllableStr
, intervalsFromString
, vStrToVInt
, strToInt
, durationsAver
, str2Durat1
, str2Durations
, str2Vol1
, str2Volume
, doublesAveragedA
, doublesAveragedG
, equalize2Vec
, intervalsFromStringG
, silentSound2G
, strengthsAver
, strengthsDbAver
, apply6G
, apply6G2
, apply6GS
, apply6GS2
) where
import CaseBi (getBFst')
import Numeric
import Data.Maybe (fromJust)
import qualified Data.Vector as V
import System.Process
import EndOfExe
import Melodics.Ukrainian (convertToProperUkrainian)
import MMSyn7l
import DobutokO.Sound.IntermediateF
import DobutokO.Sound.Functional.Params
import DobutokO.Sound.Decibel
intervalsFromStringG :: Intervals -> String -> Intervals
intervalsFromStringG v = vStrToVIntG v . convertToProperUkrainian
vStrToVInt :: V.Vector String -> Intervals
vStrToVInt = V.map (strToIntG defInt)
strToInt :: String -> Int
strToInt = strToIntG defInt
{-# INLINE strToInt #-}
doublesAveragedA :: V.Vector Float -> Float -> V.Vector Float
doublesAveragedA v4 y3
| V.null v4 || y3 == 0 = V.empty
| otherwise = let aver = V.sum v4 / fromIntegral (V.length v4) in if aver == 0.0 then doublesAveragedA (V.filter (/= 0.0) v4) y3
else V.map (\t4 -> t4 * y3 / aver) v4
doublesAveragedG :: V.Vector Float -> Float -> V.Vector Float
doublesAveragedG v4 y3
| V.null v4 || y3 == 0 = V.empty
| otherwise = let aver = V.product v4 ** (fromIntegral 1 / (fromIntegral (V.length v4))) in if aver == 0.0 then doublesAveragedG (V.filter (/= 0.0) v4) y3
else V.map (\t4 -> t4 * y3 / aver) v4
durationsAver :: Durations -> Float -> Durations
durationsAver = doublesAveragedA
strengthsAver :: Strengths -> Float -> Strengths
strengthsAver = doublesAveragedG
strengthsDbAver :: StrengthsDb -> Float -> StrengthsDb
strengthsDbAver = doublesAveragedG
equalize2Vec :: V.Vector (V.Vector a) -> V.Vector (V.Vector a)
equalize2Vec v = let min = V.minimum . V.map V.length $ v in V.map (V.unsafeSlice 0 min) v
str2Durations :: String -> Float -> Durations
str2Durations xs y
| compare y 0.0 == GT && not (null xs) = durationsAver (V.map str2Durat1 . convertToProperUkrainian $ xs) y
| otherwise = V.empty
str2Durat1 :: String -> Float
str2Durat1 = getBFst' ((-0.153016), V.fromList [("-", (-0.101995)), ("0", (-0.051020)), ("1", (-0.153016)), ("а", 0.138231), ("б", 0.057143),
("в", 0.082268), ("г", 0.076825), ("д", 0.072063), ("дж", 0.048934), ("дз", 0.055601), ("е", 0.093605), ("ж", 0.070658), ("з", 0.056054),
("и", 0.099955), ("й", 0.057143), ("к", 0.045351), ("л", 0.064036), ("м", 0.077370), ("н", 0.074240), ("о", 0.116463), ("п", 0.134830),
("р", 0.049206), ("с", 0.074603), ("сь", 0.074558), ("т", 0.110658), ("у", 0.109070), ("ф", 0.062268), ("х", 0.077188), ("ц", 0.053061),
("ць", 0.089342), ("ч", 0.057596), ("ш", 0.066077), ("ь", 0.020227), ("і", 0.094150), ("ґ", 0.062948)])
str2Volume :: String -> Strengths
str2Volume = V.map (getBFst' (0.0, V.fromList [("а", 0.890533), ("б", 0.211334), ("в", (-0.630859)), ("г", (-0.757599)), ("д", 0.884613), ("дж", 0.768127),
("дз", (-0.731262)), ("е", (-0.742523)), ("ж", (-0.588959)), ("з", (-0.528870)), ("и", 0.770935), ("й", (-0.708008)), ("к", (-0.443085)),
("л", 0.572632), ("м", (-0.782349)), ("н", (-0.797607)), ("о", (-0.579559)), ("п", 0.124908), ("р", 0.647369), ("с", 0.155640), ("сь", (-0.207764)),
("т", -0.304443), ("у", 0.718262), ("ф", (-0.374359)), ("х", (-0.251160)), ("ц", (-0.392365)), ("ць", 0.381348), ("ч", (-0.189240)),
("ш", 0.251221), ("ь", 0.495483), ("і", (-0.682709)), ("ґ", 0.557098)])) . convertToProperUkrainian
str2Vol1 :: String -> Float
str2Vol1 = getBFst' (0.0, V.fromList [("а", 0.890533), ("б", 0.211334), ("в", (-0.630859)), ("г", (-0.757599)), ("д", 0.884613), ("дж", 0.768127),
("дз", (-0.731262)), ("е", (-0.742523)), ("ж", (-0.588959)), ("з", (-0.528870)), ("и", 0.770935), ("й", (-0.708008)), ("к", (-0.443085)),
("л", 0.572632), ("м", (-0.782349)), ("н", (-0.797607)), ("о", (-0.579559)), ("п", 0.124908), ("р", 0.647369), ("с", 0.155640), ("сь", (-0.207764)),
("т", -0.304443), ("у", 0.718262), ("ф", (-0.374359)), ("х", (-0.251160)), ("ц", (-0.392365)), ("ць", 0.381348), ("ч", (-0.189240)),
("ш", 0.251221), ("ь", 0.495483), ("і", (-0.682709)), ("ґ", 0.557098)]) . V.unsafeHead . convertToProperUkrainian
silentSound2G :: FilePath -> Float -> String -> IO ()
silentSound2G file y4 ys = do
_ <- readProcessWithExitCode (fromJust (showE "sox"))
((if null ys then id else soxBasicParams ys) ["-r22040","-n",file,"synth", showFFloat (Just 1) y4 "","sine","440.0","vol","0"]) ""
putStr ""
apply6G :: Strengths -> String -> String -> IO ()
apply6G v6 ys zs
| V.null v6 = putStrLn "Nothing changed, because the vector of volume adjustments is empty! "
| otherwise = do
dir0v <- listVDirectory3G ys zs
V.imapM_ (\i file -> soxE file ["norm","vol", showFFloat (Just 4) (V.unsafeIndex v6 (i `rem` V.length v6)) ""]) dir0v
apply6GS :: String -> String -> String -> IO ()
apply6GS xs = apply6G (str2Volume xs)
apply6G2 :: Strengths -> String -> String -> Float -> IO ()
apply6G2 v6 ys zs limV
| V.null v6 = putStrLn "Nothing changed, because the vector of volume adjustments is empty! "
| otherwise = do
dir0v <- listVDirectory3G ys zs
V.imapM_ (\i file -> apply6GSilentFile file limV (V.unsafeIndex v6 (i `rem` V.length v6))) dir0v
apply6GS2 :: String -> String -> String -> Float -> IO ()
apply6GS2 xs = apply6G2 (str2Volume xs)