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 Wave
s by using Channel::queue_wave()
.
Implementations§
source§impl<Buffer> Wave<Buffer>where
Buffer: LinearAllocation + AsRef<[u8]>,
impl<Buffer> Wave<Buffer>where
Buffer: LinearAllocation + AsRef<[u8]>,
sourcepub fn new(buffer: Buffer, audio_format: AudioFormat, looping: bool) -> Self
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);
sourcepub fn get_buffer(&self) -> &[u8] ⓘ
pub fn get_buffer(&self) -> &[u8] ⓘ
Returns a slice to the audio data (on the LINEAR memory).
sourcepub fn get_buffer_mut(&mut self) -> Result<&mut [u8], Error>where
Buffer: AsMut<[u8]>,
pub fn get_buffer_mut(&mut self) -> Result<&mut [u8], Error>where
Buffer: AsMut<[u8]>,
sourcepub fn status(&self) -> Status
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));
sourcepub fn sample_count(&self) -> usize
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
.
sourcepub fn format(&self) -> AudioFormat
pub fn format(&self) -> AudioFormat
Returns the format of the audio data.
sourcepub fn set_sample_count(&mut self, sample_count: usize) -> Result<(), Error>
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.