coastline 0.0.4
Loading...
Searching...
No Matches
audio.h File Reference

The music player of FastTracker 2 modules, the sound channels, and the mixing thread. More...

Include dependency graph for audio.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  XmSample
 The header of an XM sample as the player keeps it, followed by its decoded data. More...
struct  MusicChannel
 The state of a channel of the music. More...
struct  MusicPlayer
 The position of the music player in its module. More...
struct  SoundEffectSample
 A sample a sound effect channel plays, and the loop at its end. More...
struct  SdlMusicState
 XM playback storage and game volumes for one SDL audio context. More...

Macros

#define AUDIO_FREQUENCY   21998
 The sample rate the audio interface is asked for.
#define MUSIC_OCTAVES   10
#define MUSIC_NOTES   12
#define MENU_MUSIC_MODULE_SIZE   0x70800
 The bytes from the menu music up to the heap at 0x80096400 on the console.
#define SILENCE_SAMPLE_BYTES   0x1000
 Silent bytes padded for a mixer block read before an SDL channel stops.
#define AUDIO_THREAD_STACK_WORDS   0x80
 The console thread that sequences music and fills the audio ring.
#define g_abMusicModuleWorkBuffer   (GetSdlMusicState()->moduleWork)
 Writable module decoding workspace, valid for this context.
#define g_nAudioChannelCount   (GetSdlMusicState()->channelCount)
#define g_bBgmVolume   (GetSdlMusicState()->bgmVolume)
#define g_bSfxMasterVolume   (GetSdlMusicState()->sfxMasterVolume)
#define g_bSfxVolume   (GetSdlMusicState()->sfxVolume)
#define g_afNoteFrequencies   (GetSdlMusicState()->noteFrequencies)
#define g_dwMusicPatternRow   (GetSdlMusicState()->patternRow)
#define g_SilenceSampleData   (GetSdlMusicState()->silence)
#define g_AudioDmaBuffer   (GetSdlMusicState()->ring)
#define g_apInstrumentData   (GetSdlMusicState()->instruments)
#define g_apPatternData   (GetSdlMusicState()->patterns)
#define g_MusicChannelStates   (GetSdlMusicState()->channels)
#define g_aSoundEffectSamples   (GetSdlMusicState()->samples)
#define g_bMusicPlaybackEnabled   (GetSdlMusicState()->playbackEnabled)
#define g_MusicPlayer   (GetSdlMusicState()->player)
#define g_aFreqScaleTable   (GetSdlMusicState()->frequencySteps)

Functions

void LoadMusicModule (u8 *module, u8 *work)
 The 32.32 step of each note of each octave.
void BuildFrequencyScaleTable (void)
 Fill the steps of every note of every octave.
void CheckMusicLoopPoints (void)
 Loop or stop the music channels that passed the end of their samples.
u8 * ParseMusicPatternRow (u8 *row)
 Read a row of a pattern for every channel and start its notes and effects.
void ResetMusicChannels (void)
 Start the music from before its first order.
void UpdateMusicPlayback (void)
 Run a tick of the music: read a row when one is due, and run the arpeggios, portamentos and volume slides.
void InitAudioSystem (void *module, void *work)
 Start the audio interface, the music player and the mixing thread.
void ResetMusicPlaybackState (void)
 Stop the music and clear the state of every channel.
void InitMusicPlayback (void *module, void *work)
 Start playing an XM module.
s16 FindFreeSoundChannel (void)
 The first sound effect channel that is silent.
void SetSoundChannelVolume (s16 channel, u32 levels)
 Set the levels of a sound effect channel, the right in the upper half and the left in the lower, each at most 32.
void CheckSoundEffectLoopPoints (void)
 Loop or stop the sound effect channels that passed the end of their samples.
void AudioMixingThreadMain (void *arg)
 The mixing thread: on each message of the timer, scale the volumes, mix what the audio interface has played, tick the music, and feed the Rumble Paks.
void N64InitSoundChannel (s16 channel, s8 *sample, u32 length, u32 loopLength)
 InitSoundChannel() of the mixer of the Nintendo 64 release, which the SDL game has beside the routine of the same name of the PC release.
void N64StartSoundChannelMuted (s16 channel, s8 *sample, u32 length, u32 loopLength)
 StartSoundChannelMuted() of the mixer of the Nintendo 64 release.
SdlMusicState * GetSdlMusicState (void)

Variables

u8 g_abMenuMusicModule [MENU_MUSIC_MODULE_SIZE]
 Storage for the decompressed menu XM module.
u8 g_bMusicVolume
 The music-volume factor, from 0 to 255.
u64 g_aAudioThreadStack [AUDIO_THREAD_STACK_WORDS]
 Stack storage for the audio mixing thread, in 64-bit words.

Detailed Description

The music player of FastTracker 2 modules, the sound channels, and the mixing thread.

The player plays the first sample of each instrument of an XM module, 8-bit and without ping-pong loops, on the channels of the music mixer. A tick comes every other message of a timer of 10 milliseconds, and the mixing thread mixes what the audio interface has played since the last message.

Macro Definition Documentation

◆ AUDIO_FREQUENCY

#define AUDIO_FREQUENCY   21998

The sample rate the audio interface is asked for.

◆ MUSIC_OCTAVES

#define MUSIC_OCTAVES   10

The octaves of the table of steps.

◆ MUSIC_NOTES

#define MUSIC_NOTES   12

The notes of each octave of the table of steps.

◆ MENU_MUSIC_MODULE_SIZE

#define MENU_MUSIC_MODULE_SIZE   0x70800

The bytes from the menu music up to the heap at 0x80096400 on the console.

◆ SILENCE_SAMPLE_BYTES

#define SILENCE_SAMPLE_BYTES   0x1000

Silent bytes padded for a mixer block read before an SDL channel stops.

◆ AUDIO_THREAD_STACK_WORDS

#define AUDIO_THREAD_STACK_WORDS   0x80

The console thread that sequences music and fills the audio ring.

Ghidra address:
USA: 0x80378fb8
Ghidra address:
Asia: 0x80378A68
Ghidra address:
EUR: 0x8037b4b8
Ghidra address:
JPN: 0x8037a128 The stack of the mixing thread, in doublewords.

◆ g_abMusicModuleWorkBuffer

#define g_abMusicModuleWorkBuffer   (GetSdlMusicState()->moduleWork)

Writable module decoding workspace, valid for this context.

◆ g_nAudioChannelCount

#define g_nAudioChannelCount   (GetSdlMusicState()->channelCount)

The number of active music mixer channels, at most MIXER_CHANNELS.

◆ g_bBgmVolume

#define g_bBgmVolume   (GetSdlMusicState()->bgmVolume)

The BGM volume applied to module playback, with zero disabling processing.

◆ g_bSfxMasterVolume

#define g_bSfxMasterVolume   (GetSdlMusicState()->sfxMasterVolume)

The effects master volume, with zero disabling effects processing.

◆ g_bSfxVolume

#define g_bSfxVolume   (GetSdlMusicState()->sfxVolume)

The transient effects level applied beneath the master volume.

◆ g_afNoteFrequencies

#define g_afNoteFrequencies   (GetSdlMusicState()->noteFrequencies)

Base note frequencies used to build the pitch table.

◆ g_dwMusicPatternRow

#define g_dwMusicPatternRow   (GetSdlMusicState()->patternRow)

The current row within the active music pattern.

◆ g_SilenceSampleData

#define g_SilenceSampleData   (GetSdlMusicState()->silence)

Zero-valued sample storage for inactive channels.

◆ g_AudioDmaBuffer

#define g_AudioDmaBuffer   (GetSdlMusicState()->ring)

The interleaved stereo PCM ring buffer.

◆ g_apInstrumentData

#define g_apInstrumentData   (GetSdlMusicState()->instruments)

Decoded instrument headers and samples in moduleWork.

◆ g_apPatternData

#define g_apPatternData   (GetSdlMusicState()->patterns)

Pattern headers and packed rows in moduleWork.

◆ g_MusicChannelStates

#define g_MusicChannelStates   (GetSdlMusicState()->channels)

Per-channel XM note and effect playback state.

◆ g_aSoundEffectSamples

#define g_aSoundEffectSamples   (GetSdlMusicState()->samples)

Loaded effect sample descriptors.

◆ g_bMusicPlaybackEnabled

#define g_bMusicPlaybackEnabled   (GetSdlMusicState()->playbackEnabled)

Whether the XM player advances music playback.

◆ g_MusicPlayer

#define g_MusicPlayer   (GetSdlMusicState()->player)

The current XM order, row timing, and pattern playback state.

◆ g_aFreqScaleTable

#define g_aFreqScaleTable   (GetSdlMusicState()->frequencySteps)

32.32 sample-position increments.

Function Documentation

◆ LoadMusicModule()

void LoadMusicModule ( u8 * module,
u8 * work )

The 32.32 step of each note of each octave.

Ghidra address:
USA: 0x80379568
Ghidra address:
Asia: 0x80379018
Ghidra address:
EUR: 0x8037ba68
Ghidra address:
JPN: 0x8037a6d8 Copy the order table, the patterns and the samples of an XM module into the work memory, decoding the samples and following each with the start of its loop or with silence.
Parameters
moduleThe XM module.
workThe memory the player reads the module from.
Ghidra address:
USA: 0x80256720
Ghidra address:
Asia: 0x80256270
Ghidra address:
EUR: 0x80257cf0
Ghidra address:
JPN: 0x80257680

◆ BuildFrequencyScaleTable()

void BuildFrequencyScaleTable ( void )

Fill the steps of every note of every octave.

Ghidra address:
USA: 0x80256c2c
Ghidra address:
Asia: 0x8025677C
Ghidra address:
EUR: 0x802581fc
Ghidra address:
JPN: 0x80257b8c

◆ CheckMusicLoopPoints()

void CheckMusicLoopPoints ( void )

Loop or stop the music channels that passed the end of their samples.

Ghidra address:
USA: 0x80256d3c
Ghidra address:
Asia: 0x8025688C
Ghidra address:
EUR: 0x8025830c
Ghidra address:
JPN: 0x80257c9c

◆ ParseMusicPatternRow()

u8 * ParseMusicPatternRow ( u8 * row)

Read a row of a pattern for every channel and start its notes and effects.

Parameters
rowThe packed data of the row.
Returns
The data of the next row.
Ghidra address:
USA: 0x80256dec
Ghidra address:
Asia: 0x8025693C
Ghidra address:
EUR: 0x802583bc
Ghidra address:
JPN: 0x80257d4c

◆ ResetMusicChannels()

void ResetMusicChannels ( void )

Start the music from before its first order.

Ghidra address:
USA: 0x802571ac
Ghidra address:
Asia: 0x80256CFC
Ghidra address:
EUR: 0x8025877c
Ghidra address:
JPN: 0x8025810c

◆ UpdateMusicPlayback()

void UpdateMusicPlayback ( void )

Run a tick of the music: read a row when one is due, and run the arpeggios, portamentos and volume slides.

Ghidra address:
USA: 0x8025721c
Ghidra address:
Asia: 0x80256D6C
Ghidra address:
EUR: 0x802587ec
Ghidra address:
JPN: 0x8025817c

◆ InitAudioSystem()

void InitAudioSystem ( void * module,
void * work )

Start the audio interface, the music player and the mixing thread.

Parameters
moduleThe XM module to play.
workThe memory the player reads the module from.
Ghidra address:
USA: 0x802575c4
Ghidra address:
Asia: 0x80257114
Ghidra address:
EUR: 0x80258b94
Ghidra address:
JPN: 0x80258524

◆ ResetMusicPlaybackState()

void ResetMusicPlaybackState ( void )

Stop the music and clear the state of every channel.

Ghidra address:
USA: 0x802578f4
Ghidra address:
Asia: 0x80257444
Ghidra address:
EUR: 0x80258ec4
Ghidra address:
JPN: 0x80258854

◆ InitMusicPlayback()

void InitMusicPlayback ( void * module,
void * work )

Start playing an XM module.

Parameters
moduleThe XM module to play.
workThe memory the player reads the module from.
Ghidra address:
USA: 0x80257964
Ghidra address:
Asia: 0x802574B4
Ghidra address:
EUR: 0x80258f34
Ghidra address:
JPN: 0x802588c4

◆ FindFreeSoundChannel()

s16 FindFreeSoundChannel ( void )

The first sound effect channel that is silent.

Returns
The channel, or -1 if all play.
Ghidra address:
USA: 0x802579f4
Ghidra address:
Asia: 0x80257544
Ghidra address:
EUR: 0x80258fc4
Ghidra address:
JPN: 0x80258954

◆ SetSoundChannelVolume()

void SetSoundChannelVolume ( s16 channel,
u32 levels )

Set the levels of a sound effect channel, the right in the upper half and the left in the lower, each at most 32.

Parameters
channelThe sound effect channel.
levelsThe right level in the upper 16 bits and the left in the lower 16 bits.
Ghidra address:
USA: 0x80257be4
Ghidra address:
Asia: 0x80257734
Ghidra address:
EUR: 0x802591b4
Ghidra address:
JPN: 0x80258b44

◆ CheckSoundEffectLoopPoints()

void CheckSoundEffectLoopPoints ( void )

Loop or stop the sound effect channels that passed the end of their samples.

Ghidra address:
USA: 0x80257c44
Ghidra address:
Asia: 0x80257794
Ghidra address:
EUR: 0x80259214
Ghidra address:
JPN: 0x80258ba4

◆ AudioMixingThreadMain()

void AudioMixingThreadMain ( void * arg)

The mixing thread: on each message of the timer, scale the volumes, mix what the audio interface has played, tick the music, and feed the Rumble Paks.

Parameters
argThe argument of the thread, which is not read.
Ghidra address:
USA: 0x80257d3c
Ghidra address:
Asia: 0x8025788C
Ghidra address:
EUR: 0x8025930c
Ghidra address:
JPN: 0x80258c9c

◆ N64InitSoundChannel()

void N64InitSoundChannel ( s16 channel,
s8 * sample,
u32 length,
u32 loopLength )

InitSoundChannel() of the mixer of the Nintendo 64 release, which the SDL game has beside the routine of the same name of the PC release.

Parameters
channelThe channel of the sound effects.
sampleThe signed 8-bit samples.
lengthThe samples before the end.
loopLengthThe samples the channel goes back at the end, or 0 to stop.

◆ N64StartSoundChannelMuted()

void N64StartSoundChannelMuted ( s16 channel,
s8 * sample,
u32 length,
u32 loopLength )

StartSoundChannelMuted() of the mixer of the Nintendo 64 release.

Parameters
channelThe channel of the sound effects.
sampleThe signed 8-bit samples.
lengthThe samples before the end.
loopLengthThe samples the channel goes back at the end, or 0 to stop.

◆ GetSdlMusicState()

SdlMusicState * GetSdlMusicState ( void )
Precondition
An N64MixerContext is active.
Returns
The XM playback storage, valid until the context is destroyed.

Variable Documentation

◆ g_abMenuMusicModule

u8 g_abMenuMusicModule[MENU_MUSIC_MODULE_SIZE]
extern

Storage for the decompressed menu XM module.

Ghidra address:
USA: 0x80025c00
Ghidra address:
Asia: 0x80025C00
Ghidra address:
EUR: 0x80025c00
Ghidra address:
JPN: 0x80025c00

◆ g_bMusicVolume

u8 g_bMusicVolume
extern

The music-volume factor, from 0 to 255.

Ghidra address:
USA: 0x802a49c8
Ghidra address:
Asia: 0x802A4518
Ghidra address:
EUR: 0x802a7188
Ghidra address:
JPN: 0x802a6c28
Ghidra address:
BRD3D: 0x100bbadc
Ghidra address:
BRGlide: 0x100bb2e4

◆ g_aAudioThreadStack

u64 g_aAudioThreadStack[AUDIO_THREAD_STACK_WORDS]
extern

Stack storage for the audio mixing thread, in 64-bit words.

Ghidra address:
USA: 0x80379168
Ghidra address:
Asia: 0x80378C18
Ghidra address:
EUR: 0x8037b668
Ghidra address:
JPN: 0x8037a2d8