Desperation about Sounds/SPU

Audio and Music (Sound Processing Unit) based area of development, including VAB, XA, etc
Post Reply
User avatar
Jaberwocky
Active PSXDEV User
Active PSXDEV User
Posts: 35
Joined: Oct 31, 2019

Desperation about Sounds/SPU

Post by Jaberwocky » January 9th, 2020, 8:07 am

Hey again xO

slowly I start to feel really bad about constantly asking stuff about PSYQ, seems like I'm the only one having those questions...
However, I'm close to giving up so I thought I could ruin my non existing reputation by asking my questions.

After I learned a bit about rendering, I thought it would be a great moment to start experimenting with sounds - but I'm completely overwhelmed with everything right now!

I actually wanted to just play some music and some SFX - but I found a jungle of file formats. My first entry point was actually "Orions Website", there he wrote:
"On the Playstation, the Sound format is called VAG, it's a compressed sound format, and you only have 512Kbytes of space for compressed sound.
To convert a WAV to VAG, you can use a tool called VAGedit. It's pretty straightforward to use."

Okay! Seems easy! So I loaded some random .wav file and created two ~4MB .vag files >_> Yeah... Well I thought, no big deal - I can stream the music from the disk... right? So I started to search through the PSYQ samples for a tutorial how to handle .VAG files. And even though I found an folder with .VAG files, they were NEVER used! Instead they used .VAB, .VH and .VB files who seem to be related to each other. Sooo after problems with the VABTOOL and some research I ran over the thread "[Tutorial] Converting MIDI + Samples to SEQ + VAB" from ArthCarvalho. Which made things even worse for me... I still have no idea how .VAG integrates into .VAB - as I understood, I design an instrument with the .VAG files, load multiple of them into the .VAB file and... Confusion... I simply wanted to stream my oversized .VAG file...

So I kept searching and encountered the thread "VAG Example (VAG DEMO)" from Shadow. So I looked into that code and - yeah! Loading .VAG files but... dang! His .VAG file was small enough to fit the 512KB, also I didn't understood what it is about those multiple channels. So I looked into Orions code how he handles the .VAG files. I saw a lot of similarities to Shadows example, but he wrote stuff like:
u_long size = (adrs[12] << 24) | (adrs[13] << 16) | (adrs[14] << 8) | adrs[15];
u_short freq = (adrs[18] << 8) | adrs[19];

Where adrs was the address of the .VAG file - how did he knew those values? Also I read the the first 16bytes of VAG files must be 0 - so how can he read a size from this? Max confusion!

Last thing I found was the "XMPlay Example + Tools" by zeroZshadow. But what on earth are xm files and how do I generate them?

Now I sit here, and I'm confused as all hell...
The only thing I seem to understand is, that I could be happy with .VAG files smaller then 512KB, but... I still don't get the thing with the multiple channels and how to playback bigger files and stuff...
Maybe I stream my big file into a 512KB buffer and do a SpuWrite? But how do I know it is time to read next? Also... If I fill the 512KB Sound RAM, how could I also play SFX when they are also .VAG?
My gut feeling tells me that .VAB files would be good for SFX buuuut... I'm confusion.

I'm not sure if this reflects my desperation :/ I really feel lost but honestly, I don't want to drop PSX development because of this... It is to interesting to just quit like that :/

Also sorry if this question is dumb.

User avatar
Jaberwocky
Active PSXDEV User
Active PSXDEV User
Posts: 35
Joined: Oct 31, 2019

Post by Jaberwocky » January 11th, 2020, 3:56 am

After calming down I decided to try the code examples of the PSYQ regarding the sound. I hope to get there VB files running, maybe I understand enough to answer my questions....

Help and tips are still welcome of course xO

rama3
Verified
/// PSXDEV | ELITE ///
/// PSXDEV | ELITE ///
Posts: 510
Joined: Apr 16, 2017

Post by rama3 » January 12th, 2020, 2:16 am

Not sure if that helps you, but you need to keep the hardware in mind.
The SPU is basically a synthesizer chip with limited memory. You create tiny samples and play them like an automated keyboard.

There's no way your 4MB file can be played like that. It simply won't fit in RAM.
Instead, you can use CD audio or XA audio to stream from disk.
These streams can't be modified with the SPU synth features, they're basically just pass-through.

So you have these 2 methods to play sound.
If you want to use the SPU to play synth, you need to use fitting samples.
Only then the various file formats come into play :)

User avatar
Jaberwocky
Active PSXDEV User
Active PSXDEV User
Posts: 35
Joined: Oct 31, 2019

Post by Jaberwocky » January 13th, 2020, 3:26 am

rama3 wrote: January 12th, 2020, 2:16 am There's no way your 4MB file can be played like that. It simply won't fit in RAM.
Instead, you can use CD audio or XA audio to stream from disk.
These streams can't be modified with the SPU synth features, they're basically just pass-through.
Are there any examples or tutorials to learn that? All I see uses those VB and VH files...
rama3 wrote: January 12th, 2020, 2:16 am So you have these 2 methods to play sound.
If you want to use the SPU to play synth, you need to use fitting samples.
Only then the various file formats come into play :)
So uhm.... I noticed that the VB files of the example where 488KB in size - that is why they can use the synth correct? But how could you make BG music with that?

Edit:
So I found a .WAV to .XA converter and a coding example for .XA
Also I read that you can convert .wav to midi and from midi to .XM oo"
So... .XA and .XM are both for direct SPU streaming from CD correct? >_x

Which still makes me wonder how to make a background music then....

rama3
Verified
/// PSXDEV | ELITE ///
/// PSXDEV | ELITE ///
Posts: 510
Joined: Apr 16, 2017

Post by rama3 » January 13th, 2020, 9:08 am

Well, the synth part is just like MIDI.
You have samples to play and programmed notes make up your song.
So this is pretty hard, unless you're already making tracker / midi style music.

The example probably has a few samples in a bank (hence VB?).
So you need to get some notes instructions to the SPU and play them.
Maybe the example tells you how to do this?

rama3
Verified
/// PSXDEV | ELITE ///
/// PSXDEV | ELITE ///
Posts: 510
Joined: Apr 16, 2017

Post by rama3 » January 15th, 2020, 9:10 am

Again, I'm not sure what you've learned up until now.
This video should help illustrate. It's for the SNES, but the SNES APU is comparable to the PSX SPU ;p
https://www.youtube.com/watch?v=yse3a7ALZYA

User avatar
Jaberwocky
Active PSXDEV User
Active PSXDEV User
Posts: 35
Joined: Oct 31, 2019

Post by Jaberwocky » May 6th, 2020, 8:04 am

Thank you for the video rama3! This is actually a really good explanation :D

Since my desperation back then I managed to get CDDA and XA to run - however this was more following the examples and such. Today I tried it a bit more detailed and I have two questions about this:

1.) Following the examples I created the following code:

Code: Select all

void enable(bool doubleSpeed)
{
	// setup the XA playback - adjust the speed as needed by your XA samples
	u_char param[4];

	param[0] = (((doubleSpeed) ? CdlModeSpeed : 0x0)|CdlModeRT|CdlModeSF|CdlModeSize1);

	CdControlB(CdlSetmode, param, 0);
	CdControlF(CdlPause, 0);

	oldCallback = CdReadyCallback((CdlCB)cbready);
}
I created a 8 channel XA file but added only one song. With "doubleSpeed" set to true this worked really well. So I went down to a 4 channel XA - this one only worked if set doubleSpeed to false (In both cases I had 37.8Khz and Stereo).
However, when I went down to only one channel - then it didn't worked at all.
What setting is needed to play a one-channel XA file?

2.) I went back to "doubleSpeed = false" and a 4 channel XA file this time setting a 3min song to channel 0 and a 4min song to channel 1 - also I implemented a loop when the end of the XA file is reached.
As expected, when I played the 3min song I still had to wait additonal 1min before the song repeated. That makes sense to me!


But what can I do about this? Should all my XA songs have the same time so the looping applies to them or is there a way to detect that a single channel would be done now to force a loop?

I hope my questions are understandable >o< For question two I basicly want to loop after 3min for channel 0 and after 4min for channel 1.

Edit:
Found in a different thread a PDF about XA_Audio which explained the detection of an end with a video data thingy. This seems to work! However... I wonder where to normaly pick up that PDF. It was not part of the PSYQ I downloaded from here :< I wonder what else I'm missing....

rama3
Verified
/// PSXDEV | ELITE ///
/// PSXDEV | ELITE ///
Posts: 510
Joined: Apr 16, 2017

Post by rama3 » May 7th, 2020, 10:15 pm

I was going to point you to that PDF :)
It has the background to XA and how you carefully need to prepare your files and whatnot.
It's not easy to use, but it performs better than CDDA for a similar quality.

User avatar
Jaberwocky
Active PSXDEV User
Active PSXDEV User
Posts: 35
Joined: Oct 31, 2019

Post by Jaberwocky » May 8th, 2020, 5:09 am

Where does the PDF actually come from? Since it seems to not be a part of the PSYQ.
Are there more PDFs like that?

User avatar
Shadow
Verified
Admin / PSXDEV
Admin / PSXDEV
Posts: 2670
Joined: Dec 31, 2012
PlayStation Model: H2000/5502
Discord: Shadow^PSXDEV

Post by Shadow » May 9th, 2020, 1:57 pm

Mike Kavallierou wrote all about getting XA to work correctly in the SCEE Technical Note in June 1998.
:null:
XATUT.DOC
You do not have the required permissions to view the files attached to this post.
Development Console: SCPH-5502 with 8MB RAM, MM3 Modchip, PAL 60 Colour Modification (for NTSC), PSIO Switch Board, DB-9 breakout headers for both RGB and Serial output and an Xplorer with CAETLA 0.34.

PlayStation Development PC: Windows 98 SE, Pentium 3 at 400MHz, 128MB SDRAM, DTL-H2000, DTL-H2010, DTL-H201A, DTL-S2020 (with 4GB SCSI-2 HDD), 21" Sony G420, CD-R burner, 3.25" and 5.25" Floppy Diskette Drives, ZIP 100 Diskette Drive and an IBM Model M keyboard.

User avatar
Jaberwocky
Active PSXDEV User
Active PSXDEV User
Posts: 35
Joined: Oct 31, 2019

Post by Jaberwocky » May 11th, 2020, 6:36 pm

But where would I find that file in PSYQ? If I search for XATUT.DOC I don't find it. I'm just curious where to pick that file up and if there are other files like that explaining other things.

Also... I wonder: When I'm doing the XA-Streaming there is no chance to also load a different file from CD right? So something like jumping between XA and for example a TIM file while not interrupting the audio is not possible - correct?

User avatar
Shadow
Verified
Admin / PSXDEV
Admin / PSXDEV
Posts: 2670
Joined: Dec 31, 2012
PlayStation Model: H2000/5502
Discord: Shadow^PSXDEV

Post by Shadow » May 11th, 2020, 10:49 pm

That file was in one of the Sony XA sample directories if I recall correctly.

No, you cannot load anything from the CD-ROM whilst streaming CDDA or XA audio. To do that, you would need to create locally based SPU audio and stream it from the SPU RAM ('Crash Bash' is a perfect example. If you want to see this technique in action check out when it's loading a level). Or, if you want longer audio loops, stream from DRAM to SPU RAM (many PSX games did this such as 'Jackie Chan Stuntmaster').

- VAG/VAB audio gives the highest quality audio without the need for CD streaming, but at larger file sizes.
- XM audio is a tracker format and it can give you high quality audio too but it takes skill to compose a decent song.
Development Console: SCPH-5502 with 8MB RAM, MM3 Modchip, PAL 60 Colour Modification (for NTSC), PSIO Switch Board, DB-9 breakout headers for both RGB and Serial output and an Xplorer with CAETLA 0.34.

PlayStation Development PC: Windows 98 SE, Pentium 3 at 400MHz, 128MB SDRAM, DTL-H2000, DTL-H2010, DTL-H201A, DTL-S2020 (with 4GB SCSI-2 HDD), 21" Sony G420, CD-R burner, 3.25" and 5.25" Floppy Diskette Drives, ZIP 100 Diskette Drive and an IBM Model M keyboard.

User avatar
Jaberwocky
Active PSXDEV User
Active PSXDEV User
Posts: 35
Joined: Oct 31, 2019

Post by Jaberwocky » May 12th, 2020, 4:34 am

For some reason the design of the forum and website is totaly broken for me .w.
I have no idea why and if it is related to the cloudflare protection? It makes it difficult to read thingy cause... it's now kinda a text file...

Back to topic :D

The longer audio loop thing caught my attention :> How would I do this? I saw a Sony example of streaming VAG (or was it VAB?) files - so I assume that I would load an entire VAG to memory and then stream that memory region right?

However, could I also partially read that VAG file? For example like 2x sector sizes, let the code stream it, read like 1x sector size from a different file, jump back to the VAG file and read the rest again?

User avatar
Shadow
Verified
Admin / PSXDEV
Admin / PSXDEV
Posts: 2670
Joined: Dec 31, 2012
PlayStation Model: H2000/5502
Discord: Shadow^PSXDEV

Post by Shadow » May 12th, 2020, 10:42 pm

It's not easy to do. Basically you have the audio cut up into multiple segments. You then have a triple buffer system. So, you copy 3x VAG files into SPU RAM from separate buffers. The SPU then plays the first. When the first finishes, it plays the second, but as it's playing it copies the next segment into the first buffer. By the time this happens, it will play the third, and you copy the next segment into the second buffer. When the third finishes, it jumps to the first, and repeats the process.

I have done this, and the maximum song I could fit in RAM was ~2 minutes of audio (25 seconds of audio into 430 KB of RAM at a bitrate of 492kb/s). Of course, I used up all the available memory but it was a fun little test. For you you'd want to stream it into those buffers from the CD-ROM. My test was several buffers all locally based in RAM :)

As for the forum not loading the CSS, try clearing your cache.
Development Console: SCPH-5502 with 8MB RAM, MM3 Modchip, PAL 60 Colour Modification (for NTSC), PSIO Switch Board, DB-9 breakout headers for both RGB and Serial output and an Xplorer with CAETLA 0.34.

PlayStation Development PC: Windows 98 SE, Pentium 3 at 400MHz, 128MB SDRAM, DTL-H2000, DTL-H2010, DTL-H201A, DTL-S2020 (with 4GB SCSI-2 HDD), 21" Sony G420, CD-R burner, 3.25" and 5.25" Floppy Diskette Drives, ZIP 100 Diskette Drive and an IBM Model M keyboard.

User avatar
Jaberwocky
Active PSXDEV User
Active PSXDEV User
Posts: 35
Joined: Oct 31, 2019

Post by Jaberwocky » May 27th, 2020, 5:28 am

For some reason the forum is still messed up for me :c
I use a different browser now...

VAG streaming sounds difficult xO I should be happy with XA I guess.
However... some games do have an intro music for there songs which will not be looped. How can I create such a thing? Having 2 XA files? One containing the intro and the other one containing the loop?

User avatar
Shadow
Verified
Admin / PSXDEV
Admin / PSXDEV
Posts: 2670
Joined: Dec 31, 2012
PlayStation Model: H2000/5502
Discord: Shadow^PSXDEV

Post by Shadow » May 27th, 2020, 10:33 am

Yes you can do that with XA. Have one play the intro, and then another which has been composed to loop. Of course, there will be a delay when it loops because the laser head needs to move back to the start of the sector. VAG does not have any delays when looping because it's all RAM based.
Development Console: SCPH-5502 with 8MB RAM, MM3 Modchip, PAL 60 Colour Modification (for NTSC), PSIO Switch Board, DB-9 breakout headers for both RGB and Serial output and an Xplorer with CAETLA 0.34.

PlayStation Development PC: Windows 98 SE, Pentium 3 at 400MHz, 128MB SDRAM, DTL-H2000, DTL-H2010, DTL-H201A, DTL-S2020 (with 4GB SCSI-2 HDD), 21" Sony G420, CD-R burner, 3.25" and 5.25" Floppy Diskette Drives, ZIP 100 Diskette Drive and an IBM Model M keyboard.

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests