summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGregor Kleen <gkleen@yggdrasil.li>2015-06-21 20:45:31 +0200
committerGregor Kleen <gkleen@yggdrasil.li>2015-06-21 20:46:05 +0200
commitdddd66c3f827ef38ed27ef12e22806b7aee880b4 (patch)
tree341c7cdc5a7ba2d4f6873dc089542d57496bfe88 /src
parentb354971344fbeaf3ca4061910796dee38b7ae025 (diff)
downloadtrivmix-dddd66c3f827ef38ed27ef12e22806b7aee880b4.tar
trivmix-dddd66c3f827ef38ed27ef12e22806b7aee880b4.tar.gz
trivmix-dddd66c3f827ef38ed27ef12e22806b7aee880b4.tar.bz2
trivmix-dddd66c3f827ef38ed27ef12e22806b7aee880b4.tar.xz
trivmix-dddd66c3f827ef38ed27ef12e22806b7aee880b4.zip
Fixed db/lin conversion
Diffstat (limited to 'src')
-rw-r--r--src/Trivmix/Types.hs8
1 files changed, 4 insertions, 4 deletions
diff --git a/src/Trivmix/Types.hs b/src/Trivmix/Types.hs
index 9822449..874eb42 100644
--- a/src/Trivmix/Types.hs
+++ b/src/Trivmix/Types.hs
@@ -44,23 +44,23 @@ withResolution :: (HasResolution a) => (Integer -> f a) -> f a
44withResolution f = withType (f . resolution) 44withResolution f = withType (f . resolution)
45 45
46linToDb :: Float -> Float 46linToDb :: Float -> Float
47linToDb x = 10 ** (0.05 * x) 47linToDb x = 20 * (logBase 10 x)
48 48
49dBToLin :: Float -> Float 49dBToLin :: Float -> Float
50dBToLin x = 20 * (logBase 10 x) 50dBToLin x = 10 ** (0.05 * x)
51 51
52instance Show Level where 52instance Show Level where
53 show (Lin x) = show x 53 show (Lin x) = show x
54 show (DB x) = (show $ (withPrec x' :: Milli)) ++ "dB" 54 show (DB x) = (show $ (withPrec x' :: Milli)) ++ "dB"
55 where 55 where
56 x' = dBToLin x 56 x' = linToDb x
57 57
58instance Read Level where 58instance Read Level where
59 readsPrec i = map toL . readsPrec i 59 readsPrec i = map toL . readsPrec i
60 where 60 where
61 toL :: (Float, String) -> (Level, String) 61 toL :: (Float, String) -> (Level, String)
62 toL (f, str) 62 toL (f, str)
63 | ((==) `on` CI.mk) prec unit = (DB $ linToDb f, rest) 63 | ((==) `on` CI.mk) prec unit = (DB $ dBToLin f, rest)
64 | otherwise = (Lin f, str) 64 | otherwise = (Lin f, str)
65 where 65 where
66 prec = take lU str 66 prec = take lU str