diff options
| author | Polesznyák Márk <contact@pml68.dev> | 2026-02-21 00:22:30 +0100 |
|---|---|---|
| committer | Polesznyák Márk <contact@pml68.dev> | 2026-02-21 00:22:30 +0100 |
| commit | 5d2ef703d4d1e998ae1f1e8f79ee0f70c37a8082 (patch) | |
| tree | 8d3ded6b650f292411c4210a9f5eaf0da7f19a0a /sdl_audio.ha | |
| parent | chore: build in release mode (diff) | |
| download | hare-chip8-5d2ef703d4d1e998ae1f1e8f79ee0f70c37a8082.tar.gz | |
feat: add audio
Diffstat (limited to '')
| -rw-r--r-- | sdl_audio.ha | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/sdl_audio.ha b/sdl_audio.ha new file mode 100644 index 0000000..545668c --- /dev/null +++ b/sdl_audio.ha @@ -0,0 +1,53 @@ +use sdl2; +use types::c; + +type SDL_AudioFormat = u16; + +def AUDIO_U8: SDL_AudioFormat = 0x0008; +def AUDIO_S8: SDL_AudioFormat = 0x8008; +def AUDIO_U16LSB: SDL_AudioFormat = 0x0010; +def AUDIO_S16LSB: SDL_AudioFormat = 0x8010; +def AUDIO_U16MSB: SDL_AudioFormat = 0x1010; +def AUDIO_S16MSB: SDL_AudioFormat = 0x9010; +def AUDIO_U16: SDL_AudioFormat = AUDIO_U16LSB; +def AUDIO_S16: SDL_AudioFormat = AUDIO_S16LSB; +def AUDIO_S32LSB: SDL_AudioFormat = 0x8020; +def AUDIO_S32MSB: SDL_AudioFormat = 0x9020; +def AUDIO_S32: SDL_AudioFormat = AUDIO_S32LSB; +def AUDIO_F32LSB: SDL_AudioFormat = 0x8120; +def AUDIO_F32MSB: SDL_AudioFormat = 0x9120; +def AUDIO_F32: SDL_AudioFormat = AUDIO_F32LSB; + +type SDL_AudioCallback = *fn(userdata: nullable *opaque, stream: *u8, len_: int) void; + +type SDL_AudioSpec = struct { + freq: int, + format: SDL_AudioFormat, + channels: u8, + silence: u8, + samples: u16, + padding: u16, + size_: u32, + callback: SDL_AudioCallback, + userdata: nullable *opaque +}; + +type SDL_AudioDeviceID = u32; + +@symbol("SDL_OpenAudioDevice") fn _SDL_OpenAudioDevice(device: nullable *c::char, iscapture: int, desired: const *SDL_AudioSpec, obtained: *SDL_AudioSpec, allowed_changes: int) SDL_AudioDeviceID; + +@symbol("SDL_CloseAudioDevice") fn SDL_CloseAudioDevice(dev: SDL_AudioDeviceID) void; + +@symbol("SDL_PauseAudioDevice") fn SDL_PauseAudioDevice(dev: SDL_AudioDeviceID, pause_on: int) void; + +@symbol("SDL_GetError") fn SDL_GetError() const *c::char; + +fn SDL_OpenAudioDevice(device: nullable *c::char, iscapture: int, desired: const *SDL_AudioSpec, obtained: *SDL_AudioSpec, allowed_changes: int) (SDL_AudioDeviceID | sdl2::error) = { + const ret = _SDL_OpenAudioDevice(device, iscapture, desired, obtained, allowed_changes); + + if (ret == 0) { + return c::tostr(SDL_GetError()): sdl2::error; + }; + + return ret; +}; |
