diff options
| author | Gregor Kleen <gkleen@yggdrasil.li> | 2015-06-21 20:45:31 +0200 | 
|---|---|---|
| committer | Gregor Kleen <gkleen@yggdrasil.li> | 2015-06-21 20:46:05 +0200 | 
| commit | dddd66c3f827ef38ed27ef12e22806b7aee880b4 (patch) | |
| tree | 341c7cdc5a7ba2d4f6873dc089542d57496bfe88 /src/Trivmix | |
| parent | b354971344fbeaf3ca4061910796dee38b7ae025 (diff) | |
| download | trivmix-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/Trivmix')
| -rw-r--r-- | src/Trivmix/Types.hs | 8 | 
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 | |||
| 44 | withResolution f = withType (f . resolution) | 44 | withResolution f = withType (f . resolution) | 
| 45 | 45 | ||
| 46 | linToDb :: Float -> Float | 46 | linToDb :: Float -> Float | 
| 47 | linToDb x = 10 ** (0.05 * x) | 47 | linToDb x = 20 * (logBase 10 x) | 
| 48 | 48 | ||
| 49 | dBToLin :: Float -> Float | 49 | dBToLin :: Float -> Float | 
| 50 | dBToLin x = 20 * (logBase 10 x) | 50 | dBToLin x = 10 ** (0.05 * x) | 
| 51 | 51 | ||
| 52 | instance Show Level where | 52 | instance 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 | ||
| 58 | instance Read Level where | 58 | instance 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 | 
