Struct playdate::sound::Sound

source ·
pub struct Sound<Api = Default>(/* private fields */);

Implementations§

source§

impl Sound

source

pub fn Default() -> Sound

Creates default Sound without type parameter requirement.

Uses ZST api::Default.

source§

impl Sound<Cache>

source

pub fn Cached() -> Sound<Cache>

Creates Sound without type parameter requirement.

Uses api::Cache.

source§

impl<Api> Sound<Api>
where Api: Default + Api,

source

pub fn new() -> Sound<Api>

source§

impl<Api> Sound<Api>
where Api: Api,

source

pub fn new_with(api: Api) -> Sound<Api>

source§

impl<Api> Sound<Api>
where Api: Api,

source

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

source

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());

See also Sound::set_headphone_state_change_callback.

source

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

source

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

source

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

source

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§

source§

impl<Api> Clone for Sound<Api>
where Api: Clone,

source§

fn clone(&self) -> Sound<Api>

Returns a copy of the value. Read more
1.0.0§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<Api> Debug for Sound<Api>
where Api: Debug,

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
source§

impl<Api> Default for Sound<Api>
where Api: Default + Api,

source§

fn default() -> Sound<Api>

Returns the “default value” for a type. Read more
source§

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 T
where T: 'static + ?Sized,

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<T> Borrow<T> for T
where T: ?Sized,

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

impl<T> BorrowMut<T> for T
where T: ?Sized,

§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T, U> Into<U> for T
where U: From<T>,

§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of [From]<T> for U chooses to do.

§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.

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.