PSXSDK
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros
Macros | Functions
spu.c File Reference
#include <stdio.h>
#include <string.h>
#include <psx.h>

Macros

#define SPU_ADDR   *((unsigned short*)0x1f801da6)
 PSXSDK.
 
#define SPU_DATA   *((unsigned short*)0x1f801da8)
 
#define SPU_CONTROL   *((unsigned short*)0x1f801daa)
 
#define SPU_STATUS   *((unsigned short*)0x1f801dac)
 
#define SPU_STATUS2   *((unsigned short*)0x1f801dae)
 
#define SPU_MVOL_L   *((unsigned short*)0x1f801d80)
 
#define SPU_MVOL_R   *((unsigned short*)0x1f801d82)
 
#define SPU_REVERB_L   *((unsigned short*)0x1f801d84)
 
#define SPU_REVERB_R   *((unsigned short*)0x1f801d86)
 
#define SPU_KEY_ON1   *((unsigned short*)0x1f801d88)
 
#define SPU_KEY_ON2   *((unsigned short*)0x1f801d8a)
 
#define SPU_KEY_OFF1   *((unsigned short*)0x1f801d8c)
 
#define SPU_KEY_OFF2   *((unsigned short*)0x1f801d8e)
 
#define SPU_KEY_FM_MODE1   *((unsigned short*)0x1f801d90)
 
#define SPU_KEY_FM_MODE2   *((unsigned short*)0x1f801d92)
 
#define SPU_KEY_NOISE_MODE1   *((unsigned short*)0x1f801d94)
 
#define SPU_KEY_NOISE_MODE2   *((unsigned short*)0x1f801d96)
 
#define SPU_KEY_REVERB_MODE1   *((unsigned short*)0x1f801d98)
 
#define SPU_KEY_REVERB_MODE2   *((unsigned short*)0x1f801d9a)
 
#define SPU_CD_MVOL_L   *((unsigned short*)0x1f801db0)
 
#define SPU_CD_MVOL_R   *((unsigned short*)0x1f801db2)
 
#define SPU_EXT_VOL_L   *((unsigned short*)0x1f801db4)
 
#define SPU_EXT_VOL_R   *((unsigned short*)0x1f801db6)
 
#define SPU_REVERB_WORK_ADDR   *((unsigned short*)0x1f801da2)
 
#define SPU_VOICE_BASE_ADDR(x)   (0x1f801c00 + (x<<4))
 
#define DPCR   *((unsigned int*)0x1f8010f0)
 

Functions

void SsVoiceVol (int voice, unsigned short left, unsigned short right)
 Set voice volume.
 
void SsVoicePitch (int voice, unsigned short pitch)
 Set voice pitch.
 
void SsVoiceStartAddr (int voice, unsigned int addr)
 Set start Sound RAM address for voice.
 
void SsVoiceADSRRaw (int voice, unsigned short level, unsigned short rate)
 Set ADSR level for voice.
 
void SsVoiceRepeatAddr (int voice, unsigned int addr)
 Set repeat address for voice.
 
void SsKeyOn (int voice)
 Set a voice to 'on'.
 
void SsKeyOff (int voice)
 Set a voice to 'off'.
 
void SsKeyOnMask (int mask)
 Set the voices specified by the bitmask to 'on'.
 
void SsKeyOffMask (int mask)
 Set the voices specified by the bitmask to 'off'.
 
void SsWait ()
 Wait for the SPU to be ready.
 
void SsInit ()
 Intialize the SPU.
 
void SsUpload (void *addr, int size, int spu_addr)
 Uploads sound data in PSX ADPCM format to Sound RAM.
 
unsigned short SsFreqToPitch (int hz)
 Converts a sampling rate in hertz to PlayStation pitch rate used by the SPU.
 
int SsReadVag (SsVag *vag, void *data)
 Reads information from a buffer containg a VAG file and stores it inside a SsVag structure.
 
void SsUploadVagEx (SsVag *vag, int spu_addr)
 Uploads the sound data specified by a SsVag structure to the specified address in Sound RAM.
 
void SsUploadVag (SsVag *vag)
 Uploads the sound data specified by a SsVag structure to Sound RAM, beginning from the base of usable Sound RAM and continuing from there, in an automatic fashion.
 
void SsPlayVag (SsVag *vag, unsigned char voice, unsigned short vl, unsigned short vr)
 Plays the sound specified by the SsVag structure at specified voice and volume.
 
void SsStopVag (SsVag *vag)
 Stops the sound specified by the SsVag structure.
 
void SsResetVagAddr ()
 Tell SsUploadVag() to start uploading from the base of usable Sound RAM again.
 
void SsEnableCd ()
 Enable CD Audio.
 
void SsEnableExt ()
 Enable External audio.
 
void SsCdVol (unsigned short left, unsigned short right)
 Set CD Audio volume.
 

Macro Definition Documentation

#define DPCR   *((unsigned int*)0x1f8010f0)
#define SPU_ADDR   *((unsigned short*)0x1f801da6)

PSXSDK.

Sound Processing Unit Functions Based on code from James Higgs's PSX lib and on code by bitmaster

#define SPU_CD_MVOL_L   *((unsigned short*)0x1f801db0)
#define SPU_CD_MVOL_R   *((unsigned short*)0x1f801db2)
#define SPU_CONTROL   *((unsigned short*)0x1f801daa)
#define SPU_DATA   *((unsigned short*)0x1f801da8)
#define SPU_EXT_VOL_L   *((unsigned short*)0x1f801db4)
#define SPU_EXT_VOL_R   *((unsigned short*)0x1f801db6)
#define SPU_KEY_FM_MODE1   *((unsigned short*)0x1f801d90)
#define SPU_KEY_FM_MODE2   *((unsigned short*)0x1f801d92)
#define SPU_KEY_NOISE_MODE1   *((unsigned short*)0x1f801d94)
#define SPU_KEY_NOISE_MODE2   *((unsigned short*)0x1f801d96)
#define SPU_KEY_OFF1   *((unsigned short*)0x1f801d8c)
#define SPU_KEY_OFF2   *((unsigned short*)0x1f801d8e)
#define SPU_KEY_ON1   *((unsigned short*)0x1f801d88)
#define SPU_KEY_ON2   *((unsigned short*)0x1f801d8a)
#define SPU_KEY_REVERB_MODE1   *((unsigned short*)0x1f801d98)
#define SPU_KEY_REVERB_MODE2   *((unsigned short*)0x1f801d9a)
#define SPU_MVOL_L   *((unsigned short*)0x1f801d80)
#define SPU_MVOL_R   *((unsigned short*)0x1f801d82)
#define SPU_REVERB_L   *((unsigned short*)0x1f801d84)
#define SPU_REVERB_R   *((unsigned short*)0x1f801d86)
#define SPU_REVERB_WORK_ADDR   *((unsigned short*)0x1f801da2)
#define SPU_STATUS   *((unsigned short*)0x1f801dac)
#define SPU_STATUS2   *((unsigned short*)0x1f801dae)
#define SPU_VOICE_BASE_ADDR (   x)    (0x1f801c00 + (x<<4))

Function Documentation

void SsCdVol ( unsigned short  left,
unsigned short  right 
)

Set CD Audio volume.

Parameters
leftLeft channel volume
rightRight channel volume
void SsEnableCd ( void  )

Enable CD Audio.

void SsEnableExt ( void  )

Enable External audio.

(???)

unsigned short SsFreqToPitch ( int  hz)

Converts a sampling rate in hertz to PlayStation pitch rate used by the SPU.

Parameters
hzSampling rate in hertz.
Returns
PlayStation pitch rate
void SsInit ( void  )

Intialize the SPU.

void SsKeyOff ( int  voice)

Set a voice to 'off'.

This stops the sound specified for the voice.

Parameters
voiceVoice
void SsKeyOffMask ( int  mask)

Set the voices specified by the bitmask to 'off'.

Like SsKeyOff()

Parameters
maskBitmask
void SsKeyOn ( int  voice)

Set a voice to 'on'.

This has the effect of playing the sound specified for the voice.

Parameters
voiceVoice
void SsKeyOnMask ( int  mask)

Set the voices specified by the bitmask to 'on'.

Like SsKeyOn()

Parameters
maskBitmask
void SsPlayVag ( SsVag vag,
unsigned char  voice,
unsigned short  vl,
unsigned short  vr 
)

Plays the sound specified by the SsVag structure at specified voice and volume.

Parameters
vagPointer to SsVag structure
voiceVoice
vlLeft channel volume
vrRight channel volume
int SsReadVag ( SsVag vag,
void *  data 
)

Reads information from a buffer containg a VAG file and stores it inside a SsVag structure.

Parameters
vagPointer to structure in which to store information.
dataPointer to VAG file data
void SsResetVagAddr ( void  )

Tell SsUploadVag() to start uploading from the base of usable Sound RAM again.

void SsStopVag ( SsVag vag)

Stops the sound specified by the SsVag structure.

Parameters
vagPointer to SsVag structure
void SsUpload ( void *  addr,
int  size,
int  spu_addr 
)

Uploads sound data in PSX ADPCM format to Sound RAM.

Parameters
addrPointer to PSX ADPCM sound data in main RAM
sizeSound data size
spu_addrDestination address in Sound RAM (multiplier of 8).
void SsUploadVag ( SsVag vag)

Uploads the sound data specified by a SsVag structure to Sound RAM, beginning from the base of usable Sound RAM and continuing from there, in an automatic fashion.

Parameters
vagPointer to SsVag structure
void SsUploadVagEx ( SsVag vag,
int  spu_addr 
)

Uploads the sound data specified by a SsVag structure to the specified address in Sound RAM.

The SsVag structure can then be used for playing with SsPlayVag()

Parameters
vagPointer to SsVag structure
spu_addrDestination address in Sound RAM (multiplier of 8)
void SsVoiceADSRRaw ( int  voice,
unsigned short  level,
unsigned short  rate 
)

Set ADSR level for voice.

Parameters
voiceVoice
levelADSR level
rateADSR rate
void SsVoicePitch ( int  voice,
unsigned short  pitch 
)

Set voice pitch.

Parameters
voiceVoice
pitchPitch.
void SsVoiceRepeatAddr ( int  voice,
unsigned int  addr 
)

Set repeat address for voice.

Parameters
voiceVoice
addrAddress in Sound RAM (multiplier of 8)
void SsVoiceStartAddr ( int  voice,
unsigned int  addr 
)

Set start Sound RAM address for voice.

Parameters
voiceVoice
addrStart address in Sound RAM (multiplier of 8)
void SsVoiceVol ( int  voice,
unsigned short  left,
unsigned short  right 
)

Set voice volume.

Parameters
voiceVoice number (0-23)
leftLeft channel volume
rightRight channel volume
void SsWait ( void  )

Wait for the SPU to be ready.