mirror of
https://github.com/zeldaret/mm.git
synced 2026-06-27 10:02:50 -04:00
audio_thread.c OK and Documented (code_80192BE0.c) (#1117)
* copy docs from audio * PR Suggestions Round 1 * more PR suggestions * fix bss * PR Suggestions * oops, duplicate * apply OoT Feedback, fix bss * cleanup * spacing * bss Co-authored-by: angie <angheloalf95@gmail.com>
This commit is contained in:
@@ -63,7 +63,7 @@ void AudioEffects_SequencePlayerProcessSound(SequencePlayer* seqPlayer) {
|
||||
}
|
||||
|
||||
seqPlayer->fadeTimer--;
|
||||
if ((seqPlayer->fadeTimer == 0) && (seqPlayer->state == SEQPLAYER_STATE_2)) {
|
||||
if ((seqPlayer->fadeTimer == 0) && (seqPlayer->state == SEQPLAYER_STATE_FADE_OUT)) {
|
||||
AudioSeq_SequencePlayerDisable(seqPlayer);
|
||||
return;
|
||||
}
|
||||
@@ -112,10 +112,10 @@ f32 AudioEffects_GetVibratoFreqScale(VibratoState* vib) {
|
||||
static f32 activeVibratoFreqScaleSum = 0.0f;
|
||||
static s32 activeVibratoCount = 0;
|
||||
f32 pitchChange;
|
||||
f32 extent;
|
||||
f32 invExtent;
|
||||
f32 depth;
|
||||
f32 invDepth;
|
||||
f32 result;
|
||||
f32 scaledExtent;
|
||||
f32 scaledDepth;
|
||||
VibratoSubStruct* subVib = vib->vibSubStruct;
|
||||
|
||||
if (vib->delay != 0) {
|
||||
@@ -124,17 +124,17 @@ f32 AudioEffects_GetVibratoFreqScale(VibratoState* vib) {
|
||||
}
|
||||
|
||||
if (subVib != NULL) {
|
||||
if (vib->extentChangeTimer) {
|
||||
if (vib->extentChangeTimer == 1) {
|
||||
vib->extent = (s32)subVib->vibratoExtentTarget;
|
||||
if (vib->depthChangeTimer) {
|
||||
if (vib->depthChangeTimer == 1) {
|
||||
vib->depth = (s32)subVib->vibratoDepthTarget;
|
||||
} else {
|
||||
vib->extent += ((s32)subVib->vibratoExtentTarget - vib->extent) / (s32)vib->extentChangeTimer;
|
||||
vib->depth += ((s32)subVib->vibratoDepthTarget - vib->depth) / (s32)vib->depthChangeTimer;
|
||||
}
|
||||
|
||||
vib->extentChangeTimer--;
|
||||
} else if (subVib->vibratoExtentTarget != (s32)vib->extent) {
|
||||
if ((vib->extentChangeTimer = subVib->vibratoExtentChangeDelay) == 0) {
|
||||
vib->extent = (s32)subVib->vibratoExtentTarget;
|
||||
vib->depthChangeTimer--;
|
||||
} else if (subVib->vibratoDepthTarget != (s32)vib->depth) {
|
||||
if ((vib->depthChangeTimer = subVib->vibratoDepthChangeDelay) == 0) {
|
||||
vib->depth = (s32)subVib->vibratoDepthTarget;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -153,17 +153,17 @@ f32 AudioEffects_GetVibratoFreqScale(VibratoState* vib) {
|
||||
}
|
||||
}
|
||||
|
||||
if (vib->extent == 0.0f) {
|
||||
if (vib->depth == 0.0f) {
|
||||
return 1.0f;
|
||||
}
|
||||
|
||||
pitchChange = AudioEffects_GetVibratoPitchChange(vib) + 32768.0f;
|
||||
scaledExtent = vib->extent / 4096.0f;
|
||||
extent = scaledExtent + 1.0f;
|
||||
invExtent = 1.0f / extent;
|
||||
scaledDepth = vib->depth / 4096.0f;
|
||||
depth = scaledDepth + 1.0f;
|
||||
invDepth = 1.0f / depth;
|
||||
|
||||
// inverse linear interpolation
|
||||
result = 1.0f / ((extent - invExtent) * pitchChange / 65536.0f + invExtent);
|
||||
result = 1.0f / ((depth - invDepth) * pitchChange / 65536.0f + invDepth);
|
||||
|
||||
activeVibratoFreqScaleSum += result;
|
||||
activeVibratoCount++;
|
||||
@@ -196,10 +196,10 @@ void AudioEffects_NoteVibratoInit(Note* note) {
|
||||
|
||||
subVib = vib->vibSubStruct;
|
||||
|
||||
if ((vib->extentChangeTimer = subVib->vibratoExtentChangeDelay) == 0) {
|
||||
vib->extent = (s32)subVib->vibratoExtentTarget;
|
||||
if ((vib->depthChangeTimer = subVib->vibratoDepthChangeDelay) == 0) {
|
||||
vib->depth = (s32)subVib->vibratoDepthTarget;
|
||||
} else {
|
||||
vib->extent = (s32)subVib->vibratoExtentStart;
|
||||
vib->depth = (s32)subVib->vibratoDepthStart;
|
||||
}
|
||||
|
||||
if ((vib->rateChangeTimer = subVib->vibratoRateChangeDelay) == 0) {
|
||||
|
||||
@@ -836,7 +836,7 @@ void AudioHeap_ClearAiBuffers(void) {
|
||||
s32 curAiBufferIndex = gAudioCtx.curAiBufferIndex;
|
||||
s32 i;
|
||||
|
||||
gAudioCtx.aiBufNumSamples[curAiBufferIndex] = gAudioCtx.audioBufferParameters.numSamplesPerFrameMin;
|
||||
gAudioCtx.numSamplesPerFrame[curAiBufferIndex] = gAudioCtx.audioBufferParameters.numSamplesPerFrameMin;
|
||||
|
||||
for (i = 0; i < AIBUF_LEN; i++) {
|
||||
gAudioCtx.aiBuffers[curAiBufferIndex][i] = 0;
|
||||
@@ -905,8 +905,8 @@ s32 AudioHeap_ResetStep(void) {
|
||||
case 1:
|
||||
AudioHeap_Init();
|
||||
gAudioCtx.resetStatus = 0;
|
||||
for (i = 0; i < ARRAY_COUNT(gAudioCtx.aiBufNumSamples); i++) {
|
||||
gAudioCtx.aiBufNumSamples[i] = gAudioCtx.audioBufferParameters.numSamplesPerFrameMax;
|
||||
for (i = 0; i < ARRAY_COUNT(gAudioCtx.numSamplesPerFrame); i++) {
|
||||
gAudioCtx.numSamplesPerFrame[i] = gAudioCtx.audioBufferParameters.numSamplesPerFrameMax;
|
||||
for (j = 0; j < AIBUF_LEN; j++) {
|
||||
gAudioCtx.aiBuffers[i][j] = 0;
|
||||
}
|
||||
@@ -932,7 +932,7 @@ void AudioHeap_Init(void) {
|
||||
s32 reverbIndex;
|
||||
s32 i;
|
||||
s32 pad2;
|
||||
AudioSpec* spec = &gAudioSpecs[gAudioCtx.audioResetSpecIdToLoad]; // Audio Specifications
|
||||
AudioSpec* spec = &gAudioSpecs[gAudioCtx.specId]; // Audio Specifications
|
||||
|
||||
gAudioCtx.sampleDmaCount = 0;
|
||||
|
||||
@@ -970,15 +970,15 @@ void AudioHeap_Init(void) {
|
||||
gAudioCtx.audioBufferParameters.numSequencePlayers = 5;
|
||||
}
|
||||
|
||||
gAudioCtx.unk_29BC = 8;
|
||||
gAudioCtx.numAbiCmdsMax = 8;
|
||||
gAudioCtx.unk_2 = spec->unk_14;
|
||||
gAudioCtx.tempoInternalToExternal =
|
||||
gAudioCtx.maxTempo =
|
||||
(u32)(gAudioCtx.audioBufferParameters.updatesPerFrame * 2880000.0f / gTatumsPerBeat / gAudioCtx.unk_2960);
|
||||
|
||||
gAudioCtx.unk_2870 = gAudioCtx.refreshRate;
|
||||
gAudioCtx.unk_2870 *= gAudioCtx.audioBufferParameters.updatesPerFrame;
|
||||
gAudioCtx.unk_2870 /= gAudioCtx.audioBufferParameters.aiSamplingFreq;
|
||||
gAudioCtx.unk_2870 /= gAudioCtx.tempoInternalToExternal;
|
||||
gAudioCtx.unk_2870 /= gAudioCtx.maxTempo;
|
||||
|
||||
gAudioCtx.audioBufferParameters.specUnk4 = spec->unk_04;
|
||||
gAudioCtx.audioBufferParameters.numSamplesPerFrameTarget *= gAudioCtx.audioBufferParameters.specUnk4;
|
||||
|
||||
@@ -1212,12 +1212,12 @@ void AudioLoad_Init(void* heap, size_t heapSize) {
|
||||
s32 i;
|
||||
s32 j;
|
||||
|
||||
gCustomAudioUpdateFunction = NULL;
|
||||
gCustomAudioReverbFunction = NULL;
|
||||
gCustomAudioSynthFunction = NULL;
|
||||
gAudioCustomUpdateFunction = NULL;
|
||||
gAudioCustomReverbFunction = NULL;
|
||||
gAudioCustomSynthFunction = NULL;
|
||||
|
||||
for (i = 0; i < ARRAY_COUNT(gAudioCtx.unk_29A8); i++) {
|
||||
gAudioCtx.unk_29A8[i] = NULL;
|
||||
for (i = 0; i < ARRAY_COUNT(gAudioCtx.customSeqFunctions); i++) {
|
||||
gAudioCtx.customSeqFunctions[i] = NULL;
|
||||
}
|
||||
|
||||
gAudioCtx.resetTimer = 0;
|
||||
@@ -1248,8 +1248,8 @@ void AudioLoad_Init(void* heap, size_t heapSize) {
|
||||
|
||||
AudioThread_InitMesgQueues();
|
||||
|
||||
for (i = 0; i < ARRAY_COUNT(gAudioCtx.aiBufNumSamples); i++) {
|
||||
gAudioCtx.aiBufNumSamples[i] = 0xA0;
|
||||
for (i = 0; i < ARRAY_COUNT(gAudioCtx.numSamplesPerFrame); i++) {
|
||||
gAudioCtx.numSamplesPerFrame[i] = 0xA0;
|
||||
}
|
||||
|
||||
gAudioCtx.totalTaskCount = 0;
|
||||
@@ -1301,7 +1301,7 @@ void AudioLoad_Init(void* heap, size_t heapSize) {
|
||||
|
||||
gAudioCtx.numSequences = gAudioCtx.sequenceTable->numEntries;
|
||||
|
||||
gAudioCtx.audioResetSpecIdToLoad = 0;
|
||||
gAudioCtx.specId = 0;
|
||||
gAudioCtx.resetStatus = 1; // Set reset to immediately initialize the audio heap
|
||||
AudioHeap_ResetStep();
|
||||
|
||||
|
||||
@@ -309,7 +309,7 @@ void AudioPlayback_ProcessNotes(void) {
|
||||
subAttrs.combFilterGain = channel->combFilterGain;
|
||||
bookOffset = channel->bookOffset & 0x7;
|
||||
|
||||
if (channel->seqPlayer->muted && (channel->muteFlags & MUTE_FLAGS_3)) {
|
||||
if (channel->seqPlayer->muted && (channel->muteFlags & MUTE_FLAGS_STOP_SAMPLES)) {
|
||||
subAttrs.frequency = 0.0f;
|
||||
subAttrs.velocity = 0.0f;
|
||||
}
|
||||
@@ -531,7 +531,7 @@ void AudioPlayback_SeqLayerDecayRelease(SequenceLayer* layer, s32 target) {
|
||||
|
||||
attrs->combFilterGain = channel->combFilterGain;
|
||||
attrs->combFilterSize = channel->combFilterSize;
|
||||
if (channel->seqPlayer->muted && (channel->muteFlags & MUTE_FLAGS_3)) {
|
||||
if (channel->seqPlayer->muted && (channel->muteFlags & MUTE_FLAGS_STOP_SAMPLES)) {
|
||||
note->sampleState.bitField0.finished = true;
|
||||
}
|
||||
|
||||
|
||||
@@ -123,7 +123,7 @@ u8 sSeqInstructionArgsTable[] = {
|
||||
CMD_ARGS_1(u8), // 0xD5 ()
|
||||
CMD_ARGS_1(u8), // 0xD6 ()
|
||||
CMD_ARGS_1(u8), // 0xD7 (channel: set vibrato rate)
|
||||
CMD_ARGS_1(u8), // 0xD8 (channel: set vibrato extent)
|
||||
CMD_ARGS_1(u8), // 0xD8 (channel: set vibrato depth)
|
||||
CMD_ARGS_1(u8), // 0xD9 (channel: set decay index)
|
||||
CMD_ARGS_1(s16), // 0xDA (channel: set envelope)
|
||||
CMD_ARGS_1(u8), // 0xDB (channel: transpose)
|
||||
@@ -133,7 +133,7 @@ u8 sSeqInstructionArgsTable[] = {
|
||||
CMD_ARGS_1(u8), // 0xDF (channel: set volume)
|
||||
CMD_ARGS_1(u8), // 0xE0 (channel: set volume scale)
|
||||
CMD_ARGS_3(u8, u8, u8), // 0xE1 (channel: set vibratorate linear)
|
||||
CMD_ARGS_3(u8, u8, u8), // 0xE2 (channel: set vibrato extent linear)
|
||||
CMD_ARGS_3(u8, u8, u8), // 0xE2 (channel: set vibrato depth linear)
|
||||
CMD_ARGS_1(u8), // 0xE3 (channel: set vibrato delay)
|
||||
CMD_ARGS_0(), // 0xE4 (channel: dyncall)
|
||||
CMD_ARGS_1(u8), // 0xE5 (channel: set reverb index)
|
||||
@@ -276,7 +276,7 @@ void AudioSeq_InitSequenceChannel(SequenceChannel* channel) {
|
||||
channel->enabled = false;
|
||||
channel->finished = false;
|
||||
channel->stopScript = false;
|
||||
channel->stopSomething2 = false;
|
||||
channel->muted = false;
|
||||
channel->hasInstrument = false;
|
||||
channel->stereoHeadsetEffects = false;
|
||||
channel->transposition = 0;
|
||||
@@ -302,10 +302,10 @@ void AudioSeq_InitSequenceChannel(SequenceChannel* channel) {
|
||||
channel->adsr.sustain = 0;
|
||||
channel->vibrato.vibratoRateTarget = 0x800;
|
||||
channel->vibrato.vibratoRateStart = 0x800;
|
||||
channel->vibrato.vibratoExtentTarget = 0;
|
||||
channel->vibrato.vibratoExtentStart = 0;
|
||||
channel->vibrato.vibratoDepthTarget = 0;
|
||||
channel->vibrato.vibratoDepthStart = 0;
|
||||
channel->vibrato.vibratoRateChangeDelay = 0;
|
||||
channel->vibrato.vibratoExtentChangeDelay = 0;
|
||||
channel->vibrato.vibratoDepthChangeDelay = 0;
|
||||
channel->vibrato.vibratoDelay = 0;
|
||||
channel->filter = NULL;
|
||||
channel->combFilterGain = 0;
|
||||
@@ -314,8 +314,8 @@ void AudioSeq_InitSequenceChannel(SequenceChannel* channel) {
|
||||
channel->volumeScale = 1.0f;
|
||||
channel->freqScale = 1.0f;
|
||||
|
||||
for (i = 0; i < ARRAY_COUNT(channel->soundScriptIO); i++) {
|
||||
channel->soundScriptIO[i] = SEQ_IO_VAL_NONE;
|
||||
for (i = 0; i < ARRAY_COUNT(channel->seqScriptIO); i++) {
|
||||
channel->seqScriptIO[i] = SEQ_IO_VAL_NONE;
|
||||
}
|
||||
|
||||
channel->unused = false;
|
||||
@@ -348,7 +348,7 @@ s32 AudioSeq_SeqChannelSetLayer(SequenceChannel* channel, s32 layerIndex) {
|
||||
layer->targetReverbVol = channel->targetReverbVol;
|
||||
layer->enabled = true;
|
||||
layer->finished = false;
|
||||
layer->stopSomething = false;
|
||||
layer->muted = false;
|
||||
layer->continuousNotes = false;
|
||||
layer->bit3 = false;
|
||||
layer->ignoreDrumPan = false;
|
||||
@@ -370,10 +370,10 @@ s32 AudioSeq_SeqChannelSetLayer(SequenceChannel* channel, s32 layerIndex) {
|
||||
layer->unk_0A.asByte = 0xFFFF;
|
||||
layer->vibrato.vibratoRateTarget = 0x800;
|
||||
layer->vibrato.vibratoRateStart = 0x800;
|
||||
layer->vibrato.vibratoExtentTarget = 0;
|
||||
layer->vibrato.vibratoExtentStart = 0;
|
||||
layer->vibrato.vibratoDepthTarget = 0;
|
||||
layer->vibrato.vibratoDepthStart = 0;
|
||||
layer->vibrato.vibratoRateChangeDelay = 0;
|
||||
layer->vibrato.vibratoExtentChangeDelay = 0;
|
||||
layer->vibrato.vibratoDepthChangeDelay = 0;
|
||||
layer->vibrato.vibratoDelay = 0;
|
||||
layer->freqScale = 1.0f;
|
||||
layer->bend = 1.0f;
|
||||
@@ -562,9 +562,9 @@ void AudioSeq_SeqLayerProcessScript(SequenceLayer* layer) {
|
||||
|
||||
if (layer->delay > 1) {
|
||||
layer->delay--;
|
||||
if (!layer->stopSomething && (layer->delay <= layer->gateDelay)) {
|
||||
if (!layer->muted && (layer->delay <= layer->gateDelay)) {
|
||||
AudioPlayback_SeqLayerNoteDecay(layer);
|
||||
layer->stopSomething = true;
|
||||
layer->muted = true;
|
||||
}
|
||||
return;
|
||||
}
|
||||
@@ -590,7 +590,7 @@ void AudioSeq_SeqLayerProcessScript(SequenceLayer* layer) {
|
||||
AudioSeq_SeqLayerProcessScriptStep5(layer, cmd);
|
||||
}
|
||||
|
||||
if (layer->stopSomething == true) {
|
||||
if (layer->muted == true) {
|
||||
if ((layer->note != NULL) || layer->continuousNotes) {
|
||||
AudioPlayback_SeqLayerNoteDecay(layer);
|
||||
}
|
||||
@@ -856,7 +856,7 @@ s32 AudioSeq_SeqLayerProcessScriptStep4(SequenceLayer* layer, s32 cmd) {
|
||||
|
||||
drum = AudioPlayback_GetDrum(channel->fontId, semitone);
|
||||
if (drum == NULL) {
|
||||
layer->stopSomething = true;
|
||||
layer->muted = true;
|
||||
layer->delay2 = layer->delay;
|
||||
return PROCESS_SCRIPT_END;
|
||||
}
|
||||
@@ -879,7 +879,7 @@ s32 AudioSeq_SeqLayerProcessScriptStep4(SequenceLayer* layer, s32 cmd) {
|
||||
|
||||
soundEffect = AudioPlayback_GetSoundEffect(channel->fontId, sfxId);
|
||||
if (soundEffect == NULL) {
|
||||
layer->stopSomething = true;
|
||||
layer->muted = true;
|
||||
layer->delay2 = layer->delay + 1;
|
||||
return PROCESS_SCRIPT_END;
|
||||
}
|
||||
@@ -895,7 +895,7 @@ s32 AudioSeq_SeqLayerProcessScriptStep4(SequenceLayer* layer, s32 cmd) {
|
||||
|
||||
layer->semitone = semitone;
|
||||
if (semitone >= 0x80) {
|
||||
layer->stopSomething = true;
|
||||
layer->muted = true;
|
||||
return PROCESS_SCRIPT_END;
|
||||
}
|
||||
|
||||
@@ -948,7 +948,7 @@ s32 AudioSeq_SeqLayerProcessScriptStep4(SequenceLayer* layer, s32 cmd) {
|
||||
portamento->extent = (freqScale2 / freqScale) - 1.0f;
|
||||
|
||||
if (PORTAMENTO_IS_SPECIAL(*portamento)) {
|
||||
speed = seqPlayer->tempo * 0x8000 / gAudioCtx.tempoInternalToExternal;
|
||||
speed = seqPlayer->tempo * 0x8000 / gAudioCtx.maxTempo;
|
||||
if (layer->delay != 0) {
|
||||
speed = speed * 0x100 / (layer->delay * layer->portamentoTime);
|
||||
}
|
||||
@@ -1011,7 +1011,7 @@ s32 AudioSeq_SeqLayerProcessScriptStep4(SequenceLayer* layer, s32 cmd) {
|
||||
// (It's a bit unclear if 'portamento' has actually always been
|
||||
// set when this is reached...)
|
||||
if (PORTAMENTO_IS_SPECIAL(*portamento)) {
|
||||
speed2 = seqPlayer->tempo * 0x8000 / gAudioCtx.tempoInternalToExternal;
|
||||
speed2 = seqPlayer->tempo * 0x8000 / gAudioCtx.maxTempo;
|
||||
speed2 = speed2 * 0x100 / (layer->delay * layer->portamentoTime);
|
||||
if (speed2 >= 0x7FFF) {
|
||||
speed2 = 0x7FFF;
|
||||
@@ -1036,12 +1036,12 @@ s32 AudioSeq_SeqLayerProcessScriptStep3(SequenceLayer* layer, s32 cmd) {
|
||||
|
||||
if (cmd == 0xC0) { // layer: delay
|
||||
layer->delay = AudioSeq_ScriptReadCompressedU16(state);
|
||||
layer->stopSomething = true;
|
||||
layer->muted = true;
|
||||
layer->bit1 = false;
|
||||
return PROCESS_SCRIPT_END;
|
||||
}
|
||||
|
||||
layer->stopSomething = false;
|
||||
layer->muted = false;
|
||||
|
||||
if (channel->largeNotes == true) {
|
||||
switch (cmd & 0xC0) {
|
||||
@@ -1124,14 +1124,14 @@ s32 AudioSeq_SeqLayerProcessScriptStep3(SequenceLayer* layer, s32 cmd) {
|
||||
}
|
||||
}
|
||||
|
||||
if ((seqPlayer->muted && (channel->muteFlags & (MUTE_FLAGS_STOP_NOTES | MUTE_FLAGS_4))) ||
|
||||
channel->stopSomething2) {
|
||||
layer->stopSomething = true;
|
||||
if ((seqPlayer->muted && (channel->muteFlags & (MUTE_FLAGS_STOP_NOTES | MUTE_FLAGS_STOP_LAYER))) ||
|
||||
channel->muted) {
|
||||
layer->muted = true;
|
||||
return PROCESS_SCRIPT_END;
|
||||
}
|
||||
|
||||
if (seqPlayer->skipTicks != 0) {
|
||||
layer->stopSomething = true;
|
||||
layer->muted = true;
|
||||
return PROCESS_SCRIPT_END;
|
||||
}
|
||||
|
||||
@@ -1380,11 +1380,11 @@ void AudioSeq_SequenceChannelProcessScript(SequenceChannel* channel) {
|
||||
channel->adsr.decayIndex = cmd;
|
||||
break;
|
||||
|
||||
case 0xD8: // channel: set vibrato extent
|
||||
case 0xD8: // channel: set vibrato depth
|
||||
cmd = (u8)cmdArgs[0];
|
||||
channel->vibrato.vibratoExtentTarget = cmd * 8;
|
||||
channel->vibrato.vibratoExtentStart = 0;
|
||||
channel->vibrato.vibratoExtentChangeDelay = 0;
|
||||
channel->vibrato.vibratoDepthTarget = cmd * 8;
|
||||
channel->vibrato.vibratoDepthStart = 0;
|
||||
channel->vibrato.vibratoDepthChangeDelay = 0;
|
||||
break;
|
||||
|
||||
case 0xD7: // channel: set vibrato rate
|
||||
@@ -1394,13 +1394,13 @@ void AudioSeq_SequenceChannelProcessScript(SequenceChannel* channel) {
|
||||
channel->vibrato.vibratoRateStart = cmd * 32;
|
||||
break;
|
||||
|
||||
case 0xE2: // channel: set vibrato extent linear
|
||||
case 0xE2: // channel: set vibrato depth linear
|
||||
cmd = (u8)cmdArgs[0];
|
||||
channel->vibrato.vibratoExtentStart = cmd * 8;
|
||||
channel->vibrato.vibratoDepthStart = cmd * 8;
|
||||
cmd = (u8)cmdArgs[1];
|
||||
channel->vibrato.vibratoExtentTarget = cmd * 8;
|
||||
channel->vibrato.vibratoDepthTarget = cmd * 8;
|
||||
cmd = (u8)cmdArgs[2];
|
||||
channel->vibrato.vibratoExtentChangeDelay = cmd * 16;
|
||||
channel->vibrato.vibratoDepthChangeDelay = cmd * 16;
|
||||
break;
|
||||
|
||||
case 0xE1: // channel: set vibratorate linear
|
||||
@@ -1559,9 +1559,9 @@ void AudioSeq_SequenceChannelProcessScript(SequenceChannel* channel) {
|
||||
break;
|
||||
|
||||
case 0xEC: // channel: reset vibrato
|
||||
channel->vibrato.vibratoExtentTarget = 0;
|
||||
channel->vibrato.vibratoExtentStart = 0;
|
||||
channel->vibrato.vibratoExtentChangeDelay = 0;
|
||||
channel->vibrato.vibratoDepthTarget = 0;
|
||||
channel->vibrato.vibratoDepthStart = 0;
|
||||
channel->vibrato.vibratoDepthChangeDelay = 0;
|
||||
channel->vibrato.vibratoRateTarget = 0;
|
||||
channel->vibrato.vibratoRateStart = 0;
|
||||
channel->vibrato.vibratoRateChangeDelay = 0;
|
||||
@@ -1667,9 +1667,9 @@ void AudioSeq_SequenceChannelProcessScript(SequenceChannel* channel) {
|
||||
case 0xBE: // channel:
|
||||
if (cmdArgs[0] < 5) {
|
||||
if (1) {}
|
||||
if (gAudioCtx.unk_29A8[cmdArgs[0]] != NULL) {
|
||||
gCustomAudioSeqFunction = gAudioCtx.unk_29A8[cmdArgs[0]];
|
||||
scriptState->value = gCustomAudioSeqFunction(scriptState->value, channel);
|
||||
if (gAudioCtx.customSeqFunctions[cmdArgs[0]] != NULL) {
|
||||
gAudioCustomSeqFunction = gAudioCtx.customSeqFunctions[cmdArgs[0]];
|
||||
scriptState->value = gAudioCustomSeqFunction(scriptState->value, channel);
|
||||
}
|
||||
}
|
||||
break;
|
||||
@@ -1698,13 +1698,13 @@ void AudioSeq_SequenceChannelProcessScript(SequenceChannel* channel) {
|
||||
break;
|
||||
|
||||
case 0xA5: // channel:
|
||||
scriptState->value += channel->unk_11;
|
||||
scriptState->value += channel->channelIndex;
|
||||
break;
|
||||
|
||||
case 0xA6: // channel:
|
||||
cmd = (u8)cmdArgs[0];
|
||||
cmdArgU16 = (u16)cmdArgs[1];
|
||||
seqData = seqPlayer->seqData + (u32)(cmdArgU16 + channel->unk_11);
|
||||
seqData = seqPlayer->seqData + (u32)(cmdArgU16 + channel->channelIndex);
|
||||
seqData[0] = (u8)scriptState->value + cmd;
|
||||
break;
|
||||
|
||||
@@ -1766,7 +1766,7 @@ void AudioSeq_SequenceChannelProcessScript(SequenceChannel* channel) {
|
||||
break;
|
||||
|
||||
case 0x70: // channel: io write value
|
||||
channel->soundScriptIO[lowBits] = scriptState->value;
|
||||
channel->seqScriptIO[lowBits] = scriptState->value;
|
||||
break;
|
||||
|
||||
case 0x78: // channel: set layer relative
|
||||
@@ -1792,26 +1792,26 @@ void AudioSeq_SequenceChannelProcessScript(SequenceChannel* channel) {
|
||||
|
||||
case 0x10: // channel: load sample
|
||||
if (lowBits < 8) {
|
||||
channel->soundScriptIO[lowBits] = SEQ_IO_VAL_NONE;
|
||||
if (AudioLoad_SlowLoadSample(channel->fontId, scriptState->value,
|
||||
&channel->soundScriptIO[lowBits]) == -1) {}
|
||||
channel->seqScriptIO[lowBits] = SEQ_IO_VAL_NONE;
|
||||
if (AudioLoad_SlowLoadSample(channel->fontId, scriptState->value, &channel->seqScriptIO[lowBits]) ==
|
||||
-1) {}
|
||||
} else {
|
||||
lowBits -= 8;
|
||||
channel->soundScriptIO[lowBits] = SEQ_IO_VAL_NONE;
|
||||
channel->seqScriptIO[lowBits] = SEQ_IO_VAL_NONE;
|
||||
if (AudioLoad_SlowLoadSample(channel->fontId, channel->unk_22 + 0x100,
|
||||
&channel->soundScriptIO[lowBits]) == -1) {}
|
||||
&channel->seqScriptIO[lowBits]) == -1) {}
|
||||
}
|
||||
break;
|
||||
|
||||
case 0x60: // channel: io read value
|
||||
scriptState->value = channel->soundScriptIO[lowBits];
|
||||
scriptState->value = channel->seqScriptIO[lowBits];
|
||||
if (lowBits < 2) {
|
||||
channel->soundScriptIO[lowBits] = SEQ_IO_VAL_NONE;
|
||||
channel->seqScriptIO[lowBits] = SEQ_IO_VAL_NONE;
|
||||
}
|
||||
break;
|
||||
|
||||
case 0x50: // channel: io read value subtract
|
||||
scriptState->value -= channel->soundScriptIO[lowBits];
|
||||
scriptState->value -= channel->seqScriptIO[lowBits];
|
||||
break;
|
||||
|
||||
case 0x20: // channel: start channel
|
||||
@@ -1821,12 +1821,12 @@ void AudioSeq_SequenceChannelProcessScript(SequenceChannel* channel) {
|
||||
|
||||
case 0x30: // channel: io write value 2
|
||||
cmd = AudioSeq_ScriptReadU8(scriptState);
|
||||
seqPlayer->channels[lowBits]->soundScriptIO[cmd] = scriptState->value;
|
||||
seqPlayer->channels[lowBits]->seqScriptIO[cmd] = scriptState->value;
|
||||
break;
|
||||
|
||||
case 0x40: // channel: io read value 2
|
||||
cmd = AudioSeq_ScriptReadU8(scriptState);
|
||||
scriptState->value = seqPlayer->channels[lowBits]->soundScriptIO[cmd];
|
||||
scriptState->value = seqPlayer->channels[lowBits]->seqScriptIO[cmd];
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -1879,18 +1879,18 @@ void AudioSeq_SequencePlayerProcessSequence(SequencePlayer* seqPlayer) {
|
||||
|
||||
seqPlayer->scriptCounter++;
|
||||
|
||||
tempoChange = seqPlayer->tempo + seqPlayer->unk_0C;
|
||||
if (tempoChange > gAudioCtx.tempoInternalToExternal) {
|
||||
tempoChange = gAudioCtx.tempoInternalToExternal;
|
||||
tempoChange = seqPlayer->tempo + seqPlayer->tempoChange;
|
||||
if (tempoChange > gAudioCtx.maxTempo) {
|
||||
tempoChange = gAudioCtx.maxTempo;
|
||||
}
|
||||
|
||||
seqPlayer->tempoAcc += tempoChange;
|
||||
|
||||
if (seqPlayer->tempoAcc < gAudioCtx.tempoInternalToExternal) {
|
||||
if (seqPlayer->tempoAcc < gAudioCtx.maxTempo) {
|
||||
return;
|
||||
}
|
||||
|
||||
seqPlayer->tempoAcc -= (u16)gAudioCtx.tempoInternalToExternal;
|
||||
seqPlayer->tempoAcc -= (u16)gAudioCtx.maxTempo;
|
||||
seqPlayer->unk_16++;
|
||||
|
||||
if (seqPlayer->stopScript == true) {
|
||||
@@ -1943,8 +1943,8 @@ void AudioSeq_SequencePlayerProcessSequence(SequencePlayer* seqPlayer) {
|
||||
|
||||
case 0xDD: // seqPlayer: set tempo
|
||||
seqPlayer->tempo = AudioSeq_ScriptReadU8(seqScript) * TATUMS_PER_BEAT;
|
||||
if (seqPlayer->tempo > gAudioCtx.tempoInternalToExternal) {
|
||||
seqPlayer->tempo = gAudioCtx.tempoInternalToExternal;
|
||||
if (seqPlayer->tempo > gAudioCtx.maxTempo) {
|
||||
seqPlayer->tempo = gAudioCtx.maxTempo;
|
||||
}
|
||||
|
||||
if ((s16)seqPlayer->tempo <= 0) {
|
||||
@@ -1953,7 +1953,7 @@ void AudioSeq_SequencePlayerProcessSequence(SequencePlayer* seqPlayer) {
|
||||
break;
|
||||
|
||||
case 0xDC: // seqPlayer: add tempo
|
||||
seqPlayer->unk_0C = (s8)AudioSeq_ScriptReadU8(seqScript) * TATUMS_PER_BEAT;
|
||||
seqPlayer->tempoChange = (s8)AudioSeq_ScriptReadU8(seqScript) * TATUMS_PER_BEAT;
|
||||
break;
|
||||
|
||||
case 0xDA: // seqPlayer: change volume
|
||||
@@ -1961,14 +1961,14 @@ void AudioSeq_SequencePlayerProcessSequence(SequencePlayer* seqPlayer) {
|
||||
temp = AudioSeq_ScriptReadS16(seqScript);
|
||||
switch (cmd) {
|
||||
case SEQPLAYER_STATE_0:
|
||||
case SEQPLAYER_STATE_1:
|
||||
if (seqPlayer->state != SEQPLAYER_STATE_2) {
|
||||
seqPlayer->fadeTimerUnkEu = temp;
|
||||
case SEQPLAYER_STATE_FADE_IN:
|
||||
if (seqPlayer->state != SEQPLAYER_STATE_FADE_OUT) {
|
||||
seqPlayer->storedFadeTimer = temp;
|
||||
seqPlayer->state = cmd;
|
||||
}
|
||||
break;
|
||||
|
||||
case SEQPLAYER_STATE_2:
|
||||
case SEQPLAYER_STATE_FADE_OUT:
|
||||
seqPlayer->fadeTimer = temp;
|
||||
seqPlayer->state = cmd;
|
||||
seqPlayer->fadeVelocity = (0.0f - seqPlayer->fadeVolume) / (s32)seqPlayer->fadeTimer;
|
||||
@@ -1979,13 +1979,13 @@ void AudioSeq_SequencePlayerProcessSequence(SequencePlayer* seqPlayer) {
|
||||
case 0xDB: // seqPlayer: set volume
|
||||
value = AudioSeq_ScriptReadU8(seqScript);
|
||||
switch (seqPlayer->state) {
|
||||
case SEQPLAYER_STATE_1:
|
||||
case SEQPLAYER_STATE_FADE_IN:
|
||||
seqPlayer->state = SEQPLAYER_STATE_0;
|
||||
seqPlayer->fadeVolume = 0.0f;
|
||||
// fallthrough
|
||||
case SEQPLAYER_STATE_0:
|
||||
seqPlayer->fadeTimer = seqPlayer->fadeTimerUnkEu;
|
||||
if (seqPlayer->fadeTimerUnkEu != 0) {
|
||||
seqPlayer->fadeTimer = seqPlayer->storedFadeTimer;
|
||||
if (seqPlayer->storedFadeTimer != 0) {
|
||||
seqPlayer->fadeVelocity =
|
||||
((value / 127.0f) - seqPlayer->fadeVolume) / (s32)seqPlayer->fadeTimer;
|
||||
} else {
|
||||
@@ -1993,7 +1993,7 @@ void AudioSeq_SequencePlayerProcessSequence(SequencePlayer* seqPlayer) {
|
||||
}
|
||||
break;
|
||||
|
||||
case SEQPLAYER_STATE_2:
|
||||
case SEQPLAYER_STATE_FADE_OUT:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
@@ -2104,7 +2104,7 @@ void AudioSeq_SequencePlayerProcessSequence(SequencePlayer* seqPlayer) {
|
||||
cmd = AudioSeq_ScriptReadU8(seqScript);
|
||||
if (cmd == 0xFF) {
|
||||
cmd = seqPlayer->playerIndex;
|
||||
if (seqPlayer->state == SEQPLAYER_STATE_2) {
|
||||
if (seqPlayer->state == SEQPLAYER_STATE_FADE_OUT) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -2123,7 +2123,7 @@ void AudioSeq_SequencePlayerProcessSequence(SequencePlayer* seqPlayer) {
|
||||
temp = *new_var;
|
||||
|
||||
for (i = 0; i < ARRAY_COUNT(seqPlayer->channels); i++) {
|
||||
seqPlayer->channels[i]->stopSomething2 = temp & 1;
|
||||
seqPlayer->channels[i]->muted = temp & 1;
|
||||
temp = temp >> 1;
|
||||
}
|
||||
}
|
||||
@@ -2141,17 +2141,17 @@ void AudioSeq_SequencePlayerProcessSequence(SequencePlayer* seqPlayer) {
|
||||
break;
|
||||
|
||||
case 0x50: // seqPlayer: io read value subtract
|
||||
seqScript->value -= seqPlayer->soundScriptIO[cmdLowBits];
|
||||
seqScript->value -= seqPlayer->seqScriptIO[cmdLowBits];
|
||||
break;
|
||||
|
||||
case 0x70: // seqPlayer: io write value
|
||||
seqPlayer->soundScriptIO[cmdLowBits] = seqScript->value;
|
||||
seqPlayer->seqScriptIO[cmdLowBits] = seqScript->value;
|
||||
break;
|
||||
|
||||
case 0x80: // seqPlayer: io read value
|
||||
seqScript->value = seqPlayer->soundScriptIO[cmdLowBits];
|
||||
seqScript->value = seqPlayer->seqScriptIO[cmdLowBits];
|
||||
if (cmdLowBits < 2) {
|
||||
seqPlayer->soundScriptIO[cmdLowBits] = SEQ_IO_VAL_NONE;
|
||||
seqPlayer->seqScriptIO[cmdLowBits] = SEQ_IO_VAL_NONE;
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -2173,14 +2173,14 @@ void AudioSeq_SequencePlayerProcessSequence(SequencePlayer* seqPlayer) {
|
||||
cmd = AudioSeq_ScriptReadU8(seqScript);
|
||||
temp = AudioSeq_ScriptReadS16(seqScript);
|
||||
data2 = &seqPlayer->seqData[temp];
|
||||
AudioLoad_SlowLoadSeq(cmd, data2, &seqPlayer->soundScriptIO[cmdLowBits]);
|
||||
AudioLoad_SlowLoadSeq(cmd, data2, &seqPlayer->seqScriptIO[cmdLowBits]);
|
||||
break;
|
||||
|
||||
case 0x60: // seqPlayer: async load
|
||||
cmd = AudioSeq_ScriptReadU8(seqScript);
|
||||
value = cmd;
|
||||
temp = AudioSeq_ScriptReadU8(seqScript);
|
||||
AudioLoad_ScriptLoad(value, temp, &seqPlayer->soundScriptIO[cmdLowBits]);
|
||||
AudioLoad_ScriptLoad(value, temp, &seqPlayer->seqScriptIO[cmdLowBits]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -2220,17 +2220,17 @@ void AudioSeq_SkipForwardSequence(SequencePlayer* seqPlayer) {
|
||||
}
|
||||
|
||||
void AudioSeq_ResetSequencePlayer(SequencePlayer* seqPlayer) {
|
||||
s32 i;
|
||||
s32 channelIndex;
|
||||
|
||||
AudioSeq_SequencePlayerDisable(seqPlayer);
|
||||
seqPlayer->stopScript = false;
|
||||
seqPlayer->delay = 0;
|
||||
seqPlayer->state = SEQPLAYER_STATE_1;
|
||||
seqPlayer->state = SEQPLAYER_STATE_FADE_IN;
|
||||
seqPlayer->fadeTimer = 0;
|
||||
seqPlayer->fadeTimerUnkEu = 0;
|
||||
seqPlayer->storedFadeTimer = 0;
|
||||
seqPlayer->tempoAcc = 0;
|
||||
seqPlayer->tempo = 120 * TATUMS_PER_BEAT; // 120 BPM
|
||||
seqPlayer->unk_0C = 0;
|
||||
seqPlayer->tempoChange = 0;
|
||||
seqPlayer->transposition = 0;
|
||||
seqPlayer->noteAllocPolicy = 0;
|
||||
seqPlayer->shortNoteVelocityTable = gDefaultShortNoteVelocityTable;
|
||||
@@ -2242,32 +2242,32 @@ void AudioSeq_ResetSequencePlayer(SequencePlayer* seqPlayer) {
|
||||
seqPlayer->volume = 0.0f;
|
||||
seqPlayer->muteVolumeScale = 0.5f;
|
||||
|
||||
for (i = 0; i < SEQ_NUM_CHANNELS; i++) {
|
||||
AudioSeq_InitSequenceChannel(seqPlayer->channels[i]);
|
||||
for (channelIndex = 0; channelIndex < SEQ_NUM_CHANNELS; channelIndex++) {
|
||||
AudioSeq_InitSequenceChannel(seqPlayer->channels[channelIndex]);
|
||||
}
|
||||
}
|
||||
|
||||
void AudioSeq_InitSequencePlayerChannels(s32 playerIndex) {
|
||||
void AudioSeq_InitSequencePlayerChannels(s32 seqPlayerIndex) {
|
||||
SequenceChannel* channel;
|
||||
SequencePlayer* seqPlayer = &gAudioCtx.seqPlayers[playerIndex];
|
||||
s32 i;
|
||||
s32 j;
|
||||
SequencePlayer* seqPlayer = &gAudioCtx.seqPlayers[seqPlayerIndex];
|
||||
s32 channelIndex;
|
||||
s32 layerIndex;
|
||||
|
||||
for (i = 0; i < SEQ_NUM_CHANNELS; i++) {
|
||||
seqPlayer->channels[i] = AudioHeap_AllocZeroed(&gAudioCtx.miscPool, sizeof(SequenceChannel));
|
||||
if (seqPlayer->channels[i] == NULL) {
|
||||
seqPlayer->channels[i] = &gAudioCtx.sequenceChannelNone;
|
||||
for (channelIndex = 0; channelIndex < SEQ_NUM_CHANNELS; channelIndex++) {
|
||||
seqPlayer->channels[channelIndex] = AudioHeap_AllocZeroed(&gAudioCtx.miscPool, sizeof(SequenceChannel));
|
||||
if (seqPlayer->channels[channelIndex] == NULL) {
|
||||
seqPlayer->channels[channelIndex] = &gAudioCtx.sequenceChannelNone;
|
||||
} else {
|
||||
channel = seqPlayer->channels[i];
|
||||
channel = seqPlayer->channels[channelIndex];
|
||||
channel->seqPlayer = seqPlayer;
|
||||
channel->enabled = false;
|
||||
channel->unk_11 = i;
|
||||
for (j = 0; j < ARRAY_COUNT(channel->layers); j++) {
|
||||
channel->layers[j] = NULL;
|
||||
channel->channelIndex = channelIndex;
|
||||
for (layerIndex = 0; layerIndex < ARRAY_COUNT(channel->layers); layerIndex++) {
|
||||
channel->layers[layerIndex] = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
AudioSeq_InitSequenceChannel(seqPlayer->channels[i]);
|
||||
AudioSeq_InitSequenceChannel(seqPlayer->channels[channelIndex]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2285,8 +2285,8 @@ void AudioSeq_InitSequencePlayer(SequencePlayer* seqPlayer) {
|
||||
seqPlayer->seqDmaInProgress = false;
|
||||
seqPlayer->applyBend = false;
|
||||
|
||||
for (j = 0; j < ARRAY_COUNT(seqPlayer->soundScriptIO); j++) {
|
||||
seqPlayer->soundScriptIO[j] = SEQ_IO_VAL_NONE;
|
||||
for (j = 0; j < ARRAY_COUNT(seqPlayer->seqScriptIO); j++) {
|
||||
seqPlayer->seqScriptIO[j] = SEQ_IO_VAL_NONE;
|
||||
}
|
||||
|
||||
seqPlayer->muteFlags = MUTE_FLAGS_SOFTEN | MUTE_FLAGS_STOP_NOTES;
|
||||
|
||||
@@ -866,8 +866,8 @@ Acmd* AudioSynth_ProcessSamples(s16* aiBuf, s32 numSamplesPerUpdate, Acmd* cmd,
|
||||
size = numSamplesPerUpdate * SAMPLE_SIZE;
|
||||
aInterleave(cmd++, DMEM_TEMP, DMEM_LEFT_CH, DMEM_RIGHT_CH, size);
|
||||
|
||||
if (gCustomAudioSynthFunction != NULL) {
|
||||
cmd = gCustomAudioSynthFunction(cmd, 2 * size, updateIndex);
|
||||
if (gAudioCustomSynthFunction != NULL) {
|
||||
cmd = gAudioCustomSynthFunction(cmd, 2 * size, updateIndex);
|
||||
}
|
||||
aSaveBuffer(cmd++, DMEM_TEMP, aiBuf, 2 * size);
|
||||
|
||||
@@ -1109,8 +1109,8 @@ Acmd* AudioSynth_ProcessSample(s32 noteIndex, NoteSampleState* sampleState, Note
|
||||
|
||||
case CODEC_REVERB:
|
||||
reverbAddrSrc = (void*)0xFFFFFFFF;
|
||||
if (gCustomAudioReverbFunction != NULL) {
|
||||
reverbAddrSrc = gCustomAudioReverbFunction(sample, numSamplesToLoadAdj, flags, noteIndex);
|
||||
if (gAudioCustomReverbFunction != NULL) {
|
||||
reverbAddrSrc = gAudioCustomReverbFunction(sample, numSamplesToLoadAdj, flags, noteIndex);
|
||||
}
|
||||
|
||||
if (reverbAddrSrc == (void*)0xFFFFFFFF) {
|
||||
|
||||
@@ -0,0 +1,977 @@
|
||||
/**
|
||||
* @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();
|
||||
}
|
||||
@@ -1,81 +0,0 @@
|
||||
#include "global.h"
|
||||
|
||||
#pragma GLOBAL_ASM("asm/non_matchings/code/code_80192BE0/func_80192BE0.s")
|
||||
|
||||
#pragma GLOBAL_ASM("asm/non_matchings/code/code_80192BE0/func_80192C00.s")
|
||||
|
||||
#pragma GLOBAL_ASM("asm/non_matchings/code/code_80192BE0/func_8019319C.s")
|
||||
|
||||
#pragma GLOBAL_ASM("asm/non_matchings/code/code_80192BE0/func_801936D8.s")
|
||||
|
||||
#pragma GLOBAL_ASM("asm/non_matchings/code/code_80192BE0/func_8019372C.s")
|
||||
|
||||
#pragma GLOBAL_ASM("asm/non_matchings/code/code_80192BE0/func_80193774.s")
|
||||
|
||||
#pragma GLOBAL_ASM("asm/non_matchings/code/code_80192BE0/func_8019380C.s")
|
||||
|
||||
#pragma GLOBAL_ASM("asm/non_matchings/code/code_80192BE0/func_80193858.s")
|
||||
|
||||
#pragma GLOBAL_ASM("asm/non_matchings/code/code_80192BE0/AudioThread_QueueCmdS32.s")
|
||||
|
||||
#pragma GLOBAL_ASM("asm/non_matchings/code/code_80192BE0/AudioThread_QueueCmdS8.s")
|
||||
|
||||
#pragma GLOBAL_ASM("asm/non_matchings/code/code_80192BE0/func_801938D0.s")
|
||||
|
||||
#pragma GLOBAL_ASM("asm/non_matchings/code/code_80192BE0/AudioThread_ScheduleProcessCmds.s")
|
||||
|
||||
#pragma GLOBAL_ASM("asm/non_matchings/code/code_80192BE0/func_80193990.s")
|
||||
|
||||
#pragma GLOBAL_ASM("asm/non_matchings/code/code_80192BE0/func_801939A8.s")
|
||||
|
||||
#pragma GLOBAL_ASM("asm/non_matchings/code/code_80192BE0/func_80193AEC.s")
|
||||
|
||||
#pragma GLOBAL_ASM("asm/non_matchings/code/code_80192BE0/func_80193BA0.s")
|
||||
|
||||
#pragma GLOBAL_ASM("asm/non_matchings/code/code_80192BE0/func_80193C04.s")
|
||||
|
||||
#pragma GLOBAL_ASM("asm/non_matchings/code/code_80192BE0/func_80193C24.s")
|
||||
|
||||
#pragma GLOBAL_ASM("asm/non_matchings/code/code_80192BE0/func_80193C5C.s")
|
||||
|
||||
#pragma GLOBAL_ASM("asm/non_matchings/code/code_80192BE0/func_80193CB4.s")
|
||||
|
||||
#pragma GLOBAL_ASM("asm/non_matchings/code/code_80192BE0/func_80193D08.s")
|
||||
|
||||
#pragma GLOBAL_ASM("asm/non_matchings/code/code_80192BE0/func_80193DA4.s")
|
||||
|
||||
#pragma GLOBAL_ASM("asm/non_matchings/code/code_80192BE0/func_80193DF0.s")
|
||||
|
||||
#pragma GLOBAL_ASM("asm/non_matchings/code/code_80192BE0/func_80193E44.s")
|
||||
|
||||
#pragma GLOBAL_ASM("asm/non_matchings/code/code_80192BE0/func_80193E6C.s")
|
||||
|
||||
#pragma GLOBAL_ASM("asm/non_matchings/code/code_80192BE0/func_80193E9C.s")
|
||||
|
||||
#pragma GLOBAL_ASM("asm/non_matchings/code/code_80192BE0/func_80193EA8.s")
|
||||
|
||||
#pragma GLOBAL_ASM("asm/non_matchings/code/code_80192BE0/func_80194080.s")
|
||||
|
||||
#pragma GLOBAL_ASM("asm/non_matchings/code/code_80192BE0/func_801942BC.s")
|
||||
|
||||
#pragma GLOBAL_ASM("asm/non_matchings/code/code_80192BE0/func_80194304.s")
|
||||
|
||||
#pragma GLOBAL_ASM("asm/non_matchings/code/code_80192BE0/func_80194328.s")
|
||||
|
||||
#pragma GLOBAL_ASM("asm/non_matchings/code/code_80192BE0/func_8019435C.s")
|
||||
|
||||
#pragma GLOBAL_ASM("asm/non_matchings/code/code_80192BE0/func_8019439C.s")
|
||||
|
||||
#pragma GLOBAL_ASM("asm/non_matchings/code/code_80192BE0/func_801943D0.s")
|
||||
|
||||
#pragma GLOBAL_ASM("asm/non_matchings/code/code_80192BE0/func_8019440C.s")
|
||||
|
||||
#pragma GLOBAL_ASM("asm/non_matchings/code/code_80192BE0/func_80194528.s")
|
||||
|
||||
#pragma GLOBAL_ASM("asm/non_matchings/code/code_80192BE0/func_80194548.s")
|
||||
|
||||
#pragma GLOBAL_ASM("asm/non_matchings/code/code_80192BE0/func_80194568.s")
|
||||
|
||||
#pragma GLOBAL_ASM("asm/non_matchings/code/code_80192BE0/AudioThread_NextRandom.s")
|
||||
|
||||
#pragma GLOBAL_ASM("asm/non_matchings/code/code_80192BE0/AudioThread_InitMesgQueues.s")
|
||||
@@ -2640,7 +2640,7 @@ void AudioOcarina_PlayControllerInput(u8 isOcarinaSfxSuppressedWhenCancelled) {
|
||||
// Add vibrato of the ocarina note based on the x control stick
|
||||
sCurOcarinaVibrato = ABS_ALT(sOcarinaInputStickRel.x) >> 2;
|
||||
// Sets vibrato to io port 6
|
||||
AudioThread_QueueCmdS8(0x6 << 24 | SEQ_PLAYER_SFX << 16 | SFX_CHANNEL_OCARINA << 8 | 6, sCurOcarinaVibrato);
|
||||
AUDIOCMD_CHANNEL_SET_IO(SEQ_PLAYER_SFX, SFX_CHANNEL_OCARINA, 6, sCurOcarinaVibrato);
|
||||
} else {
|
||||
// no bending or vibrato for recording state OCARINA_RECORD_SCARECROW_SPAWN
|
||||
sCurOcarinaBendIndex = 0;
|
||||
@@ -2652,10 +2652,9 @@ void AudioOcarina_PlayControllerInput(u8 isOcarinaSfxSuppressedWhenCancelled) {
|
||||
if ((sCurOcarinaPitch != OCARINA_PITCH_NONE) && (sPrevOcarinaPitch != sCurOcarinaPitch)) {
|
||||
// Sets ocarina instrument Id to io port 7, which is used
|
||||
// as an index in seq 0 to get the true instrument Id
|
||||
AudioThread_QueueCmdS8(0x6 << 24 | SEQ_PLAYER_SFX << 16 | SFX_CHANNEL_OCARINA << 8 | 7,
|
||||
sOcarinaInstrumentId - 1);
|
||||
AUDIOCMD_CHANNEL_SET_IO(SEQ_PLAYER_SFX, SFX_CHANNEL_OCARINA, 7, sOcarinaInstrumentId - 1);
|
||||
// Sets pitch to io port 5
|
||||
AudioThread_QueueCmdS8(0x6 << 24 | SEQ_PLAYER_SFX << 16 | SFX_CHANNEL_OCARINA << 8 | 5, sCurOcarinaPitch);
|
||||
AUDIOCMD_CHANNEL_SET_IO(SEQ_PLAYER_SFX, SFX_CHANNEL_OCARINA, 5, sCurOcarinaPitch);
|
||||
AudioSfx_PlaySfx(NA_SE_OC_OCARINA, &gSfxDefaultPos, 4, &sCurOcarinaBendFreq, &sDefaultOcarinaVolume,
|
||||
&gSfxDefaultReverb);
|
||||
} else if ((sPrevOcarinaPitch != OCARINA_PITCH_NONE) && (sCurOcarinaPitch == OCARINA_PITCH_NONE) &&
|
||||
@@ -2862,7 +2861,7 @@ void AudioOcarina_PlaybackSong(void) {
|
||||
// Update vibrato
|
||||
sNotePlaybackVibrato = sPlaybackSong[sPlaybackNotePos].vibrato;
|
||||
// Sets vibrato to io port 6
|
||||
AudioThread_QueueCmdS8(0x6 << 24 | SEQ_PLAYER_SFX << 16 | SFX_CHANNEL_OCARINA << 8 | 6, sNotePlaybackVibrato);
|
||||
AUDIOCMD_CHANNEL_SET_IO(SEQ_PLAYER_SFX, SFX_CHANNEL_OCARINA, 6, sNotePlaybackVibrato);
|
||||
|
||||
// Update bend
|
||||
if (sNotePlaybackBend != sPlaybackSong[sPlaybackNotePos].bend) {
|
||||
@@ -2892,10 +2891,9 @@ void AudioOcarina_PlaybackSong(void) {
|
||||
sPlaybackStaffPos++;
|
||||
// Sets ocarina instrument Id to io port 7, which is used
|
||||
// as an index in seq 0 to get the true instrument Id
|
||||
AudioThread_QueueCmdS8(0x6 << 24 | SEQ_PLAYER_SFX << 16 | SFX_CHANNEL_OCARINA << 8 | 7,
|
||||
sOcarinaInstrumentId - 1);
|
||||
AudioThread_QueueCmdS8(0x6 << 24 | SEQ_PLAYER_SFX << 16 | SFX_CHANNEL_OCARINA << 8 | 5,
|
||||
sPlaybackPitch & OCARINA_BUTTON_MASK_PITCH);
|
||||
AUDIOCMD_CHANNEL_SET_IO(SEQ_PLAYER_SFX, SFX_CHANNEL_OCARINA, 7, sOcarinaInstrumentId - 1);
|
||||
AUDIOCMD_CHANNEL_SET_IO(SEQ_PLAYER_SFX, SFX_CHANNEL_OCARINA, 5,
|
||||
sPlaybackPitch & OCARINA_BUTTON_MASK_PITCH);
|
||||
AudioSfx_PlaySfx(NA_SE_OC_OCARINA, &gSfxDefaultPos, 4, &sRelativeNotePlaybackBend,
|
||||
&sRelativeNotePlaybackVolume, &gSfxDefaultReverb);
|
||||
} else {
|
||||
@@ -3400,7 +3398,7 @@ u8 sRequestCustomSequence = false;
|
||||
void AudioOcarina_SetCustomSequence(void) {
|
||||
// Never passes true as sRequestCustomSequence is never set true
|
||||
if (sRequestCustomSequence && gAudioCtx.seqPlayers[SEQ_PLAYER_FANFARE].enabled &&
|
||||
((u8)gAudioCtx.seqPlayers[SEQ_PLAYER_FANFARE].soundScriptIO[0] == (u8)SEQ_IO_VAL_NONE)) {
|
||||
((u8)gAudioCtx.seqPlayers[SEQ_PLAYER_FANFARE].seqScriptIO[0] == (u8)SEQ_IO_VAL_NONE)) {
|
||||
gAudioCtx.seqPlayers[SEQ_PLAYER_FANFARE].seqData = sCustomSequenceScript;
|
||||
sRequestCustomSequence = false;
|
||||
}
|
||||
@@ -3754,8 +3752,8 @@ s8 AudioSfx_ComputeReverb(u8 bankId, u8 entryIndex, u8 channelIndex) {
|
||||
}
|
||||
|
||||
if (IS_SEQUENCE_CHANNEL_VALID(gAudioCtx.seqPlayers[SEQ_PLAYER_SFX].channels[channelIndex])) {
|
||||
scriptAdd = gAudioCtx.seqPlayers[SEQ_PLAYER_SFX].channels[channelIndex]->soundScriptIO[1];
|
||||
if (gAudioCtx.seqPlayers[SEQ_PLAYER_SFX].channels[channelIndex]->soundScriptIO[1] <= SEQ_IO_VAL_NONE) {
|
||||
scriptAdd = gAudioCtx.seqPlayers[SEQ_PLAYER_SFX].channels[channelIndex]->seqScriptIO[1];
|
||||
if (gAudioCtx.seqPlayers[SEQ_PLAYER_SFX].channels[channelIndex]->seqScriptIO[1] <= SEQ_IO_VAL_NONE) {
|
||||
scriptAdd = 0;
|
||||
}
|
||||
}
|
||||
@@ -4051,8 +4049,8 @@ void AudioSfx_SetProperties(u8 bankId, u8 entryIndex, u8 channelIndex) {
|
||||
//! FAKE:
|
||||
if (1) {}
|
||||
|
||||
// CHAN_UPD_SCRIPT_IO (slot 2, sets volume)
|
||||
AudioThread_QueueCmdS8((0x6 << 24) | (SEQ_PLAYER_SFX << 16) | (channelIndex << 8) | 2, volumeS8);
|
||||
// ioPort 2, sets volume
|
||||
AUDIOCMD_CHANNEL_SET_IO(SEQ_PLAYER_SFX, channelIndex, 2, volumeS8);
|
||||
|
||||
if (sSfxChannelState[channelIndex].reverb != reverb) {
|
||||
sSfxChannelState[channelIndex].reverb = reverb;
|
||||
@@ -4307,16 +4305,16 @@ f32 sBigBellsVolume[8] = {
|
||||
*/
|
||||
void Audio_SetGanonsTowerBgmVolumeLevel(u8 ganonsTowerLevel) {
|
||||
u8 channelIndex;
|
||||
s8 pan = 0;
|
||||
s8 panChannelWeight = 0;
|
||||
|
||||
// Ganondorfs's Lair
|
||||
if (ganonsTowerLevel == 0) {
|
||||
pan = 0x7F;
|
||||
// Pan comes entirely from the SequenceChannel
|
||||
panChannelWeight = 0x7F;
|
||||
}
|
||||
|
||||
for (channelIndex = 0; channelIndex < 16; channelIndex++) {
|
||||
// CHAN_UPD_PAN_UNSIGNED
|
||||
AudioThread_QueueCmdS8(((u8)(u32)channelIndex << 8) | 0x7000000, pan);
|
||||
for (channelIndex = 0; channelIndex < SEQ_NUM_CHANNELS; channelIndex++) {
|
||||
AUDIOCMD_CHANNEL_SET_PAN_WEIGHT(SEQ_PLAYER_BGM_MAIN, channelIndex, panChannelWeight);
|
||||
}
|
||||
|
||||
// Lowest room in Ganon's Tower (Entrance Room)
|
||||
@@ -4359,11 +4357,12 @@ s32 Audio_SetGanonsTowerBgmVolume(u8 targetVolume) {
|
||||
for (channelIndex = 0; channelIndex < ARRAY_COUNT(gAudioCtx.seqPlayers[SEQ_PLAYER_BGM_MAIN].channels);
|
||||
channelIndex++) {
|
||||
if (&gAudioCtx.sequenceChannelNone != gAudioCtx.seqPlayers[SEQ_PLAYER_BGM_MAIN].channels[channelIndex]) {
|
||||
// soundScriptIO[5] was set to 0x40 in channels 0, 1, and 4 (BGM no longer in OoT)
|
||||
if ((u8)gAudioCtx.seqPlayers[SEQ_PLAYER_BGM_MAIN].channels[channelIndex]->soundScriptIO[5] !=
|
||||
// seqScriptIO[5] was originally set to 0x40 in channels 0, 1, and 4 by OoT's Ganon's Tower BGM,
|
||||
// which was removed in MM
|
||||
if ((u8)gAudioCtx.seqPlayers[SEQ_PLAYER_BGM_MAIN].channels[channelIndex]->seqScriptIO[5] !=
|
||||
(u8)SEQ_IO_VAL_NONE) {
|
||||
// Higher volume leads to lower reverb
|
||||
reverb = (((u16)gAudioCtx.seqPlayers[SEQ_PLAYER_BGM_MAIN].channels[channelIndex]->soundScriptIO[5] -
|
||||
reverb = (((u16)gAudioCtx.seqPlayers[SEQ_PLAYER_BGM_MAIN].channels[channelIndex]->seqScriptIO[5] -
|
||||
targetVolume) +
|
||||
0x7F);
|
||||
|
||||
@@ -4371,10 +4370,7 @@ s32 Audio_SetGanonsTowerBgmVolume(u8 targetVolume) {
|
||||
reverb = 0x7F;
|
||||
}
|
||||
|
||||
// CHAN_UPD_REVERB
|
||||
AudioThread_QueueCmdS8(_SHIFTL(5, 24, 8) | _SHIFTL(SEQ_PLAYER_BGM_MAIN, 16, 8) |
|
||||
_SHIFTL(channelIndex, 8, 8),
|
||||
(u8)reverb);
|
||||
AUDIOCMD_CHANNEL_SET_REVERB_VOLUME(SEQ_PLAYER_BGM_MAIN, channelIndex, (u8)reverb);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4445,9 +4441,7 @@ void AudioSfx_SetChannelIO(Vec3f* pos, u16 sfxId, u8 ioData) {
|
||||
|
||||
if (entryIndex != 0xFF) {
|
||||
if ((sfxId == gSfxBanks[bankId][entryIndex].sfxId) && (&pos->x == gSfxBanks[bankId][entryIndex].posX)) {
|
||||
AudioThread_QueueCmdS8(_SHIFTL(6, 24, 8) | _SHIFTL(SEQ_PLAYER_SFX, 16, 8) |
|
||||
_SHIFTL(channelIndex, 8, 8) | _SHIFTL(6, 0, 8),
|
||||
ioData);
|
||||
AUDIOCMD_CHANNEL_SET_IO(SEQ_PLAYER_SFX, channelIndex, 6, ioData);
|
||||
}
|
||||
}
|
||||
channelIndex++;
|
||||
@@ -4498,7 +4492,7 @@ void func_801A09D4(Vec3f* pos, f32 xzDistToPlayer) {
|
||||
if (channelIndex != 9) {
|
||||
Audio_QueueSeqCmd(((u32)(6) << 28) | ((u32)(SEQ_PLAYER_BGM_MAIN) << 24) | ((u32)(2) << 16) |
|
||||
((u32)(channelIndex) << 8) | ((u8)(127.0f * volumeRel)));
|
||||
AudioThread_QueueCmdS8(0x03000000 | ((u8)((u32)channelIndex) << 8), pan);
|
||||
AUDIOCMD_CHANNEL_SET_PAN(SEQ_PLAYER_BGM_MAIN, channelIndex, pan);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4721,7 +4715,7 @@ void Audio_UpdateSceneSequenceResumePoint(void) {
|
||||
if ((seqId != NA_BGM_DISABLED) && (sSeqFlags[seqId & 0xFF & 0xFF] & SEQ_FLAG_RESUME)) {
|
||||
if (sSeqResumePoint != SEQ_RESUME_POINT_NONE) {
|
||||
// Get the current point to resume from
|
||||
sSeqResumePoint = gAudioCtx.seqPlayers[SEQ_PLAYER_BGM_MAIN].soundScriptIO[3];
|
||||
sSeqResumePoint = gAudioCtx.seqPlayers[SEQ_PLAYER_BGM_MAIN].seqScriptIO[3];
|
||||
} else {
|
||||
// Initialize the point to resume from to the start of the sequence
|
||||
sSeqResumePoint = 0;
|
||||
@@ -5089,7 +5083,7 @@ void Audio_StartAmbience(u16 initChannelMask, u16 initMuteChannelMask) {
|
||||
if ((Audio_GetActiveSequence(SEQ_PLAYER_AMBIENCE) != NA_BGM_DISABLED) &&
|
||||
(Audio_GetActiveSequence(SEQ_PLAYER_AMBIENCE) != NA_BGM_AMBIENCE)) {
|
||||
Audio_StopSequence(SEQ_PLAYER_AMBIENCE, 0);
|
||||
AudioThread_QueueCmdS32(0xF8 << 24, 0);
|
||||
AUDIOCMD_GLOBAL_STOP_AUDIOCMDS();
|
||||
}
|
||||
|
||||
if (Audio_GetActiveSequence(SEQ_PLAYER_BGM_SUB) == (NA_BGM_ENEMY | 0x800)) {
|
||||
@@ -5164,12 +5158,11 @@ void AudioSfx_Init(u16 fadeTimer) {
|
||||
Audio_StartSequence(SEQ_PLAYER_SFX, NA_BGM_GENERAL_SFX, 0x70, fadeTimer);
|
||||
|
||||
for (channelIndex = 0; channelIndex < ARRAY_COUNT(sSfxChannelState); channelIndex++) {
|
||||
AudioThread_QueueCmdS32(0x10 << 24 | SEQ_PLAYER_SFX << 16 | ((u8)(u32)channelIndex << 8),
|
||||
&sSfxChannelState[channelIndex]);
|
||||
AUDIOCMD_CHANNEL_SET_SFX_STATE(SEQ_PLAYER_SFX, channelIndex, &sSfxChannelState[channelIndex]);
|
||||
}
|
||||
|
||||
AudioThread_QueueCmdS32(0xE4000000, AudioSfx_SetFreqAndStereoBits);
|
||||
AudioThread_QueueCmdS32(0xE4000001, Audio_SetAmbienceRandomBend);
|
||||
AUDIOCMD_GLOBAL_SET_CUSTOM_FUNCTION(AUDIO_CUSTOM_FUNCTION_SEQ_0, AudioSfx_SetFreqAndStereoBits);
|
||||
AUDIOCMD_GLOBAL_SET_CUSTOM_FUNCTION(AUDIO_CUSTOM_FUNCTION_SEQ_1, Audio_SetAmbienceRandomBend);
|
||||
}
|
||||
|
||||
#pragma GLOBAL_ASM("asm/non_matchings/code/code_8019AF00/func_801A4D00.s")
|
||||
|
||||
@@ -410,9 +410,8 @@ void AudioSfx_ChooseActiveSfx(u8 bankId) {
|
||||
// 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)) {
|
||||
// CHAN_UPD_SCRIPT_IO (ioPort 0, force stop sfx in seq 0)
|
||||
AudioThread_QueueCmdS8(
|
||||
(0x6 << 24) | (SEQ_PLAYER_SFX << 16) | (gSfxBanks[bankId][entryIndex].channelIndex << 8), 0);
|
||||
// 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);
|
||||
}
|
||||
|
||||
@@ -459,8 +458,8 @@ void AudioSfx_ChooseActiveSfx(u8 bankId) {
|
||||
|
||||
// If too far away and also playing, stop playing
|
||||
if (entry->state == SFX_STATE_PLAYING) {
|
||||
// CHAN_UPD_SCRIPT_IO (ioPort 0, force stop sfx in seq 0)
|
||||
AudioThread_QueueCmdS8((0x6 << 24) | (SEQ_PLAYER_SFX << 16) | (entry->channelIndex << 8), 0);
|
||||
// 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;
|
||||
@@ -632,15 +631,11 @@ void AudioSfx_PlayActiveSfx(u8 bankId) {
|
||||
// Calculate all the properties of sfx
|
||||
AudioSfx_SetProperties(bankId, entryIndex, sCurSfxPlayerChannelIndex);
|
||||
|
||||
// CHAN_UPD_SCRIPT_IO (ioPort 0, enable the sfx to play in seq 0)
|
||||
AudioThread_QueueCmdS8((0x6 << 24) | (SEQ_PLAYER_SFX << 16) | ((sCurSfxPlayerChannelIndex & 0xFF) << 8),
|
||||
1);
|
||||
// ioPort 0, enable the sfx to play in `NA_BGM_GENERAL_SFX`
|
||||
AUDIOCMD_CHANNEL_SET_IO(SEQ_PLAYER_SFX, sCurSfxPlayerChannelIndex, 0, 1);
|
||||
|
||||
// CHAN_UPD_SCRIPT_IO (ioPort 4, write the lower bits sfx index to seq 0 so it can find the right code
|
||||
// to execute)
|
||||
AudioThread_QueueCmdS8((0x6 << 24) | (SEQ_PLAYER_SFX << 16) |
|
||||
((sCurSfxPlayerChannelIndex & 0xFF) << 8) | 4,
|
||||
entry->sfxId & 0xFF);
|
||||
// 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
|
||||
@@ -656,11 +651,9 @@ void AudioSfx_PlayActiveSfx(u8 bankId) {
|
||||
}
|
||||
|
||||
if (D_801D6608[bankId]) {
|
||||
// CHAN_UPD_SCRIPT_IO (ioPort 5, write the upper bits sfx index and a flag to seq 0, for banks with
|
||||
// > 0xFF entries)
|
||||
AudioThread_QueueCmdS8((0x6 << 24) | (SEQ_PLAYER_SFX << 16) |
|
||||
((sCurSfxPlayerChannelIndex & 0xFF) << 8) | 5,
|
||||
ioPort5Data);
|
||||
// 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
|
||||
@@ -671,7 +664,7 @@ void AudioSfx_PlayActiveSfx(u8 bankId) {
|
||||
// "one-frame" sfx
|
||||
entry->state = SFX_STATE_PLAYING_ONE_FRAME;
|
||||
}
|
||||
} else if ((u8)channel->soundScriptIO[1] == (u8)SEQ_IO_VAL_NONE) {
|
||||
} 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) {
|
||||
@@ -702,7 +695,7 @@ void AudioSfx_StopByBank(u8 bankId) {
|
||||
while (entryIndex != 0xFF) {
|
||||
entry = &gSfxBanks[bankId][entryIndex];
|
||||
if (entry->state >= SFX_STATE_PLAYING_REFRESH) {
|
||||
AudioThread_QueueCmdS8((0x6 << 24) | (SEQ_PLAYER_SFX << 16) | ((entry->channelIndex & 0xFF) << 8), 0);
|
||||
AUDIOCMD_CHANNEL_SET_IO(SEQ_PLAYER_SFX, entry->channelIndex, 0, 0);
|
||||
}
|
||||
|
||||
if (entry->state != SFX_STATE_EMPTY) {
|
||||
@@ -724,7 +717,7 @@ void AudioSfx_StopByPosAndBankImpl(u8 bankId, Vec3f* pos) {
|
||||
entry = &gSfxBanks[bankId][entryIndex];
|
||||
if (entry->posX == &pos->x) {
|
||||
if (entry->state >= SFX_STATE_PLAYING_REFRESH) {
|
||||
AudioThread_QueueCmdS8((0x6 << 24) | (SEQ_PLAYER_SFX << 16) | ((entry->channelIndex & 0xFF) << 8), 0);
|
||||
AUDIOCMD_CHANNEL_SET_IO(SEQ_PLAYER_SFX, entry->channelIndex, 0, 0);
|
||||
}
|
||||
|
||||
if (entry->state != SFX_STATE_EMPTY) {
|
||||
@@ -769,7 +762,7 @@ void AudioSfx_StopByPosAndId(Vec3f* pos, u16 sfxId) {
|
||||
entry = &gSfxBanks[SFX_BANK(sfxId)][entryIndex];
|
||||
if ((entry->posX == &pos->x) && (entry->sfxId == sfxId)) {
|
||||
if (entry->state >= SFX_STATE_PLAYING_REFRESH) {
|
||||
AudioThread_QueueCmdS8((0x6 << 24) | (SEQ_PLAYER_SFX << 16) | ((entry->channelIndex & 0xFF) << 8), 0);
|
||||
AUDIOCMD_CHANNEL_SET_IO(SEQ_PLAYER_SFX, entry->channelIndex, 0, 0);
|
||||
}
|
||||
|
||||
if (entry->state != SFX_STATE_EMPTY) {
|
||||
@@ -800,7 +793,7 @@ void AudioSfx_StopByTokenAndId(u8 token, u16 sfxId) {
|
||||
entry = &gSfxBanks[SFX_BANK(sfxId)][entryIndex];
|
||||
if ((entry->token == token) && (entry->sfxId == sfxId)) {
|
||||
if (entry->state >= SFX_STATE_PLAYING_REFRESH) {
|
||||
AudioThread_QueueCmdS8((0x6 << 24) | (SEQ_PLAYER_SFX << 16) | ((entry->channelIndex & 0xFF) << 8), 0);
|
||||
AUDIOCMD_CHANNEL_SET_IO(SEQ_PLAYER_SFX, entry->channelIndex, 0, 0);
|
||||
}
|
||||
|
||||
if (entry->state != SFX_STATE_EMPTY) {
|
||||
@@ -830,7 +823,7 @@ void AudioSfx_StopById(u32 sfxId) {
|
||||
entry = &gSfxBanks[SFX_BANK(sfxId)][entryIndex];
|
||||
if (entry->sfxId == sfxId) {
|
||||
if (entry->state >= SFX_STATE_PLAYING_REFRESH) {
|
||||
AudioThread_QueueCmdS8((0x6 << 24) | (SEQ_PLAYER_SFX << 16) | ((entry->channelIndex & 0xFF) << 8), 0);
|
||||
AUDIOCMD_CHANNEL_SET_IO(SEQ_PLAYER_SFX, entry->channelIndex, 0, 0);
|
||||
}
|
||||
if (entry->state != SFX_STATE_EMPTY) {
|
||||
AudioSfx_RemoveBankEntry(SFX_BANK(sfxId), entryIndex);
|
||||
|
||||
+1
-1
@@ -39,7 +39,7 @@ void AudioMgr_HandleRetrace(AudioMgr* audioMgr) {
|
||||
if (SREG(20) >= 2) {
|
||||
rspTask = NULL;
|
||||
} else {
|
||||
rspTask = func_80192BE0();
|
||||
rspTask = AudioThread_Update();
|
||||
}
|
||||
|
||||
if (audioMgr->rspTask != NULL) {
|
||||
|
||||
Reference in New Issue
Block a user