module SoXBasics1 (
norm
, normL
, gainL
, quarterSinFade
, silenceBoth
, resampleA
, noiseReduceB
, noiseReduceE
, sincA
, volS
, volS2
) where
import System.Directory
import Data.Maybe (isJust, fromJust)
import Numeric
import System.Process
import EndOfExe
import System.Exit
import qualified SoXBasics as SB (extremeS1,upperBnd,selMA,maxAbs,norm)
norm :: FilePath -> IO ()
norm file = if isJust (showE "sox")
then do
(code, _, _) <- readProcessWithExitCode (fromJust (showE "sox")) [file, "8" ++ file, "norm"] ""
if code /= ExitSuccess
then do
e1 <- doesFileExist $ "8" ++ file
if e1
then do
removeFile $ "8" ++ file
error "File was not created with \"norm\" effect!"
else error "File was not created with \"norm\" effect!"
else do
e2 <- doesFileExist $ "8" ++ file
if e2
then do
removeFile file
renameFile ("8" ++ file) file
else error "The initial file was not changed!"
else error "SoX is not properly installed in your system. Please, install it properly and then call the function again."
normL :: FilePath -> Int -> IO ()
normL file level = if isJust (showE "sox")
then do
(code, _, _) <- readProcessWithExitCode (fromJust (showE "sox")) [file, "9" ++ file, "gain", "-n", show level] ""
if code /= ExitSuccess
then do
e1 <- doesFileExist $ "9" ++ file
if e1
then do
removeFile $ "9" ++ file
error "File was not created with \"gain -n\" effect!"
else error "File was not created with \"gain -n\" effect!"
else do
e2 <- doesFileExist $ "9" ++ file
if e2
then do
removeFile file
renameFile ("9" ++ file) file
else error "The initial file was not changed!"
else error "SoX is not properly installed in your system. Please, install it properly and then call the function again."
gainL :: FilePath -> Double -> IO ()
gainL file level = if isJust (showE "sox")
then do
(code, _, _) <- readProcessWithExitCode (fromJust (showE "sox")) [file, "9" ++ file, "gain", "-b", showFFloat (Just 6) level $ show 0] ""
if code /= ExitSuccess
then do
e1 <- doesFileExist $ "9" ++ file
if e1
then do
removeFile $ "9" ++ file
error "File was not created with \"gain\" effect!"
else error "File was not created with \"gain\" effect!"
else do
e2 <- doesFileExist $ "9" ++ file
if e2
then do
removeFile file
renameFile ("9" ++ file) file
else error "The initial file was not changed!"
else error "SoX is not properly installed in your system. Please, install it properly and then call the function again."
quarterSinFade :: FilePath -> IO ()
quarterSinFade file = if isJust (showE "sox")
then do
pos <- SB.extremeS1 file
upp <- SB.upperBnd file
(code, _, _) <- readProcessWithExitCode (fromJust (showE "sox")) [file, "4" ++ file, "fade", "q", show pos ++ "s", "=" ++ show upp ++ "s", show (upp - pos) ++ "s"] ""
if code /= ExitSuccess
then do
e1 <- doesFileExist $ "4" ++ file
if e1
then do
removeFile $ "4" ++ file
error "File was not created with \"fade\" effect!"
else error "File was not created with \"fade\" effect!"
else do
e2 <- doesFileExist $ "4" ++ file
if e2
then do
removeFile file
renameFile ("4" ++ file) file
else error "The initial file was not changed!"
else error "SoX is not properly installed in your system. Please, install it properly and then call the function again."
silenceBoth :: FilePath -> Int -> Int -> IO ()
silenceBoth file beginning end = if isJust (showE "sox")
then do
(code, _, _) <- readProcessWithExitCode (fromJust (showE "sox")) [file, "3" ++ file, "delay", show beginning ++ "s", "reverse"] ""
if code /= ExitSuccess
then do
e1 <- doesFileExist $ "3" ++ file
if e1
then do
removeFile $ "3" ++ file
error "File was not created with \"delay\" and \"reverse\" effects!"
else error "File was not created with \"delay\" and \"reverse\" effects!"
else do
e2 <- doesFileExist $ "3" ++ file
if e2
then do
(code1, _, _) <- readProcessWithExitCode (fromJust (showE "sox")) ["3" ++ file, "2" ++ file, "delay", show end ++ "s", "reverse"] ""
if code1 /= ExitSuccess
then do
e2 <- doesFileExist $ "2" ++ file
if e2
then do
removeFile $ "3" ++ file
removeFile $ "2" ++ file
error "The resulting file was not created!"
else do
removeFile $ "3" ++ file
error "The resulting file was not created!"
else do
e3 <- doesFileExist $ "2" ++ file
if e3
then do
removeFile $ "3" ++ file
removeFile file
renameFile ("2" ++ file) file
else do
removeFile $ "3" ++ file
error "The resulting file was not created!"
else error "The initial file was not changed!"
else error "SoX is not properly installed in your system. Please, install it properly and then call the function again."
resampleA :: FilePath -> Int -> IO ()
resampleA file frequency = if isJust (showE "sox")
then do
(code, _, _) <- readProcessWithExitCode (fromJust (showE "sox")) [file, "3" ++ file, "rate", "-s", "-I", show frequency] ""
if code /= ExitSuccess
then do
e1 <- doesFileExist $ "3" ++ file
if e1
then do
removeFile $ "3" ++ file
error "File was not created with \"rate\" effect!"
else error "File was not created with \"rate\" effect!"
else do
e2 <- doesFileExist $ "3" ++ file
if e2
then do
removeFile file
renameFile ("3" ++ file) file
else error "The initial file was not changed!"
else error "SoX is not properly installed in your system. Please, install it properly and then call the function again."
noiseReduceB :: FilePath -> IO ()
noiseReduceB file = if isJust (showE "sox")
then do
(code, _, _) <- readProcessWithExitCode (fromJust (showE "sox")) [file, "_" ++ file, "noisered", file ++ ".b.prof"] ""
if code /= ExitSuccess
then do
e1 <- doesFileExist $ "_" ++ file
if e1
then do
removeFile $ "_" ++ file
error "File was not created with \"noisered\" effect!"
else error "File was not created with \"noisered\" effect!"
else do
e2 <- doesFileExist $ "_" ++ file
if e2
then do
removeFile file
renameFile ("_" ++ file) file
else error "The initial file was not changed!"
else error "SoX is not properly installed in your system. Please, install it properly and then call the function again."
noiseReduceE :: FilePath -> IO ()
noiseReduceE file = if isJust (showE "sox")
then do
(code, _, _) <- readProcessWithExitCode (fromJust (showE "sox")) [file, "_." ++ file, "noisered", file ++ ".e.prof"] ""
if code /= ExitSuccess
then do
e1 <- doesFileExist $ "_." ++ file
if e1
then do
removeFile $ "_." ++ file
error "File was not created with \"noisered\" effect!"
else error "File was not created with \"noisered\" effect!"
else do
e2 <- doesFileExist $ "_." ++ file
if e2
then do
removeFile file
renameFile ("_." ++ file) file
else error "The initial file was not changed!"
else error "SoX is not properly installed in your system. Please, install it properly and then call the function again."
volS :: FilePath -> Double -> IO ()
volS file amplitude = if isJust (showE "sox")
then do
SB.norm file
e0 <- doesFileExist $ "8" ++ file
if e0
then do
(code, _, _) <- readProcessWithExitCode (fromJust (showE "sox")) ["8" ++ file, "8." ++ file, "vol", showFFloat Nothing amplitude $ show 0, "amplitude"] ""
if code /= ExitSuccess
then do
e1 <- doesFileExist $ "8." ++ file
if e1
then do
removeFile $ "8." ++ file
removeFile $ "8" ++ file
error "File was not created with \"vol\" effect!"
else do
removeFile $ "8" ++ file
error "File was not created with \"vol\" effect!"
else do
e2 <- doesFileExist $ "8." ++ file
if e2
then do
removeFile file
removeFile $ "8" ++ file
renameFile ("8." ++ file) file
else do
removeFile $ "8" ++ file
error "The initial file was not changed!"
else error "The initial file was not changed!"
else error "SoX is not properly installed in your system. Please, install it properly and then call the function again."
volS2 :: FilePath -> FilePath -> IO ()
volS2 fileA fileB = if isJust (showE "sox")
then do
upp <- SB.upperBnd fileB
amplMax <- SB.selMA fileB (0, upp) True
amplMin <- SB.selMA fileB (0, upp) False
let ampl = read (fst . SB.maxAbs $ (amplMax, amplMin))::Double
(code, _, _) <- readProcessWithExitCode (fromJust (showE "sox")) [fileA, "8." ++ tail fileA, "vol", showFFloat Nothing ampl $ show 0, "amplitude"] ""
if code /= ExitSuccess
then do
e1 <- doesFileExist $ "8." ++ tail fileA
if e1
then do
removeFile $ "8." ++ tail fileA
error "File was not created with \"vol\" effect!"
else error "File was not created with \"vol\" effect!"
else do
file8e <- doesFileExist $ "8." ++ tail fileA
if file8e
then do
removeFile fileA
renameFile ("8." ++ tail fileA) fileA
else error "The initial file was not changed!"
else error "SoX is not properly installed in your system. Please, install it properly and then call the function again."
sincA :: FilePath -> IO ()
sincA file = if isJust (showE "sox")
then do
(code, _, _) <- readProcessWithExitCode (fromJust (showE "sox")) [file, "4." ++ file, "sinc", "-a", "50", "-I", "0.07k-11k"] ""
if code /= ExitSuccess
then do
e1 <- doesFileExist $ "4." ++ file
if e1
then do
removeFile $ "4." ++ file
error "File was not created with \"sinc\" effect!"
else error "File was not created with \"sinc\" effect!"
else do
e0 <- doesFileExist $ "4." ++ file
if e0
then do
removeFile file
renameFile ("4." ++ file) file
else error "The initial file was not changed!"
else error "SoX is not properly installed in your system. Please, install it properly and then call the function again."