KallistiOS git master
Independent SDK for the Sega Dreamcast
Loading...
Searching...
No Matches
sound.h
Go to the documentation of this file.
1/* KallistiOS ##version##
2
3 dc/sound/sound.h
4 Copyright (C) 2002 Megan Potter
5 Copyright (C) 2023, 2024 Ruslan Rostovtsev
6
7*/
8
9/** \file dc/sound/sound.h
10 \brief Low-level sound support and memory management.
11 \ingroup audio_driver
12
13 This file contains declarations for low-level sound operations and for SPU
14 RAM pool memory management. Most of the time you'll be better off using the
15 higher-level functionality in the sound effect support or streaming support,
16 but this stuff can be very useful for some things.
17
18 \author Megan Potter
19 \author Ruslan Rostovtsev
20*/
21
22#ifndef __DC_SOUND_SOUND_H
23#define __DC_SOUND_SOUND_H
24
25#include <sys/cdefs.h>
26__BEGIN_DECLS
27
28#include <arch/types.h>
29#include <stdint.h>
30#include <stdbool.h>
31
32/** \defgroup audio_driver Driver
33 \brief Low-level driver for SPU and audio management
34 \ingroup audio
35
36 @{
37*/
38
39/** \brief Allocate memory in the SPU RAM pool
40
41 This function acts as the memory allocator for the SPU RAM pool. It acts
42 much like one would expect a malloc() function to act, although it does not
43 return a pointer directly, but rather an offset in SPU RAM.
44
45 \param size The amount of memory to allocate, in bytes.
46
47 \return The location of the start of the block on success,
48 or 0 on failure.
49*/
51
52/** \brief Free a block of allocated memory in the SPU RAM pool.
53
54 This function frees memory previously allocated with snd_mem_malloc().
55
56 \param addr The location of the start of the block to free.
57*/
59
60/** \brief Get the size of the largest allocateable block in the SPU RAM pool.
61
62 This function returns the largest size that can be currently passed to
63 snd_mem_malloc() and expected to not return failure. There may be more
64 memory available in the pool, especially if multiple blocks have been
65 allocated and freed, but calls to snd_mem_malloc() for larger blocks will
66 return failure, since the memory is not available contiguously.
67
68 \return The size of the largest available block of memory in
69 the SPU RAM pool.
70*/
72
73/** \brief Reinitialize the SPU RAM pool.
74
75 This function reinitializes the SPU RAM pool with the given base offset
76 within the memory space. There is generally not a good reason to do this in
77 your own code, but the functionality is there if needed.
78
79 \param reserve The amount of memory to reserve as a base.
80 \retval 0 On success (no failure conditions defined).
81*/
82int snd_mem_init(uint32 reserve);
83
84/** \brief Shutdown the SPU RAM allocator.
85
86 There is generally no reason to be calling this function in your own code,
87 as doing so will cause problems if you try to allocate SPU memory without
88 calling snd_mem_init() afterwards.
89*/
91
92/** \brief Initialize the sound system.
93
94 This function reinitializes the whole sound system. It will not do anything
95 unless the sound system has been shut down previously or has not been
96 initialized yet. This will implicitly replace the program running on the
97 AICA's ARM processor when it actually initializes anything. The default
98 snd_stream_drv will be loaded if a new program is uploaded to the SPU.
99*/
100int snd_init(void);
101
102/** \brief Shut down the sound system.
103
104 This function shuts down the whole sound system, freeing memory and
105 disabling the SPU in the process. There's not generally many good reasons
106 for doing this in your own code.
107*/
108void snd_shutdown(void);
109
110/** \brief Copy a request packet to the AICA queue.
111
112 This function is to put in a low-level request using the built-in streaming
113 sound driver.
114
115 \param packet The packet of data to copy.
116 \param size The size of the packet, in 32-bit increments.
117 \retval 0 On success (no error conditions defined).
118*/
119int snd_sh4_to_aica(void *packet, uint32 size);
120
121/** \brief Begin processing AICA queue requests.
122
123 This function begins processing of any queued requests in the AICA queue.
124*/
126
127/** \brief Stop processing AICA queue requests.
128
129 This function stops the processing of any queued requests in the AICA queue.
130*/
132
133/** \brief Transfer a packet of data from the AICA's SH4 queue.
134
135 This function is used to retrieve a packet of data from the AICA back to the
136 SH4. The buffer passed in should at least contain 1024 bytes of space to
137 make sure any packet can fit.
138
139 \param packetout The buffer to store the retrieved packet in.
140 \retval -1 On failure. Failure probably indicates the queue has
141 been corrupted, and thus should be reinitialized.
142 \retval 0 If no packets are available.
143 \retval 1 On successful copy of one packet.
144*/
145int snd_aica_to_sh4(void *packetout);
146
147/** \brief Poll for a response from the AICA.
148
149 This function waits for the AICA to respond to a previously sent request.
150 This function is not safe to call in an IRQ, as it does implicitly wait.
151*/
152void snd_poll_resp(void);
153
154/** \brief Separates stereo PCM samples into 2 mono channels.
155
156 Splits a buffer containing 2 interleaved channels of 16-bit PCM samples
157 into 2 separate buffers of 16-bit PCM samples.
158
159 \warning
160 All arguments must be 32-byte aligned.
161
162 \param data Source buffer of interleaved stereo samples
163 \param left Destination buffer for left mono samples
164 \param right Destination buffer for right mono samples
165 \param size Size of the source buffer in bytes (must be divisible by 32)
166
167 \sa snd_pcm16_split_sq()
168*/
169void snd_pcm16_split(uint32_t *data, uint32_t *left, uint32_t *right, size_t size);
170
171/** \brief Separates stereo PCM samples into 2 mono channels with SQ transfer.
172
173 Splits a buffer containing 2 interleaved channels of 16-bit PCM samples
174 into 2 separate buffers of 16-bit PCM samples by using the store queues
175 for data transfer.
176
177 \warning
178 All arguments must be 32-byte aligned.
179
180 \param data Source buffer of interleaved stereo samples
181 \param left Destination buffer address for left mono samples
182 \param right Destination buffer address for right mono samples
183 \param size Size of the source buffer in bytes (must be divisible by 32)
184
185 \sa snd_pcm16_split()
186 Store queues must be prepared before.
187*/
188void snd_pcm16_split_sq(uint32_t *data, uintptr_t left, uintptr_t right, size_t size);
189
190/** \brief Separates stereo PCM samples into 2 mono channels.
191
192 Splits a buffer containing 2 interleaved channels of 8-bit PCM samples
193 into 2 separate buffers of 8-bit PCM samples.
194
195 \param data Source buffer of interleaved stereo samples
196 \param left Destination buffer for left mono samples
197 \param right Destination buffer for right mono samples
198 \param size Size of the source buffer in bytes
199
200 \sa snd_adpcm_split()
201*/
202void snd_pcm8_split(uint32_t *data, uint32_t *left, uint32_t *right, size_t size);
203
204/** \brief Separates stereo ADPCM samples into 2 mono channels.
205
206 Splits a buffer containing 2 interleaved channels of 4-bit ADPCM samples
207 into 2 separate buffers of 4-bit ADPCM samples.
208
209 \param data Source buffer of interleaved stereo samples
210 \param left Destination buffer for left mono samples
211 \param right Destination buffer for right mono samples
212 \param size Size of the source buffer in bytes
213
214 \sa snd_pcm16_split()
215*/
216void snd_adpcm_split(uint32_t *data, uint32_t *left, uint32_t *right, size_t size);
217
218/** @} */
219
220/** \brief Get AICA channel position.
221
222 This function returns actual the channel position
223 that stores in SPU memory and updated by the SPU firmware.
224
225 \param chn The channel to retrieve position.
226
227 \return Last channel position in samples.
228*/
229uint16_t snd_get_pos(unsigned int ch);
230
231/** \brief Get AICA channel playback state.
232
233 This function returns actual the channel playback state
234 that stores in AICA registers directly.
235
236 \param chn The channel to check.
237
238 \return True if the channel is playing.
239*/
240bool snd_is_playing(unsigned int ch);
241
242__END_DECLS
243
244#endif /* __DC_SOUND_SOUND_H */
void snd_pcm16_split_sq(uint32_t *data, uintptr_t left, uintptr_t right, size_t size)
Separates stereo PCM samples into 2 mono channels with SQ transfer.
void snd_shutdown(void)
Shut down the sound system.
void snd_sh4_to_aica_start(void)
Begin processing AICA queue requests.
int snd_init(void)
Initialize the sound system.
uint32 snd_mem_available(void)
Get the size of the largest allocateable block in the SPU RAM pool.
void snd_mem_free(uint32 addr)
Free a block of allocated memory in the SPU RAM pool.
void snd_adpcm_split(uint32_t *data, uint32_t *left, uint32_t *right, size_t size)
Separates stereo ADPCM samples into 2 mono channels.
int snd_mem_init(uint32 reserve)
Reinitialize the SPU RAM pool.
void snd_pcm8_split(uint32_t *data, uint32_t *left, uint32_t *right, size_t size)
Separates stereo PCM samples into 2 mono channels.
void snd_mem_shutdown(void)
Shutdown the SPU RAM allocator.
uint32 snd_mem_malloc(size_t size)
Allocate memory in the SPU RAM pool.
void snd_sh4_to_aica_stop(void)
Stop processing AICA queue requests.
int snd_aica_to_sh4(void *packetout)
Transfer a packet of data from the AICA's SH4 queue.
int snd_sh4_to_aica(void *packet, uint32 size)
Copy a request packet to the AICA queue.
void snd_pcm16_split(uint32_t *data, uint32_t *left, uint32_t *right, size_t size)
Separates stereo PCM samples into 2 mono channels.
void snd_poll_resp(void)
Poll for a response from the AICA.
unsigned long uint32
32-bit unsigned integer
Definition types.h:33
uint16_t snd_get_pos(unsigned int ch)
Get AICA channel position.
bool snd_is_playing(unsigned int ch)
Get AICA channel playback state.
Common integer types.