summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOleksandrZhabenko <>2020-06-29 19:36:00 (GMT)
committerhdiff <hdiff@hdiff.luite.com>2020-06-29 19:36:00 (GMT)
commit58a6937cb732061702c6967ce4d12098c47548fa (patch)
tree543a69ff8499d2b7a8958a5424f4ea00873cbb5a
parent7093da3a44cd7743eee84d7dcfdbb5699db8319d (diff)
version 0.2.0.00.2.0.0
-rw-r--r--ChangeLog.md4
-rw-r--r--DobutokO/Sound/Effects/Remix.hs155
-rw-r--r--dobutokO-effects.cabal4
3 files changed, 161 insertions, 2 deletions
diff --git a/ChangeLog.md b/ChangeLog.md
index c1d6066..017c31e 100644
--- a/ChangeLog.md
+++ b/ChangeLog.md
@@ -3,3 +3,7 @@
## 0.1.0.0 -- 2020-06-27
* First version. Released on an unsuspecting world.
+
+## 0.2.0.0 -- 2020-06-29
+
+* Second version. Added a new module DobutokO.Sound.Effects.Remix to deal with the SoX "remix" effect.
diff --git a/DobutokO/Sound/Effects/Remix.hs b/DobutokO/Sound/Effects/Remix.hs
new file mode 100644
index 0000000..b12a43c
--- /dev/null
+++ b/DobutokO/Sound/Effects/Remix.hs
@@ -0,0 +1,155 @@
+-- |
+-- Module : DobutokO.Sound.Effects.Remix
+-- Copyright : (c) OleksandrZhabenko 2020
+-- License : MIT
+-- Stability : Experimental
+-- Maintainer : olexandr543@yahoo.com
+--
+-- Helps to create experimental music.
+-- Can be used for applying the SoX \"reverb\" and \"reverse\" effects.
+--
+
+{-# OPTIONS_GHC -threaded #-}
+{-# LANGUAGE CPP, FlexibleInstances #-}
+
+module DobutokO.Sound.Effects.Remix where
+
+#ifdef __GLASGOW_HASKELL__
+#if __GLASGOW_HASKELL__>=710
+/* code that applies only to GHC 7.10.* and higher versions */
+import GHC.Base (mconcat)
+#endif
+#endif
+import Numeric (showFFloat)
+import Data.List (intersperse)
+import qualified DobutokO.Sound.Frequency as FQ
+
+#ifdef __GLASGOW_HASKELL__
+#if __GLASGOW_HASKELL__==708
+/* code that applies only to GHC 7.8.* */
+mconcat = concat
+#endif
+#endif
+
+data Vol3 a = P | I | V | P2 a | I2 a | V2 a deriving Eq
+
+instance (Show a, RealFloat a) => Show (Vol3 a) where
+ show P = "p0"
+ show I = "i0"
+ show V = "v1"
+ show (P2 a) = 'p':showFFloat Nothing a ""
+ show (I2 a) = 'i':showFFloat Nothing a ""
+ show (V2 a) = 'v':showFFloat Nothing a ""
+
+vol3 :: Vol3 Float -> Float
+vol3 P = 0.0
+vol3 I = 0.0
+vol3 V = 1.0
+vol3 (P2 x) = x
+vol3 (I2 x) = x
+vol3 (V2 x) = x
+
+vol3Set :: Float -> Vol3 Float -> Vol3 Float
+vol3Set x P
+ | x == 0.0 = P
+ | otherwise = P2 x
+vol3Set x I
+ | x == 0.0 = I
+ | otherwise = I2 x
+vol3Set x V
+ | x == 1.0 = V
+ | otherwise = V2 x
+vol3Set x (P2 _) = P2 x
+vol3Set x (I2 _) = I2 x
+vol3Set x (V2 _) = V2 x
+
+type Vol3F = Vol3 Float
+
+data IChannel a b = ICh a (Vol3 b) deriving Eq
+
+ichannel1 :: IChannel a b -> a
+ichannel1 (ICh x _) = x
+
+ichannel2 :: Vol3F -> IChannel a Float -> Vol3F
+ichannel2 P (ICh _ y) = y
+ichannel2 I (ICh _ y) = y
+ichannel2 V (ICh _ y) = y
+ichannel2 (P2 _) (ICh _ y) = P2 (vol3 y)
+ichannel2 (I2 _) (ICh _ y) = I2 (vol3 y)
+ichannel2 (V2 _) (ICh _ y) = V2 (vol3 y)
+
+ichannel2C :: IChannel a b -> String
+ichannel2C (ICh _ P) = "P"
+ichannel2C (ICh _ I) = "I"
+ichannel2C (ICh _ V) = "V"
+ichannel2C (ICh _ (P2 _)) = "P2"
+ichannel2C (ICh _ (I2 _)) = "I2"
+ichannel2C (ICh _ (V2 _)) = "V2"
+
+ichannel21 :: IChannel a Float -> Float
+ichannel21 (ICh _ y) = vol3 y
+
+ichannelSet1 :: a -> IChannel a b -> IChannel a b
+ichannelSet1 x (ICh _ y) = ICh x y
+
+ichannelSet2 :: Vol3 b -> IChannel a b -> IChannel a b
+ichannelSet2 y (ICh x _) = ICh x y
+
+type IChanF = IChannel Int Float
+
+instance (Show a, Integral a, Show b, RealFloat b) => Show (IChannel a b) where
+ show (ICh x y) = mconcat [show x, show y]
+
+data OChannel a = OCh [a] deriving Eq
+
+instance (Show a) => Show (OChannel a) where
+ show (OCh []) = []
+ show (OCh [x]) = show x
+ show (OCh ys) = mconcat . intersperse "," . map show $ ys
+
+ochannel1 :: OChannel a -> [a]
+ochannel1 (OCh xs) = xs
+
+ochannelSet1 :: [a] -> OChannel a -> OChannel a
+ochannelSet1 xs _ = OCh xs
+
+type OChanF = OChannel IChanF
+
+data MixSpec = A | M | D deriving Eq
+
+instance Show MixSpec where
+ show A = "-a "
+ show M = "-m "
+ show D = []
+
+data Remix a b = Rmx | Rmix a [b] deriving Eq
+
+instance Show (Remix MixSpec OChanF) where
+ show (Rmix x ys) = mconcat ["remix ",show x, mconcat . intersperse " " . map show $ ys]
+ show Rmx = "remix -"
+
+remixC :: Remix a b -> String
+remixC Rmx = "Rmx"
+remixC (Rmix _ _) = "Rmix"
+
+remix1 :: Remix a b -> Maybe a
+remix1 Rmx = Nothing
+remix1 (Rmix x _) = Just x
+
+remix2 :: Remix a b -> [b]
+remix2 Rmx = []
+remix2 (Rmix _ xs) = xs
+
+type ReMix = Remix MixSpec OChanF
+
+remixSet1 :: MixSpec -> ReMix -> ReMix
+remixSet1 _ Rmx = Rmx
+remixSet1 y (Rmix _ xs) = Rmix y xs
+
+remixSet2 :: [OChanF] -> ReMix -> ReMix
+remixSet2 ys Rmx = Rmix D ys
+remixSet2 ys (Rmix x _) = Rmix x ys
+
+showRmQ :: ReMix -> [String]
+showRmQ = words . show
+
diff --git a/dobutokO-effects.cabal b/dobutokO-effects.cabal
index bc88ac8..5ff964c 100644
--- a/dobutokO-effects.cabal
+++ b/dobutokO-effects.cabal
@@ -2,7 +2,7 @@
-- documentation, see http://haskell.org/cabal/users-guide/
name: dobutokO-effects
-version: 0.1.0.0
+version: 0.2.0.0
synopsis: A library to deal with SoX effects and possibilities
description: Can be used to get access to different SoX possibilities
homepage: https://hackage.haskell.org/package/dobutokO-effects
@@ -17,7 +17,7 @@ extra-source-files: ChangeLog.md
cabal-version: >=1.10
library
- exposed-modules: DobutokO.Sound.Combine, DobutokO.Sound.Effects.Reverb, DobutokO.Sound.Effects.Fade
+ exposed-modules: DobutokO.Sound.Combine, DobutokO.Sound.Effects.Reverb, DobutokO.Sound.Effects.Fade, DobutokO.Sound.Effects.Remix
-- other-modules:
other-extensions: CPP, FlexibleInstances
build-depends: base >=4.7 && <4.15, dobutokO-frequency >=0.1 && <1