Audio Load Improvements

Audio in EU and US has been modified so it no longer has coded dead frames in between loading, speeding up level load times substantially.
This commit is contained in:
Fazana
2021-09-14 21:41:06 +01:00
committed by GitHub
30 changed files with 541 additions and 479 deletions

View File

@@ -157,12 +157,12 @@ LINK_LIBRARIES = $(foreach i,$(LIBRARIES),-l$(i))
ifeq ($(COMPILER),gcc)
NON_MATCHING := 1
MIPSISET := -mips3
OPT_FLAGS := -Ofast
OPT_FLAGS := -Os
else ifeq ($(COMPILER),clang)
NON_MATCHING := 1
# clang doesn't support ABI 'o32' for 'mips3'
MIPSISET := -mips2
OPT_FLAGS := -Ofast
OPT_FLAGS := -Os
endif
@@ -398,8 +398,8 @@ export LD_LIBRARY_PATH=./tools
AS := $(CROSS)as
ifeq ($(COMPILER),gcc)
CC := $(CROSS)gcc
$(BUILD_DIR)/actors/%.o: OPT_FLAGS := -Ofast -mlong-calls
$(BUILD_DIR)/levels/%.o: OPT_FLAGS := -Ofast -mlong-calls
$(BUILD_DIR)/actors/%.o: OPT_FLAGS := -Os -mlong-calls
$(BUILD_DIR)/levels/%.o: OPT_FLAGS := -Os -mlong-calls
else ifeq ($(COMPILER),clang)
CC := clang
endif

View File

@@ -26,13 +26,13 @@
.ascii "E" /* NTSC-U (North America) */
#endif
#if defined(SRAM)
.byte 0x30 /* Version */
.byte 0x32 /* Version */
#elif defined(EEP16K)
.byte 0x20 /* Version */
.byte 0x22 /* Version */
#elif defined(SRAM768K)
.byte 0x40 /* Version */
.byte 0x42 /* Version */
#elif defined(FLASHRAM)
.byte 0x50 /* Version */
.byte 0x52 /* Version */
#else
.byte 0x10 /* Version */
.byte 0x12 /* Version */
#endif

View File

@@ -113,7 +113,7 @@
#define LONGER_POLES
// Number of possible unique model ID's (keep it higher than 256)
#define MODEL_ID_COUNT 256
// Increase audio heap size to allow for more concurrent notes to be played and for more custom sequences/banks to be imported (does nothing with EU and SH versions)
// 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)
#define EXPAND_AUDIO_HEAP
// Allow all surfaces types to have force, (doesn't require setting force, just allows it to be optional).
#define ALL_SURFACES_HAVE_FORCE

View File

@@ -69,4 +69,8 @@
#define VIRTUAL_TO_PHYSICAL2(addr) ((void *)(addr))
#endif
#define MODE_NTSC 0
#define MODE_MPAL 1
#define MODE_PAL 2
#endif // MACROS_H

View File

@@ -19,6 +19,14 @@
#define BAD_RETURN(cmd) cmd
#endif
struct Config
{
f32 audioFrequency;
#ifdef WIDE
s16 widescreen;
#endif
u8 tvType;
};
struct Controller
{

View File

@@ -2113,9 +2113,6 @@ chan_setlayer 0, .layer_C6C
chan_end
.layer_C6C:
#if defined(VERSION_EU) || defined(VERSION_SH)
layer_transpose 1
#endif
layer_portamento 0x82, 44, 200
layer_note1 39, 0x30, 127
layer_end

View File

@@ -8,32 +8,40 @@ extern struct OSMesgQueue OSMesgQueue1;
extern struct OSMesgQueue OSMesgQueue2;
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.
#ifdef VERSION_EU
struct ReverbSettingsEU sReverbSettings[] = {
{ 0x04, 0x0c, 0x2fff },
{ 0x04, 0x0a, 0x47ff },
{ 0x04, 0x10, 0x2fff },
{ 0x04, 0x0e, 0x3fff },
{ 0x04, 0x0c, 0x4fff },
{ 0x04, 0x0a, 0x37ff }
struct ReverbSettingsEU sReverbSettings[8] = {
{/*Downsample Rate*/ 1,/*Window Size*/ 64,/*Gain*/ 0x2FFF },
{/*Downsample Rate*/ 1,/*Window Size*/ 40,/*Gain*/ 0x47FF },
{/*Downsample Rate*/ 1,/*Window Size*/ 64,/*Gain*/ 0x2FFF },
{/*Downsample Rate*/ 1,/*Window Size*/ 60,/*Gain*/ 0x3FFF },
{/*Downsample Rate*/ 1,/*Window Size*/ 48,/*Gain*/ 0x4FFF },
{/*Downsample Rate*/ 1,/*Window Size*/ 64,/*Gain*/ 0x2FFF }, //Duplicate of the first index
{/*Downsample Rate*/ 1,/*Window Size*/ 40,/*Gain*/ 0x47FF }, //Duplicate of the second index
{/*Downsample Rate*/ 1,/*Window Size*/ 40,/*Gain*/ 0x37FF },
};
/**
1: Frequency
2: Unk1 - Should be 1
3: Simultaneous Notes
4: Number of Reverberations
5: Unk2 - Should be 0
6: Volume
7: Unk3 - Should be 0
8: Persistent Sequence Memory
9: Persistent Bank Memory
10: Temporary Sequence Memory
11: Temporary Bank Memory
*/
struct AudioSessionSettingsEU gAudioSessionPresets[] = {
{ 0x00007d00, 0x01, 0x10, 0x01, 0x00, &sReverbSettings[0], 0x7fff, 0x0000, 0x00003a40, 0x00006d00,
0x00004400, 0x00002a00 },
{ 0x00007d00, 0x01, 0x10, 0x01, 0x00, &sReverbSettings[1], 0x7fff, 0x0000, 0x00003a40, 0x00006d00,
0x00004400, 0x00002a00 },
{ 0x00007d00, 0x01, 0x10, 0x01, 0x00, &sReverbSettings[2], 0x7fff, 0x0000, 0x00003a40, 0x00006d00,
0x00004400, 0x00002a00 },
{ 0x00007d00, 0x01, 0x10, 0x01, 0x00, &sReverbSettings[3], 0x7fff, 0x0000, 0x00003a40, 0x00006d00,
0x00004400, 0x00002a00 },
{ 0x00007d00, 0x01, 0x10, 0x01, 0x00, &sReverbSettings[4], 0x7fff, 0x0000, 0x00003a40, 0x00006d00,
0x00004400, 0x00002a00 },
{ 0x00007d00, 0x01, 0x10, 0x01, 0x00, &sReverbSettings[0], 0x7fff, 0x0000, 0x00004000, 0x00006e00,
0x00003f00, 0x00002a00 },
{ 0x00007d00, 0x01, 0x10, 0x01, 0x00, &sReverbSettings[1], 0x7fff, 0x0000, 0x00004100, 0x00006e00,
0x00004400, 0x00002a80 },
{ 0x00007d00, 0x01, 0x14, 0x01, 0x00, &sReverbSettings[5], 0x7fff, 0x0000, 0x00003500, 0x00006280,
0x00004000, 0x00001b00 }
#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
};
#endif
@@ -48,70 +56,39 @@ struct AudioSessionSettingsEU gAudioSessionPresets[] = {
// - memory used for persistent banks
// - 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.
#if defined(VERSION_JP) || defined(VERSION_US)
struct ReverbSettingsUS gReverbSettings[18] =
{
{1, 0x0C00, 0x2FFF},
{1, 0x0A00, 0x47FF},
{1, 0x1000, 0x2FFF},
{1, 0x0E00, 0x3FFF},
{1, 0x0C00, 0x4FFF},
{1, 0x0C00, 0x2FFF},
{1, 0x0A00, 0x47FF},
{1, 0x0800, 0x37FF},
{1, 0x0800, 0x2FFF},
{1, 0x0800, 0x3FFF},
{1, 0x1000, 0x3FFF},
{1, 0x1000, 0x2FFF},
{1, 0x0C00, 0x3FFF},
{1, 0x0800, 0x4FFF},
{1, 0x0800, 0x2FFF},
{1, 0x0800, 0x2FFF},
{1, 0x0800, 0x2FFF},
{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[18] = {
#ifdef VERSION_JP
{ 32000, 32, 1, 0x0800, 0x2FFF, 0x7FFF, 0x7200, 0xC000, 0x8800, 0x5400 },
{ 32000, 32, 1, 0x0A00, 0x47FF, 0x7FFF, 0x7200, 0xC000, 0x8800, 0x5400 },
{ 32000, 32, 1, 0x1000, 0x2FFF, 0x7FFF, 0x7200, 0xC000, 0x8800, 0x5400 },
{ 32000, 32, 1, 0x0E00, 0x3FFF, 0x7FFF, 0x7200, 0xC000, 0x8800, 0x5400 },
{ 32000, 32, 1, 0x0C00, 0x4FFF, 0x7FFF, 0x7200, 0xC000, 0x8800, 0x5400 },
{ 32000, 32, 1, 0x0800, 0x2FFF, 0x7FFF, 0x7C00, 0xC400, 0x7E00, 0x5400 },
{ 32000, 32, 1, 0x0A00, 0x47FF, 0x7FFF, 0x7E00, 0xC400, 0x8800, 0x5500 },
{ 32000, 40, 1, 0x0800, 0x37FF, 0x7FFF, 0x6600, 0xAA00, 0x8000, 0x3600 },
#else
{ 32000, 32, 1, 0x0C00, 0x2FFF, 0x7FFF, 0x7400, 0xDA00, 0x8800, 0x5400 },
{ 32000, 32, 1, 0x0A00, 0x47FF, 0x7FFF, 0x7400, 0xDA00, 0x8800, 0x5400 },
{ 32000, 32, 1, 0x1000, 0x2FFF, 0x7FFF, 0x7400, 0xDA00, 0x8800, 0x5400 },
{ 32000, 32, 1, 0x0E00, 0x3FFF, 0x7FFF, 0x7400, 0xDA00, 0x8800, 0x5400 },
{ 32000, 32, 1, 0x0C00, 0x4FFF, 0x7FFF, 0x7400, 0xDA00, 0x8800, 0x5400 },
{ 32000, 32, 1, 0x0C00, 0x2FFF, 0x7FFF, 0x8000, 0xDC00, 0x7E00, 0x5400 },
{ 32000, 32, 1, 0x0A00, 0x47FF, 0x7FFF, 0x8200, 0xDC00, 0x8800, 0x5500 },
{ 32000, 40, 1, 0x0800, 0x37FF, 0x7FFF, 0x6980, 0xC500, 0x8000, 0x3600 },
#endif
{ 27000, 32, 1, 0x0800, 0x2FFF, 0x7FFF, 0x4A00, 0xAA00, 0xE800, 0x4800 },
{ 27000, 32, 1, 0x0800, 0x3FFF, 0x7FFF, 0x4A00, 0xAA00, 0xE800, 0x4800 },
{ 27000, 32, 1, 0x1000, 0x2FFF, 0x7FFF, 0x4A00, 0xAA00, 0xE800, 0x4800 },
{ 27000, 32, 1, 0x1000, 0x3FFF, 0x7FFF, 0x4A00, 0xAA00, 0xE800, 0x4800 },
{ 27000, 32, 1, 0x0C00, 0x4FFF, 0x7FFF, 0x4A00, 0xAA00, 0xE800, 0x4800 },
{ 32000, 28, 1, 0x0800, 0x2FFF, 0x7FFF, 0x4A00, 0xAA00, 0xE800, 0x4800 },
{ 32000, 24, 1, 0x0800, 0x2FFF, 0x7FFF, 0x4A00, 0xAA00, 0xE800, 0x4800 },
{ 32000, 20, 1, 0x0800, 0x2FFF, 0x7FFF, 0x4A00, 0xAA00, 0xE800, 0x4800 },
{ 32000, 16, 1, 0x0800, 0x2FFF, 0x7FFF, 0x4A00, 0xAA00, 0xE800, 0x4800 },
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
struct AudioSessionSettings gAudioSessionPresets[1] = {
{ 32000, 40, 1, 0x1000, 0x2FFF, 0x7FFF, 0x8200, 0xDC00, 0xE800, 0x5500 },
};
#else
struct AudioSessionSettings gAudioSessionPresets[18] = {
#ifdef VERSION_JP
{ 32000, 16, 1, 0x0800, 0x2FFF, 0x7FFF, 0x3900, 0x6000, 0x4400, 0x2A00 },
{ 32000, 16, 1, 0x0A00, 0x47FF, 0x7FFF, 0x3900, 0x6000, 0x4400, 0x2A00 },
{ 32000, 16, 1, 0x1000, 0x2FFF, 0x7FFF, 0x3900, 0x6000, 0x4400, 0x2A00 },
{ 32000, 16, 1, 0x0E00, 0x3FFF, 0x7FFF, 0x3900, 0x6000, 0x4400, 0x2A00 },
{ 32000, 16, 1, 0x0C00, 0x4FFF, 0x7FFF, 0x3900, 0x6000, 0x4400, 0x2A00 },
{ 32000, 16, 1, 0x0800, 0x2FFF, 0x7FFF, 0x3E00, 0x6200, 0x3F00, 0x2A00 },
{ 32000, 16, 1, 0x0A00, 0x47FF, 0x7FFF, 0x3F00, 0x6200, 0x4400, 0x2A80 },
{ 32000, 20, 1, 0x0800, 0x37FF, 0x7FFF, 0x3300, 0x5500, 0x4000, 0x1B00 },
#else
{ 32000, 16, 1, 0x0C00, 0x2FFF, 0x7FFF, 0x3A00, 0x6D00, 0x4400, 0x2A00 },
{ 32000, 16, 1, 0x0A00, 0x47FF, 0x7FFF, 0x3A00, 0x6D00, 0x4400, 0x2A00 },
{ 32000, 16, 1, 0x1000, 0x2FFF, 0x7FFF, 0x3A00, 0x6D00, 0x4400, 0x2A00 },
{ 32000, 16, 1, 0x0E00, 0x3FFF, 0x7FFF, 0x3A00, 0x6D00, 0x4400, 0x2A00 },
{ 32000, 16, 1, 0x0C00, 0x4FFF, 0x7FFF, 0x3A00, 0x6D00, 0x4400, 0x2A00 },
{ 32000, 16, 1, 0x0C00, 0x2FFF, 0x7FFF, 0x4000, 0x6E00, 0x3F00, 0x2A00 },
{ 32000, 16, 1, 0x0A00, 0x47FF, 0x7FFF, 0x4100, 0x6E00, 0x4400, 0x2A80 },
{ 32000, 20, 1, 0x0800, 0x37FF, 0x7FFF, 0x34C0, 0x6280, 0x4000, 0x1B00 },
#endif
{ 27000, 16, 1, 0x0800, 0x2FFF, 0x7FFF, 0x2500, 0x5500, 0x7400, 0x2400 },
{ 27000, 16, 1, 0x0800, 0x3FFF, 0x7FFF, 0x2500, 0x5500, 0x7400, 0x2400 },
{ 27000, 16, 1, 0x1000, 0x2FFF, 0x7FFF, 0x2500, 0x5500, 0x7400, 0x2400 },
{ 27000, 16, 1, 0x1000, 0x3FFF, 0x7FFF, 0x2500, 0x5500, 0x7400, 0x2400 },
{ 27000, 16, 1, 0x0C00, 0x4FFF, 0x7FFF, 0x2500, 0x5500, 0x7400, 0x2400 },
{ 32000, 14, 1, 0x0800, 0x2FFF, 0x7FFF, 0x2500, 0x5500, 0x7400, 0x2400 },
{ 32000, 12, 1, 0x0800, 0x2FFF, 0x7FFF, 0x2500, 0x5500, 0x7400, 0x2400 },
{ 32000, 10, 1, 0x0800, 0x2FFF, 0x7FFF, 0x2500, 0x5500, 0x7400, 0x2400 },
{ 32000, 8, 1, 0x0800, 0x2FFF, 0x7FFF, 0x2500, 0x5500, 0x7400, 0x2400 },
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
struct AudioSessionSettings gAudioSessionPresets[1] = {
{ 32000, 20, 1, 0x1000, 0x2FFF, 0x7FFF, 0x4100, 0x6E00, 0x7400, 0x2A80 },
};
#endif
#endif

View File

@@ -16,8 +16,10 @@
// constant .data
#if defined(VERSION_EU) || defined(VERSION_SH)
extern struct AudioSessionSettingsEU gAudioSessionPresets[];
extern struct ReverbSettingsEU sReverbSettings[8];
#else
extern struct AudioSessionSettings gAudioSessionPresets[18];
extern struct AudioSessionSettings gAudioSessionPresets[1];
extern struct ReverbSettingsUS gReverbSettings[18];
#endif
extern u16 D_80332388[128]; // unused
@@ -111,13 +113,13 @@ extern u16 gUnused80226E98[0x10];
extern u32 gAudioRandom;
#ifdef EXPAND_AUDIO_HEAP
#if defined(VERSION_US) || defined(VERSION_JP)
#define EXT_AUDIO_HEAP_SIZE 0x24400
#if defined(VERSION_US) || defined(VERSION_JP) || defined(VERSION_EU)
#define EXT_AUDIO_HEAP_SIZE 0x27400
#define EXT_AUDIO_INIT_POOL_SIZE 0x8000
#else
// EU and SH versions not yet supported for extended audio heap
#define EXT_AUDIO_HEAP_SIZE 0x24400
#define EXT_AUDIO_INIT_POOL_SIZE 0x8000
// 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
@@ -151,11 +153,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 + BETTER_REVERB_SIZE)
#define AUDIO_INIT_POOL_SIZE (0x2c00 + EXT_AUDIO_INIT_POOL_SIZE)
#define AUDIO_HEAP_SIZE (0x3AB00 + 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 + BETTER_REVERB_SIZE)
#define AUDIO_HEAP_SIZE (0x34750 + EXT_AUDIO_HEAP_SIZE + EXT_AUDIO_INIT_POOL_SIZE + BETTER_REVERB_SIZE)
#define AUDIO_INIT_POOL_SIZE (0x2500 + EXT_AUDIO_INIT_POOL_SIZE)
#endif

View File

@@ -4,6 +4,7 @@
#include "load.h"
#include "data.h"
#include "seqplayer.h"
#include "game/main.h"
#ifdef VERSION_JP
#define US_FLOAT2(x) x##.0
@@ -73,7 +74,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;
layer->noteFreqScale = layer->freqScale * seqChannel->freqScale * gConfig.audioFrequency;
layer->noteVelocity = layer->velocitySquare * channelVolume;
layer->notePan = (layer->pan * panLayerWeight) + panFromChannel;
}
@@ -402,7 +403,7 @@ s32 adsr_update(struct AdsrState *adsr) {
restart:
#endif
// fall through
case ADSR_STATE_LOOP:
adsr->delay = BSWAP16(adsr->envelope[adsr->envIndex].delay);
switch (adsr->delay) {

View File

@@ -57,11 +57,6 @@ struct SoundCharacteristics {
// Also the number of frames a discrete sound can be in the WAITING state before being deleted
#define SOUND_MAX_FRESHNESS 10
struct SequenceQueueItem {
u8 seqId;
u8 priority;
}; // size = 0x2
// data
#if defined(VERSION_EU) || defined(VERSION_SH)
// moved to bss in data.c
@@ -2355,7 +2350,10 @@ void play_music(u8 player, u16 seqArgs, u16 fadeTimer) {
}
// Abort if the queue is already full.
if (sBackgroundMusicQueueSize == MAX_BACKGROUND_MUSIC_QUEUE_SIZE) {
if (sBackgroundMusicQueueSize >= MAX_BACKGROUND_MUSIC_QUEUE_SIZE) {
#if PUPPYPRINT_DEBUG
append_puppyprint_log("Sequence queue full, aborting.");
#endif
return;
}
@@ -2686,7 +2684,7 @@ void sound_reset(u8 presetId) {
func_802ad74c(0xF2000000, 0);
#endif
#if defined(VERSION_JP) || defined(VERSION_US)
audio_reset_session(&gAudioSessionPresets[presetId]);
audio_reset_session(&gAudioSessionPresets[0], presetId);
#else
audio_reset_session_eu(presetId);
#endif

View File

@@ -18,6 +18,11 @@
#define SEQ_PLAYER_ENV 1 // Misc music like the puzzle jingle
#define SEQ_PLAYER_SFX 2 // Sound effects
struct SequenceQueueItem {
u8 seqId;
u8 priority;
}; // size = 0x2
extern s32 gAudioErrorFlags;
extern f32 gGlobalSoundSource[3];

File diff suppressed because it is too large Load Diff

View File

@@ -129,7 +129,7 @@ void *get_bank_or_seq(struct SoundMultiPool *arg0, s32 arg1, s32 id);
s32 audio_shut_down_and_reset_step(void);
void audio_reset_session(void);
#else
void audio_reset_session(struct AudioSessionSettings *preset);
void audio_reset_session(struct AudioSessionSettings *preset, s32 presetId);
#endif
void discard_bank(s32 bankId);

View File

@@ -84,11 +84,20 @@
#endif
#endif
#include "game/puppyprint.h"
#ifdef VERSION_EU
/*#if PUPPYPRINT_DEBUG
#define eu_stubbed_printf_0(msg) append_puppyprint_log(msg)
#define eu_stubbed_printf_1(msg, a) append_puppyprint_log(msg, a)
#define eu_stubbed_printf_2(msg, a, b) append_puppyprint_log(msg, a, b)
#define eu_stubbed_printf_3(msg, a, b, c) append_puppyprint_log(msg, a, b, c)
#else*/
#define eu_stubbed_printf_0(msg) stubbed_printf(msg)
#define eu_stubbed_printf_1(msg, a) stubbed_printf(msg, a)
#define eu_stubbed_printf_2(msg, a, b) stubbed_printf(msg, a, b)
#define eu_stubbed_printf_3(msg, a, b, c) stubbed_printf(msg, a, b, c)
//#endif
#else
#define eu_stubbed_printf_0(msg)
#define eu_stubbed_printf_1(msg, a)
@@ -749,6 +758,12 @@ struct ReverbSettingsEU
u16 gain;
};
#else
struct ReverbSettingsUS
{
u8 downsampleRate;
u16 windowSize;
u16 gain;
};
struct ReverbSettingsEU
{
u8 downsampleRate; // always 1

View File

@@ -847,7 +847,7 @@ void preload_sequence(u32 seqId, u8 preloadMask) {
if (preloadMask & PRELOAD_SEQUENCE) {
// @bug should be IS_SEQ_LOAD_COMPLETE
if (IS_BANK_LOAD_COMPLETE(seqId) == TRUE) {
if (IS_SEQ_LOAD_COMPLETE(seqId) == TRUE) {
eu_stubbed_printf_1("SEQ %d ALREADY CACHED\n", seqId);
sequenceData = get_bank_or_seq(&gSeqLoadedPool, 2, seqId);
} else {
@@ -929,7 +929,7 @@ void load_sequence_internal(u32 player, u32 seqId, s32 loadAsync) {
}
}
eu_stubbed_printf_1("SEQ %d ALREADY CACHED\n", seqId);
eu_stubbed_printf_1("SEQ %d ALREADY CACHED2\n", seqId);
init_sequence_player(player);
seqPlayer->scriptState.depth = 0;
seqPlayer->delay = 0;
@@ -1019,7 +1019,7 @@ void audio_init() {
eu_stubbed_printf_1("AudioHeap is %x\n", gAudioHeapSize);
for (i = 0; i < NUMAIBUFFERS; i++) {
gAiBufferLengths[i] = 0xa0;
gAiBufferLengths[i] = 10;
}
gAudioFrameCount = 0;
@@ -1037,12 +1037,13 @@ void audio_init() {
sound_init_main_pools(gAudioInitPoolSize);
bzero(&gAiBuffers, sizeof(gAiBuffers));
for (i = 0; i < NUMAIBUFFERS; i++) {
gAiBuffers[i] = soundAlloc(&gAudioInitPool, AIBUFFER_LEN);
for (j = 0; j < (s32) (AIBUFFER_LEN / sizeof(s16)); j++) {
/*for (j = 0; j < (s32) (AIBUFFER_LEN / sizeof(s16)); j++) {
gAiBuffers[i][j] = 0;
}
}*/
}
#if defined(VERSION_EU)
@@ -1050,7 +1051,7 @@ void audio_init() {
gAudioResetStatus = 1;
audio_shut_down_and_reset_step();
#else
audio_reset_session(&gAudioSessionPresets[0]);
audio_reset_session(&gAudioSessionPresets[0], 0);
#endif
// Not sure about these prints

View File

@@ -13,6 +13,7 @@
#define IS_SEQUENCE_CHANNEL_VALID(ptr) ((uintptr_t)(ptr) != (uintptr_t)&gSequenceChannelNone)
extern struct Note *gNotes;
extern u8 sAudioFirstBoot;
// Music in SM64 is played using 3 players:
// gSequencePlayers[0] is level background music

View File

@@ -45,13 +45,13 @@
/**
* 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).
*
*
* Most parameter configuration is to be done here, though BETTER_REVERB_SIZE can be adjusted in audio/synthesis.h.
*
*
* If after changing the parameters, you hear increasing noise followed by a sudden disappearance of reverb and/or scratchy audio, this indicates an s16 overflow.
* If this happens, stop immediately and reduce the parameters at fault. This becomes a ticking time bomb, and may eventually result in very loud noise if it reaches the point of s32 overflow.
* Depending on the violating parameters chosen, you probably won't ever experience s32 overflow, but s16 overflow still isn't a pleasant experience.
@@ -102,12 +102,13 @@ u8 monoReverbEmulator = FALSE;
// 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 are set to s32 instead of u8 to increase performance. Setting these to values larger than 0xFF (255) or less than 0 may cause issues and is not recommended.
s32 gReverbRevIndex = 0x5F; // Affects decay time mostly (large values can cause terrible feedback!); can be messed with at any time
s32 gReverbGainIndex = 0x9F; // Affects signal immediately retransmitted back into buffers (mid-high values yield the strongest effect); can be messed with at any time
s32 gReverbWetSignal = 0xE7; // Amount of reverb specific output in final signal (also affects decay); can be messed with at any time, also very easy to control
// These are set to defines rather than variables to increase performance. Change these to s32 if you want them to be configurable in-game. (Maybe extern them in synthesis.h)
// Setting these to values larger than 0xFF (255) or less than 0 may cause issues and is not recommended.
#define REVERB_REV_INDEX 0x60 // Affects decay time mostly (large values can cause terrible feedback!); can be messed with at any time
#define REVERB_GAIN_INDEX 0xA0 // Affects signal immediately retransmitted back into buffers (mid-high values yield the strongest effect); can be messed with at any time
#define REVERB_WET_SIGNAL 0xE8 // Amount of reverb specific output in final signal (also affects decay); can be messed with at any time, also very easy to control
// s32 gReverbDrySignal = 0x00; // Amount of original input in final signal (large values can cause terrible feedback!); declaration and uses commented out by default to improve compiler optimization
// #define REVERB_DRY_SIGNAL = 0x00; // Amount of original input in final signal (large values can cause terrible feedback!); declaration and uses commented out by default to improve compiler optimization
/* ---------------------------------------------------------------------ADVANCED REVERB PARAMETERS-------------------------------------------------------------------- */
@@ -155,8 +156,8 @@ s32 reverbMultsR[NUM_ALLPASS / 3] = {0xCF, 0x73, 0x38, 0x1F};
/* -----------------------------------------------------------------------END REVERB PARAMETERS----------------------------------------------------------------------- */
// Do not touch these values manually, unless you want potential for problems.
u32 reverbFilterCount = NUM_ALLPASS;
u32 reverbFilterCountm1 = NUM_ALLPASS - 1;
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};
@@ -212,15 +213,15 @@ static inline s16 clamp16(s32 x) {
}
static inline void reverb_samples(s16 *outSampleL, s16 *outSampleR, s32 inSampleL, s32 inSampleR) {
u32 i = 0;
s32 i = 0;
s32 j = 0;
u8 k = 0;
s32 k = 0;
s32 outTmpL = 0;
s32 outTmpR = 0;
s32 tmpCarryoverL = ((tmpBufL[reverbFilterCountm1] * gReverbRevIndex) / 256) + inSampleL;
s32 tmpCarryoverR = ((tmpBufR[reverbFilterCountm1] * gReverbRevIndex) / 256) + inSampleR;
s32 tmpCarryoverL = ((tmpBufL[reverbFilterCountm1] * REVERB_REV_INDEX) / 256) + inSampleL;
s32 tmpCarryoverR = ((tmpBufR[reverbFilterCountm1] * REVERB_REV_INDEX) / 256) + inSampleR;
for (; i < reverbFilterCount; ++i, ++j) {
for (; i != reverbFilterCount; ++i, ++j) {
tmpBufL[i] = delayBufsL[i][allpassIdxL[i]];
tmpBufR[i] = delayBufsR[i][allpassIdxR[i]];
@@ -231,15 +232,15 @@ static inline void reverb_samples(s16 *outSampleL, s16 *outSampleR, s32 inSample
delayBufsL[i][allpassIdxL[i]] = tmpCarryoverL;
delayBufsR[i][allpassIdxR[i]] = tmpCarryoverR;
if (i != reverbFilterCountm1) {
tmpCarryoverL = (tmpBufL[i] * gReverbRevIndex) / 256;
tmpCarryoverR = (tmpBufR[i] * gReverbRevIndex) / 256;
tmpCarryoverL = (tmpBufL[i] * REVERB_REV_INDEX) / 256;
tmpCarryoverR = (tmpBufR[i] * REVERB_REV_INDEX) / 256;
}
}
else {
delayBufsL[i][allpassIdxL[i]] = (tmpBufL[i] * (-gReverbGainIndex)) / 256 + tmpCarryoverL;
delayBufsR[i][allpassIdxR[i]] = (tmpBufR[i] * (-gReverbGainIndex)) / 256 + tmpCarryoverR;
tmpCarryoverL = (delayBufsL[i][allpassIdxL[i]] * gReverbGainIndex) / 256 + tmpBufL[i];
tmpCarryoverR = (delayBufsR[i][allpassIdxR[i]] * gReverbGainIndex) / 256 + tmpBufR[i];
delayBufsL[i][allpassIdxL[i]] = (tmpBufL[i] * (-REVERB_GAIN_INDEX)) / 256 + tmpCarryoverL;
delayBufsR[i][allpassIdxR[i]] = (tmpBufR[i] * (-REVERB_GAIN_INDEX)) / 256 + tmpCarryoverR;
tmpCarryoverL = (delayBufsL[i][allpassIdxL[i]] * REVERB_GAIN_INDEX) / 256 + tmpBufL[i];
tmpCarryoverR = (delayBufsR[i][allpassIdxR[i]] * REVERB_GAIN_INDEX) / 256 + tmpBufR[i];
}
if (++allpassIdxL[i] == delaysL[i])
@@ -248,18 +249,18 @@ static inline void reverb_samples(s16 *outSampleL, s16 *outSampleR, s32 inSample
allpassIdxR[i] = 0;
}
*outSampleL = clamp16((outTmpL * gReverbWetSignal/* + inSampleL * gReverbDrySignal*/) / 256);
*outSampleR = clamp16((outTmpR * gReverbWetSignal/* + inSampleR * gReverbDrySignal*/) / 256);
*outSampleL = clamp16((outTmpL * REVERB_WET_SIGNAL/* + inSampleL * REVERB_DRY_SIGNAL*/) / 256);
*outSampleR = clamp16((outTmpR * REVERB_WET_SIGNAL/* + inSampleR * REVERB_DRY_SIGNAL*/) / 256);
}
static inline void reverb_mono_sample(s16 *outSample, s32 inSample) {
u32 i = 0;
s32 i = 0;
s32 j = 0;
u8 k = 0;
s32 k = 0;
s32 outTmp = 0;
s32 tmpCarryover = ((tmpBufL[reverbFilterCountm1] * gReverbRevIndex) / 256) + inSample;
s32 tmpCarryover = ((tmpBufL[reverbFilterCountm1] * REVERB_REV_INDEX) / 256) + inSample;
for (; i < reverbFilterCount; ++i, ++j) {
for (; i != reverbFilterCount; ++i, ++j) {
tmpBufL[i] = delayBufsL[i][allpassIdxL[i]];
if (j == 2) {
@@ -267,18 +268,18 @@ static inline void reverb_mono_sample(s16 *outSample, s32 inSample) {
outTmp += (tmpBufL[i] * reverbMultsL[k++]) / 256;
delayBufsL[i][allpassIdxL[i]] = tmpCarryover;
if (i != reverbFilterCountm1)
tmpCarryover = (tmpBufL[i] * gReverbRevIndex) / 256;
tmpCarryover = (tmpBufL[i] * REVERB_REV_INDEX) / 256;
}
else {
delayBufsL[i][allpassIdxL[i]] = (tmpBufL[i] * (-gReverbGainIndex)) / 256 + tmpCarryover;
tmpCarryover = (delayBufsL[i][allpassIdxL[i]] * gReverbGainIndex) / 256 + tmpBufL[i];
delayBufsL[i][allpassIdxL[i]] = (tmpBufL[i] * (-REVERB_GAIN_INDEX)) / 256 + tmpCarryover;
tmpCarryover = (delayBufsL[i][allpassIdxL[i]] * REVERB_GAIN_INDEX) / 256 + tmpBufL[i];
}
if (++allpassIdxL[i] == delaysL[i])
allpassIdxL[i] = 0;
}
*outSample = clamp16((outTmp * gReverbWetSignal/* + inSample * gReverbDrySignal*/) / 256);
*outSample = clamp16((outTmp * REVERB_WET_SIGNAL/* + inSample * REVERB_DRY_SIGNAL*/) / 256);
}
#endif
@@ -591,11 +592,11 @@ u64 *synthesis_execute(u64 *cmdBuf, s32 *writtenCmds, s16 *aiBuf, s32 bufLen) {
#ifdef BETTER_REVERB
if (gIsConsole) {
reverbFilterCount = reverbFilterCountConsole;
reverbFilterCount = (s32) reverbFilterCountConsole;
monoReverb = monoReverbConsole;
}
else {
reverbFilterCount = reverbFilterCountEmulator;
reverbFilterCount = (s32) reverbFilterCountEmulator;
monoReverb = monoReverbEmulator;
}
if (reverbFilterCount > NUM_ALLPASS)

View File

@@ -18,7 +18,7 @@
#endif
#if defined(BETTER_REVERB) && (defined(VERSION_US) || defined(VERSION_JP))
// Size determined by ((all delaysBaselineL/R values * 8) / (2 ^ Minimum Downsample Factor)) + array pointers.
// Size determined by ((all delaysBaselineL/R values * 8) / (2 ^ Minimum Downsample Factor)) + array pointers (0x80).
// The default value can be increased or decreased in conjunction with the values in delaysBaselineL/R
#define BETTER_REVERB_SIZE 0xF200
@@ -34,10 +34,6 @@ extern u32 reverbFilterCountEmulator;
extern u8 monoReverbConsole;
extern u8 monoReverbEmulator;
extern s32 betterReverbWindowsSize;
extern s32 gReverbRevIndex;
extern s32 gReverbGainIndex;
extern s32 gReverbWetSigna;
// extern s32 gReverbDrySignal;
extern const s32 delaysBaselineL[NUM_ALLPASS];
extern const s32 delaysBaselineR[NUM_ALLPASS];

View File

@@ -51,6 +51,8 @@ OSMesg gUnknownMesgBuf[16];
OSViMode VI;
struct Config gConfig;
struct VblankHandler *gVblankHandler1 = NULL;
struct VblankHandler *gVblankHandler2 = NULL;
struct VblankHandler *gVblankHandler3 = NULL;
@@ -460,6 +462,34 @@ void change_vi(OSViMode *mode, int width, int height){
}
}
void get_audio_frequency(void)
{
switch (gConfig.tvType)
{
#if defined(VERSION_JP) || defined(VERSION_US)
case MODE_NTSC:
gConfig.audioFrequency = 1.0f;
break;
case MODE_MPAL:
gConfig.audioFrequency = 0.9915f;
break;
case MODE_PAL:
gConfig.audioFrequency = 0.9876f;
break;
#else
case MODE_NTSC:
gConfig.audioFrequency = 1.0126f;
break;
case MODE_MPAL:
gConfig.audioFrequency = 1.0086f;
break;
case MODE_PAL:
gConfig.audioFrequency = 1.0f;
break;
#endif
}
}
/**
* Initialize hardware, start main thread, then idle.
*/
@@ -471,18 +501,22 @@ void thread1_idle(UNUSED void *arg) {
// NTSC
//osViSetMode(&osViModeTable[OS_VI_NTSC_LAN1]);
VI = osViModeTable[OS_VI_NTSC_LAN1];
gConfig.tvType = MODE_NTSC;
break;
case OS_TV_MPAL:
// MPAL
//osViSetMode(&osViModeTable[OS_VI_MPAL_LAN1]);
VI = osViModeTable[OS_VI_MPAL_LAN1];
VI = osViModeTable[OS_VI_NTSC_LAN1];
gConfig.tvType = MODE_MPAL;
break;
case OS_TV_PAL:
// PAL
//osViSetMode(&osViModeTable[OS_VI_PAL_LAN1]);
VI = osViModeTable[OS_VI_PAL_LAN1];
VI = osViModeTable[OS_VI_NTSC_LAN1];
gConfig.tvType = MODE_PAL;
break;
}
get_audio_frequency();
change_vi(&VI, SCREEN_WIDTH, SCREEN_HEIGHT);
osViSetMode(&VI);
osViBlack(TRUE);

View File

@@ -10,7 +10,7 @@
#include "audio/synthesis.h"
ALIGNED8 u8 gDecompressionHeap[0xD000];
ALIGNED16 u8 gAudioHeap[DOUBLE_SIZE_ON_64_BIT(0x31200 + EXT_AUDIO_HEAP_SIZE + EXT_AUDIO_INIT_POOL_SIZE + BETTER_REVERB_SIZE)];
ALIGNED16 u8 gAudioHeap[(DOUBLE_SIZE_ON_64_BIT(AUDIO_HEAP_SIZE + 0x100))];
ALIGNED8 u8 gIdleThreadStack[0x800];
ALIGNED8 u8 gThread3Stack[0x2000];

Some files were not shown because too many files have changed in this diff Show More