-
Notifications
You must be signed in to change notification settings - Fork 3
/
Mixer.hs
60 lines (49 loc) · 1.3 KB
/
Mixer.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
module Mixer where
import Graphics.UI.SDL
import Data.IORef
import Data.Maybe (catMaybes)
import Util (pair)
type AudioData = ()
type Mixer = IORef [AudioData]
--freq = 22050
--format = AUDIO_S16LSB
--channel = 1
--samples = 4096
createMixer = do
mixer <- newIORef []
-- openAudio freq format channel samples (cb mixer)
return mixer
-- where
-- cb mixer len = do
-- wavs <- readIORef mixer
-- lockAudio
-- writeIORef mixer $ filter (not . audioIsEnd) $ map (audioAdvance len) wavs
-- unlockAudio
-- return wavs
playWav mixer Nothing = return ()
--playWav mixer (Just ad) = do
-- pauseAudio 1
-- lockAudio
-- modifyIORef mixer (++ [ad])
-- unlockAudio
-- pauseAudio 0
-- return ()
playWav mixer _ = return ()
data SoundType =
SndJump
| SndShot
| SndPunch
deriving (Eq, Show)
soundFn SndJump = "jump.wav"
soundFn SndShot = "jump.wav"
soundFn SndPunch = "jump.wav"
soundTypes = [SndJump, SndShot, SndPunch]
type SoundResource = [(SoundType, AudioData)]
loadSoundResource :: [SoundType] -> IO SoundResource
--loadSoundResource sndtypes = mapM load sndtypes >>= return . catMaybes
-- where
-- load :: SoundType -> IO (Maybe (SoundType, AudioData))
-- load sndtype = do
-- dat <- loadWAV $ ("data/snd/" ++) $ soundFn sndtype
-- return $ dat >>= Just . pair sndtype
loadSoundResource sndtypes = return []