From 913cda93b80cd1686181d6ab29d00ea9a1ba179a Mon Sep 17 00:00:00 2001 From: Gregory Heskett Date: Fri, 15 Dec 2023 23:57:19 -0500 Subject: [PATCH] Audio cleanup checkpoint: Large portion of synthesis.c taken care of + occasional audio optimizations (#710) --- src/audio/effects.c | 4 +- src/audio/external.c | 6 +- src/audio/internal.h | 15 +- src/audio/playback.c | 22 +- src/audio/seqplayer.c | 13 +- src/audio/synthesis.c | 801 +++++------------------------------------- 6 files changed, 108 insertions(+), 753 deletions(-) diff --git a/src/audio/effects.c b/src/audio/effects.c index 9b635e28..ec2abc25 100644 --- a/src/audio/effects.c +++ b/src/audio/effects.c @@ -3,7 +3,9 @@ #include "effects.h" #include "load.h" #include "data.h" +#include "external.h" #include "seqplayer.h" +#include "game/game_init.h" #include "game/main.h" #include "engine/math_util.h" @@ -66,7 +68,7 @@ static void sequence_channel_process_sound(struct SequenceChannel *seqChannel) { for (i = 0; i < 4; i++) { struct SequenceChannelLayer *layer = seqChannel->layers[i]; if (layer != NULL && layer->enabled && layer->note != NULL) { - layer->noteFreqScale = layer->freqScale * seqChannel->freqScale * gConfig.audioFrequency; + layer->noteFreqScale = layer->freqScale * seqChannel->freqScale; layer->noteVelocity = layer->velocitySquare * channelVolume; layer->notePan = (layer->pan * panLayerWeight) + panFromChannel; } diff --git a/src/audio/external.c b/src/audio/external.c index cf33cd37..bed409f6 100644 --- a/src/audio/external.c +++ b/src/audio/external.c @@ -1129,7 +1129,7 @@ static f32 get_sound_freq_scale(u8 bank, u8 item) { // Goes from 1 at the camera to 1 + 1/15 at AUDIO_MAX_DISTANCE (and continues rising // farther than that) - return amount / 15.0f + 1.0f; + return (amount / 15.0f + 1.0f) * gConfig.audioFrequency; } /** @@ -1311,7 +1311,7 @@ static void update_game_sound(void) { #else gSequencePlayers[SEQ_PLAYER_SFX].channels[channelIndex]->volume = 1.0f; gSequencePlayers[SEQ_PLAYER_SFX].channels[channelIndex]->pan = 0.5f; - gSequencePlayers[SEQ_PLAYER_SFX].channels[channelIndex]->freqScale = 1.0f; + gSequencePlayers[SEQ_PLAYER_SFX].channels[channelIndex]->freqScale = gConfig.audioFrequency; #endif break; case SOUND_BANK_ACTION: @@ -1477,7 +1477,7 @@ static void update_game_sound(void) { #else gSequencePlayers[SEQ_PLAYER_SFX].channels[channelIndex]->volume = 1.0f; gSequencePlayers[SEQ_PLAYER_SFX].channels[channelIndex]->pan = 0.5f; - gSequencePlayers[SEQ_PLAYER_SFX].channels[channelIndex]->freqScale = 1.0f; + gSequencePlayers[SEQ_PLAYER_SFX].channels[channelIndex]->freqScale = gConfig.audioFrequency; #endif break; case SOUND_BANK_ACTION: diff --git a/src/audio/internal.h b/src/audio/internal.h index e9c65bc9..a70d5566 100644 --- a/src/audio/internal.h +++ b/src/audio/internal.h @@ -706,17 +706,14 @@ struct Note { /*0x8C*/ struct AudioListItem listItem; /*0x9C*/ s16 curVolLeft; // Q1.15, but will always be non-negative /*0x9E*/ s16 curVolRight; // Q1.15, but will always be non-negative - /*0xA0*/ s16 reverbVolShifted; // Q1.15 #ifdef ENABLE_STEREO_HEADSET_EFFECTS - /*0xA2*/ u16 headsetPanRight; - /*0xA4*/ u16 headsetPanLeft; - /*0xA6*/ u16 prevHeadsetPanRight; - /*0xA8*/ u16 prevHeadsetPanLeft; - /* */ u8 align16Padding[0x06]; -#else - /* */ u8 align16Padding[0x0E]; + /*0xA0*/ u16 headsetPanRight; + /*0xA2*/ u16 headsetPanLeft; + /*0xA4*/ u16 prevHeadsetPanRight; + /*0xA6*/ u16 prevHeadsetPanLeft; + /* */ u8 align16Padding[0x08]; #endif -}; // size = 0xB0 +}; // size = 0xA0, 0xB0 #endif struct NoteSynthesisBuffers { diff --git a/src/audio/playback.c b/src/audio/playback.c index 50622a4b..b36faeeb 100644 --- a/src/audio/playback.c +++ b/src/audio/playback.c @@ -359,7 +359,6 @@ void process_notes(void) { #endif u8 bookOffset; #endif - struct NoteAttributes *attributes; #if defined(VERSION_JP) || defined(VERSION_US) struct AudioListItem *it; #endif @@ -580,17 +579,18 @@ void process_notes(void) { adsr_update(note); note_vibrato_update(note); - attributes = ¬e->attributes; if (note->priority == NOTE_PRIORITY_STOPPING) { + struct NoteAttributes *attributes = ¬e->attributes; frequency = attributes->freqScale; velocity = attributes->velocity; pan = attributes->pan; reverbVol = attributes->reverbVol; } else { - frequency = note->parentLayer->noteFreqScale; - velocity = note->parentLayer->noteVelocity; - pan = note->parentLayer->notePan; - reverbVol = note->parentLayer->seqChannel->reverbVol; + struct SequenceChannelLayer *parentLayer = note->parentLayer; + frequency = parentLayer->noteFreqScale; + velocity = parentLayer->noteVelocity; + pan = parentLayer->notePan; + reverbVol = parentLayer->seqChannel->reverbVol; } scale = note->adsrVolScale; @@ -875,14 +875,8 @@ void build_synthetic_wave(struct Note *note, struct SequenceChannelLayer *seqLay // Repeat sample for (offset = note->sampleCount; offset < 0x40; offset += note->sampleCount) { lim = note->sampleCount; - if (offset < 0 || offset > 0) { - for (j = 0; j < lim; j++) { - note->synthesisBuffers->samples[offset + j] = note->synthesisBuffers->samples[j]; - } - } else { - for (j = 0; j < lim; j++) { - note->synthesisBuffers->samples[offset + j] = note->synthesisBuffers->samples[j]; - } + for (j = 0; j < lim; j++) { + note->synthesisBuffers->samples[offset + j] = note->synthesisBuffers->samples[j]; } } diff --git a/src/audio/seqplayer.c b/src/audio/seqplayer.c index 1e139b2b..65a948be 100644 --- a/src/audio/seqplayer.c +++ b/src/audio/seqplayer.c @@ -6,6 +6,7 @@ #include "heap.h" #include "load.h" #include "seqplayer.h" +#include "game/main.h" #ifdef VERSION_SH void seq_channel_layer_process_script_part1(struct SequenceChannelLayer *layer); @@ -44,7 +45,7 @@ void sequence_channel_init(struct SequenceChannel *seqChannel) { seqChannel->scriptState.depth = 0; seqChannel->volume = 1.0f; seqChannel->volumeScale = 1.0f; - seqChannel->freqScale = 1.0f; + seqChannel->freqScale = gConfig.audioFrequency; seqChannel->pan = 0.5f; seqChannel->panChannelWeight = 1.0f; seqChannel->noteUnused = NULL; @@ -77,7 +78,7 @@ void sequence_channel_init(struct SequenceChannel *seqChannel) { #if defined(VERSION_EU) || defined(VERSION_SH) seqChannel->volume = 1.0f; seqChannel->volumeScale = 1.0f; - seqChannel->freqScale = 1.0f; + seqChannel->freqScale = gConfig.audioFrequency; #endif for (i = 0; i < 8; i++) { @@ -1684,7 +1685,7 @@ void sequence_channel_process_script(struct SequenceChannel *seqChannel) { case 0xde: // chan_freqscale; pitch bend using raw frequency multiplier N/2^15 (N is u16) sp5A = m64_read_s16(state); - seqChannel->freqScale = FLOAT_CAST(sp5A) / 32768.0f; + seqChannel->freqScale = FLOAT_CAST(sp5A) / 32768.0f * gConfig.audioFrequency; #if defined(VERSION_EU) || defined(VERSION_SH) seqChannel->changes.as_bitfields.freqScale = TRUE; #endif @@ -1697,7 +1698,7 @@ void sequence_channel_process_script(struct SequenceChannel *seqChannel) { #else cmd = m64_read_u8(state) + 127; #endif - seqChannel->freqScale = gPitchBendFrequencyScale[cmd]; + seqChannel->freqScale = gPitchBendFrequencyScale[cmd] * gConfig.audioFrequency; #if defined(VERSION_EU) || defined(VERSION_SH) seqChannel->changes.as_bitfields.freqScale = TRUE; #endif @@ -1706,7 +1707,7 @@ void sequence_channel_process_script(struct SequenceChannel *seqChannel) { #ifdef VERSION_SH case 0xee: cmd = m64_read_u8(state) + 0x80; - seqChannel->freqScale = unk_sh_data_1[cmd]; + seqChannel->freqScale = unk_sh_data_1[cmd] * gConfig.audioFrequency; seqChannel->changes.as_bitfields.freqScale = TRUE; break; #endif @@ -1955,7 +1956,7 @@ void sequence_channel_process_script(struct SequenceChannel *seqChannel) { seqChannel->vibratoRateTarget = 0; seqChannel->vibratoRateStart = 0; seqChannel->vibratoRateChangeDelay = 0; - seqChannel->freqScale = 1.0f; + seqChannel->freqScale = gConfig.audioFrequency; break; case 0xe9: // chan_setnotepriority diff --git a/src/audio/synthesis.c b/src/audio/synthesis.c index 6d027440..4b866a72 100644 --- a/src/audio/synthesis.c +++ b/src/audio/synthesis.c @@ -12,7 +12,6 @@ #include "game/debug.h" #include "engine/math_util.h" - #define DMEM_ADDR_TEMP 0x0 #define DMEM_ADDR_RESAMPLED 0x20 #define DMEM_ADDR_RESAMPLED2 0x160 @@ -61,7 +60,6 @@ s32 betterReverbRevIndex; // This one is okay to adjust whenever s32 betterReverbGainIndex; // This one is okay to adjust whenever #endif - struct VolumeChange { u16 sourceLeft; u16 sourceRight; @@ -69,33 +67,20 @@ struct VolumeChange { u16 targetRight; }; -u64 *synthesis_do_one_audio_update(s16 *aiBuf, s32 bufLen, u64 *cmd, s32 updateIndex); -#ifdef VERSION_EU -u64 *synthesis_process_note(struct Note *note, struct NoteSubEu *noteSubEu, struct NoteSynthesisState *synthesisState, s16 *aiBuf, s32 bufLen, u64 *cmd); -u64 *load_wave_samples(u64 *cmd, struct NoteSubEu *noteSubEu, struct NoteSynthesisState *synthesisState, s32 nSamplesToLoad); -u64 *process_envelope(u64 *cmd, struct NoteSubEu *noteSubEu, struct NoteSynthesisState *synthesisState, s32 nSamples, u16 inBuf, s32 headsetPanSettings, u32 flags); -u64 *note_apply_headset_pan_effects(u64 *cmd, struct NoteSubEu *noteSubEu, struct NoteSynthesisState *note, s32 bufLen, s32 flags, s32 leftRight); -#else -u64 *synthesis_process_notes(s16 *aiBuf, s32 bufLen, u64 *cmd); +u64 *synthesis_do_one_audio_update(s16 *aiBuf, u32 bufLen, u64 *cmd, s32 updateIndex); +u64 *synthesis_process_notes(s16 *aiBuf, u32 bufLen, u64 *cmd); u64 *load_wave_samples(u64 *cmd, struct Note *note, s32 nSamplesToLoad); #ifdef ENABLE_STEREO_HEADSET_EFFECTS u64 *process_envelope(u64 *cmd, struct Note *note, s32 nSamples, u16 inBuf, s32 headsetPanSettings); -u64 *process_envelope_inner(u64 *cmd, struct Note *note, s32 nSamples, u16 inBuf, - s32 headsetPanSettings, struct VolumeChange *vol); u64 *note_apply_headset_pan_effects(u64 *cmd, struct Note *note, s32 bufLen, s32 flags, s32 leftRight); #else u64 *process_envelope(u64 *cmd, struct Note *note, s32 nSamples, u16 inBuf); -u64 *process_envelope_inner(u64 *cmd, struct Note *note, s32 nSamples, u16 inBuf, struct VolumeChange *vol); -#endif #endif -#ifdef VERSION_EU -struct SynthesisReverb gSynthesisReverbs[4]; -u8 sAudioSynthesisPad[0x10]; -#else struct SynthesisReverb gSynthesisReverb; -u8 sAudioSynthesisPad[0x20]; -#endif + +f32 *currentRampingTableLeft; +f32 *currentRampingTableRight; #ifdef BETTER_REVERB static void reverb_samples(s16 *start, s16 *end, s16 *downsampleBuffer, s32 channel) { @@ -227,74 +212,6 @@ void set_better_reverb_buffers(u32 *inputDelaysL, u32 *inputDelaysR) { } #endif -#ifdef VERSION_EU -s16 gVolume; -s8 gUseReverb; -s8 gNumSynthesisReverbs; -struct NoteSubEu *gNoteSubsEu; -#endif - -#ifdef VERSION_EU -f32 gLeftVolRampings[3][1024]; -f32 gRightVolRampings[3][1024]; -f32 *gCurrentLeftVolRamping; // Points to any of the three left buffers above -f32 *gCurrentRightVolRamping; // Points to any of the three right buffers above - -u8 audioString1[] = "pitch %x: delaybytes %d : olddelay %d\n"; -u8 audioString2[] = "cont %x: delaybytes %d : olddelay %d\n"; -#endif - -#ifdef VERSION_EU -// Equivalent functionality as the US/JP version, -// just that the reverb structure is chosen from an array with index -void prepare_reverb_ring_buffer(s32 chunkLen, u32 updateIndex, s32 reverbIndex) { - struct ReverbRingBufferItem *item; - struct SynthesisReverb *reverb = &gSynthesisReverbs[reverbIndex]; - s32 srcPos, dstPos; - s32 nSamples; - s32 excessiveSamples; - if (reverb->downsampleRate != 1) { - if (reverb->framesLeftToIgnore == 0) { - // Now that the RSP has finished, downsample the samples produced two frames ago by skipping - // samples. - item = &reverb->items[reverb->curFrame][updateIndex]; - - // Touches both left and right since they are adjacent in memory - osInvalDCache(item->toDownsampleLeft, DEFAULT_LEN_2CH); - - for (srcPos = 0, dstPos = 0; dstPos < item->lengthA / 2; - srcPos += reverb->downsampleRate, dstPos++) { - reverb->ringBuffer.left[item->startPos + dstPos] = item->toDownsampleLeft[srcPos]; - reverb->ringBuffer.right[item->startPos + dstPos] = item->toDownsampleRight[srcPos]; - } - for (dstPos = 0; dstPos < item->lengthB / 2; srcPos += reverb->downsampleRate, dstPos++) { - reverb->ringBuffer.left[dstPos] = item->toDownsampleLeft[srcPos]; - reverb->ringBuffer.right[dstPos] = item->toDownsampleRight[srcPos]; - } - } - } - - item = &reverb->items[reverb->curFrame][updateIndex]; - nSamples = chunkLen / reverb->downsampleRate; - excessiveSamples = (nSamples + reverb->nextRingBufferPos) - reverb->bufSizePerChannel; - if (excessiveSamples < 0) { - // There is space in the ring buffer before it wraps around - item->lengthA = nSamples * 2; - item->lengthB = 0; - item->startPos = (s32) reverb->nextRingBufferPos; - reverb->nextRingBufferPos += nSamples; - } else { - // Ring buffer wrapped around - item->lengthA = (nSamples - excessiveSamples) * 2; - item->lengthB = excessiveSamples * 2; - item->startPos = reverb->nextRingBufferPos; - reverb->nextRingBufferPos = excessiveSamples; - } - // These fields are never read later - item->numSamplesAfterDownsampling = nSamples; - item->chunkLen = chunkLen; -} -#else void prepare_reverb_ring_buffer(s32 chunkLen, u32 updateIndex) { struct ReverbRingBufferItem *item; s32 srcPos, dstPos; @@ -406,108 +323,10 @@ void prepare_reverb_ring_buffer(s32 chunkLen, u32 updateIndex) { item->numSamplesAfterDownsampling = numSamplesAfterDownsampling; item->chunkLen = chunkLen; } -#endif -#ifdef VERSION_EU -u64 *synthesis_load_reverb_ring_buffer(u64 *cmd, u16 addr, u16 srcOffset, s32 len, s32 reverbIndex) { - aSetBuffer(cmd++, 0, addr, 0, len); - aLoadBuffer(cmd++, VIRTUAL_TO_PHYSICAL2(&gSynthesisReverbs[reverbIndex].ringBuffer.left[srcOffset])); - - aSetBuffer(cmd++, 0, addr + DEFAULT_LEN_1CH, 0, len); - aLoadBuffer(cmd++, VIRTUAL_TO_PHYSICAL2(&gSynthesisReverbs[reverbIndex].ringBuffer.right[srcOffset])); - - return cmd; -} -#endif - -#ifdef VERSION_EU -u64 *synthesis_save_reverb_ring_buffer(u64 *cmd, u16 addr, u16 destOffset, s32 len, s32 reverbIndex) { - aSetBuffer(cmd++, 0, 0, addr, len); - aSaveBuffer(cmd++, VIRTUAL_TO_PHYSICAL2(&gSynthesisReverbs[reverbIndex].ringBuffer.left[destOffset])); - - aSetBuffer(cmd++, 0, 0, addr + DEFAULT_LEN_1CH, len); - aSaveBuffer(cmd++, VIRTUAL_TO_PHYSICAL2(&gSynthesisReverbs[reverbIndex].ringBuffer.right[destOffset])); - - return cmd; -} -#endif - -#ifdef VERSION_EU -void synthesis_load_note_subs_eu(s32 updateIndex) { - struct NoteSubEu *src; - struct NoteSubEu *dest; - s32 i; - - for (i = 0; i < gMaxSimultaneousNotes; i++) { - src = &gNotes[i].noteSubEu; - dest = &gNoteSubsEu[gMaxSimultaneousNotes * updateIndex + i]; - if (src->enabled) { - *dest = *src; - src->needsInit = FALSE; - } else { - dest->enabled = FALSE; - } - } -} -#endif - -#ifdef VERSION_EU -// TODO: (Scrub C) pointless mask and whitespace -u64 *synthesis_execute(u64 *cmdBuf, s32 *writtenCmds, s16 *aiBuf, s32 bufLen) { - s32 i, j; - f32 *leftVolRamp; - f32 *rightVolRamp; - u32 *aiBufPtr; - u64 *cmd = cmdBuf; - s32 chunkLen; - s32 nextVolRampTable = 0; - - for (i = gAudioBufferParameters.updatesPerFrame; i > 0; i--) { - process_sequences(i - 1); - synthesis_load_note_subs_eu(gAudioBufferParameters.updatesPerFrame - i); - } - aSegment(cmd++, 0, 0); - aiBufPtr = (u32 *) aiBuf; - for (i = gAudioBufferParameters.updatesPerFrame; i > 0; i--) { - if (i == 1) { - // self-assignment has no affect when added here, could possibly simplify a macro definition - chunkLen = bufLen; - leftVolRamp = gLeftVolRampings[nextVolRampTable]; - rightVolRamp = gRightVolRampings[nextVolRampTable & 0xFFFFFFFF]; - } else { - if (bufLen / i >= gAudioBufferParameters.samplesPerUpdateMax) { - chunkLen = gAudioBufferParameters.samplesPerUpdateMax; nextVolRampTable = 2; leftVolRamp = gLeftVolRampings[2]; rightVolRamp = gRightVolRampings[2]; - } else if (bufLen / i <= gAudioBufferParameters.samplesPerUpdateMin) { - chunkLen = gAudioBufferParameters.samplesPerUpdateMin; nextVolRampTable = 0; leftVolRamp = gLeftVolRampings[0]; rightVolRamp = gRightVolRampings[0]; - } else { - chunkLen = gAudioBufferParameters.samplesPerUpdate; nextVolRampTable = 1; leftVolRamp = gLeftVolRampings[1]; rightVolRamp = gRightVolRampings[1]; - } - } - gCurrentLeftVolRamping = leftVolRamp; - gCurrentRightVolRamping = rightVolRamp; - for (j = 0; j < gNumSynthesisReverbs; j++) { - if (gSynthesisReverbs[j].useReverb) { - prepare_reverb_ring_buffer(chunkLen, gAudioBufferParameters.updatesPerFrame - i, j); - } - } - cmd = synthesis_do_one_audio_update((s16 *) aiBufPtr, chunkLen, cmd, gAudioBufferParameters.updatesPerFrame - i); - bufLen -= chunkLen; - aiBufPtr += chunkLen; - } - - for (j = 0; j < gNumSynthesisReverbs; j++) { - if (gSynthesisReverbs[j].framesLeftToIgnore != 0) { - gSynthesisReverbs[j].framesLeftToIgnore--; - } - gSynthesisReverbs[j].curFrame ^= 1; - } - *writtenCmds = cmd - cmdBuf; - return cmd; -} -#else // bufLen will be divisible by 16 u64 *synthesis_execute(u64 *cmdBuf, s32 *writtenCmds, s16 *aiBuf, s32 bufLen) { - s32 chunkLen; + u32 chunkLen; s32 i; u32 *aiBufPtr = (u32 *) aiBuf; u64 *cmd = cmdBuf + 1; @@ -567,7 +386,7 @@ u64 *synthesis_execute(u64 *cmdBuf, s32 *writtenCmds, s16 *aiBuf, s32 bufLen) { if (gSynthesisReverb.useReverb) { prepare_reverb_ring_buffer(chunkLen, gAudioUpdatesPerFrame - i); } - cmd = synthesis_do_one_audio_update((s16 *) aiBufPtr, chunkLen, cmd, gAudioUpdatesPerFrame - i); + cmd = synthesis_do_one_audio_update((s16 *) aiBufPtr, chunkLen * 2, cmd, gAudioUpdatesPerFrame - i); AUDIO_PROFILER_COMPLETE_AND_SWITCH(PROFILER_TIME_SUB_AUDIO_SYNTHESIS_ENVELOPE_REVERB, PROFILER_TIME_SUB_AUDIO_SYNTHESIS, PROFILER_TIME_SUB_AUDIO_UPDATE); @@ -581,152 +400,8 @@ u64 *synthesis_execute(u64 *cmdBuf, s32 *writtenCmds, s16 *aiBuf, s32 bufLen) { *writtenCmds = cmd - cmdBuf; return cmd; } -#endif - -#ifdef VERSION_EU -u64 *synthesis_resample_and_mix_reverb(u64 *cmd, s32 bufLen, s16 reverbIndex, s16 updateIndex) { - struct ReverbRingBufferItem *item; - s16 startPad; - s16 paddedLengthA; - - item = &gSynthesisReverbs[reverbIndex].items[gSynthesisReverbs[reverbIndex].curFrame][updateIndex]; - - aClearBuffer(cmd++, DMEM_ADDR_WET_LEFT_CH, DEFAULT_LEN_2CH); - if (gSynthesisReverbs[reverbIndex].downsampleRate == 1) { - cmd = synthesis_load_reverb_ring_buffer(cmd, DMEM_ADDR_WET_LEFT_CH, item->startPos, item->lengthA, reverbIndex); - if (item->lengthB != 0) { - cmd = synthesis_load_reverb_ring_buffer(cmd, DMEM_ADDR_WET_LEFT_CH + item->lengthA, 0, item->lengthB, reverbIndex); - } - aSetBuffer(cmd++, 0, 0, 0, DEFAULT_LEN_2CH); - aMix(cmd++, 0, 0x7fff, DMEM_ADDR_WET_LEFT_CH, DMEM_ADDR_LEFT_CH); - aMix(cmd++, 0, 0x8000 + gSynthesisReverbs[reverbIndex].reverbGain, DMEM_ADDR_WET_LEFT_CH, DMEM_ADDR_WET_LEFT_CH); - } else { - startPad = (item->startPos & 0x7) * 2; - paddedLengthA = ALIGN16(startPad + item->lengthA); - - cmd = synthesis_load_reverb_ring_buffer(cmd, DMEM_ADDR_RESAMPLED, (item->startPos - startPad / 2), DEFAULT_LEN_1CH, reverbIndex); - if (item->lengthB != 0) { - cmd = synthesis_load_reverb_ring_buffer(cmd, DMEM_ADDR_RESAMPLED + paddedLengthA, 0, DEFAULT_LEN_1CH - paddedLengthA, reverbIndex); - } - - aSetBuffer(cmd++, 0, DMEM_ADDR_RESAMPLED + startPad, DMEM_ADDR_WET_LEFT_CH, bufLen * 2); - aResample(cmd++, gSynthesisReverbs[reverbIndex].resampleFlags, gSynthesisReverbs[reverbIndex].resampleRate, VIRTUAL_TO_PHYSICAL2(gSynthesisReverbs[reverbIndex].resampleStateLeft)); - - aSetBuffer(cmd++, 0, DMEM_ADDR_RESAMPLED2 + startPad, DMEM_ADDR_WET_RIGHT_CH, bufLen * 2); - aResample(cmd++, gSynthesisReverbs[reverbIndex].resampleFlags, gSynthesisReverbs[reverbIndex].resampleRate, VIRTUAL_TO_PHYSICAL2(gSynthesisReverbs[reverbIndex].resampleStateRight)); - - aSetBuffer(cmd++, 0, 0, 0, DEFAULT_LEN_2CH); - aMix(cmd++, 0, 0x7fff, DMEM_ADDR_WET_LEFT_CH, DMEM_ADDR_LEFT_CH); - aMix(cmd++, 0, 0x8000 + gSynthesisReverbs[reverbIndex].reverbGain, DMEM_ADDR_WET_LEFT_CH, DMEM_ADDR_WET_LEFT_CH); - } - return cmd; -} - -u64 *synthesis_save_reverb_samples(u64 *cmd, s16 reverbIndex, s16 updateIndex) { - struct ReverbRingBufferItem *item; - - item = &gSynthesisReverbs[reverbIndex].items[gSynthesisReverbs[reverbIndex].curFrame][updateIndex]; - if (gSynthesisReverbs[reverbIndex].useReverb) { - switch (gSynthesisReverbs[reverbIndex].downsampleRate) { - case 1: - // Put the oldest samples in the ring buffer into the wet channels - cmd = synthesis_save_reverb_ring_buffer(cmd, DMEM_ADDR_WET_LEFT_CH, item->startPos, item->lengthA, reverbIndex); - if (item->lengthB != 0) { - // Ring buffer wrapped - cmd = synthesis_save_reverb_ring_buffer(cmd, DMEM_ADDR_WET_LEFT_CH + item->lengthA, 0, item->lengthB, reverbIndex); - } - break; - - default: - // Downsampling is done later by CPU when RSP is done, therefore we need to have double - // buffering. Left and right buffers are adjacent in memory. - aSetBuffer(cmd++, 0, 0, DMEM_ADDR_WET_LEFT_CH, DEFAULT_LEN_2CH); - aSaveBuffer(cmd++, VIRTUAL_TO_PHYSICAL2(gSynthesisReverbs[reverbIndex].items[gSynthesisReverbs[reverbIndex].curFrame][updateIndex].toDownsampleLeft)); - gSynthesisReverbs[reverbIndex].resampleFlags = 0; - break; - } - } - return cmd; -} -#endif - -#ifdef VERSION_EU -u64 *synthesis_do_one_audio_update(s16 *aiBuf, s32 bufLen, u64 *cmd, s32 updateIndex) { - struct NoteSubEu *noteSubEu; - u8 noteIndices[56]; - s32 temp; - s32 i; - s16 j; - s16 notePos = 0; - - if (gNumSynthesisReverbs == 0) { - for (i = 0; i < gMaxSimultaneousNotes; i++) { - if (gNoteSubsEu[gMaxSimultaneousNotes * updateIndex + i].enabled) { - noteIndices[notePos++] = i; - } - } - } else { - for (j = 0; j < gNumSynthesisReverbs; j++) { - for (i = 0; i < gMaxSimultaneousNotes; i++) { - noteSubEu = &gNoteSubsEu[gMaxSimultaneousNotes * updateIndex + i]; - if (noteSubEu->enabled && j == noteSubEu->reverbIndex) { - noteIndices[notePos++] = i; - } - } - } - - for (i = 0; i < gMaxSimultaneousNotes; i++) { - noteSubEu = &gNoteSubsEu[gMaxSimultaneousNotes * updateIndex + i]; - if (noteSubEu->enabled && noteSubEu->reverbIndex >= gNumSynthesisReverbs) { - noteIndices[notePos++] = i; - } - } - } - aClearBuffer(cmd++, DMEM_ADDR_LEFT_CH, DEFAULT_LEN_2CH); - i = 0; - for (j = 0; j < gNumSynthesisReverbs; j++) { - gUseReverb = gSynthesisReverbs[j].useReverb; - if (gUseReverb) { - cmd = synthesis_resample_and_mix_reverb(cmd, bufLen, j, updateIndex); - } - for (; i < notePos; i++) { - temp = updateIndex * gMaxSimultaneousNotes; - if (j == gNoteSubsEu[temp + noteIndices[i]].reverbIndex) { - cmd = synthesis_process_note(&gNotes[noteIndices[i]], - &gNoteSubsEu[temp + noteIndices[i]], - &gNotes[noteIndices[i]].synthesisState, - aiBuf, bufLen, cmd); - continue; - } else { - break; - } - } - if (gSynthesisReverbs[j].useReverb) { - cmd = synthesis_save_reverb_samples(cmd, j, updateIndex); - } - } - for (; i < notePos; i++) { - temp = updateIndex * gMaxSimultaneousNotes; - if (IS_BANK_LOAD_COMPLETE(gNoteSubsEu[temp + noteIndices[i]].bankId)) { - cmd = synthesis_process_note(&gNotes[noteIndices[i]], - &gNoteSubsEu[temp + noteIndices[i]], - &gNotes[noteIndices[i]].synthesisState, - aiBuf, bufLen, cmd); - } else { - gAudioErrorFlags = (gNoteSubsEu[temp + noteIndices[i]].bankId + (i << 8)) + 0x10000000; - } - } - - temp = bufLen * 2; - aSetBuffer(cmd++, 0, 0, DMEM_ADDR_TEMP, temp); - aInterleave(cmd++, DMEM_ADDR_LEFT_CH, DMEM_ADDR_RIGHT_CH); - aSetBuffer(cmd++, 0, 0, DMEM_ADDR_TEMP, temp * 2); - aSaveBuffer(cmd++, VIRTUAL_TO_PHYSICAL2(aiBuf)); - return cmd; -} -#else -u64 *synthesis_do_one_audio_update(s16 *aiBuf, s32 bufLen, u64 *cmd, s32 updateIndex) { +u64 *synthesis_do_one_audio_update(s16 *aiBuf, u32 bufLen, u64 *cmd, s32 updateIndex) { s16 ra; s16 t4; struct ReverbRingBufferItem *v1; @@ -766,9 +441,9 @@ u64 *synthesis_do_one_audio_update(s16 *aiBuf, s32 bufLen, u64 *cmd, s32 updateI // Ring buffer wrapped aSetLoadBufferPair(cmd++, ra, 0); } - aSetBuffer(cmd++, 0, t4 + DMEM_ADDR_WET_LEFT_CH, DMEM_ADDR_LEFT_CH, bufLen << 1); + aSetBuffer(cmd++, 0, t4 + DMEM_ADDR_WET_LEFT_CH, DMEM_ADDR_LEFT_CH, bufLen); aResample(cmd++, gSynthesisReverb.resampleFlags, (u16) gSynthesisReverb.resampleRate, VIRTUAL_TO_PHYSICAL2(gSynthesisReverb.resampleStateLeft)); - aSetBuffer(cmd++, 0, t4 + DMEM_ADDR_WET_RIGHT_CH, DMEM_ADDR_RIGHT_CH, bufLen << 1); + aSetBuffer(cmd++, 0, t4 + DMEM_ADDR_WET_RIGHT_CH, DMEM_ADDR_RIGHT_CH, bufLen); aResample(cmd++, gSynthesisReverb.resampleFlags, (u16) gSynthesisReverb.resampleRate, VIRTUAL_TO_PHYSICAL2(gSynthesisReverb.resampleStateRight)); aDMEMMove(cmd++, DMEM_ADDR_LEFT_CH, DMEM_ADDR_WET_LEFT_CH, DEFAULT_LEN_2CH); aSetBuffer(cmd++, 0, 0, 0, DEFAULT_LEN_2CH); @@ -795,57 +470,28 @@ u64 *synthesis_do_one_audio_update(s16 *aiBuf, s32 bufLen, u64 *cmd, s32 updateI } return cmd; } -#endif -#ifdef VERSION_EU -// Processes just one note, not all -u64 *synthesis_process_note(struct Note *note, struct NoteSubEu *noteSubEu, struct NoteSynthesisState *synthesisState, UNUSED s16 *aiBuf, s32 bufLen, u64 *cmd) { -#else -u64 *synthesis_process_notes(s16 *aiBuf, s32 bufLen, u64 *cmd) { +u64 *synthesis_process_notes(s16 *aiBuf, u32 bufLen, u64 *cmd) { s32 noteIndex; // sp174 struct Note *note; // s7 -#endif struct AudioBankSample *audioBookSample; // sp164, sp138 struct AdpcmLoop *loopInfo; // sp160, sp134 s16 *curLoadedBook = NULL; // sp154, sp130 -#ifndef VERSION_EU - u16 resamplingRateFixedPoint; // sp5c, sp11A -#endif s32 noteFinished; // 150 t2, sp124 s32 restart; // 14c t3, sp120 s32 flags; // sp148, sp11C -#ifdef VERSION_EU - u16 resamplingRateFixedPoint; // sp5c, sp11A -#endif - UNUSED s32 tempBufLen; s32 sp130 = 0; //sp128, sp104 s32 nAdpcmSamplesProcessed; // signed required for US s32 t0; -#ifdef VERSION_EU u8 *sampleAddr; // sp120, spF4 s32 s6; -#else - s32 s6; - u8 *sampleAddr; // sp120, spF4 -#endif -#ifdef VERSION_EU - s32 samplesLenAdjusted; // 108, spEC - // Might have been used to store (samplesLenFixedPoint >> 0x10), but doing so causes strange + // Might have been used to store (samplesLenFixedPoint >> 16), but doing so causes strange // behavior with the break near the end of the loop, causing US and JP to need a goto instead - UNUSED s32 samplesLenInt; - s32 endPos; // sp110, spE4 - s32 nSamplesToProcess; // sp10c/a0, spE0 - s32 s2; -#else - // Might have been used to store (samplesLenFixedPoint >> 0x10), but doing so causes strange - // behavior with the break near the end of the loop, causing US and JP to need a goto instead - UNUSED s32 samplesLenInt; s32 samplesLenAdjusted; // 108 s32 s2; s32 endPos; // sp110, spE4 s32 nSamplesToProcess; // sp10c/a0, spE0 -#endif #ifdef ENABLE_STEREO_HEADSET_EFFECTS s32 leftRight; @@ -856,68 +502,49 @@ u64 *synthesis_process_notes(s16 *aiBuf, s32 bufLen, u64 *cmd) { u32 samplesLenFixedPoint; // v1_1 s32 nSamplesInThisIteration; // v1_2 u32 a3; -#ifndef VERSION_EU - s32 t9; -#endif u8 *v0_2; s32 nParts; // spE8, spBC s32 curPart; // spE4, spB8 -#ifndef VERSION_EU f32 resamplingRate; // f12 -#endif s32 temp; -#ifdef VERSION_EU s32 s5Aligned; -#endif s32 resampledTempLen; // spD8, spAC u16 noteSamplesDmemAddrBeforeResampling = 0; // spD6, spAA + u16 resamplingRateFixedPoint; // sp5c, sp11A + switch (bufLen) { + case (128 * 2): + currentRampingTableLeft = gVolRampingLhs128; + currentRampingTableRight = gVolRampingRhs128; + break; + case (144 * 2): + currentRampingTableLeft = gVolRampingLhs144; + currentRampingTableRight = gVolRampingRhs144; + break; + case (136 * 2): + default: + currentRampingTableLeft = gVolRampingLhs136; + currentRampingTableRight = gVolRampingRhs136; + break; + } -#ifndef VERSION_EU for (noteIndex = 0; noteIndex < gMaxSimultaneousNotes; noteIndex++) { 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. if (((struct vNote *)note)->enabled && !IS_BANK_LOAD_COMPLETE(note->bankId)) { -#else - if (!IS_BANK_LOAD_COMPLETE(note->bankId)) { -#endif 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 -#ifdef VERSION_EU - if (noteSubEu->needsInit == TRUE) { -#else 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 if (note->frequency < 2.0f) { nParts = 1; if (note->frequency > 1.99996f) { @@ -934,39 +561,20 @@ u64 *synthesis_process_notes(s16 *aiBuf, s32 bufLen, u64 *cmd) { } resamplingRateFixedPoint = (u16)(s32)(resamplingRate * 32768.0f); - samplesLenFixedPoint = note->samplePosFrac + (resamplingRateFixedPoint * bufLen) * 2; + samplesLenFixedPoint = note->samplePosFrac + (resamplingRateFixedPoint * bufLen); 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 if (note->sound == NULL) { // A wave synthesis note (not ADPCM) - cmd = load_wave_samples(cmd, note, samplesLenFixedPoint >> 0x10); + cmd = load_wave_samples(cmd, note, samplesLenFixedPoint >> 16); noteSamplesDmemAddrBeforeResampling = DMEM_ADDR_UNCOMPRESSED_NOTE + note->samplePosInt * 2; - note->samplePosInt += (samplesLenFixedPoint >> 0x10); + note->samplePosInt += (samplesLenFixedPoint >> 16); flags = 0; } -#endif else { // ADPCM note - -#ifdef VERSION_EU - audioBookSample = noteSubEu->sound.audioBankSound->sample; -#else audioBookSample = note->sound->sample; -#endif loopInfo = audioBookSample->loop; endPos = loopInfo->end; @@ -977,32 +585,21 @@ u64 *synthesis_process_notes(s16 *aiBuf, s32 bufLen, u64 *cmd) { s5 = 0; // s4 if (nParts == 1) { - samplesLenAdjusted = samplesLenFixedPoint >> 0x10; - } else if ((samplesLenFixedPoint >> 0x10) & 1) { - samplesLenAdjusted = ((samplesLenFixedPoint >> 0x10) & ~1) + (curPart * 2); + samplesLenAdjusted = samplesLenFixedPoint >> 16; + } else if ((samplesLenFixedPoint >> 16) & 1) { + samplesLenAdjusted = ((samplesLenFixedPoint >> 16) & ~1) + (curPart * 2); } else { - samplesLenAdjusted = (samplesLenFixedPoint >> 0x10); + samplesLenAdjusted = (samplesLenFixedPoint >> 16); } 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; - aLoadADPCM(cmd++, nEntries * 16, VIRTUAL_TO_PHYSICAL2(curLoadedBook)); -#endif + nEntries = audioBookSample->book->order * audioBookSample->book->npredictors * 16U; + aLoadADPCM(cmd++, nEntries, VIRTUAL_TO_PHYSICAL2(curLoadedBook)); } -#ifdef VERSION_EU - if (noteSubEu->bookOffset) { - curLoadedBook = euUnknownData_80301950; // what's this? never read - } -#endif - while (nAdpcmSamplesProcessed != samplesLenAdjusted) { s32 samplesRemaining; // v1 s32 s0; @@ -1010,23 +607,13 @@ 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) { @@ -1034,11 +621,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; @@ -1054,22 +637,7 @@ 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 { - AUDIO_PROFILER_SWITCH(PROFILER_TIME_SUB_AUDIO_SYNTHESIS_PROCESSING, PROFILER_TIME_SUB_AUDIO_SYNTHESIS_DMA); - - v0_2 = dma_sample_data( - (uintptr_t) (sampleAddr + temp * 9), - t0 * 9, flags, &synthesisState->sampleDmaIndex); - - AUDIO_PROFILER_SWITCH(PROFILER_TIME_SUB_AUDIO_SYNTHESIS_DMA, PROFILER_TIME_SUB_AUDIO_SYNTHESIS_PROCESSING); - } -#else - // HACKERSM64_TODO: Is the EU thing above applicable to US? Could potentially save some resources. - temp = (note->samplePosInt - s2 + 0x10) / 16; + temp = (note->samplePosInt - s2 + 16) / 16; AUDIO_PROFILER_SWITCH(PROFILER_TIME_SUB_AUDIO_SYNTHESIS_PROCESSING, PROFILER_TIME_SUB_AUDIO_SYNTHESIS_DMA); @@ -1078,7 +646,7 @@ u64 *synthesis_process_notes(s16 *aiBuf, s32 bufLen, u64 *cmd) { t0 * 9, flags, ¬e->sampleDmaIndex); AUDIO_PROFILER_SWITCH(PROFILER_TIME_SUB_AUDIO_SYNTHESIS_DMA, PROFILER_TIME_SUB_AUDIO_SYNTHESIS_PROCESSING); -#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)); @@ -1087,48 +655,23 @@ 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 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 = ALIGN32(s5); - 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)); sp130 = s2 * 2; } else { - aSetBuffer(cmd++, 0, DMEM_ADDR_COMPRESSED_ADPCM_DATA + a3, DMEM_ADDR_UNCOMPRESSED_NOTE + ALIGN32(s5), s0 * 2); + s5Aligned = ALIGN32(s5); + aSetBuffer(cmd++, 0, DMEM_ADDR_COMPRESSED_ADPCM_DATA + a3, DMEM_ADDR_UNCOMPRESSED_NOTE + s5Aligned, s0 * 2); aADPCMdec(cmd++, flags, VIRTUAL_TO_PHYSICAL2(note->synthesisBuffers->adpcmdecState)); - aDMEMMove(cmd++, DMEM_ADDR_UNCOMPRESSED_NOTE + ALIGN32(s5) + (s2 * 2), DMEM_ADDR_UNCOMPRESSED_NOTE + s5, (nSamplesInThisIteration) * 2); + aDMEMMove(cmd++, DMEM_ADDR_UNCOMPRESSED_NOTE + s5Aligned + (s2 * 2), DMEM_ADDR_UNCOMPRESSED_NOTE + s5, (nSamplesInThisIteration) * 2); } -#endif nAdpcmSamplesProcessed += nSamplesInThisIteration; @@ -1160,32 +703,18 @@ u64 *synthesis_process_notes(s16 *aiBuf, s32 bufLen, u64 *cmd) { 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 + if (restart) { note->restart = TRUE; note->samplePosInt = loopInfo->start; } else { note->samplePosInt += nSamplesToProcess; } -#endif } switch (nParts) { @@ -1197,19 +726,11 @@ 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); + aClearBuffer(cmd++, DMEM_ADDR_RESAMPLED + resampledTempLen, samplesLenAdjusted + 16); } break; @@ -1217,15 +738,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); @@ -1233,137 +748,86 @@ u64 *synthesis_process_notes(s16 *aiBuf, s32 bufLen, u64 *cmd) { } } -#ifdef VERSION_EU - if (noteSubEu->finished != FALSE) { -#else if (note->finished != FALSE) { -#endif break; } } } flags = 0; - -#ifdef VERSION_EU - if (noteSubEu->needsInit == TRUE) { - flags = A_INIT; - noteSubEu->needsInit = FALSE; - } - - // final resample - aSetBuffer(cmd++, /*flags*/ 0, noteSamplesDmemAddrBeforeResampling, /*dmemout*/ DMEM_ADDR_TEMP, bufLen * 2); - aResample(cmd++, flags, resamplingRateFixedPoint, VIRTUAL_TO_PHYSICAL2(synthesisState->synthesisBuffers->finalResampleState)); -#else if (note->needsInit == TRUE) { flags = A_INIT; note->needsInit = FALSE; } // final resample - aSetBuffer(cmd++, /*flags*/ 0, noteSamplesDmemAddrBeforeResampling, /*dmemout*/ DMEM_ADDR_TEMP, bufLen * 2); + aSetBuffer(cmd++, /*flags*/ 0, noteSamplesDmemAddrBeforeResampling, /*dmemout*/ DMEM_ADDR_TEMP, bufLen); aResample(cmd++, flags, resamplingRateFixedPoint, VIRTUAL_TO_PHYSICAL2(note->synthesisBuffers->finalResampleState)); -#endif #ifdef ENABLE_STEREO_HEADSET_EFFECTS -#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; } AUDIO_PROFILER_SWITCH(PROFILER_TIME_SUB_AUDIO_SYNTHESIS_PROCESSING, PROFILER_TIME_SUB_AUDIO_SYNTHESIS_ENVELOPE_REVERB); -#ifdef VERSION_EU - cmd = process_envelope(cmd, noteSubEu, synthesisState, bufLen, 0, leftRight, flags); -#else cmd = process_envelope(cmd, note, bufLen, 0, leftRight); -#endif AUDIO_PROFILER_SWITCH(PROFILER_TIME_SUB_AUDIO_SYNTHESIS_ENVELOPE_REVERB, PROFILER_TIME_SUB_AUDIO_SYNTHESIS_PROCESSING); -#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); + cmd = note_apply_headset_pan_effects(cmd, note, bufLen, flags, leftRight); } -#endif #else AUDIO_PROFILER_SWITCH(PROFILER_TIME_SUB_AUDIO_SYNTHESIS_PROCESSING, PROFILER_TIME_SUB_AUDIO_SYNTHESIS_ENVELOPE_REVERB); cmd = process_envelope(cmd, note, bufLen, 0); AUDIO_PROFILER_SWITCH(PROFILER_TIME_SUB_AUDIO_SYNTHESIS_ENVELOPE_REVERB, PROFILER_TIME_SUB_AUDIO_SYNTHESIS_PROCESSING); #endif } -#ifndef VERSION_EU } - t9 = bufLen * 2; - aSetBuffer(cmd++, 0, 0, DMEM_ADDR_TEMP, t9); + aSetBuffer(cmd++, 0, 0, DMEM_ADDR_TEMP, bufLen); aInterleave(cmd++, DMEM_ADDR_LEFT_CH, DMEM_ADDR_RIGHT_CH); - t9 *= 2; - aSetBuffer(cmd++, 0, 0, DMEM_ADDR_TEMP, t9); + aSetBuffer(cmd++, 0, 0, DMEM_ADDR_TEMP, bufLen * 2); aSaveBuffer(cmd++, VIRTUAL_TO_PHYSICAL2(aiBuf)); -#endif return cmd; } -#ifdef VERSION_EU -u64 *load_wave_samples(u64 *cmd, struct NoteSubEu *noteSubEu, struct NoteSynthesisState *synthesisState, s32 nSamplesToLoad) { +u64 *load_wave_samples(u64 *cmd, struct Note *note, 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)); + aSetBuffer(cmd++, /*flags*/ 0, /*dmemin*/ DMEM_ADDR_UNCOMPRESSED_NOTE, /*dmemout*/ 0, + /*count*/ sizeof(note->synthesisBuffers->samples)); + aLoadBuffer(cmd++, VIRTUAL_TO_PHYSICAL2(note->synthesisBuffers->samples)); - synthesisState->samplePosInt &= 0x3f; - a3 = 64 - synthesisState->samplePosInt; + note->samplePosInt &= (note->sampleCount - 1); + a3 = 64 - note->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); + /*dmemout*/ DMEM_ADDR_UNCOMPRESSED_NOTE + (1 + i) * sizeof(note->synthesisBuffers->samples), + /*count*/ sizeof(note->synthesisBuffers->samples)); } } return cmd; } -#else -u64 *load_wave_samples(u64 *cmd, struct Note *note, s32 nSamplesToLoad) { - s32 a3; - s32 i; - aSetBuffer(cmd++, /*flags*/ 0, /*dmemin*/ DMEM_ADDR_UNCOMPRESSED_NOTE, /*dmemout*/ 0, - /*count*/ sizeof(note->synthesisBuffers->samples)); - aLoadBuffer(cmd++, VIRTUAL_TO_PHYSICAL2(note->synthesisBuffers->samples)); - note->samplePosInt &= (note->sampleCount - 1); - a3 = 64 - note->samplePosInt; - if (a3 < nSamplesToLoad) { - for (i = 0; i <= (nSamplesToLoad - a3 + 63) / 64 - 1; i++) { - aDMEMMove(cmd++, /*dmemin*/ DMEM_ADDR_UNCOMPRESSED_NOTE, /*dmemout*/ DMEM_ADDR_UNCOMPRESSED_NOTE + (1 + i) * sizeof(note->synthesisBuffers->samples), /*count*/ sizeof(note->synthesisBuffers->samples)); - } - } - return cmd; -} -#endif -#ifndef VERSION_EU #ifdef ENABLE_STEREO_HEADSET_EFFECTS u64 *process_envelope(u64 *cmd, struct Note *note, s32 nSamples, u16 inBuf, s32 headsetPanSettings) { #else u64 *process_envelope(u64 *cmd, struct Note *note, s32 nSamples, u16 inBuf) { #endif + u8 mixerFlags; + s32 rampLeft; + s32 rampRight; struct VolumeChange vol; + if (note->initFullVelocity) { note->initFullVelocity = FALSE; vol.sourceLeft = note->targetVolLeft; @@ -1376,45 +840,6 @@ u64 *process_envelope(u64 *cmd, struct Note *note, s32 nSamples, u16 inBuf) { vol.targetRight = note->targetVolRight; note->curVolLeft = vol.targetLeft; note->curVolRight = vol.targetRight; -#ifdef ENABLE_STEREO_HEADSET_EFFECTS - return process_envelope_inner(cmd, note, nSamples, inBuf, headsetPanSettings, &vol); -#else - return process_envelope_inner(cmd, note, nSamples, inBuf, &vol); -#endif -} - -#ifdef ENABLE_STEREO_HEADSET_EFFECTS -u64 *process_envelope_inner(u64 *cmd, struct Note *note, s32 nSamples, u16 inBuf, - s32 headsetPanSettings, struct VolumeChange *vol) { -#else -u64 *process_envelope_inner(u64 *cmd, struct Note *note, s32 nSamples, u16 inBuf, - struct VolumeChange *vol) { -#endif - u8 mixerFlags; - s32 rampLeft, rampRight; -#elif defined(VERSION_EU) -u64 *process_envelope(u64 *cmd, struct NoteSubEu *note, struct NoteSynthesisState *synthesisState, s32 nSamples, u16 inBuf, s32 headsetPanSettings, UNUSED u32 flags) { - u16 sourceRight; - u16 sourceLeft; - u16 targetLeft; - u16 targetRight; - s32 mixerFlags; - s32 rampLeft; - s32 rampRight; - - sourceLeft = synthesisState->curVolLeft; - sourceRight = synthesisState->curVolRight; - targetLeft = (note->targetVolLeft << 5); - targetRight = (note->targetVolRight << 5); - if (targetLeft == 0) { - targetLeft++; - } - if (targetRight == 0) { - targetRight++; - } - synthesisState->curVolLeft = targetLeft; - synthesisState->curVolRight = targetRight; -#endif // For aEnvMixer, five buffers and count are set using aSetBuffer. // in, dry left, count without A_AUX flag. @@ -1426,17 +851,17 @@ u64 *process_envelope(u64 *cmd, struct NoteSubEu *note, struct NoteSynthesisStat switch (headsetPanSettings) { case 1: - aSetBuffer(cmd++, 0, inBuf, DMEM_ADDR_NOTE_PAN_TEMP, nSamples * 2); + aSetBuffer(cmd++, 0, inBuf, DMEM_ADDR_NOTE_PAN_TEMP, nSamples); aSetBuffer(cmd++, A_AUX, DMEM_ADDR_RIGHT_CH, DMEM_ADDR_WET_LEFT_CH, DMEM_ADDR_WET_RIGHT_CH); break; case 2: - aSetBuffer(cmd++, 0, inBuf, DMEM_ADDR_LEFT_CH, nSamples * 2); + aSetBuffer(cmd++, 0, inBuf, DMEM_ADDR_LEFT_CH, nSamples); aSetBuffer(cmd++, A_AUX, DMEM_ADDR_NOTE_PAN_TEMP, DMEM_ADDR_WET_LEFT_CH, DMEM_ADDR_WET_RIGHT_CH); break; default: - aSetBuffer(cmd++, 0, inBuf, DMEM_ADDR_LEFT_CH, nSamples * 2); + aSetBuffer(cmd++, 0, inBuf, DMEM_ADDR_LEFT_CH, nSamples); aSetBuffer(cmd++, A_AUX, DMEM_ADDR_RIGHT_CH, DMEM_ADDR_WET_LEFT_CH, DMEM_ADDR_WET_RIGHT_CH); break; @@ -1447,106 +872,66 @@ u64 *process_envelope(u64 *cmd, struct NoteSubEu *note, struct NoteSynthesisStat // mixed into a temporary buffer and then subtracted from the normal buffer. if (note->stereoStrongRight) { aClearBuffer(cmd++, DMEM_ADDR_STEREO_STRONG_TEMP_DRY, DEFAULT_LEN_2CH); - aSetBuffer(cmd++, 0, inBuf, DMEM_ADDR_STEREO_STRONG_TEMP_DRY, nSamples * 2); + aSetBuffer(cmd++, 0, inBuf, DMEM_ADDR_STEREO_STRONG_TEMP_DRY, nSamples); aSetBuffer(cmd++, A_AUX, DMEM_ADDR_RIGHT_CH, DMEM_ADDR_STEREO_STRONG_TEMP_WET, DMEM_ADDR_WET_RIGHT_CH); } else if (note->stereoStrongLeft) { aClearBuffer(cmd++, DMEM_ADDR_STEREO_STRONG_TEMP_DRY, DEFAULT_LEN_2CH); - aSetBuffer(cmd++, 0, inBuf, DMEM_ADDR_LEFT_CH, nSamples * 2); + aSetBuffer(cmd++, 0, inBuf, DMEM_ADDR_LEFT_CH, nSamples); aSetBuffer(cmd++, A_AUX, DMEM_ADDR_STEREO_STRONG_TEMP_DRY, DMEM_ADDR_WET_LEFT_CH, DMEM_ADDR_STEREO_STRONG_TEMP_WET); } else { - aSetBuffer(cmd++, 0, inBuf, DMEM_ADDR_LEFT_CH, nSamples * 2); + aSetBuffer(cmd++, 0, inBuf, DMEM_ADDR_LEFT_CH, nSamples); aSetBuffer(cmd++, A_AUX, DMEM_ADDR_RIGHT_CH, DMEM_ADDR_WET_LEFT_CH, DMEM_ADDR_WET_RIGHT_CH); } } #else - aSetBuffer(cmd++, 0, inBuf, DMEM_ADDR_LEFT_CH, nSamples * 2); + aSetBuffer(cmd++, 0, inBuf, DMEM_ADDR_LEFT_CH, nSamples); aSetBuffer(cmd++, A_AUX, DMEM_ADDR_RIGHT_CH, DMEM_ADDR_WET_LEFT_CH, DMEM_ADDR_WET_RIGHT_CH); #endif -#ifdef VERSION_EU - if (targetLeft == sourceLeft && targetRight == sourceRight && !note->envMixerNeedsInit) { -#else - if (vol->targetLeft == vol->sourceLeft && vol->targetRight == vol->sourceRight + if (vol.targetLeft == vol.sourceLeft && vol.targetRight == vol.sourceRight && !note->envMixerNeedsInit) { -#endif mixerFlags = A_CONTINUE; } else { mixerFlags = A_INIT; -#ifdef VERSION_EU - rampLeft = gCurrentLeftVolRamping[targetLeft >> 5] * gCurrentRightVolRamping[sourceLeft >> 5]; - rampRight = gCurrentLeftVolRamping[targetRight >> 5] * gCurrentRightVolRamping[sourceRight >> 5]; -#else // volume ramping // This roughly computes 2^16 * (targetVol / sourceVol) ^ (8 / arg2), // but with discretizations of targetVol, sourceVol and arg2. - switch (nSamples) { - case 128: - rampLeft = gVolRampingLhs128[vol->targetLeft >> (15 - VOL_RAMPING_EXPONENT)] * gVolRampingRhs128[vol->sourceLeft >> (15 - VOL_RAMPING_EXPONENT)]; - rampRight = gVolRampingLhs128[vol->targetRight >> (15 - VOL_RAMPING_EXPONENT)] * gVolRampingRhs128[vol->sourceRight >> (15 - VOL_RAMPING_EXPONENT)]; - break; - case 144: - rampLeft = gVolRampingLhs144[vol->targetLeft >> (15 - VOL_RAMPING_EXPONENT)] * gVolRampingRhs144[vol->sourceLeft >> (15 - VOL_RAMPING_EXPONENT)]; - rampRight = gVolRampingLhs144[vol->targetRight >> (15 - VOL_RAMPING_EXPONENT)] * gVolRampingRhs144[vol->sourceRight >> (15 - VOL_RAMPING_EXPONENT)]; - break; - case 136: - default: - rampLeft = gVolRampingLhs136[vol->targetLeft >> (15 - VOL_RAMPING_EXPONENT)] * gVolRampingRhs136[vol->sourceLeft >> (15 - VOL_RAMPING_EXPONENT)]; - rampRight = gVolRampingLhs136[vol->targetRight >> (15 - VOL_RAMPING_EXPONENT)] * gVolRampingRhs136[vol->sourceRight >> (15 - VOL_RAMPING_EXPONENT)]; - break; - } -#endif + rampLeft = currentRampingTableLeft[vol.targetLeft >> (15 - VOL_RAMPING_EXPONENT)] * currentRampingTableRight[vol.sourceLeft >> (15 - VOL_RAMPING_EXPONENT)]; + rampRight = currentRampingTableLeft[vol.targetRight >> (15 - VOL_RAMPING_EXPONENT)] * currentRampingTableRight[vol.sourceRight >> (15 - VOL_RAMPING_EXPONENT)]; // The operation's parameters change meanings depending on flags -#ifdef VERSION_EU - aSetVolume(cmd++, A_VOL | A_LEFT, sourceLeft, 0, 0); - aSetVolume(cmd++, A_VOL | A_RIGHT, sourceRight, 0, 0); - aSetVolume32(cmd++, A_RATE | A_LEFT, targetLeft, rampLeft); - aSetVolume32(cmd++, A_RATE | A_RIGHT, targetRight, rampRight); + aSetVolume(cmd++, A_VOL | A_LEFT, vol.sourceLeft, 0, 0); + aSetVolume(cmd++, A_VOL | A_RIGHT, vol.sourceRight, 0, 0); + aSetVolume32(cmd++, A_RATE | A_LEFT, vol.targetLeft, rampLeft); + aSetVolume32(cmd++, A_RATE | A_RIGHT, vol.targetRight, rampRight); aSetVolume(cmd++, A_AUX, gVolume, 0, note->reverbVol << 8); -#else - aSetVolume(cmd++, A_VOL | A_LEFT, vol->sourceLeft, 0, 0); - aSetVolume(cmd++, A_VOL | A_RIGHT, vol->sourceRight, 0, 0); - aSetVolume32(cmd++, A_RATE | A_LEFT, vol->targetLeft, rampLeft); - aSetVolume32(cmd++, A_RATE | A_RIGHT, vol->targetRight, rampRight); - aSetVolume(cmd++, A_AUX, gVolume, 0, note->reverbVolShifted); -#endif } #ifdef ENABLE_STEREO_HEADSET_EFFECTS -#ifdef VERSION_EU - if (gUseReverb && note->reverbVol != 0) { - aEnvMixer(cmd++, mixerFlags | A_AUX, - VIRTUAL_TO_PHYSICAL2(synthesisState->synthesisBuffers->mixEnvelopeState)); -#else if (gSynthesisReverb.useReverb && note->reverbVol != 0) { aEnvMixer(cmd++, mixerFlags | A_AUX, VIRTUAL_TO_PHYSICAL2(note->synthesisBuffers->mixEnvelopeState)); -#endif if (note->stereoStrongRight) { - aSetBuffer(cmd++, 0, 0, 0, nSamples * 2); + aSetBuffer(cmd++, 0, 0, 0, nSamples); // 0x8000 is -100%, so subtract sound instead of adding... aMix(cmd++, 0, /*gain*/ 0x8000, /*in*/ DMEM_ADDR_STEREO_STRONG_TEMP_DRY, /*out*/ DMEM_ADDR_LEFT_CH); aMix(cmd++, 0, /*gain*/ 0x8000, /*in*/ DMEM_ADDR_STEREO_STRONG_TEMP_WET, /*out*/ DMEM_ADDR_WET_LEFT_CH); } else if (note->stereoStrongLeft) { - aSetBuffer(cmd++, 0, 0, 0, nSamples * 2); + aSetBuffer(cmd++, 0, 0, 0, nSamples); aMix(cmd++, 0, /*gain*/ 0x8000, /*in*/ DMEM_ADDR_STEREO_STRONG_TEMP_DRY, /*out*/ DMEM_ADDR_RIGHT_CH); aMix(cmd++, 0, /*gain*/ 0x8000, /*in*/ DMEM_ADDR_STEREO_STRONG_TEMP_WET, /*out*/ DMEM_ADDR_WET_RIGHT_CH); } } else { -#ifdef VERSION_EU - aEnvMixer(cmd++, mixerFlags, VIRTUAL_TO_PHYSICAL2(synthesisState->synthesisBuffers->mixEnvelopeState)); -#else aEnvMixer(cmd++, mixerFlags, VIRTUAL_TO_PHYSICAL2(note->synthesisBuffers->mixEnvelopeState)); -#endif if (note->stereoStrongRight) { - aSetBuffer(cmd++, 0, 0, 0, nSamples * 2); + aSetBuffer(cmd++, 0, 0, 0, nSamples); aMix(cmd++, 0, /*gain*/ 0x8000, /*in*/ DMEM_ADDR_STEREO_STRONG_TEMP_DRY, /*out*/ DMEM_ADDR_LEFT_CH); } else if (note->stereoStrongLeft) { - aSetBuffer(cmd++, 0, 0, 0, nSamples * 2); + aSetBuffer(cmd++, 0, 0, 0, nSamples); aMix(cmd++, 0, /*gain*/ 0x8000, /*in*/ DMEM_ADDR_STEREO_STRONG_TEMP_DRY, /*out*/ DMEM_ADDR_RIGHT_CH); } @@ -1561,41 +946,23 @@ u64 *process_envelope(u64 *cmd, struct NoteSubEu *note, struct NoteSynthesisStat } #ifdef ENABLE_STEREO_HEADSET_EFFECTS -#ifdef VERSION_EU -u64 *note_apply_headset_pan_effects(u64 *cmd, struct NoteSubEu *noteSubEu, struct NoteSynthesisState *note, s32 bufLen, s32 flags, s32 leftRight) { -#else u64 *note_apply_headset_pan_effects(u64 *cmd, struct Note *note, s32 bufLen, s32 flags, s32 leftRight) { -#endif u16 dest; u16 pitch; -#ifdef VERSION_EU - u8 prevPanShift; - u8 panShift; - UNUSED u8 unkDebug; -#else u16 prevPanShift; u16 panShift; -#endif switch (leftRight) { case 1: dest = DMEM_ADDR_LEFT_CH; -#ifdef VERSION_EU - panShift = noteSubEu->headsetPanRight; -#else panShift = note->headsetPanRight; -#endif note->prevHeadsetPanLeft = 0; prevPanShift = note->prevHeadsetPanRight; note->prevHeadsetPanRight = panShift; break; case 2: dest = DMEM_ADDR_RIGHT_CH; -#ifdef VERSION_EU - panShift = noteSubEu->headsetPanLeft; -#else panShift = note->headsetPanLeft; -#endif note->prevHeadsetPanRight = 0; prevPanShift = note->prevHeadsetPanLeft; @@ -1611,8 +978,8 @@ u64 *note_apply_headset_pan_effects(u64 *cmd, struct Note *note, s32 bufLen, s32 // Kind of a hack that moves the first samples into the resample state aDMEMMove(cmd++, DMEM_ADDR_NOTE_PAN_TEMP, DMEM_ADDR_TEMP, 8); aClearBuffer(cmd++, 8, 8); // Set pitch accumulator to 0 in the resample state - aDMEMMove(cmd++, DMEM_ADDR_NOTE_PAN_TEMP, DMEM_ADDR_TEMP + 0x10, - 0x10); // No idea, result seems to be overwritten later + aDMEMMove(cmd++, DMEM_ADDR_NOTE_PAN_TEMP, DMEM_ADDR_TEMP + 16, + 16); // No idea, result seems to be overwritten later aSetBuffer(cmd++, 0, 0, DMEM_ADDR_TEMP, 32); aSaveBuffer(cmd++, VIRTUAL_TO_PHYSICAL2(note->synthesisBuffers->panResampleState)); @@ -1658,14 +1025,10 @@ u64 *note_apply_headset_pan_effects(u64 *cmd, struct Note *note, s32 bufLen, s32 } #endif -#ifndef VERSION_EU -// Moved to playback.c in EU - void note_init_volume(struct Note *note) { note->targetVolLeft = 0; note->targetVolRight = 0; note->reverbVol = 0; - note->reverbVolShifted = 0; note->curVolLeft = 1; note->curVolRight = 1; note->frequency = 0.0f; @@ -1728,7 +1091,6 @@ void note_set_vel_pan_reverb(struct Note *note, f32 velocity, f32 pan, u8 reverb } if (note->reverbVol != reverbVol) { note->reverbVol = reverbVol; - note->reverbVolShifted = reverbVol << 8; note->envMixerNeedsInit = TRUE; return; } @@ -1770,4 +1132,3 @@ void note_disable(struct Note *note) { note->prevParentLayer = NO_LAYER; } #endif -#endif