playdate_rs/sound/mod.rs
1mod file_player;
2mod sample;
3mod sample_player;
4mod sound_source;
5
6pub use file_player::FilePlayer;
7pub use sample::{AudioSample, AudioSampleData, SoundFormat};
8pub use sample_player::SamplePlayer;
9pub use sound_source::SoundSource;
10
11pub struct PlaydateSound {
12 #[allow(unused)]
13 handle: *const sys::playdate_sound,
14 // pub channel: *const playdate_sound_channel,
15 file_player: file_player::PlaydateFilePlayer,
16 sample: sample::PlaydateSample,
17 sample_player: sample_player::PlaydateSamplePlayer,
18 // pub synth: *const playdate_sound_synth,
19 // pub sequence: *const playdate_sound_sequence,
20 // pub effect: *const playdate_sound_effect,
21 // pub lfo: *const playdate_sound_lfo,
22 // pub envelope: *const playdate_sound_envelope,
23 source: sound_source::PlaydateSoundSource,
24 // pub controlsignal: *const playdate_control_signal,
25 // pub track: *const playdate_sound_track,
26 // pub instrument: *const playdate_sound_instrument,
27 // pub signal: *const playdate_sound_signal,
28}
29
30impl PlaydateSound {
31 pub(crate) fn new(handle: *const sys::playdate_sound) -> Self {
32 Self {
33 handle,
34 file_player: file_player::PlaydateFilePlayer::new(unsafe { (*handle).fileplayer }),
35 sample: sample::PlaydateSample::new(unsafe { (*handle).sample }),
36 sample_player: sample_player::PlaydateSamplePlayer::new(unsafe {
37 (*handle).sampleplayer
38 }),
39 source: sound_source::PlaydateSoundSource::new(unsafe { (*handle).source }),
40 }
41 }
42
43 /// Returns the sound engine’s current time value, in units of sample frames, 44,100 per second.
44 pub fn get_current_time(&self) -> u32 {
45 unsafe { (*self.handle).getCurrentTime.unwrap()() }
46 }
47
48 // pub getCurrentTime: ::core::option::Option<unsafe extern "C" fn() -> u32>,
49 // pub addSource: ::core::option::Option<
50 // unsafe extern "C" fn(
51 // callback: AudioSourceFunction,
52 // context: *mut ::core::ffi::c_void,
53 // stereo: ::core::ffi::c_int,
54 // ) -> *mut SoundSource,
55 // >,
56
57 // Returns the default channel, where sound sources play if they haven’t been explicity assigned to a different channel.
58 // pub(crate) fn get_default_channel(&self) -> Option<sys::SoundChannel> {
59 // let channel = unsafe { (*self.handle).getDefaultChannel.unwrap()() };
60 // if channel.is_null() {
61 // None
62 // } else {
63 // Some(SoundChannel::new(channel))
64 // }
65 // }
66
67 // pub getDefaultChannel: ::core::option::Option<unsafe extern "C" fn() -> *mut SoundChannel>,
68 // pub addChannel: ::core::option::Option<
69 // unsafe extern "C" fn(channel: *mut SoundChannel) -> ::core::ffi::c_int,
70 // >,
71 // pub removeChannel: ::core::option::Option<
72 // unsafe extern "C" fn(channel: *mut SoundChannel) -> ::core::ffi::c_int,
73 // >,
74 // pub setMicCallback: ::core::option::Option<
75 // unsafe extern "C" fn(
76 // callback: RecordCallback,
77 // context: *mut ::core::ffi::c_void,
78 // forceInternal: ::core::ffi::c_int,
79 // ),
80 // >,
81 // pub getHeadphoneState: ::core::option::Option<
82 // unsafe extern "C" fn(
83 // headphone: *mut ::core::ffi::c_int,
84 // headsetmic: *mut ::core::ffi::c_int,
85 // changeCallback: ::core::option::Option<
86 // unsafe extern "C" fn(headphone: ::core::ffi::c_int, mic: ::core::ffi::c_int),
87 // >,
88 // ),
89 // >,
90 // pub setOutputsActive: ::core::option::Option<
91 // unsafe extern "C" fn(headphone: ::core::ffi::c_int, speaker: ::core::ffi::c_int),
92 // >,
93 // pub removeSource: ::core::option::Option<
94 // unsafe extern "C" fn(source: *mut SoundSource) -> ::core::ffi::c_int,
95 // >,
96}