a couple au units

This commit is contained in:
z64a 2025-06-11 13:40:17 -04:00
parent b2796df912
commit c3a02ef17d
3 changed files with 20 additions and 17 deletions

View File

@ -107,8 +107,11 @@ typedef u8* WaveData;
#define MUS_QUEUE_SIZE 16
#define SFX_QUEUE_SIZE 16
#define AU_SEMITONE 100 // cents
#define AU_OCTAVE (12 * AU_SEMITONE)
// semitone pitch interval in cents
#define AU_SEMITONE_CENTS 100
// octave pitch interval in cents
#define AU_OCTAVE_CENTS (12 * AU_SEMITONE_CENTS)
#define ENV_VOL_MAX 0x80 // for 7-bit volumes, 128 (1 << 7) represents full volume
#define ENV_VOL_SHIFT 7 // Shift required to divide by 128 (normalize 7-bit volumes after a multiply)
@ -444,7 +447,7 @@ typedef union SeqArgs {
u8 value;
} TrackVolume;
struct { // cmd ED
s8 cent;
s8 semitone;
} InstrumentCoarseTune;
struct { // cmd EE
s8 cent;

View File

@ -1652,7 +1652,7 @@ void au_BGMCmd_EC_TrackVolume(BGMPlayer* player, BGMPlayerTrack* track) {
}
void au_BGMCmd_ED_InstrumentCoarseTune(BGMPlayer* player, BGMPlayerTrack* track) {
track->insCoarseDetune = player->seqCmdArgs.InstrumentCoarseTune.cent * 100;
track->insCoarseDetune = player->seqCmdArgs.InstrumentCoarseTune.semitone * AU_SEMITONE_CENTS;
}
void au_BGMCmd_EE_InstrumentFineTune(BGMPlayer* player, BGMPlayerTrack* track) {
@ -1720,7 +1720,7 @@ void au_BGMCmd_F5_UseInstrument(BGMPlayer* player, BGMPlayerTrack* track) {
track->insVolume = volume;
track->insPan = instrument->pan & 0x7F;
track->insReverb = instrument->reverb & 0x7F;
track->insCoarseDetune = instrument->coarseTune * 100;
track->insCoarseDetune = instrument->coarseTune * AU_SEMITONE_CENTS;
track->insFineDetune = instrument->fineTune;
track->changed.all |= 0x10101; // volume, pan, and reverb
}
@ -2014,10 +2014,10 @@ void au_bgm_set_playback_rate(BGMPlayer* player, f32 rate) {
}
void au_bgm_player_set_detune(BGMPlayer* player, s32 detune) {
if (detune > AU_OCTAVE) {
detune = AU_OCTAVE;
} else if (detune < -2 * AU_OCTAVE) {
detune = -2 * AU_OCTAVE;
if (detune > AU_OCTAVE_CENTS) {
detune = AU_OCTAVE_CENTS;
} else if (detune < -2 * AU_OCTAVE_CENTS) {
detune = -2 * AU_OCTAVE_CENTS;
}
player->detune = detune;

View File

@ -221,10 +221,10 @@ void snd_start_sound_with_shift(s32 soundID, u8 volume, u8 pan, s16 pitchShift)
pan = AU_PAN_MAX;
}
if (pitchShift > 2 * AU_OCTAVE) {
pitchShift = 2 * AU_OCTAVE;
} else if (pitchShift < -2 * AU_OCTAVE) {
pitchShift = -2 * AU_OCTAVE;
if (pitchShift > 2 * AU_OCTAVE_CENTS) {
pitchShift = 2 * AU_OCTAVE_CENTS;
} else if (pitchShift < -2 * AU_OCTAVE_CENTS) {
pitchShift = -2 * AU_OCTAVE_CENTS;
}
au_sfx_enqueue_event(soundManager, soundID, vol, pitchShift, pan);
@ -257,10 +257,10 @@ void snd_adjust_sound_with_shift(s32 soundID, u8 volume, u8 pan, s16 pitchShift)
pan = AU_PAN_MAX;
}
if (pitchShift > 2 * AU_OCTAVE) {
pitchShift = 2 * AU_OCTAVE;
} else if (pitchShift < -2 * AU_OCTAVE) {
pitchShift = -2 * AU_OCTAVE;
if (pitchShift > 2 * AU_OCTAVE_CENTS) {
pitchShift = 2 * AU_OCTAVE_CENTS;
} else if (pitchShift < -2 * AU_OCTAVE_CENTS) {
pitchShift = -2 * AU_OCTAVE_CENTS;
}
au_sfx_enqueue_event(soundManager, soundID | SOUND_ID_ADJUST, vol, pitchShift, pan);