libctru  v2.4.1
channel.h File Reference

Functions for interacting with DSP audio channels. More...

Go to the source code of this file.

Functions

Basic channel operation
void ndspChnReset (int id)
 Resets a channel. More...
 
void ndspChnInitParams (int id)
 Initializes the parameters of a channel. More...
 
bool ndspChnIsPlaying (int id)
 Checks whether a channel is currently playing. More...
 
u32 ndspChnGetSamplePos (int id)
 Gets the current sample position of a channel. More...
 
u16 ndspChnGetWaveBufSeq (int id)
 Gets the sequence ID of the wave buffer that is currently playing in a channel. More...
 
bool ndspChnIsPaused (int id)
 Checks whether a channel is currently paused. More...
 
void ndspChnSetPaused (int id, bool paused)
 Sets the pause status of a channel. More...
 
Configuration
void ndspChnSetFormat (int id, u16 format)
 Sets the format of a channel. More...
 
u16 ndspChnGetFormat (int id)
 Gets the format of a channel. More...
 
void ndspChnSetInterp (int id, ndspInterpType type)
 Sets the interpolation type of a channel. More...
 
ndspInterpType ndspChnGetInterp (int id)
 Gets the interpolation type of a channel. More...
 
void ndspChnSetRate (int id, float rate)
 Sets the sample rate of a channel. More...
 
float ndspChnGetRate (int id)
 Gets the sample rate of a channel. More...
 
void ndspChnSetMix (int id, float mix[12])
 Sets the mix parameters (volumes) of a channel. More...
 
void ndspChnGetMix (int id, float mix[12])
 Gets the mix parameters (volumes) of a channel. More...
 
void ndspChnSetAdpcmCoefs (int id, u16 coefs[16])
 Sets the DSPADPCM coefficients of a channel. More...
 
Wave buffers
void ndspChnWaveBufClear (int id)
 Clears the wave buffer queue of a channel and stops playback. More...
 
void ndspChnWaveBufAdd (int id, ndspWaveBuf *buf)
 Adds a wave buffer to the wave buffer queue of a channel. More...
 
IIR filters
void ndspChnIirMonoSetEnable (int id, bool enable)
 Configures whether the IIR monopole filter of a channel is enabled. More...
 
bool ndspChnIirMonoSetParamsCustomFilter (int id, float a0, float a1, float b0)
 Manually sets up the parameters on monopole filter. More...
 
bool ndspChnIirMonoSetParamsLowPassFilter (int id, float f0)
 Sets the monopole to be a low pass filter. More...
 
bool ndspChnIirMonoSetParamsHighPassFilter (int id, float f0)
 Sets the monopole to be a high pass filter. More...
 
void ndspChnIirBiquadSetEnable (int id, bool enable)
 Configures whether the IIR biquad filter of a channel is enabled. More...
 
bool ndspChnIirBiquadSetParamsCustomFilter (int id, float a0, float a1, float a2, float b0, float b1, float b2)
 Manually sets up the parameters of the biquad filter. More...
 
bool ndspChnIirBiquadSetParamsLowPassFilter (int id, float f0, float Q)
 Sets the biquad to be a low pass filter. More...
 
bool ndspChnIirBiquadSetParamsHighPassFilter (int id, float f0, float Q)
 Sets the biquad to be a high pass filter. More...
 
bool ndspChnIirBiquadSetParamsBandPassFilter (int id, float f0, float Q)
 Sets the biquad to be a band pass filter. More...
 
bool ndspChnIirBiquadSetParamsNotchFilter (int id, float f0, float Q)
 Sets the biquad to be a notch filter. More...
 
bool ndspChnIirBiquadSetParamsPeakingEqualizer (int id, float f0, float Q, float gain)
 Sets the biquad to be a peaking equalizer. More...
 

Data types

Supported sample encodings.

#define NDSP_CHANNELS(n)   ((u32)(n) & 3)
 Specifies the number of channels used in a sample.
 
#define NDSP_ENCODING(n)   (((u32)(n) & 3) << 2)
 Specifies the encoding used in a sample.
 
enum  {
  NDSP_ENCODING_PCM8 = 0 ,
  NDSP_ENCODING_PCM16 ,
  NDSP_ENCODING_ADPCM
}
 
enum  {
  NDSP_FORMAT_MONO_PCM8 = NDSP_CHANNELS(1) | NDSP_ENCODING(NDSP_ENCODING_PCM8) ,
  NDSP_FORMAT_MONO_PCM16 = NDSP_CHANNELS(1) | NDSP_ENCODING(NDSP_ENCODING_PCM16) ,
  NDSP_FORMAT_MONO_ADPCM = NDSP_CHANNELS(1) | NDSP_ENCODING(NDSP_ENCODING_ADPCM) ,
  NDSP_FORMAT_STEREO_PCM8 = NDSP_CHANNELS(2) | NDSP_ENCODING(NDSP_ENCODING_PCM8) ,
  NDSP_FORMAT_STEREO_PCM16 = NDSP_CHANNELS(2) | NDSP_ENCODING(NDSP_ENCODING_PCM16) ,
  NDSP_FORMAT_PCM8 = NDSP_FORMAT_MONO_PCM8 ,
  NDSP_FORMAT_PCM16 = NDSP_FORMAT_MONO_PCM16 ,
  NDSP_FORMAT_ADPCM = NDSP_FORMAT_MONO_ADPCM ,
  NDSP_FRONT_BYPASS = BIT(4) ,
  NDSP_3D_SURROUND_PREPROCESSED = BIT(6)
}
 Channel format flags for use with ndspChnSetFormat. More...
 
enum  ndspInterpType {
  NDSP_INTERP_POLYPHASE = 0 ,
  NDSP_INTERP_LINEAR = 1 ,
  NDSP_INTERP_NONE = 2
}
 Interpolation types. More...
 

Detailed Description

Functions for interacting with DSP audio channels.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
NDSP_ENCODING_PCM8 

PCM8.

NDSP_ENCODING_PCM16 

PCM16.

NDSP_ENCODING_ADPCM 

DSPADPCM (GameCube format)

◆ anonymous enum

anonymous enum

Channel format flags for use with ndspChnSetFormat.

Enumerator
NDSP_FORMAT_MONO_PCM8 

Buffer contains Mono PCM8.

NDSP_FORMAT_MONO_PCM16 

Buffer contains Mono PCM16.

NDSP_FORMAT_MONO_ADPCM 

Buffer contains Mono ADPCM.

NDSP_FORMAT_STEREO_PCM8 

Buffer contains Stereo PCM8.

NDSP_FORMAT_STEREO_PCM16 

Buffer contains Stereo PCM16.

NDSP_FORMAT_PCM8 

(Alias) Buffer contains Mono PCM8.

NDSP_FORMAT_PCM16 

(Alias) Buffer contains Mono PCM16.

NDSP_FORMAT_ADPCM 

(Alias) Buffer contains Mono ADPCM.

NDSP_FRONT_BYPASS 

Front bypass.

NDSP_3D_SURROUND_PREPROCESSED 

(?) Unknown, under research

◆ ndspInterpType

Interpolation types.

Enumerator
NDSP_INTERP_POLYPHASE 

Polyphase interpolation.

NDSP_INTERP_LINEAR 

Linear interpolation.

NDSP_INTERP_NONE 

No interpolation.

Function Documentation

◆ ndspChnGetFormat()

u16 ndspChnGetFormat ( int  id)

Gets the format of a channel.

Parameters
idID of the channel (0..23).
Returns
The format of the channel.

◆ ndspChnGetInterp()

ndspInterpType ndspChnGetInterp ( int  id)

Gets the interpolation type of a channel.

Parameters
idID of the channel (0..23).
Returns
The interpolation type of the channel.

◆ ndspChnGetMix()

void ndspChnGetMix ( int  id,
float  mix[12] 
)

Gets the mix parameters (volumes) of a channel.

Parameters
idID of the channel (0..23)
mixMix parameters to write out to. See ndspChnSetMix.

◆ ndspChnGetRate()

float ndspChnGetRate ( int  id)

Gets the sample rate of a channel.

Parameters
idID of the channel (0..23).
Returns
The sample rate of the channel.

◆ ndspChnGetSamplePos()

u32 ndspChnGetSamplePos ( int  id)

Gets the current sample position of a channel.

Parameters
idID of the channel (0..23).
Returns
The channel's sample position.

◆ ndspChnGetWaveBufSeq()

u16 ndspChnGetWaveBufSeq ( int  id)

Gets the sequence ID of the wave buffer that is currently playing in a channel.

Parameters
idID of the channel (0..23).
Returns
The sequence ID of the wave buffer.

◆ ndspChnIirBiquadSetEnable()

void ndspChnIirBiquadSetEnable ( int  id,
bool  enable 
)

Configures whether the IIR biquad filter of a channel is enabled.

Parameters
idID of the channel (0..23).
enableWhether to enable the IIR biquad filter.
Examples
audio/filters/source/main.c.

◆ ndspChnIirBiquadSetParamsBandPassFilter()

bool ndspChnIirBiquadSetParamsBandPassFilter ( int  id,
float  f0,
float  Q 
)

Sets the biquad to be a band pass filter.

Parameters
idID of the channel (0..23).
f0Mid-frequency.
Q"Quality factor", typically should be sqrt(2)/2 (i.e. 0.7071).
Examples
audio/filters/source/main.c.

◆ ndspChnIirBiquadSetParamsCustomFilter()

bool ndspChnIirBiquadSetParamsCustomFilter ( int  id,
float  a0,
float  a1,
float  a2,
float  b0,
float  b1,
float  b2 
)

Manually sets up the parameters of the biquad filter.

Parameters
idID of the channel (0..23).

◆ ndspChnIirBiquadSetParamsHighPassFilter()

bool ndspChnIirBiquadSetParamsHighPassFilter ( int  id,
float  f0,
float  Q 
)

Sets the biquad to be a high pass filter.

Parameters
idID of the channel (0..23).
f0High pass cut-off frequency.
Q"Quality factor", typically should be sqrt(2)/2 (i.e. 0.7071).
Examples
audio/filters/source/main.c.

◆ ndspChnIirBiquadSetParamsLowPassFilter()

bool ndspChnIirBiquadSetParamsLowPassFilter ( int  id,
float  f0,
float  Q 
)

Sets the biquad to be a low pass filter.

Parameters
idID of the channel (0..23).
f0Low pass cut-off frequency.
Q"Quality factor", typically should be sqrt(2)/2 (i.e. 0.7071).
Examples
audio/filters/source/main.c.

◆ ndspChnIirBiquadSetParamsNotchFilter()

bool ndspChnIirBiquadSetParamsNotchFilter ( int  id,
float  f0,
float  Q 
)

Sets the biquad to be a notch filter.

Parameters
idID of the channel (0..23).
f0Notch frequency.
Q"Quality factor", typically should be sqrt(2)/2 (i.e. 0.7071).
Examples
audio/filters/source/main.c.

◆ ndspChnIirBiquadSetParamsPeakingEqualizer()

bool ndspChnIirBiquadSetParamsPeakingEqualizer ( int  id,
float  f0,
float  Q,
float  gain 
)

Sets the biquad to be a peaking equalizer.

Parameters
idID of the channel (0..23).
f0Central frequency.
Q"Quality factor", typically should be sqrt(2)/2 (i.e. 0.7071).
gainAmount of gain (raw value = 10 ^ dB/40)
Examples
audio/filters/source/main.c.

◆ ndspChnIirMonoSetEnable()

void ndspChnIirMonoSetEnable ( int  id,
bool  enable 
)

Configures whether the IIR monopole filter of a channel is enabled.

Parameters
idID of the channel (0..23).
enableWhether to enable the IIR monopole filter.

◆ ndspChnIirMonoSetParamsCustomFilter()

bool ndspChnIirMonoSetParamsCustomFilter ( int  id,
float  a0,
float  a1,
float  b0 
)

Manually sets up the parameters on monopole filter.

Parameters
idID of the channel (0..23).
enableWhether to enable the IIR monopole filter.

◆ ndspChnIirMonoSetParamsHighPassFilter()

bool ndspChnIirMonoSetParamsHighPassFilter ( int  id,
float  f0 
)

Sets the monopole to be a high pass filter.

(Note: This is a lower-quality filter than the biquad one.)

Parameters
idID of the channel (0..23).
f0High pass cut-off frequency.

◆ ndspChnIirMonoSetParamsLowPassFilter()

bool ndspChnIirMonoSetParamsLowPassFilter ( int  id,
float  f0 
)

Sets the monopole to be a low pass filter.

(Note: This is a lower-quality filter than the biquad one.)

Parameters
idID of the channel (0..23).
f0Low pass cut-off frequency.

◆ ndspChnInitParams()

void ndspChnInitParams ( int  id)

Initializes the parameters of a channel.

Parameters
idID of the channel (0..23).

◆ ndspChnIsPaused()

bool ndspChnIsPaused ( int  id)

Checks whether a channel is currently paused.

Parameters
idID of the channel (0..23).
Returns
Whether the channel is currently paused.

◆ ndspChnIsPlaying()

bool ndspChnIsPlaying ( int  id)

Checks whether a channel is currently playing.

Parameters
idID of the channel (0..23).
Returns
Whether the channel is currently playing.

◆ ndspChnReset()

void ndspChnReset ( int  id)

Resets a channel.

Parameters
idID of the channel (0..23).

◆ ndspChnSetAdpcmCoefs()

void ndspChnSetAdpcmCoefs ( int  id,
u16  coefs[16] 
)

Sets the DSPADPCM coefficients of a channel.

Parameters
idID of the channel (0..23).
coefsDSPADPCM coefficients to use.

◆ ndspChnSetFormat()

void ndspChnSetFormat ( int  id,
u16  format 
)

Sets the format of a channel.

Parameters
idID of the channel (0..23).
formatFormat to use.
Examples
audio/filters/source/main.c, and audio/streaming/source/main.c.

◆ ndspChnSetInterp()

void ndspChnSetInterp ( int  id,
ndspInterpType  type 
)

Sets the interpolation type of a channel.

Parameters
idID of the channel (0..23).
typeInterpolation type to use.
Examples
audio/filters/source/main.c, and audio/streaming/source/main.c.

◆ ndspChnSetMix()

void ndspChnSetMix ( int  id,
float  mix[12] 
)

Sets the mix parameters (volumes) of a channel.

Parameters
idID of the channel (0..23).
mixMix parameters to use. Working hypothesis:
  • 0: Front left volume.
  • 1: Front right volume.
  • 2: Back left volume:
  • 3: Back right volume:
  • 4..7: Same as 0..3, but for auxiliary output 0.
  • 8..11: Same as 0..3, but for auxiliary output 1.
Examples
audio/filters/source/main.c, and audio/streaming/source/main.c.

◆ ndspChnSetPaused()

void ndspChnSetPaused ( int  id,
bool  paused 
)

Sets the pause status of a channel.

Parameters
idID of the channel (0..23).
pausedWhether the channel is to be paused (true) or unpaused (false).

◆ ndspChnSetRate()

void ndspChnSetRate ( int  id,
float  rate 
)

Sets the sample rate of a channel.

Parameters
idID of the channel (0..23).
rateSample rate to use.
Examples
audio/filters/source/main.c, and audio/streaming/source/main.c.

◆ ndspChnWaveBufAdd()

void ndspChnWaveBufAdd ( int  id,
ndspWaveBuf *  buf 
)

Adds a wave buffer to the wave buffer queue of a channel.

Remarks
If the channel's wave buffer queue was empty before the use of this function, playback is started.
Parameters
idID of the channel (0..23).
bufWave buffer to add.
Examples
audio/filters/source/main.c, and audio/streaming/source/main.c.

◆ ndspChnWaveBufClear()

void ndspChnWaveBufClear ( int  id)

Clears the wave buffer queue of a channel and stops playback.

Parameters
idID of the channel (0..23).