19 pitchScale = (
u32)pitch << 24;
22 pitchScale = 255U << 24;
33 *(
s32 *)((
u8 *)wave + 4),
44#define SOUND_PLAYER_COUNT ((u16)(u32)Sound_PlayerCount)
45#define SOUND_MAX_LINES ((u32)Sound_MaxLines)
113#define SOUND_MIXER_CODE_SIZE 0x400
145 const struct SongEntry *song = &songs[songId];
155 const struct SongEntry *song = &songs[songId];
160 else if ((player->
status & 0xFFFF) == 0 ||
170 const struct SongEntry *song = &songs[songId];
175 else if ((player->
status & 0xFFFF) == 0)
186 const struct SongEntry *song = &songs[songId];
198 const struct SongEntry *song = &songs[songId];
323 (
sizeof(
struct CgbNote) * 4 / 4));
static __inline__ void MusicPlayer_SetFadeParameters(struct SoundPlayer *player, u16 period, u16 volume)
Starts a fade under the player lock, resuming the player for fade-ins.
UNUSED void MusicPlayer_FadeIn(struct SoundPlayer *player, u16 speed)
Starts a fade from zero volume and resumes the player.
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.
#define SOUND_PLAYER_COUNT
void MusicTrack_SetLfoSpeedFromCommand(struct SoundPlayer *player, struct SoundTrack *track)
struct SoundWork gSound_Work
UNUSED void MusicPlayer_FadeOutPause(struct SoundPlayer *player, u16 speed)
Begins a fade that pauses the player at zero volume, keeping its tracks' state for a later resume.
void AudioEngine_Initialize(struct SoundWork *work)
Resets the sound hardware, clears the whole sound work block and installs the default PCM driver: sto...
#define SOUND_MIXER_CODE_SIZE
The bytes of mixer code Audio_Initialize copies to IWRAM.
void CgbAudio_Initialize(struct CgbNote *notes)
Resets the CGB sound hardware, installs the CGB-aware command handlers and callbacks in the sound wor...
void MusicTrack_ReleaseKey(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.
UNUSED void Audio_ResumeAllPlayers(void)
Resumes every player. Nothing in ☀️ calls it.
void Audio_PlaySound(u16 songId)
Starts the song on the player selected by its song-table entry.
void AudioEngine_SetPcmRate(u32 mode)
Sets the PCM frame length (mode bits 16 to 19 pick a gSound_FrameLengths entry) and the rates derived...
void Cgb_UpdateChannels(void)
Steps CGB note envelopes and writes changed pitch, volume and trigger registers, once a frame.
void Audio_Initialize(void)
Copies the RAM mixer to IWRAM, initializes the PCM and CGB paths and configures every player from gSo...
UNUSED void MusicPlayer_Resume(struct SoundPlayer *player)
Resumes player. Nothing in ☀️ calls it.
void MusicTrack_CalcOutput(struct SoundPlayer *player, struct SoundTrack *track)
Recalculates dirty stereo volumes and pitch from track settings and modulation.
const struct PlayerSlot gSound_PlayerSlots[]
void AudioEngine_RunMixer(void)
u32 Audio_UmulHigh32(u32 left, u32 right)
void CgbChannel_Mute(u8 channel)
Disables one CGB channel using its envelope or wave-control register.
void AudioEngine_RunMixerTick(void)
void MusicPlayer_StartSong(struct SoundPlayer *player, const struct SequenceHeader *header)
Starts a song when its priority permits, resetting its tracks and tempo.
s32 Pcm_KeyToFrequency(void *wave, u8 key, u8 pitch)
Interpolates adjacent key frequencies and scales them by the wave sample frequency.
UNUSED void Audio_StopSound(u16 songId)
Stops the selected player only when it holds this song.
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...
UNUSED void MusicPlayer_ResetActiveTracks(struct SoundPlayer *player)
Initializes active tracks still carrying their reset flag: clears their settings and gives them the d...
UNUSED void Audio_ResumeSound(u16 songId)
Resumes the selected player only when it holds this song.
struct CgbNote gSound_CgbNotes[4]
s32 Cgb_KeyToFrequency(u8 kind, u8 key, u8 fine)
Converts a key and fractional pitch to a CGB tone or noise-register value.
UNUSED void Audio_StopAllPlayers(void)
Stops every player. Nothing in ☀️ calls it.
void MusicTrack_Stop(struct SoundPlayer *player, struct SoundTrack *track)
void MusicPlayer_FadeOut(struct SoundPlayer *player, u16 speed)
Begins the standard stop-and-clear fade.
u32 gSound_PcmFrequencySteps[]
Frequencies by note at octave zero, in 32-bit fixed point.
UNUSED void Audio_PlaySoundIfInactive(u16 songId)
Starts the song unless its selected player is already playing it.
SoundCommand gSound_CommandTable[36]
void AudioEngine_SetMode(u32 mode)
Applies the reverb, channel-count, volume, bias and sample-rate fields of mode to the sound work,...
void MusicPlayer_BeginFadeOut(struct SoundPlayer *player, u16 speed)
Begins a fade that stops and clears tracks when its volume reaches zero.
void MusicTrack_SetModulationFromCommand(struct SoundPlayer *player, struct SoundTrack *track)
u8 gSound_PcmPitchCodes[]
PCM pitches: the high four bits hold the octave, the low four the note.
UNUSED void Audio_PlayOrResumeSound(u16 songId)
Starts a different or finished song, or resumes the same paused song.
void Audio_ResumePlayer(struct SoundPlayer *player)
Clears the player's paused flag while holding the player lock.
const struct SongEntry gSound_SongTable[]
void Audio_NoopStub(void)
Provides the empty callback retained by the sound driver.
Declares nothing of its own: it only includes audio_engine_symbols.h and sound/audio_engine_types....
void Bios_CpuSet(const void *source, void *destination, u32 control)
#define AUDIO_INITIAL_MODE
#define SOUNDCNT_X_ALL_TONES_ON
#define SOUND_COMMAND_FADE
MusicPlayer_StepFade: a frame of a fade.
#define SOUND_COMMAND_RELEASE_KEY
Byte 0xCE: releases the track's sounding note of the key given (or of its last key when no key byte f...
#define SOUND_FADE_FULL_VOLUME
#define SOUND_COMMAND_CALCULATE_OUTPUT
MusicTrack_CalcOutput.
#define SOUNDCNT_X_ENABLE
#define SOUND_COMMAND_STOP_TRACK
MusicTrack_Stop: silences the track's notes and empties its list.
#define SOUND_COMMAND_LFO_SPEED
Byte 0xC2: sets lfoSpeed from the next byte; 0 clears the modulation.
#define SOUND_COMMAND_PCM_RATE
AudioEngine_SetPcmRate.
#define SOUND_COMMAND_EXTENDED
Byte 0xCD, installed by CgbAudio_Initialize: runs the entry of gSound_ExtendedCommandTable the next b...
#define SOUND_COMMAND_WORK_BYTE
Byte 0xB9, installed by CgbAudio_Initialize: an operation, a work byte and an operand; sets,...
#define SOUND_COMMAND_CAST(type, routine)
Converts between SoundCommand and a table entry that takes other parameters, through the generic func...
#define SOUND_COMMAND_MODULATION
Byte 0xC4: sets modDepth from the next byte; 0 clears the modulation.
void MusicTrack_DispatchStreamCommand(struct SoundPlayer *player, struct SoundTrack *track)
Reads an extended-command index and invokes its handler.
void AudioCommand_InvokeSlot35(void *block)
Clears a 64-byte player or track prefix through the driver command table.
The hardware's I/O registers and their bits, as pret names them.
#define CPU_SET_SRC_FIXED
BIOS CpuSet control flags, above its count.
The work pointers in the gWorkSlot table, by name.
A note on one of the four CGB channels of the hardware: its state and envelope, its levels and pan,...
u8 channelBits
This channel's NR51 bits: 0x11, 0x22, 0x44, 0x88.
u8 kind
Channel number 1 to 4 at setup, then the voice's kind; bit 3 rounds the frequency to the sound bias's...
An entry of the player table: a player, its tracks and track count, and its priority check.
struct SoundPlayer * player
u16 checkPriority
Copied to the player's checkPriority; 0 everywhere.
An entry of the song table: a song's header and the player table entry that plays it.
u16 slot
Index into gSound_PlayerSlots; AudioCommand_Play gives slot 7's songs the first player from 7 down to...
const struct SequenceHeader * header
A player, which plays one song: its header and status, its tracks, its tempo and fade.
const struct SequenceHeader * header
The song playing or last played.
u8 checkPriority
Nonzero: a song of lower priority does not replace a playing one.
u16 fadeCounter
Frames left until the next fade step.
u16 fadeVolume
bits: 8..4 level, 0 to 0x100 in steps of 16 | 1 fade in | 0 pause at the end (SoundFadeFlag).
u32 status
bits: 31 paused | 15..0 tracks active after the last tick.
u8 trackCount
Tracks this player owns, at most 16.
u8 * workBytes
gSound_WorkBytes, which the work-byte command uses.
u32 lock
SOUND_LOCK when free; raised while the player is changed or ticked.
struct SoundTrack * tracks
trackCount tracks.
u16 fadePeriod
Frames between fade steps; 0 when not fading.
A track of a playing song: the song commands it runs, its voice and notes, and the pitch,...
u8 bendRange
Semitones a full bend reaches; 2 at reset.
u8 lfoSpeed
LFO phase step a tick, 22 at reset; 0 stops the LFO and clears modAmount.
struct SoundNote * notes
The notes this track started, newest first, linked through SoundNote.next; PCM notes from SoundWork....
struct SoundVoice voice
Copied from the player's voice table by the voice command, or set a field at a time by extended comma...
u8 volumeScale
0 to 64 (full, the reset value): a player volume or fade level of 0 to 0x100 divided by 4.
u8 kind
bits: 7 rhythm | 6 key split | 3 fixed rate for PCM, bias rounding for CGB | 2..0 CGB channel (0 PCM)...
The sound driver's work: its lock, the mixer's rate and buffers, the PCM and CGB notes,...
s32(*) cgbFrequency(u8 kind, u8 key, u8 fine)
Cgb_KeyToFrequency.
u32 lock
SOUND_LOCK when free; raised while the driver changes it.
struct CgbNote * cgbNotes
gSound_CgbNotes; NULL before CGB setup.
u8 maxLines
Nonzero: the mixer stops taking notes once the scanline passes this many lines after its start.
void(*) cgbUpdate(void)
Run each mixer frame: Cgb_UpdateChannels.
void(*) cgbMute(u8 channel)
CgbChannel_Mute, channel 1 to 4.
void(*) SoundCommand(struct SoundPlayer *player, struct SoundTrack *track)
A command table entry: the driver calls it with the player and the track.
The integer types, TRUE, UNUSED and the fixed-address macros.