-
Notifications
You must be signed in to change notification settings - Fork 172
/
Copy pathSDL_mixer.carp
79 lines (60 loc) · 1.88 KB
/
SDL_mixer.carp
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
(system-include "SDL2/SDL_mixer.h")
(add-pkg "SDL2_mixer")
(Project.config "cflag" "-Wno-incompatible-pointer-types-discards-qualifiers")
(register-type Mix_Chunk)
(register-type Mix_Music)
(defmodule Mixer
;; Setup
(register open-audio
;; freq format channels chunksize
(Fn [Int Int Int Int] Int)
"Mix_OpenAudio")
;; Argument to open-audio:s "format"
(register default-format Int "MIX_DEFAULT_FORMAT")
(register init (Fn [Int] Int) "Mix_Init")
;; Argument to "init" function, can be xor:ed
(register ogg-support Int "MIX_INIT_OGG")
(register mp3-support Int "MIX_INIT_MP3")
(register mod-support Int "MIX_INIT_MOD")
(register flac-support Int "MIX_INIT_FLAC")
(register quit (Fn [] ()) "Mix_Quit")
;; Loading
(register load-wav
(Fn [(Ptr CChar)] (Ptr Mix_Chunk))
"Mix_LoadWAV")
(register load-music
(Fn [(Ptr CChar)] (Ptr Mix_Music))
"Mix_LoadMUS")
;; Playing samples (Mix_Chunk:s)
(register play-channel
;; args: channel chunk loops
;; ret: channel
(Fn [Int (Ptr Mix_Chunk) Int] Int)
"Mix_PlayChannel")
(register channel-playing?
(Fn [Int] Bool)
"Mix_Playing")
;; Music
(register nr-of-music-decoders
(Fn [] Int)
"Mix_GetNumMusicDecoders")
;; This function seems flakey, returns NULL?
(register get-music-decoder
(Fn [Int] (Ptr CChar))
"Mix_GetMusicDecoder")
(register play-music
;; args: music loops
;; ret: ok-code
(Fn [(Ptr Mix_Music) Int] Int)
"Mix_PlayMusic")
;; Error handling
(register get-error
(Fn [] (Ptr CChar))
"Mix_GetError")
;; Helpers
(defn ok? [error-code]
(= 0 error-code))
(def any-free-channel -1)
(defn valid-channel? [ch]
(not (= ch -1)))
)