|
|
|
@ -22,8 +22,6 @@ pub enum AudioFormat {
@@ -22,8 +22,6 @@ pub enum AudioFormat {
|
|
|
|
|
ADPCMMono = ctru_sys::NDSP_FORMAT_MONO_ADPCM, |
|
|
|
|
PCM8Stereo = ctru_sys::NDSP_FORMAT_STEREO_PCM8, |
|
|
|
|
PCM16Stereo = ctru_sys::NDSP_FORMAT_STEREO_PCM16, |
|
|
|
|
FrontBypass = ctru_sys::NDSP_FRONT_BYPASS, |
|
|
|
|
SurroundPreprocessed = ctru_sys::NDSP_3D_SURROUND_PREPROCESSED, |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
#[derive(Copy, Clone, Debug)] |
|
|
|
@ -34,13 +32,10 @@ pub enum InterpolationType {
@@ -34,13 +32,10 @@ pub enum InterpolationType {
|
|
|
|
|
None = ctru_sys::NDSP_INTERP_NONE, |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
pub struct Channel { |
|
|
|
|
id: i32, |
|
|
|
|
} |
|
|
|
|
pub struct Channel(i32); |
|
|
|
|
|
|
|
|
|
static NDSP_ACTIVE: Mutex<usize> = Mutex::new(0); |
|
|
|
|
|
|
|
|
|
#[non_exhaustive] |
|
|
|
|
pub struct Ndsp { |
|
|
|
|
_service_handler: ServiceReference, |
|
|
|
|
} |
|
|
|
@ -73,7 +68,7 @@ impl Ndsp {
@@ -73,7 +68,7 @@ impl Ndsp {
|
|
|
|
|
return Err(crate::Error::InvalidChannel(id.into())); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Ok(Channel { id: id.into() }) |
|
|
|
|
Ok(Channel(id.into())) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/// Set the audio output mode. Defaults to `OutputMode::Stereo`.
|
|
|
|
@ -88,66 +83,66 @@ impl Ndsp {
@@ -88,66 +83,66 @@ impl Ndsp {
|
|
|
|
|
impl Channel { |
|
|
|
|
/// Reset the channel
|
|
|
|
|
pub fn reset(&self) { |
|
|
|
|
unsafe { ctru_sys::ndspChnReset(self.id) }; |
|
|
|
|
unsafe { ctru_sys::ndspChnReset(self.0) }; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/// Initialize the channel's parameters
|
|
|
|
|
pub fn init_parameters(&self) { |
|
|
|
|
unsafe { ctru_sys::ndspChnInitParams(self.id) }; |
|
|
|
|
unsafe { ctru_sys::ndspChnInitParams(self.0) }; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/// Returns whether the channel is playing any audio.
|
|
|
|
|
pub fn is_playing(&self) -> bool { |
|
|
|
|
unsafe { ctru_sys::ndspChnIsPlaying(self.id) } |
|
|
|
|
unsafe { ctru_sys::ndspChnIsPlaying(self.0) } |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/// Returns whether the channel's playback is currently paused.
|
|
|
|
|
pub fn is_paused(&self) -> bool { |
|
|
|
|
unsafe { ctru_sys::ndspChnIsPaused(self.id) } |
|
|
|
|
unsafe { ctru_sys::ndspChnIsPaused(self.0) } |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/// Returns the channel's current sample's position.
|
|
|
|
|
pub fn get_sample_position(&self) -> u32 { |
|
|
|
|
unsafe { ctru_sys::ndspChnGetSamplePos(self.id) } |
|
|
|
|
unsafe { ctru_sys::ndspChnGetSamplePos(self.0) } |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/// Returns the channel's current wave sequence's id.
|
|
|
|
|
pub fn get_wave_sequence_id(&self) -> u16 { |
|
|
|
|
unsafe { ctru_sys::ndspChnGetWaveBufSeq(self.id) } |
|
|
|
|
unsafe { ctru_sys::ndspChnGetWaveBufSeq(self.0) } |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/// Pause or un-pause the channel's playback.
|
|
|
|
|
pub fn set_paused(&self, state: bool) { |
|
|
|
|
unsafe { ctru_sys::ndspChnSetPaused(self.id, state) }; |
|
|
|
|
unsafe { ctru_sys::ndspChnSetPaused(self.0, state) }; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/// Set the channel's output format.
|
|
|
|
|
/// Change this setting based on the used sample's format.
|
|
|
|
|
pub fn set_format(&self, format: AudioFormat) { |
|
|
|
|
unsafe { ctru_sys::ndspChnSetFormat(self.id, format as u16) }; |
|
|
|
|
unsafe { ctru_sys::ndspChnSetFormat(self.0, format as u16) }; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/// Set the channel's interpolation mode.
|
|
|
|
|
pub fn set_interpolation(&self, interp_type: InterpolationType) { |
|
|
|
|
unsafe { ctru_sys::ndspChnSetInterp(self.id, interp_type as u32) }; |
|
|
|
|
unsafe { ctru_sys::ndspChnSetInterp(self.0, interp_type as u32) }; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/// Set the channel's volume mix.
|
|
|
|
|
/// Docs about the buffer usage: https://libctru.devkitpro.org/channel_8h.html#a30eb26f1972cc3ec28370263796c0444
|
|
|
|
|
pub fn set_mix(&self, mix: &[f32; 12]) { |
|
|
|
|
unsafe { ctru_sys::ndspChnSetMix(self.id, mix.as_ptr().cast_mut()) } |
|
|
|
|
unsafe { ctru_sys::ndspChnSetMix(self.0, mix.as_ptr().cast_mut()) } |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/// Set the channel's rate of sampling.
|
|
|
|
|
pub fn set_sample_rate(&self, rate: f32) { |
|
|
|
|
unsafe { ctru_sys::ndspChnSetRate(self.id, rate) }; |
|
|
|
|
unsafe { ctru_sys::ndspChnSetRate(self.0, rate) }; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// TODO: find a way to wrap `ndspChnSetAdpcmCoefs`
|
|
|
|
|
|
|
|
|
|
/// Clear the wave buffer queue and stop playback.
|
|
|
|
|
pub fn clear_queue(&self) { |
|
|
|
|
unsafe { ctru_sys::ndspChnWaveBufClear(self.id) }; |
|
|
|
|
unsafe { ctru_sys::ndspChnWaveBufClear(self.0) }; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/// Add a wave buffer to the channel's queue.
|
|
|
|
@ -164,9 +159,9 @@ impl Channel {
@@ -164,9 +159,9 @@ impl Channel {
|
|
|
|
|
_ => (), |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
wave.set_channel(self.id); |
|
|
|
|
wave.set_channel(self.0); |
|
|
|
|
|
|
|
|
|
unsafe { ctru_sys::ndspChnWaveBufAdd(self.id, &mut wave.raw_data) }; |
|
|
|
|
unsafe { ctru_sys::ndspChnWaveBufAdd(self.0, &mut wave.raw_data) }; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// FILTERS
|
|
|
|
@ -174,25 +169,25 @@ impl Channel {
@@ -174,25 +169,25 @@ impl Channel {
|
|
|
|
|
// TODO: Add Mono filters (and maybe setup the filter functions in a better way)
|
|
|
|
|
|
|
|
|
|
pub fn iir_biquad_set_enabled(&self, enable: bool) { |
|
|
|
|
unsafe { ctru_sys::ndspChnIirBiquadSetEnable(self.id, enable) }; |
|
|
|
|
unsafe { ctru_sys::ndspChnIirBiquadSetEnable(self.0, enable) }; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
pub fn iir_biquad_set_params_high_pass_filter(&self, cut_off_freq: f32, quality: f32) { |
|
|
|
|
unsafe { |
|
|
|
|
ctru_sys::ndspChnIirBiquadSetParamsHighPassFilter(self.id, cut_off_freq, quality) |
|
|
|
|
ctru_sys::ndspChnIirBiquadSetParamsHighPassFilter(self.0, cut_off_freq, quality) |
|
|
|
|
}; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
pub fn iir_biquad_set_params_low_pass_filter(&self, cut_off_freq: f32, quality: f32) { |
|
|
|
|
unsafe { ctru_sys::ndspChnIirBiquadSetParamsLowPassFilter(self.id, cut_off_freq, quality) }; |
|
|
|
|
unsafe { ctru_sys::ndspChnIirBiquadSetParamsLowPassFilter(self.0, cut_off_freq, quality) }; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
pub fn iir_biquad_set_params_notch_filter(&self, notch_freq: f32, quality: f32) { |
|
|
|
|
unsafe { ctru_sys::ndspChnIirBiquadSetParamsNotchFilter(self.id, notch_freq, quality) }; |
|
|
|
|
unsafe { ctru_sys::ndspChnIirBiquadSetParamsNotchFilter(self.0, notch_freq, quality) }; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
pub fn iir_biquad_set_params_band_pass_filter(&self, mid_freq: f32, quality: f32) { |
|
|
|
|
unsafe { ctru_sys::ndspChnIirBiquadSetParamsBandPassFilter(self.id, mid_freq, quality) }; |
|
|
|
|
unsafe { ctru_sys::ndspChnIirBiquadSetParamsBandPassFilter(self.0, mid_freq, quality) }; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
pub fn iir_biquad_set_params_peaking_equalizer( |
|
|
|
@ -203,7 +198,7 @@ impl Channel {
@@ -203,7 +198,7 @@ impl Channel {
|
|
|
|
|
) { |
|
|
|
|
unsafe { |
|
|
|
|
ctru_sys::ndspChnIirBiquadSetParamsPeakingEqualizer( |
|
|
|
|
self.id, |
|
|
|
|
self.0, |
|
|
|
|
central_freq, |
|
|
|
|
quality, |
|
|
|
|
gain, |
|
|
|
@ -222,13 +217,6 @@ impl AudioFormat {
@@ -222,13 +217,6 @@ impl AudioFormat {
|
|
|
|
|
AudioFormat::PCM8Mono | AudioFormat::ADPCMMono => 1, |
|
|
|
|
AudioFormat::PCM16Mono | AudioFormat::PCM8Stereo => 2, |
|
|
|
|
AudioFormat::PCM16Stereo => 4, |
|
|
|
|
AudioFormat::SurroundPreprocessed => { |
|
|
|
|
panic!("Can't find sample size for Sourround Preprocessed audio: format is under research") |
|
|
|
|
} |
|
|
|
|
// TODO: Understand what this is.
|
|
|
|
|
AudioFormat::FrontBypass => { |
|
|
|
|
panic!("Can't find sample size for FrontBypass audio") |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|