Merge pull request #338 from Reonu/develop/gheskett/audio-changes

Develop/gheskett/audio changes
This commit is contained in:
Gregory Heskett authored and GitHub committed 2022-03-08 08:21:55 -06:00
commit cc92b33676
17 files changed
+250 -143

No files matched your search

+20 -5
View File
@@ -4,12 +4,27 @@
* AUDIO SETTINGS *
******************/
// Fixes the castle music sometimes triggering after getting a dialog
/**
* Fixes the castle music sometimes triggering after getting a dialog.
*/
#define CASTLE_MUSIC_FIX
// Increase audio heap size to allow for more concurrent notes to be played and for more custom sequences/banks to be imported (not supported for SH)
/**
* Increase audio heap size to allow for larger/more custom sequences/banks/sfx to be imported without causing issues (not supported for SH).
*/
#define EXPAND_AUDIO_HEAP
// 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. Currently US/JP only. Hurts emulator and console performance.
//#define BETTER_REVERB
/**
* The maximum number of notes (sfx inclusive) that can sound at any given time (not supported for SH).
* Lower values may cause notes to get cut more easily but can potentially improve performance slightly.
* Lower values may cause problems with streamed audio if a sequence used for it is missing channel priority data.
* Vanilla by default only generally allocates 16 or 20 notes at once. Memory usage is always determined by the largest of the two values here (~7200 bytes per US/JP note).
*/
#define MAX_SIMULTANEOUS_NOTES_EMULATOR 40
#define MAX_SIMULTANEOUS_NOTES_CONSOLE 24
/**
* 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. Currently US/JP only. Hurts emulator and console performance.
*/
// #define BETTER_REVERB
+40
View File
@@ -10,6 +10,46 @@
*/
/*****************
* config_audio
*/
#ifndef MAX_SIMULTANEOUS_NOTES_EMULATOR
#ifdef EXPAND_AUDIO_HEAP
#define MAX_SIMULTANEOUS_NOTES_EMULATOR 40
#else
#define MAX_SIMULTANEOUS_NOTES_EMULATOR 20
#endif
#endif // MAX_SIMULTANEOUS_NOTES_EMULATOR
#ifndef MAX_SIMULTANEOUS_NOTES_CONSOLE
#ifdef EXPAND_AUDIO_HEAP
#define MAX_SIMULTANEOUS_NOTES_CONSOLE 24
#else
#define MAX_SIMULTANEOUS_NOTES_CONSOLE 16
#endif
#endif // MAX_SIMULTANEOUS_NOTES_CONSOLE
#if (MAX_SIMULTANEOUS_NOTES_EMULATOR >= MAX_SIMULTANEOUS_NOTES_CONSOLE)
#define MAX_SIMULTANEOUS_NOTES MAX_SIMULTANEOUS_NOTES_EMULATOR
#else
#define MAX_SIMULTANEOUS_NOTES MAX_SIMULTANEOUS_NOTES_CONSOLE
#endif
// Anything higher than 64 will most likely crash on boot. Even if it doesn't, it's still dangerous.
#if (MAX_SIMULTANEOUS_NOTES > 64)
#undef MAX_SIMULTANEOUS_NOTES
#define MAX_SIMULTANEOUS_NOTES 64
#elif (MAX_SIMULTANEOUS_NOTES < 0)
#undef MAX_SIMULTANEOUS_NOTES
#define MAX_SIMULTANEOUS_NOTES 0
#endif
#if defined(BETTER_REVERB) && !(defined(VERSION_US) || defined(VERSION_JP))
#undef BETTER_REVERB
#endif
/*****************
* config_graphics
*/
+4 -15
View File
@@ -10,7 +10,7 @@ extern struct OSMesgQueue OSMesgQueue3;
// Since the audio session is just one now, the reverb settings are duplicated to match the original audio setting scenario.
// It's a bit hacky but whatever lol. Index range must be defined, since it's needed by the compiler.
// To increase reverb window sizes beyond 64, please increase the REVERB_WINDOW_SIZE_MAX in heap.c by a factor of 0x40 and update AUDIO_HEAP_SIZE by 4x the same amount.
// To increase reverb window sizes beyond 64, please increase the REVERB_WINDOW_SIZE_MAX in heap.c by a factor of 0x40.
#ifdef VERSION_EU
struct ReverbSettingsEU sReverbSettings[8] = {
{ /*Downsample Rate*/ 1, /*Window Size*/ 64, /*Gain*/ 0x2FFF },
@@ -37,11 +37,7 @@ struct ReverbSettingsEU sReverbSettings[8] = {
*/
struct AudioSessionSettingsEU gAudioSessionPresets[] = {
#ifdef EXPAND_AUDIO_HEAP
{ /*1*/ 32000,/*2*/ 1,/*3*/ 40,/*4*/ 1,/*5*/ 0, &sReverbSettings[0],/*6*/ 0x7FFF,/*7*/ 0,/*8*/ 0x8200,/*9*/ 0xDC00,/*10*/ 0xE800,/*11*/ 0x5500 },
#else
{ /*1*/ 32000,/*2*/ 1,/*3*/ 20,/*4*/ 1,/*5*/ 0, &sReverbSettings[0],/*6*/ 0x7FFF,/*7*/ 0,/*8*/ 0x4100,/*9*/ 0x6E00,/*10*/ 0x7400,/*11*/ 0x2A80 },
#endif
{ /*1*/ 32000,/*2*/ 1,/*3*/ MAX_SIMULTANEOUS_NOTES,/*4*/ 1,/*5*/ 0, &sReverbSettings[0],/*6*/ 0x7FFF,/*7*/ 0,/*8*/ PERSISTENT_SEQ_MEM,/*9*/ PERSISTENT_BANK_MEM,/*10*/ TEMPORARY_SEQ_MEM,/*11*/ TEMPORARY_BANK_MEM },
};
#endif
@@ -57,7 +53,7 @@ struct AudioSessionSettingsEU gAudioSessionPresets[] = {
// - memory used for temporary sequences
// - memory used for temporary banks
// To increase reverb window sizes beyond 0x1000, please increase the REVERB_WINDOW_SIZE_MAX in heap.c and update AUDIO_HEAP_SIZE by the same amount.
// To increase reverb window sizes beyond 0x1000, please increase the REVERB_WINDOW_SIZE_MAX in heap.c.
#if defined(VERSION_JP) || defined(VERSION_US)
struct ReverbSettingsUS gReverbSettings[18] = {
{ 1, 0x0C00, 0x2FFF },
@@ -80,16 +76,9 @@ struct ReverbSettingsUS gReverbSettings[18] = {
{ 1, 0x0800, 0x2FFF },
};
// TODO: Does using 40/20 instead of 32/16 for gMaxSimultaneousNotes cause memory problems at high capacities or is it good as is?
#ifdef EXPAND_AUDIO_HEAP
struct AudioSessionSettings gAudioSessionPresets[1] = {
{ 32000, 40, 1, 0x1000, 0x2FFF, 0x7FFF, 0x8200, 0xDC00, 0xE800, 0x5500 },
{ 32000, MAX_SIMULTANEOUS_NOTES, 1, 0x1000, 0x2FFF, 0x7FFF, PERSISTENT_SEQ_MEM, PERSISTENT_BANK_MEM, TEMPORARY_SEQ_MEM, TEMPORARY_BANK_MEM },
};
#else
struct AudioSessionSettings gAudioSessionPresets[1] = {
{ 32000, 20, 1, 0x1000, 0x2FFF, 0x7FFF, 0x4100, 0x6E00, 0x7400, 0x2A80 },
};
#endif
#endif
// gAudioCosineTable[k] = round((2**15 - 1) * cos(pi/2 * k / 127)). Unused.
#if defined(VERSION_JP) || defined(VERSION_US)
+51 -17
View File
@@ -13,6 +13,32 @@
#define NUMAIBUFFERS 3
#if defined(VERSION_EU)
#define DMA_BUF_SIZE_0 0x400
#define DMA_BUF_SIZE_1 0x200
#else
#define DMA_BUF_SIZE_0 (144 * 9)
#define DMA_BUF_SIZE_1 (160 * 9)
#endif
#ifdef EXPAND_AUDIO_HEAP
#define PERSISTENT_SEQ_MEM 0x8200
#define PERSISTENT_BANK_MEM 0xDC00
#define TEMPORARY_SEQ_MEM 0xE800
#define TEMPORARY_BANK_MEM 0x5500
#define BANK_SETS_ALLOC 0x400
#define EXT_AUDIO_INIT_POOL_SIZE 0x2000
#else
#define PERSISTENT_SEQ_MEM 0x4100
#define PERSISTENT_BANK_MEM 0x6E00
#define TEMPORARY_SEQ_MEM 0x7400
#define TEMPORARY_BANK_MEM 0x2A80
#define BANK_SETS_ALLOC 0x100
#define EXT_AUDIO_INIT_POOL_SIZE 0x0
#endif
#define SEQ_BANK_MEM (PERSISTENT_SEQ_MEM + PERSISTENT_BANK_MEM + TEMPORARY_SEQ_MEM + TEMPORARY_BANK_MEM)
// constant .data
#if defined(VERSION_EU) || defined(VERSION_SH)
extern struct AudioSessionSettingsEU gAudioSessionPresets[];
@@ -108,18 +134,27 @@ extern s16 gAiBufferLengths[NUMAIBUFFERS];
extern u32 gAudioRandom;
#ifdef EXPAND_AUDIO_HEAP
#if defined(VERSION_US) || defined(VERSION_JP) || defined(VERSION_EU)
#define EXT_AUDIO_HEAP_SIZE 0x27400
#define EXT_AUDIO_INIT_POOL_SIZE 0x02000
#else
// SH not yet supported for expanded audio heap
#define EXT_AUDIO_HEAP_SIZE 0x0
#define EXT_AUDIO_INIT_POOL_SIZE 0x0
#endif
#else
#define EXT_AUDIO_HEAP_SIZE 0x0
#define EXT_AUDIO_INIT_POOL_SIZE 0x0
#if defined(VERSION_US) || defined(VERSION_JP)
#define NOTES_BUFFER_SIZE \
( \
MAX_SIMULTANEOUS_NOTES * ((4 /* updatesPerFrame */ * 20 * 2 * sizeof(u64)) \
+ ALIGN16(sizeof(struct Note)) \
+ (DMA_BUF_SIZE_0 * 3) \
+ DMA_BUF_SIZE_1 \
+ ALIGN16(sizeof(struct NoteSynthesisBuffers))) \
+ (320 * 2 * sizeof(u64)) /* gMaxAudioCmds */ \
)
#else // Probably SH incompatible but that's an entirely different headache to save at this point tbh
#define NOTES_BUFFER_SIZE \
( \
MAX_SIMULTANEOUS_NOTES * ((4 /* updatesPerFrame */ * 0x10 * 2 * sizeof(u64)) \
+ ALIGN16(sizeof(struct Note)) \
+ (DMA_BUF_SIZE_0 * 3 * 1 /* presetUnk4 */) \
+ (DMA_BUF_SIZE_1) \
+ ALIGN16(sizeof(struct NoteSynthesisBuffers)) \
+ ALIGN16(4 /* updatesPerFrame */ * sizeof(struct NoteSubEu))) \
+ ((0x300 + (4 /* numReverbs */ * 0x20)) * 2 * sizeof(u64)) /* gMaxAudioCmds */ \
)
#endif
#ifdef VERSION_SH
@@ -148,14 +183,13 @@ extern OSMesgQueue *D_SH_80350FA8;
#endif
#if defined(VERSION_EU) || defined(VERSION_SH)
#define AUDIO_HEAP_BASE 0x36B00
#define AUDIO_INIT_POOL_SIZE (0x2C00 + EXT_AUDIO_INIT_POOL_SIZE)
#define AUDIO_INIT_POOL_SIZE (0x2B00 + BANK_SETS_ALLOC + EXT_AUDIO_INIT_POOL_SIZE)
#else
#define AUDIO_HEAP_BASE 0x30750
#define AUDIO_INIT_POOL_SIZE (0x2500 + EXT_AUDIO_INIT_POOL_SIZE)
#define AUDIO_INIT_POOL_SIZE (0x2400 + BANK_SETS_ALLOC + EXT_AUDIO_INIT_POOL_SIZE)
#endif
#define AUDIO_HEAP_SIZE (AUDIO_HEAP_BASE + EXT_AUDIO_HEAP_SIZE + EXT_AUDIO_INIT_POOL_SIZE + BETTER_REVERB_SIZE + REVERB_WINDOW_HEAP_SIZE)
// TODO: needs validation once EU can compile. EU is very likely incorrect!
#define AUDIO_HEAP_SIZE (SEQ_BANK_MEM + AUDIO_INIT_POOL_SIZE + NOTES_BUFFER_SIZE + BETTER_REVERB_SIZE + REVERB_WINDOW_HEAP_SIZE)
#ifdef VERSION_SH
extern u32 D_SH_80315EF0;
+10 -4
View File
@@ -259,7 +259,12 @@ u16 sLevelAcousticReaches[LEVEL_COUNT] = {
#define VOLUME_RANGE_UNK2 0.8f
#endif
// Default volume for background music sequences (playing on player 0).
// sBackgroundMusicDefaultVolume represents the default volume for background music sequences using the level player (deprecated).
// This code block is simply commented out for now as to not destroy compatibility with any streamed audio tools.
// TODO: Delete this entirely once the unsupporting streamed tools or their builds are outdated.
/*
u8 sBackgroundMusicDefaultVolume[] = {
127, // SEQ_SOUND_PLAYER
80, // SEQ_EVENT_CUTSCENE_COLLECT_STAR
@@ -301,6 +306,8 @@ u8 sBackgroundMusicDefaultVolume[] = {
STATIC_ASSERT(ARRAY_COUNT(sBackgroundMusicDefaultVolume) == SEQ_COUNT,
"change this array if you are adding sequences");
*/
u8 sCurrentBackgroundMusicSeqId = SEQUENCE_NONE;
u8 sMusicDynamicDelay = 0;
u8 sSoundBankUsedListBack[SOUND_BANK_COUNT] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
@@ -1885,7 +1892,7 @@ static u8 begin_background_music_fade(u16 fadeDuration) {
targetVolume = 40;
}
if (sSoundBanksThatLowerBackgroundMusic != 0 && targetVolume > 20) {
if (sSoundBanksThatLowerBackgroundMusic && targetVolume > 20) {
targetVolume = 20;
}
@@ -1894,8 +1901,7 @@ static u8 begin_background_music_fade(u16 fadeDuration) {
seq_player_fade_to_target_volume(SEQ_PLAYER_LEVEL, fadeDuration, targetVolume);
} else {
#if defined(VERSION_JP) || defined(VERSION_US)
gSequencePlayers[SEQ_PLAYER_LEVEL].volume =
sBackgroundMusicDefaultVolume[sCurrentBackgroundMusicSeqId] / 127.0f;
gSequencePlayers[SEQ_PLAYER_LEVEL].volume = gSequencePlayers[SEQ_PLAYER_LEVEL].volumeDefault;
#endif
seq_player_fade_to_normal_volume(SEQ_PLAYER_LEVEL, fadeDuration);
}
+41 -22
View File
@@ -32,7 +32,7 @@ struct SoundAllocPool gAudioSessionPool;
struct SoundAllocPool gAudioInitPool;
struct SoundAllocPool gNotesAndBuffersPool;
u8 sAudioHeapPad[0x20]; // probably two unused pools
#if defined(BETTER_REVERB) && (defined(VERSION_US) || defined(VERSION_JP))
#ifdef BETTER_REVERB
struct SoundAllocPool gBetterReverbPool;
#endif
struct SoundAllocPool gSeqAndBankPool;
@@ -307,10 +307,10 @@ void puppyprint_get_allocated_pools(s32 *audioPoolList) {
&gAudioInitPool,
&gNotesAndBuffersPool,
&gSeqLoadedPool.persistent.pool,
&gSeqLoadedPool.temporary.pool,
&gBankLoadedPool.persistent.pool,
&gSeqLoadedPool.temporary.pool,
&gBankLoadedPool.temporary.pool,
#if defined(BETTER_REVERB) && (defined(VERSION_US) || defined(VERSION_JP))
#ifdef BETTER_REVERB
&gBetterReverbPool,
#endif
};
@@ -332,7 +332,7 @@ void session_pools_init(struct PoolSplit *a) {
gAudioSessionPool.cur = gAudioSessionPool.start;
sound_alloc_pool_init(&gNotesAndBuffersPool, SOUND_ALLOC_FUNC(&gAudioSessionPool, a->wantSeq ), a->wantSeq );
sound_alloc_pool_init(&gSeqAndBankPool, SOUND_ALLOC_FUNC(&gAudioSessionPool, a->wantCustom ), a->wantCustom );
#if defined(BETTER_REVERB) && (defined(VERSION_US) || defined(VERSION_JP))
#ifdef BETTER_REVERB
sound_alloc_pool_init(&gBetterReverbPool, SOUND_ALLOC_FUNC(&gAudioSessionPool, BETTER_REVERB_SIZE), BETTER_REVERB_SIZE);
#endif
}
@@ -985,7 +985,7 @@ void wait_for_audio_frames(s32 frames) {
}
#endif
u8 sAudioFirstBoot = 0;
u8 sAudioIsInitialized = FALSE;
// Separate the reverb settings into their own func. Bit unstable currently, so still only runs at boot.
#if defined(VERSION_EU) || defined(VERSION_SH)
void init_reverb_eu(void) {
@@ -1000,7 +1000,7 @@ void init_reverb_eu(void) {
gSynthesisReverbs[j].useReverb = 0;
// Both left and right channels are allocated/cleared together, then separated based on the reverb window size
if (!sAudioFirstBoot) {
if (!sAudioIsInitialized) {
gSynthesisReverbs[j].ringBuffer.left = soundAlloc(&gNotesAndBuffersPool, REVERB_WINDOW_SIZE_MAX * 4);
}
}
@@ -1015,7 +1015,7 @@ void init_reverb_eu(void) {
if (reverb->windowSize > REVERB_WINDOW_SIZE_MAX) {
reverb->windowSize = REVERB_WINDOW_SIZE_MAX;
}
if (sAudioFirstBoot) {
if (sAudioIsInitialized) {
bzero(reverb->ringBuffer.left, (REVERB_WINDOW_SIZE_MAX * 4));
} else {
reverb->resampleRate = (0x8000 / reverb->downsampleRate);
@@ -1041,7 +1041,7 @@ void init_reverb_eu(void) {
reverb->framesLeftToIgnore = 2;
if (reverb->downsampleRate != 1) {
reverb->resampleRate = (0x8000 / reverb->downsampleRate);
if (sAudioFirstBoot) {
if (sAudioIsInitialized) {
bzero(reverb->resampleStateLeft, (16 * sizeof(s16)));
bzero(reverb->resampleStateRight, (16 * sizeof(s16)));
bzero(reverb->unk24, (16 * sizeof(s16)));
@@ -1096,7 +1096,7 @@ void init_reverb_us(s32 presetId) {
reverbWindowSize = REVERB_WINDOW_SIZE_MAX;
}
// Both left and right channels are allocated/cleared together, then separated based on the reverb window size
if (!sAudioFirstBoot) {
if (!sAudioIsInitialized) {
gSynthesisReverb.ringBuffer.left = soundAlloc(&gNotesAndBuffersPool, REVERB_WINDOW_SIZE_MAX * 2 * sizeof(s16));
gSynthesisReverb.resampleStateLeft = soundAlloc(&gNotesAndBuffersPool, (16 * sizeof(s16)));
@@ -1130,7 +1130,7 @@ void init_reverb_us(s32 presetId) {
if (gReverbDownsampleRate != 1) {
gSynthesisReverb.resampleFlags = A_INIT;
gSynthesisReverb.resampleRate = (0x8000 / gReverbDownsampleRate);
if (sAudioFirstBoot) {
if (sAudioIsInitialized) {
bzero(gSynthesisReverb.resampleStateLeft, (16 * sizeof(s16)));
bzero(gSynthesisReverb.resampleStateRight, (16 * sizeof(s16)));
bzero(gSynthesisReverb.unk24, (16 * sizeof(s16)));
@@ -1145,7 +1145,7 @@ void init_reverb_us(s32 presetId) {
// 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) {
if (sAudioFirstBoot) {
if (sAudioIsInitialized) {
bzero(delayBufsL[0], (BETTER_REVERB_SIZE - BETTER_REVERB_PTR_SIZE));
}
@@ -1166,7 +1166,7 @@ void init_reverb_us(s32 presetId) {
#if defined(VERSION_JP) || defined(VERSION_US)
void audio_reset_session(struct AudioSessionSettings *preset, s32 presetId) {
if (sAudioFirstBoot) {
if (sAudioIsInitialized) {
bzero(&gAiBuffers[0][0], (AIBUFFER_LEN * NUMAIBUFFERS));
persistent_pool_clear(&gSeqLoadedPool.persistent);
persistent_pool_clear(&gBankLoadedPool.persistent);
@@ -1187,7 +1187,7 @@ void audio_reset_session(struct AudioSessionSettings *preset, s32 presetId) {
}
#else
void audio_reset_session(void) {
if (sAudioFirstBoot) {
if (sAudioIsInitialized) {
persistent_pool_clear(&gSeqLoadedPool.persistent);
persistent_pool_clear(&gBankLoadedPool.persistent);
temporary_pool_clear(&gSeqLoadedPool.temporary);
@@ -1313,6 +1313,16 @@ void audio_reset_session(void) {
gAudioBufferParameters.minAiBufferLength *= gAudioBufferParameters.presetUnk4;
gAudioBufferParameters.updatesPerFrame *= gAudioBufferParameters.presetUnk4;
if (gIsConsole)
gMaxSimultaneousNotes = MAX_SIMULTANEOUS_NOTES_CONSOLE;
else
gMaxSimultaneousNotes = MAX_SIMULTANEOUS_NOTES_EMULATOR;
if (gMaxSimultaneousNotes > MAX_SIMULTANEOUS_NOTES)
gMaxSimultaneousNotes = MAX_SIMULTANEOUS_NOTES;
else if (gMaxSimultaneousNotes < 0)
gMaxSimultaneousNotes = 0;
#ifdef VERSION_SH
if (gAudioBufferParameters.presetUnk4 >= 2) {
gAudioBufferParameters.maxAiBufferLength -= 0x10;
@@ -1330,6 +1340,16 @@ void audio_reset_session(void) {
gMinAiBufferLength = gSamplesPerFrameTarget - 0x10;
gAudioUpdatesPerFrame = updatesPerFrame = gSamplesPerFrameTarget / 160 + 1;
if (gIsConsole)
gMaxSimultaneousNotes = MAX_SIMULTANEOUS_NOTES_CONSOLE;
else
gMaxSimultaneousNotes = MAX_SIMULTANEOUS_NOTES_EMULATOR;
if (gMaxSimultaneousNotes > MAX_SIMULTANEOUS_NOTES)
gMaxSimultaneousNotes = MAX_SIMULTANEOUS_NOTES;
else if (gMaxSimultaneousNotes < 0)
gMaxSimultaneousNotes = 0;
// Compute conversion ratio from the internal unit tatums/tick to the
// external beats/minute (JP) or tatums/minute (US). In practice this is
// 300 on JP and 14360 on US.
@@ -1344,12 +1364,9 @@ void audio_reset_session(void) {
#if defined(VERSION_SH)
persistentMem = DOUBLE_SIZE_ON_64_BIT(preset->persistentSeqMem + preset->persistentBankMem + preset->unk18 + preset->unkMem28 + 0x10);
temporaryMem = DOUBLE_SIZE_ON_64_BIT(preset->temporarySeqMem + preset->temporaryBankMem + preset->unk24 + preset->unkMem2C + 0x10);
#elif defined(VERSION_EU)
#else
persistentMem = DOUBLE_SIZE_ON_64_BIT(preset->persistentSeqMem + preset->persistentBankMem);
temporaryMem = DOUBLE_SIZE_ON_64_BIT(preset->temporarySeqMem + preset->temporaryBankMem);
#else
persistentMem = DOUBLE_SIZE_ON_64_BIT(preset->persistentBankMem + preset->persistentSeqMem);
temporaryMem = DOUBLE_SIZE_ON_64_BIT(preset->temporaryBankMem + preset->temporarySeqMem);
#endif
totalMem = persistentMem + temporaryMem;
wantMisc = gAudioSessionPool.size - totalMem - BETTER_REVERB_SIZE;
@@ -1382,19 +1399,20 @@ void audio_reset_session(void) {
#if defined(VERSION_JP) || defined(VERSION_US)
for (j = 0; j < 2; j++) {
gAudioCmdBuffers[j] = soundAlloc(&gNotesAndBuffersPool, gMaxAudioCmds * sizeof(u64));
gAudioCmdBuffers[j] = soundAlloc(&gNotesAndBuffersPool, ALIGN16(gMaxAudioCmds * sizeof(u64)));
}
#endif
gNotes = soundAlloc(&gNotesAndBuffersPool, gMaxSimultaneousNotes * sizeof(struct Note));
gNotes = soundAlloc(&gNotesAndBuffersPool, ALIGN16(gMaxSimultaneousNotes * sizeof(struct Note)));
note_init_all();
init_note_free_list();
#if defined(VERSION_EU) || defined(VERSION_SH)
gNoteSubsEu = soundAlloc(&gNotesAndBuffersPool, (gAudioBufferParameters.updatesPerFrame * gMaxSimultaneousNotes) * sizeof(struct NoteSubEu));
// NOTE: Cannot be computed automatically in the audio heap define; approximation to be used instead
gNoteSubsEu = soundAlloc(&gNotesAndBuffersPool, ALIGN16((gAudioBufferParameters.updatesPerFrame * gMaxSimultaneousNotes) * sizeof(struct NoteSubEu)));
for (j = 0; j != 2; j++) {
gAudioCmdBuffers[j] = soundAlloc(&gNotesAndBuffersPool, gMaxAudioCmds * sizeof(u64));
gAudioCmdBuffers[j] = soundAlloc(&gNotesAndBuffersPool, ALIGN16(gMaxAudioCmds * sizeof(u64)));
}
init_reverb_eu();
@@ -1427,7 +1445,8 @@ void audio_reset_session(void) {
append_puppyprint_log("Audio Initialised in %dus.", (s32)OS_CYCLES_TO_USEC(osGetTime() - first));
#endif
#endif
sAudioFirstBoot = 1;
sAudioIsInitialized = TRUE;
}
#ifdef VERSION_SH
+4 -2
View File
@@ -300,7 +300,7 @@ struct SequencePlayer {
/* , 0x028, 0x02C*/ f32 fadeVolumeScale;
/* , 0x02C*/ f32 appliedFadeVolume;
#else
/* */ u8 pad2[4];
/*0x028, */ f32 volumeDefault;
#endif
/*0x02C, 0x030, 0x034*/ struct SequenceChannel *channels[CHANNELS_MAX];
/*0x06C, 0x070*/ struct M64ScriptState scriptState;
@@ -680,6 +680,7 @@ struct Note {
/*0x18, 0x38*/ f32 portamentoFreqScale;
/*0x1C, 0x3C*/ f32 vibratoFreqScale;
/*0x20*/ u16 samplePosFrac;
/* */ u8 pad2[2];
/*0x24*/ struct AudioBankSound *sound;
/*0x28, 0x40*/ struct SequenceChannelLayer *prevParentLayer;
/*0x2C, 0x44*/ struct SequenceChannelLayer *parentLayer;
@@ -690,6 +691,7 @@ struct Note {
/*0x3E*/ u16 targetVolRight; // Q1.15, but will always be non-negative
/*0x40*/ u8 reverbVol; // Q1.7
/*0x41*/ u8 unused1; // never read, set to 0x3f
/* */ u8 pad3[2];
/*0x44*/ struct NoteAttributes attributes;
/*0x54, 0x58*/ struct AdsrState adsr;
/*0x74, 0x7C*/ struct Portamento portamento;
@@ -699,7 +701,7 @@ struct Note {
/*0xA0*/ s16 reverbVolShifted; // Q1.15
/*0xA2*/ s16 unused2; // never read, set to 0
/*0xA4, 0x00*/ struct AudioListItem listItem;
/* */ u8 pad2[0xc];
/* */ u8 pad4[0xc];
}; // size = 0xC0
#endif
+7 -19
View File
@@ -42,7 +42,7 @@ OSMesgQueue gAudioDmaMesgQueue;
OSMesg gAudioDmaMesg;
OSIoMesg gAudioDmaIoMesg;
struct SharedDma sSampleDmas[0x60];
struct SharedDma sSampleDmas[MAX_SIMULTANEOUS_NOTES * 4];
u32 gSampleDmaNumListItems; // sh: 0x803503D4
u32 sSampleDmaListSize1; // sh: 0x803503D8
@@ -335,11 +335,7 @@ void init_sample_dma_buffers(UNUSED s32 arg0) {
s32 j;
#endif
#if defined(VERSION_EU)
sDmaBufSize = 0x400;
#else
sDmaBufSize = 144 * 9;
#endif
sDmaBufSize = DMA_BUF_SIZE_0;
#if defined(VERSION_EU)
for (i = 0; i < gMaxSimultaneousNotes * 3 * gAudioBufferParameters.presetUnk4; i++) {
@@ -378,11 +374,8 @@ out1:
sSampleDmaReuseQueueHead1 = (u8) gSampleDmaNumListItems;
sSampleDmaListSize1 = gSampleDmaNumListItems;
#if defined(VERSION_EU)
sDmaBufSize = 0x200;
#else
sDmaBufSize = 160 * 9;
#endif
sDmaBufSize = DMA_BUF_SIZE_1;
for (i = 0; i < gMaxSimultaneousNotes; i++) {
sSampleDmas[gSampleDmaNumListItems].buffer = soundAlloc(&gNotesAndBuffersPool, sDmaBufSize);
if (sSampleDmas[gSampleDmaNumListItems].buffer == NULL) {
@@ -442,7 +435,7 @@ void patch_sound(UNUSED struct AudioBankSound *sound, UNUSED u8 *memBase, UNUSED
#if defined(VERSION_EU)
else if (sample->loaded == 0x80) {
PATCH(sample->sampleAddr, offsetBase);
u8 *mem = soundAlloc(&gNotesAndBuffersPool, sample->sampleSize); // TODO: Memory leak!
u8 *mem = soundAlloc(&gNotesAndBuffersPool, sample->sampleSize); // TODO: Memory issue most likely!
if (mem == NULL) {
sample->sampleAddr = patched;
sample->loaded = 1;
@@ -990,13 +983,8 @@ void audio_init() {
alSeqFileNew(gAlTbl, gSoundDataRaw);
// Load bank sets for each sequence
#ifdef EXPAND_AUDIO_HEAP
gAlBankSets = soundAlloc(&gAudioInitPool, 0x400);
audio_dma_copy_immediate((uintptr_t) gBankSetsData, gAlBankSets, 0x400);
#else
gAlBankSets = soundAlloc(&gAudioInitPool, 0x100);
audio_dma_copy_immediate((uintptr_t) gBankSetsData, gAlBankSets, 0x100);
#endif
gAlBankSets = soundAlloc(&gAudioInitPool, BANK_SETS_ALLOC);
audio_dma_copy_immediate((uintptr_t) gBankSetsData, gAlBankSets, BANK_SETS_ALLOC);
init_sequence_players();
gAudioLoadLock = AUDIO_LOCK_NOT_LOADING;
+1 -1
View File
@@ -16,7 +16,7 @@ enum Preloads {
#define IS_SEQUENCE_CHANNEL_VALID(ptr) ((uintptr_t)(ptr) != (uintptr_t)&gSequenceChannelNone)
extern struct Note *gNotes;
extern u8 sAudioFirstBoot;
extern u8 sAudioIsInitialized;
// Music in SM64 is played using 3 players:
// gSequencePlayers[0] is level background music
+2 -2
View File
@@ -1443,9 +1443,9 @@ void note_init_all(void) {
#if defined(VERSION_SH)
note->synthesisState.synthesisBuffers = sound_alloc_uninitialized(&gNotesAndBuffersPool, sizeof(struct NoteSynthesisBuffers));
#elif defined(VERSION_EU)
note->synthesisState.synthesisBuffers = soundAlloc(&gNotesAndBuffersPool, sizeof(struct NoteSynthesisBuffers));
note->synthesisState.synthesisBuffers = soundAlloc(&gNotesAndBuffersPool, ALIGN16(sizeof(struct NoteSynthesisBuffers)));
#else
note->synthesisBuffers = soundAlloc(&gNotesAndBuffersPool, sizeof(struct NoteSynthesisBuffers));
note->synthesisBuffers = soundAlloc(&gNotesAndBuffersPool, ALIGN16(sizeof(struct NoteSynthesisBuffers)));
#endif
}
}
+12 -2
View File
@@ -2493,6 +2493,10 @@ void sequence_player_process_sequence(struct SequencePlayer *seqPlayer) {
#else
case 0xdb: // seq_setvol
cmd = m64_read_u8(state);
seqPlayer->volumeDefault = FLOAT_CAST(cmd) / 127.0f;
if (seqPlayer->volumeDefault >= 1.0f)
seqPlayer->volumeDefault = 1.0f;
switch (seqPlayer->state) {
case SEQUENCE_PLAYER_STATE_2:
if (seqPlayer->fadeRemainingFrames != 0) {
@@ -2514,8 +2518,13 @@ void sequence_player_process_sequence(struct SequencePlayer *seqPlayer) {
case 0xda: // seq_changevol
temp = m64_read_u8(state);
seqPlayer->fadeVolume =
seqPlayer->fadeVolume + (f32)(s8) temp / 127.0f;
seqPlayer->fadeVolume += (f32)(s8) temp / 127.0f;
seqPlayer->volumeDefault += (f32)(s8) temp / 127.0f;
if (seqPlayer->volumeDefault > 1.0f)
seqPlayer->volumeDefault = 1.0f;
else if (seqPlayer->volumeDefault < 0.0f)
seqPlayer->volumeDefault = 0.0f;
break;
#endif
@@ -2707,6 +2716,7 @@ void init_sequence_player(u32 player) {
seqPlayer->state = 1;
#else
seqPlayer->state = SEQUENCE_PLAYER_STATE_0;
seqPlayer->volumeDefault = 1.0f;
#endif
seqPlayer->fadeRemainingFrames = 0;
#if defined(VERSION_EU) || defined(VERSION_SH)
+18 -32
View File
@@ -39,7 +39,7 @@
#define AUDIO_ALIGN(val, amnt) (((val) + (1 << amnt) - 1) & ~((1 << amnt) - 1))
#if defined(BETTER_REVERB) && (defined(VERSION_US) || defined(VERSION_JP))
#ifdef BETTER_REVERB
/* ----------------------------------------------------------------------BEGIN REVERB PARAMETERS---------------------------------------------------------------------- */
@@ -61,6 +61,7 @@
*
* This is also known to cause severe lag on emulators that have counter factor set to 2 or greater.
* Be sure either you alert the user in advance, or check for and set betterReverbDownsampleEmulator to -1 if it's detected the user isn't using good settings.
* Reducing performance heavy parameters or using RCVI hack may be another working solution to this problem.
*/
@@ -80,28 +81,28 @@ s8 betterReverbDownsampleEmulator = 2;
// This value represents the number of filters to use with the reverb. This can be decreased to improve performance, but at the cost of a lesser presence of reverb in the final audio.
// Filter count should always be a multiple of 3. Never ever set this value to be greater than NUM_ALLPASS.
// Setting it to anything less than 3 will disable reverb outright.
// This can be changed at any time, but is best set when calling audio_reset_session.
// This can be changed at any time, but is best set immediately before calling audio_reset_session.
u32 reverbFilterCountConsole = (NUM_ALLPASS - 6);
// This value represents the number of filters to use with the reverb. This can be decreased to improve performance, but at the cost of a lesser presence of reverb in the final audio.
// Filter count should always be a multiple of 3. Never ever set this value to be greater than NUM_ALLPASS.
// Setting it to anything less than 3 will disable reverb outright.
// This can be changed at any time, but is best set when calling audio_reset_session.
// This can be changed at any time, but is best set immediately before calling audio_reset_session.
u32 reverbFilterCountEmulator = NUM_ALLPASS;
// Set this to TRUE to use mono over stereo for reverb. This should increase performance, but at the cost of a less fullfilling reverb experience.
// If performance is desirable, it is recommended to change reverbFilterCountConsole or betterReverbDownsampleConsole first.
// This can be changed at any time, but is best set when calling audio_reset_session.
// This can be changed at any time, but is best set immediately before calling audio_reset_session.
u8 monoReverbConsole = FALSE;
// Set this to TRUE to use mono over stereo for reverb. This should increase performance, but at the cost of a less fullfilling reverb experience.
// If performance is desirable, it is recommended to change reverbFilterCountEmulator or betterReverbDownsampleEmulator first.
// This can be changed at any time, but is best set when calling audio_reset_session.
// This can be changed at any time, but is best set immediately before calling audio_reset_session.
u8 monoReverbEmulator = FALSE;
// This value controls the size of the reverb buffer. It affects the global reverb delay time. This variable is one of the easiest to control.
// 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. This is taken into account automatically, but also means the value set here isn't what always gets used.
// Similarly, this value maxes out at (REVERB_WINDOW_SIZE_MAX * 2^(downsample factor - 1)).
// 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;
@@ -120,32 +121,15 @@ 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/2.
// If setting a reverb downsample value to 1, these must be cumulatively smaller than BETTER_REVERB_SIZE/4.
// 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 delaysL[NUM_ALLPASS] = {
// None of the delay values should ever be smaller than 1; these are s32s purely to avoid typecasts.
// These values are applied any time audio_reset_session is called, and as such can be changed at any time without issues.
s32 delaysBaselineL[NUM_ALLPASS] = {
1080, 1352, 1200,
1200, 1232, 1432,
1384, 1048, 1352,
928, 1504, 1512
};
s32 delaysR[NUM_ALLPASS] = {
1384, 1352, 1048,
928, 1512, 1504,
1080, 1200, 1352,
1200, 1432, 1232
};
// 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 delaysL/R, these should be kept within the memory constraints defined by BETTER_REVERB_SIZE.
const s32 delaysBaselineL[NUM_ALLPASS] = {
1080, 1352, 1200,
1200, 1232, 1432,
1384, 1048, 1352,
928, 1504, 1512
};
const s32 delaysBaselineR[NUM_ALLPASS] = {
s32 delaysBaselineR[NUM_ALLPASS] = {
1384, 1352, 1048,
928, 1512, 1504,
1080, 1200, 1352,
@@ -164,10 +148,12 @@ s32 reverbFilterCount = NUM_ALLPASS;
s32 reverbFilterCountm1 = (NUM_ALLPASS - 1);
u8 monoReverb = FALSE;
u8 toggleBetterReverb = TRUE;
s32 allpassIdxL[NUM_ALLPASS] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
s32 allpassIdxR[NUM_ALLPASS] = { 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 allpassIdxL[NUM_ALLPASS] = {0};
s32 allpassIdxR[NUM_ALLPASS] = {0};
s32 tmpBufL[NUM_ALLPASS] = {0};
s32 tmpBufR[NUM_ALLPASS] = {0};
s32 delaysL[NUM_ALLPASS] = {0};
s32 delaysR[NUM_ALLPASS] = {0};
s32 **delayBufsL;
s32 **delayBufsR;
#endif
@@ -206,7 +192,7 @@ struct SynthesisReverb gSynthesisReverb;
u8 sAudioSynthesisPad[0x20];
#endif
#if defined(BETTER_REVERB) && (defined(VERSION_US) || defined(VERSION_JP))
#ifdef BETTER_REVERB
static inline void reverb_samples(s16 *outSampleL, s16 *outSampleR, s32 inSampleL, s32 inSampleR) {
s32 i = 0;
s32 j = 0;
+21 -4
View File
@@ -19,7 +19,7 @@
#define ALIGN16(val) (((val) + 0xF) & ~0xF)
#if defined(BETTER_REVERB) && (defined(VERSION_US) || defined(VERSION_JP))
#ifdef BETTER_REVERB
#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.
#define BETTER_REVERB_PTR_SIZE ALIGN16(NUM_ALLPASS * sizeof(s32*) * 2) // Allocation space consumed by dynamically allocated pointers
@@ -39,8 +39,8 @@ extern u8 monoReverbConsole;
extern u8 monoReverbEmulator;
extern s32 betterReverbWindowsSize;
extern const s32 delaysBaselineL[NUM_ALLPASS];
extern const s32 delaysBaselineR[NUM_ALLPASS];
extern s32 delaysBaselineL[NUM_ALLPASS];
extern s32 delaysBaselineR[NUM_ALLPASS];
extern s32 delaysL[NUM_ALLPASS];
extern s32 delaysR[NUM_ALLPASS];
extern s32 reverbMultsL[NUM_ALLPASS / 3];
@@ -51,6 +51,8 @@ extern s32 **delayBufsR;
extern u8 toggleBetterReverb;
#define REVERB_WINDOW_SIZE_MAX 0x2000
STATIC_ASSERT(NUM_ALLPASS % 3 == 0, "NUM_ALLPASS must be a multiple of 3!");
#else
#define BETTER_REVERB_SIZE 0
@@ -63,7 +65,22 @@ extern u8 toggleBetterReverb;
#endif
#define REVERB_WINDOW_HEAP_SIZE (REVERB_WINDOW_SIZE_MAX * sizeof(s16) * 2)
#if defined(VERSION_JP) || defined(VERSION_US)
#define REVERB_WINDOW_HEAP_SIZE \
( \
(REVERB_WINDOW_SIZE_MAX * sizeof(s16) * 2) \
+ (4 * (16 * sizeof(s16))) \
+ (4 /* gAudioUpdatesPerFrame */ * (2 * DEFAULT_LEN_2CH)) \
)
#else
#define REVERB_WINDOW_HEAP_SIZE \
( \
((REVERB_WINDOW_SIZE_MAX * sizeof(s16) * 2) \
+ (4 * (16 * sizeof(s16))) \
+ (4 /* gAudioUpdatesPerFrame */ * (2 * DEFAULT_LEN_2CH))) \
* 4 /* gNumSynthesisReverbs */ \
)
#endif
struct ReverbRingBufferItem {
s16 numSamplesAfterDownsampling;
+10
View File
@@ -13,6 +13,7 @@
#include "game/main.h"
#include "game/rumble_init.h"
#include "game/version.h"
#include "game/vc_check.h"
#ifdef UNF
#include "usb/usb.h"
#include "usb/debug.h"
@@ -317,6 +318,15 @@ void thread3_main(UNUSED void *arg) {
osSyncPrintf("Linker : %s\n", __linker__);
#endif
if (IO_READ(DPC_CLOCK_REG) == 0) {
gIsConsole = FALSE;
gBorderHeight = BORDER_HEIGHT_EMULATOR;
gIsVC = IS_VC();
} else {
gIsConsole = TRUE;
gBorderHeight = BORDER_HEIGHT_CONSOLE;
}
create_thread(&gSoundThread, THREAD_4_SOUND, thread4_sound, NULL, gThread4Stack + 0x2000, 20);
osStartThread(&gSoundThread);
-9
View File
@@ -391,15 +391,6 @@ void render_init(void) {
#ifdef DEBUG_FORCE_CRASH_ON_BOOT
FORCE_CRASH
#endif
if (IO_READ(DPC_PIPEBUSY_REG) == 0) {
gIsConsole = FALSE;
gBorderHeight = BORDER_HEIGHT_EMULATOR;
gIsVC = IS_VC();
} else {
gIsConsole = TRUE;
gBorderHeight = BORDER_HEIGHT_CONSOLE;
}
gGfxPool = &gGfxPools[0];
set_segment_base_addr(SEGMENT_RENDER, gGfxPool->buffer);
gGfxSPTask = &gGfxPool->spTask;
+8 -8
View File
@@ -310,14 +310,14 @@ void print_ram_overview(void) {
}
const char *audioPoolNames[NUM_AUDIO_POOLS] = {
"gAudioInitPool",
"gNotesAndBuffersPool",
"gSeqLoadedPool.persistent.pool",
"gSeqLoadedPool.temporary.pool",
"gBankLoadedPool.persistent.pool",
"gBankLoadedPool.temporary.pool",
#if defined(BETTER_REVERB) && (defined(VERSION_US) || defined(VERSION_JP))
"gBetterReverbPool",
"Audio Init Pool",
"Notes And Buffers Pool",
"Persistent Sequence Pool",
"Persistent Bank Pool",
"Temporary Sequence Pool",
"Temporary Bank Pool",
#ifdef BETTER_REVERB
"Better Reverb Pool",
#endif
};
+1 -1
View File
@@ -33,7 +33,7 @@ enum PuppyprintTextAlign {
};
#if PUPPYPRINT_DEBUG
#if defined(BETTER_REVERB) && (defined(VERSION_US) || defined(VERSION_JP))
#ifdef BETTER_REVERB
#define NUM_AUDIO_POOLS 7
#else
#define NUM_AUDIO_POOLS 6