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:
- Default audio format is set to
AudioFormat::PCM16Mono
. - Default sample rate is set to 1 Hz.
- Default interpolation type is set to
InterpolationType::Polyphase
. - Default mix is set to
AudioMix::default()
The handle to a channel can be retrieved with Ndsp::channel()
Implementations§
source§impl Channel<'_>
impl Channel<'_>
sourcepub fn reset(&mut self)
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();
sourcepub fn init_parameters(&mut self)
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();
sourcepub fn is_playing(&self) -> bool
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());
sourcepub fn is_paused(&self) -> bool
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());
sourcepub fn id(&self) -> u8
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);
sourcepub fn sample_position(&self) -> usize
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.
sourcepub fn wave_sequence_id(&self) -> u16
pub fn wave_sequence_id(&self) -> u16
Returns the channel’s current wave sequence’s id.
sourcepub fn set_paused(&mut self, state: bool)
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());
sourcepub fn set_format(&mut self, format: AudioFormat)
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);
sourcepub fn set_interpolation(&mut self, interp_type: InterpolationType)
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);
sourcepub fn set_sample_rate(&mut self, rate: f32)
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.);
sourcepub fn clear_queue(&mut self)
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();
sourcepub fn queue_wave<Buffer: LinearAllocation + AsRef<[u8]>>(
&mut self,
wave: &mut Wave<Buffer>
) -> Result<(), Error>
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<'_>
impl Channel<'_>
Functions to handle audio filtering.
Refer to libctru
for more info.
sourcepub fn iir_mono_set_enabled(&mut self, enable: bool)
pub fn iir_mono_set_enabled(&mut self, enable: bool)
Enables/disables monopole filters.
sourcepub fn iir_mono_set_params_high_pass_filter(&mut self, cut_off_freq: f32)
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.
sourcepub fn iir_mono_set_params_low_pass_filter(&mut self, cut_off_freq: f32)
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.
sourcepub fn iir_biquad_set_enabled(&mut self, enable: bool)
pub fn iir_biquad_set_enabled(&mut self, enable: bool)
Enables/disables biquad filters.
sourcepub fn iir_biquad_set_params_high_pass_filter(
&mut self,
cut_off_freq: f32,
quality: f32
)
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.
sourcepub fn iir_biquad_set_params_low_pass_filter(
&mut self,
cut_off_freq: f32,
quality: f32
)
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.
sourcepub fn iir_biquad_set_params_notch_filter(
&mut self,
notch_freq: f32,
quality: f32
)
pub fn iir_biquad_set_params_notch_filter( &mut self, notch_freq: f32, quality: f32 )
Set the biquad to be a notch filter.
sourcepub fn iir_biquad_set_params_band_pass_filter(
&mut self,
mid_freq: f32,
quality: f32
)
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.
sourcepub fn iir_biquad_set_params_peaking_equalizer(
&mut self,
central_freq: f32,
quality: f32,
gain: f32
)
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.