libctru v2.5.0
Loading...
Searching...
No Matches
channel.h
Go to the documentation of this file.
1/**
2 * @file channel.h
3 * @brief Functions for interacting with DSP audio channels.
4 */
5#pragma once
6
7///@name Data types
8///@{
9/// Supported sample encodings.
10enum
11{
12 NDSP_ENCODING_PCM8 = 0, ///< PCM8
14 NDSP_ENCODING_ADPCM, ///< DSPADPCM (GameCube format)
15};
16
17/// Specifies the number of channels used in a sample.
18#define NDSP_CHANNELS(n) ((u32)(n) & 3)
19/// Specifies the encoding used in a sample.
20#define NDSP_ENCODING(n) (((u32)(n) & 3) << 2)
21
22/// Channel format flags for use with ndspChnSetFormat.
23enum
24{
28 NDSP_FORMAT_STEREO_PCM8 = NDSP_CHANNELS(2) | NDSP_ENCODING(NDSP_ENCODING_PCM8), ///< Buffer contains Stereo PCM8.
29 NDSP_FORMAT_STEREO_PCM16 = NDSP_CHANNELS(2) | NDSP_ENCODING(NDSP_ENCODING_PCM16), ///< Buffer contains Stereo PCM16.
30
31 NDSP_FORMAT_PCM8 = NDSP_FORMAT_MONO_PCM8, ///< (Alias) Buffer contains Mono PCM8.
32 NDSP_FORMAT_PCM16 = NDSP_FORMAT_MONO_PCM16, ///< (Alias) Buffer contains Mono PCM16.
33 NDSP_FORMAT_ADPCM = NDSP_FORMAT_MONO_ADPCM, ///< (Alias) Buffer contains Mono ADPCM.
34
35 // Flags
36 NDSP_FRONT_BYPASS = BIT(4), ///< Front bypass.
37 NDSP_3D_SURROUND_PREPROCESSED = BIT(6), ///< (?) Unknown, under research
38};
39
40/// Interpolation types.
41typedef enum
42{
43 NDSP_INTERP_POLYPHASE = 0, ///< Polyphase interpolation
44 NDSP_INTERP_LINEAR = 1, ///< Linear interpolation
45 NDSP_INTERP_NONE = 2, ///< No interpolation
47
48///@}
49
50///@name Basic channel operation
51///@{
52/**
53 * @brief Resets a channel.
54 * @param id ID of the channel (0..23).
55 */
56void ndspChnReset(int id);
57
58/**
59 * @brief Initializes the parameters of a channel.
60 * @param id ID of the channel (0..23).
61 */
62void ndspChnInitParams(int id);
63
64/**
65 * @brief Checks whether a channel is currently playing.
66 * @param id ID of the channel (0..23).
67 * @return Whether the channel is currently playing.
68 */
69bool ndspChnIsPlaying(int id);
70
71/**
72 * @brief Gets the current sample position of a channel.
73 * @param id ID of the channel (0..23).
74 * @return The channel's sample position.
75 */
77
78/**
79 * @brief Gets the sequence ID of the wave buffer that is currently playing in a channel.
80 * @param id ID of the channel (0..23).
81 * @return The sequence ID of the wave buffer.
82 */
84
85/**
86 * @brief Checks whether a channel is currently paused.
87 * @param id ID of the channel (0..23).
88 * @return Whether the channel is currently paused.
89 */
90bool ndspChnIsPaused(int id);
91
92/**
93 * @brief Sets the pause status of a channel.
94 * @param id ID of the channel (0..23).
95 * @param paused Whether the channel is to be paused (true) or unpaused (false).
96 */
97void ndspChnSetPaused(int id, bool paused);
98
99///@}
100
101///@name Configuration
102///@{
103/**
104 * @brief Sets the format of a channel.
105 * @param id ID of the channel (0..23).
106 * @param format Format to use.
107 */
108void ndspChnSetFormat(int id, u16 format);
109
110/**
111 *
112 * @brief Gets the format of a channel.
113 * @param id ID of the channel (0..23).
114 * @return The format of the channel.
115 */
117
118/**
119 * @brief Sets the interpolation type of a channel.
120 * @param id ID of the channel (0..23).
121 * @param type Interpolation type to use.
122 */
124
125/**
126 * @brief Gets the interpolation type of a channel.
127 * @param id ID of the channel (0..23).
128 * @return The interpolation type of the channel.
129 */
131
132/**
133 * @brief Sets the sample rate of a channel.
134 * @param id ID of the channel (0..23).
135 * @param rate Sample rate to use.
136 */
137void ndspChnSetRate(int id, float rate);
138
139/**
140 * @brief Gets the sample rate of a channel.
141 * @param id ID of the channel (0..23).
142 * @return The sample rate of the channel.
143 */
144float ndspChnGetRate(int id);
145
146/**
147 * @brief Sets the mix parameters (volumes) of a channel.
148 * @param id ID of the channel (0..23).
149 * @param mix Mix parameters to use. Working hypothesis:
150 * - 0: Front left volume.
151 * - 1: Front right volume.
152 * - 2: Back left volume:
153 * - 3: Back right volume:
154 * - 4..7: Same as 0..3, but for auxiliary output 0.
155 * - 8..11: Same as 0..3, but for auxiliary output 1.
156 */
157void ndspChnSetMix(int id, float mix[12]);
158
159/**
160 * @brief Gets the mix parameters (volumes) of a channel.
161 * @param id ID of the channel (0..23)
162 * @param mix Mix parameters to write out to. See \ref ndspChnSetMix.
163 */
164void ndspChnGetMix(int id, float mix[12]);
165
166/**
167 * @brief Sets the DSPADPCM coefficients of a channel.
168 * @param id ID of the channel (0..23).
169 * @param coefs DSPADPCM coefficients to use.
170 */
171void ndspChnSetAdpcmCoefs(int id, u16 coefs[16]);
172///@}
173
174///@name Wave buffers
175///@{
176/**
177 * @brief Clears the wave buffer queue of a channel and stops playback.
178 * @param id ID of the channel (0..23).
179 */
181
182/**
183 * @brief Adds a wave buffer to the wave buffer queue of a channel.
184 * @remark If the channel's wave buffer queue was empty before the use of this function, playback is started.
185 * @param id ID of the channel (0..23).
186 * @param buf Wave buffer to add.
187 */
188void ndspChnWaveBufAdd(int id, ndspWaveBuf* buf);
189///@}
190
191///@name IIR filters
192///@{
193/**
194 * @brief Configures whether the IIR monopole filter of a channel is enabled.
195 * @param id ID of the channel (0..23).
196 * @param enable Whether to enable the IIR monopole filter.
197 */
198void ndspChnIirMonoSetEnable(int id, bool enable);
199/**
200 * @brief Manually sets up the parameters on monopole filter
201 * @param id ID of the channel (0..23).
202 * @param enable Whether to enable the IIR monopole filter.
203 */
204bool ndspChnIirMonoSetParamsCustomFilter(int id, float a0, float a1, float b0);
205/**
206 * @brief Sets the monopole to be a low pass filter. (Note: This is a lower-quality filter than the biquad one.)
207 * @param id ID of the channel (0..23).
208 * @param f0 Low pass cut-off frequency.
209 */
211/**
212 * @brief Sets the monopole to be a high pass filter. (Note: This is a lower-quality filter than the biquad one.)
213 * @param id ID of the channel (0..23).
214 * @param f0 High pass cut-off frequency.
215 */
217/**
218 * @brief Configures whether the IIR biquad filter of a channel is enabled.
219 * @param id ID of the channel (0..23).
220 * @param enable Whether to enable the IIR biquad filter.
221 */
222void ndspChnIirBiquadSetEnable(int id, bool enable);
223/**
224 * @brief Manually sets up the parameters of the biquad filter
225 * @param id ID of the channel (0..23).
226 */
227bool ndspChnIirBiquadSetParamsCustomFilter(int id, float a0, float a1, float a2, float b0, float b1, float b2);
228/**
229 * @brief Sets the biquad to be a low pass filter.
230 * @param id ID of the channel (0..23).
231 * @param f0 Low pass cut-off frequency.
232 * @param Q "Quality factor", typically should be sqrt(2)/2 (i.e. 0.7071).
233 */
234bool ndspChnIirBiquadSetParamsLowPassFilter(int id, float f0, float Q);
235/**
236 * @brief Sets the biquad to be a high pass filter.
237 * @param id ID of the channel (0..23).
238 * @param f0 High pass cut-off frequency.
239 * @param Q "Quality factor", typically should be sqrt(2)/2 (i.e. 0.7071).
240 */
241bool ndspChnIirBiquadSetParamsHighPassFilter(int id, float f0, float Q);
242/**
243 * @brief Sets the biquad to be a band pass filter.
244 * @param id ID of the channel (0..23).
245 * @param f0 Mid-frequency.
246 * @param Q "Quality factor", typically should be sqrt(2)/2 (i.e. 0.7071).
247 */
248bool ndspChnIirBiquadSetParamsBandPassFilter(int id, float f0, float Q);
249/**
250 * @brief Sets the biquad to be a notch filter.
251 * @param id ID of the channel (0..23).
252 * @param f0 Notch frequency.
253 * @param Q "Quality factor", typically should be sqrt(2)/2 (i.e. 0.7071).
254 */
255bool ndspChnIirBiquadSetParamsNotchFilter(int id, float f0, float Q);
256/**
257 * @brief Sets the biquad to be a peaking equalizer.
258 * @param id ID of the channel (0..23).
259 * @param f0 Central frequency.
260 * @param Q "Quality factor", typically should be sqrt(2)/2 (i.e. 0.7071).
261 * @param gain Amount of gain (raw value = 10 ^ dB/40)
262 */
263bool ndspChnIirBiquadSetParamsPeakingEqualizer(int id, float f0, float Q, float gain);
264///@}
void ndspChnWaveBufClear(int id)
Clears the wave buffer queue of a channel and stops playback.
void ndspChnInitParams(int id)
Initializes the parameters of a channel.
bool ndspChnIsPlaying(int id)
Checks whether a channel is currently playing.
u16 ndspChnGetFormat(int id)
Gets the format of a channel.
u16 ndspChnGetWaveBufSeq(int id)
Gets the sequence ID of the wave buffer that is currently playing in a channel.
void ndspChnIirMonoSetEnable(int id, bool enable)
Configures whether the IIR monopole filter of a channel is enabled.
@ NDSP_FRONT_BYPASS
Front bypass.
Definition channel.h:36
@ NDSP_FORMAT_PCM16
(Alias) Buffer contains Mono PCM16.
Definition channel.h:32
@ NDSP_FORMAT_ADPCM
(Alias) Buffer contains Mono ADPCM.
Definition channel.h:33
@ NDSP_FORMAT_MONO_PCM8
Buffer contains Mono PCM8.
Definition channel.h:25
@ NDSP_FORMAT_STEREO_PCM8
Buffer contains Stereo PCM8.
Definition channel.h:28
@ NDSP_3D_SURROUND_PREPROCESSED
(?) Unknown, under research
Definition channel.h:37
@ NDSP_FORMAT_STEREO_PCM16
Buffer contains Stereo PCM16.
Definition channel.h:29
@ NDSP_FORMAT_MONO_ADPCM
Buffer contains Mono ADPCM.
Definition channel.h:27
@ NDSP_FORMAT_MONO_PCM16
Buffer contains Mono PCM16.
Definition channel.h:26
@ NDSP_FORMAT_PCM8
(Alias) Buffer contains Mono PCM8.
Definition channel.h:31
void ndspChnSetMix(int id, float mix[12])
Sets the mix parameters (volumes) of a channel.
void ndspChnWaveBufAdd(int id, ndspWaveBuf *buf)
Adds a wave buffer to the wave buffer queue of a channel.
void ndspChnGetMix(int id, float mix[12])
Gets the mix parameters (volumes) of a channel.
@ NDSP_ENCODING_PCM16
PCM16.
Definition channel.h:13
@ NDSP_ENCODING_ADPCM
DSPADPCM (GameCube format)
Definition channel.h:14
@ NDSP_ENCODING_PCM8
PCM8.
Definition channel.h:12
bool ndspChnIirMonoSetParamsCustomFilter(int id, float a0, float a1, float b0)
Manually sets up the parameters on monopole filter.
ndspInterpType ndspChnGetInterp(int id)
Gets the interpolation type of a channel.
ndspInterpType
Interpolation types.
Definition channel.h:42
@ NDSP_INTERP_LINEAR
Linear interpolation.
Definition channel.h:44
@ NDSP_INTERP_POLYPHASE
Polyphase interpolation.
Definition channel.h:43
@ NDSP_INTERP_NONE
No interpolation.
Definition channel.h:45
bool ndspChnIirBiquadSetParamsNotchFilter(int id, float f0, float Q)
Sets the biquad to be a notch filter.
#define NDSP_ENCODING(n)
Specifies the encoding used in a sample.
Definition channel.h:20
void ndspChnSetRate(int id, float rate)
Sets the sample rate of a channel.
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.
bool ndspChnIirBiquadSetParamsLowPassFilter(int id, float f0, float Q)
Sets the biquad to be a low pass filter.
void ndspChnSetFormat(int id, u16 format)
Sets the format of a channel.
void ndspChnReset(int id)
Resets a channel.
bool ndspChnIirMonoSetParamsHighPassFilter(int id, float f0)
Sets the monopole to be a high pass filter.
u32 ndspChnGetSamplePos(int id)
Gets the current sample position of a channel.
bool ndspChnIsPaused(int id)
Checks whether a channel is currently paused.
bool ndspChnIirBiquadSetParamsHighPassFilter(int id, float f0, float Q)
Sets the biquad to be a high pass filter.
bool ndspChnIirBiquadSetParamsPeakingEqualizer(int id, float f0, float Q, float gain)
Sets the biquad to be a peaking equalizer.
void ndspChnIirBiquadSetEnable(int id, bool enable)
Configures whether the IIR biquad filter of a channel is enabled.
#define NDSP_CHANNELS(n)
Specifies the number of channels used in a sample.
Definition channel.h:18
bool ndspChnIirMonoSetParamsLowPassFilter(int id, float f0)
Sets the monopole to be a low pass filter.
void ndspChnSetInterp(int id, ndspInterpType type)
Sets the interpolation type of a channel.
void ndspChnSetPaused(int id, bool paused)
Sets the pause status of a channel.
void ndspChnSetAdpcmCoefs(int id, u16 coefs[16])
Sets the DSPADPCM coefficients of a channel.
bool ndspChnIirBiquadSetParamsBandPassFilter(int id, float f0, float Q)
Sets the biquad to be a band pass filter.
float ndspChnGetRate(int id)
Gets the sample rate of a channel.
#define BIT(n)
Creates a bitmask from a bit number.
Definition types.h:47
uint16_t u16
16-bit unsigned integer
Definition types.h:22
uint32_t u32
32-bit unsigned integer
Definition types.h:23