Struct ctru::services::ndsp::wave::Wave

source ·
pub struct Wave<Buffer: LinearAllocation + AsRef<[u8]>> { /* private fields */ }
Expand description

Informational struct holding the raw audio data and playback info.

You can play audio Waves by using Channel::queue_wave().

Implementations§

source§

impl<Buffer> Wave<Buffer>
where Buffer: LinearAllocation + AsRef<[u8]>,

source

pub fn new(buffer: Buffer, audio_format: AudioFormat, looping: bool) -> Self

Build a new playable wave object from a raw buffer on LINEAR memory and some info.

§Example
use ctru::linear::LinearAllocator;
use ctru::services::ndsp::{AudioFormat, wave::Wave};

// Zeroed box allocated in the LINEAR memory.
let audio_data: Box<[_], _> = Box::new_in([0u8; 96], LinearAllocator);

let wave = Wave::new(audio_data, AudioFormat::PCM16Stereo, false);
source

pub fn get_buffer(&self) -> &[u8]

Returns a slice to the audio data (on the LINEAR memory).

source

pub fn get_buffer_mut(&mut self) -> Result<&mut [u8], Error>
where Buffer: AsMut<[u8]>,

Returns a mutable slice to the audio data (on the LINEAR memory).

§Errors

This function will return an error if the Wave is currently busy, with the id to the channel in which it’s queued.

source

pub fn status(&self) -> Status

Returns this wave’s playback status.

§Example
use ctru::services::ndsp::{AudioFormat, wave::{Wave, Status}};

// Provide your own audio data.
let wave = Wave::new(_audio_data, AudioFormat::PCM16Stereo, false);

// The `Wave` is free if never played before.
assert!(matches!(wave.status(), Status::Free));
source

pub fn sample_count(&self) -> usize

Returns the amount of samples read by the NDSP process.

§Notes

This value varies depending on Wave::set_sample_count.

source

pub fn format(&self) -> AudioFormat

Returns the format of the audio data.

source

pub fn set_sample_count(&mut self, sample_count: usize) -> Result<(), Error>

Set the amount of samples to be read.

§Note

This function doesn’t resize the internal buffer. Operations of this kind are particularly useful to allocate memory pools for VBR (Variable BitRate) formats, like OGG Vorbis.

§Errors

This function will return an error if the sample size exceeds the buffer’s capacity or if the Wave is currently queued.

Trait Implementations§

source§

impl<Buffer> Drop for Wave<Buffer>
where Buffer: LinearAllocation + AsRef<[u8]>,

source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl<Buffer> RefUnwindSafe for Wave<Buffer>
where Buffer: RefUnwindSafe,

§

impl<Buffer> !Send for Wave<Buffer>

§

impl<Buffer> !Sync for Wave<Buffer>

§

impl<Buffer> Unpin for Wave<Buffer>
where Buffer: Unpin,

§

impl<Buffer> UnwindSafe for Wave<Buffer>
where Buffer: 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.