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