diff --git a/README.md b/README.md index 89667e4c..3c835b5c 100644 --- a/README.md +++ b/README.md @@ -75,6 +75,7 @@ This is a fork of the ultrasm64 repo by CrashOveride which includes the followin - ia8 coins (64x64), the vanilla coin texture is upgraded to accomodate. * - Skybox size modifier. You can have 2x, 3x and 4x size skyboxes (you can select the skybox size in `config.h`.) Please note that this might affect console performance, especially 4x mode. 2x or 3x mode is recommended if aiming for console. By CowQuack * - You can set the black border size to different values for console and emulator. It's set to 0 by default for both. * +- This repo supports much better implementation of reverb over vanilla's fake echo reverb. Great for caves or eerie levels, as well as just a better audio experience in general. See `audio/synthesis.c` for more configuration info. (By ArcticJaguar725) * # UltraSM64 diff --git a/include/config.h b/include/config.h index d5a142f0..c9002a94 100644 --- a/include/config.h +++ b/include/config.h @@ -153,6 +153,9 @@ #define DISABLE_AA // Makes the coins ia8 64x64 instead of ia16 32x32. Uses new ia8 textures so that vanilla coins look better. #define IA8_COINS +// Use a much better implementation of reverb over vanilla's fake echo reverb. Great for caves or eerie levels, as well as just a better audio experience in general. +// Reverb parameters can be configured in audio/synthesis.c to meet desired aesthetic/performance needs. +//#define BETTER_REVERB // If you want to change the extended boundaries mode, go to engine/extended_bounds.h and change EXTENDED_BOUNDS_MODE diff --git a/src/audio/data.h b/src/audio/data.h index cf19472d..a8bc7f78 100644 --- a/src/audio/data.h +++ b/src/audio/data.h @@ -5,6 +5,7 @@ #include "internal.h" #include "types.h" +#include "synthesis.h" #define AUDIO_LOCK_UNINITIALIZED 0 #define AUDIO_LOCK_NOT_LOADING 0x76557364 @@ -150,11 +151,11 @@ extern OSMesgQueue *D_SH_80350FA8; #if defined(VERSION_EU) || defined(VERSION_SH) #define UNUSED_COUNT_80333EE8 24 -#define AUDIO_HEAP_SIZE (0x2c500 + EXT_AUDIO_HEAP_SIZE + EXT_AUDIO_INIT_POOL_SIZE) +#define AUDIO_HEAP_SIZE (0x2c500 + EXT_AUDIO_HEAP_SIZE + EXT_AUDIO_INIT_POOL_SIZE + BETTER_REVERB_SIZE) #define AUDIO_INIT_POOL_SIZE (0x2c00 + EXT_AUDIO_INIT_POOL_SIZE) #else #define UNUSED_COUNT_80333EE8 16 -#define AUDIO_HEAP_SIZE (0x31150 + EXT_AUDIO_HEAP_SIZE + EXT_AUDIO_INIT_POOL_SIZE) +#define AUDIO_HEAP_SIZE (0x31150 + EXT_AUDIO_HEAP_SIZE + EXT_AUDIO_INIT_POOL_SIZE + BETTER_REVERB_SIZE) #define AUDIO_INIT_POOL_SIZE (0x2500 + EXT_AUDIO_INIT_POOL_SIZE) #endif diff --git a/src/audio/heap.c b/src/audio/heap.c index 71d7584a..27423a10 100644 --- a/src/audio/heap.c +++ b/src/audio/heap.c @@ -6,6 +6,7 @@ #include "synthesis.h" #include "seqplayer.h" #include "effects.h" +#include "game/game_init.h" #define ALIGN16(val) (((val) + 0xF) & ~0xF) @@ -1122,6 +1123,9 @@ void audio_reset_session(void) { #if defined(VERSION_JP) || defined(VERSION_US) s32 frames; s32 remainingDmas; +#ifdef BETTER_REVERB + s8 reverbConsole; +#endif #else struct SynthesisReverb *reverb; #endif @@ -1234,6 +1238,29 @@ void audio_reset_session(void) { gMaxSimultaneousNotes = preset->maxSimultaneousNotes; gSamplesPerFrameTarget = ALIGN16(gAiFrequency / 60); gReverbDownsampleRate = preset->reverbDownsampleRate; +#ifdef BETTER_REVERB + if (gIsConsole) + reverbConsole = betterReverbConsoleDownsample; // Console! + else + reverbConsole = betterReverbEmulatorDownsample; // Setting this to 1 is REALLY slow, please use sparingly! + + if (reverbConsole <= 0) { + reverbConsole = 1; + toggleBetterReverb = FALSE; + } + else { + toggleBetterReverb = TRUE; + } + + if (toggleBetterReverb && betterReverbWindowsSize >= 0) + reverbWindowSize = betterReverbWindowsSize; + + if (gReverbDownsampleRate < (1 << (reverbConsole - 1))) + gReverbDownsampleRate = (1 << (reverbConsole - 1)); + reverbWindowSize /= gReverbDownsampleRate; + if (reverbWindowSize < DEFAULT_LEN_2CH) // Minimum window size to not overflow + reverbWindowSize = DEFAULT_LEN_2CH; +#endif switch (gReverbDownsampleRate) { case 1: @@ -1255,7 +1282,6 @@ void audio_reset_session(void) { sReverbDownsampleRateLog = 0; } - gReverbDownsampleRate = preset->reverbDownsampleRate; gVolume = preset->volume; gMinAiBufferLength = gSamplesPerFrameTarget - 0x10; updatesPerFrame = gSamplesPerFrameTarget / 160 + 1; @@ -1283,7 +1309,7 @@ void audio_reset_session(void) { temporaryMem = DOUBLE_SIZE_ON_64_BIT(preset->temporaryBankMem + preset->temporarySeqMem); #endif totalMem = persistentMem + temporaryMem; - wantMisc = gAudioSessionPool.size - totalMem - 0x100; + wantMisc = gAudioSessionPool.size - totalMem - 0x100 - BETTER_REVERB_SIZE; sSessionPoolSplit.wantSeq = wantMisc; sSessionPoolSplit.wantCustom = totalMem; session_pools_init(&sSessionPoolSplit); @@ -1426,6 +1452,23 @@ void audio_reset_session(void) { gSynthesisReverb.items[1][i].toDownsampleRight = mem + DEFAULT_LEN_1CH / sizeof(s16); } } + + // This does not have to be reset after being initialized for the first time, which would speed up load times dramatically. + // However, reseting this allows for proper clearing of the reverb buffers, as well as dynamic customization of the delays array. +#ifdef BETTER_REVERB + if (toggleBetterReverb) { + for (i = 0; i < NUM_ALLPASS; ++i) + delays[i] = delaysBaseline[i] / gReverbDownsampleRate; + + delayBufs = (s32***) soundAlloc(&gAudioSessionPool, 2 * sizeof(s32**)); + delayBufs[0] = (s32**) soundAlloc(&gAudioSessionPool, NUM_ALLPASS * sizeof(s32*)); + delayBufs[1] = (s32**) soundAlloc(&gAudioSessionPool, NUM_ALLPASS * sizeof(s32*)); + for (i = 0; i < NUM_ALLPASS; ++i) { + delayBufs[0][i] = (s32*) soundAlloc(&gAudioSessionPool, delays[i] * sizeof(s32)); + delayBufs[1][i] = (s32*) soundAlloc(&gAudioSessionPool, delays[i] * sizeof(s32)); + } + } +#endif } #endif diff --git a/src/audio/synthesis.c b/src/audio/synthesis.c index f35e491d..96ddd0a7 100644 --- a/src/audio/synthesis.c +++ b/src/audio/synthesis.c @@ -37,6 +37,83 @@ #define AUDIO_ALIGN(val, amnt) (((val) + (1 << amnt) - 1) & ~((1 << amnt) - 1)) +/* -------------------------------------------------------BEGIN REVERB PARAMETERS-------------------------------------------------------------- */ + +/** + * This reverb is a much more natural, ambient implementation over vanilla's, though at the cost of some memory and performance. + * These parameters are here to provide maximum control over the usage of the reverb effect, as well as with game performance. + * + * To take advantage of the reverb effect, you can change the echo parameters set in levels/level_defines.h to tailor the reverb to each specific level area. + * To adjust reverb presence with individual sound effects, apply the .set_reverb command within sound/sequences/00_sound_player.s (see examples of other sounds that use it). + * To use with M64 sequences, set the Effect parameter for each channel accordingly (CC 91 for MIDI files). + */ + +s32 gReverbRevIndex = 0x7F; // Affects decay time mostly; can be messed with at any time (and also probably the most useful parameter here) +s32 gReverbGainIndex = 0xA3; // Affects signal immediately retransmitted back into buffers; can be messed with at any time +s32 gReverbWetSignal = 0xEF; // Amount of reverb specific output in final signal; can be messed with at any time +s32 gReverbDrySignal = 0x00; // Amount of original input in final signal (large values can cause terrible feedback!); can be messed with at any time + +// This value controls the size of the reverb buffer. It affects the global reverb delay time. This is probably the easiest parameter to control usefully. +// It is not recommended setting this to values greater than 0x1000 * 2^(downsample factor - 1), as you run the risk of running into a memory issue (though this is far from a guarantee). +// Setting the value lower than the downsample buffer size will destroy the game audio, so this is taken into account automatically but may limit the lower possibilities. +// If this value is changed, it will go into effect the next time audio_reset_session is called. +// Set to -1 to use a default preset instead. Higher values represent more audio delay (usually better for echoey spaces). +s32 betterReverbWindowsSize = -1; + +// These values affect filter delays. Bigger values will result in fatter echo (and more memory); must be cumulatively smaller than BETTER_REVERB_SIZE/4. +// If setting a reverb downsample value to 1, this must be smaller than BETTER_REVERB_SIZE/8. +// These values should never be changed unless in this declaration or during a call to audio_reset_session, as it could otherwise lead to a major memory leak or garbage audio. +// None of the delay values should ever be smaller than 1 either; these are s32s purely to avoid typecasts. +// These values are currently set by using delaysBaseline in the audio_reset_session function, so its behavior must be overridden to use dynamically (or at all). +s32 delays[NUM_ALLPASS] = { + 1080, 1352, 1200, + 1384, 1048, 1352, + 1200, 1232, 1432, + 928, 1504, 1512 +}; + +// Like the delays array, but represents default max values that don't change (also probably somewhat redundant) +// Change this array rather than the delays array to customize reverb delay times globally. +// Similarly to delays, these should be kept within the memory constraints defined by BETTER_REVERB_SIZE. +const s32 delaysBaseline[NUM_ALLPASS] = { + 1080, 1352, 1200, + 1384, 1048, 1352, + 1200, 1232, 1432, + 928, 1504, 1512 +}; + +// These values affect reverb decay depending on the filter index; can be messed with at any time +const s32 reverbMults[2][NUM_ALLPASS / 3] = { + {0xD2, 0x6E, 0x36, 0x1F}, // Left Channel + {0x38, 0x26, 0xCF, 0x71} // Right Channel +}; + +// Setting this to 4 corrupts the game, so set this value to -1 to use vanilla reverb if this is too slow, or if it just doesn't fit the desired aesthetic of a level. +// You can change this value before audio_reset_session gets called if different levels can tolerate the demand better than others or just have different reverb goals. +// A higher downsample value hits the game's frequency limit sooner, which can cause the reverb sometimes to be off pitch. This is a vanilla level issue (and also counter intuitive). +// Higher downsample values also result in slightly shorter reverb decay times. +s8 betterReverbConsoleDownsample = 3; + +// Most emulators can handle a default value of 2, but 3 may be advisable in some cases if targeting older emulators (e.g. PJ64 1.6). Setting this to -1 also uses vanilla reverb. +// Using a value of 1 is not recommended except in very specific situations. If you do decide to use 1 here, you must adjust BETTER_REVERB_SIZE appropriately. +// You can change this value before audio_reset_session gets called if different levels can tolerate the demand better than others or just have different reverb goals. +// A higher downsample value hits the game's frequency limit sooner, which can cause the reverb sometimes to be off pitch. This is a vanilla level issue (and also counter intuitive). +// Higher downsample values also result in slightly shorter reverb decay times. +s8 betterReverbEmulatorDownsample = 2; + +/* --------------------------------------------------------END REVERB PARAMETERS--------------------------------------------------------------- */ + +// Do not touch these values. +u8 toggleBetterReverb = TRUE; +s32 allpassIdx[2][NUM_ALLPASS] = { + {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} +}; +s32 tmpBufL[NUM_ALLPASS] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; +s32 tmpBufR[NUM_ALLPASS] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; +s32 ***delayBufs; + + struct VolumeChange { u16 sourceLeft; u16 sourceRight; @@ -70,6 +147,123 @@ struct SynthesisReverb gSynthesisReverb; u8 sAudioSynthesisPad[0x20]; #endif +inline s16 clamp16(s32 x) { + if (x >= 32767) + return 32767; + if (x <= -32768) + return -32768; + + return (s16) x; +} + +inline void reverb_samples(s16 *outSampleL, s16 *outSampleR, s32 inSampleL, s32 inSampleR) { + u32 i = 0; + s32 j = 0; + u8 k = 0; + s32 outTmpL = 0; + s32 outTmpR = 0; + s32 tmpCarryoverL = ((tmpBufL[NUM_ALLPASS-1] * gReverbRevIndex) / 256) + inSampleL; // Unique to left channel + s32 tmpCarryoverR = ((tmpBufR[NUM_ALLPASS-1] * gReverbRevIndex) / 256); + + for (; i < NUM_ALLPASS; ++i, ++j) { + tmpBufL[i] = delayBufs[0][i][allpassIdx[0][i]]; + tmpBufR[i] = delayBufs[1][i][allpassIdx[1][i]]; + + if (j == 2) { + j = -1; + outTmpL += (tmpBufL[i] * reverbMults[0][k]) / 256; + outTmpR += (tmpBufR[i] * reverbMults[1][k++]) / 256; + delayBufs[0][i][allpassIdx[0][i]] = tmpCarryoverL; + delayBufs[1][i][allpassIdx[1][i]] = tmpCarryoverR; + if (i != NUM_ALLPASS - 1) { + tmpCarryoverL = (tmpBufL[i] * gReverbRevIndex) / 256; + tmpCarryoverR = (tmpBufR[i] * gReverbRevIndex) / 256; + } + } + else { + delayBufs[0][i][allpassIdx[0][i]] = (tmpBufL[i] * (-gReverbGainIndex)) / 256 + tmpCarryoverL; + delayBufs[1][i][allpassIdx[1][i]] = (tmpBufR[i] * (-gReverbGainIndex)) / 256 + tmpCarryoverR; + + if (i == 6) + delayBufs[1][i][allpassIdx[1][i]] += inSampleR; // Unique to right channel + + tmpCarryoverL = (delayBufs[0][i][allpassIdx[0][i]] * gReverbGainIndex) / 256 + tmpBufL[i]; + tmpCarryoverR = (delayBufs[1][i][allpassIdx[1][i]] * gReverbGainIndex) / 256 + tmpBufR[i]; + } + + if (++allpassIdx[0][i] == delays[i]) { + allpassIdx[0][i] = 0; + allpassIdx[1][i] = -1; // To avoid an else branch + } + ++allpassIdx[1][i]; + } + + *outSampleL = clamp16((outTmpL * gReverbWetSignal + inSampleL * gReverbDrySignal) / 256); + *outSampleR = clamp16((outTmpR * gReverbWetSignal + inSampleR * gReverbDrySignal) / 256); +} + +inline s16 reverb_sample_left(s32 inSample) { + u32 i = 0; + s32 j = 0; + u8 k = 0; + s32 outTmp = 0; + s32 tmpCarryover = ((tmpBufL[NUM_ALLPASS-1] * gReverbRevIndex) / 256) + inSample; + + for (; i < NUM_ALLPASS; ++i, ++j) { + tmpBufL[i] = delayBufs[0][i][allpassIdx[0][i]]; + + if (j == 2) { + j = -1; + outTmp += (tmpBufL[i] * reverbMults[0][k++]) / 256; + delayBufs[0][i][allpassIdx[0][i]] = tmpCarryover; + if (i != NUM_ALLPASS - 1) + tmpCarryover = (tmpBufL[i] * gReverbRevIndex) / 256; + } + else { + delayBufs[0][i][allpassIdx[0][i]] = (tmpBufL[i] * (-gReverbGainIndex)) / 256 + tmpCarryover; + tmpCarryover = (delayBufs[0][i][allpassIdx[0][i]] * gReverbGainIndex) / 256 + tmpBufL[i]; + } + + if (++allpassIdx[0][i] == delays[i]) + allpassIdx[0][i] = 0; + } + + return clamp16((outTmp * gReverbWetSignal + inSample * gReverbDrySignal) / 256); +} + +inline s16 reverb_sample_right(s32 inSample) { + u32 i = 0; + s32 j = 0; + u8 k = 0; + s32 outTmp = 0; + s32 tmpCarryover = ((tmpBufR[NUM_ALLPASS-1] * gReverbRevIndex) / 256); + + for (; i < NUM_ALLPASS; ++i, ++j) { + tmpBufR[i] = delayBufs[1][i][allpassIdx[1][i]]; + + if (j == 2) { + j = -1; + outTmp += (tmpBufR[i] * reverbMults[1][k++]) / 256; + delayBufs[1][i][allpassIdx[1][i]] = tmpCarryover; + if (i != NUM_ALLPASS - 1) + tmpCarryover = (tmpBufR[i] * gReverbRevIndex) / 256; + } + else { + delayBufs[1][i][allpassIdx[1][i]] = (tmpBufR[i] * (-gReverbGainIndex)) / 256 + tmpCarryover; + + if (i == 6) + delayBufs[1][i][allpassIdx[1][i]] += inSample; + + tmpCarryover = (delayBufs[1][i][allpassIdx[1][i]] * gReverbGainIndex) / 256 + tmpBufR[i]; + } + + if (++allpassIdx[1][i] == delays[i]) + allpassIdx[1][i] = 0; + } + + return clamp16((outTmp * gReverbWetSignal + inSample * gReverbDrySignal) / 256); +} + #ifdef VERSION_EU s16 gVolume; s8 gUseReverb; @@ -149,7 +343,12 @@ void prepare_reverb_ring_buffer(s32 chunkLen, u32 updateIndex) { s32 nSamples; s32 numSamplesAfterDownsampling; s32 excessiveSamples; + +#ifdef BETTER_REVERB + if (!toggleBetterReverb && gReverbDownsampleRate != 1) { +#else if (gReverbDownsampleRate != 1) { +#endif if (gSynthesisReverb.framesLeftToIgnore == 0) { // Now that the RSP has finished, downsample the samples produced two frames ago by skipping // samples. @@ -171,6 +370,68 @@ void prepare_reverb_ring_buffer(s32 chunkLen, u32 updateIndex) { } } } +#ifdef BETTER_REVERB + else if (toggleBetterReverb) { + item = &gSynthesisReverb.items[gSynthesisReverb.curFrame][updateIndex]; + if (gSoundMode == SOUND_MODE_MONO) { + if (gReverbDownsampleRate != 1) { + osInvalDCache(item->toDownsampleLeft, DEFAULT_LEN_2CH); + for (srcPos = 0, dstPos = item->startPos; dstPos < item->lengthA / 2 + item->startPos; srcPos += gReverbDownsampleRate, dstPos++) { + gSynthesisReverb.ringBuffer.left[dstPos] = reverb_sample_left(((s32) item->toDownsampleLeft[srcPos] + (s32) item->toDownsampleRight[srcPos]) / 2); + gSynthesisReverb.ringBuffer.right[dstPos] = gSynthesisReverb.ringBuffer.left[dstPos]; + } + for (dstPos = 0; dstPos < item->lengthB / 2; srcPos += gReverbDownsampleRate, dstPos++) { + gSynthesisReverb.ringBuffer.left[dstPos] = reverb_sample_left(((s32) item->toDownsampleLeft[srcPos] + (s32) item->toDownsampleRight[srcPos]) / 2); + gSynthesisReverb.ringBuffer.right[dstPos] = gSynthesisReverb.ringBuffer.left[dstPos]; + } + } + else { // Too slow for practical use, not recommended most of the time. + for (dstPos = item->startPos; dstPos < item->lengthA / 2 + item->startPos; dstPos++) { + gSynthesisReverb.ringBuffer.left[dstPos] = reverb_sample_left(((s32) gSynthesisReverb.ringBuffer.left[dstPos] + (s32) gSynthesisReverb.ringBuffer.right[dstPos]) / 2); + gSynthesisReverb.ringBuffer.right[dstPos] = gSynthesisReverb.ringBuffer.left[dstPos]; + } + for (dstPos = 0; dstPos < item->lengthB / 2; dstPos++) { + gSynthesisReverb.ringBuffer.left[dstPos] = reverb_sample_left(((s32) gSynthesisReverb.ringBuffer.left[dstPos] + (s32) gSynthesisReverb.ringBuffer.right[dstPos]) / 2); + gSynthesisReverb.ringBuffer.right[dstPos] = gSynthesisReverb.ringBuffer.left[dstPos]; + } + } + } + else { + if (gReverbDownsampleRate != 1) { + osInvalDCache(item->toDownsampleLeft, DEFAULT_LEN_2CH); + for (srcPos = 0, dstPos = item->startPos; dstPos < item->lengthA / 2 + item->startPos; srcPos += gReverbDownsampleRate, dstPos++) + reverb_samples(&gSynthesisReverb.ringBuffer.left[dstPos], &gSynthesisReverb.ringBuffer.right[dstPos], item->toDownsampleLeft[srcPos], item->toDownsampleRight[srcPos]); + for (dstPos = 0; dstPos < item->lengthB / 2; srcPos += gReverbDownsampleRate, dstPos++) + reverb_samples(&gSynthesisReverb.ringBuffer.left[dstPos], &gSynthesisReverb.ringBuffer.right[dstPos], item->toDownsampleLeft[srcPos], item->toDownsampleRight[srcPos]); + + // for (srcPos = 0, dstPos = item->startPos; dstPos < item->lengthA / 2 + item->startPos; + // srcPos += gReverbDownsampleRate, dstPos++) { + // gSynthesisReverb.ringBuffer.left[dstPos] = reverb_sample_left(item->toDownsampleLeft[srcPos]); + // gSynthesisReverb.ringBuffer.right[dstPos] = reverb_sample_right(item->toDownsampleRight[srcPos]); + // } + // for (dstPos = 0; dstPos < item->lengthB / 2; srcPos += gReverbDownsampleRate, dstPos++) { + // gSynthesisReverb.ringBuffer.left[dstPos] = reverb_sample_left(item->toDownsampleLeft[srcPos]); + // gSynthesisReverb.ringBuffer.right[dstPos] = reverb_sample_right(item->toDownsampleRight[srcPos]); + // } + } + else { // Too slow for practical use, not recommended most of the time. + for (dstPos = item->startPos; dstPos < item->lengthA / 2 + item->startPos; dstPos++) + reverb_samples(&gSynthesisReverb.ringBuffer.left[dstPos], &gSynthesisReverb.ringBuffer.right[dstPos], gSynthesisReverb.ringBuffer.left[dstPos], gSynthesisReverb.ringBuffer.right[dstPos]); + for (dstPos = 0; dstPos < item->lengthB / 2; dstPos++) + reverb_samples(&gSynthesisReverb.ringBuffer.left[dstPos], &gSynthesisReverb.ringBuffer.right[dstPos], gSynthesisReverb.ringBuffer.left[dstPos], gSynthesisReverb.ringBuffer.right[dstPos]); + + // for (dstPos = item->startPos; dstPos < item->lengthA / 2 + item->startPos; dstPos++) { + // gSynthesisReverb.ringBuffer.left[dstPos] = reverb_sample_left(gSynthesisReverb.ringBuffer.left[dstPos]); + // gSynthesisReverb.ringBuffer.right[dstPos] = reverb_sample_right(gSynthesisReverb.ringBuffer.right[dstPos]); + // } + // for (dstPos = 0; dstPos < item->lengthB / 2; srcPos += gReverbDownsampleRate, dstPos++) { + // gSynthesisReverb.ringBuffer.left[dstPos] = reverb_sample_left(gSynthesisReverb.ringBuffer.left[dstPos]); + // gSynthesisReverb.ringBuffer.right[dstPos] = reverb_sample_right(gSynthesisReverb.ringBuffer.right[dstPos]); + // } + } + } + } +#endif item = &gSynthesisReverb.items[gSynthesisReverb.curFrame][updateIndex]; numSamplesAfterDownsampling = chunkLen / gReverbDownsampleRate; diff --git a/src/audio/synthesis.h b/src/audio/synthesis.h index 9ca86439..19f341ab 100644 --- a/src/audio/synthesis.h +++ b/src/audio/synthesis.h @@ -17,6 +17,24 @@ #define MAX_UPDATES_PER_FRAME 4 #endif +#ifdef BETTER_REVERB +#define BETTER_REVERB_SIZE 0xF200 // Size determined by ((all delaysBaseline values * 16) / (2 ^ Minimum Downsample Factor)) + array pointers; can be increased if needed +// #define BETTER_REVERB_SIZE 0x1E200 // For use with a downsampling value of 1 (i.e. no downsampling at all) +#else +#define BETTER_REVERB_SIZE 0 +#endif + +#define NUM_ALLPASS 12 // Number of delay filters to use with better reverb; do not change this value if you don't know what you're doing. + +extern s32 betterReverbWindowsSize; +extern const s32 delaysBaseline[NUM_ALLPASS]; +extern s32 delays[NUM_ALLPASS]; +extern s32 ***delayBufs; + +extern u8 toggleBetterReverb; +extern s8 betterReverbConsoleDownsample; +extern s8 betterReverbEmulatorDownsample; + struct ReverbRingBufferItem { s16 numSamplesAfterDownsampling; diff --git a/src/buffers/buffers.c b/src/buffers/buffers.c index 1a2c2bc7..95174530 100644 --- a/src/buffers/buffers.c +++ b/src/buffers/buffers.c @@ -7,6 +7,7 @@ #include #endif #include "config.h" +#include "audio/synthesis.h" ALIGNED8 u8 gDecompressionHeap[0xD000]; #if defined(VERSION_EU) @@ -14,7 +15,7 @@ ALIGNED16 u8 gAudioHeap[DOUBLE_SIZE_ON_64_BIT(0x31200 + EXT_AUDIO_HEAP_SIZE + EX #elif defined(VERSION_SH) ALIGNED16 u8 gAudioHeap[DOUBLE_SIZE_ON_64_BIT(0x31200 + EXT_AUDIO_HEAP_SIZE + EXT_AUDIO_INIT_POOL_SIZE) - 0x4800]; #else -ALIGNED16 u8 gAudioHeap[DOUBLE_SIZE_ON_64_BIT(0x31200 + EXT_AUDIO_HEAP_SIZE + EXT_AUDIO_INIT_POOL_SIZE)]; +ALIGNED16 u8 gAudioHeap[DOUBLE_SIZE_ON_64_BIT(0x31200 + EXT_AUDIO_HEAP_SIZE + EXT_AUDIO_INIT_POOL_SIZE + BETTER_REVERB_SIZE)]; #endif ALIGNED8 u8 gIdleThreadStack[0x800]; diff --git a/src/game/game_init.c b/src/game/game_init.c index e0cac752..83a90626 100644 --- a/src/game/game_init.c +++ b/src/game/game_init.c @@ -44,7 +44,7 @@ struct GfxPool *gGfxPool; OSContStatus gControllerStatuses[4]; OSContPad gControllerPads[4]; u8 gControllerBits; -u8 gIsConsole; +u8 gIsConsole = TRUE; // Needs to be initialized before audio_reset_session is called u8 gBorderHeight; #ifdef EEP s8 gEepromProbe; @@ -76,11 +76,9 @@ UNUSED static s32 sUnusedGameInitValue = 0; // General timer that runs as the game starts u32 gGlobalTimer = 0; -u8 gIsConsole; #ifdef WIDE u8 gWidescreen; #endif -u8 gBorderHeight; // Framebuffer rendering values (max 3) u16 sRenderedFramebuffer = 0;