Nugget
Bare-metal libraries and examples for the original PlayStation
Loading...
Searching...
No Matches
spu.h
Go to the documentation of this file.
1/*
2
3MIT License
4
5Copyright (c) 2019 PCSX-Redux authors
6
7Permission is hereby granted, free of charge, to any person obtaining a copy
8of this software and associated documentation files (the "Software"), to deal
9in the Software without restriction, including without limitation the rights
10to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11copies of the Software, and to permit persons to whom the Software is
12furnished to do so, subject to the following conditions:
13
14The above copyright notice and this permission notice shall be included in all
15copies or substantial portions of the Software.
16
17THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23SOFTWARE.
24
25*/
26
27#pragma once
28
29#include "hwregs.h"
30
31struct SPUVoice {
32 uint16_t volumeLeft;
33 uint16_t volumeRight;
34 uint16_t sampleRate;
36 uint16_t adsrLo; // +0x08: release rate/mode, sustain rate/dir/mode
37 uint16_t adsrHi; // +0x0A: attack mode/rate, decay rate, sustain level
38 uint16_t currentVolume;
40};
41
42#define SPU_VOICES ((volatile struct SPUVoice *)0x1f801c00)
43
44// Reverb configuration area, 1F801DC0h..1F801DFFh (rev00..rev1F).
45// Names match psx-spx: d* = SPU-RAM displacement/offset, m* = SPU-RAM
46// src/dst address, v* = volume. All 16-bit.
47struct SPUReverb {
48 uint16_t dAPF1; // +0x00 rev00 APF offset 1
49 uint16_t dAPF2; // +0x02 rev01 APF offset 2
50 uint16_t vIIR; // +0x04 rev02 reflection volume 1
51 uint16_t vCOMB1; // +0x06 rev03 comb volume 1
52 uint16_t vCOMB2; // +0x08 rev04 comb volume 2
53 uint16_t vCOMB3; // +0x0A rev05 comb volume 3
54 uint16_t vCOMB4; // +0x0C rev06 comb volume 4
55 uint16_t vWALL; // +0x0E rev07 reflection volume 2
56 uint16_t vAPF1; // +0x10 rev08 APF volume 1
57 uint16_t vAPF2; // +0x12 rev09 APF volume 2
58 uint16_t mLSAME; // +0x14 rev0A same-side reflect addr 1 left
59 uint16_t mRSAME; // +0x16 rev0B same-side reflect addr 1 right
60 uint16_t mLCOMB1; // +0x18 rev0C comb addr 1 left
61 uint16_t mRCOMB1; // +0x1A rev0D comb addr 1 right
62 uint16_t mLCOMB2; // +0x1C rev0E comb addr 2 left
63 uint16_t mRCOMB2; // +0x1E rev0F comb addr 2 right
64 uint16_t dLSAME; // +0x20 rev10 same-side reflect addr 2 left
65 uint16_t dRSAME; // +0x22 rev11 same-side reflect addr 2 right
66 uint16_t mLDIFF; // +0x24 rev12 diff-side reflect addr 1 left
67 uint16_t mRDIFF; // +0x26 rev13 diff-side reflect addr 1 right
68 uint16_t mLCOMB3; // +0x28 rev14 comb addr 3 left
69 uint16_t mRCOMB3; // +0x2A rev15 comb addr 3 right
70 uint16_t mLCOMB4; // +0x2C rev16 comb addr 4 left
71 uint16_t mRCOMB4; // +0x2E rev17 comb addr 4 right
72 uint16_t dLDIFF; // +0x30 rev18 diff-side reflect addr 2 left
73 uint16_t dRDIFF; // +0x32 rev19 diff-side reflect addr 2 right
74 uint16_t mLAPF1; // +0x34 rev1A APF addr 1 left
75 uint16_t mRAPF1; // +0x36 rev1B APF addr 1 right
76 uint16_t mLAPF2; // +0x38 rev1C APF addr 2 left
77 uint16_t mRAPF2; // +0x3A rev1D APF addr 2 right
78 uint16_t vLIN; // +0x3C rev1E input volume left
79 uint16_t vRIN; // +0x3E rev1F input volume right
80};
81
82#define SPU_REVERB ((volatile struct SPUReverb *)0x1f801dc0)
83
84#define SPU_VOL_MAIN_LEFT HW_U16(0x1f801d80)
85#define SPU_VOL_MAIN_RIGHT HW_U16(0x1f801d82)
86#define SPU_REVERB_LEFT HW_U16(0x1f801d84)
87#define SPU_REVERB_RIGHT HW_U16(0x1f801d86)
88#define SPU_KEY_ON_LOW HW_U16(0x1f801d88)
89#define SPU_KEY_ON_HIGH HW_U16(0x1f801d8a)
90#define SPU_KEY_OFF_LOW HW_U16(0x1f801d8c)
91#define SPU_KEY_OFF_HIGH HW_U16(0x1f801d8e)
92#define SPU_PITCH_MOD_LOW HW_U16(0x1f801d90)
93#define SPU_PITCH_MOD_HIGH HW_U16(0x1f801d92)
94#define SPU_NOISE_EN_LOW HW_U16(0x1f801d94)
95#define SPU_NOISE_EN_HIGH HW_U16(0x1f801d96)
96#define SPU_REVERB_EN_LOW HW_U16(0x1f801d98)
97#define SPU_REVERB_EN_HIGH HW_U16(0x1f801d9a)
98#define SPU_REVERB_ADDR HW_U16(0x1f801da2)
99// Sound RAM IRQ address (IRQ9). Triggers when a voice reads ADPCM data from
100// this address; for stable IRQs, align to the 16-byte ADPCM block boundary.
101#define SPU_IRQ_ADDR HW_U16(0x1f801da4)
102
103#define SPU_RAM_DTA HW_U16(0x1f801da6)
104#define SPU_CTRL HW_U16(0x1f801daa)
105#define SPU_RAM_DTC HW_U16(0x1f801dac)
106#define SPU_STATUS HW_U16(0x1f801dae)
107#define SPU_VOL_CD_LEFT HW_U16(0x1f801db0)
108#define SPU_VOL_CD_RIGHT HW_U16(0x1f801db2)
109#define SPU_VOL_EXT_LEFT HW_U16(0x1f801db4)
110#define SPU_VOL_EXT_RIGHT HW_U16(0x1f801db6)
111
112static inline void muteSpu() {
114 SPU_REVERB_LEFT = 0;
117}
#define SPU_VOL_MAIN_LEFT
Definition spu.h:84
#define SPU_REVERB_RIGHT
Definition spu.h:87
#define SPU_VOL_MAIN_RIGHT
Definition spu.h:85
#define SPU_REVERB_LEFT
Definition spu.h:86
Definition spu.h:47
uint16_t mRCOMB4
Definition spu.h:71
uint16_t dRSAME
Definition spu.h:65
uint16_t mRDIFF
Definition spu.h:67
uint16_t dLSAME
Definition spu.h:64
uint16_t dLDIFF
Definition spu.h:72
uint16_t mLAPF2
Definition spu.h:76
uint16_t mRCOMB2
Definition spu.h:63
uint16_t vAPF2
Definition spu.h:57
uint16_t vAPF1
Definition spu.h:56
uint16_t dAPF2
Definition spu.h:49
uint16_t vCOMB3
Definition spu.h:53
uint16_t mLDIFF
Definition spu.h:66
uint16_t dRDIFF
Definition spu.h:73
uint16_t vRIN
Definition spu.h:79
uint16_t vWALL
Definition spu.h:55
uint16_t mRAPF1
Definition spu.h:75
uint16_t vIIR
Definition spu.h:50
uint16_t mRCOMB1
Definition spu.h:61
uint16_t mRAPF2
Definition spu.h:77
uint16_t mLAPF1
Definition spu.h:74
uint16_t mLCOMB1
Definition spu.h:60
uint16_t mLCOMB4
Definition spu.h:70
uint16_t vCOMB1
Definition spu.h:51
uint16_t dAPF1
Definition spu.h:48
uint16_t mRCOMB3
Definition spu.h:69
uint16_t vCOMB4
Definition spu.h:54
uint16_t mLCOMB2
Definition spu.h:62
uint16_t vCOMB2
Definition spu.h:52
uint16_t mRSAME
Definition spu.h:59
uint16_t vLIN
Definition spu.h:78
uint16_t mLSAME
Definition spu.h:58
uint16_t mLCOMB3
Definition spu.h:68
Definition spu.h:31
uint16_t volumeLeft
Definition spu.h:32
uint16_t volumeRight
Definition spu.h:33
uint16_t adsrLo
Definition spu.h:36
uint16_t currentVolume
Definition spu.h:38
uint16_t sampleRepeatAddr
Definition spu.h:39
uint16_t sampleRate
Definition spu.h:34
uint16_t sampleStartAddr
Definition spu.h:35
uint16_t adsrHi
Definition spu.h:37