5 import Control.Monad.IO.Class
6 import Control.Monad.Trans.Region
8 import qualified Data.StorableVector.Lazy as L
14 do pl ← openPlayer 44100 Nothing Nothing
15 -- Let's play an 'A' note for 1 sec.
16 playMono16Sine pl 44100 1 440
18 playMono16Sine ∷ ( AncestorRegion pr cr
21 ⇒ Player Int16 Mono pr
26 playMono16Sine pl sampleFreq sec noteFreq
29 buffer ∷ L.Vector Int16
30 buffer = L.pack L.defaultChunkSize frames
33 frames = let nFrames = round $ sec ⋅ realToFrac sampleFreq
35 map calcFrame [0 .. nFrames - 1]
37 calcFrame ∷ Int → Int16
38 calcFrame n = let frame = calcFrame' n
41 floor $ fromIntegral ((maxBound ∷ Int16) - 1) ⋅ frame
43 calcFrame' ∷ Int → Double
49 ⋅ (realToFrac n / realToFrac sampleFreq)