In [1]:
import Media.Timed.Audio.Stream
import Math.FunctionalAnalysis.L2Function.R1
import qualified Data.Vector.Generic as Arr
import Data.Default

In [2]:
import qualified Data.Time as Time
type Duration = Time.NominalDiffTime

In [3]:
bell :: Duration -> Audio
bell τ = Audio ldτ . fromUniformSampled def . Arr.generate (round $ 2^ldτ*νs) $
      \j -> let t = fromIntegral j/νs
            in sin (130*2*pi*t) * tanh (3*sin (210*t*2*pi) + sin (200*t^2*2*pi)/4) * exp (-t) / 2
 where νs = 40000
       ldτ = ceiling $ logBase 2 (realToFrac τ)

In [4]:
timePerformance :: IO a -> IO Time.NominalDiffTime
timePerformance action = do
    t₀ <- Time.getCurrentTime
    action
    te <- Time.getCurrentTime
    return $ Time.diffUTCTime te t₀

In [5]:
{-# LANGUAGE TupleSections #-}
timings <- mapM (\τ -> fmap (τ,) . timePerformance . playMonoAudio $ bell τ) [1,2,4,8,16]
timings


[(1s,2.311294s),(2s,4.332929s),(4s,9.076178s),(8s,16.657636s),(16s,30.71858s)]

In [6]:
import Graphics.Dynamic.Plot.R2
plotWindow [lineSegPlot [(realToFrac τ, realToFrac p) | (τ,p) <- timings]]


GraphWindowSpecR2{lBound=-1.4999999999999996, rBound=18.5, bBound=-2.4232536666666666, tBound=35.45312766666667, xResolution=640, yResolution=480}

In [ ]: