Sample

Struct Sample 

Source
pub struct Sample<Api: Api = Default>(/* private fields */);

Implementations§

Source§

impl<Api: Default + Api> Sample<Api>

Source

pub fn new_with_size(bytes: c_int) -> Result<Self, Error>

Allocates and returns a new Sample with a buffer large enough to load a file of length bytes.

Equivalent to sys::ffi::playdate_sound_sample::newSampleBuffer

Source

pub fn new_for_file<P: AsRef<Path>>(path: P) -> Result<Self, ApiError>

Retrieves size of file and allocate with that size.

Does not load a file.

Uses sys::ffi::playdate_sound_sample::newSampleBuffer

Source

pub fn new_from_file<P: AsRef<Path>>(path: P) -> Result<Self, ApiError>

Loads the file into the self.

Equivalent to sys::ffi::playdate_sound_sample::load

Source

pub fn new_from_data<'t>( data: &'t mut [u8], format: SoundFormat, sample_rate: u32, ) -> Result<SampleWithData<'t, Api>, Error>

Returns a new Sample referencing the given audio data.

The sample keeps a reference to the data instead of copying it, so the data must remain valid while the sample is active.

Equivalent to sys::ffi::playdate_sound_sample::newSampleFromData

Source§

impl<Api: Api> Sample<Api>

Source

pub fn new_with_size_with(api: Api, bytes: c_int) -> Result<Self, Error>

Allocates and returns a new Sample with a buffer large enough to load a file of length bytes.

Equivalent to sys::ffi::playdate_sound_sample::newSampleBuffer

Source

pub fn new_for_file_with<P: AsRef<Path>>( api: Api, path: P, ) -> Result<Self, ApiError>

Retrieves size of file and allocate with that size.

Does not load a file.

Uses sys::ffi::playdate_sound_sample::newSampleBuffer

Source

pub fn new_from_file_with<P: AsRef<Path>>( api: Api, path: P, ) -> Result<Self, ApiError>

Loads the file into the self.

Equivalent to sys::ffi::playdate_sound_sample::load

Source

pub fn new_from_data_with<'t>( api: Api, data: &'t mut [u8], format: SoundFormat, sample_rate: u32, ) -> Result<SampleWithData<'t, Api>, Error>

Returns a new Sample referencing the given audio data.

The sample keeps a reference to the data instead of copying it, so the data must remain valid while the sample is active.

Equivalent to sys::ffi::playdate_sound_sample::newSampleFromData

Source§

impl<Api: Api> Sample<Api>

Source

pub fn length(&self) -> c_float

Returns the length, in seconds.

Equivalent to sys::ffi::playdate_sound_sample::getLength

Source

pub fn get_data<'t>(&'t self) -> SampleData<'t>

Trait Implementations§

Source§

impl<Api: Api> AsRef<Sample<Api>> for SampleWithData<'_, Api>

Source§

fn as_ref(&self) -> &Sample<Api>

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl<Api: Debug + Api> Debug for Sample<Api>

Source§

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

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

impl<Api: Api> Drop for Sample<Api>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl<Api> Freeze for Sample<Api>
where Api: Freeze,

§

impl<Api> RefUnwindSafe for Sample<Api>
where Api: RefUnwindSafe,

§

impl<Api = Default> !Send for Sample<Api>

§

impl<Api = Default> !Sync for Sample<Api>

§

impl<Api> Unpin for Sample<Api>
where Api: Unpin,

§

impl<Api> UnwindSafe for Sample<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, 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.