pub struct Sound<Api = Default>(/* private fields */);
Implementations§
source§impl Sound
impl Sound
sourcepub fn Default() -> Sound
pub fn Default() -> Sound
Creates default Sound
without type parameter requirement.
Uses ZST api::Default
.
source§impl<Api> Sound<Api>where
Api: Api,
impl<Api> Sound<Api>where
Api: Api,
sourcepub fn current_time(&self) -> u32
pub fn current_time(&self) -> u32
Returns the sound engine’s current time value, in units of sample frames, 44100
per second.
Equivalent to sys::ffi::playdate_sound::getCurrentTime
sourcepub fn headphone_state(
&self,
headphone: Option<&mut i32>,
mic: Option<&mut i32>
)
pub fn headphone_state( &self, headphone: Option<&mut i32>, mic: Option<&mut i32> )
If headphone
is Some
, the value is set to 1 if headphones are currently plugged in.
Likewise, mic
is set if the headphones include a microphone.
Example:
let mut headphone = Some(0);
let mut mic = Some(0);
sound.headphone_state(headphone.as_mut(), mic.as_mut());
println!( "{}/{}", current_frame.unwrap(), mic.unwrap());
sourcepub fn set_headphone_state_change_callback(
&self,
headphone: Option<&mut i32>,
mic: Option<&mut i32>,
change_callback: Option<unsafe extern "C" fn(_: i32, _: i32)>
)
pub fn set_headphone_state_change_callback( &self, headphone: Option<&mut i32>, mic: Option<&mut i32>, change_callback: Option<unsafe extern "C" fn(_: i32, _: i32)> )
If headphone
is Some
, the value is set to 1 if headphones are currently plugged in.
Likewise, mic
is set if the headphones include a microphone.
If change_callback
is provided, it will be called when the headset or mic status changes,
and audio output will not automatically switch from speaker to headphones when headphones are plugged in (and vice versa).
In this case, the callback should use Sound::set_outputs_active
to change the output if needed.
Equivalent to sys::ffi::playdate_sound::getHeadphoneState
sourcepub fn set_outputs_active(&self, headphone: bool, speaker: bool)
pub fn set_outputs_active(&self, headphone: bool, speaker: bool)
Force audio output to the given outputs, regardless of headphone status.
Equivalent to sys::ffi::playdate_sound::setOutputsActive
sourcepub fn add_source_raw(
&self,
callback: Option<unsafe extern "C" fn(_: *mut c_void, _: *mut i16, _: *mut i16, _: i32) -> i32>,
context: *mut c_void,
stereo: bool
) -> SoundSource
pub fn add_source_raw( &self, callback: Option<unsafe extern "C" fn(_: *mut c_void, _: *mut i16, _: *mut i16, _: i32) -> i32>, context: *mut c_void, stereo: bool ) -> SoundSource
The callback function you pass in will be called every audio render cycle.
// AudioSourceFunction:
unsafe extern "C" fn(context: *mut c_void, left: *mut i16, right: *mut i16, len: c_int) -> c_int
This function should fill the passed-in left
buffer (and right
if it’s a stereo source)
with len
samples each and return 1,
or return 0 if the source is silent through the cycle.
Equivalent to sys::ffi::playdate_sound::addSource
sourcepub fn remove_source(&self, source: &SoundSource) -> bool
pub fn remove_source(&self, source: &SoundSource) -> bool
Removes the given SoundSource
object from its channel,
whether it’s in the default channel or a channel created with [Sound::add_channel
].
Returns true
if a source was removed, false
if the source wasn’t in a channel.
Equivalent to sys::ffi::playdate_sound::removeSource
Trait Implementations§
impl<Api> Copy for Sound<Api>where
Api: Copy,
Auto Trait Implementations§
impl<Api> Freeze for Sound<Api>where
Api: Freeze,
impl<Api> RefUnwindSafe for Sound<Api>where
Api: RefUnwindSafe,
impl<Api> Send for Sound<Api>where
Api: Send,
impl<Api> Sync for Sound<Api>where
Api: Sync,
impl<Api> Unpin for Sound<Api>where
Api: Unpin,
impl<Api> UnwindSafe for Sound<Api>where
Api: UnwindSafe,
Blanket Implementations§
§impl<T> Any for Twhere
T: 'static + ?Sized,
impl<T> Any for Twhere
T: 'static + ?Sized,
§impl<T> Borrow<T> for Twhere
T: ?Sized,
impl<T> Borrow<T> for Twhere
T: ?Sized,
§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T, U> Into<U> for Twhere
U: From<T>,
impl<T, U> Into<U> for Twhere
U: From<T>,
§impl<T> ToOwned for Twhere
T: Clone,
impl<T> ToOwned for Twhere
T: Clone,
§impl<T, U> TryFrom<U> for Twhere
U: Into<T>,
impl<T, U> TryFrom<U> for Twhere
U: Into<T>,
Layout§
Note: Unable to compute type layout, possibly due to this type having generic parameters. Layout can only be computed for concrete, fully-instantiated types.