frno7 / linux

Linux 2.2, 2.6, 3.x, 4.x and 5.x kernels for the PlayStation 2.
Other
84 stars 5 forks source link

Enable the SPU1 and SPU2 sound processing units #16

Open frno7 opened 5 years ago

frno7 commented 5 years ago

Enable the SPU1 and SPU2 sound processing units.

Ravenslofty commented 5 years ago

The SPU2 is accessed through IOP DMA, I believe, so it would need to be DMA'd into IOP memory, then into SPU2 memory, Additionally, the SPU2 is a synthesizer, so I have no clue how one would go about writing an ALSA driver for it to get desktop sound. Perhaps use a buffer of audio as a "sample" that you play?

frno7 commented 5 years ago

The SPU2 is accessed through IOP DMA, I believe, so it would need to be DMA'd into IOP memory, then into SPU2 memory,

Is there any efficient way to stream audio via the SIF, using tagged DMA?

Additionally, the SPU2 is a synthesizer, so I have no clue how one would go about writing an ALSA driver for it to get desktop sound. Perhaps use a buffer of audio as a "sample" that you play?

Perhaps something similar to a MIDI sequencer would be a suitable device?

Ravenslofty commented 5 years ago

I apologise for the delay in responding, but Real Life happened.

I just read through the SPU2 User's Manual, and there is actually support for sending buffers of audio directly to the SPU2. Writing to SPU2 address 2000-21FF places a buffer of 16-bit samples in the SPU2 CORE0 left channel; 2200-23FF is the same for the right channel, and 2400-27FF is the same for CORE1, but I don't think there's any significant use to writing to both CORE0 and CORE1. Since the SPU2 output frequency depends on the IOP frequency (it outputs at 1/768 the IOP clock), sample rate is effectively locked at 48kHz while running Linux.

Is there any efficient way to stream audio via the SIF, using tagged DMA?

The SPU2 UM states that it supports AutoDMA, which is essentially reading samples directly from RAM. However, it is entirely undocumented; I believe @PSI-Rockin would know more details about how it functions.

thp commented 1 year ago

(This might not be fully relevant, apologies if it's just noise...)

The ps2sdk implements audio streaming via the "audsrv" IOP module:

https://github.com/ps2dev/ps2sdk/tree/master/iop/sound/audsrv/src

The EE side of things is implemented using the "audsrv" RPC library:

https://github.com/ps2dev/ps2sdk/tree/master/ee/rpc/audsrv/src

Here's an example how this is used:

https://github.com/ps2dev/ps2sdk/tree/master/ee/rpc/audsrv/samples/playwav

thp commented 1 year ago

The 2.2 kernel port also has a "ps2sd" driver that probably implements an audio device:

https://github.com/jur/linux-2.2.1-ps2/blob/master/drivers/ps2/sd.c https://github.com/jur/linux-2.2.1-ps2/blob/master/drivers/ps2/sdmixer.c

(Edit: Nevermind, this seems to be using some BIOS calls which I read were not supported in this new port?)

2.4.17 (from Black Rhino LInux Live DVD) has these:

https://github.com/rickgaiser/linux-2.4.17-ps2/blob/master/drivers/ps2/sd.c https://github.com/rickgaiser/linux-2.4.17-ps2/blob/master/drivers/ps2/sdmixer.c

According to the README there:

4. To get sound working you need to copy old versions of LIBSD.IRX and
   SDRDRV.IRX to mc0:kloader. The version number of SDRDRV.IRX should be 2.0 or
   smaller. You need to enable these modules in the kernelloader. For this you
   need to interrupt the auto boot and save the configuration after you enable
   the modules.

The mentioned files are on the PS2 PAL Linux Discs, Disc 1:

MODULES/MOD203/LIBSD.IRX
MODULES/MOD203/SDRDRV.IRX

(Again, also here, it might be that BIOS calls are required, haven't looked too closely)

frno7 commented 1 year ago

Hi @thp! Apologies for the late reply. Github is no longer posting email notifications, apparently.

(Edit: Nevermind, this seems to be using some BIOS calls which I read were not supported in this new port?)

Yeah, BIOS memory is completely reclaimed by this Linux kernel. However, the Linux kernel does implement a small subset of the RPC protocol used by IOP (IRX) modules, for example to allocate memory when the IOP has booted. The plan is to make a free software implementation of the audio driver, and thereby avoid dependencies on Sony modules. The main problem with implementing drivers is usually lack of (or incomplete) hardware documentation.