Struct ctru::services::ndsp::Channel

source ·
pub struct Channel<'ndsp> { /* private fields */ }
Expand description

NDSP Channel representation.

There are 24 individual channels in total and each can play a different audio Wave simultaneuosly.

§Default

NDSP initialises all channels with default values on initialization, but the developer is supposed to change these values to correctly work with the service.

In particular:

The handle to a channel can be retrieved with Ndsp::channel()

Implementations§

source§

impl Channel<'_>

source

pub fn reset(&mut self)

Reset the channel (clear the queue and reset parameters).

§Example
use ctru::services::ndsp::Ndsp;
let ndsp = Ndsp::new()?;
let mut channel_0 = ndsp.channel(0)?;

channel_0.reset();
source

pub fn init_parameters(&mut self)

Initialize the channel’s parameters with default values.

§Example
use ctru::services::ndsp::Ndsp;
let ndsp = Ndsp::new()?;
let mut channel_0 = ndsp.channel(0)?;

channel_0.init_parameters();
source

pub fn is_playing(&self) -> bool

Returns whether the channel is playing any audio.

§Example
use ctru::services::ndsp::Ndsp;
let ndsp = Ndsp::new()?;
let mut channel_0 = ndsp.channel(0)?;

// The channel is not playing any audio.
assert!(!channel_0.is_playing());
source

pub fn is_paused(&self) -> bool

Returns whether the channel’s playback is currently paused.

§Example
use ctru::services::ndsp::Ndsp;
let ndsp = Ndsp::new()?;
let mut channel_0 = ndsp.channel(0)?;

// The channel is not paused.
assert!(!channel_0.is_paused());
source

pub fn id(&self) -> u8

Returns the channel’s index.

§Example
use ctru::services::ndsp::Ndsp;
let ndsp = Ndsp::new()?;
let mut channel_0 = ndsp.channel(0)?;

// The channel's index is 0.
assert_eq!(channel_0.id(), 0);
source

pub fn sample_position(&self) -> usize

Returns the index of the currently played sample.

Because of how fast this value changes, it should only be used as a rough estimate of the current progress.

source

pub fn wave_sequence_id(&self) -> u16

Returns the channel’s current wave sequence’s id.

source

pub fn set_paused(&mut self, state: bool)

Pause or un-pause the channel’s playback.

§Example
use ctru::services::ndsp::Ndsp;
let ndsp = Ndsp::new()?;
let mut channel_0 = ndsp.channel(0)?;

channel_0.set_paused(true);

// The channel is paused.
assert!(channel_0.is_paused());
source

pub fn set_format(&mut self, format: AudioFormat)

Set the channel’s output format.

Change this setting based on the used wave’s format.

§Example
use ctru::services::ndsp::{AudioFormat, Ndsp};
let ndsp = Ndsp::new()?;
let mut channel_0 = ndsp.channel(0)?;

// Use the PCM16 interleaved dual-channel audio format.
channel_0.set_format(AudioFormat::PCM16Stereo);
source

pub fn set_interpolation(&mut self, interp_type: InterpolationType)

Set the channel’s interpolation mode.

§Example
use ctru::services::ndsp::{InterpolationType, Ndsp};
let ndsp = Ndsp::new()?;
let mut channel_0 = ndsp.channel(0)?;

// Use linear interpolation within frames.
channel_0.set_interpolation(InterpolationType::Linear);
source

pub fn set_mix(&mut self, mix: &AudioMix)

Set the channel’s volume mix.

Look at AudioMix for more information on the volume mix.

§Example
use ctru::services::ndsp::{AudioMix, Ndsp};
let ndsp = Ndsp::new()?;
let mut channel_0 = ndsp.channel(0)?;

// Front-left and front-right channel maxed.
channel_0.set_mix(&AudioMix::default());
source

pub fn set_sample_rate(&mut self, rate: f32)

Set the channel’s rate of sampling in hertz.

§Example
use ctru::services::ndsp::Ndsp;
let ndsp = Ndsp::new()?;
let mut channel_0 = ndsp.channel(0)?;

// Standard CD sample rate. (44100 Hz)
channel_0.set_sample_rate(44100.);
source

pub fn clear_queue(&mut self)

Clear the wave buffer queue and stop playback.

§Example
use ctru::services::ndsp::Ndsp;
let ndsp = Ndsp::new()?;
let mut channel_0 = ndsp.channel(0)?;

// Clear the audio queue and stop playback.
channel_0.clear_queue();
source

pub fn queue_wave<Buffer: LinearAllocation + AsRef<[u8]>>( &mut self, wave: &mut Wave<Buffer> ) -> Result<(), Error>

Add a wave buffer to the channel’s queue. If there are no other buffers in queue, playback for this buffer will start.

§Warning

libctru expects the user to manually keep the info data (in this case Wave) alive during playback. To ensure safety, checks within Wave will clear the whole channel queue if any queued Wave is dropped prematurely.

§Example
use ctru::services::ndsp::wave::Wave;
use ctru::services::ndsp::{AudioFormat, Ndsp};
let ndsp = Ndsp::new()?;
let mut channel_0 = ndsp.channel(0)?;


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

// Clear the audio queue and stop playback.
channel_0.queue_wave(&mut wave);
source§

impl Channel<'_>

Functions to handle audio filtering.

Refer to libctru for more info.

source

pub fn iir_mono_set_enabled(&mut self, enable: bool)

Enables/disables monopole filters.

source

pub fn iir_mono_set_params_high_pass_filter(&mut self, cut_off_freq: f32)

Set the monopole to be a high pass filter.

§Notes

This is a lower quality filter than the Biquad alternative.

source

pub fn iir_mono_set_params_low_pass_filter(&mut self, cut_off_freq: f32)

Set the monopole to be a low pass filter.

§Notes

This is a lower quality filter than the Biquad alternative.

source

pub fn iir_biquad_set_enabled(&mut self, enable: bool)

Enables/disables biquad filters.

source

pub fn iir_biquad_set_params_high_pass_filter( &mut self, cut_off_freq: f32, quality: f32 )

Set the biquad to be a high pass filter.

source

pub fn iir_biquad_set_params_low_pass_filter( &mut self, cut_off_freq: f32, quality: f32 )

Set the biquad to be a low pass filter.

source

pub fn iir_biquad_set_params_notch_filter( &mut self, notch_freq: f32, quality: f32 )

Set the biquad to be a notch filter.

source

pub fn iir_biquad_set_params_band_pass_filter( &mut self, mid_freq: f32, quality: f32 )

Set the biquad to be a band pass filter.

source

pub fn iir_biquad_set_params_peaking_equalizer( &mut self, central_freq: f32, quality: f32, gain: f32 )

Set the biquad to be a peaking equalizer.

Auto Trait Implementations§

§

impl<'ndsp> !RefUnwindSafe for Channel<'ndsp>

§

impl<'ndsp> !Send for Channel<'ndsp>

§

impl<'ndsp> !Sync for Channel<'ndsp>

§

impl<'ndsp> Unpin for Channel<'ndsp>

§

impl<'ndsp> !UnwindSafe for Channel<'ndsp>

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.