# PLAYSTATION PORTABLE SPECIFIC ISSUES / FEATURES

Introduction

This section describes how to get started with FMOD for PSP, and also some of the PSP 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 PSP specifically.
What to link and loading modules.
A simple PlayStation Portable application needs the following steps to be taken to use FMOD.
- Link /api/lib/fmod.a into your project.
  FMOD requires the following sony libraries and modules to be used as well to get audio support. They are linked and loaded by the user.
- Link library libsas.a into your project.
- Link weak import stub library file libatrac3plus_stub_weak.a into your project.
- Load module file sc_sascore.prx at runtime.
  If you require AT3 playback support, load the following sony run-time modules.
- Load module file libatrac3plus.prx
- Load module file libaudiocodec.prx
  Note that the default position for sc_sascore.prx and audiocodec.prx is at /usr/local/devkit/kmodule but it may differ on your machine.
  libatrac3plus.prx can be found normally at /usr/local/devkit/module.
  Loading the modules.
  For examples on how to load sony modules, see the FMOD examples.
  Load sony's sc_sascore.prx. If AT3 support is desired also load audiocodec.prx and libatrac3plus.prx. This is done from host0 or disc0 or whatever file device you store your files on.
  eg.
  /* load module */
  static SceUID load_module(const char *filename, SceKernelLMOption *lm_opt, SceKernelSMOption *sm_opt)
  {
  SceUID mid;
  int ret;
  /* load module */
  mid = sceKernelLoadModule((char *)filename, 0, lm_opt);
  if (mid < 0)
  {
  printf("fatal error : cannot load %s 0x%08x\n", filename, mid);
  return mid;
  }
  /* start module */
  if ((ret = sceKernelStartModule(mid, 0, NULL, NULL, sm_opt)) < 0)
  {
  printf("fatal error : cannot start %s 0x%08x\n", filename, ret);
  return ret;
  }
  return mid;
  }
  ...
  SceKernelLMOption kMode;
  SceUID sasMid;
  sasMid = 0;
  kMode.size = sizeof(kMode);
  kMode.mpidtext = SCE_KERNEL_PRIMARY_KERNEL_PARTITION;
  kMode.mpiddata = SCE_KERNEL_PRIMARY_KERNEL_PARTITION;
  kMode.position = SCE_KERNEL_LMWO_POS_Low;
  kMode.access = SCE_KERNEL_LMWO_ACCESS_Noseek;
  sasMid = load_module("host0:/usr/local/devkit/kmodule/sc_sascore.prx", &kMode, NULL);
  if(sasMid < 0)
  {
  printf ("fatal error : load SAS module\n");
  return -1;
  }
  Initialize FMOD.
  Call FSOUND_Init and proceed programming with the FMOD API as you would on any other platform.
  Release / Debug.
  fmod.a and fmodD.a have been supplied. fmodD 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.a and fmodD_small.a. These versions use less 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.

Formats supported - hardware / software

FMOD PSP 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 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.
Software mixing speed.
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 PSP 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 Portable 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 RAM. This is the fastest way to load sound data from UMD.

Memory managment.

If so desired, the user can limit fmod's RAM usage to a single block of pre-allocated memory.
If you want to limit FMOD's memory usage in this way, 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.

Streaming ATRAC music

FMOD supports the playback of .at3 files. All the user has to do is play it from disc0, or if they like, they can load the file into memory, then use FSOUND_OPENMEMORY to stream the file from memory.
Note that the user can use FSOUND_Stream_SetBufferSize to adjust the amount of memory FMOD uses when streaming a file, and if it is from memory, then it will require only a very small stream buffer.
If streaming from UMD, the buffer size need to be a lot larger. It should be the number of milliseconds between each read, which could be anywhere up to 5000ms.

Battery considerations

Note, that even though FMOD supports streaming multiple streams from UMD at once, this is not recommended. On the PlayStation Portable seeking should be avoided at all times to preserve movement of the umd read head and therefore battery life.
This also goes for data streaming. Do not stream data and music at the same time if there is seeking involved. Continuous seeking will degrade battery life because it has to mechanically move the seek head.
It may be preferable to play 'in memory' music such as sequenced formats like .MOD/.S3M/.XM or .IT. Another idea is to load an AT3 file into memory first, then stream the file from memory as has been mentioned previously in this documentation. As atrac can store a minute of audio per mb at 128kbs stereo, then you would need 3mb of memory for 3 minutes of music.

The "15-20% cpu problem"

Some users may notice a framerate impact when implementing audio. This is a known issue with Sony, and it is common knowledge among PSP developers that simply playing one sound in 'hardware' will cause up to 15-20% of the PSP's CPU to be used by audio.
The problem lies in Sony's libwave, and there is nothing that can be done about it from FMOD's side until the issue is resolved with sony. FMOD offers a software mixer that can bypass Sony's VAG routines, but it will still require libwave access which is the problem.