mirror of
https://github.com/zeldaret/mm.git
synced 2026-06-12 21:44:40 -04:00
rename audio files (#1188)
This commit is contained in:
@@ -1,107 +0,0 @@
|
||||
#include "global.h"
|
||||
|
||||
//! Note that this is not the same as the original libultra
|
||||
//! osAiSetNextBuffer, see comments in the function
|
||||
|
||||
s32 osAiSetNextBuffer(void* buf, u32 size) {
|
||||
static u8 D_801D6010 = false;
|
||||
u32 bufAdjusted = (u32)buf;
|
||||
s32 status;
|
||||
|
||||
if (D_801D6010) {
|
||||
bufAdjusted = (u32)buf - 0x2000;
|
||||
}
|
||||
if ((((u32)buf + size) & 0x1FFF) == 0) {
|
||||
D_801D6010 = true;
|
||||
} else {
|
||||
D_801D6010 = false;
|
||||
}
|
||||
|
||||
// Originally a call to __osAiDeviceBusy
|
||||
status = HW_REG(AI_STATUS_REG, s32);
|
||||
if (status & AI_STATUS_AI_FULL) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
// OS_K0_TO_PHYSICAL replaces osVirtualToPhysical, this replacement
|
||||
// assumes that only KSEG0 addresses are given
|
||||
HW_REG(AI_DRAM_ADDR_REG, u32) = OS_K0_TO_PHYSICAL(bufAdjusted);
|
||||
HW_REG(AI_LEN_REG, u32) = size;
|
||||
return 0;
|
||||
}
|
||||
|
||||
//! Note that the remaining data and functions are unused and not part of the
|
||||
//! original libultra osAiSetNextBuffer
|
||||
|
||||
s16 D_801D6014[] = {
|
||||
19720, 18360, 17680, 16320, 14960, 13600, 12240, 10880, 9520, 0,
|
||||
};
|
||||
s8 D_801D6028[7][16] = {
|
||||
{ 0, 1, 2, 2, 1, 3, 4, 5, 6, 7, 8, 7, 6, 5, 4, 3 }, { 0, 1, 2, 3, 3, 2, 1, 4, 5, 6, 7, 8, 7, 6, 5, 4 },
|
||||
{ 0, 1, 2, 3, 4, 4, 3, 2, 1, 5, 6, 7, 8, 7, 6, 5 }, { 0, 1, 2, 3, 4, 5, 5, 4, 3, 2, 1, 6, 7, 8, 7, 6 },
|
||||
{ 0, 1, 2, 3, 4, 5, 6, 6, 5, 4, 3, 2, 1, 7, 8, 7 }, { 0, 1, 2, 3, 4, 5, 6, 7, 7, 6, 5, 4, 3, 2, 1, 8 },
|
||||
{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 7, 6, 5, 4, 3, 2, 1 },
|
||||
};
|
||||
s16 D_801D6098[7][17] = {
|
||||
{ 0, 268, 560, 834, 1126, 1418, 1692, 1966, 2240, 2514, 2718, 2922, 3196, 3470, 3744, 4018, 4292 },
|
||||
{ 0, 268, 560, 834, 1108, 1382, 1674, 1966, 2240, 2514, 2788, 2992, 3196, 3470, 3744, 4018, 4292 },
|
||||
{ 0, 268, 560, 834, 1108, 1382, 1656, 1930, 2222, 2514, 2788, 3062, 3266, 3470, 3744, 4018, 4292 },
|
||||
{ 0, 268, 560, 834, 1108, 1382, 1656, 1930, 2204, 2478, 2770, 3062, 3336, 3540, 3744, 4018, 4292 },
|
||||
{ 0, 268, 560, 834, 1108, 1382, 1656, 1930, 2222, 2514, 2752, 3026, 3318, 3610, 3814, 4018, 4292 },
|
||||
{ 0, 268, 560, 834, 1108, 1382, 1656, 1930, 2134, 2408, 2682, 2956, 3230, 3504, 3796, 4088, 4292 },
|
||||
{ 0, 268, 560, 834, 1108, 1382, 1656, 1930, 2134, 2338, 2612, 2886, 3163, 3434, 3708, 4000, 4292 },
|
||||
};
|
||||
s16* D_801D6188 = D_801D6098[0];
|
||||
s8* D_801D618C = D_801D6028[0];
|
||||
|
||||
// Unused
|
||||
void func_80194804(s32 index) {
|
||||
D_801D6188 = D_801D6098[index];
|
||||
D_801D618C = D_801D6028[index];
|
||||
}
|
||||
|
||||
// Only used below
|
||||
s16 func_80194840(s32 arg0) {
|
||||
s32 i;
|
||||
s32 j = 0;
|
||||
|
||||
for (i = 1; i < 16; i++) {
|
||||
if (arg0 < D_801D6188[i]) {
|
||||
break;
|
||||
}
|
||||
j++;
|
||||
}
|
||||
|
||||
if (i == 16) {
|
||||
return 0;
|
||||
} else {
|
||||
j = D_801D618C[j];
|
||||
return D_801D6014[j];
|
||||
}
|
||||
}
|
||||
|
||||
// Unused
|
||||
s32 func_801948B0(s32* arg0, s32* arg1) {
|
||||
s32 temp_v0;
|
||||
s32 phi_s0 = *arg0;
|
||||
s32 phi_s1 = *arg1;
|
||||
|
||||
while (true) {
|
||||
temp_v0 = func_80194840(phi_s0);
|
||||
if (temp_v0 == 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (phi_s1 < temp_v0) {
|
||||
break;
|
||||
}
|
||||
|
||||
phi_s1 -= temp_v0;
|
||||
phi_s0++;
|
||||
}
|
||||
|
||||
*arg0 = phi_s0;
|
||||
*arg1 = phi_s1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,15 +0,0 @@
|
||||
#include "global.h"
|
||||
|
||||
void Audio_InvalDCache(void* buf, size_t size) {
|
||||
OSIntMask prevMask = osSetIntMask(1);
|
||||
|
||||
osInvalDCache(buf, size);
|
||||
osSetIntMask(prevMask);
|
||||
}
|
||||
|
||||
void Audio_WritebackDCache(void* buf, size_t size) {
|
||||
OSIntMask prevMask = osSetIntMask(1);
|
||||
|
||||
osWritebackDCache(buf, size);
|
||||
osSetIntMask(prevMask);
|
||||
}
|
||||
@@ -1,341 +0,0 @@
|
||||
#include "global.h"
|
||||
|
||||
void AudioEffects_SequenceChannelProcessSound(SequenceChannel* channel, s32 recalculateVolume, s32 applyBend) {
|
||||
f32 channelVolume;
|
||||
f32 chanFreqScale;
|
||||
s32 i;
|
||||
|
||||
if (channel->changes.s.volume || recalculateVolume) {
|
||||
channelVolume = channel->volume * channel->volumeScale * channel->seqPlayer->appliedFadeVolume;
|
||||
if (channel->seqPlayer->muted && (channel->muteFlags & MUTE_FLAGS_SOFTEN)) {
|
||||
channelVolume = channel->seqPlayer->muteVolumeScale * channelVolume;
|
||||
}
|
||||
channel->appliedVolume = channelVolume * channelVolume;
|
||||
}
|
||||
|
||||
if (channel->changes.s.pan) {
|
||||
channel->pan = channel->newPan * channel->panChannelWeight;
|
||||
}
|
||||
|
||||
chanFreqScale = channel->freqScale;
|
||||
if (applyBend) {
|
||||
chanFreqScale *= channel->seqPlayer->bend;
|
||||
channel->changes.s.freqScale = true;
|
||||
}
|
||||
|
||||
for (i = 0; i < ARRAY_COUNT(channel->layers); i++) {
|
||||
SequenceLayer* layer = channel->layers[i];
|
||||
|
||||
if (layer != NULL && layer->enabled && layer->note != NULL) {
|
||||
if (layer->notePropertiesNeedInit) {
|
||||
layer->noteFreqScale = layer->freqScale * chanFreqScale;
|
||||
layer->noteVelocity = layer->velocitySquare2 * channel->appliedVolume;
|
||||
layer->notePan = (channel->pan + layer->pan * (0x80 - channel->panChannelWeight)) >> 7;
|
||||
layer->notePropertiesNeedInit = false;
|
||||
} else {
|
||||
if (channel->changes.s.freqScale) {
|
||||
layer->noteFreqScale = layer->freqScale * chanFreqScale;
|
||||
}
|
||||
if (channel->changes.s.volume || recalculateVolume) {
|
||||
layer->noteVelocity = layer->velocitySquare2 * channel->appliedVolume;
|
||||
}
|
||||
if (channel->changes.s.pan) {
|
||||
layer->notePan = (channel->pan + layer->pan * (0x80 - channel->panChannelWeight)) >> 7;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
channel->changes.asByte = 0;
|
||||
}
|
||||
|
||||
void AudioEffects_SequencePlayerProcessSound(SequencePlayer* seqPlayer) {
|
||||
s32 i;
|
||||
|
||||
if ((seqPlayer->fadeTimer != 0) && (seqPlayer->skipTicks == 0)) {
|
||||
seqPlayer->fadeVolume += seqPlayer->fadeVelocity;
|
||||
seqPlayer->recalculateVolume = true;
|
||||
|
||||
if (seqPlayer->fadeVolume > 1.0f) {
|
||||
seqPlayer->fadeVolume = 1.0f;
|
||||
}
|
||||
if (seqPlayer->fadeVolume < 0.0f) {
|
||||
seqPlayer->fadeVolume = 0.0f;
|
||||
}
|
||||
|
||||
seqPlayer->fadeTimer--;
|
||||
if ((seqPlayer->fadeTimer == 0) && (seqPlayer->state == SEQPLAYER_STATE_FADE_OUT)) {
|
||||
AudioSeq_SequencePlayerDisable(seqPlayer);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (seqPlayer->recalculateVolume) {
|
||||
seqPlayer->appliedFadeVolume = seqPlayer->fadeVolume * seqPlayer->fadeVolumeScale;
|
||||
}
|
||||
|
||||
for (i = 0; i < ARRAY_COUNT(seqPlayer->channels); i++) {
|
||||
if (seqPlayer->channels[i]->enabled == true) {
|
||||
AudioEffects_SequenceChannelProcessSound(seqPlayer->channels[i], seqPlayer->recalculateVolume,
|
||||
seqPlayer->applyBend);
|
||||
}
|
||||
}
|
||||
|
||||
seqPlayer->recalculateVolume = false;
|
||||
}
|
||||
|
||||
f32 AudioEffects_GetPortamentoFreqScale(Portamento* portamento) {
|
||||
u32 loResCur;
|
||||
f32 portamentoFreq;
|
||||
|
||||
portamento->cur += portamento->speed;
|
||||
loResCur = (portamento->cur >> 8) & 0xFF;
|
||||
|
||||
if (loResCur >= 127) {
|
||||
loResCur = 127;
|
||||
portamento->mode = 0;
|
||||
}
|
||||
|
||||
portamentoFreq = AUDIO_LERPIMP(1.0f, gBendPitchOneOctaveFrequencies[loResCur + 128], portamento->extent);
|
||||
|
||||
return portamentoFreq;
|
||||
}
|
||||
|
||||
s16 AudioEffects_GetVibratoPitchChange(VibratoState* vib) {
|
||||
s32 index;
|
||||
|
||||
vib->time += (s32)vib->rate;
|
||||
index = (vib->time >> 10) & 0x3F;
|
||||
return vib->curve[index];
|
||||
}
|
||||
|
||||
f32 AudioEffects_GetVibratoFreqScale(VibratoState* vib) {
|
||||
static f32 activeVibratoFreqScaleSum = 0.0f;
|
||||
static s32 activeVibratoCount = 0;
|
||||
f32 pitchChange;
|
||||
f32 depth;
|
||||
f32 invDepth;
|
||||
f32 result;
|
||||
f32 scaledDepth;
|
||||
VibratoSubStruct* subVib = vib->vibSubStruct;
|
||||
|
||||
if (vib->delay != 0) {
|
||||
vib->delay--;
|
||||
return 1.0f;
|
||||
}
|
||||
|
||||
if (subVib != NULL) {
|
||||
if (vib->depthChangeTimer) {
|
||||
if (vib->depthChangeTimer == 1) {
|
||||
vib->depth = (s32)subVib->vibratoDepthTarget;
|
||||
} else {
|
||||
vib->depth += ((s32)subVib->vibratoDepthTarget - vib->depth) / (s32)vib->depthChangeTimer;
|
||||
}
|
||||
|
||||
vib->depthChangeTimer--;
|
||||
} else if (subVib->vibratoDepthTarget != (s32)vib->depth) {
|
||||
if ((vib->depthChangeTimer = subVib->vibratoDepthChangeDelay) == 0) {
|
||||
vib->depth = (s32)subVib->vibratoDepthTarget;
|
||||
}
|
||||
}
|
||||
|
||||
if (vib->rateChangeTimer) {
|
||||
if (vib->rateChangeTimer == 1) {
|
||||
vib->rate = (s32)subVib->vibratoRateTarget;
|
||||
} else {
|
||||
vib->rate += ((s32)subVib->vibratoRateTarget - vib->rate) / (s32)vib->rateChangeTimer;
|
||||
}
|
||||
|
||||
vib->rateChangeTimer--;
|
||||
} else if (subVib->vibratoRateTarget != (s32)vib->rate) {
|
||||
if ((vib->rateChangeTimer = subVib->vibratoRateChangeDelay) == 0) {
|
||||
vib->rate = (s32)subVib->vibratoRateTarget;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (vib->depth == 0.0f) {
|
||||
return 1.0f;
|
||||
}
|
||||
|
||||
pitchChange = AudioEffects_GetVibratoPitchChange(vib) + 32768.0f;
|
||||
scaledDepth = vib->depth / 4096.0f;
|
||||
depth = scaledDepth + 1.0f;
|
||||
invDepth = 1.0f / depth;
|
||||
|
||||
// inverse linear interpolation
|
||||
result = 1.0f / ((depth - invDepth) * pitchChange / 65536.0f + invDepth);
|
||||
|
||||
activeVibratoFreqScaleSum += result;
|
||||
activeVibratoCount++;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void AudioEffects_NoteVibratoUpdate(Note* note) {
|
||||
if (note->playbackState.portamento.mode != 0) {
|
||||
note->playbackState.portamentoFreqScale = AudioEffects_GetPortamentoFreqScale(¬e->playbackState.portamento);
|
||||
}
|
||||
if (note->playbackState.vibratoState.active) {
|
||||
note->playbackState.vibratoFreqScale = AudioEffects_GetVibratoFreqScale(¬e->playbackState.vibratoState);
|
||||
}
|
||||
}
|
||||
|
||||
void AudioEffects_NoteVibratoInit(Note* note) {
|
||||
NotePlaybackState* playbackState = ¬e->playbackState;
|
||||
VibratoState* vib = &playbackState->vibratoState;
|
||||
VibratoSubStruct* subVib;
|
||||
|
||||
vib->active = true;
|
||||
vib->curve = gWaveSamples[2];
|
||||
|
||||
if (playbackState->parentLayer->unk_0A.s.bit_3 == 1) {
|
||||
vib->vibSubStruct = &playbackState->parentLayer->channel->vibrato;
|
||||
} else {
|
||||
vib->vibSubStruct = &playbackState->parentLayer->vibrato;
|
||||
}
|
||||
|
||||
subVib = vib->vibSubStruct;
|
||||
|
||||
if ((vib->depthChangeTimer = subVib->vibratoDepthChangeDelay) == 0) {
|
||||
vib->depth = (s32)subVib->vibratoDepthTarget;
|
||||
} else {
|
||||
vib->depth = (s32)subVib->vibratoDepthStart;
|
||||
}
|
||||
|
||||
if ((vib->rateChangeTimer = subVib->vibratoRateChangeDelay) == 0) {
|
||||
vib->rate = (s32)subVib->vibratoRateTarget;
|
||||
} else {
|
||||
vib->rate = (s32)subVib->vibratoRateStart;
|
||||
}
|
||||
|
||||
playbackState->vibratoFreqScale = 1.0f;
|
||||
vib->time = 0;
|
||||
vib->delay = subVib->vibratoDelay;
|
||||
}
|
||||
|
||||
void AudioEffects_NotePortamentoInit(Note* note) {
|
||||
note->playbackState.portamentoFreqScale = 1.0f;
|
||||
note->playbackState.portamento = note->playbackState.parentLayer->portamento;
|
||||
}
|
||||
|
||||
void AudioEffects_AdsrInit(AdsrState* adsr, EnvelopePoint* envelope, s16* volOut) {
|
||||
adsr->action.asByte = 0;
|
||||
adsr->delay = 0;
|
||||
adsr->envelope = envelope;
|
||||
adsr->sustain = 0.0f;
|
||||
adsr->current = 0.0f;
|
||||
adsr->velocity = 0.0f;
|
||||
// (An older versions of the audio engine used in Super Mario 64 did
|
||||
// adsr->volOut = volOut. That line and associated struct member were
|
||||
// removed, but the function parameter was forgotten and remains.)
|
||||
}
|
||||
|
||||
f32 AudioEffects_AdsrUpdate(AdsrState* adsr) {
|
||||
u8 state = adsr->action.s.state;
|
||||
|
||||
switch (state) {
|
||||
case ADSR_STATE_DISABLED:
|
||||
return 0.0f;
|
||||
|
||||
case ADSR_STATE_INITIAL:
|
||||
if (adsr->action.s.hang) {
|
||||
adsr->action.s.state = ADSR_STATE_HANG;
|
||||
break;
|
||||
}
|
||||
// fallthrough
|
||||
case ADSR_STATE_START_LOOP:
|
||||
adsr->envIndex = 0;
|
||||
adsr->action.s.state = ADSR_STATE_LOOP;
|
||||
// fallthrough
|
||||
retry:
|
||||
case ADSR_STATE_LOOP:
|
||||
adsr->delay = adsr->envelope[adsr->envIndex].delay;
|
||||
switch (adsr->delay) {
|
||||
case ADSR_DISABLE:
|
||||
adsr->action.s.state = ADSR_STATE_DISABLED;
|
||||
break;
|
||||
|
||||
case ADSR_HANG:
|
||||
adsr->action.s.state = ADSR_STATE_HANG;
|
||||
break;
|
||||
|
||||
case ADSR_GOTO:
|
||||
adsr->envIndex = adsr->envelope[adsr->envIndex].arg;
|
||||
goto retry;
|
||||
|
||||
case ADSR_RESTART:
|
||||
adsr->action.s.state = ADSR_STATE_INITIAL;
|
||||
break;
|
||||
|
||||
default:
|
||||
adsr->delay *= gAudioCtx.audioBufferParameters.updatesPerFrameScaled;
|
||||
if (adsr->delay == 0) {
|
||||
adsr->delay = 1;
|
||||
}
|
||||
adsr->target = adsr->envelope[adsr->envIndex].arg / 32767.0f;
|
||||
adsr->target = adsr->target * adsr->target;
|
||||
adsr->velocity = (adsr->target - adsr->current) / adsr->delay;
|
||||
adsr->action.s.state = ADSR_STATE_FADE;
|
||||
adsr->envIndex++;
|
||||
break;
|
||||
}
|
||||
if (adsr->action.s.state != ADSR_STATE_FADE) {
|
||||
break;
|
||||
}
|
||||
// fallthrough
|
||||
case ADSR_STATE_FADE:
|
||||
adsr->current += adsr->velocity;
|
||||
adsr->delay--;
|
||||
if (adsr->delay <= 0) {
|
||||
adsr->action.s.state = ADSR_STATE_LOOP;
|
||||
}
|
||||
// fallthrough
|
||||
case ADSR_STATE_HANG:
|
||||
break;
|
||||
|
||||
case ADSR_STATE_DECAY:
|
||||
case ADSR_STATE_RELEASE:
|
||||
adsr->current -= adsr->fadeOutVel;
|
||||
if (adsr->sustain != 0.0f && state == ADSR_STATE_DECAY) {
|
||||
if (adsr->current < adsr->sustain) {
|
||||
adsr->current = adsr->sustain;
|
||||
adsr->delay = 128;
|
||||
adsr->action.s.state = ADSR_STATE_SUSTAIN;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if (adsr->current < 0.00001f) {
|
||||
adsr->current = 0.0f;
|
||||
adsr->action.s.state = ADSR_STATE_DISABLED;
|
||||
}
|
||||
break;
|
||||
|
||||
case ADSR_STATE_SUSTAIN:
|
||||
adsr->delay--;
|
||||
if (adsr->delay == 0) {
|
||||
adsr->action.s.state = ADSR_STATE_RELEASE;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if (adsr->action.s.decay) {
|
||||
adsr->action.s.state = ADSR_STATE_DECAY;
|
||||
adsr->action.s.decay = false;
|
||||
}
|
||||
|
||||
if (adsr->action.s.release) {
|
||||
adsr->action.s.state = ADSR_STATE_RELEASE;
|
||||
adsr->action.s.release = false;
|
||||
}
|
||||
|
||||
if (adsr->current < 0.0f) {
|
||||
return 0.0f;
|
||||
}
|
||||
|
||||
if (adsr->current > 1.0f) {
|
||||
return 1.0f;
|
||||
}
|
||||
|
||||
return adsr->current;
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,184 +0,0 @@
|
||||
#include "global.h"
|
||||
|
||||
const s16 gAudioTatumInit[] = {
|
||||
0x1C00, // unused
|
||||
TATUMS_PER_BEAT, // gTatumsPerBeat
|
||||
};
|
||||
|
||||
// TODO: Extract from table?
|
||||
#define NUM_SOUNDFONTS 41
|
||||
#define SFX_SEQ_SIZE 0xC6A0
|
||||
#define AMBIENCE_SEQ_SIZE 0xFC0
|
||||
#define SOUNDFONT_0_SIZE 0x81C0
|
||||
#define SOUNDFONT_1_SIZE 0x36D0
|
||||
#define SOUNDFONT_2_SIZE 0xCE0
|
||||
|
||||
// Sizes of everything on the init pool
|
||||
#define AI_BUFFERS_SIZE (AIBUF_SIZE * ARRAY_COUNT(gAudioCtx.aiBuffers))
|
||||
#define SOUNDFONT_LIST_SIZE (NUM_SOUNDFONTS * sizeof(SoundFont))
|
||||
|
||||
// 0x19BD0
|
||||
#define PERMANENT_POOL_SIZE \
|
||||
(SFX_SEQ_SIZE + AMBIENCE_SEQ_SIZE + SOUNDFONT_0_SIZE + SOUNDFONT_1_SIZE + SOUNDFONT_2_SIZE + 0x430)
|
||||
|
||||
const AudioHeapInitSizes gAudioHeapInitSizes = {
|
||||
ALIGN16(sizeof(gAudioHeap) - 0x100), // audio heap size
|
||||
ALIGN16(PERMANENT_POOL_SIZE + AI_BUFFERS_SIZE + SOUNDFONT_LIST_SIZE + 0x40), // init pool size
|
||||
ALIGN16(PERMANENT_POOL_SIZE), // permanent pool size
|
||||
};
|
||||
|
||||
#define REVERB_INDEX_0_SETTINGS \
|
||||
{ 1, 0x30, 0x3000, 0, 0, 0x7FFF, 0x0000, 0x0000, REVERB_INDEX_NONE, 0x3000, 0, 0 }
|
||||
|
||||
ReverbSettings reverbSettings0[3] = {
|
||||
REVERB_INDEX_0_SETTINGS,
|
||||
{ 1, 0x20, 0x0800, 0, 0, 0x7FFF, 0x0000, 0x0000, REVERB_INDEX_NONE, 0x0000, 0, 0 },
|
||||
};
|
||||
|
||||
ReverbSettings reverbSettings1[3] = {
|
||||
REVERB_INDEX_0_SETTINGS,
|
||||
{ 1, 0x30, 0x1800, 0, 0, 0x7FFF, 0x0000, 0x0000, REVERB_INDEX_NONE, 0x0000, 11, 11 },
|
||||
};
|
||||
|
||||
ReverbSettings reverbSettings2[3] = {
|
||||
REVERB_INDEX_0_SETTINGS,
|
||||
{ 1, 0x38, 0x2800, 0, 0, 0x7FFF, 0x0000, 0x0000, REVERB_INDEX_NONE, 0x0000, 7, 7 },
|
||||
};
|
||||
|
||||
ReverbSettings reverbSettings3[3] = {
|
||||
REVERB_INDEX_0_SETTINGS,
|
||||
{ 1, 0x30, 0x6800, 0, 0, 0x7FFF, 0x1400, 0x1400, REVERB_INDEX_NONE, 0x3000, 6, 6 },
|
||||
{ 2, 0x50, 0x6000, 0, 0, 0x7FFF, 0xD000, 0x3000, REVERB_INDEX_NONE, 0x3000, 0, 0 },
|
||||
};
|
||||
|
||||
ReverbSettings reverbSettings4[3] = {
|
||||
REVERB_INDEX_0_SETTINGS,
|
||||
{ 1, 0x40, 0x5000, 0, 0, 0x7FFF, 0x1800, 0x1800, REVERB_INDEX_NONE, 0x3000, 7, 7 },
|
||||
};
|
||||
|
||||
ReverbSettings reverbSettings5[3] = {
|
||||
REVERB_INDEX_0_SETTINGS,
|
||||
{ 1, 0x40, 0x5C00, 0, 0, 0x7FFF, 0x2000, 0x2000, REVERB_INDEX_NONE, 0x3000, 4, 4 },
|
||||
};
|
||||
|
||||
ReverbSettings reverbSettings6[3] = {
|
||||
REVERB_INDEX_0_SETTINGS,
|
||||
{ 1, 0x30, 0x6000, 0, 0, 0x7FFF, 0x1000, 0x1000, REVERB_INDEX_NONE, 0x3000, 10, 10 },
|
||||
};
|
||||
|
||||
ReverbSettings reverbSettings7[3] = {
|
||||
REVERB_INDEX_0_SETTINGS,
|
||||
{ 1, 0x30, 0x6800, 0, 0, 0x7FFF, 0x1400, 0x1400, REVERB_INDEX_NONE, 0x3000, 6, 6 },
|
||||
};
|
||||
|
||||
ReverbSettings reverbSettings8[2] = {
|
||||
REVERB_INDEX_0_SETTINGS,
|
||||
{ 1, 0x50, 0x5000, 0, 0, 0x7FFF, 0xD000, 0x3000, REVERB_INDEX_NONE, 0x3000, 0, 0 },
|
||||
};
|
||||
|
||||
ReverbSettings reverbSettings9[3] = {
|
||||
REVERB_INDEX_0_SETTINGS,
|
||||
{ 1, 0x20, 0x0000, 0, 0, 0x7FFF, 0x0000, 0x0000, REVERB_INDEX_NONE, 0x0000, 0, 0 },
|
||||
};
|
||||
|
||||
ReverbSettings reverbSettingsA[3] = {
|
||||
REVERB_INDEX_0_SETTINGS,
|
||||
{ 1, 0x30, 0x1800, 0, 0, 0x7FFF, 0x0000, 0x0000, REVERB_INDEX_NONE, 0x0000, 11, 11 },
|
||||
};
|
||||
|
||||
ReverbSettings reverbSettingsB[3] = {
|
||||
REVERB_INDEX_0_SETTINGS,
|
||||
};
|
||||
|
||||
ReverbSettings reverbSettingsC[3] = {
|
||||
REVERB_INDEX_0_SETTINGS,
|
||||
{ 1, 0x40, 0x5000, 0, 0, 0x7FFF, 0x0000, 0x0000, REVERB_INDEX_NONE, 0x3000, 0, 0 },
|
||||
};
|
||||
|
||||
ReverbSettings reverbSettingsD[3] = {
|
||||
REVERB_INDEX_0_SETTINGS,
|
||||
{ 1, 0x30, 0x6800, 0, 0, 0x7FFF, 0x1400, 0x1400, REVERB_INDEX_NONE, 0x3000, 6, 6 },
|
||||
{ 2, 0x50, 0x6000, 0, 0, 0x7FFF, 0xD000, 0x3000, REVERB_INDEX_NONE, 0x3000, 0, 0 },
|
||||
};
|
||||
|
||||
ReverbSettings reverbSettingsE[3] = {
|
||||
REVERB_INDEX_0_SETTINGS,
|
||||
{ 1, 0x30, 0x1800, 0, 0, 0x7FFF, 0x0000, 0x0000, REVERB_INDEX_NONE, 0x0000, 11, 11 },
|
||||
{ 1, 0x40, 0x5000, 0, 0, 0x7FFF, 0x1800, 0x1800, REVERB_INDEX_NONE, 0x3000, 7, 7 },
|
||||
};
|
||||
|
||||
ReverbSettings reverbSettingsF[2] = {
|
||||
REVERB_INDEX_0_SETTINGS,
|
||||
{ 1, 0x50, 0x1800, 0, 0, 0x7FFF, 0x0000, 0x0000, REVERB_INDEX_NONE, 0x0000, 11, 11 },
|
||||
};
|
||||
|
||||
ReverbSettings* gReverbSettingsTable[] = {
|
||||
reverbSettings0, reverbSettings1, reverbSettings2, reverbSettings4, reverbSettings5,
|
||||
reverbSettings6, reverbSettings7, reverbSettings8, reverbSettings9, reverbSettings3,
|
||||
};
|
||||
|
||||
AudioSpec gAudioSpecs[21] = {
|
||||
/* 0x0 */
|
||||
{ 32000, 1, 24, 5, 0, 0, 2, reverbSettingsF, 0x500, 0x200, 0x7FFF, 0xAF0, 0x2D80, 0, 0x4100, 0x2D00, 0, 0,
|
||||
0xDC800 },
|
||||
/* 0x1 */
|
||||
{ 32000, 1, 24, 5, 0, 0, 2, reverbSettingsF, 0x500, 0x200, 0x7FFF, 0xAF0, 0x2D80, 0, 0x4100, 0x2D00, 0, 0,
|
||||
0xDC800 },
|
||||
/* 0x2 */
|
||||
{ 32000, 1, 24, 5, 0, 0, 2, reverbSettingsF, 0x500, 0x200, 0x7FFF, 0xAF0, 0x2D80, 0, 0x4100, 0x2D00, 0, 0,
|
||||
0xDC800 },
|
||||
/* 0x3 */
|
||||
{ 32000, 1, 24, 5, 0, 0, 2, reverbSettingsF, 0x500, 0x200, 0x7FFF, 0xAF0, 0x2D80, 0, 0x4100, 0x2D00, 0, 0,
|
||||
0xDC800 },
|
||||
/* 0x4 */
|
||||
{ 32000, 1, 24, 5, 0, 0, 2, reverbSettingsF, 0x500, 0x200, 0x7FFF, 0xAF0, 0x2D80, 0, 0x4100, 0x2D00, 0, 0,
|
||||
0xDC800 },
|
||||
/* 0x5 */
|
||||
{ 32000, 1, 24, 5, 0, 0, 2, reverbSettingsF, 0x500, 0x200, 0x7FFF, 0xAF0, 0x2D80, 0, 0x4100, 0x2D00, 0, 0,
|
||||
0xDC800 },
|
||||
/* 0x6 */
|
||||
{ 32000, 1, 24, 5, 0, 0, 2, reverbSettingsF, 0x500, 0x200, 0x7FFF, 0xAF0, 0x2D80, 0, 0x4100, 0x2D00, 0, 0,
|
||||
0xDC800 },
|
||||
/* 0x7 */
|
||||
{ 32000, 1, 24, 5, 0, 0, 2, reverbSettingsF, 0x500, 0x200, 0x7FFF, 0xAF0, 0x2D80, 0, 0x4100, 0x2D00, 0, 0,
|
||||
0xDC800 },
|
||||
/* 0x8 */
|
||||
{ 32000, 1, 24, 5, 0, 0, 2, reverbSettingsF, 0x500, 0x200, 0x7FFF, 0xAF0, 0x2D80, 0, 0x4100, 0x2D00, 0, 0,
|
||||
0xDC800 },
|
||||
/* 0x9 */
|
||||
{ 32000, 1, 24, 5, 0, 0, 2, reverbSettingsF, 0x500, 0x200, 0x7FFF, 0xAF0, 0x2D80, 0, 0x4100, 0x2D00, 0, 0,
|
||||
0xDC800 },
|
||||
/* 0xA */
|
||||
{ 32000, 1, 28, 3, 0, 0, 2, reverbSettingsA, 0x500, 0x200, 0x7FFF, 0xAF0, 0x2D80, 0, 0x2800, 0x2D00, 0, 0,
|
||||
0xDC800 },
|
||||
/* 0xB */
|
||||
{ 32000, 1, 28, 3, 0, 0, 2, reverbSettingsA, 0x500, 0x200, 0x7FFF, 0xAF0, 0x2D80, 0, 0x4100, 0x2D00, 0, 0,
|
||||
0xDC800 },
|
||||
/* 0xC */
|
||||
{ 32000, 1, 28, 5, 0, 0, 2, reverbSettingsA, 0x500, 0x200, 0x7FFF, 0xAF0, 0x2D80, 0, 0x4100, 0x2D00, 0, 0,
|
||||
0xCC800 },
|
||||
/* 0xD */
|
||||
{ 32000, 1, 24, 5, 0, 0, 3, reverbSettingsD, 0x500, 0x200, 0x7FFF, 0xAF0, 0x2D80, 0, 0x4100, 0x2D00, 0, 0,
|
||||
0xDC800 },
|
||||
/* 0xE */
|
||||
{ 32000, 1, 24, 5, 0, 0, 3, reverbSettingsE, 0x500, 0x200, 0x7FFF, 0xAF0, 0x2D80, 0, 0x4100, 0x2D00, 0, 0,
|
||||
0xDC800 },
|
||||
/* 0xF */
|
||||
{ 32000, 1, 24, 5, 0, 0, 2, reverbSettingsF, 0x500, 0x200, 0x7FFF, 0xAF0, 0x2D80, 0, 0x4000, 0x2D00, 0, 0,
|
||||
0xDC800 },
|
||||
/* 0x10 */
|
||||
{ 32000, 1, 22, 5, 0, 0, 2, reverbSettings0, 0x500, 0x200, 0x7FFF, 0xAF0, 0x2D80, 0, 0x4100, 0x2D00, 0, 0,
|
||||
0xDC800 },
|
||||
/* 0x11 */
|
||||
{ 32000, 1, 22, 5, 0, 0, 2, reverbSettings8, 0x500, 0x200, 0x7FFF, 0xAF0, 0x2D80, 0, 0x4100, 0x2D00, 0, 0,
|
||||
0xDC800 },
|
||||
/* 0x12 */
|
||||
{ 32000, 1, 16, 5, 0, 0, 2, reverbSettings0, 0x500, 0x200, 0x7FFF, 0xAF0, 0x2D80, 0, 0x4100, 0x2D00, 0, 0,
|
||||
0xDC800 },
|
||||
/* 0x13 */
|
||||
{ 22050, 1, 24, 5, 0, 0, 2, reverbSettings0, 0x500, 0x200, 0x7FFF, 0xAF0, 0x2D80, 0, 0x4100, 0x2D00, 0, 0,
|
||||
0xDC800 },
|
||||
/* 0x14 */
|
||||
{ 32000, 1, 24, 5, 0, 0, 2, reverbSettings2, 0x500, 0x200, 0x7FFF, 0xAF0, 0x2D80, 0, 0x3600, 0x2600, 0, 0,
|
||||
0xDC800 },
|
||||
};
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -1,41 +0,0 @@
|
||||
#include "global.h"
|
||||
|
||||
#define DEFINE_SFX(_0, importance, distParam, randParam, flags2, flags1) \
|
||||
{ importance, flags2, \
|
||||
((((distParam) << SFX_PARAM_DIST_RANGE_SHIFT) & SFX_PARAM_DIST_RANGE_MASK) | \
|
||||
(((randParam) << SFX_PARAM_RAND_FREQ_RAISE_SHIFT) & SFX_PARAM_RAND_FREQ_RAISE_MASK) | (flags1)) },
|
||||
|
||||
SfxParams sEnemyBankParams[] = {
|
||||
#include "tables/sfx/enemybank_table.h"
|
||||
};
|
||||
|
||||
SfxParams sPlayerBankParams[] = {
|
||||
#include "tables/sfx/playerbank_table.h"
|
||||
};
|
||||
|
||||
SfxParams sItemBankParams[] = {
|
||||
#include "tables/sfx/itembank_table.h"
|
||||
};
|
||||
|
||||
SfxParams sEnvBankParams[] = {
|
||||
#include "tables/sfx/environmentbank_table.h"
|
||||
};
|
||||
|
||||
SfxParams sSystemBankParams[] = {
|
||||
#include "tables/sfx/systembank_table.h"
|
||||
};
|
||||
|
||||
SfxParams sOcarinaBankParams[] = {
|
||||
#include "tables/sfx/ocarinabank_table.h"
|
||||
};
|
||||
|
||||
SfxParams sVoiceBankParams[] = {
|
||||
#include "tables/sfx/voicebank_table.h"
|
||||
};
|
||||
|
||||
#undef DEFINE_SFX
|
||||
|
||||
SfxParams* gSfxParams[7] = {
|
||||
sPlayerBankParams, sItemBankParams, sEnvBankParams, sEnemyBankParams,
|
||||
sSystemBankParams, sOcarinaBankParams, sVoiceBankParams,
|
||||
};
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,977 +0,0 @@
|
||||
/**
|
||||
* @file audio_thread.c
|
||||
*
|
||||
* Top-level file that coordinates all audio code on the audio thread.
|
||||
*/
|
||||
#include "global.h"
|
||||
|
||||
AudioTask* AudioThread_UpdateImpl(void);
|
||||
void AudioThread_SetFadeOutTimer(s32 seqPlayerIndex, s32 fadeTimer);
|
||||
void AudioThread_SetFadeInTimer(s32 seqPlayerIndex, s32 fadeTimer);
|
||||
void AudioThread_ProcessCmds(u32 msg);
|
||||
void AudioThread_ProcessSeqPlayerCmd(SequencePlayer* seqPlayer, AudioCmd* cmd);
|
||||
void AudioThread_ProcessChannelCmd(SequenceChannel* channel, AudioCmd* cmd);
|
||||
s32 AudioThread_GetSamplePos(s32 seqPlayerIndex, s32 channelIndex, s32 layerIndex, s32* loopEnd, s32* samplePosInt);
|
||||
s32 AudioThread_CountAndReleaseNotes(s32 flags);
|
||||
|
||||
AudioTask* AudioThread_Update(void) {
|
||||
return AudioThread_UpdateImpl();
|
||||
}
|
||||
|
||||
AudioTask* AudioThread_UpdateImpl(void) {
|
||||
static AudioTask* sWaitingAudioTask = NULL;
|
||||
u32 numSamplesRemainingInAi;
|
||||
s32 numAbiCmds;
|
||||
s32 pad;
|
||||
s32 j;
|
||||
s32 dmaCount;
|
||||
s16* curAiBuffer;
|
||||
OSTask_t* task;
|
||||
s32 index;
|
||||
u32 msg;
|
||||
s32 validCount;
|
||||
s32 i;
|
||||
|
||||
gAudioCtx.totalTaskCount++;
|
||||
if ((gAudioCtx.totalTaskCount % gAudioCtx.audioBufferParameters.specUnk4) != 0) {
|
||||
if (gAudioCustomUpdateFunction != NULL) {
|
||||
gAudioCustomUpdateFunction();
|
||||
}
|
||||
|
||||
if (((gAudioCtx.totalTaskCount % gAudioCtx.audioBufferParameters.specUnk4) + 1) ==
|
||||
gAudioCtx.audioBufferParameters.specUnk4) {
|
||||
return sWaitingAudioTask;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
osSendMesg(gAudioCtx.taskStartQueueP, gAudioCtx.totalTaskCount, OS_MESG_NOBLOCK);
|
||||
gAudioCtx.rspTaskIndex ^= 1;
|
||||
gAudioCtx.curAiBufferIndex++;
|
||||
gAudioCtx.curAiBufferIndex %= 3;
|
||||
index = (gAudioCtx.curAiBufferIndex + 1) % 3;
|
||||
|
||||
// Division converts size to numSamples: 2 channels (left/right) * 2 bytes per sample
|
||||
numSamplesRemainingInAi = osAiGetLength() / (2 * SAMPLE_SIZE);
|
||||
|
||||
if (gAudioCtx.resetTimer < 16) {
|
||||
if (gAudioCtx.numSamplesPerFrame[index] != 0) {
|
||||
osAiSetNextBuffer(gAudioCtx.aiBuffers[index], 2 * gAudioCtx.numSamplesPerFrame[index] * (s32)SAMPLE_SIZE);
|
||||
if (gAudioCtx.aiBuffers[index]) {}
|
||||
if (gAudioCtx.numSamplesPerFrame[index]) {}
|
||||
}
|
||||
}
|
||||
|
||||
if (gAudioCustomUpdateFunction != NULL) {
|
||||
gAudioCustomUpdateFunction();
|
||||
}
|
||||
|
||||
dmaCount = gAudioCtx.curAudioFrameDmaCount;
|
||||
for (i = 0; i < gAudioCtx.curAudioFrameDmaCount; i++) {
|
||||
if (osRecvMesg(&gAudioCtx.curAudioFrameDmaQueue, NULL, OS_MESG_NOBLOCK) == 0) {
|
||||
dmaCount--;
|
||||
}
|
||||
}
|
||||
|
||||
if (dmaCount != 0) {
|
||||
for (i = 0; i < dmaCount; i++) {
|
||||
osRecvMesg(&gAudioCtx.curAudioFrameDmaQueue, NULL, OS_MESG_BLOCK);
|
||||
}
|
||||
}
|
||||
|
||||
validCount = gAudioCtx.curAudioFrameDmaQueue.validCount;
|
||||
if (validCount != 0) {
|
||||
for (i = 0; i < validCount; i++) {
|
||||
osRecvMesg(&gAudioCtx.curAudioFrameDmaQueue, NULL, OS_MESG_NOBLOCK);
|
||||
}
|
||||
}
|
||||
|
||||
gAudioCtx.curAudioFrameDmaCount = 0;
|
||||
AudioLoad_DecreaseSampleDmaTtls();
|
||||
AudioLoad_ProcessLoads(gAudioCtx.resetStatus);
|
||||
AudioLoad_ProcessScriptLoads();
|
||||
|
||||
if (gAudioCtx.resetStatus != 0) {
|
||||
if (AudioHeap_ResetStep() == 0) {
|
||||
if (gAudioCtx.resetStatus == 0) {
|
||||
osSendMesg(gAudioCtx.audioResetQueueP, gAudioCtx.specId, OS_MESG_NOBLOCK);
|
||||
}
|
||||
|
||||
sWaitingAudioTask = NULL;
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
if (gAudioCtx.resetTimer > 16) {
|
||||
return NULL;
|
||||
}
|
||||
if (gAudioCtx.resetTimer != 0) {
|
||||
gAudioCtx.resetTimer++;
|
||||
}
|
||||
|
||||
gAudioCtx.curTask = &gAudioCtx.rspTask[gAudioCtx.rspTaskIndex];
|
||||
gAudioCtx.curAbiCmdBuf = gAudioCtx.abiCmdBufs[gAudioCtx.rspTaskIndex];
|
||||
|
||||
index = gAudioCtx.curAiBufferIndex;
|
||||
curAiBuffer = gAudioCtx.aiBuffers[index];
|
||||
|
||||
gAudioCtx.numSamplesPerFrame[index] =
|
||||
(s16)((((gAudioCtx.audioBufferParameters.numSamplesPerFrameTarget - numSamplesRemainingInAi) +
|
||||
(8 * SAMPLES_PER_FRAME)) &
|
||||
~0xF) +
|
||||
(1 * SAMPLES_PER_FRAME));
|
||||
|
||||
// Clamp numSamplesPerFrame between numSamplesPerFrameMin and numSamplesPerFrameMax
|
||||
if (gAudioCtx.numSamplesPerFrame[index] < gAudioCtx.audioBufferParameters.numSamplesPerFrameMin) {
|
||||
gAudioCtx.numSamplesPerFrame[index] = gAudioCtx.audioBufferParameters.numSamplesPerFrameMin;
|
||||
}
|
||||
if (gAudioCtx.numSamplesPerFrame[index] > gAudioCtx.audioBufferParameters.numSamplesPerFrameMax) {
|
||||
gAudioCtx.numSamplesPerFrame[index] = gAudioCtx.audioBufferParameters.numSamplesPerFrameMax;
|
||||
}
|
||||
|
||||
j = 0;
|
||||
if (gAudioCtx.resetStatus == 0) {
|
||||
// msg = 0000RREE R = read pos, E = End Pos
|
||||
while (osRecvMesg(gAudioCtx.threadCmdProcQueueP, (OSMesg*)&msg, OS_MESG_NOBLOCK) != -1) {
|
||||
//! FAKE:
|
||||
if (1) {}
|
||||
AudioThread_ProcessCmds(msg);
|
||||
j++;
|
||||
}
|
||||
if ((j == 0) && gAudioCtx.threadCmdQueueFinished) {
|
||||
AudioThread_ScheduleProcessCmds();
|
||||
}
|
||||
}
|
||||
|
||||
if (gAudioSPDataPtr == (u64*)gAudioCtx.curAbiCmdBuf) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
gAudioCtx.curAbiCmdBuf =
|
||||
AudioSynth_Update(gAudioCtx.curAbiCmdBuf, &numAbiCmds, curAiBuffer, gAudioCtx.numSamplesPerFrame[index]);
|
||||
|
||||
// Update audioRandom to the next random number
|
||||
gAudioCtx.audioRandom = (gAudioCtx.audioRandom + gAudioCtx.totalTaskCount) * osGetCount();
|
||||
gAudioCtx.audioRandom = gAudioCtx.audioRandom + gAudioCtx.aiBuffers[index][gAudioCtx.totalTaskCount & 0xFF];
|
||||
|
||||
// gWaveSamples[8] interprets compiled assembly code as s16 samples as a way to generate sound with noise.
|
||||
// Start with the address of AudioThread_Update(), and offset it by a random number between 0 - 0xFFF0
|
||||
// Use the resulting address as the starting address to interpret an array of samples i.e. `s16 samples[]`
|
||||
gWaveSamples[8] = (s16*)((u8*)AudioThread_Update + (gAudioCtx.audioRandom & 0xFFF0));
|
||||
|
||||
index = gAudioCtx.rspTaskIndex;
|
||||
gAudioCtx.curTask->taskQueue = NULL;
|
||||
gAudioCtx.curTask->unk_44 = NULL;
|
||||
|
||||
task = &gAudioCtx.curTask->task.t;
|
||||
task->type = M_AUDTASK;
|
||||
task->flags = 0;
|
||||
task->ucodeBoot = aspMainTextStart;
|
||||
task->ucodeBootSize = SP_UCODE_SIZE;
|
||||
task->ucodeDataSize = ((aspMainDataEnd - aspMainDataStart) * sizeof(u64)) - 1;
|
||||
task->ucode = aspMainTextStart;
|
||||
task->ucodeData = aspMainDataStart;
|
||||
task->ucodeSize = SP_UCODE_SIZE;
|
||||
task->dramStack = (u64*)D_801D6200;
|
||||
task->dramStackSize = 0;
|
||||
task->outputBuff = NULL;
|
||||
task->outputBuffSize = NULL;
|
||||
if (1) {}
|
||||
task->dataPtr = (u64*)gAudioCtx.abiCmdBufs[index];
|
||||
task->dataSize = numAbiCmds * sizeof(Acmd);
|
||||
task->yieldDataPtr = NULL;
|
||||
task->yieldDataSize = 0;
|
||||
|
||||
if (gAudioCtx.numAbiCmdsMax < numAbiCmds) {
|
||||
gAudioCtx.numAbiCmdsMax = numAbiCmds;
|
||||
}
|
||||
|
||||
if (gAudioCtx.audioBufferParameters.specUnk4 == 1) {
|
||||
return gAudioCtx.curTask;
|
||||
} else {
|
||||
sWaitingAudioTask = gAudioCtx.curTask;
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
void AudioThread_ProcessGlobalCmd(AudioCmd* cmd) {
|
||||
s32 i;
|
||||
s32 pad;
|
||||
|
||||
switch (cmd->op) {
|
||||
case AUDIOCMD_OP_GLOBAL_SYNC_LOAD_SEQ_PARTS:
|
||||
AudioLoad_SyncLoadSeqParts(cmd->arg1, cmd->arg2, cmd->asInt, &gAudioCtx.externalLoadQueue);
|
||||
break;
|
||||
|
||||
case AUDIOCMD_OP_GLOBAL_INIT_SEQPLAYER:
|
||||
AudioLoad_SyncInitSeqPlayer(cmd->arg0, cmd->arg1, cmd->arg2);
|
||||
AudioThread_SetFadeInTimer(cmd->arg0, cmd->asInt);
|
||||
break;
|
||||
|
||||
case AUDIOCMD_OP_GLOBAL_INIT_SEQPLAYER_SKIP_TICKS:
|
||||
AudioLoad_SyncInitSeqPlayerSkipTicks(cmd->arg0, cmd->arg1, cmd->asInt);
|
||||
AudioThread_SetFadeInTimer(cmd->arg0, 500);
|
||||
AudioSeq_SkipForwardSequence(&gAudioCtx.seqPlayers[cmd->arg0]);
|
||||
break;
|
||||
|
||||
case AUDIOCMD_OP_GLOBAL_DISABLE_SEQPLAYER:
|
||||
if (gAudioCtx.seqPlayers[cmd->arg0].enabled) {
|
||||
if (cmd->asInt == 0) {
|
||||
AudioSeq_SequencePlayerDisableAsFinished(&gAudioCtx.seqPlayers[cmd->arg0]);
|
||||
} else {
|
||||
AudioThread_SetFadeOutTimer(cmd->arg0, cmd->asInt);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case AUDIOCMD_OP_GLOBAL_SET_SOUND_MODE:
|
||||
gAudioCtx.soundMode = cmd->asInt;
|
||||
break;
|
||||
|
||||
case AUDIOCMD_OP_GLOBAL_MUTE:
|
||||
if (cmd->arg0 == AUDIOCMD_ALL_SEQPLAYERS) {
|
||||
for (i = 0; i < gAudioCtx.audioBufferParameters.numSequencePlayers; i++) {
|
||||
gAudioCtx.seqPlayers[i].muted = true;
|
||||
gAudioCtx.seqPlayers[i].recalculateVolume = true;
|
||||
}
|
||||
} else {
|
||||
gAudioCtx.seqPlayers[cmd->arg0].muted = true;
|
||||
gAudioCtx.seqPlayers[cmd->arg0].recalculateVolume = true;
|
||||
}
|
||||
break;
|
||||
|
||||
case AUDIOCMD_OP_GLOBAL_UNMUTE:
|
||||
if (cmd->asInt == true) {
|
||||
for (i = 0; i < gAudioCtx.numNotes; i++) {
|
||||
Note* note = &gAudioCtx.notes[i];
|
||||
NoteSampleState* noteSampleState = ¬e->sampleState;
|
||||
|
||||
if (noteSampleState->bitField0.enabled && (note->playbackState.status == PLAYBACK_STATUS_0) &&
|
||||
(note->playbackState.parentLayer->channel->muteFlags & MUTE_FLAGS_STOP_SAMPLES)) {
|
||||
noteSampleState->bitField0.finished = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (cmd->arg0 == AUDIOCMD_ALL_SEQPLAYERS) {
|
||||
for (i = 0; i < gAudioCtx.audioBufferParameters.numSequencePlayers; i++) {
|
||||
gAudioCtx.seqPlayers[i].muted = false;
|
||||
gAudioCtx.seqPlayers[i].recalculateVolume = true;
|
||||
}
|
||||
} else {
|
||||
gAudioCtx.seqPlayers[cmd->arg0].muted = false;
|
||||
gAudioCtx.seqPlayers[cmd->arg0].recalculateVolume = true;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case AUDIOCMD_OP_GLOBAL_SYNC_LOAD_INSTRUMENT:
|
||||
AudioLoad_SyncLoadInstrument(cmd->arg0, cmd->arg1, cmd->arg2);
|
||||
break;
|
||||
|
||||
case AUDIOCMD_OP_GLOBAL_ASYNC_LOAD_SAMPLE_BANK:
|
||||
AudioLoad_AsyncLoadSampleBank(cmd->arg0, cmd->arg1, cmd->arg2, &gAudioCtx.externalLoadQueue);
|
||||
break;
|
||||
|
||||
case AUDIOCMD_OP_GLOBAL_ASYNC_LOAD_FONT:
|
||||
AudioLoad_AsyncLoadFont(cmd->arg0, cmd->arg1, cmd->arg2, &gAudioCtx.externalLoadQueue);
|
||||
break;
|
||||
|
||||
case AUDIOCMD_OP_GLOBAL_ASYNC_LOAD_SEQ:
|
||||
AudioLoad_AsyncLoadSeq(cmd->arg0, cmd->arg1, cmd->arg2, &gAudioCtx.externalLoadQueue);
|
||||
break;
|
||||
|
||||
case AUDIOCMD_OP_GLOBAL_DISCARD_SEQ_FONTS:
|
||||
AudioLoad_DiscardSeqFonts(cmd->arg1);
|
||||
break;
|
||||
|
||||
case AUDIOCMD_OP_GLOBAL_SET_CHANNEL_MASK:
|
||||
gAudioCtx.threadCmdChannelMask[cmd->arg0] = cmd->asUShort;
|
||||
break;
|
||||
|
||||
case AUDIOCMD_OP_GLOBAL_RESET_AUDIO_HEAP:
|
||||
gAudioCtx.resetStatus = 5;
|
||||
gAudioCtx.specId = cmd->asUInt;
|
||||
break;
|
||||
|
||||
case AUDIOCMD_OP_GLOBAL_SET_CUSTOM_UPDATE_FUNCTION:
|
||||
gAudioCustomUpdateFunction = cmd->asUInt;
|
||||
break;
|
||||
|
||||
case AUDIOCMD_OP_GLOBAL_SET_CUSTOM_FUNCTION:
|
||||
if (cmd->arg2 == AUDIO_CUSTOM_FUNCTION_REVERB) {
|
||||
gAudioCustomReverbFunction = cmd->asUInt;
|
||||
} else if (cmd->arg2 == AUDIO_CUSTOM_FUNCTION_SYNTH) {
|
||||
gAudioCustomSynthFunction = cmd->asUInt;
|
||||
} else {
|
||||
gAudioCtx.customSeqFunctions[cmd->arg2] = cmd->asUInt;
|
||||
}
|
||||
break;
|
||||
|
||||
case AUDIOCMD_OP_GLOBAL_SET_DRUM_FONT:
|
||||
case AUDIOCMD_OP_GLOBAL_SET_SFX_FONT:
|
||||
case AUDIOCMD_OP_GLOBAL_SET_INSTRUMENT_FONT:
|
||||
if (AudioPlayback_SetFontInstrument(cmd->op - AUDIOCMD_OP_GLOBAL_SET_DRUM_FONT, cmd->arg1, cmd->arg2,
|
||||
cmd->asInt)) {}
|
||||
break;
|
||||
|
||||
case AUDIOCMD_OP_GLOBAL_DISABLE_ALL_SEQPLAYERS: {
|
||||
u32 flags = cmd->asUInt;
|
||||
|
||||
if (flags == AUDIO_NOTE_RELEASE) {
|
||||
for (i = 0; i < gAudioCtx.audioBufferParameters.numSequencePlayers; i++) {
|
||||
if (gAudioCtx.seqPlayers[i].enabled) {
|
||||
AudioSeq_SequencePlayerDisableAsFinished(&gAudioCtx.seqPlayers[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
AudioThread_CountAndReleaseNotes(flags);
|
||||
break;
|
||||
}
|
||||
|
||||
case AUDIOCMD_OP_GLOBAL_POP_PERSISTENT_CACHE:
|
||||
AudioHeap_PopPersistentCache(cmd->asInt);
|
||||
break;
|
||||
|
||||
case AUDIOCMD_OP_GLOBAL_E5:
|
||||
func_8018FA60(cmd->arg0, cmd->arg1, cmd->arg2, cmd->asInt);
|
||||
break;
|
||||
|
||||
case AUDIOCMD_OP_GLOBAL_SET_REVERB_DATA:
|
||||
AudioHeap_SetReverbData(cmd->arg1, cmd->arg0, cmd->asInt, false);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void AudioThread_SetFadeOutTimer(s32 seqPlayerIndex, s32 fadeTimer) {
|
||||
SequencePlayer* seqPlayer = &gAudioCtx.seqPlayers[seqPlayerIndex];
|
||||
|
||||
if (fadeTimer == 0) {
|
||||
fadeTimer = 1;
|
||||
}
|
||||
|
||||
seqPlayer->fadeVelocity = -(seqPlayer->fadeVolume / fadeTimer);
|
||||
seqPlayer->state = SEQPLAYER_STATE_FADE_OUT;
|
||||
seqPlayer->fadeTimer = fadeTimer;
|
||||
}
|
||||
|
||||
void AudioThread_SetFadeInTimer(s32 seqPlayerIndex, s32 fadeTimer) {
|
||||
SequencePlayer* seqPlayer;
|
||||
|
||||
if (fadeTimer != 0) {
|
||||
seqPlayer = &gAudioCtx.seqPlayers[seqPlayerIndex];
|
||||
seqPlayer->state = SEQPLAYER_STATE_FADE_IN;
|
||||
seqPlayer->storedFadeTimer = fadeTimer;
|
||||
seqPlayer->fadeTimer = fadeTimer;
|
||||
seqPlayer->fadeVolume = 0.0f;
|
||||
seqPlayer->fadeVelocity = 0.0f;
|
||||
}
|
||||
}
|
||||
|
||||
void AudioThread_InitMesgQueuesInternal(void) {
|
||||
gAudioCtx.threadCmdWritePos = 0;
|
||||
gAudioCtx.threadCmdReadPos = 0;
|
||||
gAudioCtx.threadCmdQueueFinished = false;
|
||||
|
||||
gAudioCtx.taskStartQueueP = &gAudioCtx.taskStartQueue;
|
||||
gAudioCtx.threadCmdProcQueueP = &gAudioCtx.threadCmdProcQueue;
|
||||
gAudioCtx.audioResetQueueP = &gAudioCtx.audioResetQueue;
|
||||
|
||||
osCreateMesgQueue(gAudioCtx.taskStartQueueP, gAudioCtx.taskStartMsgs, ARRAY_COUNT(gAudioCtx.taskStartMsgs));
|
||||
osCreateMesgQueue(gAudioCtx.threadCmdProcQueueP, gAudioCtx.threadCmdProcMsgBuf,
|
||||
ARRAY_COUNT(gAudioCtx.threadCmdProcMsgBuf));
|
||||
osCreateMesgQueue(gAudioCtx.audioResetQueueP, gAudioCtx.audioResetMesgs, ARRAY_COUNT(gAudioCtx.audioResetMesgs));
|
||||
}
|
||||
|
||||
void AudioThread_QueueCmd(u32 opArgs, void** data) {
|
||||
AudioCmd* cmd = &gAudioCtx.threadCmdBuf[gAudioCtx.threadCmdWritePos & 0xFF];
|
||||
|
||||
cmd->opArgs = opArgs;
|
||||
cmd->data = *data;
|
||||
|
||||
gAudioCtx.threadCmdWritePos++;
|
||||
|
||||
if (gAudioCtx.threadCmdWritePos == gAudioCtx.threadCmdReadPos) {
|
||||
gAudioCtx.threadCmdWritePos--;
|
||||
}
|
||||
}
|
||||
|
||||
void AudioThread_QueueCmdF32(u32 opArgs, f32 data) {
|
||||
AudioThread_QueueCmd(opArgs, (void**)&data);
|
||||
}
|
||||
|
||||
void AudioThread_QueueCmdS32(u32 opArgs, s32 data) {
|
||||
AudioThread_QueueCmd(opArgs, (void**)&data);
|
||||
}
|
||||
|
||||
void AudioThread_QueueCmdS8(u32 opArgs, s8 data) {
|
||||
u32 uData = data << 0x18;
|
||||
|
||||
AudioThread_QueueCmd(opArgs, (void**)&uData);
|
||||
}
|
||||
|
||||
void AudioThread_QueueCmdU16(u32 opArgs, u16 data) {
|
||||
u32 uData = data << 0x10;
|
||||
|
||||
AudioThread_QueueCmd(opArgs, (void**)&uData);
|
||||
}
|
||||
|
||||
s32 AudioThread_ScheduleProcessCmds(void) {
|
||||
static s32 sMaxWriteReadDiff = 0;
|
||||
s32 ret;
|
||||
|
||||
if (sMaxWriteReadDiff < (u8)((gAudioCtx.threadCmdWritePos - gAudioCtx.threadCmdReadPos) + 0x100)) {
|
||||
sMaxWriteReadDiff = (u8)((gAudioCtx.threadCmdWritePos - gAudioCtx.threadCmdReadPos) + 0x100);
|
||||
}
|
||||
|
||||
ret = osSendMesg(gAudioCtx.threadCmdProcQueueP,
|
||||
(void*)(((gAudioCtx.threadCmdReadPos & 0xFF) << 8) | (gAudioCtx.threadCmdWritePos & 0xFF)),
|
||||
OS_MESG_NOBLOCK);
|
||||
if (ret != -1) {
|
||||
gAudioCtx.threadCmdReadPos = gAudioCtx.threadCmdWritePos;
|
||||
ret = 0;
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
void AudioThread_ResetCmdQueue(void) {
|
||||
gAudioCtx.threadCmdQueueFinished = false;
|
||||
gAudioCtx.threadCmdReadPos = gAudioCtx.threadCmdWritePos;
|
||||
}
|
||||
|
||||
void AudioThread_ProcessCmd(AudioCmd* cmd) {
|
||||
SequencePlayer* seqPlayer;
|
||||
u16 threadCmdChannelMask;
|
||||
s32 channelIndex;
|
||||
|
||||
if ((cmd->op & 0xF0) >= 0xE0) {
|
||||
AudioThread_ProcessGlobalCmd(cmd);
|
||||
return;
|
||||
}
|
||||
|
||||
if (cmd->arg0 < gAudioCtx.audioBufferParameters.numSequencePlayers) {
|
||||
seqPlayer = &gAudioCtx.seqPlayers[cmd->arg0];
|
||||
if (cmd->op & 0x80) {
|
||||
AudioThread_ProcessGlobalCmd(cmd);
|
||||
return;
|
||||
}
|
||||
|
||||
if (cmd->op & 0x40) {
|
||||
AudioThread_ProcessSeqPlayerCmd(seqPlayer, cmd);
|
||||
return;
|
||||
}
|
||||
|
||||
if (cmd->arg1 < SEQ_NUM_CHANNELS) {
|
||||
AudioThread_ProcessChannelCmd(seqPlayer->channels[cmd->arg1], cmd);
|
||||
return;
|
||||
}
|
||||
|
||||
if (cmd->arg1 == AUDIOCMD_ALL_CHANNELS) {
|
||||
threadCmdChannelMask = gAudioCtx.threadCmdChannelMask[cmd->arg0];
|
||||
for (channelIndex = 0; channelIndex < SEQ_NUM_CHANNELS; channelIndex++) {
|
||||
if (threadCmdChannelMask & 1) {
|
||||
AudioThread_ProcessChannelCmd(seqPlayer->channels[channelIndex], cmd);
|
||||
}
|
||||
threadCmdChannelMask = threadCmdChannelMask >> 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void AudioThread_ProcessCmds(u32 msg) {
|
||||
static u8 sCurCmdRdPos = 0;
|
||||
AudioCmd* cmd;
|
||||
u8 endPos;
|
||||
|
||||
if (!gAudioCtx.threadCmdQueueFinished) {
|
||||
sCurCmdRdPos = msg >> 8;
|
||||
}
|
||||
|
||||
while (true) {
|
||||
endPos = msg & 0xFF;
|
||||
if (sCurCmdRdPos == endPos) {
|
||||
gAudioCtx.threadCmdQueueFinished = false;
|
||||
break;
|
||||
}
|
||||
|
||||
cmd = &gAudioCtx.threadCmdBuf[sCurCmdRdPos++ & 0xFF];
|
||||
if (cmd->op == AUDIOCMD_OP_GLOBAL_STOP_AUDIOCMDS) {
|
||||
gAudioCtx.threadCmdQueueFinished = true;
|
||||
break;
|
||||
}
|
||||
|
||||
AudioThread_ProcessCmd(cmd);
|
||||
cmd->op = AUDIOCMD_OP_NOOP;
|
||||
}
|
||||
}
|
||||
|
||||
u32 AudioThread_GetExternalLoadQueueMsg(u32* retMsg) {
|
||||
u32 msg;
|
||||
|
||||
if (osRecvMesg(&gAudioCtx.externalLoadQueue, (OSMesg*)&msg, OS_MESG_NOBLOCK) == -1) {
|
||||
*retMsg = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
*retMsg = msg & 0xFFFFFF;
|
||||
return msg >> 0x18;
|
||||
}
|
||||
|
||||
u8* AudioThread_GetFontsForSequence(s32 seqId, u32* outNumFonts) {
|
||||
return AudioLoad_GetFontsForSequence(seqId, outNumFonts);
|
||||
}
|
||||
|
||||
void AudioThread_GetSampleBankIdsOfFont(s32 fontId, u32* sampleBankId1, u32* sampleBankId2) {
|
||||
*sampleBankId1 = gAudioCtx.soundFontList[fontId].sampleBankId1;
|
||||
*sampleBankId2 = gAudioCtx.soundFontList[fontId].sampleBankId2;
|
||||
}
|
||||
|
||||
s32 func_80193C5C(void) {
|
||||
s32 pad;
|
||||
s32 specId;
|
||||
|
||||
if (osRecvMesg(gAudioCtx.audioResetQueueP, (OSMesg*)&specId, OS_MESG_NOBLOCK) == -1) {
|
||||
return 0;
|
||||
} else if (gAudioCtx.specId != specId) {
|
||||
return -1;
|
||||
} else {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
void AudioThread_WaitForAudioResetQueueP(void) {
|
||||
// macro?
|
||||
// clang-format off
|
||||
s32 chk = -1; s32 msg; do {} while (osRecvMesg(gAudioCtx.audioResetQueueP, (OSMesg*)&msg, OS_MESG_NOBLOCK) != chk);
|
||||
// clang-format on
|
||||
}
|
||||
|
||||
s32 AudioThread_ResetAudioHeap(s32 specId) {
|
||||
s32 resetStatus;
|
||||
OSMesg msg;
|
||||
s32 pad;
|
||||
|
||||
AudioThread_WaitForAudioResetQueueP();
|
||||
resetStatus = gAudioCtx.resetStatus;
|
||||
if (resetStatus != 0) {
|
||||
AudioThread_ResetCmdQueue();
|
||||
if (gAudioCtx.specId == specId) {
|
||||
return -2;
|
||||
} else if (resetStatus > 2) {
|
||||
gAudioCtx.specId = specId;
|
||||
return -3;
|
||||
} else {
|
||||
osRecvMesg(gAudioCtx.audioResetQueueP, &msg, OS_MESG_BLOCK);
|
||||
}
|
||||
}
|
||||
|
||||
AudioThread_WaitForAudioResetQueueP();
|
||||
AUDIOCMD_GLOBAL_RESET_AUDIO_HEAP(specId);
|
||||
|
||||
return AudioThread_ScheduleProcessCmds();
|
||||
}
|
||||
|
||||
void AudioThread_PreNMIInternal(void) {
|
||||
gAudioCtx.resetTimer = 1;
|
||||
if (gAudioCtxInitalized) {
|
||||
AudioThread_ResetAudioHeap(0);
|
||||
gAudioCtx.resetStatus = 0;
|
||||
}
|
||||
}
|
||||
|
||||
// Unused
|
||||
s8 AudioThread_GetChannelIO(s32 seqPlayerIndex, s32 channelIndex, s32 ioPort) {
|
||||
SequencePlayer* seqPlayer = &gAudioCtx.seqPlayers[seqPlayerIndex];
|
||||
SequenceChannel* channel;
|
||||
|
||||
if (seqPlayer->enabled) {
|
||||
channel = seqPlayer->channels[channelIndex];
|
||||
return channel->seqScriptIO[ioPort];
|
||||
} else {
|
||||
return SEQ_IO_VAL_NONE;
|
||||
}
|
||||
}
|
||||
|
||||
// Unused
|
||||
s8 AudioThread_GetSeqPlayerIO(s32 seqPlayerIndex, s32 ioPort) {
|
||||
return gAudioCtx.seqPlayers[seqPlayerIndex].seqScriptIO[ioPort];
|
||||
}
|
||||
|
||||
// Unused
|
||||
void AudioThread_InitExternalPool(void* addr, size_t size) {
|
||||
AudioHeap_InitPool(&gAudioCtx.externalPool, addr, size);
|
||||
}
|
||||
|
||||
// Unused
|
||||
void AudioThread_ResetExternalPool(void) {
|
||||
gAudioCtx.externalPool.startAddr = NULL;
|
||||
}
|
||||
|
||||
void AudioThread_ProcessSeqPlayerCmd(SequencePlayer* seqPlayer, AudioCmd* cmd) {
|
||||
f32 fadeVolume;
|
||||
|
||||
switch (cmd->op) {
|
||||
case AUDIOCMD_OP_SEQPLAYER_FADE_VOLUME_SCALE:
|
||||
if (seqPlayer->fadeVolumeScale != cmd->asFloat) {
|
||||
seqPlayer->fadeVolumeScale = cmd->asFloat;
|
||||
seqPlayer->recalculateVolume = true;
|
||||
}
|
||||
break;
|
||||
|
||||
case AUDIOCMD_OP_SEQPLAYER_SET_TEMPO:
|
||||
seqPlayer->tempo = cmd->asInt * TATUMS_PER_BEAT;
|
||||
break;
|
||||
|
||||
case AUDIOCMD_OP_SEQPLAYER_CHANGE_TEMPO:
|
||||
seqPlayer->tempoChange = cmd->asInt * TATUMS_PER_BEAT;
|
||||
break;
|
||||
|
||||
case AUDIOCMD_OP_SEQPLAYER_CHANGE_TEMPO_TICKS:
|
||||
seqPlayer->tempoChange = cmd->asInt;
|
||||
break;
|
||||
|
||||
case AUDIOCMD_OP_SEQPLAYER_SET_TRANSPOSITION:
|
||||
seqPlayer->transposition = cmd->asSbyte;
|
||||
break;
|
||||
|
||||
case AUDIOCMD_OP_SEQPLAYER_SET_IO:
|
||||
seqPlayer->seqScriptIO[cmd->arg2] = cmd->asSbyte;
|
||||
break;
|
||||
|
||||
case AUDIOCMD_OP_SEQPLAYER_FADE_TO_SET_VOLUME:
|
||||
fadeVolume = (s32)cmd->arg1 / 127.0f;
|
||||
goto apply_fade;
|
||||
|
||||
case AUDIOCMD_OP_SEQPLAYER_FADE_TO_SCALED_VOLUME:
|
||||
fadeVolume = ((s32)cmd->arg1 / 100.0f) * seqPlayer->fadeVolume;
|
||||
apply_fade:
|
||||
if (seqPlayer->state != SEQPLAYER_STATE_FADE_OUT) {
|
||||
seqPlayer->volume = seqPlayer->fadeVolume;
|
||||
if (cmd->asInt == 0) {
|
||||
seqPlayer->fadeVolume = fadeVolume;
|
||||
} else {
|
||||
s32 fadeTimer = cmd->asInt;
|
||||
|
||||
seqPlayer->state = SEQPLAYER_STATE_0;
|
||||
seqPlayer->fadeTimer = fadeTimer;
|
||||
seqPlayer->fadeVelocity = (fadeVolume - seqPlayer->fadeVolume) / fadeTimer;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case AUDIOCMD_OP_SEQPLAYER_RESET_VOLUME:
|
||||
if (seqPlayer->state != SEQPLAYER_STATE_FADE_OUT) {
|
||||
if (cmd->asInt == 0) {
|
||||
seqPlayer->fadeVolume = seqPlayer->volume;
|
||||
} else {
|
||||
s32 fadeTimer = cmd->asInt;
|
||||
|
||||
seqPlayer->state = SEQPLAYER_STATE_0;
|
||||
seqPlayer->fadeTimer = fadeTimer;
|
||||
seqPlayer->fadeVelocity = (seqPlayer->volume - seqPlayer->fadeVolume) / fadeTimer;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case AUDIOCMD_OP_SEQPLAYER_SET_BEND:
|
||||
seqPlayer->bend = cmd->asFloat;
|
||||
if (seqPlayer->bend == 1.0f) {
|
||||
seqPlayer->applyBend = false;
|
||||
} else {
|
||||
seqPlayer->applyBend = true;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void AudioThread_ProcessChannelCmd(SequenceChannel* channel, AudioCmd* cmd) {
|
||||
u8 filterCutoff;
|
||||
|
||||
switch (cmd->op) {
|
||||
case AUDIOCMD_OP_CHANNEL_SET_VOL_SCALE:
|
||||
if (channel->volumeScale != cmd->asFloat) {
|
||||
channel->volumeScale = cmd->asFloat;
|
||||
channel->changes.s.volume = true;
|
||||
}
|
||||
break;
|
||||
|
||||
case AUDIOCMD_OP_CHANNEL_SET_VOL:
|
||||
if (channel->volume != cmd->asFloat) {
|
||||
channel->volume = cmd->asFloat;
|
||||
channel->changes.s.volume = true;
|
||||
}
|
||||
break;
|
||||
|
||||
case AUDIOCMD_OP_CHANNEL_SET_PAN:
|
||||
if (channel->newPan != cmd->asSbyte) {
|
||||
channel->newPan = cmd->asSbyte;
|
||||
channel->changes.s.pan = true;
|
||||
}
|
||||
break;
|
||||
|
||||
case AUDIOCMD_OP_CHANNEL_SET_PAN_WEIGHT:
|
||||
if (channel->newPan != cmd->asSbyte) {
|
||||
channel->panChannelWeight = cmd->asSbyte;
|
||||
channel->changes.s.pan = true;
|
||||
}
|
||||
break;
|
||||
|
||||
case AUDIOCMD_OP_CHANNEL_SET_FREQ_SCALE:
|
||||
if (channel->freqScale != cmd->asFloat) {
|
||||
channel->freqScale = cmd->asFloat;
|
||||
channel->changes.s.freqScale = true;
|
||||
}
|
||||
break;
|
||||
|
||||
case AUDIOCMD_OP_CHANNEL_SET_REVERB_VOLUME:
|
||||
if (channel->targetReverbVol != cmd->asSbyte) {
|
||||
channel->targetReverbVol = cmd->asSbyte;
|
||||
}
|
||||
break;
|
||||
|
||||
case AUDIOCMD_OP_CHANNEL_SET_REVERB_INDEX:
|
||||
if (channel->reverbIndex != cmd->asSbyte) {
|
||||
channel->reverbIndex = cmd->asSbyte;
|
||||
}
|
||||
break;
|
||||
|
||||
case AUDIOCMD_OP_CHANNEL_SET_SURROUND_EFFECT_INDEX:
|
||||
channel->surroundEffectIndex = cmd->asSbyte;
|
||||
break;
|
||||
|
||||
case AUDIOCMD_OP_CHANNEL_SET_IO:
|
||||
if (cmd->arg2 < ARRAY_COUNT(channel->seqScriptIO)) {
|
||||
channel->seqScriptIO[cmd->arg2] = cmd->asSbyte;
|
||||
}
|
||||
break;
|
||||
|
||||
case AUDIOCMD_OP_CHANNEL_SET_MUTE:
|
||||
channel->muted = cmd->asSbyte;
|
||||
break;
|
||||
|
||||
case AUDIOCMD_OP_CHANNEL_SET_MUTE_FLAGS:
|
||||
channel->muteFlags = cmd->asSbyte;
|
||||
break;
|
||||
|
||||
case AUDIOCMD_OP_CHANNEL_SET_VIBRATO_DEPTH:
|
||||
channel->vibrato.vibratoDepthTarget = cmd->asUbyte * 8;
|
||||
channel->vibrato.vibratoDepthChangeDelay = 1;
|
||||
break;
|
||||
|
||||
case AUDIOCMD_OP_CHANNEL_SET_VIBRATO_RATE:
|
||||
channel->vibrato.vibratoRateTarget = cmd->asUbyte * 32;
|
||||
channel->vibrato.vibratoRateChangeDelay = 1;
|
||||
break;
|
||||
|
||||
case AUDIOCMD_OP_CHANNEL_SET_COMB_FILTER_SIZE:
|
||||
channel->combFilterSize = cmd->asUbyte;
|
||||
break;
|
||||
|
||||
case AUDIOCMD_OP_CHANNEL_SET_COMB_FILTER_GAIN:
|
||||
channel->combFilterGain = cmd->asUShort;
|
||||
break;
|
||||
|
||||
case AUDIOCMD_OP_CHANNEL_SET_STEREO:
|
||||
channel->stereoData.asByte = cmd->asUbyte;
|
||||
break;
|
||||
|
||||
case AUDIOCMD_OP_CHANNEL_SET_SET_START_POS:
|
||||
channel->startSamplePos = cmd->asInt;
|
||||
break;
|
||||
|
||||
case AUDIOCMD_OP_CHANNEL_SET_SFX_STATE:
|
||||
channel->sfxState = cmd->asUInt;
|
||||
break;
|
||||
|
||||
case AUDIOCMD_OP_CHANNEL_SET_FILTER:
|
||||
filterCutoff = cmd->arg2;
|
||||
if (cmd->asUInt != 0) {
|
||||
channel->filter = cmd->asUInt;
|
||||
}
|
||||
if (channel->filter != NULL) {
|
||||
AudioHeap_LoadFilter(channel->filter, filterCutoff >> 4, filterCutoff & 0xF);
|
||||
}
|
||||
break;
|
||||
|
||||
case AUDIOCMD_OP_CHANNEL_SET_GAIN:
|
||||
channel->gain = cmd->asUbyte;
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Call an audio-thread command that has no code to process it. Unused.
|
||||
*/
|
||||
void AudioThread_Noop1Cmd(s32 arg0, s32 arg1, s32 arg2) {
|
||||
AUDIOCMD_GLOBAL_NOOP_1(arg0, arg1, arg2, 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Call an audio-thread command that has no code to process it. Unused.
|
||||
*/
|
||||
void AudioThread_Noop1CmdZeroed(void) {
|
||||
AUDIOCMD_GLOBAL_NOOP_1(0, 0, 0, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Call an audio-thread command that has no code to process it. Unused.
|
||||
*/
|
||||
void AudioThread_Noop2Cmd(u32 arg0, s32 arg1) {
|
||||
AUDIOCMD_GLOBAL_NOOP_2(0, 0, arg1, arg0);
|
||||
}
|
||||
|
||||
// Unused
|
||||
void AudioThread_WaitForAudioTask(void) {
|
||||
osRecvMesg(gAudioCtx.taskStartQueueP, NULL, OS_MESG_NOBLOCK);
|
||||
osRecvMesg(gAudioCtx.taskStartQueueP, NULL, OS_MESG_BLOCK);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the number of s16-samples from the start of the sample to the current sample position.
|
||||
* Unused
|
||||
*/
|
||||
s32 AudioThread_GetSamplePosFromStart(s32 seqPlayerIndex, s32 channelIndex, s32 layerIndex) {
|
||||
s32 pad;
|
||||
s32 loopEnd;
|
||||
s32 samplePosInt;
|
||||
|
||||
if (!AudioThread_GetSamplePos(seqPlayerIndex, channelIndex, layerIndex, &loopEnd, &samplePosInt)) {
|
||||
return 0;
|
||||
}
|
||||
return samplePosInt;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the number of s16-samples from the current sample position to the end of the sample.
|
||||
* Unused
|
||||
*/
|
||||
s32 AudioThread_GetSamplePosUntilEnd(s32 seqPlayerIndex, s32 channelIndex, s32 layerIndex) {
|
||||
s32 pad;
|
||||
s32 loopEnd;
|
||||
s32 samplePosInt;
|
||||
|
||||
if (!AudioThread_GetSamplePos(seqPlayerIndex, channelIndex, layerIndex, &loopEnd, &samplePosInt)) {
|
||||
return 0;
|
||||
}
|
||||
return loopEnd - samplePosInt;
|
||||
}
|
||||
|
||||
// Only used in unused functions
|
||||
s32 AudioThread_GetSamplePos(s32 seqPlayerIndex, s32 channelIndex, s32 layerIndex, s32* loopEnd, s32* samplePosInt) {
|
||||
SequencePlayer* seqPlayer = &gAudioCtx.seqPlayers[seqPlayerIndex];
|
||||
SequenceLayer* layer;
|
||||
Note* note;
|
||||
TunedSample* tunedSample;
|
||||
|
||||
if (seqPlayer->enabled && seqPlayer->channels[channelIndex]->enabled) {
|
||||
layer = seqPlayer->channels[channelIndex]->layers[layerIndex];
|
||||
if (layer == NULL) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (layer->enabled) {
|
||||
if (layer->note == NULL) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!layer->bit3) {
|
||||
return false;
|
||||
}
|
||||
|
||||
note = layer->note;
|
||||
if (layer == note->playbackState.parentLayer) {
|
||||
|
||||
if (note->sampleState.bitField1.isSyntheticWave == true) {
|
||||
return false;
|
||||
}
|
||||
|
||||
tunedSample = note->sampleState.tunedSample;
|
||||
if (tunedSample == NULL) {
|
||||
return false;
|
||||
}
|
||||
*loopEnd = tunedSample->sample->loop->loopEnd;
|
||||
*samplePosInt = note->synthesisState.samplePosInt;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
s32 AudioThread_GetEnabledNotesCount(void) {
|
||||
return AudioThread_CountAndReleaseNotes(0);
|
||||
}
|
||||
|
||||
s32 AudioThread_GetEnabledSampledNotesCount(void) {
|
||||
return AudioThread_CountAndReleaseNotes(AUDIO_NOTE_SAMPLE_NOTES);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param flags 0: count notes. 1: release all notes. 2: count sample notes 3: release sample notes
|
||||
* @return s32 number of notes
|
||||
*/
|
||||
s32 AudioThread_CountAndReleaseNotes(s32 flags) {
|
||||
s32 noteCount;
|
||||
NotePlaybackState* playbackState;
|
||||
NoteSampleState* noteSampleState;
|
||||
s32 i;
|
||||
Note* note;
|
||||
TunedSample* tunedSample;
|
||||
|
||||
noteCount = 0;
|
||||
for (i = 0; i < gAudioCtx.numNotes; i++) {
|
||||
note = &gAudioCtx.notes[i];
|
||||
playbackState = ¬e->playbackState;
|
||||
if (note->sampleState.bitField0.enabled) {
|
||||
noteSampleState = ¬e->sampleState;
|
||||
if (playbackState->adsr.action.s.state != ADSR_STATE_DISABLED) {
|
||||
if (flags >= AUDIO_NOTE_SAMPLE_NOTES) {
|
||||
tunedSample = noteSampleState->tunedSample;
|
||||
if ((tunedSample == NULL) || noteSampleState->bitField1.isSyntheticWave) {
|
||||
continue;
|
||||
}
|
||||
if (tunedSample->sample->medium == MEDIUM_RAM) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
noteCount++;
|
||||
if ((flags & AUDIO_NOTE_RELEASE) == AUDIO_NOTE_RELEASE) {
|
||||
playbackState->adsr.fadeOutVel = gAudioCtx.audioBufferParameters.updatesPerFrameInv;
|
||||
playbackState->adsr.action.s.release = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return noteCount;
|
||||
}
|
||||
|
||||
u32 AudioThread_NextRandom(void) {
|
||||
static u32 sAudioRandom = 0x12345678;
|
||||
static u32 sAudioOsCount = 0x11111111;
|
||||
u32 count = osGetCount();
|
||||
|
||||
sAudioRandom = (gAudioCtx.totalTaskCount + sAudioRandom + count) * (gAudioCtx.audioRandom + 0x1234567);
|
||||
sAudioRandom = (sAudioRandom & 1) + (sAudioRandom * 2) + sAudioOsCount;
|
||||
sAudioOsCount = count;
|
||||
|
||||
return sAudioRandom;
|
||||
}
|
||||
|
||||
void AudioThread_InitMesgQueues(void) {
|
||||
AudioThread_InitMesgQueuesInternal();
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,17 +0,0 @@
|
||||
#include "global.h"
|
||||
|
||||
#pragma GLOBAL_ASM("asm/non_matchings/code/code_801A4EB0/func_801A4EB0.s")
|
||||
|
||||
#pragma GLOBAL_ASM("asm/non_matchings/code/code_801A4EB0/func_801A4EB8.s")
|
||||
|
||||
#pragma GLOBAL_ASM("asm/non_matchings/code/code_801A4EB0/func_801A4FD8.s")
|
||||
|
||||
#pragma GLOBAL_ASM("asm/non_matchings/code/code_801A4EB0/func_801A5080.s")
|
||||
|
||||
#pragma GLOBAL_ASM("asm/non_matchings/code/code_801A4EB0/func_801A50C0.s")
|
||||
|
||||
#pragma GLOBAL_ASM("asm/non_matchings/code/code_801A4EB0/func_801A5100.s")
|
||||
|
||||
#pragma GLOBAL_ASM("asm/non_matchings/code/code_801A4EB0/func_801A510C.s")
|
||||
|
||||
#pragma GLOBAL_ASM("asm/non_matchings/code/code_801A4EB0/func_801A5118.s")
|
||||
@@ -1,42 +0,0 @@
|
||||
#include "global.h"
|
||||
|
||||
#pragma GLOBAL_ASM("asm/non_matchings/code/code_801A51F0/D_801E0EC0.s")
|
||||
|
||||
UNK_TYPE func_801A51F0(UNK_TYPE arg0) {
|
||||
switch (arg0) {
|
||||
case 1:
|
||||
case 4:
|
||||
case 5:
|
||||
case 11:
|
||||
case 13:
|
||||
case 14:
|
||||
case 15:
|
||||
return -1;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
#pragma GLOBAL_ASM("asm/non_matchings/code/code_801A51F0/func_801A5228.s")
|
||||
|
||||
#pragma GLOBAL_ASM("asm/non_matchings/code/code_801A51F0/func_801A5390.s")
|
||||
|
||||
#pragma GLOBAL_ASM("asm/non_matchings/code/code_801A51F0/func_801A53DC.s")
|
||||
|
||||
#pragma GLOBAL_ASM("asm/non_matchings/code/code_801A51F0/func_801A53E8.s")
|
||||
|
||||
#pragma GLOBAL_ASM("asm/non_matchings/code/code_801A51F0/func_801A541C.s")
|
||||
|
||||
#pragma GLOBAL_ASM("asm/non_matchings/code/code_801A51F0/func_801A5488.s")
|
||||
|
||||
#pragma GLOBAL_ASM("asm/non_matchings/code/code_801A51F0/func_801A54C4.s")
|
||||
|
||||
#pragma GLOBAL_ASM("asm/non_matchings/code/code_801A51F0/func_801A54D0.s")
|
||||
|
||||
#pragma GLOBAL_ASM("asm/non_matchings/code/code_801A51F0/func_801A5680.s")
|
||||
|
||||
#pragma GLOBAL_ASM("asm/non_matchings/code/code_801A51F0/func_801A5808.s")
|
||||
|
||||
#pragma GLOBAL_ASM("asm/non_matchings/code/code_801A51F0/func_801A5A10.s")
|
||||
|
||||
#pragma GLOBAL_ASM("asm/non_matchings/code/code_801A51F0/func_801A5A1C.s")
|
||||
@@ -1,944 +0,0 @@
|
||||
#include "global.h"
|
||||
|
||||
typedef struct {
|
||||
/* 0x00 */ u16 sfxId;
|
||||
/* 0x02 */ u8 token;
|
||||
/* 0x04 */ s8* reverbAdd;
|
||||
/* 0x08 */ Vec3f* pos;
|
||||
/* 0x0C */ f32* freqScale;
|
||||
/* 0x10 */ f32* volume;
|
||||
} SfxRequest; // size = 0x14
|
||||
|
||||
typedef struct {
|
||||
/* 0x0 */ f32 value;
|
||||
/* 0x4 */ f32 target;
|
||||
/* 0x8 */ f32 step;
|
||||
/* 0xC */ u16 remainingFrames;
|
||||
} SfxBankLerp; // size = 0x10
|
||||
|
||||
typedef enum {
|
||||
/* 0 */ SFX_RM_REQ_BY_BANK,
|
||||
/* 1 */ SFX_RM_REQ_BY_POS_AND_BANK,
|
||||
/* 2 */ SFX_RM_REQ_BY_POS,
|
||||
/* 3 */ SFX_RM_REQ_BY_POS_AND_ID,
|
||||
/* 4 */ SFX_RM_REQ_BY_TOKEN_AND_ID,
|
||||
/* 5 */ SFX_RM_REQ_BY_ID
|
||||
} SfxRemoveRequest;
|
||||
|
||||
SfxBankEntry sSfxPlayerBank[9];
|
||||
SfxBankEntry sSfxItemBank[12];
|
||||
SfxBankEntry sSfxEnvironmentBank[32];
|
||||
SfxBankEntry sSfxEnemyBank[20];
|
||||
SfxBankEntry sSfxSystemBank[8];
|
||||
SfxBankEntry sSfxOcarinaBank[3];
|
||||
SfxBankEntry sSfxVoiceBank[5];
|
||||
SfxRequest sSfxRequests[0x100];
|
||||
u8 sSfxBankListEnd[7];
|
||||
u8 sSfxBankFreeListStart[7];
|
||||
u8 sSfxBankUnused[7];
|
||||
ActiveSfx gActiveSfx[7][3];
|
||||
u8 sCurSfxPlayerChannelIndex;
|
||||
u8 gSfxBankMuted[7];
|
||||
SfxBankLerp sSfxBankLerp[7];
|
||||
|
||||
// sSfxRequests ring buffer endpoints. read index <= write index, wrapping around mod 256.
|
||||
u8 sSfxRequestWriteIndex = 0;
|
||||
u8 sSfxRequestReadIndex = 0;
|
||||
|
||||
/**
|
||||
* Array of pointers to arrays of SfxBankEntry of sizes: 9, 12, 32, 20, 8, 3, 5
|
||||
*
|
||||
* 0 : Player Bank size 9
|
||||
* 1 : Item Bank size 12
|
||||
* 2 : Environment Bank size 32
|
||||
* 3 : Enemy Bank size 20
|
||||
* 4 : System Bank size 8
|
||||
* 5 : Ocarina Bank size 3
|
||||
* 6 : Voice Bank size 5
|
||||
*/
|
||||
SfxBankEntry* gSfxBanks[7] = {
|
||||
sSfxPlayerBank, sSfxItemBank, sSfxEnvironmentBank, sSfxEnemyBank, sSfxSystemBank, sSfxOcarinaBank, sSfxVoiceBank,
|
||||
};
|
||||
|
||||
u8 sSfxBankSizes[ARRAY_COUNT(gSfxBanks)] = {
|
||||
ARRAY_COUNT(sSfxPlayerBank), ARRAY_COUNT(sSfxItemBank), ARRAY_COUNT(sSfxEnvironmentBank),
|
||||
ARRAY_COUNT(sSfxEnemyBank), ARRAY_COUNT(sSfxSystemBank), ARRAY_COUNT(sSfxOcarinaBank),
|
||||
ARRAY_COUNT(sSfxVoiceBank),
|
||||
};
|
||||
|
||||
u8 gSfxChannelLayout = 0;
|
||||
u16 sSfxChannelLowVolumeFlag = 0;
|
||||
|
||||
// The center of the screen in projected coordinates.
|
||||
// Gives the impression that the sfx has no specific location
|
||||
Vec3f gSfxDefaultPos = { 0.0f, 0.0f, 0.0f };
|
||||
|
||||
// Reused as either frequency or volume multiplicative scaling factor
|
||||
// Does not alter or change frequency or volume
|
||||
f32 gSfxDefaultFreqAndVolScale = 1.0f;
|
||||
s32 D_801DB4B4 = 0; // unused
|
||||
|
||||
// Adds no reverb to the existing reverb
|
||||
s8 gSfxDefaultReverb = 0;
|
||||
|
||||
void AudioSfx_MuteBanks(u16 muteMask) {
|
||||
u8 bankId;
|
||||
|
||||
for (bankId = 0; bankId < ARRAY_COUNT(gSfxBanks); bankId++) {
|
||||
if (muteMask & 1) {
|
||||
gSfxBankMuted[bankId] = true;
|
||||
} else {
|
||||
gSfxBankMuted[bankId] = false;
|
||||
}
|
||||
muteMask = muteMask >> 1;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Lowers volumes of both bgm players so that sfx can be more pronounced.
|
||||
* Each sfx channel stores its own bit to lower the volume.
|
||||
* Only a single channel needs to request this to lower the volume.
|
||||
*/
|
||||
void AudioSfx_LowerBgmVolume(u8 channelIndex) {
|
||||
sSfxChannelLowVolumeFlag |= (1 << channelIndex);
|
||||
|
||||
Audio_SetVolumeScale(SEQ_PLAYER_BGM_MAIN, 2, 0x40, 0xF);
|
||||
Audio_SetVolumeScale(SEQ_PLAYER_BGM_SUB, 2, 0x40, 0xF);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears the flag for the specific channel to lower volume.
|
||||
* If all flags are cleared, then both bgm players return to full volume
|
||||
*/
|
||||
void AudioSfx_RestoreBgmVolume(u8 channelIndex) {
|
||||
sSfxChannelLowVolumeFlag &= ((1 << channelIndex) ^ 0xFFFF);
|
||||
|
||||
if (sSfxChannelLowVolumeFlag == 0) {
|
||||
Audio_SetVolumeScale(SEQ_PLAYER_BGM_MAIN, 2, 0x7F, 0xF);
|
||||
Audio_SetVolumeScale(SEQ_PLAYER_BGM_SUB, 2, 0x7F, 0xF);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The main function to request a sfx. All sfx requests begin here.
|
||||
*/
|
||||
void AudioSfx_PlaySfx(u16 sfxId, Vec3f* pos, u8 token, f32* freqScale, f32* volume, s8* reverbAdd) {
|
||||
u8 i;
|
||||
SfxRequest* reqWrite;
|
||||
SfxRequest* reqRead;
|
||||
|
||||
if (!gSfxBankMuted[SFX_BANK_SHIFT(sfxId)]) {
|
||||
reqWrite = &sSfxRequests[sSfxRequestWriteIndex];
|
||||
|
||||
for (i = sSfxRequestReadIndex; sSfxRequestWriteIndex != i; i++) {
|
||||
reqRead = &sSfxRequests[i];
|
||||
if ((reqRead->pos == pos) && (reqRead->sfxId == sfxId)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
reqWrite->sfxId = sfxId;
|
||||
reqWrite->pos = pos;
|
||||
reqWrite->token = token;
|
||||
reqWrite->freqScale = freqScale;
|
||||
reqWrite->volume = volume;
|
||||
reqWrite->reverbAdd = reverbAdd;
|
||||
sSfxRequestWriteIndex++;
|
||||
}
|
||||
}
|
||||
|
||||
void AudioSfx_RemoveMatchingRequests(u8 aspect, SfxBankEntry* entry) {
|
||||
SfxRequest* req;
|
||||
s32 remove;
|
||||
u8 i = sSfxRequestReadIndex;
|
||||
|
||||
for (; i != sSfxRequestWriteIndex; i++) {
|
||||
remove = false;
|
||||
req = &sSfxRequests[i];
|
||||
|
||||
switch (aspect) {
|
||||
case SFX_RM_REQ_BY_BANK:
|
||||
if (SFX_BANK_MASK(req->sfxId) == SFX_BANK_MASK(entry->sfxId)) {
|
||||
remove = true;
|
||||
}
|
||||
break;
|
||||
|
||||
case SFX_RM_REQ_BY_POS_AND_BANK:
|
||||
if ((SFX_BANK_MASK(req->sfxId) == SFX_BANK_MASK(entry->sfxId)) && (&req->pos->x == entry->posX)) {
|
||||
remove = true;
|
||||
}
|
||||
break;
|
||||
|
||||
case SFX_RM_REQ_BY_POS:
|
||||
if (&req->pos->x == entry->posX) {
|
||||
remove = true;
|
||||
}
|
||||
break;
|
||||
|
||||
case SFX_RM_REQ_BY_POS_AND_ID:
|
||||
if ((&req->pos->x == entry->posX) && (req->sfxId == entry->sfxId)) {
|
||||
remove = true;
|
||||
}
|
||||
break;
|
||||
|
||||
case SFX_RM_REQ_BY_TOKEN_AND_ID:
|
||||
if ((req->token == entry->token) && (req->sfxId == entry->sfxId)) {
|
||||
remove = true;
|
||||
}
|
||||
break;
|
||||
|
||||
case SFX_RM_REQ_BY_ID:
|
||||
if (req->sfxId == entry->sfxId) {
|
||||
remove = true;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if (remove) {
|
||||
req->sfxId = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void AudioSfx_ProcessRequest(void) {
|
||||
u16 sfxId;
|
||||
u8 channelCount;
|
||||
u8 index;
|
||||
SfxRequest* req = &sSfxRequests[sSfxRequestReadIndex];
|
||||
SfxBankEntry* entry;
|
||||
SfxParams* sfxParams;
|
||||
s32 bankId;
|
||||
u8 evictImportance;
|
||||
u8 evictIndex = 0x80;
|
||||
|
||||
if (req->sfxId == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
bankId = SFX_BANK(req->sfxId);
|
||||
channelCount = 0;
|
||||
index = gSfxBanks[bankId][0].next;
|
||||
|
||||
// Compare the sfx request to all sfx bank entries
|
||||
while ((index != 0xFF) && (index != 0)) {
|
||||
|
||||
// If an existing sfx from the same source exists in the bank, then we should either:
|
||||
// renew if it is the same sfx, check if any sfx channels are available for that bank,
|
||||
// interrupt that sfx and replace it with the new sfx request, or drop the new sfx request.
|
||||
if (gSfxBanks[bankId][index].posX == &req->pos->x) {
|
||||
|
||||
// If the new sfx has equal importance to the existing sfx,
|
||||
// drop the request if the existing sfx has the "SFX_FLAG_BLOCK_EQUAL_IMPORTANCE" flag.
|
||||
// Otherwise, keep processing the new sfx request
|
||||
if ((gSfxParams[SFX_BANK_SHIFT(req->sfxId)][SFX_INDEX(req->sfxId)].params &
|
||||
SFX_FLAG_BLOCK_EQUAL_IMPORTANCE) &&
|
||||
(gSfxParams[SFX_BANK_SHIFT(req->sfxId)][SFX_INDEX(req->sfxId)].importance ==
|
||||
gSfxBanks[bankId][index].sfxImportance)) {
|
||||
// Drop the new request
|
||||
return;
|
||||
}
|
||||
|
||||
if (gSfxBanks[bankId][index].sfxId == req->sfxId) {
|
||||
// The new sfx is the same as the existing sfx
|
||||
// Set channelCount to max value to reprocess the sfx
|
||||
channelCount = gUsedChannelsPerBank[gSfxChannelLayout][bankId];
|
||||
} else {
|
||||
// Determine which sfx to evict based on importance if there are no more channels available
|
||||
if (channelCount == 0) {
|
||||
// If this is the first sfx at the same source, than store the existing sfx info into evict temps
|
||||
evictIndex = index;
|
||||
sfxId = gSfxBanks[bankId][index].sfxId & 0xFFFF;
|
||||
evictImportance = gSfxParams[SFX_BANK_SHIFT(sfxId)][SFX_INDEX(sfxId)].importance;
|
||||
} else if (gSfxBanks[bankId][index].sfxImportance < evictImportance) {
|
||||
// If a different existing sfx is at the same source, than update the evict temps if the next
|
||||
// existing src has lower importance than the previous existing source
|
||||
evictIndex = index;
|
||||
sfxId = gSfxBanks[bankId][index].sfxId & 0xFFFF;
|
||||
evictImportance = gSfxParams[SFX_BANK_SHIFT(sfxId)][SFX_INDEX(sfxId)].importance;
|
||||
}
|
||||
|
||||
channelCount++;
|
||||
|
||||
// There are no channels available, evict the lowest importance
|
||||
if (channelCount == gUsedChannelsPerBank[gSfxChannelLayout][bankId]) {
|
||||
if (gSfxParams[SFX_BANK_SHIFT(req->sfxId)][SFX_INDEX(req->sfxId)].importance >= evictImportance) {
|
||||
index = evictIndex;
|
||||
} else {
|
||||
index = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Process this sfx by refreshing or replacing and existing sfx
|
||||
if (channelCount == gUsedChannelsPerBank[gSfxChannelLayout][bankId]) {
|
||||
sfxParams = &gSfxParams[SFX_BANK_SHIFT(req->sfxId)][SFX_INDEX(req->sfxId)];
|
||||
|
||||
// Interrupt existing sfx and play the new sfx instead.
|
||||
if ((req->sfxId & SFX_FLAG_MASK) || (sfxParams->flags & SFX_FLAG2_FORCE_RESET) ||
|
||||
(index == evictIndex)) {
|
||||
|
||||
// Restore bgm if the sfx about to be replaced has the right flag
|
||||
if ((gSfxBanks[bankId][index].sfxParams & SFX_FLAG_LOWER_VOLUME_BGM) &&
|
||||
(gSfxBanks[bankId][index].state != SFX_STATE_QUEUED)) {
|
||||
AudioSfx_RestoreBgmVolume(gSfxBanks[bankId][index].channelIndex);
|
||||
}
|
||||
|
||||
gSfxBanks[bankId][index].token = req->token;
|
||||
gSfxBanks[bankId][index].sfxId = req->sfxId;
|
||||
gSfxBanks[bankId][index].state = SFX_STATE_QUEUED;
|
||||
gSfxBanks[bankId][index].freshness = 2;
|
||||
gSfxBanks[bankId][index].freqScale = req->freqScale;
|
||||
gSfxBanks[bankId][index].volume = req->volume;
|
||||
gSfxBanks[bankId][index].reverbAdd = req->reverbAdd;
|
||||
gSfxBanks[bankId][index].sfxParams = sfxParams->params;
|
||||
gSfxBanks[bankId][index].sfxFlags = sfxParams->flags;
|
||||
gSfxBanks[bankId][index].sfxImportance = sfxParams->importance;
|
||||
} else if (gSfxBanks[bankId][index].state == SFX_STATE_PLAYING_ONE_FRAME) {
|
||||
// The new sfx is "one-frame" and equals the existing sfx,
|
||||
// continue playing the "one-frame" sfx by setting "SFX_STATE_PLAYING".
|
||||
// This will avoid triggering deletion and get "SFX_STATE_REFRESH"
|
||||
// The state will be set back to "SFX_STATE_PLAYING_ONE_FRAME" at the end of the cycle
|
||||
gSfxBanks[bankId][index].state = SFX_STATE_PLAYING;
|
||||
}
|
||||
// Terminate loop, function is finished (nothing more is processed)
|
||||
index = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (index != 0) {
|
||||
index = gSfxBanks[bankId][index].next;
|
||||
}
|
||||
}
|
||||
|
||||
if ((gSfxBanks[bankId][sSfxBankFreeListStart[bankId]].next != 0xFF) && (index != 0)) {
|
||||
// Allocate from free list
|
||||
index = sSfxBankFreeListStart[bankId];
|
||||
|
||||
entry = &gSfxBanks[bankId][index];
|
||||
entry->posX = &req->pos->x;
|
||||
entry->posY = &req->pos->y;
|
||||
entry->posZ = &req->pos->z;
|
||||
entry->token = req->token;
|
||||
entry->freqScale = req->freqScale;
|
||||
entry->volume = req->volume;
|
||||
entry->reverbAdd = req->reverbAdd;
|
||||
|
||||
sfxParams = &gSfxParams[SFX_BANK_SHIFT(req->sfxId)][SFX_INDEX(req->sfxId)];
|
||||
|
||||
entry->sfxParams = sfxParams->params;
|
||||
entry->sfxFlags = sfxParams->flags;
|
||||
entry->sfxImportance = sfxParams->importance;
|
||||
entry->sfxId = req->sfxId;
|
||||
entry->state = SFX_STATE_QUEUED;
|
||||
entry->freshness = 2;
|
||||
entry->prev = sSfxBankListEnd[bankId];
|
||||
|
||||
gSfxBanks[bankId][sSfxBankListEnd[bankId]].next = sSfxBankFreeListStart[bankId];
|
||||
sSfxBankListEnd[bankId] = sSfxBankFreeListStart[bankId];
|
||||
sSfxBankFreeListStart[bankId] = gSfxBanks[bankId][sSfxBankFreeListStart[bankId]].next;
|
||||
gSfxBanks[bankId][sSfxBankFreeListStart[bankId]].prev = 0xFF;
|
||||
|
||||
entry->next = 0xFF;
|
||||
}
|
||||
}
|
||||
|
||||
void AudioSfx_RemoveBankEntry(u8 bankId, u8 entryIndex) {
|
||||
SfxBankEntry* entry = &gSfxBanks[bankId][entryIndex];
|
||||
u8 i;
|
||||
|
||||
if (entry->sfxParams & SFX_FLAG_LOWER_VOLUME_BGM) {
|
||||
AudioSfx_RestoreBgmVolume(entry->channelIndex);
|
||||
}
|
||||
|
||||
if (entryIndex == sSfxBankListEnd[bankId]) {
|
||||
sSfxBankListEnd[bankId] = entry->prev;
|
||||
} else {
|
||||
gSfxBanks[bankId][entry->next].prev = entry->prev;
|
||||
}
|
||||
|
||||
gSfxBanks[bankId][entry->prev].next = entry->next;
|
||||
entry->next = sSfxBankFreeListStart[bankId];
|
||||
entry->prev = 0xFF;
|
||||
gSfxBanks[bankId][sSfxBankFreeListStart[bankId]].prev = entryIndex;
|
||||
sSfxBankFreeListStart[bankId] = entryIndex;
|
||||
entry->state = SFX_STATE_EMPTY;
|
||||
|
||||
for (i = 0; i < gChannelsPerBank[gSfxChannelLayout][bankId]; i++) {
|
||||
if (gActiveSfx[bankId][i].entryIndex == entryIndex) {
|
||||
gActiveSfx[bankId][i].entryIndex = 0xFF;
|
||||
i = gChannelsPerBank[gSfxChannelLayout][bankId];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void AudioSfx_ChooseActiveSfx(u8 bankId) {
|
||||
u8 numChosenSfx = 0;
|
||||
u8 numChannels;
|
||||
u8 entryIndex;
|
||||
u8 i;
|
||||
u8 j;
|
||||
u8 k;
|
||||
u8 sfxImportance;
|
||||
u8 needNewSfx;
|
||||
u8 chosenEntryIndex;
|
||||
s32 pad;
|
||||
SfxBankEntry* entry;
|
||||
ActiveSfx chosenSfx[MAX_CHANNELS_PER_BANK];
|
||||
ActiveSfx* activeSfx;
|
||||
f32 entryPosY;
|
||||
f32 entryPosX;
|
||||
|
||||
for (i = 0; i < MAX_CHANNELS_PER_BANK; i++) {
|
||||
chosenSfx[i].priority = 0x7FFFFFFF;
|
||||
chosenSfx[i].entryIndex = 0xFF;
|
||||
}
|
||||
|
||||
entryIndex = gSfxBanks[bankId][0].next;
|
||||
k = 0;
|
||||
|
||||
// Delete stale sfx and prioritize remaining sfx into the gActiveSfx arrays
|
||||
while (entryIndex != 0xFF) {
|
||||
|
||||
// Update the freshness for an "all-frame" sfx if it is still queued
|
||||
if ((gSfxBanks[bankId][entryIndex].state == SFX_STATE_QUEUED) &&
|
||||
(gSfxBanks[bankId][entryIndex].sfxId & SFX_FLAG_MASK)) {
|
||||
gSfxBanks[bankId][entryIndex].freshness--;
|
||||
|
||||
// If a "one-frame" sfx is still in "SFX_STATE_PLAYING_ONE_FRAME", then remove the sfx
|
||||
} else if (!(gSfxBanks[bankId][entryIndex].sfxId & SFX_FLAG_MASK) &&
|
||||
(gSfxBanks[bankId][entryIndex].state == SFX_STATE_PLAYING_ONE_FRAME)) {
|
||||
// ioPort 0, force stop sfx in seq 0
|
||||
AUDIOCMD_CHANNEL_SET_IO(SEQ_PLAYER_SFX, gSfxBanks[bankId][entryIndex].channelIndex, 0, 0);
|
||||
AudioSfx_RemoveBankEntry(bankId, entryIndex);
|
||||
}
|
||||
|
||||
// If a "all-frame" sfx goes 2 frames in the "queued" state
|
||||
// (because it is too low priority), then remove the sfx
|
||||
if (gSfxBanks[bankId][entryIndex].freshness == 0) {
|
||||
AudioSfx_RemoveBankEntry(bankId, entryIndex);
|
||||
} else if (gSfxBanks[bankId][entryIndex].state != SFX_STATE_EMPTY) {
|
||||
// process the entry
|
||||
entry = &gSfxBanks[bankId][entryIndex];
|
||||
|
||||
// Recompute distSq each frame since the sound's position may have changed
|
||||
// (later converted into dist)
|
||||
if (&gSfxDefaultPos.x == entry[0].posX) {
|
||||
entry->dist = 0.0f;
|
||||
} else {
|
||||
entryPosY = *entry->posY * 1;
|
||||
entryPosX = *entry->posX * 0.5f;
|
||||
entry->dist = (SQ(entryPosX) + SQ(entryPosY) + SQ(*entry->posZ)) / 10.0f;
|
||||
}
|
||||
|
||||
// Recompute priority, possibly based on sfx position relative to the camera.
|
||||
// (Note that the priority is the opposite of importance; lower is more preserved)
|
||||
sfxImportance = entry->sfxImportance;
|
||||
|
||||
if (entry->sfxParams & SFX_FLAG_PRIORITY_NO_DIST) {
|
||||
// Priority is independent of distance
|
||||
entry->priority = SQ(0xFF - sfxImportance) * SQ(76);
|
||||
} else {
|
||||
// Priority value increases with distance (more likely to eject)
|
||||
if (entry->dist > 0x7FFFFFD0) {
|
||||
// max distance
|
||||
entry->dist = 0x70000008;
|
||||
}
|
||||
|
||||
entry->priority = (u32)entry->dist + (SQ(0xFF - sfxImportance) * SQ(76));
|
||||
if (*entry->posZ < 0.0f) {
|
||||
entry->priority += (s32)(-*entry->posZ * 6.0f);
|
||||
}
|
||||
}
|
||||
|
||||
// Sfx is too far away, do not consider for chosen sfx
|
||||
if (entry->dist > SQ(1e5f)) {
|
||||
|
||||
// If too far away and also playing, stop playing
|
||||
if (entry->state == SFX_STATE_PLAYING) {
|
||||
// ioPort 0, force stop sfx in seq 0
|
||||
AUDIOCMD_CHANNEL_SET_IO(SEQ_PLAYER_SFX, entry->channelIndex, 0, 0);
|
||||
if (entry->sfxId & SFX_FLAG_MASK) {
|
||||
AudioSfx_RemoveBankEntry(bankId, entryIndex);
|
||||
entryIndex = k;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Loop through all channels allocated to a specific bank
|
||||
// Choose which sfx from gSfxBanks to play
|
||||
// This includes all sfx requests and sfx already playing
|
||||
// Sort all current sfx entries in gSfxBanks by priority
|
||||
// This is where the "active" sfx are chosen
|
||||
numChannels = gChannelsPerBank[gSfxChannelLayout][bankId];
|
||||
|
||||
for (i = 0; i < numChannels; i++) {
|
||||
// Sort all sfx entries by priority
|
||||
if (chosenSfx[i].priority >= entry->priority) {
|
||||
// Update the number of sfx to attampt to play
|
||||
if (numChosenSfx < gChannelsPerBank[gSfxChannelLayout][bankId]) {
|
||||
numChosenSfx++;
|
||||
}
|
||||
|
||||
for (j = numChannels - 1; j > i; j--) {
|
||||
chosenSfx[j].priority = chosenSfx[j - 1].priority;
|
||||
chosenSfx[j].entryIndex = chosenSfx[j - 1].entryIndex;
|
||||
}
|
||||
|
||||
chosenSfx[i].priority = entry->priority;
|
||||
chosenSfx[i].entryIndex = entryIndex;
|
||||
i = numChannels; // make this the last pass through the loop, here equivalent to "break"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
k = entryIndex;
|
||||
}
|
||||
|
||||
entryIndex = gSfxBanks[bankId][k].next;
|
||||
}
|
||||
|
||||
// If a sfx is chosen, update its state
|
||||
for (i = 0; i < numChosenSfx; i++) {
|
||||
entry = &gSfxBanks[bankId][chosenSfx[i].entryIndex];
|
||||
|
||||
if (entry->state == SFX_STATE_QUEUED) {
|
||||
// sfx is a new entry
|
||||
entry->state = SFX_STATE_READY;
|
||||
} else if (entry->state == SFX_STATE_PLAYING) {
|
||||
// sfx is already playing
|
||||
entry->state = SFX_STATE_PLAYING_REFRESH;
|
||||
}
|
||||
}
|
||||
|
||||
// Apply the chosenSfx to the activeSfx in each channel
|
||||
numChannels = gChannelsPerBank[gSfxChannelLayout][bankId];
|
||||
for (i = 0; i < numChannels; i++) {
|
||||
needNewSfx = false;
|
||||
activeSfx = &gActiveSfx[bankId][i];
|
||||
|
||||
// Check if a sfx is already in the channel
|
||||
if (activeSfx->entryIndex == 0xFF) {
|
||||
// No sfx playing in the channel
|
||||
// Available for use
|
||||
needNewSfx = true;
|
||||
} else {
|
||||
// The channel is already playing a sfx
|
||||
// Get the entry of the sfx playing
|
||||
entry = &gSfxBanks[bankId][activeSfx[0].entryIndex];
|
||||
|
||||
// Check the state of the sfx playing
|
||||
if (entry->state == SFX_STATE_PLAYING) {
|
||||
if (entry->sfxId & SFX_FLAG_MASK) {
|
||||
// For "all-frames" sfx, remove the entry
|
||||
AudioSfx_RemoveBankEntry(bankId, activeSfx->entryIndex);
|
||||
} else {
|
||||
// For "one-frame" sfx, reset the state to queued
|
||||
entry->state = SFX_STATE_QUEUED;
|
||||
entry->freshness = 0x80;
|
||||
}
|
||||
needNewSfx = true;
|
||||
} else if (entry->state == SFX_STATE_EMPTY) {
|
||||
// The sfx already in the channel is empty
|
||||
// Can replace the sfx
|
||||
activeSfx->entryIndex = 0xFF;
|
||||
needNewSfx = true;
|
||||
} else {
|
||||
// Sfx is already playing as it should, nothing to do.
|
||||
for (j = 0; j < numChannels; j++) {
|
||||
if (activeSfx->entryIndex == chosenSfx[j].entryIndex) {
|
||||
chosenSfx[j].entryIndex = 0xFF;
|
||||
j = numChannels;
|
||||
}
|
||||
}
|
||||
|
||||
numChosenSfx--;
|
||||
}
|
||||
}
|
||||
|
||||
// enter the new sfx into the activeSfx
|
||||
if (needNewSfx == true) {
|
||||
for (j = 0; j < numChannels; j++) {
|
||||
chosenEntryIndex = chosenSfx[j].entryIndex;
|
||||
if ((chosenEntryIndex != 0xFF) &&
|
||||
(gSfxBanks[bankId][chosenEntryIndex].state != SFX_STATE_PLAYING_REFRESH)) {
|
||||
for (k = 0; k < numChannels; k++) {
|
||||
if (chosenEntryIndex == gActiveSfx[bankId][k].entryIndex) {
|
||||
needNewSfx = false;
|
||||
k = numChannels; // "break; i.e. force for-loop to end"
|
||||
}
|
||||
}
|
||||
|
||||
if (needNewSfx == true) {
|
||||
activeSfx->entryIndex = chosenEntryIndex;
|
||||
chosenSfx[j].entryIndex = 0xFF;
|
||||
j = numChannels + 1;
|
||||
numChosenSfx--;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (j == numChannels) {
|
||||
// nothing found
|
||||
activeSfx->entryIndex = 0xFF;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void AudioSfx_PlayActiveSfx(u8 bankId) {
|
||||
u8 entryIndex;
|
||||
SequenceChannel* channel;
|
||||
SfxBankEntry* entry;
|
||||
u8 i;
|
||||
u8 ioPort5Data;
|
||||
|
||||
for (i = 0; i < gChannelsPerBank[gSfxChannelLayout][bankId]; i++) {
|
||||
entryIndex = gActiveSfx[bankId][i].entryIndex;
|
||||
// If entry is not empty
|
||||
if (entryIndex != 0xFF) {
|
||||
entry = &gSfxBanks[bankId][entryIndex];
|
||||
channel = gAudioCtx.seqPlayers[SEQ_PLAYER_SFX].channels[sCurSfxPlayerChannelIndex];
|
||||
|
||||
if (entry->state == SFX_STATE_READY) {
|
||||
// Initialize a sfx (new sfx request)
|
||||
entry->channelIndex = sCurSfxPlayerChannelIndex;
|
||||
if (entry->sfxParams & SFX_FLAG_LOWER_VOLUME_BGM) {
|
||||
AudioSfx_LowerBgmVolume(sCurSfxPlayerChannelIndex);
|
||||
}
|
||||
|
||||
// Add noise that will offset the frequency of the sfx
|
||||
if ((entry->sfxParams & SFX_PARAM_RAND_FREQ_RAISE_MASK) != (0 << SFX_PARAM_RAND_FREQ_RAISE_SHIFT)) {
|
||||
switch (entry->sfxParams & SFX_PARAM_RAND_FREQ_RAISE_MASK) {
|
||||
case (1 << SFX_PARAM_RAND_FREQ_RAISE_SHIFT):
|
||||
entry->randFreq = AudioThread_NextRandom() & 0xF;
|
||||
break;
|
||||
|
||||
case (2 << SFX_PARAM_RAND_FREQ_RAISE_SHIFT):
|
||||
entry->randFreq = AudioThread_NextRandom() & 0x1F;
|
||||
break;
|
||||
|
||||
case (3 << SFX_PARAM_RAND_FREQ_RAISE_SHIFT):
|
||||
entry->randFreq = AudioThread_NextRandom() & 0x3F;
|
||||
break;
|
||||
|
||||
default:
|
||||
entry->randFreq = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Calculate all the properties of sfx
|
||||
AudioSfx_SetProperties(bankId, entryIndex, sCurSfxPlayerChannelIndex);
|
||||
|
||||
// ioPort 0, enable the sfx to play in `NA_BGM_GENERAL_SFX`
|
||||
AUDIOCMD_CHANNEL_SET_IO(SEQ_PLAYER_SFX, sCurSfxPlayerChannelIndex, 0, 1);
|
||||
|
||||
// ioPort 4, write the lower bits sfx index for `NA_BGM_GENERAL_SFX` to find the right code to execute
|
||||
AUDIOCMD_CHANNEL_SET_IO(SEQ_PLAYER_SFX, sCurSfxPlayerChannelIndex, 4, entry->sfxId & 0xFF);
|
||||
|
||||
// If the sfx bank has more than 255 entries (greater than a u8 can store),
|
||||
// then store the Id in upper and lower bits
|
||||
if (gIsLargeSfxBank[bankId]) {
|
||||
// Store upper bits
|
||||
ioPort5Data = ((u8)((entry->sfxId & 0x300) >> 7) + (u8)((entry->sfxId & 0xFF) >> 7));
|
||||
} else {
|
||||
ioPort5Data = 0;
|
||||
}
|
||||
|
||||
if ((entry->sfxParams & SFX_FLAG_8) && (entry->freshness == 0x80)) {
|
||||
ioPort5Data += 0x80;
|
||||
}
|
||||
|
||||
if (D_801D6608[bankId]) {
|
||||
// ioPort 5, write the upper bits sfx index and a flag for `NA_BGM_GENERAL_SFX`,
|
||||
// for banks with > 0xFF entries
|
||||
AUDIOCMD_CHANNEL_SET_IO(SEQ_PLAYER_SFX, sCurSfxPlayerChannelIndex, 5, ioPort5Data);
|
||||
}
|
||||
|
||||
// Update playing state
|
||||
if (entry->sfxId & SFX_FLAG_MASK) {
|
||||
// "all-frames" sfx
|
||||
entry->state = SFX_STATE_PLAYING;
|
||||
} else {
|
||||
// "one-frame" sfx
|
||||
entry->state = SFX_STATE_PLAYING_ONE_FRAME;
|
||||
}
|
||||
} else if ((u8)channel->seqScriptIO[1] == (u8)SEQ_IO_VAL_NONE) {
|
||||
// Signal from seq 0 that the sfx is finished playing. Remove entry
|
||||
AudioSfx_RemoveBankEntry(bankId, entryIndex);
|
||||
} else if (entry->state == SFX_STATE_PLAYING_REFRESH) {
|
||||
// Sfx is playing but a refresh is requested
|
||||
AudioSfx_SetProperties(bankId, entryIndex, sCurSfxPlayerChannelIndex);
|
||||
|
||||
// Update playing state
|
||||
if (entry->sfxId & SFX_FLAG_MASK) {
|
||||
// "all-frames" sfx
|
||||
entry->state = SFX_STATE_PLAYING;
|
||||
} else {
|
||||
// "one-frame" sfx
|
||||
entry->state = SFX_STATE_PLAYING_ONE_FRAME;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
sCurSfxPlayerChannelIndex++;
|
||||
}
|
||||
}
|
||||
|
||||
void AudioSfx_StopByBank(u8 bankId) {
|
||||
SfxBankEntry* entry;
|
||||
s32 pad;
|
||||
SfxBankEntry entryToRemove;
|
||||
u8 entryIndex = gSfxBanks[bankId][0].next;
|
||||
|
||||
while (entryIndex != 0xFF) {
|
||||
entry = &gSfxBanks[bankId][entryIndex];
|
||||
if (entry->state >= SFX_STATE_PLAYING_REFRESH) {
|
||||
AUDIOCMD_CHANNEL_SET_IO(SEQ_PLAYER_SFX, entry->channelIndex, 0, 0);
|
||||
}
|
||||
|
||||
if (entry->state != SFX_STATE_EMPTY) {
|
||||
AudioSfx_RemoveBankEntry(bankId, entryIndex);
|
||||
}
|
||||
entryIndex = gSfxBanks[bankId][0].next;
|
||||
}
|
||||
|
||||
entryToRemove.sfxId = bankId << 12;
|
||||
AudioSfx_RemoveMatchingRequests(SFX_RM_REQ_BY_BANK, &entryToRemove);
|
||||
}
|
||||
|
||||
void AudioSfx_StopByPosAndBankImpl(u8 bankId, Vec3f* pos) {
|
||||
SfxBankEntry* entry;
|
||||
u8 entryIndex = gSfxBanks[bankId][0].next;
|
||||
u8 prevEntryIndex = 0;
|
||||
|
||||
while (entryIndex != 0xFF) {
|
||||
entry = &gSfxBanks[bankId][entryIndex];
|
||||
if (entry->posX == &pos->x) {
|
||||
if (entry->state >= SFX_STATE_PLAYING_REFRESH) {
|
||||
AUDIOCMD_CHANNEL_SET_IO(SEQ_PLAYER_SFX, entry->channelIndex, 0, 0);
|
||||
}
|
||||
|
||||
if (entry->state != SFX_STATE_EMPTY) {
|
||||
AudioSfx_RemoveBankEntry(bankId, entryIndex);
|
||||
}
|
||||
} else {
|
||||
prevEntryIndex = entryIndex;
|
||||
}
|
||||
|
||||
entryIndex = gSfxBanks[bankId][prevEntryIndex].next;
|
||||
}
|
||||
}
|
||||
|
||||
void AudioSfx_StopByPosAndBank(u8 bankId, Vec3f* pos) {
|
||||
SfxBankEntry entryToRemove;
|
||||
|
||||
AudioSfx_StopByPosAndBankImpl(bankId, pos);
|
||||
entryToRemove.sfxId = bankId << 12;
|
||||
entryToRemove.posX = &pos->x;
|
||||
AudioSfx_RemoveMatchingRequests(SFX_RM_REQ_BY_POS_AND_BANK, &entryToRemove);
|
||||
}
|
||||
|
||||
void AudioSfx_StopByPos(Vec3f* pos) {
|
||||
u8 bankId;
|
||||
SfxBankEntry entryToRemove;
|
||||
|
||||
for (bankId = 0; bankId < ARRAY_COUNT(gSfxBanks); bankId++) {
|
||||
AudioSfx_StopByPosAndBankImpl(bankId, pos);
|
||||
}
|
||||
|
||||
entryToRemove.posX = &pos->x;
|
||||
AudioSfx_RemoveMatchingRequests(SFX_RM_REQ_BY_POS, &entryToRemove);
|
||||
}
|
||||
|
||||
void AudioSfx_StopByPosAndId(Vec3f* pos, u16 sfxId) {
|
||||
SfxBankEntry* entry;
|
||||
u8 entryIndex = gSfxBanks[SFX_BANK(sfxId)][0].next;
|
||||
u8 prevEntryIndex = 0;
|
||||
SfxBankEntry entryToRemove;
|
||||
|
||||
while (entryIndex != 0xFF) {
|
||||
entry = &gSfxBanks[SFX_BANK(sfxId)][entryIndex];
|
||||
if ((entry->posX == &pos->x) && (entry->sfxId == sfxId)) {
|
||||
if (entry->state >= SFX_STATE_PLAYING_REFRESH) {
|
||||
AUDIOCMD_CHANNEL_SET_IO(SEQ_PLAYER_SFX, entry->channelIndex, 0, 0);
|
||||
}
|
||||
|
||||
if (entry->state != SFX_STATE_EMPTY) {
|
||||
AudioSfx_RemoveBankEntry(SFX_BANK(sfxId), entryIndex);
|
||||
}
|
||||
entryIndex = 0xFF;
|
||||
} else {
|
||||
prevEntryIndex = entryIndex;
|
||||
}
|
||||
|
||||
if (entryIndex != 0xFF) {
|
||||
entryIndex = gSfxBanks[SFX_BANK(sfxId)][prevEntryIndex].next;
|
||||
}
|
||||
}
|
||||
|
||||
entryToRemove.posX = &pos->x;
|
||||
entryToRemove.sfxId = sfxId;
|
||||
AudioSfx_RemoveMatchingRequests(SFX_RM_REQ_BY_POS_AND_ID, &entryToRemove);
|
||||
}
|
||||
|
||||
void AudioSfx_StopByTokenAndId(u8 token, u16 sfxId) {
|
||||
SfxBankEntry* entry;
|
||||
u8 entryIndex = gSfxBanks[SFX_BANK(sfxId)][0].next;
|
||||
u8 prevEntryIndex = 0;
|
||||
SfxBankEntry entryToRemove;
|
||||
|
||||
while (entryIndex != 0xFF) {
|
||||
entry = &gSfxBanks[SFX_BANK(sfxId)][entryIndex];
|
||||
if ((entry->token == token) && (entry->sfxId == sfxId)) {
|
||||
if (entry->state >= SFX_STATE_PLAYING_REFRESH) {
|
||||
AUDIOCMD_CHANNEL_SET_IO(SEQ_PLAYER_SFX, entry->channelIndex, 0, 0);
|
||||
}
|
||||
|
||||
if (entry->state != SFX_STATE_EMPTY) {
|
||||
AudioSfx_RemoveBankEntry(SFX_BANK(sfxId), entryIndex);
|
||||
}
|
||||
} else {
|
||||
prevEntryIndex = entryIndex;
|
||||
}
|
||||
|
||||
if (entryIndex != 0xFF) {
|
||||
entryIndex = gSfxBanks[SFX_BANK(sfxId)][prevEntryIndex].next;
|
||||
}
|
||||
}
|
||||
|
||||
entryToRemove.token = token;
|
||||
entryToRemove.sfxId = sfxId;
|
||||
AudioSfx_RemoveMatchingRequests(SFX_RM_REQ_BY_TOKEN_AND_ID, &entryToRemove);
|
||||
}
|
||||
|
||||
void AudioSfx_StopById(u32 sfxId) {
|
||||
SfxBankEntry* entry;
|
||||
u8 entryIndex = gSfxBanks[SFX_BANK(sfxId)][0].next;
|
||||
u8 prevEntryIndex = 0;
|
||||
SfxBankEntry entryToRemove;
|
||||
|
||||
while (entryIndex != 0xFF) {
|
||||
entry = &gSfxBanks[SFX_BANK(sfxId)][entryIndex];
|
||||
if (entry->sfxId == sfxId) {
|
||||
if (entry->state >= SFX_STATE_PLAYING_REFRESH) {
|
||||
AUDIOCMD_CHANNEL_SET_IO(SEQ_PLAYER_SFX, entry->channelIndex, 0, 0);
|
||||
}
|
||||
if (entry->state != SFX_STATE_EMPTY) {
|
||||
AudioSfx_RemoveBankEntry(SFX_BANK(sfxId), entryIndex);
|
||||
}
|
||||
} else {
|
||||
prevEntryIndex = entryIndex;
|
||||
}
|
||||
|
||||
entryIndex = gSfxBanks[SFX_BANK(sfxId)][prevEntryIndex].next;
|
||||
}
|
||||
|
||||
entryToRemove.sfxId = sfxId;
|
||||
AudioSfx_RemoveMatchingRequests(SFX_RM_REQ_BY_ID, &entryToRemove);
|
||||
}
|
||||
|
||||
void AudioSfx_ProcessRequests(void) {
|
||||
if (gAudioCtx.seqPlayers[SEQ_PLAYER_SFX].enabled) {
|
||||
while (sSfxRequestWriteIndex != sSfxRequestReadIndex) {
|
||||
AudioSfx_ProcessRequest();
|
||||
sSfxRequestReadIndex++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Unused
|
||||
*/
|
||||
void AudioSfx_SetBankLerp(u8 bankId, u8 target, u16 delay) {
|
||||
if (delay == 0) {
|
||||
delay++;
|
||||
}
|
||||
|
||||
sSfxBankLerp[bankId].target = target / 127.0f;
|
||||
sSfxBankLerp[bankId].remainingFrames = delay;
|
||||
sSfxBankLerp[bankId].step = ((sSfxBankLerp[bankId].value - sSfxBankLerp[bankId].target) / delay);
|
||||
}
|
||||
|
||||
/**
|
||||
* Unused
|
||||
*/
|
||||
void AudioSfx_StepBankLerp(u8 bankId) {
|
||||
if (sSfxBankLerp[bankId].remainingFrames != 0) {
|
||||
sSfxBankLerp[bankId].remainingFrames--;
|
||||
|
||||
if (sSfxBankLerp[bankId].remainingFrames != 0) {
|
||||
sSfxBankLerp[bankId].value -= sSfxBankLerp[bankId].step;
|
||||
} else {
|
||||
sSfxBankLerp[bankId].value = sSfxBankLerp[bankId].target;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void AudioSfx_ProcessActiveSfx(void) {
|
||||
u8 bankId;
|
||||
|
||||
if (gAudioCtx.seqPlayers[SEQ_PLAYER_SFX].enabled) {
|
||||
sCurSfxPlayerChannelIndex = 0;
|
||||
|
||||
for (bankId = 0; bankId < ARRAY_COUNT(gSfxBanks); bankId++) {
|
||||
AudioSfx_ChooseActiveSfx(bankId);
|
||||
AudioSfx_PlayActiveSfx(bankId);
|
||||
AudioSfx_StepBankLerp(bankId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
u8 AudioSfx_IsPlaying(u32 sfxId) {
|
||||
SfxBankEntry* entry;
|
||||
u8 entryIndex = gSfxBanks[SFX_BANK(sfxId)][0].next;
|
||||
|
||||
while (entryIndex != 0xFF) {
|
||||
entry = &gSfxBanks[SFX_BANK(sfxId)][entryIndex];
|
||||
if (entry->sfxId == sfxId) {
|
||||
return true;
|
||||
}
|
||||
entryIndex = entry->next;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void AudioSfx_Reset(void) {
|
||||
u8 bankId;
|
||||
u8 i;
|
||||
u8 entryIndex;
|
||||
|
||||
sSfxRequestWriteIndex = 0;
|
||||
sSfxRequestReadIndex = 0;
|
||||
sSfxChannelLowVolumeFlag = 0;
|
||||
|
||||
for (bankId = 0; bankId < ARRAY_COUNT(gSfxBanks); bankId++) {
|
||||
sSfxBankListEnd[bankId] = 0;
|
||||
sSfxBankFreeListStart[bankId] = 1;
|
||||
sSfxBankUnused[bankId] = 0;
|
||||
gSfxBankMuted[bankId] = false;
|
||||
sSfxBankLerp[bankId].value = 1.0f;
|
||||
sSfxBankLerp[bankId].remainingFrames = 0;
|
||||
}
|
||||
|
||||
for (bankId = 0; bankId < ARRAY_COUNT(gSfxBanks); bankId++) {
|
||||
for (i = 0; i < MAX_CHANNELS_PER_BANK; i++) {
|
||||
gActiveSfx[bankId][i].entryIndex = 0xFF;
|
||||
}
|
||||
}
|
||||
|
||||
for (bankId = 0; bankId < ARRAY_COUNT(gSfxBanks); bankId++) {
|
||||
gSfxBanks[bankId][0].prev = 0xFF;
|
||||
gSfxBanks[bankId][0].next = 0xFF;
|
||||
|
||||
for (i = 1; i < sSfxBankSizes[bankId] - 1; i++) {
|
||||
gSfxBanks[bankId][i].prev = i - 1;
|
||||
gSfxBanks[bankId][i].next = i + 1;
|
||||
}
|
||||
|
||||
gSfxBanks[bankId][i].prev = i - 1;
|
||||
gSfxBanks[bankId][i].next = 0xFF;
|
||||
}
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
#include "global.h"
|
||||
|
||||
#pragma GLOBAL_ASM("asm/non_matchings/code/code_801A7B10/Audio_StartSequence.s")
|
||||
|
||||
#pragma GLOBAL_ASM("asm/non_matchings/code/code_801A7B10/Audio_StopSequence.s")
|
||||
|
||||
#pragma GLOBAL_ASM("asm/non_matchings/code/code_801A7B10/func_801A7D84.s")
|
||||
|
||||
#pragma GLOBAL_ASM("asm/non_matchings/code/code_801A7B10/Audio_QueueSeqCmd.s")
|
||||
|
||||
#pragma GLOBAL_ASM("asm/non_matchings/code/code_801A7B10/func_801A89D0.s")
|
||||
|
||||
#pragma GLOBAL_ASM("asm/non_matchings/code/code_801A7B10/Audio_GetActiveSequence.s")
|
||||
|
||||
#pragma GLOBAL_ASM("asm/non_matchings/code/code_801A7B10/func_801A8ABC.s")
|
||||
|
||||
#pragma GLOBAL_ASM("asm/non_matchings/code/code_801A7B10/func_801A8B14.s")
|
||||
|
||||
#pragma GLOBAL_ASM("asm/non_matchings/code/code_801A7B10/func_801A8B2C.s")
|
||||
|
||||
#pragma GLOBAL_ASM("asm/non_matchings/code/code_801A7B10/Audio_SetVolumeScale.s")
|
||||
|
||||
#pragma GLOBAL_ASM("asm/non_matchings/code/code_801A7B10/func_801A8D5C.s")
|
||||
|
||||
#pragma GLOBAL_ASM("asm/non_matchings/code/code_801A7B10/func_801A9768.s")
|
||||
|
||||
#pragma GLOBAL_ASM("asm/non_matchings/code/code_801A7B10/func_801A982C.s")
|
||||
|
||||
#pragma GLOBAL_ASM("asm/non_matchings/code/code_801A7B10/func_801A99B8.s")
|
||||
|
||||
#pragma GLOBAL_ASM("asm/non_matchings/code/code_801A7B10/func_801A9A74.s")
|
||||
Reference in New Issue
Block a user