Carp/core/SDL_mixer.carp
Jorge Acereda 9b08b6df3c Merge
2020-05-11 16:10:35 +02:00

80 lines
1.9 KiB
Plaintext

(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)))
)