diff options
| author | Polesznyák Márk <contact@pml68.dev> | 2026-04-06 23:44:45 +0200 |
|---|---|---|
| committer | Polesznyák Márk <contact@pml68.dev> | 2026-04-06 23:44:45 +0200 |
| commit | 6637fdded6f3c5fba7e7a378ca7e30d0db11f27d (patch) | |
| tree | 40f8868ae2140680645b1f90f4a1fc2a378920b3 /vendor/hare-sdl2/sdl2/mixer/samples.ha | |
| parent | docs: add README (diff) | |
| parent | Add ! after c::fromstr calls to handle nomem (diff) | |
| download | hare-chip8-6637fdded6f3c5fba7e7a378ca7e30d0db11f27d.tar.gz | |
Add 'vendor/hare-sdl2/' from commit 'fb6008be0b79a2a24b1ac960316a83f7873b4f39'
git-subtree-dir: vendor/hare-sdl2
git-subtree-mainline: ed088aa81ac23fa48d5ae48ee739c97e0fcb4490
git-subtree-split: fb6008be0b79a2a24b1ac960316a83f7873b4f39
Diffstat (limited to '')
| -rw-r--r-- | vendor/hare-sdl2/sdl2/mixer/samples.ha | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/vendor/hare-sdl2/sdl2/mixer/samples.ha b/vendor/hare-sdl2/sdl2/mixer/samples.ha new file mode 100644 index 0000000..ad1ecc1 --- /dev/null +++ b/vendor/hare-sdl2/sdl2/mixer/samples.ha @@ -0,0 +1,38 @@ +use fs; +use io; +use os; +use sdl2; + +// The internal format for an audio Mix_Chunk +export type Mix_Chunk = struct { + allocated: int, + abuf: *u8, + alen: u32, + volume: u8, +}; + +@symbol("Mix_LoadWAV_RW") fn _Mix_LoadWAV_RW(src: *sdl2::SDL_RWops, freesrc: int) nullable *Mix_Chunk; + +// Loads a sample from an [[io::handle]]. +export fn Mix_LoadWAV_RW(src: io::handle) (*Mix_Chunk | sdl2::error) = { + const rw = sdl2::rw_from_handle(src); + return sdl2::wrapptr(_Mix_LoadWAV_RW(rw, 0))?: *Mix_Chunk; +}; + +// Loads a sample from a file path. +export fn load_file(src: str) (*Mix_Chunk | fs::error | sdl2::error) = { + const file = os::open(src)?; + defer io::close(file)!; + return Mix_LoadWAV_RW(file); +}; + +// Free the memory used in Mix_Chunk, and free Mix_Chunk itself as well. Do not use +// Mix_Chunk after this without loading a new sample to it. Note: It's a bad idea to +// free a Mix_Chunk that is still being played... +export @symbol("Mix_FreeChunk") fn Mix_FreeChunk(Mix_Chunk: *Mix_Chunk) void; + +// Maximum volume for a Mix_Chunk. +export def MIX_MAX_VOLUME: int = 128; // XXX: SDL_mixer derives this from SDL_MIX_MAXVOLUME + +// Sets the Mix_Chunk volume as specified, returning the previous value. +export @symbol("Mix_VolumeChunk") fn Mix_VolumeChunk(Mix_Chunk: *Mix_Chunk, volume: int) int; |
