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