summaryrefslogtreecommitdiff
path: root/src/audio
diff options
context:
space:
mode:
authorMegaMech <MegaMech@users.noreply.github.com>2024-05-01 11:35:05 -0600
committerGitHub <noreply@github.com>2024-05-01 11:35:05 -0600
commita66a6fd0091161bd4864f25ce4794397058eefcb (patch)
treedd6c1fc7f27c7895a9a750b17dbc05b95f927618 /src/audio
parentd04a5dcddacd4a0ec516df242ddc89fe1ff1e714 (diff)
Add an attempt for synthesis_process_notes (#632)
* Update synthesis.c with attempt
Diffstat (limited to 'src/audio')
-rw-r--r--src/audio/synthesis.c615
-rw-r--r--src/audio/synthesis.h2
2 files changed, 325 insertions, 292 deletions
diff --git a/src/audio/synthesis.c b/src/audio/synthesis.c
index 56f3e2a6d..b688bb061 100644
--- a/src/audio/synthesis.c
+++ b/src/audio/synthesis.c
@@ -324,86 +324,62 @@ Acmd *synthesis_do_one_audio_update(s16 *aiBuf, s32 bufLen, Acmd *acmd, s32 upda
return acmd;
}
-#ifdef MIPS_TO_C
+#ifdef NON_MATCHING
//generated by m2c commit beb457dabfc7a01ec6540a5404a6a05097a13602 on Nov-01-2023
-Acmd *synthesis_process_note(s32 noteIndex, struct NoteSubEu *noteSubEu, struct NoteSynthesisState *synthesisState, s16 *aiBuf, s32 bufLen, Acmd *acmd, s32 updateIndex) {
- void *sp130;
- void *sp12C;
- s32 *sp128;
- s32 sp11C;
- s32 sp118;
- s32 sp114; /* compiler-managed */
- u16 sp112;
+u64 *synthesis_process_note(s32 noteIndex, struct NoteSubEu *noteSubEu, struct NoteSynthesisState *synthesisState, s16 *aiBuf, s32 inBuf, u64 *cmd, s32 updateIndex) {
+ s32 pad[4];
+ struct AudioBankSample *audioBookSample;
+ s16 *curLoadedBook;
+ struct AdpcmLoop *loopInfo;
+ s32 noteFinished;
+ s32 restart;
+ s32 flags;
+ u16 resamplingRateFixedPoint;
+ s32 nSamplesToLoad;
+
s32 spFC;
- s32 spEC;
- u32 spE4;
- s32 spDC;
- s32 spD8;
- s32 spB0;
- s32 spAC;
- s32 spA0; /* compiler-managed */
- u16 sp9E;
- struct Note *sp8C;
- u32 sp50;
- Acmd *temp_a0_2;
- Acmd *temp_s2;
- Acmd *temp_s2_2;
- Acmd *temp_s2_3;
- Acmd *temp_v0_2;
- Acmd *temp_v0_3;
- Acmd *temp_v0_4;
- Acmd *temp_v0_5;
- Acmd *temp_v0_6;
- Acmd *temp_v0_8;
- Acmd *var_s2;
- Acmd *var_s2_2;
- s16 var_t1;
- s32 *temp_a2_2;
- s32 temp_a0;
- s32 temp_a1_2;
- s32 temp_a2;
- s32 temp_a2_3;
- s32 temp_a2_4;
- s32 temp_t6;
- s32 temp_t8;
- s32 temp_t9_2;
- s32 temp_v0_7;
- s32 temp_v1;
- s32 var_a0;
- s32 var_a2;
- s32 var_a3;
- s32 var_fp;
- s32 var_s0_2;
- s32 var_s1;
- s32 var_s3;
- s32 var_s4;
- s32 var_s5;
+ s32 pad2[2];
+
+ s32 loopInfo_2;
+ u8 *sampleAddr;
+ s32 a1;
+
+
+ s32 samplesLenAdjusted;
+ s32 nAdpcmSamplesProcessed;
+ s32 endPos;
+ s32 nSamplesToProcess;
+
+ s32 pad3;
+
+ //u32 spE4;
+ s32 s3;
+ s32 leftRight;
+ s32 s4;
+ u32 samplesLenFixedPoint;
s32 var_s6;
- s32 var_t0;
- s32 var_t2;
- s32 var_t3;
- s32 var_t4;
- s32 var_v1;
- u16 temp_t7;
- u16 temp_v0;
- u32 temp_a1_3;
- u32 temp_s0;
- u32 temp_t7_3;
- u32 var_s0;
- u32 var_t5;
- u32 var_t6;
- u32 var_v1_2;
- u32 var_v1_3;
- void *temp_a1;
- void *temp_t7_2;
- void *temp_t9;
- void *var_a0_2;
-
- sp128 = NULL;
- sp8C = &gNotes[noteIndex];
- var_v1 = 0;
- if (((u32) (noteSubEu->unk0 * 2) >> 0x1F) == 1) {
- var_v1 = 1;
+ s32 nSamplesInThisIteration;
+ u32 var_t2;
+ u8 *var_a0_2;
+
+ //s32 spD8;
+ s32 s5Aligned;
+ s32 temp_t6;
+ s32 nParts;
+ s32 curPart;
+ s32 aligned;
+ s32 pad4;
+ s32 resampledTempLen; /* compiler-managed */
+ u16 noteSamplesDmemAddrBeforeResampling;
+ s32 pad6[1];
+ struct Note *note;
+ u16 addr;
+
+ curLoadedBook = NULL;
+ note = &gNotes[noteIndex];
+ flags = 0;
+ if (noteSubEu->needsInit == TRUE) {
+ flags = A_INIT;
synthesisState->restart = 0;
synthesisState->samplePosInt = 0;
synthesisState->samplePosFrac = 0;
@@ -411,259 +387,316 @@ Acmd *synthesis_process_note(s32 noteIndex, struct NoteSubEu *noteSubEu, struct
synthesisState->curVolRight = 0;
synthesisState->prevHeadsetPanRight = 0;
synthesisState->prevHeadsetPanLeft = 0;
+ //synthesisState->reverbVol = noteSubEu->reverbVol;
+ ////synthesisState->unk5 = 0;
+ //note->noteSubEu.finished = 0;
}
- temp_t7 = noteSubEu->resamplingRateFixedPoint;
- sp112 = temp_t7;
- spB0 = ((u16) noteSubEu->unk0 & 1) + 1;
- temp_v0 = (temp_t7 * bufLen * 2) + synthesisState->samplePosFrac;
- synthesisState->samplePosFrac = temp_v0;
- temp_s0 = temp_v0 >> 0x10;
- var_a0 = noteSubEu->unk0;
- if (var_a0 & 0x20000) {
- temp_v0_2 = load_wave_samples(acmd, noteSubEu, synthesisState, (s32) temp_s0);
- temp_a2 = synthesisState->samplePosInt;
- sp9E = (temp_a2 * 2) + 0x1A0;
- synthesisState->samplePosInt = temp_a2 + temp_s0;
- var_a0 = noteSubEu->unk0;
- acmd = temp_v0_2;
+ resamplingRateFixedPoint = noteSubEu->resamplingRateFixedPoint;
+
+ nParts = noteSubEu->hasTwoAdpcmParts + 1;
+ samplesLenFixedPoint = (resamplingRateFixedPoint * inBuf * 2) + synthesisState->samplePosFrac;
+ nSamplesToLoad = (samplesLenFixedPoint >> 0x10);
+ synthesisState->samplePosFrac = samplesLenFixedPoint & 0xFFFF; // m2c didn't have & 0xFFFF
+
+//var_a0 = noteSubEu->unk0;
+ if (noteSubEu->isSyntheticWave) {
+ cmd = load_wave_samples(cmd, noteSubEu, synthesisState, nSamplesToLoad);
+
+ noteSamplesDmemAddrBeforeResampling = (synthesisState->samplePosInt * 2) + 0x1A0; // DMEM_ADDR_UNCOMPRESSED_NOTE
+ synthesisState->samplePosInt += nSamplesToLoad;
} else {
- temp_t7_2 = *noteSubEu->sound.samples;
- sp130 = temp_t7_2;
- temp_t9 = temp_t7_2->unk8;
- sp12C = temp_t9;
- spDC = temp_t9->unk4;
- spA0 = 0;
- spAC = 0;
- spEC = temp_t7_2->unk4;
- if (spB0 > 0) {
- sp50 = temp_v0 >> 0x10;
- sp114 = var_v1;
- var_s2_2 = acmd;
-loop_6:
- temp_a1 = sp130->unkC;
- var_fp = 0;
- var_s4 = 0;
- temp_a2_2 = temp_a1 + 8;
- if (spB0 == 1) {
- var_t5 = sp50;
+ audioBookSample = noteSubEu->sound.audioBankSound->sample;
+ //sp130 = audioBookSample;
+ loopInfo = audioBookSample->loop;
+ //sp12C = loopInfo;
+ endPos = loopInfo->end;
+ sampleAddr = audioBookSample->sampleAddr; // book?
+ resampledTempLen = 0;
+ //if (nParts > 0) {
+ // nSamplesToLoad = samplesLenFixedPoint >> 0x10;
+ // sp114 = flags;
+ // var_s2_2 = cmd;
+//loop_6:
+ for (curPart = 0; curPart < nParts; curPart++) {
+ nAdpcmSamplesProcessed = 0;
+ s4 = 0;
+
+
+ //temp_a1 = audioBookSample->unkC;
+ //temp_a2_2 = temp_a1 + 8;
+
+ if (nParts == 1) {
+ samplesLenAdjusted = nSamplesToLoad;
+ } else if (nSamplesToLoad & 1) {
+ samplesLenAdjusted = (nSamplesToLoad & ~1) + (curPart * 2);
} else {
- var_t5 = sp50;
- if (sp50 & 1) {
- var_t5 = (sp50 & ~1) + (spAC * 2);
- }
+ samplesLenAdjusted = nSamplesToLoad;
}
- if (sp128 != temp_a2_2) {
- temp_v0_3 = var_s2_2;
- var_s2_2 += 8;
- temp_v0_3->words.w0 = ((temp_a1->unk0 * 0x10 * temp_a1->unk4) & 0xFFFFFF) | 0x0B000000;
- temp_v0_3->words.w1 = (((u32) (noteSubEu->unk0 << 0xB) >> 0x1D) * 2) + temp_a2_2 + 0x80000000;
- var_a0 = noteSubEu->unk0;
- sp128 = temp_a2_2;
+ // sm64 also has if (audioBookSample->codec == CODEC_A) {
+ if (curLoadedBook != (*audioBookSample->book).book) {
+ u32 nEntries;
+ //temp_v0_3 = var_s2_2;
+ // var_s2_2 += 8;
+ //temp_v0_3->unk0 = ((temp_a1->unk0 * 16 * temp_a1->unk4) & 0xFFFFFF) | 0x0B000000;
+ //temp_v0_3->unk4 = (s32) ((((u32) (noteSubEu->unk0 << 0xB) >> 0x1D) * 2) + temp_a2_2 + 0x80000000);
+ //var_a0 = noteSubEu->unk0;
+ curLoadedBook = audioBookSample->book->book; // or just one book?
+ nEntries = 16 * audioBookSample->book->order * audioBookSample->book->npredictors;
+ aLoadADPCM(cmd++, nEntries, VIRTUAL_TO_PHYSICAL2(noteSubEu->bookOffset+curLoadedBook));
+ // noteSubEu here unsure but seems better?
}
- if (((u32) (var_a0 << 0xB) >> 0x1D) != 0) {
- sp128 = gUnknownData_800F6290;
+ if (noteSubEu->bookOffset != 0) {
+ curLoadedBook = &gUnknownData_800F6290; // type?
}
- if (var_t5 != 0) {
-loop_15:
- temp_a2_3 = synthesisState->samplePosInt;
- temp_a0 = var_t5 - var_fp;
- var_s3 = temp_a2_3 & 0xF;
- var_t3 = 0;
- var_t4 = 0;
- temp_v1 = spDC - temp_a2_3;
- if ((var_s3 == 0) && (synthesisState->restart == 0)) {
- var_s3 = 0x10;
+ while (nAdpcmSamplesProcessed != samplesLenAdjusted) {
+//loop_15:
+ s32 samplesRemaining;
+ s32 s1;
+
+ noteFinished = FALSE;
+ restart = FALSE;
+ //temp_a2_3 = synthesisState->samplePosInt;
+ s3 = synthesisState->samplePosInt & 0xF;
+ samplesRemaining = endPos - synthesisState->samplePosInt;
+ nSamplesToProcess = samplesLenAdjusted - nAdpcmSamplesProcessed;
+ if ((s3 == 0) && (synthesisState->restart == FALSE)) {
+ s3 = 16;
}
- temp_a1_2 = 0x10 - var_s3;
- var_s5 = temp_a1_2;
- if (temp_a0 < temp_v1) {
- temp_t9_2 = (s32) ((temp_a0 - temp_a1_2) + 0xF) / 16;
- var_s1 = temp_t9_2 * 0x10;
- var_t0 = temp_t9_2;
- var_s6 = (temp_a1_2 + var_s1) - temp_a0;
+
+ a1 = 16 - s3;
+ //var_s5 = a1;
+ if (nSamplesToProcess < samplesRemaining) {
+ loopInfo_2 = ((nSamplesToProcess - a1) + 0xF) / 16;
+ s1 = loopInfo_2 * 16;
+ //var_t0 = loopInfo_2;
+ var_s6 = (a1 + s1) - nSamplesToProcess;
} else {
- var_s1 = temp_v1 - temp_a1_2;
+ s1 = samplesRemaining - a1;
var_s6 = 0;
- if (var_s1 <= 0) {
- var_s1 = 0;
- var_s5 = temp_v1;
+ if (s1 <= 0) {
+ s1 = 0;
+ a1 = samplesRemaining;
}
- var_t0 = (s32) (var_s1 + 0xF) / 16;
- if (sp12C->unk8 != 0) {
- var_t4 = 1;
+ loopInfo_2 = (s1 + 0xF) / 16;
+ if (loopInfo->count != 0) {
+ restart = 1;
} else {
- var_t3 = 1;
+ noteFinished = 1;
}
}
- var_t2 = 0;
- if (var_t0 != 0) {
- temp_t6 = (s32) ((temp_a2_3 - var_s3) + 0x10) / 16;
- if (sp130->unk1 == 0x81) {
- var_s0 = ((var_t0 * 9) + 0x1F) & ~0xF;
- var_a0_2 = (temp_t6 * 9) + spEC;
+ //var_t2 = 0; // unsure
+ if (loopInfo_2 != 0) {
+ temp_t6 = ((synthesisState->samplePosInt - s3) + 16) / 16; // diff from sm64 sh
+ if (audioBookSample->loaded == 0x81) { // sm64 has audioBookSample->medium
+ //var_s0 = ((loopInfo_2 * 9) + 0x1F) & ~0xF;
+ var_a0_2 = (temp_t6 * 9) + sampleAddr;
} else {
- spD8 = temp_a0;
- sp11C = var_t3;
- sp118 = var_t4;
- spE4 = var_t5;
- temp_a1_3 = ((var_t0 * 9) + 0x1F) & ~0xF;
- var_s0 = temp_a1_3;
- var_a0_2 = dma_sample_data((temp_t6 * 9) + spEC, temp_a1_3, sp114, &synthesisState->sampleDmaIndex);
+ //spD8 = nSamplesToProcess;
+ //sp11C = noteFinished;
+ //sp118 = restart;
+ //spE4 = samplesLenAdjusted;
+ //temp_a1_3 += ((loopInfo_2 * 9) + 0x1F) & ~0xF;
+ //var_s0 = temp_a1_3;
+ var_a0_2 = dma_sample_data((uintptr_t) (temp_t6 * 9) + sampleAddr, ALIGN(((loopInfo_2 * 9) + 16), 4), flags, &synthesisState->sampleDmaIndex);
+ // unsure flags?
}
- var_t1 = 0x540 - var_s0;
- var_t2 = (s32) var_a0_2 & 0xF;
- var_s2_2->words.w1 = (var_a0_2 - var_t2) + 0x80000000;
- var_s2_2->words.w0 = ((((s32) var_s0 >> 4) & 0xFF) << 0x10) | 0x14000000 | (var_t1 & 0xFFFF);
- var_s2_2 += 8;
+ //var_t1 = 0x540 - var_s0;
+ var_t2 = ((uintptr_t)var_a0_2 & 0xF);
+
+ //var_s2_2->unk4 = (s32) ((var_a0_2 - var_t2) + 0x80000000);
+
+ aligned = ALIGN(((loopInfo_2 * 9) + 16), 4);
+ addr = (0x540 - aligned) & 0xFFFF; // DMEM_ADDR_COMPRESSED_ADPCM_DATA
+ //var_s2_2->unk0 = (((var_s0 >> 4) & 0xFF) << 16) | 0x14000000 | ((0x540 - var_s0) & 0xFFFF);
+ // var_s2_2 += 8;
+ //aLoadBuffer(cmd++, ALIGN(((loopInfo_2 * 9) + 16), 4), addr, VIRTUAL_TO_PHYSICAL2(var_a0_2 - var_t2));
+ aLoadBuffer(cmd++, VIRTUAL_TO_PHYSICAL2(var_a0_2 - var_t2), addr, aligned);
} else {
- var_s1 = 0;
- var_t1 = 0x540 - (((var_t0 * 9) + 0x1F) & 0xFFF0);
+ s1 = 0; // ?
+ var_t2 = 0;
+ //addr = 0x540 - (((loopInfo_2 * 9) + 16));
}
- temp_v0_4 = var_s2_2;
- if (synthesisState->restart != 0) {
- temp_v0_4->words.w0 = 0x0F000000;
- var_s2_2 += 8;
- temp_v0_4->words.w1 = sp130->unk8 + 0x80000010;
- sp114 = 2;
- synthesisState->restart = 0;
+ //temp_v0_4 = var_s2_2;
+ if (synthesisState->restart != FALSE) {
+ aSetLoop(cmd++, VIRTUAL_TO_PHYSICAL2(audioBookSample->loop->state));
+ //temp_v0_4->unk0 = 0x0F000000;
+ //var_s2_2 += 8;
+ //temp_v0_4->unk4 = (s32) (audioBookSample->unk8 + 0x80000010);
+ flags = A_LOOP;
+ synthesisState->restart = FALSE;
}
- if (var_fp == 0) {
- var_a2 = var_s1 * 2;
- var_s2_2->words.w1 = (var_a2 & 0xFFFF) | 0x01A00000;
- var_s2_2->words.w0 = ((var_t1 + var_t2) & 0xFFFF) | 0x08000000;
- temp_s2 = var_s2_2 + 8;
- temp_s2->words.w0 = ((sp114 & 0xFF) << 0x10) | 0x01000000;
- temp_s2->words.w1 = (u32) (synthesisState->synthesisBuffers + 0x80000000);
- var_s2_2 = temp_s2 + 8;
- spFC = var_s3 * 2;
- var_a3 = (var_s1 + var_s5) - var_s6;
+ nSamplesInThisIteration = (s1 + a1) - var_s6;
+ s5Aligned = ALIGN(s4 + 16, 4);
+ if (nAdpcmSamplesProcessed == 0) {
+ //var_a2 = s1 * 2;
+ //var_s2_2->unk4 = (s32) ((var_a2 & 0xFFFF) | 0x01A00000);
+ ///var_s2_2->unk0 = ((var_t1 + var_t2) & 0xFFFF) | 0x08000000;
+ //temp_s2 = var_s2_2 + 8;
+ //temp_s2->unk0 = (s32) (((sp114 & 0xFF) << 0x10) | 0x01000000);
+ //temp_s2->unk4 = (s32) VIRTUAL_TO_PHYSICAL2(synthesisState->synthesisBuffers->adpcmdecState);
+ //var_s2_2 = temp_s2 + 8;
+ //spFC = s3 * 2;
+ aligned = ALIGN(((loopInfo_2 * 9) + 16), 4);
+ addr = (0x540 - aligned) & 0xFFFF;
+ aSetBuffer(cmd++, 0, addr + var_t2, 0x1A0, s1 * 2); // unsure
+ // s1 or s3 here?
+ aADPCMdec(cmd++, flags, VIRTUAL_TO_PHYSICAL2(synthesisState->synthesisBuffers->adpcmdecState));
+ spFC = s3 * 2;
+ //nSamplesInThisIteration = (s1 + a1) - var_s6;
} else {
- temp_t8 = (var_s4 + 0x1F) & ~0xF;
- var_s2_2->words.w0 = ((var_t1 + var_t2) & 0xFFFF) | 0x08000000;
- var_a2 = var_s1 * 2;
- var_s2_2->words.w1 = ((temp_t8 + 0x1A0) << 0x10) | (var_a2 & 0xFFFF);
- temp_s2_2 = var_s2_2 + 8;
- temp_s2_2->words.w0 = ((sp114 & 0xFF) << 0x10) | 0x01000000;
- temp_s2_2->words.w1 = (u32) (synthesisState->synthesisBuffers + 0x80000000);
- temp_s2_3 = temp_s2_2 + 8;
- var_a3 = (var_s1 + var_s5) - var_s6;
- temp_s2_3->words.w0 = ((temp_t8 + (var_s3 * 2) + 0x1A0) & 0xFFFFFF) | 0x0A000000;
- temp_s2_3->words.w1 = ((var_s4 + 0x1A0) << 0x10) | ((var_a3 * 2) & 0xFFFF);
- var_s2_2 = temp_s2_3 + 8;
+ // temp_t8 = (s4 + 0x1F) & ~0xF;
+ // var_s2_2->unk0 = ((var_t1 + var_t2) & 0xFFFF) | 0x08000000;
+ // var_a2 = s1 * 2;
+ // var_s2_2->unk4 = (s32) (((temp_t8 + 0x1A0) << 0x10) | (var_a2 & 0xFFFF));
+ // temp_s2_2 = var_s2_2 + 8;
+ // temp_s2_2->unk0 = (s32) (((sp114 & 0xFF) << 0x10) | 0x01000000);
+ // temp_s2_2->unk4 = (s32) VIRTUAL_TO_PHYSICAL2(synthesisState->synthesisBuffers->adpcmdecState);
+ // temp_s2_3 = temp_s2_2 + 8;
+ // temp_s2_3->unk0 = (s32) (((temp_t8 + (s3 * 2) + 0x1A0) & 0xFFFFFF) | 0x0A000000);
+ // temp_s2_3->unk4 = (s32) (((s4 + 0x1A0) << 0x10) | ((nSamplesInThisIteration * 2) & 0xFFFF));
+ // var_s2_2 = temp_s2_3 + 8;
+ aligned = ALIGN(((loopInfo_2 * 9) + 16), 4);
+ addr = (0x540 - aligned) & 0xFFFF;
+ aSetBuffer(cmd++, 0, addr + var_t2, 0x1A0 + s5Aligned, s1 * 2); // unsure
+
+ // The real macro here. Decompme requires the below to work.
+ //aS8Dec(cmd++, flags, VIRTUAL_TO_PHYSICAL2(synthesisState->synthesisBuffers->adpcmdecState));
+ aADPCMdec(cmd++, flags, VIRTUAL_TO_PHYSICAL2(synthesisState->synthesisBuffers->adpcmdecState));
+ // {\
+ // Acmd *_a = (Acmd *) (cmd++);\
+ // _a->words.w0 = _SHIFTL(23, 24, 8) | _SHIFTL(flags, 16, 8);\
+ // _a->words.w1 = (uintptr_t) VIRTUAL_TO_PHYSICAL2(synthesisState->synthesisBuffers->adpcmdecState);\
+ // };
+ //nSamplesInThisIteration = (s1 + a1) - var_s6;
+ aDMEMMove(cmd++, 0x1A0 + s5Aligned + (s3 * 2), 0x1A0 + s4, nSamplesInThisIteration * 2);
}
- var_fp += var_a3;
- if (sp114 != 1) {
- sp114 = 0;
- if ((sp114 ^ 2) != 0) {
- if (var_s4 != 0) {
- var_s4 += var_a3 * 2;
+
+ nAdpcmSamplesProcessed += nSamplesInThisIteration;
+ switch(flags) {
+ case 1:
+ spFC = 0x20;
+ s4 = (s1 * 2) + 0x20;
+ break;
+ case 2:
+ s4 += nSamplesInThisIteration * 2;
+ break;
+ default:
+ if (s4 != 0) {
+ s4 += nSamplesInThisIteration * 2;
} else {
- var_s4 = (var_s3 + var_a3) * 2;
+ s4 = (s3 + nSamplesInThisIteration) * 2;
}
- } else {
- var_s4 += var_a3 * 2;
- }
- } else {
- spFC = 0x00000020;
- var_s4 = var_a2 + 0x20;
- sp114 = 0;
+ break;
}
- if (var_t3 != 0) {
- var_s2_2->words.w0 = ((var_s4 + 0x1A0) & 0xFFFFFF) | 0x02000000;
- var_s2_2->words.w1 = (var_t5 - var_fp) * 2;
- var_s2_2 += 8;
- noteSubEu->unk0 = (s8) ((u8) noteSubEu->unk0 | 0x20);
+ flags = 0;
+
+ if (noteFinished) {
+ aClearBuffer(cmd++, 0x1A0 + s4,
+ (samplesLenAdjusted - nAdpcmSamplesProcessed) * 2);
+ //var_s2_2->unk0 = ((s4 + 0x1A0) & 0xFFFFFF) | 0x02000000;
+ //var_s2_2->unk4 = (s32) ((samplesLenAdjusted - nAdpcmSamplesProcessed) * 2);
+ //var_s2_2 += 8;
+ noteSubEu->finished = 1; // sm64 says = 1
+ note->noteSubEu.finished = 1;
+ //note->noteSubEu.enabled = 0;
+ //note->noteSubEu.samplePosInt = 0;
+
+ //note->noteSubEu.stereoHeadsetEffects = note->noteSubEu.stereoHeadsetEffects | 0x20;// |= 0x20;
+ //note->noteSubEu.stereoHeadsetEffects = ~(1 << 6);
+ /* mips to c
+ arg1->unk0 = (s8) ((u8) arg1->unk0 | 0x20);
sp8C->unkB0 = (u8) (sp8C->unkB0 | 0x20);
sp8C->unkB0 = (u8) (sp8C->unkB0 & 0xFF7F);
- spE4 = var_t5;
+ */
+ //spE4 = samplesLenAdjusted;
+
func_800B6FB4(updateIndex, noteIndex);
} else {
- if (var_t4 != 0) {
- synthesisState->restart = 1;
- synthesisState->samplePosInt = sp12C->unk0;
+ if (restart) {
+ synthesisState->restart = TRUE;
+ synthesisState->samplePosInt = loopInfo->start;
} else {
- synthesisState->samplePosInt += temp_a0;
- }
- if (var_fp != var_t5) {
- goto loop_15;
+ synthesisState->samplePosInt += nSamplesToProcess;
}
+ // if (nAdpcmSamplesProcessed != samplesLenAdjusted) {
+ // goto loop_15;
+ // }
}
}
- if (spB0 != 1) {
- if (spB0 != 2) {
- var_a0 = noteSubEu->unk0;
- var_t6 = (u32) (var_a0 * 4) >> 0x1F;
- goto block_60;
- }
- if (spAC != 0) {
- temp_v0_5 = var_s2_2;
- if (spAC != 1) {
- var_a0 = noteSubEu->unk0;
- var_v1_2 = (u32) (var_a0 * 4) >> 0x1F;
- } else {
- var_s2_2 += 8;
- temp_v0_5->words.w0 = ((((s32) var_t5 / 2) + 7) & 0xFFF8) | 0x11000000;
- temp_v0_5->words.w1 = ((spFC + 0x1A0) << 0x10) | ((spA0 + 0x20) & 0xFFFF);
- var_a0 = noteSubEu->unk0;
- var_t6 = (u32) (var_a0 * 4) >> 0x1F;
- goto block_60;
- }
- } else {
- temp_v0_6 = var_s2_2;
- var_s2_2 += 8;
- temp_v0_6->words.w0 = ((((s32) var_t5 / 2) + 7) & 0xFFF8) | 0x11000000;
- temp_v0_6->words.w1 = ((spFC + 0x1A0) << 0x10) | 0x20;
- spA0 = var_t5;
- sp9E = 0x0020;
- var_a0 = noteSubEu->unk0;
- temp_t7_3 = (u32) (var_a0 * 4) >> 0x1F;
- var_v1_2 = temp_t7_3;
- if (temp_t7_3 != 0) {
- var_s2_2->words.w1 = var_t5 + 0x10;
- var_s2_2->words.w0 = ((var_t5 + 0x20) & 0xFFFFFF) | 0x02000000;
- var_a0 = noteSubEu->unk0;
- var_s2_2 += 8;
- var_v1_2 = (u32) (var_a0 * 4) >> 0x1F;
+
+ switch(nParts) {
+ case 1:
+ noteSamplesDmemAddrBeforeResampling = 0x1A0 + spFC;
+ break;
+ case 2:
+ //temp_v0_5 = var_s2_2;
+ switch(curPart) {
+ case 0:
+ // temp_v0_6 = var_s2_2;
+ // var_s2_2 += 8;
+ // temp_v0_6->unk0 = ((((s32) var_t5 / 2) + 7) & 0xFFF8) | 0x11000000;
+ // temp_v0_6->unk4 = (s32) (((spFC + 0x1A0) << 0x10) | 0x20);
+ // spA0 = var_t5;
+ // sp9E = 0x20;
+ // var_a0 = arg1->unk0;
+ // temp_t7_3 = (u32) (var_a0 * 4) >> 0x1F;
+ // var_v1_2 = temp_t7_3;
+ // if (temp_t7_3 != 0) {
+ // var_s2_2->unk4 = (s32) (var_t5 + 0x10);
+ // var_s2_2->unk0 = ((var_t5 + 0x20) & 0xFFFFFF) | 0x02000000;
+ // var_a0 = arg1->unk0;
+ // var_s2_2 += 8;
+ // var_v1_2 = (u32) (var_a0 * 4) >> 0x1F;
+ // }
+ aDownsampleHalf(cmd++, ALIGN(samplesLenAdjusted / 2, 3), 0x1A0 + spFC, DMEM_ADDR_RESAMPLED);
+ resampledTempLen = samplesLenAdjusted;
+ noteSamplesDmemAddrBeforeResampling = DMEM_ADDR_RESAMPLED;
+ if (noteSubEu->finished != FALSE) {
+ aClearBuffer(cmd++, noteSamplesDmemAddrBeforeResampling + resampledTempLen, samplesLenAdjusted + 0x10);
+ }
+ break;
+ case 1:
+ //var_s2_2 += 8;
+ // temp_v0_5->unk0 = ((((s32) var_t5 / 2) + 7) & 0xFFF8) | 0x11000000;
+ // temp_v0_5->unk4 = (s32) (((spFC + 0x1A0) << 0x10) | ((spA0 + 0x20) & 0xFFFF));
+ // var_a0 = arg1->unk0;
+ // var_t6 = (u32) (var_a0 * 4) >> 0x1F;
+ aDownsampleHalf(cmd++, ALIGN(samplesLenAdjusted / 2, 3), DMEM_ADDR_RESAMPLED2 + spFC, resampledTempLen + DMEM_ADDR_RESAMPLED);
+ break;
+
}
- }
- } else {
- sp9E = spFC + 0x1A0;
- var_a0 = noteSubEu->unk0;
- var_t6 = (u32) (var_a0 * 4) >> 0x1F;
-block_60:
- var_v1_2 = var_t6;
+ break;
}
- if (var_v1_2 != 0) {
-
- } else {
- temp_v0_7 = spAC + 1;
- spAC = temp_v0_7;
- if (temp_v0_7 != spB0) {
- goto loop_6;
- }
+ if (noteSubEu->finished != FALSE) {
+ break;
}
- acmd = var_s2_2;
}
}
- var_v1_3 = 0;
- if (((u32) (var_a0 * 2) >> 0x1F) == 1) {
- var_v1_3 = 1;
- noteSubEu->unk0 = (s8) ((u8) noteSubEu->unk0 & 0xFFBF);
+ flags = 0;
+ if (noteSubEu->needsInit == TRUE) {
+ flags = A_INIT;
+ noteSubEu->needsInit = FALSE;
}
- temp_a2_4 = bufLen * 2;
- sp114 = var_v1_3;
- temp_a0_2 = final_resample(acmd, synthesisState, temp_a2_4, sp112, (u16) (s32) sp9E, var_v1_3);
- if ((noteSubEu->headsetPanRight != 0) || (synthesisState->prevHeadsetPanRight != 0)) {
- var_s0_2 = 1;
- } else if ((noteSubEu->headsetPanLeft != 0) || (var_s0_2 = 0, (synthesisState->prevHeadsetPanLeft != 0))) {
- var_s0_2 = 2;
+ //temp_a2_4 = inBuf * 2;
+ // flags = flags;
+ //sp114 = flags;
+ //flags = flags | sp54;
+ cmd = final_resample(cmd, synthesisState, inBuf * 2, resamplingRateFixedPoint, noteSamplesDmemAddrBeforeResampling, flags);
+
+ if ((noteSubEu->headsetPanRight) || (synthesisState->prevHeadsetPanRight)) {
+ leftRight = 1; // According to m2c this is a new var. Perhaps flags?
+ } else if ((noteSubEu->headsetPanLeft) || (synthesisState->prevHeadsetPanLeft)) {
+ leftRight = 2;
+ } else {
+ leftRight = 0;
}
- temp_v0_8 = func_800B86A0(temp_a0_2, noteSubEu, synthesisState, bufLen, (u16) 0, var_s0_2, sp114);
- var_s2 = temp_v0_8;
- if ((u8) noteSubEu->unk0 & 1) {
- var_s2 = note_apply_headset_pan_effects(temp_v0_8, noteSubEu, synthesisState, temp_a2_4, (s32) sp114, var_s0_2);
+ cmd = func_800B86A0(cmd, noteSubEu, synthesisState, inBuf, 0, leftRight, flags);
+ //var_s2 = temp_v0_8;
+ if (noteSubEu->usesHeadsetPanEffects) {
+ //synthesisState->restart = 1;
+ cmd = note_apply_headset_pan_effects(cmd, noteSubEu, synthesisState, inBuf * 2, flags, leftRight);
}
- return var_s2;
+ return cmd;
}
#else
GLOBAL_ASM("asm/non_matchings/audio/synthesis/synthesis_process_note.s")
diff --git a/src/audio/synthesis.h b/src/audio/synthesis.h
index 974fc9c32..9d8de57a9 100644
--- a/src/audio/synthesis.h
+++ b/src/audio/synthesis.h
@@ -103,7 +103,7 @@ Acmd *synthesis_execute(Acmd*, s32*, s16*, s32);
Acmd *synthesis_resample_and_mix_reverb(Acmd*, s32, s16, s16);
Acmd *synthesis_save_reverb_samples(Acmd*, s16, s16);
Acmd *synthesis_do_one_audio_update(s16*, s32, Acmd*, s32);
-Acmd *synthesis_process_note(s32, struct NoteSubEu*, struct NoteSynthesisState*, s16*, s32, Acmd*, s32);
+u64 *synthesis_process_note(s32 noteIndex, struct NoteSubEu *noteSubEu, struct NoteSynthesisState *synthesisState, s16 *aiBuf, s32 inBuf, u64 *cmd, s32 updateIndex);
Acmd *load_wave_samples(Acmd *acmd, struct NoteSubEu *noteSubEu, struct NoteSynthesisState *synthesisState, s32 nSamplesToLoad);
Acmd *final_resample(Acmd *acmd, struct NoteSynthesisState *synthesisState, s32 count, u16 pitch, u16 dmemIn, u32 flags);
Acmd *func_800B86A0(Acmd *cmd, struct NoteSubEu *note, struct NoteSynthesisState *synthesisState, s32 nSamples, u16 inBuf, s32 headsetPanSettings, u32 flags);