Page 1 of 1

Talk to me about sound

Posted: Fri Mar 04, 2005 1:46 am
by mharris
Since the SPU (or is it SPU2 -- I don't even know the processor's name) is not officially documented anywhere for non-licensed developers, I have a bunch of questions that have arisen from digging through what code is available. Some are pretty obvious, but I'd just like some confirmation...
  • LIBSD is IOP-only -- there's no SifRpcLoop to communicate with the EE, right? And freesd.irx is a drop-in replacement for some PS2 models that don't have LIBSD in ROM.
  • Obviously, the SPU can play PCM streams, and most of sjpcm.irx is a wrapper to queue PCM buffers to LIBSD and to interface w/ the EE. Is the only supported bitrate 48KHz? Or can other rates be sent -- e.g., 44.1KHz (used by CD-DA), or 8KHz (for lower-quality audio)? My question is mostly about the capabilities of the SPU, not of sjpcm.irx here...
  • Is there a "midi-like" capability? In other words, a way to send note-on and note-off messages rather than PCM data? It looks like there is, based on some of the headers I've seen, but I haven't seen any code that uses it. If so, does the SPU use the General MIDI spec for the predefined channels (i.e., patch #1 is "Acoustic Grand Piano")?
  • Is the source for amigamod.irx available anywhere? It was initially written by Vzzrzzn, but the latest release I have (1.1) has comments about code changes from blackdroid. The only source code I've seen is just the EE RPC interface.
Doubtless I'll have further questions, but that'll do for now... thanks.

Re: Talk to me about sound

Posted: Fri Mar 04, 2005 4:37 am
by J.F.
mharris wrote:LIBSD is IOP-only -- there's no SifRpcLoop to communicate with the EE, right? And freesd.irx is a drop-in replacement for some PS2 models that don't have LIBSD in ROM.
Correct. There is an IRX to allow the EE to use the sound library. It's called librsd and you'll find it and some other info in this thread:
http://forums.ps2dev.org/viewtopic.php?t=867
Obviously, the SPU can play PCM streams, and most of sjpcm.irx is a wrapper to queue PCM buffers to LIBSD and to interface w/ the EE. Is the only supported bitrate 48KHz? Or can other rates be sent -- e.g., 44.1KHz (used by CD-DA), or 8KHz (for lower-quality audio)? My question is mostly about the capabilities of the SPU, not of sjpcm.irx here...
The SPU2 for the PS2 only handles 48KHz. The original SPU for PS1 compatibility only handles 44.1KHz. I don't know if the original SPU is available when using the SPU2.
Is there a "midi-like" capability? In other words, a way to send note-on and note-off messages rather than PCM data? It looks like there is, based on some of the headers I've seen, but I haven't seen any code that uses it. If so, does the SPU use the General MIDI spec for the predefined channels (i.e., patch #1 is "Acoustic Grand Piano")?
OSDSND allows you to setup and manipulate ADPCM voices. These voices are nominally clocked at 48KHz, but the pitch can be varied. They also can be turned on or off, and have an envelope. This can be used to generate the various MIDI instruments, but the SPU doesn't understand anything MIDI in particular.

Look at code for using the PS1's SPU ADPCM channels. The SPU2 has the same thing available, only clocked at 48KHz base and two cores for twice the channels.

Edit: OSDSND allows you to setup and use the SPU voices (up to 24). libsd has calls for handling the SPU2 voices in a similar manner (up to 48 voices). The SPU voices are clocked at 44.1KHz, while the SPU2 voices are clocked at 48KHz.

Posted: Fri Mar 04, 2005 6:33 am
by mrbrown
The SPU2 voices are always clocked at 48Khz. Where did you get that OSDSND provided voices that were 44Khz?

Posted: Fri Mar 04, 2005 7:25 am
by J.F.
mrbrown wrote:The SPU2 voices are always clocked at 48Khz. Where did you get that OSDSND provided voices that were 44Khz?
http://ps2dev.org/kb.x?T=745

If you check the code, OSDSND gives you 24 voices clocked at a 44.1KHz base. OSDSND is to the SPU as libsd is to the SPU2. An interesting experiment might be to try to use the two at once. It would certainly tell you if the SPU was useable at the same time as the SPU2.

Remember that voices have the ability to vary the playback rate by changing how much they step through the adpcm data. The sample rate is 44.1KHz, but if you make the step 1/2, the frequency of the voice is 22050 Hz. The PCM channel is fixed at 48/44.1 KHz.

Here's a doc on the SPU. Remember that the SPU2 isn't quite the same. There's more different than just the sample rate.

http://dev.paradogs.com/bin/docs/spu.txt

More good PSX info here:
http://www.syncscroller.net/psx/psx-index.html

Too bad there isn't info this good on the SPU2 yet. :(

Posted: Fri Mar 04, 2005 9:45 am
by mrbrown
The SPU Overview manual from Sony explicitly says that *both* cores of the SPU2 generate sound at 48Khz. I already know about the PITCH register, which only applies to ADPCM streams, but I was asking where did you get 44Khz for the fixed SPU core value (e.g. PCM streams).

OSDSND would have to "reset" the SPU2 into PS1 mode, in order to get a fixed value of 44Khz. There is no documented way to do this. Anyway, I doubt that's what happening but feel free to post code to prove me wrong. From the looks of it Icewater's code is wrong - OR - sit down for this one - OSDSND scales the pitch to 48Khz properly before setting the hardware register.

Posted: Fri Mar 04, 2005 1:18 pm
by J.F.
From what I understand, the IOP has ALL the hardware of the PS1 that was directly accessible by the PS1 CPU, period. It was needed for backwards compatibility. The only piece of PS1 hw the IOP doesn't have is the GPU as it was accessible only via DMA, so the DMA is intercepted and emulated on the PS2. The two SPU2 cores are in addition to the SPU, not in place of it. The SPU2 cores are accessed at a completely different location than the SPU. I have yet to see anything that indicates the SPU2 uses the SPU resources. It doesn't mean it doesn't, just that I haven't seen anything indicating it.

This would be an interesting area to check... make some kind of program that tries to access both the SPU and the SPU2 cores. See what happens. Whatever the case, the actual SPU core runs at 44.1KHz for PS1 compatibility. It's not a software issue as the SPU is directly accessible to the IOP and many PS1 programs bang on it directly. These work fine on the PS2, so the SPU core in the PS2 really is running at 44.1KHz.

Posted: Fri Mar 04, 2005 4:22 pm
by mrbrown
You are completely off here. I've been inside PS1DRV, and PS1DRV resets the SPU2 into compatibility mode. I have studied the code that does this. The point that I was trying to make is that OSDSND (being an IRX module) doesn't do it, meaning the SPU2 is always running at 48Khz, whether you use LIBSD or OSDSND.

There is no 'PS1 SPU' running side-by-side with the SPU2 in normal mode. You have two SPU cores running at 48Khz that make up the SPU2. In PS1 mode, you lose the second SPU core and the SPU runs at 44Khz.

You can't use the SPU2 in compatiblity mode without resetting the IOP into PS1 mode. You're welcome to try, but I guarantee you you'll get a friendly Bus Error when you do. The PS1 SPU registers don't exist in normal SPU2 mode.

I hope that's clear enough.

Posted: Fri Mar 04, 2005 5:07 pm
by J.F.
Yep. I kinda thought it might reuse the SPU resources for one of the cores, but there's nothing definitive I ever found. The OSDSND uses the SPU like it's in 44.1KHz, so I thought it might be possible they used separate resources. I haven't actually tried the OSDSND example code to see how it works (or doesn't as the case may be). The fact that OSDSND was in the ROM gave me the impression that Sony would make sure it worked, whether that meant switching the SPU into the proper mode or whatever.

I should probably disassemble the PS1DRV from my PS2 and look at all that myself. It would be interesting at the very least. In the meantime, better docs for libsd would be nice. You could load up to 48 voices and play mod/midi/mus files more easily. PS1 players did this. As it is, about the only thing I've seen anyone do with libsd is the PCM stream. I know the PCM stream can be redirected as binary to the SPDIF port which would be great for a player program for AC3/DTS audio streams. I use the optical out on my PS2. In it's default mode, whatever is the final output of the PCM channels is mirrored on the SPDIF, but it's just 16bit PCM.

Posted: Fri Mar 04, 2005 8:14 pm
by mrbrown
I think the main problem with folks using ADPCM streams for homebrew is that folks want to play mods or mp3's which means the PCM stream would have to be compressed first. On the IOP, that ain't fast :). Homebrew games or demos would definitely benefit from preprocessing sound into VAG.

Another issue is that the SPU2 only supports 2 simultaneous PCM streams, so anything wanting to do more than that has to mix streams in software.

Icewater's code is the only thing I've seen for PS2 homebrew that compresses PCM on-the-fly. Anybody want to come up with a fast ADPCM encoder on the IOP? :P