Alchemy
Loading...
Searching...
No Matches

sound.h File Reference

The sound tables (CGB codes, frequency steps, frame lengths) and the sound routines. More...

Go to the source code of this file.

Functions

void Audio_ResumeAllPlayers (void)
 Resumes every player. Nothing in ☀️ calls it.
void Audio_ResumePlayer (struct SoundPlayer *player)
 Clears the player's paused flag while holding the player lock.
void Audio_StopAllPlayers (void)
 Stops every player. Nothing in ☀️ calls it.
u32 Audio_UmulHigh32 (u32 left, u32 right)
void AudioEngine_Initialize (struct SoundWork *work)
 Resets the sound hardware, clears the whole sound work block and installs the default PCM driver: stores work in SOUND_WORK, points the FIFO DMAs at its two buffers, fills in the driver callbacks and command table, sets the default rate and finally sets the work's lock.
void AudioEngine_ResumeDirectSound (void)
 Restarts both FIFO transfers and releases the suspended-work lock.
void AudioEngine_RunMixerTick (void)
void AudioEngine_SetMode (u32 mode)
 Applies the reverb, channel-count, volume, bias and sample-rate fields of mode to the sound work, under its lock.
void AudioEngine_SetPcmRate (u32 mode)
 Sets the PCM frame length (mode bits 16 to 19 pick a gSound_FrameLengths entry) and the rates derived from it, and Timer 0's reload, starting playback at scanline 159.
void AudioEngine_SuspendDirectSound (void)
 Stops both FIFO transfers and clears their sample buffers, raising the work's lock until AudioEngine_ResumeDirectSound.
s32 Cgb_KeyToFrequency (u8 kind, u8 key, u8 fine)
 Converts a key and fractional pitch to a CGB tone or noise-register value.
void Cgb_UpdateChannels (void)
 Steps CGB note envelopes and writes changed pitch, volume and trigger registers, once a frame.
void CgbChannel_Mute (u8 channel)
 Disables one CGB channel using its envelope or wave-control register.
void MusicPlayer_BeginFadeOut (struct SoundPlayer *player, u16 speed)
 Begins a fade that stops and clears tracks when its volume reaches zero.
void MusicPlayer_Initialize (struct SoundPlayer *player, struct SoundTrack *tracks, u8 count)
 Deactivates up to sixteen tracks and links the player into the mixer tick chain.
void MusicPlayer_StepFade (struct SoundPlayer *player)
 Advances a due fade step, updating active track volumes, or at the end of a fade out stops (or pauses) the player.
void MusicPlayer_Stop (struct SoundPlayer *player)
 Pauses this player and stops all of its tracks, under the player's lock.
void MusicPlayer_Tick (struct SoundPlayer *player)
void MusicTrack_CalcOutput (struct SoundPlayer *player, struct SoundTrack *track)
 Recalculates dirty stereo volumes and pitch from track settings and modulation.
void MusicTrack_HandleNote (u32 command, struct SoundPlayer *player, struct SoundTrack *track)
void MusicTrack_OperateWorkByte (struct SoundPlayer *player, struct SoundTrack *track)
 Executes a work-byte operation and consumes a branch address for comparisons.
void MusicTrack_ReleaseKey (struct SoundPlayer *player, struct SoundTrack *track)
void MusicTrack_SetLfoSpeedFromCommand (struct SoundPlayer *player, struct SoundTrack *track)
void MusicTrack_SetModulationFromCommand (struct SoundPlayer *player, struct SoundTrack *track)
void MusicTrack_Stop (struct SoundPlayer *player, struct SoundTrack *track)
void Sound_Mixer (void)
void Audio_Initialize (void)
 Copies the RAM mixer to IWRAM, initializes the PCM and CGB paths and configures every player from gSound_PlayerSlots.
void Audio_PlaySound (u16 id)
 Starts the song on the player selected by its song-table entry.
void Sound_TickDmaRestartTimer (void)

Variables

const u8 gSound_Cgb3LevelCodes []
 CGB channel 3 waveform volumes.
const s16 gSound_CgbFrequencySteps []
 Frequencies by note for CGB channels.
const u8 gSound_CgbPitchCodes []
 CGB channel pitches.
const u16 gSound_FrameLengths []
 Samples per frame for each playback frequency setting.
const u8 gSound_NoisePitchCodes []
 Noise channel pitches.
u32 gSound_PcmFrequencySteps []
 Frequencies by note at octave zero, in 32-bit fixed point.
u8 gSound_PcmPitchCodes []
 PCM pitches: the high four bits hold the octave, the low four the note.
struct SoundWork gSound_Work
u8 gSound_WorkBytes []
s32 gBuildStamp []
 The build stamp System_CopyBuildStamp copies to IWRAM at power-on: twelve digits and a zero word, at the bottom of the frame-wait stack.
u8 gMusicFadeRequested
s32 gSoundClipFlag
u8 gEwram_Data1

Detailed Description

The sound tables (CGB codes, frequency steps, frame lengths) and the sound routines.

Definition in file sound.h.

Function Documentation

◆ Audio_ResumeAllPlayers()

void Audio_ResumeAllPlayers ( void )

Resumes every player. Nothing in ☀️ calls it.

Definition at line 219 of file audio.c.

Referenced by Audio_ResumeAllPlayers(), and AudioCommand_ResumeAllPlayers().

◆ Audio_ResumePlayer()

void Audio_ResumePlayer ( struct SoundPlayer * player)

Clears the player's paused flag while holding the player lock.

Called by the resume and play-or-resume commands.

Definition at line 84 of file audio.c.

Referenced by Audio_PlayOrResumeSound(), Audio_ResumeAllPlayers(), Audio_ResumePlayer(), Audio_ResumeSound(), AudioEngine_RunMixerTick(), and MusicPlayer_Resume().

◆ Audio_StopAllPlayers()

void Audio_StopAllPlayers ( void )

Stops every player. Nothing in ☀️ calls it.

Definition at line 206 of file audio.c.

Referenced by Audio_StopAllPlayers(), and AudioCommand_StopAllPlayers().

◆ Audio_UmulHigh32()

u32 Audio_UmulHigh32 ( u32 left,
u32 right )

◆ AudioEngine_Initialize()

void AudioEngine_Initialize ( struct SoundWork * work)

Resets the sound hardware, clears the whole sound work block and installs the default PCM driver: stores work in SOUND_WORK, points the FIFO DMAs at its two buffers, fills in the driver callbacks and command table, sets the default rate and finally sets the work's lock.

Called by Audio_Initialize.

Definition at line 64 of file engine.c.

◆ AudioEngine_ResumeDirectSound()

void AudioEngine_ResumeDirectSound ( void )

Restarts both FIFO transfers and releases the suspended-work lock.

Called by AudioEngine_SetPcmRate.

Definition at line 232 of file engine.c.

Referenced by Audio_UmulHigh32(), AudioEngine_ResumeDirectSound(), AudioEngine_SetPcmRate(), and MusicTrack_HandleNote().

◆ AudioEngine_RunMixerTick()

void AudioEngine_RunMixerTick ( void )

◆ AudioEngine_SetMode()

void AudioEngine_SetMode ( u32 mode)

Applies the reverb, channel-count, volume, bias and sample-rate fields of mode to the sound work, under its lock.

Called by Audio_Initialize.

Definition at line 136 of file engine.c.

◆ AudioEngine_SetPcmRate()

void AudioEngine_SetPcmRate ( u32 mode)

Sets the PCM frame length (mode bits 16 to 19 pick a gSound_FrameLengths entry) and the rates derived from it, and Timer 0's reload, starting playback at scanline 159.

Called by AudioEngine_Initialize and AudioEngine_SetMode, and by songs through the command table.

Definition at line 105 of file engine.c.

◆ AudioEngine_SuspendDirectSound()

void AudioEngine_SuspendDirectSound ( void )

Stops both FIFO transfers and clears their sample buffers, raising the work's lock until AudioEngine_ResumeDirectSound.

Called by AudioEngine_SetMode around a rate change.

Definition at line 213 of file engine.c.

Referenced by AudioEngine_RunMixerTick(), AudioEngine_SetMode(), AudioEngine_SuspendDirectSound(), and MusicTrack_HandleNote().

◆ Cgb_KeyToFrequency()

s32 Cgb_KeyToFrequency ( u8 kind,
u8 key,
u8 fine )

Converts a key and fractional pitch to a CGB tone or noise-register value.

Installed as the work's cgbFrequency callback by CgbAudio_Initialize.

Definition at line 448 of file engine.c.

◆ Cgb_UpdateChannels()

void Cgb_UpdateChannels ( void )

Steps CGB note envelopes and writes changed pitch, volume and trigger registers, once a frame.

Installed as the work's cgbUpdate callback by CgbAudio_Initialize; the mixer calls it.

Definition at line 537 of file engine.c.

◆ CgbChannel_Mute()

void CgbChannel_Mute ( u8 channel)

Disables one CGB channel using its envelope or wave-control register.

Called by Cgb_UpdateChannels, and installed as the work's cgbMute callback.

Definition at line 485 of file engine.c.

◆ MusicPlayer_BeginFadeOut()

void MusicPlayer_BeginFadeOut ( struct SoundPlayer * player,
u16 speed )

Begins a fade that stops and clears tracks when its volume reaches zero.

Called by MusicPlayer_FadeOut.

Definition at line 108 of file audio.c.

Referenced by AudioEngine_RunMixerTick(), MusicPlayer_BeginFadeOut(), and MusicPlayer_FadeOut().

◆ MusicPlayer_Initialize()

void MusicPlayer_Initialize ( struct SoundPlayer * player,
struct SoundTrack * tracks,
u8 count )

Deactivates up to sixteen tracks and links the player into the mixer tick chain.

Definition at line 246 of file engine.c.

◆ MusicPlayer_StepFade()

void MusicPlayer_StepFade ( struct SoundPlayer * player)

Advances a due fade step, updating active track volumes, or at the end of a fade out stops (or pauses) the player.

Called by the song player each tick through the command table.

Definition at line 360 of file engine.c.

◆ MusicPlayer_Stop()

void MusicPlayer_Stop ( struct SoundPlayer * player)

Pauses this player and stops all of its tracks, under the player's lock.

Called by Audio_StopSound and Audio_StopAllPlayers.

Definition at line 339 of file engine.c.

◆ MusicPlayer_Tick()

void MusicPlayer_Tick ( struct SoundPlayer * player)

◆ MusicTrack_CalcOutput()

void MusicTrack_CalcOutput ( struct SoundPlayer * player,
struct SoundTrack * track )

Recalculates dirty stereo volumes and pitch from track settings and modulation.

Definition at line 411 of file engine.c.

◆ MusicTrack_HandleNote()

void MusicTrack_HandleNote ( u32 command,
struct SoundPlayer * player,
struct SoundTrack * track )

◆ MusicTrack_OperateWorkByte()

void MusicTrack_OperateWorkByte ( struct SoundPlayer * player,
struct SoundTrack * track )

Executes a work-byte operation and consumes a branch address for comparisons.

Definition at line 957 of file engine.c.

◆ MusicTrack_ReleaseKey()

void MusicTrack_ReleaseKey ( struct SoundPlayer * player,
struct SoundTrack * track )

◆ MusicTrack_SetLfoSpeedFromCommand()

void MusicTrack_SetLfoSpeedFromCommand ( struct SoundPlayer * player,
struct SoundTrack * track )

◆ MusicTrack_SetModulationFromCommand()

void MusicTrack_SetModulationFromCommand ( struct SoundPlayer * player,
struct SoundTrack * track )

◆ MusicTrack_Stop()

void MusicTrack_Stop ( struct SoundPlayer * player,
struct SoundTrack * track )

◆ Sound_Mixer()

void Sound_Mixer ( void )

◆ Audio_Initialize()

void Audio_Initialize ( void )

Copies the RAM mixer to IWRAM, initializes the PCM and CGB paths and configures every player from gSound_PlayerSlots.

Called by Audio_InitializeRuntimeDefaults at power-on.

Definition at line 118 of file audio.c.

Referenced by Audio_Initialize(), Audio_InitializeRuntimeDefaults(), and Sound_Mixer().

◆ Audio_PlaySound()

void Audio_PlaySound ( u16 songId)

Starts the song on the player selected by its song-table entry.

Called by AudioCommand_Play.

Definition at line 142 of file audio.c.

Referenced by Audio_PlaySound(), AudioCommand_Play(), and Sound_Mixer().

◆ Sound_TickDmaRestartTimer()

void Sound_TickDmaRestartTimer ( void )

Variable Documentation

◆ gSound_Cgb3LevelCodes

const u8 gSound_Cgb3LevelCodes[]
extern

CGB channel 3 waveform volumes.

Definition at line 165 of file tables.c.

◆ gSound_CgbFrequencySteps

const s16 gSound_CgbFrequencySteps[]
extern

Frequencies by note for CGB channels.

Definition at line 151 of file tables.c.

◆ gSound_CgbPitchCodes

const u8 gSound_CgbPitchCodes[]
extern

CGB channel pitches.

Definition at line 136 of file tables.c.

◆ gSound_FrameLengths

const u16 gSound_FrameLengths[]
extern

Samples per frame for each playback frequency setting.

Definition at line 131 of file tables.c.

◆ gSound_NoisePitchCodes

const u8 gSound_NoisePitchCodes[]
extern

Noise channel pitches.

Definition at line 156 of file tables.c.

◆ gSound_PcmFrequencySteps

u32 gSound_PcmFrequencySteps[]
extern

Frequencies by note at octave zero, in 32-bit fixed point.

Definition at line 124 of file tables.c.

◆ gSound_PcmPitchCodes

u8 gSound_PcmPitchCodes[]
extern

PCM pitches: the high four bits hold the octave, the low four the note.

Definition at line 105 of file tables.c.

◆ gSound_Work

struct SoundWork gSound_Work
extern

◆ gSound_WorkBytes

u8 gSound_WorkBytes[]
extern

◆ gBuildStamp

s32 gBuildStamp[]
extern

The build stamp System_CopyBuildStamp copies to IWRAM at power-on: twelve digits and a zero word, at the bottom of the frame-wait stack.

Referenced by AudioTest_RunParameterController(), Sound_Mixer(), and System_CopyBuildStamp().

◆ gMusicFadeRequested

u8 gMusicFadeRequested
extern

◆ gSoundClipFlag

s32 gSoundClipFlag
extern

◆ gEwram_Data1

u8 gEwram_Data1
extern