hsc3-lang-0.15: Haskell SuperCollider Language

Safe HaskellSafe-Inferred
LanguageHaskell98

Sound.SC3.Lang.Math

Contents

Description

sclang math functions.

Synopsis

SimpleNumber

ampdb :: Floating a => a -> a Source

SimpleNumber.ampdb converts linear amplitude to decibels.

> [1,0.5,0.25,0.13,6e-2].collect({|i| i.ampdb.round}) == [0,-6,-12,-18,-24]
map (round . ampdb) [1,0.5,0.25,0.13,6e-2] == [0,-6,-12,-18,-24]
> [1,0.7,0.5,0.35,0.25].collect({|i| i.ampdb.round}) == [0,-3,-6,-9,-12]
map (round . ampdb) [1,0.7,0.5,0.35,0.25] == [0,-3,-6,-9,-12]

dbamp :: Floating a => a -> a Source

SimpleNumber.dbamp converts decibels to a linear amplitude.

> [0,-3,-6,-9,-12].collect({|i| (i.dbamp * 100).floor}) == [100,70,50,35,25]
map (floor . (* 100) . dbamp) [0,-3,-6,-9,-12] == [100,70,50,35,25]

degreeToKey :: RealFrac a => [a] -> a -> a -> a Source

SimpleNumber.degreeToKey translates degree, scale and steps per octave to key.

> (0..5).collect({|i| i.degreeToKey([0,1,5,9,11],12)}) == [0,1,5,9,11,12]
map (degreeToKey [0,1,5,9,11] 12) [0..5] == [0,1,5,9,11,12]
map (degreeToKey [0,2,4,5,7,9,11] 12) [5,6,7,8] == [9,11,12,14]

inf :: Bounded a => a Source

Psuedo-inifite bounded value.

inf == maxBound

isInf :: (Eq a, Bounded a) => a -> Bool Source

Predicate for inf.

isInf inf == True

linexp :: (Ord a, Floating a) => a -> a -> a -> a -> a -> a Source

SimpleNumber.linexp shifts from linear to exponential ranges.

> [1,1.5,2].collect({|i| i.linexp(1,2,10,100).floor}) == [10,31,100]
map (floor . linexp 1 2 10 100) [1,1.5,2] == [10,31,100]

log10 :: Floating a => a -> a Source

SimpleNumber.log10 is the base 10 logarithm.

octpc_to_midi :: Num a => (a, a) -> a Source

midicps :: Floating a => a -> a Source

SimpleNumber.midicps translates from midi note number to cycles per second.

> [57,69].collect({|i| i.midicps}) == [220,440]
map midicps [57,69] == [220,440]

degree_to_cps :: (Floating a, RealFrac a) => [a] -> a -> a -> a -> a Source

degree_to_cps' :: (Floating a, RealFrac a) => [a] -> a -> [a] -> [a] -> [a] Source

Variant with list inputs for degree and octave, and scalar inputs for scale and steps.

UGen

exprange :: Floating b => b -> b -> b -> b Source

UGen.exprand shifts a linear (0,1) value to an exponential range.

map (floor . exprange 10 100) [0,0.5,1] == [10,31,100]

Binary

bitChar :: Char -> Bool Source

0 is false, 1 is True, else error.

map bitChar "01" == [False,True]

parseBits :: (Num a, Bits a) => String -> a Source

Parse a sequence of 0 and 1 characters as a BE bit sequence

parseBits "101" == 5
parseBits "00001111" == 15