libctru v2.5.0
Loading...
Searching...
No Matches
ndsp.h
Go to the documentation of this file.
1/**
2 * @file ndsp.h
3 * @brief Interface for Nintendo's default DSP component.
4 */
5#pragma once
6
7#include <3ds/os.h>
8
9#define NDSP_SAMPLE_RATE (SYSCLOCK_SOC / 512.0)
10
11///@name Data types
12///@{
13/// Sound output modes.
14typedef enum
15{
16 NDSP_OUTPUT_MONO = 0, ///< Mono sound
17 NDSP_OUTPUT_STEREO = 1, ///< Stereo sound
18 NDSP_OUTPUT_SURROUND = 2, ///< 3D Surround sound
20
21// Clipping modes.
22typedef enum
23{
24 NDSP_CLIP_NORMAL = 0, ///< "Normal" clipping mode (?)
25 NDSP_CLIP_SOFT = 1, ///< "Soft" clipping mode (?)
27
28// Surround speaker positions.
29typedef enum
30{
33 NDSP_SPKPOS_NUM = 2, ///<?
35
36/// ADPCM data.
37typedef struct
38{
39 u16 index; ///< Current predictor index
40 s16 history0; ///< Last outputted PCM16 sample.
41 s16 history1; ///< Second to last outputted PCM16 sample.
43
44/// Wave buffer type.
45typedef struct tag_ndspWaveBuf ndspWaveBuf;
46
47/// Wave buffer status.
48enum
49{
50 NDSP_WBUF_FREE = 0, ///< The wave buffer is not queued.
51 NDSP_WBUF_QUEUED = 1, ///< The wave buffer is queued and has not been played yet.
52 NDSP_WBUF_PLAYING = 2, ///< The wave buffer is playing right now.
53 NDSP_WBUF_DONE = 3, ///< The wave buffer has finished being played.
54};
55
56/// Wave buffer struct.
58{
59 union
60 {
61 s8* data_pcm8; ///< Pointer to PCM8 sample data.
62 s16* data_pcm16; ///< Pointer to PCM16 sample data.
63 u8* data_adpcm; ///< Pointer to DSPADPCM sample data.
64 const void* data_vaddr; ///< Data virtual address.
65 };
66 u32 nsamples; ///< Total number of samples (PCM8=bytes, PCM16=halfwords, DSPADPCM=nibbles without frame headers)
67 ndspAdpcmData* adpcm_data; ///< ADPCM data.
68
69 u32 offset; ///< Buffer offset. Only used for capture.
70 bool looping; ///< Whether to loop the buffer.
71 u8 status; ///< Queuing/playback status.
72
73 u16 sequence_id; ///< Sequence ID. Assigned automatically by ndspChnWaveBufAdd.
74 ndspWaveBuf* next; ///< Next buffer to play. Used internally, do not modify.
75};
76
77/// Sound frame callback function. (data = User provided data)
78typedef void (*ndspCallback)(void* data);
79/// Auxiliary output callback function. (data = User provided data, nsamples = Number of samples, samples = Sample data)
80typedef void (*ndspAuxCallback)(void* data, int nsamples, void* samples[4]);
81///@}
82
83///@name Initialization and basic operations
84///@{
85/**
86 * @brief Sets up the DSP component.
87 * @param binary DSP binary to load.
88 * @param size Size of the DSP binary.
89 * @param progMask Program RAM block mask to load the binary to.
90 * @param dataMask Data RAM block mask to load the binary to.
91 */
92void ndspUseComponent(const void* binary, u32 size, u16 progMask, u16 dataMask);
93
94/// Initializes NDSP.
96
97/// Exits NDSP.
98void ndspExit(void);
99
100/**
101 * @brief Gets the number of dropped sound frames.
102 * @return The number of dropped sound frames.
103 */
105
106/**
107 * @brief Gets the total sound frame count.
108 * @return The total sound frame count.
109 */
111///@}
112
113///@name General parameters
114///@{
115/**
116 * @brief Sets the master volume.
117 * @param volume Volume to set. Defaults to 1.0f.
118 */
119void ndspSetMasterVol(float volume);
120
121/**
122 * @brief Gets the master volume.
123 * @return The master volume.
124 */
125float ndspGetMasterVol(void);
126
127/**
128 * @brief Sets the output mode.
129 * @param mode Output mode to set. Defaults to NDSP_OUTPUT_STEREO.
130 */
132
133/**
134 * @brief Gets the output mode.
135 * @return The output mode.
136 */
138
139/**
140 * @brief Sets the clipping mode.
141 * @param mode Clipping mode to set. Defaults to NDSP_CLIP_SOFT.
142 */
144
145/**
146 * @brief Gets the clipping mode.
147 * @return The clipping mode.
148 */
150
151/**
152 * @brief Sets the output count.
153 * @param count Output count to set. Defaults to 2.
154 */
155void ndspSetOutputCount(int count);
156
157/**
158 * @brief Gets the output count.
159 * @return The output count.
160 */
162
163/**
164 * @brief Sets the wave buffer to capture audio to.
165 * @param capture Wave buffer to capture to.
166 */
167void ndspSetCapture(ndspWaveBuf* capture);
168
169/**
170 * @brief Sets the sound frame callback.
171 * @param callback Callback to set.
172 * @param data User-defined data to pass to the callback.
173 */
174void ndspSetCallback(ndspCallback callback, void* data);
175///@}
176
177///@name Surround
178///@{
179/**
180 * @brief Sets the surround sound depth.
181 * @param depth Depth to set. Defaults to 0x7FFF.
182 */
184
185/**
186 * @brief Gets the surround sound depth.
187 * @return The surround sound depth.
188 */
190
191/**
192 * @brief Sets the surround sound position.
193 * @param pos Position to set. Defaults to NDSP_SPKPOS_SQUARE.
194 */
196
197/**
198 * @brief Gets the surround sound position.
199 * @return The surround sound speaker position.
200 */
202
203/**
204 * @brief Sets the surround sound rear ratio.
205 * @param ratio Rear ratio to set. Defaults to 0x8000.
206 */
208
209/**
210 * @brief Gets the surround sound rear ratio.
211 * @return The rear ratio.
212 */
214///@}
215
216///@name Auxiliary output
217///@{
218/**
219 * @brief Configures whether an auxiliary output is enabled.
220 * @param id ID of the auxiliary output.
221 * @param enable Whether to enable the auxiliary output.
222 */
223void ndspAuxSetEnable(int id, bool enable);
224
225/**
226 * @brief Gets whether auxiliary output is enabled.
227 * @param id ID of the auxiliary output.
228 * @return Whether auxiliary output is enabled.
229 */
230bool ndspAuxIsEnabled(int id);
231
232/**
233 * @brief Configures whether an auxiliary output should use front bypass.
234 * @param id ID of the auxiliary output.
235 * @param bypass Whether to use front bypass.
236 */
237void ndspAuxSetFrontBypass(int id, bool bypass);
238
239/**
240 * @brief Gets whether auxiliary output front bypass is enabled.
241 * @param id ID of the auxiliary output.
242 * @return Whether auxiliary output front bypass is enabled.
243 */
245
246/**
247 * @brief Sets the volume of an auxiliary output.
248 * @param id ID of the auxiliary output.
249 * @param volume Volume to set.
250 */
251void ndspAuxSetVolume(int id, float volume);
252
253/**
254 * @brief Gets the volume of an auxiliary output.
255 * @param id ID of the auxiliary output.
256 * @return Volume of the auxiliary output.
257 */
258float ndspAuxGetVolume(int id);
259
260/**
261 * @brief Sets the callback of an auxiliary output.
262 * @param id ID of the auxiliary output.
263 * @param callback Callback to set.
264 * @param data User-defined data to pass to the callback.
265 */
266void ndspAuxSetCallback(int id, ndspAuxCallback callback, void* data);
267///@}
bool ndspAuxGetFrontBypass(int id)
Gets whether auxiliary output front bypass is enabled.
float ndspAuxGetVolume(int id)
Gets the volume of an auxiliary output.
u32 ndspGetDroppedFrames(void)
Gets the number of dropped sound frames.
void ndspSetOutputCount(int count)
Sets the output count.
ndspClippingMode
Definition ndsp.h:23
@ NDSP_CLIP_NORMAL
"Normal" clipping mode (?)
Definition ndsp.h:24
@ NDSP_CLIP_SOFT
"Soft" clipping mode (?)
Definition ndsp.h:25
ndspSpeakerPos ndspSurroundGetPos(void)
Gets the surround sound position.
bool ndspAuxIsEnabled(int id)
Gets whether auxiliary output is enabled.
u16 ndspSurroundGetRearRatio(void)
Gets the surround sound rear ratio.
void ndspAuxSetCallback(int id, ndspAuxCallback callback, void *data)
Sets the callback of an auxiliary output.
float ndspGetMasterVol(void)
Gets the master volume.
void ndspSetOutputMode(ndspOutputMode mode)
Sets the output mode.
void ndspSurroundSetPos(ndspSpeakerPos pos)
Sets the surround sound position.
void ndspUseComponent(const void *binary, u32 size, u16 progMask, u16 dataMask)
Sets up the DSP component.
void ndspAuxSetFrontBypass(int id, bool bypass)
Configures whether an auxiliary output should use front bypass.
void ndspSetCallback(ndspCallback callback, void *data)
Sets the sound frame callback.
ndspClippingMode ndspGetClippingMode(void)
Gets the clipping mode.
u16 ndspSurroundGetDepth(void)
Gets the surround sound depth.
@ NDSP_WBUF_QUEUED
The wave buffer is queued and has not been played yet.
Definition ndsp.h:51
@ NDSP_WBUF_FREE
The wave buffer is not queued.
Definition ndsp.h:50
@ NDSP_WBUF_PLAYING
The wave buffer is playing right now.
Definition ndsp.h:52
@ NDSP_WBUF_DONE
The wave buffer has finished being played.
Definition ndsp.h:53
void(* ndspCallback)(void *data)
Sound frame callback function. (data = User provided data)
Definition ndsp.h:78
u32 ndspGetFrameCount(void)
Gets the total sound frame count.
ndspOutputMode ndspGetOutputMode(void)
Gets the output mode.
void ndspAuxSetEnable(int id, bool enable)
Configures whether an auxiliary output is enabled.
void ndspExit(void)
Exits NDSP.
void ndspSetMasterVol(float volume)
Sets the master volume.
ndspOutputMode
Definition ndsp.h:15
@ NDSP_OUTPUT_MONO
Mono sound.
Definition ndsp.h:16
@ NDSP_OUTPUT_STEREO
Stereo sound.
Definition ndsp.h:17
@ NDSP_OUTPUT_SURROUND
3D Surround sound
Definition ndsp.h:18
ndspSpeakerPos
Definition ndsp.h:30
@ NDSP_SPKPOS_WIDE
?
Definition ndsp.h:32
@ NDSP_SPKPOS_NUM
?
Definition ndsp.h:33
@ NDSP_SPKPOS_SQUARE
?
Definition ndsp.h:31
void ndspSurroundSetDepth(u16 depth)
Sets the surround sound depth.
void ndspSetCapture(ndspWaveBuf *capture)
Sets the wave buffer to capture audio to.
void(* ndspAuxCallback)(void *data, int nsamples, void *samples[4])
Auxiliary output callback function. (data = User provided data, nsamples = Number of samples,...
Definition ndsp.h:80
void ndspAuxSetVolume(int id, float volume)
Sets the volume of an auxiliary output.
int ndspGetOutputCount(void)
Gets the output count.
void ndspSetClippingMode(ndspClippingMode mode)
Sets the clipping mode.
Result ndspInit(void)
Initializes NDSP.
void ndspSurroundSetRearRatio(u16 ratio)
Sets the surround sound rear ratio.
OS related stuff.
ADPCM data.
Definition ndsp.h:38
s16 history0
Last outputted PCM16 sample.
Definition ndsp.h:40
s16 history1
Second to last outputted PCM16 sample.
Definition ndsp.h:41
u16 index
Current predictor index.
Definition ndsp.h:39
Wave buffer struct.
Definition ndsp.h:58
const void * data_vaddr
Data virtual address.
Definition ndsp.h:64
s8 * data_pcm8
Pointer to PCM8 sample data.
Definition ndsp.h:61
ndspWaveBuf * next
Next buffer to play. Used internally, do not modify.
Definition ndsp.h:74
bool looping
Whether to loop the buffer.
Definition ndsp.h:70
u8 * data_adpcm
Pointer to DSPADPCM sample data.
Definition ndsp.h:63
u16 sequence_id
Sequence ID. Assigned automatically by ndspChnWaveBufAdd.
Definition ndsp.h:73
ndspAdpcmData * adpcm_data
ADPCM data.
Definition ndsp.h:67
u32 nsamples
Total number of samples (PCM8=bytes, PCM16=halfwords, DSPADPCM=nibbles without frame headers)
Definition ndsp.h:66
u8 status
Queuing/playback status.
Definition ndsp.h:71
s16 * data_pcm16
Pointer to PCM16 sample data.
Definition ndsp.h:62
u32 offset
Buffer offset. Only used for capture.
Definition ndsp.h:69
uint8_t u8
would be nice if newlib had this already
Definition types.h:21
int8_t s8
8-bit signed integer
Definition types.h:26
int16_t s16
16-bit signed integer
Definition types.h:27
s32 Result
Function result.
Definition types.h:42
uint16_t u16
16-bit unsigned integer
Definition types.h:22
uint32_t u32
32-bit unsigned integer
Definition types.h:23