summaryrefslogtreecommitdiff
path: root/libpsx/include/psxspu.h
blob: 9c5178123f6529c59497dbfc3978ba0a9ccaf72c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
#ifndef _SPU_H
#define _SPU_H

#ifdef __cplusplus
extern "C"
{
#endif

#define SPU_ADDR						*((volatile unsigned short*)0x1f801da6)
#define SPU_DATA						*((volatile unsigned short*)0x1f801da8)
#define SPU_CONTROL 					*((volatile unsigned short*)0x1f801daa)
#define SPU_STATUS					*((volatile unsigned short*)0x1f801dac)
#define SPU_STATUS2					*((volatile unsigned short*)0x1f801dae)
#define SPU_MVOL_L					*((volatile unsigned short*)0x1f801d80)
#define SPU_MVOL_R					*((volatile unsigned short*)0x1f801d82)
#define SPU_REVERB_L					*((volatile unsigned short*)0x1f801d84)
#define SPU_REVERB_R					*((volatile unsigned short*)0x1f801d86)
#define SPU_KEY_ON1           				*((volatile unsigned short*)0x1f801d88)
#define SPU_KEY_ON2	            			*((volatile unsigned short*)0x1f801d8a)
#define SPU_KEY_OFF1           				*((volatile unsigned short*)0x1f801d8c)
#define SPU_KEY_OFF2            			*((volatile unsigned short*)0x1f801d8e)
#define SPU_KEY_FM_MODE1				*((volatile unsigned short*)0x1f801d90)
#define SPU_KEY_FM_MODE2				*((volatile unsigned short*)0x1f801d92)
#define SPU_KEY_NOISE_MODE1			*((volatile unsigned short*)0x1f801d94)
#define SPU_KEY_NOISE_MODE2			*((volatile unsigned short*)0x1f801d96)
#define SPU_KEY_REVERB_MODE1			*((volatile unsigned short*)0x1f801d98)
#define SPU_KEY_REVERB_MODE2			*((volatile unsigned short*)0x1f801d9a)
#define SPU_CD_MVOL_L					*((volatile unsigned short*)0x1f801db0)
#define SPU_CD_MVOL_R					*((volatile unsigned short*)0x1f801db2)
#define SPU_EXT_VOL_L					*((volatile unsigned short*)0x1f801db4)
#define SPU_EXT_VOL_R					*((volatile unsigned short*)0x1f801db6)
#define SPU_REVERB_WORK_ADDR			*((volatile unsigned short*)0x1f801da2)
#define SPU_VOICE_BASE_ADDR(x)			(0x1f801c00 + (x<<4))

/** Start address of sound data in Sound RAM */
#define SPU_DATA_BASE_ADDR		0x1010
/** Maximum volume. */
#define SPU_MAXVOL				0x3FFF

/** VAG file */

typedef struct
{
	/** Version. */
	unsigned int version;
	/** Data size. */
	unsigned int data_size;
	/** Sample rate. */
	unsigned int sample_rate;
	/** Name */
	unsigned char name[16];
	/** Pointer to sound data */
	const void *data;
	/** Address in Sound RAM where the sound data was uploaded */
	unsigned int spu_addr;
	/** [Runtime] Voice this VAG is currently being played on */
	char cur_voice;
}SsVag;

/**
 * Set voice volume.
 * @param voice Voice number (0-23)
 * @param left Left channel volume
 * @param right Right channel volume
 */

void SsVoiceVol(int voice, unsigned short left, unsigned short right);

/**
 * Set voice pitch.
 * @param voice Voice
 * @param pitch Pitch.
 */

void SsVoicePitch(int voice, unsigned short pitch);


/**
 * Set start Sound RAM address for voice.
 * @param voice Voice
 * @param addr Start address in Sound RAM (multiplier of 8)
 */

void SsVoiceStartAddr(int voice, unsigned int addr);

/**
 * Set ADSR level for voice
 * @param voice Voice
 * @param level ADSR level
 * @param rate ADSR rate
 */

void SsVoiceADSRRaw(int voice, unsigned short level, unsigned short rate);

/**
 * Set repeat address for voice
 * @param voice Voice
 * @param addr Address in Sound RAM (multiplier of 8)
 */

void SsVoiceRepeatAddr(int voice, unsigned int addr);

/**
 * Set a voice to 'on'. This has the effect of playing the sound specified for the voice.
 * @param voice Voice
 */

void SsKeyOn(int voice);

/**
 * Set a voice to 'off'. This stops the sound specified for the voice.
 * @param voice Voice
 */

void SsKeyOff(int voice);

/**
 * Set the voices specified by the bitmask to 'on'. Like SsKeyOn()
 * @param mask Bitmask
 */

void SsKeyOnMask(int mask);

/**
 * Set the voices specified by the bitmask to 'off'. Like SsKeyOff()
 * @param mask Bitmask
 */

void SsKeyOffMask(int mask);

/**
 * Wait for the SPU to be ready.
 */

void SsWait(void);

/**
 * Intialize the SPU.
 */

void SsInit(void);

/**
 * Uploads sound data in PSX ADPCM format to Sound RAM.
 * @param addr Pointer to PSX ADPCM sound data in main RAM
 * @param size Sound data size
 * @param spu_addr Destination address in Sound RAM (multiplier of 8).
 */

void SsUpload(const void *addr, int size, int spu_addr);

/**
 * Converts a sampling rate in hertz to PlayStation pitch rate used by the SPU.
 * @param hz Sampling rate in hertz.
 * @return PlayStation pitch rate
 */

unsigned short SsFreqToPitch(int hz);

/**
 * Reads information from a buffer containg a VAG file and stores it inside a SsVag structure.
 * @param vag Pointer to structure in which to store information.
 * @param data Pointer to VAG file data
 */

int SsReadVag(SsVag *vag, const void *data);

/**
 * Uploads the sound data specified by a SsVag structure to the specified address in Sound RAM.
 * The SsVag structure can then be used for playing with SsPlayVag()
 * @param vag Pointer to SsVag structure
 * @param spu_addr Destination address in Sound RAM (multiplier of 8)
 */

void SsUploadVagEx(SsVag *vag, int spu_addr);


/**
 * Uploads the sound data specified by a SsVag structure to Sound RAM, beginning from the
 * base of usable Sound RAM and continuing from there, in an automatic fashion.
 * @param vag Pointer to SsVag structure
 */

void SsUploadVag(SsVag *vag);

/**
 * Plays the sound specified by the SsVag structure at specified voice and volume.
 * @param vag Pointer to SsVag structure
 * @param voice Voice
 * @param vl Left channel volume
 * @param vr Right channel volume
 */

void SsPlayVag(SsVag *vag, unsigned char voice, unsigned short vl,
	unsigned short vr);

/**
 * Stops the sound specified by the SsVag structure
 * @param vag Pointer to SsVag structure
 */

void SsStopVag(SsVag *vag);

/**
 * Tell SsUploadVag() to start uploading from the base of usable Sound RAM again.
 */

void SsResetVagAddr(void);

/**
 * Enable CD Audio.
 */

void SsEnableCd(void);

/**
 * Enable External audio. (???)
 */

void SsEnableExt(void);

/**
 * Set CD Audio volume.
 * @param left Left channel volume
 * @param right Right channel volume
 */

void SsCdVol(unsigned short left, unsigned short right);

#ifdef __cplusplus
}
#endif

#endif