aboutsummaryrefslogtreecommitdiff
path: root/examples/sound/vagsample
diff options
context:
space:
mode:
authorJohn "Lameguy" Wilbert Villamor <lameguy64@gmail.com>2022-09-26 16:49:56 +0800
committerGitHub <noreply@github.com>2022-09-26 16:49:56 +0800
commitc4a2533d21dfd05cde841ea48c67b05e0e6a853f (patch)
treec7ef61653b157b69fb0956709366996ddbc4ecfa /examples/sound/vagsample
parenta8b404b3400c3ebd8e0b923dcaefcc49ea563e36 (diff)
parent86f0064afb8200e60dd80827535cac30d0eab028 (diff)
downloadpsn00bsdk-c4a2533d21dfd05cde841ea48c67b05e0e6a853f.tar.gz
Merge pull request #55 from spicyjpeg/psxmdec
Full MDEC support, C library refactors, cleanups and bugfixes (v0.20)
Diffstat (limited to 'examples/sound/vagsample')
-rw-r--r--examples/sound/vagsample/main.c73
1 files changed, 34 insertions, 39 deletions
diff --git a/examples/sound/vagsample/main.c b/examples/sound/vagsample/main.c
index 2b04c34..c79e68e 100644
--- a/examples/sound/vagsample/main.c
+++ b/examples/sound/vagsample/main.c
@@ -32,13 +32,14 @@
*/
#include <stdio.h>
-#include <sys/types.h>
+#include <stdint.h>
#include <psxetc.h>
#include <psxgte.h>
#include <psxgpu.h>
#include <psxpad.h>
#include <psxapi.h>
#include <psxspu.h>
+#include <hwregs_c.h>
extern const unsigned char proyt[];
extern const int proyt_size;
@@ -103,8 +104,8 @@ void init(void)
SpuSetTransferStartAddr(addr_temp);
// Upload first sound clip and wait for transfer to finish
- SpuWrite(((unsigned char*)proyt)+48, proyt_size-48);
- SpuWait();
+ SpuWrite((const uint32_t *) &proyt[48], proyt_size-48);
+ SpuIsTransferCompleted(SPU_TRANSFER_WAIT);
// Obtain the address of the sound and advance address for the next one
// Samples are addressed in 8-byte units, so it'll have to be divided by 8
@@ -115,8 +116,8 @@ void init(void)
// Upload second sound clip
SpuSetTransferStartAddr(addr_temp);
- SpuWrite(((unsigned char*)tdfx)+48, tdfx_size-48);
- SpuWait();
+ SpuWrite((const uint32_t *) &tdfx[48], tdfx_size-48);
+ SpuIsTransferCompleted(SPU_TRANSFER_WAIT);
// Obtain the address of the second sound clip
tdfx_addr = addr_temp/8;
@@ -127,7 +128,7 @@ void init(void)
// Begin pad polling
InitPAD( pad_buff[0], 34, pad_buff[1], 34 );
StartPAD();
-
+ ChangeClearPAD(0);
} /* init */
// Display function
@@ -158,27 +159,17 @@ int main(int argc, const char *argv[])
int counter,nextchan;
int cross_pressed;
int circle_pressed;
-
PADTYPE *pad;
- SpuVoiceRaw voice;
// Init stuff
init();
-
- // Set common values for the SpuVoiceRaw stuct
- // Technically one struct can be used to play all sounds as the
- // parameters are copied to the SPU registers
-
- voice.vol.left = 0x3FFE; // Left voice volume, 3FFEh = max
- voice.vol.right = 0x3FFE; // Right voice volume, 3FFEh = max
- voice.adsr_param = 0xdff18087; // ADSR parameters
-
+
// Main loop
counter = 0;
nextchan = 0;
cross_pressed = 0;
circle_pressed = 0;
-
+
while(1)
{
pad = (PADTYPE*)&pad_buff[0][0];
@@ -194,22 +185,24 @@ int main(int argc, const char *argv[])
if( !cross_pressed )
{
// Voice frequency
- // (400h = 11.25KHz, 1000h = 44.1KHz)
- voice.freq = 0x800;
+ // (800h = 22.05KHz)
+ SPU_CH_FREQ(nextchan) = 0x800;
// Voice start playback address
// (transfer address / 8)
- voice.addr = proyt_addr;
+ SPU_CH_ADDR(nextchan) = proyt_addr;
// Voice loop address
// (transfer address / 8)
- voice.loop_addr = proyt_addr;
-
+ SPU_CH_LOOP_ADDR(nextchan) = proyt_addr;
+ // Voice volume and envelope
+ SPU_CH_VOL_L(nextchan) = 0x3fff;
+ SPU_CH_VOL_R(nextchan) = 0x3fff;
+ SPU_CH_ADSR(nextchan) = 0x1fee80ff;
+
// Set voice to key-off to allow restart
- SpuSetKey(0, 1<<nextchan);
- // Set voice parameters
- SpuSetVoiceRaw(nextchan, &voice);
+ SPU_KEY_OFF = 1 << nextchan;
// Set voice to key-on
- SpuSetKey(1, 1<<nextchan);
-
+ SPU_KEY_ON = 1 << nextchan;
+
// Advance to next voice
nextchan++;
if( nextchan > 23 )
@@ -229,27 +222,29 @@ int main(int argc, const char *argv[])
if( !circle_pressed )
{
// Voice frequency
- // (400h = 11.25KHz, 1000h = 44.1KHz)
- voice.freq = 0x1000;
+ // (1000h = 44.1KHz)
+ SPU_CH_FREQ(nextchan) = 0x1000;
// Voice start playback address
// (transfer address / 8)
- voice.addr = tdfx_addr;
+ SPU_CH_ADDR(nextchan) = tdfx_addr;
// Voice loop address
// (transfer address / 8)
- voice.loop_addr = tdfx_addr;
-
+ SPU_CH_LOOP_ADDR(nextchan) = tdfx_addr;
+ // Voice volume and envelope
+ SPU_CH_VOL_L(nextchan) = 0x3fff;
+ SPU_CH_VOL_R(nextchan) = 0x3fff;
+ SPU_CH_ADSR(nextchan) = 0x1fee80ff;
+
// Set voice to key-off to allow restart
- SpuSetKey(0, 1<<nextchan);
- // Set voice parameters
- SpuSetVoiceRaw(nextchan, &voice);
+ SPU_KEY_OFF = 1 << nextchan;
// Set voice to key-on
- SpuSetKey(1, 1<<nextchan);
-
+ SPU_KEY_ON = 1 << nextchan;
+
// Advance to next voice
nextchan++;
if( nextchan > 23 )
nextchan = 0;
-
+
circle_pressed = 1;
}
}