Go to the source code of this file.
Data Structures | |
| union | PackedWord |
| A word put together from its four bytes, lowest first. More... | |
Macros | |
| #define | SOUND_PCM_BUFFER_SIZE 0x630 |
| The PCM buffer's size in samples, a multiple of every frame length: the DMA plays it round and round. | |
| #define | SOUND_FRAME_RATE_E4 597275 |
| The display's frame rate in ten-thousandths of a hertz: 59.7275 frames a second. | |
| #define | SOUND_CYCLES_PER_FRAME (228 * 1232) |
| CPU cycles in a frame: 228 lines of 1232 cycles. | |
Functions | |
| void | AudioCommand_InvokeSlot34 (struct SoundNote *note) |
| Detaches a note through the command table entry installed by the driver. | |
| void | AudioCommand_InvokeSlot35 (void *block) |
| Clears a 64-byte player or track prefix through the driver command table. | |
| s32 | __divsi3 (s32 numerator, s32 denominator) |
| void | Sound_LoadCommandTable (SoundCommand *table) |
| void | MusicTrack_HandleNote (u32 command, struct SoundPlayer *player, struct SoundTrack *track) |
| void | Audio_EmptyCallback (void) |
| Provides the default empty callback before the sound driver installs its handlers. | |
| 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. | |
| void | AudioEngine_ResumeDirectSound (void) |
| Restarts both FIFO transfers and releases the suspended-work lock. | |
| void | MusicPlayer_Tick (struct SoundPlayer *player) |
| void | MusicTrack_Stop (struct SoundPlayer *player, struct SoundTrack *track) |
| 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 | CgbChannel_Mute (u8 channel) |
| Disables one CGB channel using its envelope or wave-control register. | |
| 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. | |
| UNUSED void | AudioEngine_StopAllChannels (void) |
| Silences every PCM and CGB note while holding the sound work lock. | |
| void | MusicPlayer_Initialize (struct SoundPlayer *player, struct SoundTrack *tracks, u8 trackCount) |
| Deactivates up to sixteen tracks and links the player into the mixer tick chain. | |
| void | MusicPlayer_StartSong (struct SoundPlayer *player, const struct SequenceHeader *header) |
| Starts a song when its priority permits, resetting its tracks and tempo. | |
| void | MusicPlayer_Stop (struct SoundPlayer *player) |
| Pauses this player and stops all of its tracks, under the player's lock. | |
| 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 | MusicTrack_CalcOutput (struct SoundPlayer *player, struct SoundTrack *track) |
| Recalculates dirty stereo volumes and pitch from track settings and modulation. | |
| s32 | Cgb_KeyToFrequency (u8 kind, u8 key, u8 fine) |
| Converts a key and fractional pitch to a CGB tone or noise-register value. | |
| void | CgbNote_UpdatePanEnvelope (struct CgbNote *note) |
| Chooses stereo routing and derives peak and sustain levels for a CGB note, writing them into note. | |
| void | Cgb_UpdateChannels (void) |
| Steps CGB note envelopes and writes changed pitch, volume and trigger registers, once a frame. | |
| void | MusicPlayer_SetPitchAndUpdateFrequency (struct SoundPlayer *player, u16 scale) |
| Sets the tempo multiplier and updates the number of ticks advanced per frame. | |
| void | MusicPlayer_SetVolume (struct SoundPlayer *player, u16 mask, u16 volume) |
| Sets the volume scale of active tracks selected by the bit mask and marks their output for recalculation. | |
| void | MusicPlayer_SetPitch (struct SoundPlayer *player, u16 mask, s16 pitch) |
| Sets the semitone and fractional pitch offsets of selected active tracks and marks their pitch for recalculation. | |
| UNUSED void | MusicPlayer_SetPan (struct SoundPlayer *player, u16 mask, s8 pan) |
| Sets the stereo pan offset of selected active tracks. | |
| void | MusicTrack_ClearModulation (struct SoundTrack *track) |
| Resets the LFO phase and amount, marking the affected output for recalculation. | |
| void | MusicPlayer_SetModulationDepth (struct SoundPlayer *player, s32 selectedTracks, s32 depthArgument) |
| Sets modulation depth on selected active tracks, resetting zero-depth modulation. | |
| void | MusicPlayer_SetLfoSpeed (struct SoundPlayer *player, u32 selectedTracks, u32 speedArgument) |
| Sets LFO speed on selected active tracks, resetting modulation when stopped. | |
| void | MusicTrack_OperateWorkByte (struct SoundPlayer *player, struct SoundTrack *track) |
| Executes a work-byte operation and consumes a branch address for comparisons. | |
| void | MusicTrack_DispatchStreamCommand (struct SoundPlayer *player, struct SoundTrack *track) |
| Reads an extended-command index and invokes its handler. | |
| void | Runtime_CallWorkEntryWithArgs (struct SoundPlayer *player, struct SoundTrack *track) |
| Finishes a track through the base command table entry. | |
| void | MusicTrack_ReadVoiceTarget (struct SoundPlayer *player, struct SoundTrack *track) |
| Reads an unaligned little-endian voice target address from the sequence. | |
| void | MusicTrack_SetVoiceKind (struct SoundPlayer *player, struct SoundTrack *track) |
| Reads the voice kind from the sequence. | |
| void | MusicTrack_SetVoiceAttack (struct SoundPlayer *player, struct SoundTrack *track) |
| Reads the voice attack rate from the sequence. | |
| void | MusicTrack_SetVoiceDecay (struct SoundPlayer *player, struct SoundTrack *track) |
| Reads the voice decay rate from the sequence. | |
| void | MusicTrack_SetVoiceSustain (struct SoundPlayer *player, struct SoundTrack *track) |
| Reads the voice sustain level from the sequence. | |
| void | MusicTrack_SetVoiceRelease (struct SoundPlayer *player, struct SoundTrack *track) |
| Reads the voice release rate from the sequence. | |
| void | MusicTrack_SetTailLevel (struct SoundPlayer *player, struct SoundTrack *track) |
| Reads the note tail volume from the sequence. | |
| void | MusicTrack_SetTailLength (struct SoundPlayer *player, struct SoundTrack *track) |
| Reads the note tail duration from the sequence. | |
| void | MusicTrack_SetVoiceLength (struct SoundPlayer *player, struct SoundTrack *track) |
| Reads the hardware note length from the sequence. | |
| void | MusicTrack_SetVoicePanOrSweep (struct SoundPlayer *player, struct SoundTrack *track) |
| Reads the voice pan or CGB sweep setting from the sequence. | |
Variables | |
| const u16 | gSound_FrameLengths [] |
| Samples per frame for each playback frequency setting. | |
| SoundCommand | gSound_CommandTable [36] |
| const u8 | gSound_CgbPitchCodes [] |
| CGB channel pitches. | |
| const s16 | gSound_CgbFrequencySteps [] |
| Frequencies by note for CGB channels. | |
| const u8 | gSound_NoisePitchCodes [] |
| Noise channel pitches. | |
| const u8 | gSound_Cgb3LevelCodes [] |
| CGB channel 3 waveform volumes. | |
| #define SOUND_PCM_BUFFER_SIZE 0x630 |
The PCM buffer's size in samples, a multiple of every frame length: the DMA plays it round and round.
Definition at line 53 of file engine.c.
Referenced by AudioEngine_SetPcmRate().
| #define SOUND_FRAME_RATE_E4 597275 |
The display's frame rate in ten-thousandths of a hertz: 59.7275 frames a second.
Definition at line 56 of file engine.c.
Referenced by AudioEngine_SetPcmRate().
| #define SOUND_CYCLES_PER_FRAME (228 * 1232) |
CPU cycles in a frame: 228 lines of 1232 cycles.
Definition at line 58 of file engine.c.
Referenced by AudioEngine_SetPcmRate().
| void AudioCommand_InvokeSlot34 | ( | struct SoundNote * | note | ) |
Detaches a note through the command table entry installed by the driver.
Called by the song player (MusicPlayer_Tick, MusicTrack_HandleNote).
Definition at line 7 of file engine.c.
Referenced by AudioCommand_InvokeSlot34(), and STATIC_ASSERT().
| void AudioCommand_InvokeSlot35 | ( | void * | block | ) |
Clears a 64-byte player or track prefix through the driver command table.
Called by the song player and MusicPlayer_ResetActiveTracks.
Definition at line 19 of file engine.c.
Referenced by AudioCommand_InvokeSlot35(), MusicPlayer_Initialize(), MusicPlayer_ResetActiveTracks(), and STATIC_ASSERT().
| void Sound_LoadCommandTable | ( | SoundCommand * | table | ) |
Referenced by AudioEngine_Initialize(), and Sound_LoadCommandTable().
| void MusicTrack_HandleNote | ( | u32 | command, |
| struct SoundPlayer * | player, | ||
| struct SoundTrack * | track ) |
Referenced by AudioEngine_Initialize(), and MusicTrack_HandleNote().
| void Audio_EmptyCallback | ( | void | ) |
Provides the default empty callback before the sound driver installs its handlers.
Definition at line 6 of file empty_callback.c.
| 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.
Referenced by AudioEngine_Initialize(), AudioEngine_RunMixerTick(), AudioEngine_SetMode(), AudioEngine_SetPcmRate(), AudioEngine_SetPcmRate(), CgbAudio_Initialize(), MusicTrack_HandleNote(), and MusicTrack_ReleaseKey().
| 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().
| 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().
| void MusicPlayer_Tick | ( | struct SoundPlayer * | player | ) |
Referenced by MusicPlayer_Initialize(), and MusicPlayer_Tick().
| void MusicTrack_Stop | ( | struct SoundPlayer * | player, |
| struct SoundTrack * | track ) |
| 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.
Referenced by Audio_Initialize(), AudioEngine_RunMixerTick(), AudioEngine_SetMode(), MusicPlayer_StartSong(), MusicTrack_Stop(), and Sound_Mixer().
| 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.
Referenced by AudioEngine_RunMixerTick(), Cgb_UpdateChannels(), CgbAudio_Initialize(), CgbChannel_Mute(), and MusicTrack_Stop().
| 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.
Referenced by Audio_Initialize(), Audio_UmulHigh32(), AudioEngine_Initialize(), and Sound_Mixer().
| UNUSED void AudioEngine_StopAllChannels | ( | void | ) |
Silences every PCM and CGB note while holding the sound work lock.
Nothing in ☀️ calls it.
Definition at line 178 of file engine.c.
Referenced by AudioEngine_StopAllChannels().
| void MusicPlayer_Initialize | ( | struct SoundPlayer * | player, |
| struct SoundTrack * | tracks, | ||
| u8 | trackCount ) |
Deactivates up to sixteen tracks and links the player into the mixer tick chain.
Definition at line 246 of file engine.c.
Referenced by Audio_Initialize(), AudioEngine_RunMixerTick(), and MusicPlayer_Initialize().
| void MusicPlayer_StartSong | ( | struct SoundPlayer * | player, |
| const struct SequenceHeader * | header ) |
Starts a song when its priority permits, resetting its tracks and tempo.
Definition at line 282 of file engine.c.
Referenced by Audio_PlayOrResumeSound(), Audio_PlaySound(), Audio_PlaySoundIfInactive(), AudioCommand_Play(), AudioEngine_RunMixerTick(), MusicPlayer_StartSong(), and STATIC_ASSERT().
| 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.
Referenced by Audio_StopAllPlayers(), Audio_StopSound(), AudioEngine_RunMixerTick(), and MusicPlayer_Stop().
| 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.
Referenced by AudioEngine_RunMixerTick(), CgbAudio_Initialize(), MusicPlayer_StepFade(), MusicPlayer_StepFade(), and MusicTrack_Stop().
| 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.
Referenced by CgbAudio_Initialize(), MusicPlayer_Tick(), MusicTrack_CalcOutput(), MusicTrack_CalcOutput(), and MusicTrack_Stop().
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.
Referenced by AudioEngine_RunMixerTick(), Cgb_KeyToFrequency(), CgbAudio_Initialize(), and MusicTrack_Stop().
| void CgbNote_UpdatePanEnvelope | ( | struct CgbNote * | note | ) |
Chooses stereo routing and derives peak and sustain levels for a CGB note, writing them into note.
Called by Cgb_UpdateChannels. Its separate peak calculations and jumps are the form the bytes show: shared, tbs-en is four bytes shorter.
Definition at line 509 of file engine.c.
Referenced by Cgb_UpdateChannels(), CgbNote_UpdatePanEnvelope(), and STATIC_ASSERT().
| 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.
Referenced by AudioEngine_RunMixerTick(), Cgb_UpdateChannels(), CgbAudio_Initialize(), and MusicTrack_Stop().
| void MusicPlayer_SetPitchAndUpdateFrequency | ( | struct SoundPlayer * | player, |
| u16 | scale ) |
Sets the tempo multiplier and updates the number of ticks advanced per frame.
Definition at line 787 of file engine.c.
Referenced by MusicCommand_SetPitchAndUpdateFrequency(), MusicPlayer_SetPitchAndUpdateFrequency(), MusicPlayer_StepVolumeAndPitchTowardTargets(), and STATIC_ASSERT().
| void MusicPlayer_SetVolume | ( | struct SoundPlayer * | player, |
| u16 | mask, | ||
| u16 | volume ) |
Sets the volume scale of active tracks selected by the bit mask and marks their output for recalculation.
Called by the music layer's volume ramps and commands (sound.c).
Definition at line 800 of file engine.c.
Referenced by AudioCommand_Play(), MusicCommand_SetVolume(), MusicPlayer_SetVolume(), MusicPlayer_StepVolumeAndPitchTowardTargets(), and STATIC_ASSERT().
| void MusicPlayer_SetPitch | ( | struct SoundPlayer * | player, |
| u16 | mask, | ||
| s16 | pitch ) |
Sets the semitone and fractional pitch offsets of selected active tracks and marks their pitch for recalculation.
Called by the music layer's pitch ramps and commands (sound.c).
Definition at line 828 of file engine.c.
Referenced by MusicCommand_SetPitch(), MusicPlayer_SetPitch(), MusicPlayer_StepVolumeAndPitchTowardTargets(), and STATIC_ASSERT().
| UNUSED void MusicPlayer_SetPan | ( | struct SoundPlayer * | player, |
| u16 | mask, | ||
| s8 | pan ) |
Sets the stereo pan offset of selected active tracks.
Nothing in ☀️ calls it.
Definition at line 856 of file engine.c.
Referenced by MusicPlayer_SetPan(), and STATIC_ASSERT().
| void MusicTrack_ClearModulation | ( | struct SoundTrack * | track | ) |
Resets the LFO phase and amount, marking the affected output for recalculation.
Definition at line 883 of file engine.c.
Referenced by MusicPlayer_SetLfoSpeed(), MusicPlayer_SetModulationDepth(), MusicTrack_ClearModulation(), and STATIC_ASSERT().
| void MusicPlayer_SetModulationDepth | ( | struct SoundPlayer * | player, |
| s32 | selectedTracks, | ||
| s32 | depthArgument ) |
Sets modulation depth on selected active tracks, resetting zero-depth modulation.
Definition at line 894 of file engine.c.
Referenced by MusicPlayer_SetModulationDepth(), and STATIC_ASSERT().
| void MusicPlayer_SetLfoSpeed | ( | struct SoundPlayer * | player, |
| u32 | selectedTracks, | ||
| u32 | speedArgument ) |
Sets LFO speed on selected active tracks, resetting modulation when stopped.
Definition at line 925 of file engine.c.
Referenced by MusicPlayer_SetLfoSpeed(), and STATIC_ASSERT().
| 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.
Referenced by AudioEngine_RunMixerTick(), CgbAudio_Initialize(), MusicTrack_HandleNote(), and MusicTrack_OperateWorkByte().
| void MusicTrack_DispatchStreamCommand | ( | struct SoundPlayer * | player, |
| struct SoundTrack * | track ) |
Reads an extended-command index and invokes its handler.
Definition at line 1049 of file engine.c.
Referenced by CgbAudio_Initialize(), MusicTrack_DispatchStreamCommand(), and STATIC_ASSERT().
| void Runtime_CallWorkEntryWithArgs | ( | struct SoundPlayer * | player, |
| struct SoundTrack * | track ) |
Finishes a track through the base command table entry.
Definition at line 1070 of file engine.c.
Referenced by Runtime_CallWorkEntryWithArgs(), Runtime_CallWorkEntryWithArgs(), and Runtime_CallWorkEntryWithArgs().
| void MusicTrack_ReadVoiceTarget | ( | struct SoundPlayer * | player, |
| struct SoundTrack * | track ) |
Reads an unaligned little-endian voice target address from the sequence.
Definition at line 1078 of file engine.c.
Referenced by MusicTrack_ReadVoiceTarget(), SoundDriver_ClearBuffer(), and STATIC_ASSERT().
| void MusicTrack_SetVoiceKind | ( | struct SoundPlayer * | player, |
| struct SoundTrack * | track ) |
Reads the voice kind from the sequence.
Definition at line 1092 of file engine.c.
Referenced by MusicTrack_SetVoiceKind(), and SoundDriver_ClearBuffer().
| void MusicTrack_SetVoiceAttack | ( | struct SoundPlayer * | player, |
| struct SoundTrack * | track ) |
Reads the voice attack rate from the sequence.
Definition at line 1099 of file engine.c.
Referenced by MusicTrack_SetVoiceAttack(), and SoundDriver_ClearBuffer().
| void MusicTrack_SetVoiceDecay | ( | struct SoundPlayer * | player, |
| struct SoundTrack * | track ) |
Reads the voice decay rate from the sequence.
Definition at line 1106 of file engine.c.
Referenced by MusicTrack_SetVoiceDecay(), and SoundDriver_ClearBuffer().
| void MusicTrack_SetVoiceSustain | ( | struct SoundPlayer * | player, |
| struct SoundTrack * | track ) |
Reads the voice sustain level from the sequence.
Definition at line 1113 of file engine.c.
Referenced by MusicTrack_SetVoiceSustain(), and SoundDriver_ClearBuffer().
| void MusicTrack_SetVoiceRelease | ( | struct SoundPlayer * | player, |
| struct SoundTrack * | track ) |
Reads the voice release rate from the sequence.
Definition at line 1120 of file engine.c.
Referenced by MusicTrack_SetVoiceRelease(), and SoundDriver_ClearBuffer().
| void MusicTrack_SetTailLevel | ( | struct SoundPlayer * | player, |
| struct SoundTrack * | track ) |
Reads the note tail volume from the sequence.
Definition at line 1127 of file engine.c.
Referenced by MusicTrack_SetTailLevel(), and SoundDriver_ClearBuffer().
| void MusicTrack_SetTailLength | ( | struct SoundPlayer * | player, |
| struct SoundTrack * | track ) |
Reads the note tail duration from the sequence.
Definition at line 1134 of file engine.c.
Referenced by MusicTrack_SetTailLength(), and SoundDriver_ClearBuffer().
| void MusicTrack_SetVoiceLength | ( | struct SoundPlayer * | player, |
| struct SoundTrack * | track ) |
Reads the hardware note length from the sequence.
Definition at line 1141 of file engine.c.
Referenced by MusicTrack_SetVoiceLength(), and SoundDriver_ClearBuffer().
| void MusicTrack_SetVoicePanOrSweep | ( | struct SoundPlayer * | player, |
| struct SoundTrack * | track ) |
Reads the voice pan or CGB sweep setting from the sequence.
Definition at line 1148 of file engine.c.
Referenced by MusicTrack_SetVoicePanOrSweep(), and SoundDriver_ClearBuffer().
|
extern |
Samples per frame for each playback frequency setting.
Definition at line 131 of file tables.c.
Referenced by AudioEngine_SetPcmRate(), and MusicTrack_HandleNote().
|
extern |
|
extern |
CGB channel pitches.
Definition at line 136 of file tables.c.
Referenced by Cgb_KeyToFrequency(), and MusicTrack_Stop().
|
extern |
Frequencies by note for CGB channels.
Definition at line 151 of file tables.c.
Referenced by Cgb_KeyToFrequency(), and MusicTrack_Stop().
|
extern |
Noise channel pitches.
Definition at line 156 of file tables.c.
Referenced by Cgb_KeyToFrequency(), and MusicTrack_Stop().
|
extern |
CGB channel 3 waveform volumes.
Definition at line 165 of file tables.c.
Referenced by Cgb_UpdateChannels(), and MusicTrack_Stop().