Alchemy
Loading...
Searching...
No Matches

sound.h

Go to the documentation of this file.
1#ifndef SOUND_H
2#define SOUND_H
3
4/// @file
5/// The sound tables (CGB codes, frequency steps, frame lengths) and the sound
6/// routines.
7
8#include "types.h"
9#include "edition.h"
10#include "audio_engine_types.h"
11
12struct SoundPlayer;
13struct SoundTrack;
14struct SoundWork;
15
16extern const u8 gSound_Cgb3LevelCodes[];
17extern const s16 gSound_CgbFrequencySteps[];
18extern const u8 gSound_CgbPitchCodes[];
19extern const u16 gSound_FrameLengths[];
20extern const u8 gSound_NoisePitchCodes[];
23extern struct SoundWork gSound_Work;
24extern u8 gSound_WorkBytes[];
25void Audio_ResumeAllPlayers(void);
26void Audio_ResumePlayer(struct SoundPlayer *player);
27void Audio_StopAllPlayers(void);
29void AudioEngine_Initialize(struct SoundWork *work);
32void AudioEngine_SetMode(u32 mode);
35s32 Cgb_KeyToFrequency(u8 kind, u8 key, u8 fine);
36void Cgb_UpdateChannels(void);
37void CgbChannel_Mute(u8 channel);
38void MusicPlayer_BeginFadeOut(struct SoundPlayer *player, u16 speed);
39void MusicPlayer_Initialize(struct SoundPlayer *player,
40 struct SoundTrack *tracks, u8 count);
41void MusicPlayer_StepFade(struct SoundPlayer *player);
42void MusicPlayer_Stop(struct SoundPlayer *player);
43void MusicPlayer_Tick(struct SoundPlayer *player);
44void MusicTrack_CalcOutput(struct SoundPlayer *player,
45 struct SoundTrack *track);
46void MusicTrack_HandleNote(u32 command, struct SoundPlayer *player,
47 struct SoundTrack *track);
48void MusicTrack_OperateWorkByte(struct SoundPlayer *player,
49 struct SoundTrack *track);
51 struct SoundTrack *track);
53 struct SoundTrack *track);
55 struct SoundTrack *track);
56void MusicTrack_Stop(struct SoundPlayer *player, struct SoundTrack *track);
57void Sound_Mixer(void);
58
59/// The build stamp System_CopyBuildStamp copies to IWRAM at power-on: twelve
60/// digits and a zero word, at the bottom of the frame-wait stack.
61extern s32 gBuildStamp[];
63extern s32 gSoundClipFlag;
64extern u8 gEwram_Data1;
65void Audio_Initialize(void);
66void Audio_PlaySound(u16 id);
68
69#endif
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 engine.c:246
void MusicTrack_SetLfoSpeedFromCommand(struct SoundPlayer *player, struct SoundTrack *track)
struct SoundWork gSound_Work
void AudioEngine_Initialize(struct SoundWork *work)
Resets the sound hardware, clears the whole sound work block and installs the default PCM driver: sto...
Definition engine.c:64
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.
Definition engine.c:957
UNUSED void Audio_ResumeAllPlayers(void)
Resumes every player. Nothing in ☀️ calls it.
Definition audio.c:219
void Audio_PlaySound(u16 songId)
Starts the song on the player selected by its song-table entry.
Definition audio.c:142
void AudioEngine_SetPcmRate(u32 mode)
Sets the PCM frame length (mode bits 16 to 19 pick a gSound_FrameLengths entry) and the rates derived...
Definition engine.c:105
void Cgb_UpdateChannels(void)
Steps CGB note envelopes and writes changed pitch, volume and trigger registers, once a frame.
Definition engine.c:537
void Audio_Initialize(void)
Copies the RAM mixer to IWRAM, initializes the PCM and CGB paths and configures every player from gSo...
Definition audio.c:118
void MusicTrack_CalcOutput(struct SoundPlayer *player, struct SoundTrack *track)
Recalculates dirty stereo volumes and pitch from track settings and modulation.
Definition engine.c:411
u32 Audio_UmulHigh32(u32 left, u32 right)
void Sound_Mixer(void)
void CgbChannel_Mute(u8 channel)
Disables one CGB channel using its envelope or wave-control register.
Definition engine.c:485
void AudioEngine_RunMixerTick(void)
void MusicPlayer_Stop(struct SoundPlayer *player)
Pauses this player and stops all of its tracks, under the player's lock.
Definition engine.c:339
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...
Definition engine.c:360
s32 Cgb_KeyToFrequency(u8 kind, u8 key, u8 fine)
Converts a key and fractional pitch to a CGB tone or noise-register value.
Definition engine.c:448
UNUSED void Audio_StopAllPlayers(void)
Stops every player. Nothing in ☀️ calls it.
Definition audio.c:206
void MusicTrack_Stop(struct SoundPlayer *player, struct SoundTrack *track)
u32 gSound_PcmFrequencySteps[]
Frequencies by note at octave zero, in 32-bit fixed point.
Definition tables.c:124
void AudioEngine_SetMode(u32 mode)
Applies the reverb, channel-count, volume, bias and sample-rate fields of mode to the sound work,...
Definition engine.c:136
void MusicPlayer_BeginFadeOut(struct SoundPlayer *player, u16 speed)
Begins a fade that stops and clears tracks when its volume reaches zero.
Definition audio.c:108
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.
Definition tables.c:105
void Audio_ResumePlayer(struct SoundPlayer *player)
Clears the player's paused flag while holding the player lock.
Definition audio.c:84
u8 gSound_WorkBytes[]
The sound driver's types, registers and work.
The edition's language, for C to compare (LANGUAGE == LANGUAGE_GERMAN).
const u16 gSound_FrameLengths[]
Samples per frame for each playback frequency setting.
Definition tables.c:131
const u8 gSound_CgbPitchCodes[]
CGB channel pitches.
Definition tables.c:136
const u8 gSound_Cgb3LevelCodes[]
CGB channel 3 waveform volumes.
Definition tables.c:165
void MusicTrack_HandleNote(u32 command, struct SoundPlayer *player, struct SoundTrack *track)
const s16 gSound_CgbFrequencySteps[]
Frequencies by note for CGB channels.
Definition tables.c:151
const u8 gSound_NoisePitchCodes[]
Noise channel pitches.
Definition tables.c:156
void AudioEngine_SuspendDirectSound(void)
Stops both FIFO transfers and clears their sample buffers, raising the work's lock until AudioEngine_...
Definition engine.c:213
void MusicPlayer_Tick(struct SoundPlayer *player)
void AudioEngine_ResumeDirectSound(void)
Restarts both FIFO transfers and releases the suspended-work lock.
Definition engine.c:232
u8 gMusicFadeRequested
s32 gSoundClipFlag
void Sound_TickDmaRestartTimer(void)
s32 gBuildStamp[]
The build stamp System_CopyBuildStamp copies to IWRAM at power-on: twelve digits and a zero word,...
u8 gEwram_Data1
A player, which plays one song: its header and status, its tracks, its tempo and fade.
A track of a playing song: the song commands it runs, its voice and notes, and the pitch,...
The sound driver's work: its lock, the mixer's rate and buffers, the PCM and CGB notes,...
The integer types, TRUE, UNUSED and the fixed-address macros.
signed int s32
Definition types.h:14
unsigned int u32
Definition types.h:15
signed short s16
Definition types.h:12
unsigned short u16
Definition types.h:13
unsigned char u8
Definition types.h:11