PVSnesLib  4.3.0
Documentation to code in C or ASM for the Nintendo SNES
sound.h File Reference

snes sound support. More...

#include <snes/snestypes.h>
#include <snes/interrupt.h>

Go to the source code of this file.

Data Structures

struct  brrsamples
 brr sample sound header(8 bytes) More...
 

Macros

#define REG_APU00   (*(vuint8 *)0x2140)
 Main CPU to Sound CPU Communication Port 0 (R/W) 7-0 APU I/O Data (Write: Data to APU, Read: Data from APU) Caution: These registers should be written only in 8bit mode (there is a hardware glitch that can cause a 16bit write to [2140h..2141h] to destroy [2143h], this might happen only in some situations, like when the cartridge contains too many ROM chips which apply too much load on the bus). More...
 

Functions

void spcAllocateSoundRegion (u8 size)
 set the size of the sound region (this must be big enough to hold your longest/largest sound) this function will STOP module playback too More...
 
void spcBoot (void)
 boots the spc700 with sm-spc. call once at startup
 
void spcEffect (u16 pitch, u16 sfxIndex, u8 volpan)
 Play sound effect (load with spcLoadEffect) More...
 
void spcFadeModuleVolume (u16 vol, u16 fadespeed)
 fade the module volume towards the target More...
 
void spcFlush (void)
 Flush message queue (force sync)
 
void spcLoad (u16 musIndex)
 load module into sm-spc. this function may take some time to execute More...
 
void spcLoadEffect (u16 sfxIndex)
 load sound effect into sm-spc. this function may take some time to execute More...
 
void spcPlay (u8 startPos)
 play module. note: this simply queues a message, use spcFlush if you want to wait until the message is processed More...
 
void spcPlaySound (u8 sndIndex)
 Play sound from memory (using default arguments) More...
 
void spcPlaySoundV (u8 sndIndex, u16 volume)
 Play sound from memory (using default arguments) More...
 
void spcProcess (void)
 Process messages This function will try to give messages to the spc until a few scanlines pass. More...
 
void spcSetBank (u8 *bank)
 set soundbank origin. soundbank must have dedicated bank(s) More...
 
void spcSetModuleVolume (u8 vol)
 set the module playback volume More...
 
void spcSetSoundDataEntry (u8 vol, u8 panning, u8 pitch, u16 length, u8 *sampleaddr, brrsamples *ptr)
 set the values of a sound entry More...
 
void spcSetSoundEntry (u8 vol, u8 panning, u8 pitch, u16 length, u8 *sampleaddr, brrsamples *ptr)
 set the values and address of the SOUND TABLE for a sound entry More...
 
void spcSetSoundTable (u16 sndTableAddr, u8 sndTableBank)
 set the address of the SOUND TABLE More...
 
void spcStop (void)
 stop playing the current module.
 

Detailed Description

snes sound support.

Really great thanks to shiru for sound engine and tools used in his Christmas Craze homebrew http://shiru.untergrund.net/

Also great thanks for mukunda for snesmod sound engine http://snes.mukunda.com/

And special thanks to Kung Fu Furby for help debugging snesmod port with C interface

Macro Definition Documentation

◆ REG_APU00

#define REG_APU00   (*(vuint8 *)0x2140)

Main CPU to Sound CPU Communication Port 0 (R/W) 7-0 APU I/O Data (Write: Data to APU, Read: Data from APU) Caution: These registers should be written only in 8bit mode (there is a hardware glitch that can cause a 16bit write to [2140h..2141h] to destroy [2143h], this might happen only in some situations, like when the cartridge contains too many ROM chips which apply too much load on the bus).

Same thing for REG_APU01, REG_APU02 and REG_APU03 for addr 2141h..2143h REG_APU0001 and REG_APU0203 for 16 bits read/write access

Function Documentation

◆ spcAllocateSoundRegion()

spcAllocateSoundRegion ( u8  size)

set the size of the sound region (this must be big enough to hold your longest/largest sound) this function will STOP module playback too

Parameters
sizesize of sound region (size*256 bytes)
Examples
audio/tada/Tada.c, and games/likemario/LikeMario.c.

◆ spcEffect()

spcEffect ( u16  pitch,
u16  sfxIndex,
u8  volpan 
)

Play sound effect (load with spcLoadEffect)

Parameters
pitchpitch (0-15, 8=32khz)
sfxIndexeffect index (0-15)
volpanvolume(0..15) AND panning(0..15) (volume*16+pan)
Examples
audio/effects/effects.c, and audio/effectsandmusic/effectsandmusic.c.

◆ spcFadeModuleVolume()

spcFadeModuleVolume ( u16  vol,
u16  fadespeed 
)

fade the module volume towards the target

Parameters
volvolume (0..255)
fadespeedfade speed (volume(0..255) += y every 32ms)

◆ spcLoad()

spcLoad ( u16  musIndex)

load module into sm-spc. this function may take some time to execute

Parameters
musIndexmodule_id
Examples
audio/effectsandmusic/effectsandmusic.c, audio/music/Music.c, audio/musicGreaterThan32k/musicGreaterThan32k.c, and games/likemario/LikeMario.c.

◆ spcLoadEffect()

spcLoadEffect ( u16  sfxIndex)

load sound effect into sm-spc. this function may take some time to execute

Parameters
sfxIndexsfx_id
Examples
audio/effects/effects.c, and audio/effectsandmusic/effectsandmusic.c.

◆ spcPlay()

spcPlay ( u8  startPos)

play module. note: this simply queues a message, use spcFlush if you want to wait until the message is processed

another note: there may be a significant startup time from after the message is processed to when the song starts playing... to sync the program with the song start use spcFlush and then wait until SPC_P of the status register is set.

Parameters
startPosstarting position
Examples
audio/effectsandmusic/effectsandmusic.c, audio/music/Music.c, audio/musicGreaterThan32k/musicGreaterThan32k.c, and games/likemario/LikeMario.c.

◆ spcPlaySound()

spcPlaySound ( u8  sndIndex)

Play sound from memory (using default arguments)

Parameters
sndIndexindex in sound table. Be careful: the index 0 corresponds to the LAST sound loaded. The index 1 is the penultimate sound loaded and so on...
Examples
audio/tada/Tada.c, and games/likemario/LikeMario.c.

◆ spcPlaySoundV()

spcPlaySoundV ( u8  sndIndex,
u16  volume 
)

Play sound from memory (using default arguments)

Parameters
sndIndexindex in sound table. Be careful: the index 0 corresponds to the LAST sound loaded. The index 1 is the penultimate sound loaded and so on...
volumevolume (0..15)

◆ spcProcess()

spcProcess ( void  )

Process messages This function will try to give messages to the spc until a few scanlines pass.

this function MUST be called every frame if you are using streamed sounds

Examples
audio/effects/effects.c, audio/effectsandmusic/effectsandmusic.c, audio/music/Music.c, audio/musicGreaterThan32k/musicGreaterThan32k.c, audio/tada/Tada.c, and games/likemario/LikeMario.c.

◆ spcSetBank()

spcSetBank ( u8 *  bank)

set soundbank origin. soundbank must have dedicated bank(s)

Parameters
bankbank address
Examples
audio/effects/effects.c, audio/effectsandmusic/effectsandmusic.c, audio/music/Music.c, audio/musicGreaterThan32k/musicGreaterThan32k.c, and games/likemario/LikeMario.c.

◆ spcSetModuleVolume()

spcSetModuleVolume ( u8  vol)

set the module playback volume

Parameters
volvolume (0..255)
Examples
games/likemario/LikeMario.c.

◆ spcSetSoundDataEntry()

spcSetSoundDataEntry ( u8  vol,
u8  panning,
u8  pitch,
u16  length,
u8 *  sampleaddr,
brrsamples ptr 
)

set the values of a sound entry

set the address of the SOUND TABLE for a sound entry

Parameters
volvolume (0..15)
panningpanning (0..15)
pitchPITCH (1..6) (hz = PITCH * 2000)
lengthlength of brr sample
sampleaddraddress of brr sample
ptraddress of variable where sounds values will be stored

◆ spcSetSoundEntry()

spcSetSoundEntry ( u8  vol,
u8  panning,
u8  pitch,
u16  length,
u8 *  sampleaddr,
brrsamples ptr 
)

set the values and address of the SOUND TABLE for a sound entry

Parameters
volvolume (0..15)
panningpanning (0..15)
pitchPITCH (1..6) (hz = PITCH * 2000)
lengthlength of brr sample
sampleaddraddress of brr sample
ptraddress of variable where sounds values will be stored
Examples
audio/tada/Tada.c, and games/likemario/LikeMario.c.

◆ spcSetSoundTable()

spcSetSoundTable ( u16  sndTableAddr,
u8  sndTableBank 
)

set the address of the SOUND TABLE

Parameters
sndTableAddraddress of sound table
sndTableBankbank of sound table