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 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
31/** \defgroup audio_driver Driver
32 \brief Low-level driver for SPU and audio management
33 \ingroup audio
34
35 @{
36*/
37
38/** \brief Allocate memory in the SPU RAM pool
39
40 This function acts as the memory allocator for the SPU RAM pool. It acts
41 much like one would expect a malloc() function to act, although it does not
42 return a pointer directly, but rather an offset in SPU RAM.
43
44 \param size The amount of memory to allocate, in bytes.
45
46 \return The location of the start of the block on success,
47 or 0 on failure.
48*/
50
51/** \brief Free a block of allocated memory in the SPU RAM pool.
52
53 This function frees memory previously allocated with snd_mem_malloc().
54
55 \param addr The location of the start of the block to free.
56*/
58
59/** \brief Get the size of the largest allocateable block in the SPU RAM pool.
60
61 This function returns the largest size that can be currently passed to
62 snd_mem_malloc() and expected to not return failure. There may be more
63 memory available in the pool, especially if multiple blocks have been
64 allocated and freed, but calls to snd_mem_malloc() for larger blocks will
65 return failure, since the memory is not available contiguously.
66
67 \return The size of the largest available block of memory in
68 the SPU RAM pool.
69*/
71
72/** \brief Reinitialize the SPU RAM pool.
73
74 This function reinitializes the SPU RAM pool with the given base offset
75 within the memory space. There is generally not a good reason to do this in
76 your own code, but the functionality is there if needed.
77
78 \param reserve The amount of memory to reserve as a base.
79 \retval 0 On success (no failure conditions defined).
80*/
81int snd_mem_init(uint32 reserve);
82
83/** \brief Shutdown the SPU RAM allocator.
84
85 There is generally no reason to be calling this function in your own code,
86 as doing so will cause problems if you try to allocate SPU memory without
87 calling snd_mem_init() afterwards.
88*/
90
91/** \brief Initialize the sound system.
92
93 This function reinitializes the whole sound system. It will not do anything
94 unless the sound system has been shut down previously or has not been
95 initialized yet. This will implicitly replace the program running on the
96 AICA's ARM processor when it actually initializes anything. The default
97 snd_stream_drv will be loaded if a new program is uploaded to the SPU.
98*/
99int snd_init(void);
100
101/** \brief Shut down the sound system.
102
103 This function shuts down the whole sound system, freeing memory and
104 disabling the SPU in the process. There's not generally many good reasons
105 for doing this in your own code.
106*/
107void snd_shutdown(void);
108
109/** \brief Copy a request packet to the AICA queue.
110
111 This function is to put in a low-level request using the built-in streaming
112 sound driver.
113
114 \param packet The packet of data to copy.
115 \param size The size of the packet, in 32-bit increments.
116 \retval 0 On success (no error conditions defined).
117*/
118int snd_sh4_to_aica(void *packet, uint32 size);
119
120/** \brief Begin processing AICA queue requests.
121
122 This function begins processing of any queued requests in the AICA queue.
123*/
125
126/** \brief Stop processing AICA queue requests.
127
128 This function stops the processing of any queued requests in the AICA queue.
129*/
131
132/** \brief Transfer a packet of data from the AICA's SH4 queue.
133
134 This function is used to retrieve a packet of data from the AICA back to the
135 SH4. The buffer passed in should at least contain 1024 bytes of space to
136 make sure any packet can fit.
137
138 \param packetout The buffer to store the retrieved packet in.
139 \retval -1 On failure. Failure probably indicates the queue has
140 been corrupted, and thus should be reinitialized.
141 \retval 0 If no packets are available.
142 \retval 1 On successful copy of one packet.
143*/
144int snd_aica_to_sh4(void *packetout);
145
146/** \brief Poll for a response from the AICA.
147
148 This function waits for the AICA to respond to a previously sent request.
149 This function is not safe to call in an IRQ, as it does implicitly wait.
150*/
151void snd_poll_resp(void);
152
153/** \brief Separates stereo PCM samples into 2 mono channels.
154
155 Splits a buffer containing 2 interleaved channels of 16-bit PCM samples
156 into 2 separate buffers of 16-bit PCM samples.
157
158 \warning
159 All arguments must be 32-byte aligned.
160
161 \param data Source buffer of interleaved stereo samples
162 \param left Destination buffer for left mono samples
163 \param right Destination buffer for right mono samples
164 \param size Size of the source buffer in bytes (must be divisible by 32)
165
166 \sa snd_pcm16_split_sq()
167*/
168void snd_pcm16_split(uint32_t *data, uint32_t *left, uint32_t *right, size_t size);
169
170/** \brief Separates stereo PCM samples into 2 mono channels with SQ transfer.
171
172 Splits a buffer containing 2 interleaved channels of 16-bit PCM samples
173 into 2 separate buffers of 16-bit PCM samples by using the store queues
174 for data transfer.
175
176 \warning
177 All arguments must be 32-byte aligned.
178
179 \param data Source buffer of interleaved stereo samples
180 \param left Destination buffer address for left mono samples
181 \param right Destination buffer address for right mono samples
182 \param size Size of the source buffer in bytes (must be divisible by 32)
183
184 \sa snd_pcm16_split()
185 Store queues must be prepared before.
186*/
187void snd_pcm16_split_sq(uint32_t *data, uintptr_t left, uintptr_t right, size_t size);
188
189/** \brief Separates stereo PCM samples into 2 mono channels.
190
191 Splits a buffer containing 2 interleaved channels of 8-bit PCM samples
192 into 2 separate buffers of 8-bit PCM samples.
193
194 \param data Source buffer of interleaved stereo samples
195 \param left Destination buffer for left mono samples
196 \param right Destination buffer for right mono samples
197 \param size Size of the source buffer in bytes
198
199 \sa snd_adpcm_split()
200*/
201void snd_pcm8_split(uint32_t *data, uint32_t *left, uint32_t *right, size_t size);
202
203/** \brief Separates stereo ADPCM samples into 2 mono channels.
204
205 Splits a buffer containing 2 interleaved channels of 4-bit ADPCM samples
206 into 2 separate buffers of 4-bit ADPCM samples.
207
208 \param data Source buffer of interleaved stereo samples
209 \param left Destination buffer for left mono samples
210 \param right Destination buffer for right mono samples
211 \param size Size of the source buffer in bytes
212
213 \sa snd_pcm16_split()
214*/
215void snd_adpcm_split(uint32_t *data, uint32_t *left, uint32_t *right, size_t size);
216
217/** @} */
218
219__END_DECLS
220
221#endif /* __DC_SOUND_SOUND_H */
222
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
Common integer types.