1use std::{ffi::CString, fmt::Debug};
2
3use libc::{c_int, c_uint, c_void};
4
5use crate::ffi;
6
7#[repr(C)]
9#[derive(Debug, Clone)]
10pub struct Wave {
11 pub frame_count: c_uint,
12 pub sample_rate: c_uint,
13 pub sample_size: c_uint,
14 pub channels: c_uint,
15 pub data: *const c_void,
16}
17
18pub type AudioCallback = extern "C" fn(buffer_data: *const c_void, frames: c_uint);
19
20#[repr(C)]
22#[derive(Debug, Clone)]
23pub struct AudioStream {
24 pub buffer: *const c_void,
26 pub processor: *const c_void,
28
29 pub sample_rate: c_uint,
31 pub sample_size: c_uint,
33 pub channels: c_uint,
35}
36
37#[repr(C)]
39#[derive(Debug, Clone)]
40pub struct Sound {
41 pub stream: AudioStream,
43 pub frame_count: c_uint,
45}
46
47impl Sound {
48 pub fn new(path: String) -> Self {
49 unsafe { ffi::load_sound(CString::new(path).unwrap().as_ptr()) }
50 }
51
52 pub fn unload(self) {
53 unsafe {
54 ffi::unload_sound(self);
55 }
56 }
57
58 pub fn unload_alias(self) {
59 unsafe {
60 ffi::unload_sound_alias(self);
61 }
62 }
63}
64
65#[repr(C)]
66#[derive(Debug, Clone)]
67pub struct Music {
68 pub stream: AudioStream,
69 pub frame_count: c_uint,
70 pub looping: bool,
71
72 pub ctx_type: c_int,
73 pub ctx_data: *const c_void,
74}
75
76impl Music {
77 pub fn new(path: String) -> Self {
78 unsafe { ffi::load_music_stream(CString::new(path).unwrap().as_ptr()) }
79 }
80
81 pub fn unload(self) {
82 unsafe {
83 ffi::unload_music_stream(self);
84 }
85 }
86}