papermario
Decompilation of Paper Mario
 
All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Loading...
Searching...
No Matches
engine.c File Reference

Macros

#define SBN_ROM_OFFSET   0xF00000
 
#define TUNE_SCALING_ARR_AMPLIFY_FINE   0
 
#define TUNE_SCALING_ARR_AMPLIFY_COARSE   128
 
#define TUNE_SCALING_ARR_ATTENUATE_FINE   160
 
#define TUNE_SCALING_ARR_ATTENUATE_COARSE   288
 
#define SBN_EXTRA_LOOKUP(i, fmt, e)   (au_fetch_SBN_file(globals->extraFileList[AmbientSoundIDtoMSEQFileIndex[i]], fmt, &e))
 
#define AL_HEADER_SIG_BK   0x424B
 
#define AL_HEADER_SIG_CR   0x4352
 
#define AL_HEADER_SIG_DR   0x4452
 
#define AL_HEADER_SIG_SR   0x5352
 

Enumerations

enum  BKParseState {
  BK_READ_DONE = 0 , BK_READ_FETCH_HEADER = 11 , BK_READ_FETCH_DATA = 21 , BK_READ_SWIZZLE = 31 ,
  BK_READ_PROCESS_CR = 101 , BK_READ_SWIZZLE_CR = 111 , BK_READ_PROCESS_DR = 201 , BK_READ_UNK_DR = 211 ,
  BK_READ_PROCESS_SR = 301 , BK_READ_UNK_SR = 311
}
 

Functions

void au_release_voice (u8 index)
 
void au_engine_init (s32 outputRate)
 
void au_update_clients_for_audio_frame (void)
 Called exactly once per audio frame (every 5.75ms at 32kHz).
 
void au_update_clients_for_video_frame (void)
 this is called once per video frame update (50 or 60 times per second)
 
void au_syn_begin_audio_frame (AuGlobals *globals)
 
void au_reset_nonfree_voice (AuVoice *voice, u8 index)
 
void au_reset_voice (AuVoice *voice, u8 voiceIdx)
 
f32 au_compute_pitch_ratio (s32 tuning)
 Converts a linear pitch value (in cents) into a frequency ratio suitable for adjusting playback speed.
 
void au_fade_init (Fade *fade, s32 time, s32 startValue, s32 endValue)
 
void au_fade_clear (Fade *fade)
 
void au_fade_update (Fade *fade)
 
void au_fade_set_volume (u8 busID, u16 volume, s32 busVolume)
 
void au_fade_flush (Fade *fade)
 
void au_fade_set_envelope (Fade *fade, s16 value)
 
void au_fade_calc_envelope (Fade *fade, u32 duration, s32 target)
 
void au_fade_update_envelope (Fade *fade)
 
Instrumentau_get_instrument (AuGlobals *globals, BankSetIndex bank, s32 patch, EnvelopeData *envData)
 Note that bank is supplied as BankSetIndex and not BankSet, which means it will be used to perform a raw access into AuGlobals::bankSets.
 
void au_get_bgm_player_and_file (u32 playerIndex, BGMHeader **outFile, BGMPlayer **outPlayer)
 
void au_get_bgm_player (u32 playerIndex, BGMPlayer **outPlayer)
 
AuResult au_load_song_files (u32 songID, BGMHeader *bgmFile, BGMPlayer *player)
 
AuResult au_reload_song_files (s32 songID, BGMHeader *bgmFile)
 
BGMPlayerau_get_snapshot_by_index (s32 index)
 
AuResult au_ambient_load (u32 ambSoundID)
 
BGMPlayerau_get_client_by_priority (u8 priority)
 
void au_load_INIT (AuGlobals *globals, s32 romAddr, ALHeap *heap)
 
AuResult au_fetch_SBN_file (u32 fileIdx, AuFileFormat format, SBNFileEntry *outEntry)
 
void au_load_PER (AuGlobals *globals, s32 romAddr)
 
void au_load_PRG (AuGlobals *globals, s32 romAddr)
 
s32 au_load_BGM (s32 arg0)
 
InstrumentBankau_get_BK_instruments (BankSet bankSet, u32 bankIndex)
 
BKFileBufferau_load_BK_to_bank (s32 bkFileOffset, BKFileBuffer *bkFile, s32 bankIndex, BankSet bankSet)
 Loads an instrument bank file from ROM, allocates memory if needed, and sets up instrument pointers.
 
void au_swizzle_BK_instruments (s32 bkFileOffset, BKFileBuffer *file, InstrumentBank instruments, u32 instrumentCount, u8 useDma)
 Fixes up (swizzles) instrument pointers in a loaded bank, converting file-relative offsets to valid RAM pointers.
 
BKFileBufferau_load_static_BK_to_bank (s32 *inAddr, void *outAddr, s32 bankIndex, BankSet bankSet)
 UNUSED Loads an instrument bank file from ROM to a given buffer (allocates if needed), and sets up instrument pointers.
 
s32 au_load_aux_bank (s32 bkFileOffset, s32 bankIndex)
 
void au_clear_instrument_group (s32 bankIndex, BankSet bankSet)
 unused. resets all instruments in (bankIndex, bankSet) to default
 
void au_set_bus_volume_level (s32 soundTypeFlags, u32 volPreset)
 
s32 au_set_reverb_type (s32 soundTypeFlags, s32 reverbType)
 
void au_sync_channel_delay_enabled (u32 bMonoSound)
 
void au_read_rom (s32 romAddr, void *buffer, u32 size)
 
void au_memset (void *dst, s32 size, u8 value)
 
void au_copy_bytes (s8 *src, s8 *dest, s32 size)
 
void au_copy_words (void *src, void *dst, s32 size)
 

Variables

AuCallback BeginSoundUpdateCallback
 
BGMPlayergBGMPlayerA
 
BGMPlayergBGMPlayerB
 
BGMPlayergBGMPlayerC
 
SoundManagergSoundManager
 
AuGlobalsgSoundGlobals
 
AmbienceManagergAuAmbienceManager
 
u16 PerceptualVolumeLevels [9]
 Volume steps use squared values so each level represents linear power increase, matching loudness perception.
 
u8 EnvelopePressDefault []
 
u8 EnvelopeReleaseDefault []
 
f32 AlTuneScaling []
 

Macro Definition Documentation

◆ AL_HEADER_SIG_BK

#define AL_HEADER_SIG_BK   0x424B

◆ AL_HEADER_SIG_CR

#define AL_HEADER_SIG_CR   0x4352

◆ AL_HEADER_SIG_DR

#define AL_HEADER_SIG_DR   0x4452

Referenced by au_load_BK_to_bank().

◆ AL_HEADER_SIG_SR

#define AL_HEADER_SIG_SR   0x5352

Referenced by au_load_BK_to_bank().

◆ SBN_EXTRA_LOOKUP

#define SBN_EXTRA_LOOKUP ( i,
fmt,
e )   (au_fetch_SBN_file(globals->extraFileList[AmbientSoundIDtoMSEQFileIndex[i]], fmt, &e))

Referenced by au_ambient_load().

◆ SBN_ROM_OFFSET

#define SBN_ROM_OFFSET   0xF00000

Referenced by au_engine_init().

◆ TUNE_SCALING_ARR_AMPLIFY_COARSE

#define TUNE_SCALING_ARR_AMPLIFY_COARSE   128

Referenced by au_compute_pitch_ratio().

◆ TUNE_SCALING_ARR_AMPLIFY_FINE

#define TUNE_SCALING_ARR_AMPLIFY_FINE   0

Referenced by au_compute_pitch_ratio().

◆ TUNE_SCALING_ARR_ATTENUATE_COARSE

#define TUNE_SCALING_ARR_ATTENUATE_COARSE   288

Referenced by au_compute_pitch_ratio().

◆ TUNE_SCALING_ARR_ATTENUATE_FINE

#define TUNE_SCALING_ARR_ATTENUATE_FINE   160

Referenced by au_compute_pitch_ratio().

Enumeration Type Documentation

◆ BKParseState

Enumerator
BK_READ_DONE 
BK_READ_FETCH_HEADER 
BK_READ_FETCH_DATA 
BK_READ_SWIZZLE 
BK_READ_PROCESS_CR 
BK_READ_SWIZZLE_CR 
BK_READ_PROCESS_DR 
BK_READ_UNK_DR 
BK_READ_PROCESS_SR 
BK_READ_UNK_SR 

Function Documentation

◆ au_ambient_load()

AuResult au_ambient_load ( u32 ambSoundID)

Referenced by snd_load_ambient().

◆ au_clear_instrument_group()

void au_clear_instrument_group ( s32 bankIndex,
BankSet bankSet )

unused. resets all instruments in (bankIndex, bankSet) to default

◆ au_compute_pitch_ratio()

f32 au_compute_pitch_ratio ( s32 tuning)

Converts a linear pitch value (in cents) into a frequency ratio suitable for adjusting playback speed.

This function computes the playback rate corresponding to a pitch shift (up or down) in cents. Positive values increase pitch (higher frequency), and negative values decrease it. Recall 100 cents = 1 semitone, and therefore 1200 cents = 1 octave.

Parameters
tuningThe pitch offset in cents, from +4095 (~ 40.95 semitones up) to -16383 (~ 163.83 semitones down)
Returns
Floating point output rate multiplier. Multiply this with the base sample rate to apply the pitch.

Referenced by au_bgm_player_update_playing(), au_mseq_player_update(), and au_mseq_restore_voices().

◆ au_copy_bytes()

void au_copy_bytes ( s8 * src,
s8 * dest,
s32 size )

◆ au_copy_words()

void au_copy_words ( void * src,
void * dst,
s32 size )

◆ au_engine_init()

void au_engine_init ( s32 outputRate)

Referenced by create_audio_system().

◆ au_fade_calc_envelope()

void au_fade_calc_envelope ( Fade * fade,
u32 duration,
s32 target )

Referenced by au_bgm_adjust_volume().

◆ au_fade_clear()

void au_fade_clear ( Fade * fade)

◆ au_fade_flush()

void au_fade_flush ( Fade * fade)

Referenced by au_set_bus_volume_level().

◆ au_fade_init()

void au_fade_init ( Fade * fade,
s32 time,
s32 startValue,
s32 endValue )

◆ au_fade_set_envelope()

void au_fade_set_envelope ( Fade * fade,
s16 value )

Referenced by au_bgm_player_init().

◆ au_fade_set_volume()

void au_fade_set_volume ( u8 busID,
u16 volume,
s32 busVolume )

◆ au_fade_update()

void au_fade_update ( Fade * fade)

◆ au_fade_update_envelope()

void au_fade_update_envelope ( Fade * fade)

◆ au_fetch_SBN_file()

AuResult au_fetch_SBN_file ( u32 fileIdx,
AuFileFormat format,
SBNFileEntry * outEntry )

◆ au_get_bgm_player()

void au_get_bgm_player ( u32 playerIndex,
BGMPlayer ** outPlayer )

◆ au_get_bgm_player_and_file()

void au_get_bgm_player_and_file ( u32 playerIndex,
BGMHeader ** outFile,
BGMPlayer ** outPlayer )

Referenced by snd_song_load().

◆ au_get_BK_instruments()

InstrumentBank * au_get_BK_instruments ( BankSet bankSet,
u32 bankIndex )

◆ au_get_client_by_priority()

BGMPlayer * au_get_client_by_priority ( u8 priority)

Referenced by au_bgm_process_resume().

◆ au_get_instrument()

Instrument * au_get_instrument ( AuGlobals * globals,
BankSetIndex bank,
s32 patch,
EnvelopeData * envData )

Note that bank is supplied as BankSetIndex and not BankSet, which means it will be used to perform a raw access into AuGlobals::bankSets.

This does not affect values above 3, but 1 and 2 differ.

Referenced by au_bgm_player_update_playing(), au_BGMCmd_E8_TrackOverridePatch(), au_BGMCmd_F5_UseInstrument(), and au_mseq_player_update().

◆ au_get_snapshot_by_index()

BGMPlayer * au_get_snapshot_by_index ( s32 index)

◆ au_load_aux_bank()

s32 au_load_aux_bank ( s32 bkFileOffset,
s32 bankIndex )

◆ au_load_BGM()

s32 au_load_BGM ( s32 arg0)

◆ au_load_BK_to_bank()

BKFileBuffer * au_load_BK_to_bank ( s32 bkFileOffset,
BKFileBuffer * bkFile,
s32 bankIndex,
BankSet bankSet )

Loads an instrument bank file from ROM, allocates memory if needed, and sets up instrument pointers.

Instruments in the bank will be configured to use DMA streaming for sample/codebook data. This is the standard loader for streamed instrument banks.

Referenced by au_load_aux_bank(), and au_load_BK_headers().

◆ au_load_INIT()

void au_load_INIT ( AuGlobals * globals,
s32 romAddr,
ALHeap * heap )

Referenced by au_engine_init().

◆ au_load_PER()

void au_load_PER ( AuGlobals * globals,
s32 romAddr )

Referenced by au_engine_init().

◆ au_load_PRG()

void au_load_PRG ( AuGlobals * globals,
s32 romAddr )

Referenced by au_engine_init().

◆ au_load_song_files()

AuResult au_load_song_files ( u32 songID,
BGMHeader * bgmFile,
BGMPlayer * player )

Referenced by snd_song_load().

◆ au_load_static_BK_to_bank()

BKFileBuffer * au_load_static_BK_to_bank ( s32 * inAddr,
void * outAddr,
s32 bankIndex,
BankSet bankSet )

UNUSED Loads an instrument bank file from ROM to a given buffer (allocates if needed), and sets up instrument pointers.

Instruments are configured to always bypass DMA: sample and codebook data is assumed to be already present in RAM. Use this only for banks whose sample data is guaranteed to be preloaded, not for standard streaming.

◆ au_memset()

void au_memset ( void * dst,
s32 size,
u8 value )

◆ au_read_rom()

◆ au_release_voice()

void au_release_voice ( u8 index)

Referenced by au_pull_voice().

◆ au_reload_song_files()

AuResult au_reload_song_files ( s32 songID,
BGMHeader * bgmFile )

Referenced by au_bgm_process_resume().

◆ au_reset_nonfree_voice()

void au_reset_nonfree_voice ( AuVoice * voice,
u8 index )

◆ au_reset_voice()

◆ au_set_bus_volume_level()

void au_set_bus_volume_level ( s32 soundTypeFlags,
u32 volPreset )

◆ au_set_reverb_type()

s32 au_set_reverb_type ( s32 soundTypeFlags,
s32 reverbType )

Referenced by snd_set_sfx_reverb_type().

◆ au_swizzle_BK_instruments()

void au_swizzle_BK_instruments ( s32 bkFileOffset,
BKFileBuffer * file,
InstrumentBank instruments,
u32 instrumentCount,
u8 useDma )

Fixes up (swizzles) instrument pointers in a loaded bank, converting file-relative offsets to valid RAM pointers.

Sets whether each instrument uses DMA streaming or not, and updates pitch ratios to match output rate. Replaces NULL instruments with a default instrument to ensure all loaded patches point to valid data.

Referenced by au_load_BK_to_bank(), and au_load_static_BK_to_bank().

◆ au_syn_begin_audio_frame()

void au_syn_begin_audio_frame ( AuGlobals * globals)

◆ au_sync_channel_delay_enabled()

void au_sync_channel_delay_enabled ( u32 bMonoSound)

Referenced by snd_set_mono(), and snd_set_stereo().

◆ au_update_clients_for_audio_frame()

void au_update_clients_for_audio_frame ( void )

Called exactly once per audio frame (every 5.75ms at 32kHz).

this is called per audio frame generated by alAudioFrame (every 184 audio samples) there will be multiuple of these per video frame

Updates MSEQ, SFX, and BGM players for the current audio frame.

Referenced by alAudioFrame().

◆ au_update_clients_for_video_frame()

void au_update_clients_for_video_frame ( void )

this is called once per video frame update (50 or 60 times per second)

Referenced by alAudioFrame().

Variable Documentation

◆ AlTuneScaling

f32 AlTuneScaling[]
extern

Referenced by au_compute_pitch_ratio().

◆ BeginSoundUpdateCallback

AuCallback BeginSoundUpdateCallback

◆ EnvelopePressDefault

u8 EnvelopePressDefault[]
extern

Referenced by au_get_instrument().

◆ EnvelopeReleaseDefault

u8 EnvelopeReleaseDefault[]
extern

◆ gAuAmbienceManager

◆ gBGMPlayerA

◆ gBGMPlayerB

◆ gBGMPlayerC

BGMPlayer* gBGMPlayerC

Referenced by au_engine_init().

◆ gSoundGlobals

◆ gSoundManager

◆ PerceptualVolumeLevels

u16 PerceptualVolumeLevels[9]
extern

Volume steps use squared values so each level represents linear power increase, matching loudness perception.

This makes each step sound evenly spaced.

Referenced by au_set_bus_volume_level().