Carp/core/SDL_mixer.carp

80 lines
1.9 KiB
Plaintext
Raw Permalink Normal View History

2018-03-23 11:55:32 +03:00
(system-include "SDL2/SDL_mixer.h")
2019-06-14 11:46:15 +03:00
(add-pkg "SDL2_mixer")
2018-03-23 11:55:32 +03:00
(Project.config "cflag" "-Wno-incompatible-pointer-types-discards-qualifiers")
(register-type Mix_Chunk)
(register-type Mix_Music)
(defmodule Mixer
;; Setup
2018-03-23 11:55:32 +03:00
(register open-audio
;; freq format channels chunksize
(Fn [Int Int Int Int] Int)
2018-03-23 11:55:32 +03:00
"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
2020-05-11 17:10:35 +03:00
(Fn [(Ptr CChar)] (Ptr Mix_Chunk))
"Mix_LoadWAV")
(register load-music
2020-05-11 17:10:35 +03:00
(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
2020-05-11 17:10:35 +03:00
(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
2020-05-11 17:10:35 +03:00
(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)))
2018-03-23 11:55:32 +03:00
)