summaryrefslogtreecommitdiff
path: root/libpsx/src/spu.c
diff options
context:
space:
mode:
Diffstat (limited to 'libpsx/src/spu.c')
-rw-r--r--libpsx/src/spu.c72
1 files changed, 36 insertions, 36 deletions
diff --git a/libpsx/src/spu.c b/libpsx/src/spu.c
index 441acb6..53ddf2d 100644
--- a/libpsx/src/spu.c
+++ b/libpsx/src/spu.c
@@ -22,17 +22,17 @@ void SsVoiceVol(int voice, unsigned short left, unsigned short right)
void SsVoicePitch(int voice, unsigned short pitch)
{
unsigned short *a = (unsigned short*)SPU_VOICE_BASE_ADDR(voice);
-
+
a[2] = pitch;
}
void SsVoiceStartAddr(int voice, unsigned int addr)
{
-// address given is real address, then it is divided by eight when written to the register
+// address given is real address, then it is divided by eight when written to the register
// example: SSVoiceStartAddr(0, 0x1008) , writes 0x201 on the register which means 0x1008
-
+
unsigned short *a = (unsigned short*)SPU_VOICE_BASE_ADDR(voice);
-
+
a[3] = (addr >> 3);
}
@@ -50,17 +50,17 @@ void SsVoiceRepeatAddr(int voice, unsigned int addr)
// the explanation for SSVoiceStartAddr() is valid for this function as well
unsigned short *a = (unsigned short*)SPU_VOICE_BASE_ADDR(voice);
-
+
a[7] = (addr >> 3);
}
void SsKeyOn(int voice)
{
unsigned int i = 1 << voice;
-
+
SPU_KEY_ON1 = i & 0xffff;
SPU_KEY_ON2 = i >> 16;
-
+
/* while(SPU_KEY_ON1 != (i & 0xffff));
while(SPU_KEY_ON2 != (i >> 16));
*/
@@ -69,7 +69,7 @@ void SsKeyOn(int voice)
void SsKeyOff(int voice)
{
unsigned int i = 1 << voice;
-
+
SPU_KEY_OFF1 = i & 0xffff;
SPU_KEY_OFF2 = i >> 16;
}
@@ -98,11 +98,11 @@ void SsInit()
int x;
printf("Initializing SPU (Sound Synthesizer)...\n");
-
+
DPCR |= 0xB0000;
-
+
SPU_MVOL_L = 0x3fff;
- SPU_MVOL_R = 0x3fff;
+ SPU_MVOL_R = 0x3fff;
SPU_CONTROL = 0x0;
SsWait();
@@ -110,7 +110,7 @@ void SsInit()
SPU_STATUS = 0x4; // Must be done, but not totally understood
while(SPU_STATUS2 & 0x7ff);
-
+
SPU_REVERB_L = 0x0;
SPU_REVERB_R = 0x0;
@@ -136,10 +136,10 @@ void SsInit()
SPU_EXT_VOL_R = 0x0;
// set volume of all voices to 0 and adsr to 0,0
-
+
for(x = 0; x < 24; x++)
{
- SsVoiceVol(x, 0, 0);
+ SsVoiceVol(x, 0, 0);
SsVoiceADSRRaw(x, 0, 0);
}
@@ -149,40 +149,40 @@ void SsInit()
SPU_REVERB_WORK_ADDR = 0xFFFE; // Reverb work address in SPU memory, 0x1fff * 8 = 0xFFF8
ss_vag_addr = SPU_DATA_BASE_ADDR;
-
+
printf("SPU/SS Initialized.\n");
}
-// This implementation of SsUpload() was contributed by Shendo
+// This implementation of SsUpload() was contributed by Shendo
// It waits either for a period of time or for the status flags to be raised, whichever comes first.
// This makes it work also on ePSXe, which never raises the status flags.
-void SsUpload(void *addr, int size, int spu_addr)
+void SsUpload(const void *addr, int size, int spu_addr)
{
- unsigned short *ptr = addr;
+ const unsigned short *ptr = addr;
int i;
-
+
while(size > 0)
- {
+ {
SPU_STATUS = 4; // Sound RAM Data Transfer Control
SPU_CONTROL = SPU_CONTROL & ~0x30; // SPUCNT.transfer_mode = 0 (STOP)
-
-
+
+
for(i = 0; i < 100; i++)
if(((SPU_STATUS2 >> 4) & 3) == 0)break; // wait until SPUSTAT.transfer is 0 (STOP)
-
+
SPU_ADDR = spu_addr >> 3;
for(i = 0; i < 32; i++)
SPU_DATA = ptr[i];
-
+
SPU_CONTROL = (SPU_CONTROL & ~0x30) | 16; // SPUCNT.transfer_mode = 1 (MANUAL)
-
+
for(i = 0; i < 100; i++)
if(((SPU_STATUS2 >> 4) & 3) == 1)break; // wait until SPUSTAT.transfer is 1 (MANUAL)
-
+
while(SPU_STATUS2 & 0x400); // wait for transfer busy bit to be cleared
-
+
spu_addr += 64;
ptr += 32;
size-=64;
@@ -194,24 +194,24 @@ unsigned short SsFreqToPitch(int hz)
// Converts a normal samples per second frequency value in Hz
// in a pitch value
-// i.e. 44100 -> 0x1000, 22050 -> 0x800
-
+// i.e. 44100 -> 0x1000, 22050 -> 0x800
+
return (hz << 12) / 44100;
}
-int SsReadVag(SsVag *vag, void *data)
+int SsReadVag(SsVag *vag, const void *data)
{
- unsigned char *i = data;
-
+ const unsigned char *i = data;
+
if(strncmp(data, "VAGp", 4) != 0)
return 0;
-
+
vag->version = (i[4]<<24)|(i[5]<<16)|(i[6]<<8)|i[7];
vag->data_size = (i[12]<<24)|(i[13]<<16)|(i[14]<<8)|i[15];
vag->sample_rate = (i[16]<<24)|(i[17]<<16)|(i[18]<<8)|i[19];
memcpy(vag->name, &i[32], 16);
vag->data = &i[48];
-
+
return 1;
}
@@ -229,14 +229,14 @@ void SsUploadVag(SsVag *vag)
ss_vag_addr += vag->data_size;
}
-void SsPlayVag(SsVag *vag, unsigned char voice, unsigned short vl,
+void SsPlayVag(SsVag *vag, unsigned char voice, unsigned short vl,
unsigned short vr)
{
SsVoicePitch(voice, SsFreqToPitch(vag->sample_rate));
SsVoiceStartAddr(voice, vag->spu_addr);
SsVoiceVol(voice, vl, vr);
SsKeyOn(voice);
-
+
vag->cur_voice = voice;
}