PlayStation 2 - Firelight Technologies Pty, Ltd.

# PLAYSTATION 2 SPECIFIC ISSUES / FEATURES

Introduction

This section describes how to get started with FMOD for PS2, and also some of the PS2 specific features available.

Getting Started

This section describes what you will need to link, and what you need to call to get up and running for PS2 specifically.
What to link and loading modules.
- Link /api/lib/fmod.a into your project.
- Put /api/fmod.irx into your modules directory. You have to load the IRX yourself using sceSifLoadModule. More about this follows.
  A simple PlayStation 2 application has to do the following to use FMOD.
  1.
  Load fmod.irx and sony's libsd.irx. This is done from host0 or cdrom0 or whatever file device you store your files on.
  Load libsd first, then fmod.
  eg.
  while (sceSifLoadModule(host0:modules/libsd.irx", 0, NULL) < 0)
  {
  printf("loading libsd.irx failed\n");
  }
  while (sceSifLoadModule("host0:modules/fmod.irx", 0, NULL) < 0)
  {
  printf("loading fmod.irx failed\n");
  }
  Note that the default position for libsd.irx is at /usr/local/sce/iop/modules/ but it may differ on your machine.
  What does each module do?
  - libsd.irx - This is a sony irx that contains the low level hardware routines needed by fmod.irx.
  - fmod.irx - This is the fmod library and contains the majority of the functionality.
  2.
  Remember to Initialize the IOP heap with sceSifInitIopHeap().
  This is to be called after the call to sceSifInitRpc(0) and before loading any modules.
  eg.
  sceSifInitRpc(0);
  sceSifInitIopHeap();
  WARNING! If you reboot the IOP you have to call the above again!!! Otherwise FMOD will fail to initialize.
  3.
  Call FSOUND_Init and proceed programming with the FMOD API as you would on any other platform.
  On PS2, you must call FSOUND_Update to get commands to issue.
  Mismatching fmod.a and fmod.irx versions are not tolerated.
  FMOD will fail to initialize if they are from different releases of FMOD.
  Release / Debug.
  fmod.irx and fmodD.irx have been supplied. fmodD.irx is debug, and slower, and prints out a log of FMOD progress, along with english explanations on errors if they occur.
  Stripped / Non stripped.
  You may notice there is also fmod_small.irx and fmodD_small.irx. These versions use less IOP ram than the full versions, but only because they have features removed.
  These features are removed in the _small versions.
  .MOD, .S3M, .XM, .IT, .WAV and .VAG support. Note for .VAG support, this is talking about the file format, so FSB "VAG" support still exists.
  Normal streaming (with FSB files), 3d sound and sample management remains.
  EE Thread Priority.
  Note that if the EE main thread priority is not changed from the default of 1, FMOD will change it to 32.
  No thread can start when the default priority is 1 so this is nescessary.
  FMOD uses 1 thread to receive messages from the IOP.

Formats supported - hardware / software

FMOD PS2 supports .VAG and .WAV, although FSB is the highly recommended format, see the next section on FSB files for more information about this.
.VAG is mixed in hardware and .WAV is mixed in software. .WAV mixing in software uses IOP processing time.
At the moment, depending on quality settings, FMOD can only mix around 12-20 channels of PCM data at once.
.MOD .S3M .XM and .IT music formats are supported, and are mixed in software.
Again currently only mods with 12-20 channels or less are recommended due to the CPU strain on the 33mhz IOP processor.
32 channel mods should be supported after more optimizations.
Software mixing speed on the IOP.
Using FSOUND_Mixer with one of the following controls the number of channels available in software. Remember hardware mixing is preferred so you may not have to encounter this issue.
- FSOUND_MIXER_AUTODETECT (non interpolating stereo output - fast)
- FSOUND_MIXER_QUALITY_AUTODETECT (high quality interpolating stereo output - slowest)
- FSOUND_MIXER_MONO (non interpolating mono output - fastest)
- FSOUND_MIXER_QUALITY_MONO (high quality interpolating mono output - slow)
FSOUND_Init on the PS2 accepts 24000 or 48000. 24000 is lower quality but increases the possible channel count significantly.
FMOD will not support other output rates! Do not try and use them! (erroneous rates just case the output rate to go to 48000)

The FSB format - The recommended format for samples and streams.

Although .WAV and .VAG formats are supported, for loading speed, and streaming speed it is highly recommended to use .FSB files.
FSB is hardware accelerated, WAV is not.
These are compiled batches of native PlayStation 2 SPU2 sound data, arranged so when loaded, it is one read to load the headers first, then the raw vag data (which is continuous), which is streamed into SPU2 ram. This is the fastest way to load sound data.

Memory managment.

IOP Memory.
Upon calling FSOUND_Init, FMOD allocates ALL remaining memory on the IOP.
This is so FMOD can store sounds in IOP ram if needed.
If you want to limit FMOD's IOP memory usage, simply call FSOUND_SetMemorySystem.
ie.
FSOUND_SetMemorySystem(NULL, 128*1024, NULL, NULL, NULL);
This will force FMOD to only use 128kb of IOP memory.
Note that setting too low a value will cause FMOD to fail in its internal system memory allocations and FSOUND_Init could even fail.
EE Memory.
The EE memory footprint is minimal. There is no dynamic memory allocation on the EE.
The EE library is simply a command layer wrapping all FMOD api functions, and uses nothing but static structures and memory to avoid malloc/free/new/delete issues on the EE side.
It uses this library to pass commands to the IOP for processing on that CPU.

Reverb.

You have access to the hardware PlayStation 2 SPU2 reverb through FMOD's FSOUND_Reverb_xxx API.
Note that the SPU2 Reverb is a lot more primitive than I3DL2 reverb and EAX3.
In the FSOUND_REVERB_PROPERTIES structure, only Environment, Room and Flags are supported.
'Environment'

This is a value between 0 and 9 mapping to the sony reverb modes.
You will find 9 special presets for the PlayStation 2 with this environment value set accordingly.
ie
FSOUND_PRESET_PS2_ROOM
FSOUND_PRESET_PS2_STUDIO_A
FSOUND_PRESET_PS2_STUDIO_B
FSOUND_PRESET_PS2_STUDIO_C
FSOUND_PRESET_PS2_HALL
FSOUND_PRESET_PS2_SPACE
FSOUND_PRESET_PS2_ECHO
FSOUND_PRESET_PS2_DELAY
FSOUND_PRESET_PS2_PIPE
The other presets will not work, except for FSOUND_PRESET_OFF.

'Room'

This still controls the amount of reverb mixed into the output.
Normally it is in decibels, between -10000 (silent) and 0 (full volume), and it is the same range on the PlayStation 2, but it is a linear scale between -10000 and 0, not a logarithmic one.

'Flags'

This only utilizes the following fields on PlayStation 2.
FSOUND_REVERB_FLAGS_CORE0 (hardware voices 0 to 23)
FSOUND_REVERB_FLAGS_CORE1 (hardware voices 24 to 47)
This tells the FMOD engine which core, or set of hardware voices to apply the reverb settings to.
By default (in the presets) it is set to apply to both cores, but you can remove these flags to control each core seperately.

Note that FSOUND_Reverb_SetChannelProperties is supported through the 'Room' parameter only,
and that this value is binary, ie -10000 is 'reverb off' for the channel, and anything else is 'reverb on'.

FSOUND_SetDiskBusy

This function is usually not optional and is essential for smooth running disk cooperation between fmod and the game.
This function causes mutual exclusion for the cdrom or host0 so that you don't get read errors when trying to access the disk while fmod is playing a stream or accessing the disk in some manner (ie opening a bank or stream in FSOUND_NONBLOCKING mode)
In your game code you would do something like this:
FSOUND_SetDiskBusy(TRUE);
sceRead(...);
FSOUND_SetDiskBusy(FALSE);
This will block on a semaphore in FSOUND_SetDiskBusy(TRUE) if fmod is using the disk, and if it enters and executes the sceRead/sceCdRead, fmod will not access the disk, and instead wait until it is available to use again.
Note - if you set this for too long, audio streams may start to skip / stutter, because FMOD didnt get enough time to fill its audio buffer. Make sure you either split up your own reads into smaller chunks, or make a bigger buffersize for FMOD to use with FSOUND_Stream_SetBufferSize.

Dolby Prologic 2 output

Use FSOUND_SetSpeakerMode(FSOUND_SPEAKERMODE_PROLOGIC2) or FSOUND_SetSpeakerMode(FSOUND_SPEAKERMODE_PROLOGIC2_INTERIOR) to enable 5.1 surround sound on ps2.
The interior mode uses twice as many hardware voices (meaning you effectively only get 24 voices instead of 48), but allows sounds to smoothly move from left to right and vice versa, where the normal mode will 'jump' from one speaker to the other if running straight along the X axis.
It is a tradeoff between voices and quality, if you need to, you should evaluate both methods to see which works better.
Note on a stereo sound system, the interior 2 voice method will cause a phasing effect, which can sound odd or bad, it is really meant for a prologic 2 system.

Volume ramping

Most games released on the ps2 (not using FMOD) make click and pop noises because the hardware doesn't support smooth volume or pan changes.
FMOD has implemented an advanced ramping system that not many people know about or are too put off by the difficulty of the method.
You can enable this as a flag in FSOUND_Init using the FSOUND_INIT_PS2_USEVOLUMERAMPING flag.
Turning this on will reduce hardware clicks or remove them, producing clean sounding audio, giving you an advantage over your competitors!