KallistiOS git master
Independent SDK for the Sega Dreamcast
Loading...
Searching...
No Matches
spu.h
Go to the documentation of this file.
1/* KallistiOS ##version##
2
3 dc/spu.h
4 Copyright (C) 2000, 2001 Megan Potter
5 Copyright (C) 2023, 2024 Ruslan Rostovtsev
6
7*/
8
9/** \file dc/spu.h
10 \brief Functions related to sound.
11 \ingroup audio_driver
12
13 This file deals with memory transfers and the like for the sound hardware.
14
15 \author Megan Potter
16 \author Ruslan Rostovtsev
17*/
18
19#ifndef __DC_SPU_H
20#define __DC_SPU_H
21
22#include <sys/cdefs.h>
23__BEGIN_DECLS
24
25#include <arch/memory.h>
26#include <dc/g2bus.h>
27
28/** \addtogroup audio_driver
29 @{
30*/
31
32/** \brief Sound ram address from the SH4 side */
33#define SPU_RAM_BASE 0x00800000
34#define SPU_RAM_UNCACHED_BASE (MEM_AREA_P2_BASE | SPU_RAM_BASE)
35
36/** \brief Copy a block of data to sound RAM.
37
38 This function acts much like memcpy() but copies to the sound RAM area.
39
40 \param to The offset in sound RAM to copy to. Do not include
41 the 0xA0800000 part, it is implied.
42 \param from A pointer to copy from.
43 \param length The number of bytes to copy. Automatically rounded
44 up to be a multiple of 4.
45*/
46void spu_memload(uintptr_t to, void *from, size_t length);
47
48
49/** \brief Copy a block of data to sound RAM by using the Store Queues.
50
51 This function acts much like memcpy() but copies to the sound RAM area
52 by using the Store Queues.
53
54 \param to The offset in sound RAM to copy to. Do not include
55 the 0xA0800000 part, it is implied.
56 \param from A pointer to copy from.
57 \param length The number of bytes to copy. Automatically rounded
58 up to be a multiple of 4.
59*/
60void spu_memload_sq(uintptr_t to, void *from, size_t length);
61
62/** \brief Copy a block of data to sound RAM by using DMA (or SQ on fails).
63
64 This function acts much like memcpy() but copies to the sound RAM area
65 by using the DMA. If DMA fails, then will be used the Store Queues.
66
67 \param to The offset in sound RAM to copy to. Do not include
68 the 0xA0800000 part, it is implied.
69 \param from A pointer to copy from.
70 \param length The number of bytes to copy. Must be a multiple of 32.
71*/
72void spu_memload_dma(uintptr_t to, void *from, size_t length);
73
74/** \brief Copy a block of data from sound RAM.
75
76 This function acts much like memcpy() but copies from the sound RAM area.
77
78 \param to A pointer to copy to.
79 \param from The offset in sound RAM to copy from. Do not include
80 the 0xA0800000 part, it is implied.
81 \param length The number of bytes to copy. Automatically rounded
82 up to be a multiple of 4.
83*/
84void spu_memread(void *to, uintptr_t from, size_t length);
85
86/** \brief Set a block of sound RAM to the specified value.
87
88 This function acts like memset4(), setting the specified block of sound RAM
89 to the given 32-bit value.
90
91 \param to The offset in sound RAM to set at. Do not include
92 the 0xA0800000 part, it is implied.
93 \param what The value to set.
94 \param length The number of bytes to copy. Automatically rounded
95 up to be a multiple of 4.
96*/
97void spu_memset(uintptr_t to, uint32_t what, size_t length);
98
99
100/** \brief Set a block of sound RAM to the specified value.
101
102 This function acts like memset4(), setting the specified block of sound RAM
103 to the given 32-bit value by using the Store Queues.
104
105 \param to The offset in sound RAM to set at. Do not include
106 the 0xA0800000 part, it is implied.
107 \param what The value to set.
108 \param length The number of bytes to copy. Automatically rounded
109 up to be a multiple of 4.
110*/
111void spu_memset_sq(uintptr_t to, uint32_t what, size_t length);
112
113/* DMA copy from SH-4 RAM to SPU RAM; length must be a multiple of 32,
114 and the source and destination addresses must be aligned on 32-byte
115 boundaries. If block is non-zero, this function won't return until
116 the transfer is complete. If callback is non-NULL, it will be called
117 upon completion (in an interrupt context!). Returns <0 on error. */
118
119/** \brief SPU DMA callback type. */
121
122/** \brief Copy a block of data from SH4 RAM to sound RAM via DMA.
123
124 This function sets up a DMA transfer from main RAM to the sound RAM with G2
125 DMA.
126
127 \param from A pointer in main RAM to transfer from. Must be
128 32-byte aligned.
129 \param dest Offset in sound RAM to transfer to. Do not include
130 the 0xA0800000 part, its implied. Must be 32-byte
131 aligned.
132 \param length Number of bytes to copy. Must be a multiple of 32.
133 \param block 1 if you want to wait for the transfer to complete,
134 0 otherwise (use the callback for this case).
135 \param callback Function to call when the DMA completes. Can be NULL
136 if you don't want to have a callback. This will be
137 called in an interrupt context, so keep that in mind
138 when writing the function.
139 \param cbdata Data to pass to the callback function.
140 \retval -1 On failure. Sets errno as appropriate.
141 \retval 0 On success.
142
143 \par Error Conditions:
144 \em EINVAL - Invalid channel \n
145 \em EFAULT - from or dest is not aligned \n
146 \em EIO - I/O error
147*/
148int spu_dma_transfer(void *from, uintptr_t dest, size_t length, int block,
149 spu_dma_callback_t callback, void *cbdata);
150
151/** \brief Enable the SPU.
152
153 This function resets all sound channels and lets the ARM out of reset.
154*/
155void spu_enable(void);
156
157/** \brief Disable the SPU.
158
159 This function resets all sound channels and puts the ARM in a reset state.
160*/
161void spu_disable(void);
162
163/** \brief Set CDDA volume.
164
165 Valid volume values are 0-15.
166
167 \param left_volume Volume of the left channel.
168 \param right_volume Volume of the right channel.
169*/
170void spu_cdda_volume(int left_volume, int right_volume);
171
172/** \brief Set CDDA panning.
173
174 Valid values are from 0-31. 16 is centered.
175
176 \param left_pan Pan of the left channel.
177 \param right_pan Pan of the right channel.
178*/
179void spu_cdda_pan(int left_pan, int right_pan);
180
181/** \brief Set master mixer settings.
182
183 This function sets the master mixer volume and mono/stereo setting.
184
185 \param volume The volume to set (0-15).
186 \param stereo 1 for stereo output, 0 for mono.
187*/
188void spu_master_mixer(int volume, int stereo);
189
190/** \brief Initialize the SPU.
191
192 This function will reset the SPU, clear the sound RAM, reinit the CDDA
193 support and run an infinite loop on the ARM.
194
195 \retval 0 On success (no error conditions defined).
196*/
197int spu_init(void);
198
199/** \brief Shutdown the SPU.
200
201 This function disables the SPU and clears sound RAM.
202
203 \retval 0 On success (no error conditions defined).
204*/
205int spu_shutdown(void);
206
207/** \brief Reset SPU channels. */
209
210/** @} */
211
212__END_DECLS
213
214#endif /* __DC_SPU_H */
215
G2 bus memory interface.
void spu_master_mixer(int volume, int stereo)
Set master mixer settings.
void spu_cdda_volume(int left_volume, int right_volume)
Set CDDA volume.
void spu_reset_chans(void)
Reset SPU channels.
g2_dma_callback_t spu_dma_callback_t
SPU DMA callback type.
Definition spu.h:120
int spu_dma_transfer(void *from, uintptr_t dest, size_t length, int block, spu_dma_callback_t callback, void *cbdata)
Copy a block of data from SH4 RAM to sound RAM via DMA.
void spu_enable(void)
Enable the SPU.
void spu_memload_dma(uintptr_t to, void *from, size_t length)
Copy a block of data to sound RAM by using DMA (or SQ on fails).
void spu_memread(void *to, uintptr_t from, size_t length)
Copy a block of data from sound RAM.
int spu_shutdown(void)
Shutdown the SPU.
void spu_cdda_pan(int left_pan, int right_pan)
Set CDDA panning.
void spu_memset_sq(uintptr_t to, uint32_t what, size_t length)
Set a block of sound RAM to the specified value.
void spu_memset(uintptr_t to, uint32_t what, size_t length)
Set a block of sound RAM to the specified value.
void spu_memload_sq(uintptr_t to, void *from, size_t length)
Copy a block of data to sound RAM by using the Store Queues.
void spu_disable(void)
Disable the SPU.
void spu_memload(uintptr_t to, void *from, size_t length)
Copy a block of data to sound RAM.
int spu_init(void)
Initialize the SPU.
void(* g2_dma_callback_t)(void *data)
G2Bus DMA interrupt callback type.
Definition g2bus.h:88
Constants for areas of the system memory map.