Pushed the final changes that got audio working!

This commit is contained in:
MeltyPlayer
2022-11-06 20:22:00 -06:00
parent 7bd0cc9a2c
commit 3a4115e8f6
17 changed files with 274 additions and 371 deletions
+66 -203
View File
@@ -1,6 +1,7 @@
#ifndef VERSION_SH
#include <ultra64.h>
#include "../../debug_print.h"
#include "synthesis.h"
#include "heap.h"
#include "data.h"
@@ -27,9 +28,13 @@
#define DMEM_ADDR_WET_RIGHT_CH 0x880
#define aSetLoadBufferPair(pkt, c, off) \
DEBUG_PRINT("- (in set load buffer pair, set buffer 1) "); \
aSetBuffer(pkt, 0, c + DMEM_ADDR_WET_LEFT_CH, 0, DEFAULT_LEN_1CH - c); \
DEBUG_PRINT("- (in set load buffer pair, load buffer 1) "); \
aLoadBuffer(pkt, VIRTUAL_TO_PHYSICAL2(gSynthesisReverb.ringBuffer.left + (off))); \
DEBUG_PRINT("- (in set load buffer pair, set buffer 2) "); \
aSetBuffer(pkt, 0, c + DMEM_ADDR_WET_RIGHT_CH, 0, DEFAULT_LEN_1CH - c); \
DEBUG_PRINT("- (in set load buffer pair, load buffer 2) "); \
aLoadBuffer(pkt, VIRTUAL_TO_PHYSICAL2(gSynthesisReverb.ringBuffer.right + (off)))
#define aSetSaveBufferPair(pkt, c, d, off) \
@@ -324,6 +329,7 @@ u64 *synthesis_execute(u64 *cmdBuf, s32 *writtenCmds, s16 *aiBuf, s32 bufLen) {
#else
// bufLen will be divisible by 16
u64 *synthesis_execute(u64 *cmdBuf, s32 *writtenCmds, s16 *aiBuf, s32 bufLen) {
DEBUG_PRINT("synthesis_execute()");
s32 chunkLen;
s32 i;
u32 *aiBufPtr = (u32 *) aiBuf;
@@ -506,6 +512,8 @@ u64 *synthesis_do_one_audio_update(s16 *aiBuf, s32 bufLen, u64 *cmd, s32 updateI
}
#else
u64 *synthesis_do_one_audio_update(s16 *aiBuf, s32 bufLen, u64 *cmd, s32 updateIndex) {
DEBUG_PRINT("synthesis_do_one_audio_update()");
UNUSED s32 pad1[1];
s16 ra;
s16 t4;
@@ -514,35 +522,52 @@ u64 *synthesis_do_one_audio_update(s16 *aiBuf, s32 bufLen, u64 *cmd, s32 updateI
UNUSED s32 pad2[1];
s16 temp;
DEBUG_PRINT("- curFrame: %d", gSynthesisReverb.curFrame);
DEBUG_PRINT("- updateIndex: %d", updateIndex);
v1 = &gSynthesisReverb.items[gSynthesisReverb.curFrame][updateIndex];
DEBUG_PRINT("- v1: %x", v1);
if (gSynthesisReverb.useReverb == 0) {
DEBUG_PRINT("- w/o reverb");
aClearBuffer(cmd++, DMEM_ADDR_LEFT_CH, DEFAULT_LEN_2CH);
cmd = synthesis_process_notes(aiBuf, bufLen, cmd);
} else {
DEBUG_PRINT("- w/ reverb");
if (gReverbDownsampleRate == 1) {
DEBUG_PRINT("- w/ reverb downsample");
// Put the oldest samples in the ring buffer into the wet channels
DEBUG_PRINT("- set load buffer pair 1");
DEBUG_PRINT("- startPos: %d", v1->startPos);
aSetLoadBufferPair(cmd++, 0, v1->startPos);
if (v1->lengthB != 0) {
// Ring buffer wrapped
DEBUG_PRINT("- set load buffer pair 2");
aSetLoadBufferPair(cmd++, v1->lengthA, 0);
temp = 0;
}
// Use the reverb sound as initial sound for this audio update
DEBUG_PRINT("- dmem move");
aDMEMMove(cmd++, DMEM_ADDR_WET_LEFT_CH, DMEM_ADDR_LEFT_CH, DEFAULT_LEN_2CH);
// (Hopefully) lower the volume of the wet channels. New reverb will later be mixed into
// these channels.
DEBUG_PRINT("- set buffer");
aSetBuffer(cmd++, 0, 0, 0, DEFAULT_LEN_2CH);
// 0x8000 here is -100%
DEBUG_PRINT("- mix");
aMix(cmd++, 0, /*gain*/ 0x8000 + gSynthesisReverb.reverbGain, /*in*/ DMEM_ADDR_WET_LEFT_CH,
/*out*/ DMEM_ADDR_WET_LEFT_CH);
} else {
DEBUG_PRINT("- w/o reverb downsample");
// Same as above but upsample the previously downsampled samples used for reverb first
temp = 0; //! jesus christ
t4 = (v1->startPos & 7) * 2;
ra = ALIGN(v1->lengthA + t4, 4);
DEBUG_PRINT("- set load buffer pair");
aSetLoadBufferPair(cmd++, 0, v1->startPos - t4 / 2);
if (v1->lengthB != 0) {
// Ring buffer wrapped
@@ -553,12 +578,19 @@ u64 *synthesis_do_one_audio_update(s16 *aiBuf, s32 bufLen, u64 *cmd, s32 updateI
//! useless assignment.
ra = ra + temp;
}
DEBUG_PRINT("- set buffer 1");
aSetBuffer(cmd++, 0, t4 + DMEM_ADDR_WET_LEFT_CH, DMEM_ADDR_LEFT_CH, bufLen << 1);
DEBUG_PRINT("- resample 1");
aResample(cmd++, gSynthesisReverb.resampleFlags, (u16) gSynthesisReverb.resampleRate, VIRTUAL_TO_PHYSICAL2(gSynthesisReverb.resampleStateLeft));
DEBUG_PRINT("- set buffer 2");
aSetBuffer(cmd++, 0, t4 + DMEM_ADDR_WET_RIGHT_CH, DMEM_ADDR_RIGHT_CH, bufLen << 1);
DEBUG_PRINT("- resample 2");
aResample(cmd++, gSynthesisReverb.resampleFlags, (u16) gSynthesisReverb.resampleRate, VIRTUAL_TO_PHYSICAL2(gSynthesisReverb.resampleStateRight));
DEBUG_PRINT("- set buffer 3");
aSetBuffer(cmd++, 0, 0, 0, DEFAULT_LEN_2CH);
DEBUG_PRINT("- mix");
aMix(cmd++, 0, /*gain*/ 0x8000 + gSynthesisReverb.reverbGain, /*in*/ DMEM_ADDR_LEFT_CH, /*out*/ DMEM_ADDR_LEFT_CH);
DEBUG_PRINT("- dmem move");
aDMEMMove(cmd++, DMEM_ADDR_LEFT_CH, DMEM_ADDR_WET_LEFT_CH, DEFAULT_LEN_2CH);
}
cmd = synthesis_process_notes(aiBuf, bufLen, cmd);
@@ -586,6 +618,8 @@ u64 *synthesis_process_note(struct Note *note, struct NoteSubEu *noteSubEu, stru
UNUSED s32 pad0[3];
#else
u64 *synthesis_process_notes(s16 *aiBuf, s32 bufLen, u64 *cmd) {
DEBUG_PRINT("synthesis_process_notes()");
s32 noteIndex; // sp174
struct Note *note; // s7
UNUSED u8 pad0[0x08];
@@ -669,49 +703,35 @@ u64 *synthesis_process_notes(s16 *aiBuf, s32 bufLen, u64 *cmd) {
u16 noteSamplesDmemAddrBeforeResampling; // spD6, spAA
#ifndef VERSION_EU
for (noteIndex = 0; noteIndex < gMaxSimultaneousNotes; noteIndex++) {
DEBUG_PRINT("- for note index %d/%d", noteIndex, gMaxSimultaneousNotes);
DEBUG_PRINT("- getting note");
note = &gNotes[noteIndex];
#ifdef VERSION_US
//! This function requires note->enabled to be volatile, but it breaks other functions like note_enable.
//! Casting to a struct with just the volatile bitfield works, but there may be a better way to match.
DEBUG_PRINT("- if note is enabled but not loaded");
if (((struct vNote *)note)->enabled && IS_BANK_LOAD_COMPLETE(note->bankId) == FALSE) {
#else
if (IS_BANK_LOAD_COMPLETE(note->bankId) == FALSE) {
#endif
DEBUG_PRINT("- note is enabled but not loaded");
gAudioErrorFlags = (note->bankId << 8) + noteIndex + 0x1000000;
} else if (((struct vNote *)note)->enabled) {
#else
if (note->noteSubEu.enabled == FALSE) {
return cmd;
} else {
#endif
flags = 0;
#ifdef VERSION_EU
tempBufLen = bufLen;
#endif
continue;
}
#ifdef VERSION_EU
if (noteSubEu->needsInit == TRUE) {
#else
DEBUG_PRINT("- if note is enabled");
if (((struct vNote *)note)->enabled) {
DEBUG_PRINT("$ note is enabled!");
flags = 0;
DEBUG_PRINT("- if note needs to be init");
if (note->needsInit == TRUE) {
#endif
flags = A_INIT;
#ifndef VERSION_EU
note->samplePosInt = 0;
note->samplePosFrac = 0;
#else
synthesisState->restart = FALSE;
synthesisState->samplePosInt = 0;
synthesisState->samplePosFrac = 0;
synthesisState->curVolLeft = 1;
synthesisState->curVolRight = 1;
synthesisState->prevHeadsetPanRight = 0;
synthesisState->prevHeadsetPanLeft = 0;
#endif
}
#ifndef VERSION_EU
DEBUG_PRINT("- if note frequency is less than 2");
if (note->frequency < US_FLOAT(2.0)) {
nParts = 1;
if (note->frequency > US_FLOAT(1.99996)) {
@@ -730,43 +750,29 @@ u64 *synthesis_process_notes(s16 *aiBuf, s32 bufLen, u64 *cmd) {
resamplingRateFixedPoint = (u16)(s32)(resamplingRate * 32768.0f);
samplesLenFixedPoint = note->samplePosFrac + (resamplingRateFixedPoint * bufLen) * 2;
note->samplePosFrac = samplesLenFixedPoint & 0xFFFF; // 16-bit store, can't reuse
#else
resamplingRateFixedPoint = noteSubEu->resamplingRateFixedPoint;
nParts = noteSubEu->hasTwoAdpcmParts + 1;
samplesLenFixedPoint = (resamplingRateFixedPoint * tempBufLen * 2) + synthesisState->samplePosFrac;
synthesisState->samplePosFrac = samplesLenFixedPoint & 0xFFFF;
#endif
#ifdef VERSION_EU
if (noteSubEu->isSyntheticWave) {
cmd = load_wave_samples(cmd, noteSubEu, synthesisState, samplesLenFixedPoint >> 0x10);
noteSamplesDmemAddrBeforeResampling = (synthesisState->samplePosInt * 2) + DMEM_ADDR_UNCOMPRESSED_NOTE;
synthesisState->samplePosInt += samplesLenFixedPoint >> 0x10;
}
#else
DEBUG_PRINT("- if note sound is null");
if (note->sound == NULL) {
// A wave synthesis note (not ADPCM)
DEBUG_PRINT("- note is null, do wave synthesis");
cmd = load_wave_samples(cmd, note, samplesLenFixedPoint >> 0x10);
noteSamplesDmemAddrBeforeResampling = DMEM_ADDR_UNCOMPRESSED_NOTE + note->samplePosInt * 2;
note->samplePosInt += (samplesLenFixedPoint >> 0x10);
flags = 0;
}
#endif
else {
// ADPCM note
DEBUG_PRINT("- @ handle adpcm note");
#ifdef VERSION_EU
audioBookSample = noteSubEu->sound.audioBankSound->sample;
#else
audioBookSample = note->sound->sample;
#endif
loopInfo = audioBookSample->loop;
endPos = loopInfo->end;
sampleAddr = audioBookSample->sampleAddr;
resampledTempLen = 0;
for (curPart = 0; curPart < nParts; curPart++) {
DEBUG_PRINT("- for part %d", curPart);
nAdpcmSamplesProcessed = 0; // s8
s5 = 0; // s4
@@ -782,21 +788,11 @@ u64 *synthesis_process_notes(s16 *aiBuf, s32 bufLen, u64 *cmd) {
if (curLoadedBook != audioBookSample->book->book) {
u32 nEntries; // v1
curLoadedBook = audioBookSample->book->book;
#ifdef VERSION_EU
nEntries = 16 * audioBookSample->book->order * audioBookSample->book->npredictors;
aLoadADPCM(cmd++, nEntries, VIRTUAL_TO_PHYSICAL2(curLoadedBook + noteSubEu->bookOffset));
#else
nEntries = audioBookSample->book->order * audioBookSample->book->npredictors;
DEBUG_PRINT("- loading adpcm");
aLoadADPCM(cmd++, nEntries * 16, VIRTUAL_TO_PHYSICAL2(curLoadedBook));
#endif
}
#ifdef VERSION_EU
if (noteSubEu->bookOffset) {
curLoadedBook = euUnknownData_80301950; // what's this? never read
}
#endif
while (nAdpcmSamplesProcessed != samplesLenAdjusted) {
s32 samplesRemaining; // v1
s32 s0;
@@ -804,23 +800,12 @@ u64 *synthesis_process_notes(s16 *aiBuf, s32 bufLen, u64 *cmd) {
noteFinished = FALSE;
restart = FALSE;
nSamplesToProcess = samplesLenAdjusted - nAdpcmSamplesProcessed;
#ifdef VERSION_EU
s2 = synthesisState->samplePosInt & 0xf;
samplesRemaining = endPos - synthesisState->samplePosInt;
#else
s2 = note->samplePosInt & 0xf;
samplesRemaining = endPos - note->samplePosInt;
#endif
#ifdef VERSION_EU
if (s2 == 0 && synthesisState->restart == FALSE) {
s2 = 16;
}
#else
if (s2 == 0 && note->restart == FALSE) {
s2 = 16;
}
#endif
s6 = 16 - s2; // a1
if (nSamplesToProcess < samplesRemaining) {
@@ -828,11 +813,7 @@ u64 *synthesis_process_notes(s16 *aiBuf, s32 bufLen, u64 *cmd) {
s0 = t0 * 16;
s3 = s6 + s0 - nSamplesToProcess;
} else {
#ifndef VERSION_EU
s0 = samplesRemaining + s2 - 0x10;
#else
s0 = samplesRemaining - s6;
#endif
s3 = 0;
if (s0 <= 0) {
s0 = 0;
@@ -848,21 +829,10 @@ u64 *synthesis_process_notes(s16 *aiBuf, s32 bufLen, u64 *cmd) {
}
if (t0 != 0) {
#ifdef VERSION_EU
temp = (synthesisState->samplePosInt - s2 + 0x10) / 16;
if (audioBookSample->loaded == 0x81) {
v0_2 = sampleAddr + temp * 9;
} else {
v0_2 = dma_sample_data(
(uintptr_t) (sampleAddr + temp * 9),
t0 * 9, flags, &synthesisState->sampleDmaIndex);
}
#else
temp = (note->samplePosInt - s2 + 0x10) / 16;
v0_2 = dma_sample_data(
(uintptr_t) (sampleAddr + temp * 9),
t0 * 9, flags, &note->sampleDmaIndex);
#endif
a3 = (u32)((uintptr_t) v0_2 & 0xf);
aSetBuffer(cmd++, 0, DMEM_ADDR_COMPRESSED_ADPCM_DATA, 0, t0 * 9 + a3);
aLoadBuffer(cmd++, VIRTUAL_TO_PHYSICAL2(v0_2 - a3));
@@ -871,38 +841,14 @@ u64 *synthesis_process_notes(s16 *aiBuf, s32 bufLen, u64 *cmd) {
a3 = 0;
}
#ifdef VERSION_EU
if (synthesisState->restart != FALSE) {
aSetLoop(cmd++, VIRTUAL_TO_PHYSICAL2(audioBookSample->loop->state));
flags = A_LOOP; // = 2
synthesisState->restart = FALSE;
}
#else
DEBUG_PRINT("- if not note restart");
if (note->restart != FALSE) {
aSetLoop(cmd++, VIRTUAL_TO_PHYSICAL2(audioBookSample->loop->state));
flags = A_LOOP; // = 2
note->restart = FALSE;
}
#endif
nSamplesInThisIteration = s0 + s6 - s3;
#ifdef VERSION_EU
if (nAdpcmSamplesProcessed == 0) {
aSetBuffer(cmd++, 0, DMEM_ADDR_COMPRESSED_ADPCM_DATA + a3,
DMEM_ADDR_UNCOMPRESSED_NOTE, s0 * 2);
aADPCMdec(cmd++, flags,
VIRTUAL_TO_PHYSICAL2(synthesisState->synthesisBuffers->adpcmdecState));
sp130 = s2 * 2;
} else {
s5Aligned = ALIGN(s5, 5);
aSetBuffer(cmd++, 0, DMEM_ADDR_COMPRESSED_ADPCM_DATA + a3,
DMEM_ADDR_UNCOMPRESSED_NOTE + s5Aligned, s0 * 2);
aADPCMdec(cmd++, flags,
VIRTUAL_TO_PHYSICAL2(synthesisState->synthesisBuffers->adpcmdecState));
aDMEMMove(cmd++, DMEM_ADDR_UNCOMPRESSED_NOTE + s5Aligned + (s2 * 2),
DMEM_ADDR_UNCOMPRESSED_NOTE + s5, (nSamplesInThisIteration) * 2);
}
#else
if (nAdpcmSamplesProcessed == 0) {
aSetBuffer(cmd++, 0, DMEM_ADDR_COMPRESSED_ADPCM_DATA + a3, DMEM_ADDR_UNCOMPRESSED_NOTE, s0 * 2);
aADPCMdec(cmd++, flags, VIRTUAL_TO_PHYSICAL2(note->synthesisBuffers->adpcmdecState));
@@ -912,7 +858,6 @@ u64 *synthesis_process_notes(s16 *aiBuf, s32 bufLen, u64 *cmd) {
aADPCMdec(cmd++, flags, VIRTUAL_TO_PHYSICAL2(note->synthesisBuffers->adpcmdecState));
aDMEMMove(cmd++, DMEM_ADDR_UNCOMPRESSED_NOTE + ALIGN(s5, 5) + (s2 * 2), DMEM_ADDR_UNCOMPRESSED_NOTE + s5, (nSamplesInThisIteration) * 2);
}
#endif
nAdpcmSamplesProcessed += nSamplesInThisIteration;
@@ -936,35 +881,23 @@ u64 *synthesis_process_notes(s16 *aiBuf, s32 bufLen, u64 *cmd) {
}
flags = 0;
DEBUG_PRINT("- if note finished");
if (noteFinished) {
aClearBuffer(cmd++, DMEM_ADDR_UNCOMPRESSED_NOTE + s5,
(samplesLenAdjusted - nAdpcmSamplesProcessed) * 2);
#ifdef VERSION_EU
noteSubEu->finished = 1;
note->noteSubEu.finished = 1;
note->noteSubEu.enabled = 0;
#else
note->samplePosInt = 0;
note->finished = 1;
((struct vNote *)note)->enabled = 0;
#endif
break;
}
#ifdef VERSION_EU
if (restart) {
synthesisState->restart = TRUE;
synthesisState->samplePosInt = loopInfo->start;
} else {
synthesisState->samplePosInt += nSamplesToProcess;
}
#else
DEBUG_PRINT("- if restart");
if (restart) {
note->restart = TRUE;
note->samplePosInt = loopInfo->start;
} else {
note->samplePosInt += nSamplesToProcess;
}
#endif
}
switch (nParts) {
@@ -976,18 +909,10 @@ u64 *synthesis_process_notes(s16 *aiBuf, s32 bufLen, u64 *cmd) {
switch (curPart) {
case 0:
aSetBuffer(cmd++, 0, DMEM_ADDR_UNCOMPRESSED_NOTE + sp130, DMEM_ADDR_RESAMPLED, samplesLenAdjusted + 4);
#ifdef VERSION_EU
aResample(cmd++, A_INIT, 0xff60, VIRTUAL_TO_PHYSICAL2(synthesisState->synthesisBuffers->dummyResampleState));
#else
aResample(cmd++, A_INIT, 0xff60, VIRTUAL_TO_PHYSICAL2(note->synthesisBuffers->dummyResampleState));
#endif
resampledTempLen = samplesLenAdjusted + 4;
noteSamplesDmemAddrBeforeResampling = DMEM_ADDR_RESAMPLED + 4;
#ifdef VERSION_EU
if (noteSubEu->finished != FALSE) {
#else
if (note->finished != FALSE) {
#endif
aClearBuffer(cmd++, DMEM_ADDR_RESAMPLED + resampledTempLen, samplesLenAdjusted + 0x10);
}
break;
@@ -996,15 +921,9 @@ u64 *synthesis_process_notes(s16 *aiBuf, s32 bufLen, u64 *cmd) {
aSetBuffer(cmd++, 0, DMEM_ADDR_UNCOMPRESSED_NOTE + sp130,
DMEM_ADDR_RESAMPLED2,
samplesLenAdjusted + 8);
#ifdef VERSION_EU
aResample(cmd++, A_INIT, 0xff60,
VIRTUAL_TO_PHYSICAL2(
synthesisState->synthesisBuffers->dummyResampleState));
#else
aResample(cmd++, A_INIT, 0xff60,
VIRTUAL_TO_PHYSICAL2(
note->synthesisBuffers->dummyResampleState));
#endif
aDMEMMove(cmd++, DMEM_ADDR_RESAMPLED2 + 4,
DMEM_ADDR_RESAMPLED + resampledTempLen,
samplesLenAdjusted + 4);
@@ -1012,11 +931,7 @@ u64 *synthesis_process_notes(s16 *aiBuf, s32 bufLen, u64 *cmd) {
}
}
#ifdef VERSION_EU
if (noteSubEu->finished != FALSE) {
#else
if (note->finished != FALSE) {
#endif
break;
}
}
@@ -1024,15 +939,6 @@ u64 *synthesis_process_notes(s16 *aiBuf, s32 bufLen, u64 *cmd) {
flags = 0;
#ifdef VERSION_EU
if (noteSubEu->needsInit == TRUE) {
flags = A_INIT;
noteSubEu->needsInit = FALSE;
}
cmd = final_resample(cmd, synthesisState, bufLen * 2, resamplingRateFixedPoint,
noteSamplesDmemAddrBeforeResampling, flags);
#else
if (note->needsInit == TRUE) {
flags = A_INIT;
note->needsInit = FALSE;
@@ -1040,75 +946,41 @@ u64 *synthesis_process_notes(s16 *aiBuf, s32 bufLen, u64 *cmd) {
cmd = final_resample(cmd, note, bufLen * 2, resamplingRateFixedPoint,
noteSamplesDmemAddrBeforeResampling, flags);
#endif
#ifdef VERSION_EU
if (noteSubEu->headsetPanRight != 0 || synthesisState->prevHeadsetPanRight != 0) {
leftRight = 1;
} else if (noteSubEu->headsetPanLeft != 0 || synthesisState->prevHeadsetPanLeft != 0) {
leftRight = 2;
#else
if (note->headsetPanRight != 0 || note->prevHeadsetPanRight != 0) {
leftRight = 1;
} else if (note->headsetPanLeft != 0 || note->prevHeadsetPanLeft != 0) {
leftRight = 2;
#endif
} else {
leftRight = 0;
}
#ifdef VERSION_EU
cmd = process_envelope(cmd, noteSubEu, synthesisState, bufLen, 0, leftRight, flags);
#else
cmd = process_envelope(cmd, note, bufLen, 0, leftRight, flags);
#endif
#ifdef VERSION_EU
if (noteSubEu->usesHeadsetPanEffects) {
cmd = note_apply_headset_pan_effects(cmd, noteSubEu, synthesisState, bufLen * 2, flags, leftRight);
}
#else
if (note->usesHeadsetPanEffects) {
cmd = note_apply_headset_pan_effects(cmd, note, bufLen * 2, flags, leftRight);
}
#endif
}
#ifndef VERSION_EU
}
DEBUG_PRINT("- done handling notes");
DEBUG_PRINT("- setting buffer 1");
t9 = bufLen * 2;
aSetBuffer(cmd++, 0, 0, DMEM_ADDR_TEMP, t9);
DEBUG_PRINT("- interleaving");
aInterleave(cmd++, DMEM_ADDR_LEFT_CH, DMEM_ADDR_RIGHT_CH);
t9 *= 2;
DEBUG_PRINT("- setting buffer 2");
aSetBuffer(cmd++, 0, 0, DMEM_ADDR_TEMP, t9);
DEBUG_PRINT("- saving buffer");
aSaveBuffer(cmd++, VIRTUAL_TO_PHYSICAL2(aiBuf));
#endif
DEBUG_PRINT("- returning from process notes");
return cmd;
}
#ifdef VERSION_EU
u64 *load_wave_samples(u64 *cmd, struct NoteSubEu *noteSubEu, struct NoteSynthesisState *synthesisState, s32 nSamplesToLoad) {
s32 a3;
s32 repeats;
s32 i;
aSetBuffer(cmd++, /*flags*/ 0, /*dmemin*/ DMEM_ADDR_UNCOMPRESSED_NOTE, /*dmemout*/ 0, /*count*/ 128);
aLoadBuffer(cmd++, VIRTUAL_TO_PHYSICAL2(noteSubEu->sound.samples));
synthesisState->samplePosInt &= 0x3f;
a3 = 64 - synthesisState->samplePosInt;
if (a3 < nSamplesToLoad) {
repeats = (nSamplesToLoad - a3 + 63) / 64;
for (i = 0; i < repeats; i++) {
aDMEMMove(cmd++,
/*dmemin*/ DMEM_ADDR_UNCOMPRESSED_NOTE,
/*dmemout*/ DMEM_ADDR_UNCOMPRESSED_NOTE + (1 + i) * 128,
/*count*/ 128);
}
}
return cmd;
}
#else
u64 *load_wave_samples(u64 *cmd, struct Note *note, s32 nSamplesToLoad) {
s32 a3;
s32 i;
@@ -1124,21 +996,12 @@ u64 *load_wave_samples(u64 *cmd, struct Note *note, s32 nSamplesToLoad) {
}
return cmd;
}
#endif
#ifdef VERSION_EU
u64 *final_resample(u64 *cmd, struct NoteSynthesisState *synthesisState, s32 count, u16 pitch, u16 dmemIn, u32 flags) {
aSetBuffer(cmd++, /*flags*/ 0, dmemIn, /*dmemout*/ DMEM_ADDR_TEMP, count);
aResample(cmd++, flags, pitch, VIRTUAL_TO_PHYSICAL2(synthesisState->synthesisBuffers->finalResampleState));
return cmd;
}
#else
u64 *final_resample(u64 *cmd, struct Note *note, s32 count, u16 pitch, u16 dmemIn, u32 flags) {
aSetBuffer(cmd++, /*flags*/ 0, dmemIn, /*dmemout*/ DMEM_ADDR_TEMP, count);
aResample(cmd++, flags, pitch, VIRTUAL_TO_PHYSICAL2(note->synthesisBuffers->finalResampleState));
return cmd;
}
#endif
#ifndef VERSION_EU
u64 *process_envelope(u64 *cmd, struct Note *note, s32 nSamples, u16 inBuf, s32 headsetPanSettings,