diff --git a/src/audio/data.c b/src/audio/data.c index 1621c7cd..8f13a076 100644 --- a/src/audio/data.c +++ b/src/audio/data.c @@ -10,30 +10,37 @@ extern struct OSMesgQueue OSMesgQueue3; #ifdef VERSION_EU struct ReverbSettingsEU sReverbSettings[] = { - { 0x04, 0x0c, 0x2fff }, - { 0x04, 0x0a, 0x47ff }, - { 0x04, 0x10, 0x2fff }, - { 0x04, 0x0e, 0x3fff }, - { 0x04, 0x0c, 0x4fff }, - { 0x04, 0x0a, 0x37ff } + { /*Downsample Rate*/ 0x04, /*Window Size*/ 0x0c, /*Gain*/ 0x2fff }, + { /*Downsample Rate*/ 0x04, /*Window Size*/ 0x0a, /*Gain*/ 0x47ff }, + { /*Downsample Rate*/ 0x04, /*Window Size*/ 0x10, /*Gain*/ 0x2fff }, + { /*Downsample Rate*/ 0x04, /*Window Size*/ 0x0e, /*Gain*/ 0x3fff }, + { /*Downsample Rate*/ 0x04, /*Window Size*/ 0x0c, /*Gain*/ 0x4fff }, + { /*Downsample Rate*/ 0x04, /*Window Size*/ 0x0a, /*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 } + { /*1*/ 0x00007d00, /*2*/ 0x01, /*3*/ 0x20, /*4*/ 0x01, /*5*/ 0x00, &sReverbSettings[0], /*6*/ 0x7fff, /*7*/ 0x0000, /*8*/ 0x0000E800, /*9*/ 0x0000E800, /*10*/ 0x0000E800, /*11*/ 0x0000E800 }, + { /*1*/ 0x00007d00, /*2*/ 0x01, /*3*/ 0x20, /*4*/ 0x01, /*5*/ 0x00, &sReverbSettings[1], /*6*/ 0x7fff, /*7*/ 0x0000, /*8*/ 0x0000E800, /*9*/ 0x0000E800, /*10*/ 0x0000E800, /*11*/ 0x0000E800 }, + { /*1*/ 0x00007d00, /*2*/ 0x01, /*3*/ 0x20, /*4*/ 0x01, /*5*/ 0x00, &sReverbSettings[2], /*6*/ 0x7fff, /*7*/ 0x0000, /*8*/ 0x0000E800, /*9*/ 0x0000E800, /*10*/ 0x0000E800, /*11*/ 0x0000E800 }, + { /*1*/ 0x00007d00, /*2*/ 0x01, /*3*/ 0x20, /*4*/ 0x01, /*5*/ 0x00, &sReverbSettings[3], /*6*/ 0x7fff, /*7*/ 0x0000, /*8*/ 0x0000E800, /*9*/ 0x0000E800, /*10*/ 0x0000E800, /*11*/ 0x0000E800 }, + { /*1*/ 0x00007d00, /*2*/ 0x01, /*3*/ 0x20, /*4*/ 0x01, /*5*/ 0x00, &sReverbSettings[4], /*6*/ 0x7fff, /*7*/ 0x0000, /*8*/ 0x0000E800, /*9*/ 0x0000E800, /*10*/ 0x0000E800, /*11*/ 0x0000E800 }, + { /*1*/ 0x00007d00, /*2*/ 0x01, /*3*/ 0x20, /*4*/ 0x01, /*5*/ 0x00, &sReverbSettings[0], /*6*/ 0x7fff, /*7*/ 0x0000, /*8*/ 0x0000E800, /*9*/ 0x0000E800, /*10*/ 0x0000E800, /*11*/ 0x0000E800 }, + { /*1*/ 0x00007d00, /*2*/ 0x01, /*3*/ 0x20, /*4*/ 0x01, /*5*/ 0x00, &sReverbSettings[1], /*6*/ 0x7fff, /*7*/ 0x0000, /*8*/ 0x0000E800, /*9*/ 0x0000E800, /*10*/ 0x0000E800, /*11*/ 0x0000E800 }, + { /*1*/ 0x00007d00, /*2*/ 0x01, /*3*/ 0x28, /*4*/ 0x01, /*5*/ 0x00, &sReverbSettings[5], /*6*/ 0x7fff, /*7*/ 0x0000, /*8*/ 0x0000E800, /*9*/ 0x0000E800, /*10*/ 0x0000E800, /*11*/ 0x0000E800 }, }; #endif @@ -51,33 +58,33 @@ struct AudioSessionSettingsEU gAudioSessionPresets[] = { #ifndef VERSION_EU 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 }, + { 32000, 32, 1, 0x0800, 0x2FFF, 0x7FFF, 0x0000E800, 0x0000E800, 0x0000E800, 0x0000E800 }, + { 32000, 32, 1, 0x0A00, 0x47FF, 0x7FFF, 0x0000E800, 0x0000E800, 0x0000E800, 0x0000E800 }, + { 32000, 32, 1, 0x1000, 0x2FFF, 0x7FFF, 0x0000E800, 0x0000E800, 0x0000E800, 0x0000E800 }, + { 32000, 32, 1, 0x0E00, 0x3FFF, 0x7FFF, 0x0000E800, 0x0000E800, 0x0000E800, 0x0000E800 }, + { 32000, 32, 1, 0x0C00, 0x4FFF, 0x7FFF, 0x0000E800, 0x0000E800, 0x0000E800, 0x0000E800 }, + { 32000, 32, 1, 0x0800, 0x2FFF, 0x7FFF, 0x0000E800, 0x0000E800, 0x0000E800, 0x0000E800 }, + { 32000, 32, 1, 0x0A00, 0x47FF, 0x7FFF, 0x0000E800, 0x0000E800, 0x0000E800, 0x0000E800 }, + { 32000, 40, 1, 0x0800, 0x37FF, 0x7FFF, 0x0000E800, 0x0000E800, 0x0000E800, 0x0000E800 }, #else - { 32000, 16, 1, 0x0C00, 0x2FFF, 0x7FFF, 0x7400, 0xA000, 0x7400, 0x7400 }, - { 32000, 16, 1, 0x0A00, 0x47FF, 0x7FFF, 0x7400, 0xA000, 0x7400, 0x7400 }, - { 32000, 16, 1, 0x1000, 0x2FFF, 0x7FFF, 0x7400, 0xA000, 0x7400, 0x7400 }, - { 32000, 16, 1, 0x0E00, 0x3FFF, 0x7FFF, 0x7400, 0xA000, 0x7400, 0x7400 }, - { 32000, 16, 1, 0x0C00, 0x4FFF, 0x7FFF, 0x7400, 0xA000, 0x7400, 0x7400 }, - { 32000, 16, 1, 0x0C00, 0x2FFF, 0x7FFF, 0x7400, 0xA000, 0x7400, 0x7400 }, - { 32000, 16, 1, 0x0A00, 0x47FF, 0x7FFF, 0x7400, 0xA000, 0x7400, 0x7400 }, - { 32000, 20, 1, 0x0800, 0x37FF, 0x7FFF, 0x7400, 0xA000, 0x7400, 0x7400 }, + { 32000, 32, 1, 0x0C00, 0x2FFF, 0x7FFF, 0x0000E800, 0x0000E800, 0x0000E800, 0x0000E800 }, + { 32000, 32, 1, 0x0A00, 0x47FF, 0x7FFF, 0x0000E800, 0x0000E800, 0x0000E800, 0x0000E800 }, + { 32000, 32, 1, 0x1000, 0x2FFF, 0x7FFF, 0x0000E800, 0x0000E800, 0x0000E800, 0x0000E800 }, + { 32000, 32, 1, 0x0E00, 0x3FFF, 0x7FFF, 0x0000E800, 0x0000E800, 0x0000E800, 0x0000E800 }, + { 32000, 32, 1, 0x0C00, 0x4FFF, 0x7FFF, 0x0000E800, 0x0000E800, 0x0000E800, 0x0000E800 }, + { 32000, 32, 1, 0x0C00, 0x2FFF, 0x7FFF, 0x0000E800, 0x0000E800, 0x0000E800, 0x0000E800 }, + { 32000, 32, 1, 0x0A00, 0x47FF, 0x7FFF, 0x0000E800, 0x0000E800, 0x0000E800, 0x0000E800 }, + { 32000, 40, 1, 0x0800, 0x37FF, 0x7FFF, 0x0000E800, 0x0000E800, 0x0000E800, 0x0000E800 }, #endif - { 27000, 16, 1, 0x0800, 0x2FFF, 0x7FFF, 0x7400, 0x7400, 0x7400, 0x7400 }, - { 27000, 16, 1, 0x0800, 0x3FFF, 0x7FFF, 0x7400, 0x7400, 0x7400, 0x7400 }, - { 27000, 16, 1, 0x1000, 0x2FFF, 0x7FFF, 0x7400, 0x7400, 0x7400, 0x7400 }, - { 27000, 16, 1, 0x1000, 0x3FFF, 0x7FFF, 0x7400, 0x7400, 0x7400, 0x7400 }, - { 27000, 16, 1, 0x0C00, 0x4FFF, 0x7FFF, 0x7400, 0x7400, 0x7400, 0x7400 }, - { 32000, 14, 1, 0x0800, 0x2FFF, 0x7FFF, 0x7400, 0x7400, 0x7400, 0x7400 }, - { 32000, 12, 1, 0x0800, 0x2FFF, 0x7FFF, 0x7400, 0x7400, 0x7400, 0x7400 }, - { 32000, 10, 1, 0x0800, 0x2FFF, 0x7FFF, 0x7400, 0x7400, 0x7400, 0x7400 }, - { 32000, 8, 1, 0x0800, 0x2FFF, 0x7FFF, 0x7400, 0x7400, 0x7400, 0x7400 }, + { 27000, 32, 1, 0x0800, 0x2FFF, 0x7FFF, 0x0000E800, 0x0000E800, 0x0000E800, 0x0000E800 }, + { 27000, 32, 1, 0x0800, 0x3FFF, 0x7FFF, 0x0000E800, 0x0000E800, 0x0000E800, 0x0000E800 }, + { 27000, 32, 1, 0x1000, 0x2FFF, 0x7FFF, 0x0000E800, 0x0000E800, 0x0000E800, 0x0000E800 }, + { 27000, 32, 1, 0x1000, 0x3FFF, 0x7FFF, 0x0000E800, 0x0000E800, 0x0000E800, 0x0000E800 }, + { 27000, 32, 1, 0x0C00, 0x4FFF, 0x7FFF, 0x0000E800, 0x0000E800, 0x0000E800, 0x0000E800 }, + { 32000, 28, 1, 0x0800, 0x2FFF, 0x7FFF, 0x0000E800, 0x0000E800, 0x0000E800, 0x0000E800 }, + { 32000, 24, 1, 0x0800, 0x2FFF, 0x7FFF, 0x0000E800, 0x0000E800, 0x0000E800, 0x0000E800 }, + { 32000, 20, 1, 0x0800, 0x2FFF, 0x7FFF, 0x0000E800, 0x0000E800, 0x0000E800, 0x0000E800 }, + { 32000, 16, 1, 0x0800, 0x2FFF, 0x7FFF, 0x0000E800, 0x0000E800, 0x0000E800, 0x0000E800 }, { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } }; #endif @@ -583,8 +590,8 @@ f32 gVolRampingRhs128[128] = { s16 gTatumsPerBeat = TATUMS_PER_BEAT; s8 gUnusedCount80333EE8 = UNUSED_COUNT_80333EE8; -s32 gAudioHeapSize = AUDIO_HEAP_SIZE; -s32 D_80333EF0 = D_80333EF0_VAL; +s32 gAudioHeapSize = DOUBLE_SIZE_ON_64_BIT(AUDIO_HEAP_SIZE); +s32 gAudioInitPoolSize = DOUBLE_SIZE_ON_64_BIT(AUDIO_INIT_POOL_SIZE); volatile s32 gAudioLoadLock = AUDIO_LOCK_UNINITIALIZED; #ifdef VERSION_EU diff --git a/src/audio/data.h b/src/audio/data.h index e131cae7..19deca33 100644 --- a/src/audio/data.h +++ b/src/audio/data.h @@ -63,7 +63,7 @@ extern f32 gVolRampingRhs128[128]; extern s16 gTatumsPerBeat; extern s8 gUnusedCount80333EE8; extern s32 gAudioHeapSize; -extern s32 D_80333EF0; // amount of heap designated to gAudioInitPool, 0x2500 +extern s32 gAudioInitPoolSize; // amount of heap designated to gAudioInitPool, 0x2500 extern volatile s32 gAudioLoadLock; // .bss @@ -92,7 +92,9 @@ extern s32 gRefreshRate; extern s16 *gAiBuffers[NUMAIBUFFERS]; extern s16 gAiBufferLengths[NUMAIBUFFERS]; -#ifdef VERSION_EU +#if defined(VERSION_SH) +#define AIBUFFER_LEN 0xb00 +#elif defined(VERSION_EU) #define AIBUFFER_LEN (0xa0 * 17) #else #define AIBUFFER_LEN (0xa0 * 16) @@ -103,16 +105,20 @@ extern u16 gUnused80226E98[0x10]; extern u32 gAudioRandom; -//make my life easier -#ifdef VERSION_EU +#define EXT_AUDIO_HEAP_SIZE 0x27400 +#define EXT_AUDIO_INIT_POOL_SIZE 0x02000 + +#if defined(VERSION_EU) || defined(VERSION_SH) #define UNUSED_COUNT_80333EE8 24 -#define AUDIO_HEAP_SIZE DOUBLE_SIZE_ON_64_BIT(0x2c500) -#define D_80333EF0_VAL DOUBLE_SIZE_ON_64_BIT(0x2c00) +#define AUDIO_HEAP_BASE 0x36B00 +#define AUDIO_INIT_POOL_SIZE (0x2c00 + EXT_AUDIO_INIT_POOL_SIZE) #else #define UNUSED_COUNT_80333EE8 16 -#define AUDIO_HEAP_SIZE DOUBLE_SIZE_ON_64_BIT(0x48000) -#define D_80333EF0_VAL DOUBLE_SIZE_ON_64_BIT(0x2500) +#define AUDIO_HEAP_BASE 0x31150 +#define AUDIO_INIT_POOL_SIZE (0x2500 + EXT_AUDIO_INIT_POOL_SIZE) #endif +// Normal Heap Size, Extended Heap Size, Extended Audio Init Pool Size +#define AUDIO_HEAP_SIZE (AUDIO_HEAP_BASE + EXT_AUDIO_HEAP_SIZE + EXT_AUDIO_INIT_POOL_SIZE) #endif // AUDIO_DATA_H diff --git a/src/audio/heap.c b/src/audio/heap.c index 17bf353d..d975ffac 100644 --- a/src/audio/heap.c +++ b/src/audio/heap.c @@ -198,38 +198,30 @@ void discard_sequence(s32 seqId) { } void *soundAlloc(struct SoundAllocPool *pool, u32 size) { -#ifdef VERSION_EU +#if defined(VERSION_EU) || defined(VERSION_SH) u8 *start; u8 *pos; u32 alignedSize = ALIGN16(size); start = pool->cur; if (start + alignedSize <= pool->start + pool->size) { + bzero(start, alignedSize); pool->cur += alignedSize; - for (pos = start; pos < pool->cur; pos++) { - *pos = 0; - } } else { - fprintf(stderr, "soundAlloc failed: tried to alloc %u bytes (%i free)\n", - ALIGN16(size), pool->start + pool->size - pool->cur); + fprintf(stderr, "soundAlloc failed: tried to alloc %u bytes (%i free)\n", ALIGN16(size), pool->start + pool->size - pool->cur); return NULL; } + pool->numAllocatedEntries++; return start; #else - u8 *start; - s32 last; - s32 i; + u32 alignedSize = ALIGN16(size); - if ((pool->cur + ALIGN16(size) <= pool->size + pool->start)) { - start = pool->cur; - pool->cur += ALIGN16(size); - last = pool->cur - start - 1; - for (i = 0; i <= last; i++) { - start[i] = 0; - } + u8* start = pool->cur; + if ((start + alignedSize <= pool->size + pool->start)) { + bzero(start, alignedSize); + pool->cur += alignedSize; } else { - fprintf(stderr, "soundAlloc failed: tried to alloc %u bytes (%i free)\n", - (unsigned int)ALIGN16(size), (int)(pool->start + pool->size - pool->cur)); + fprintf(stderr, "soundAlloc failed: tried to alloc %u bytes (%i free)\n", (unsigned int)ALIGN16(size), (int)(pool->start + pool->size - pool->cur)); return NULL; } return start; @@ -237,19 +229,23 @@ void *soundAlloc(struct SoundAllocPool *pool, u32 size) { } void sound_alloc_pool_init(struct SoundAllocPool *pool, void *memAddr, u32 size) { - pool->cur = pool->start = (u8 *) ALIGN16((uintptr_t) memAddr); + pool->cur = pool->start = (u8*)ALIGN16((uintptr_t)memAddr); +#ifdef VERSION_SH + pool->size = size - ((uintptr_t)memAddr & 0xf); +#else pool->size = size; - pool->unused = 0; +#endif + pool->numAllocatedEntries = 0; } void persistent_pool_clear(struct PersistentPool *persistent) { - persistent->pool.unused = 0; + persistent->pool.numAllocatedEntries = 0; persistent->pool.cur = persistent->pool.start; persistent->numEntries = 0; } void temporary_pool_clear(struct TemporaryPool *temporary) { - temporary->pool.unused = 0; + temporary->pool.numAllocatedEntries = 0; temporary->pool.cur = temporary->pool.start; temporary->nextSide = 0; temporary->entries[0].ptr = temporary->pool.start; @@ -263,7 +259,7 @@ void temporary_pool_clear(struct TemporaryPool *temporary) { } void unused_803160F8(struct SoundAllocPool *pool) { - pool->unused = 0; + pool->numAllocatedEntries = 0; pool->cur = pool->start; } diff --git a/src/audio/heap.h b/src/audio/heap.h index 7f99b9a7..2ccf53fd 100644 --- a/src/audio/heap.h +++ b/src/audio/heap.h @@ -18,7 +18,7 @@ struct SoundAllocPool u8 *start; u8 *cur; u32 size; - s32 unused; // set to 0, never read + s32 numAllocatedEntries; }; // size = 0x10 struct SeqOrBankEntry { diff --git a/src/audio/load.c b/src/audio/load.c index d4c27b74..9e49edff 100644 --- a/src/audio/load.c +++ b/src/audio/load.c @@ -76,7 +76,7 @@ struct AudioBufferParametersEU gAudioBufferParameters; s32 gAiFrequency; #endif -u32 D_80226D68; +u32 sDmaBufSize; s32 gMaxAudioCmds; s32 gMaxSimultaneousNotes; @@ -299,13 +299,13 @@ void init_sample_dma_buffers(UNUSED s32 arg0) { #endif #ifdef VERSION_EU - D_80226D68 = 0x400; + sDmaBufSize = 0x400 * 4; for (i = 0; i < gMaxSimultaneousNotes * 3 * gAudioBufferParameters.presetUnk4; i++) { #else - D_80226D68 = 144 * 9; + sDmaBufSize = (144 * 9) * 4; for (i = 0; i < gMaxSimultaneousNotes * 3; i++) { #endif - sSampleDmas[gSampleDmaNumListItems].buffer = soundAlloc(&gNotesAndBuffersPool, D_80226D68); + sSampleDmas[gSampleDmaNumListItems].buffer = soundAlloc(&gNotesAndBuffersPool, sDmaBufSize); if (sSampleDmas[gSampleDmaNumListItems].buffer == NULL) { #ifdef VERSION_EU break; @@ -317,7 +317,7 @@ void init_sample_dma_buffers(UNUSED s32 arg0) { sSampleDmas[gSampleDmaNumListItems].sizeUnused = 0; sSampleDmas[gSampleDmaNumListItems].unused2 = 0; sSampleDmas[gSampleDmaNumListItems].ttl = 0; - sSampleDmas[gSampleDmaNumListItems].bufSize = D_80226D68; + sSampleDmas[gSampleDmaNumListItems].bufSize = sDmaBufSize; gSampleDmaNumListItems++; } #ifndef VERSION_EU @@ -338,12 +338,12 @@ out1: sSampleDmaListSize1 = gSampleDmaNumListItems; #ifdef VERSION_EU - D_80226D68 = 0x200; + sDmaBufSize = 0x200 * 4; #else - D_80226D68 = 160 * 9; + sDmaBufSize = (160 * 9) * 4; #endif for (i = 0; i < gMaxSimultaneousNotes; i++) { - sSampleDmas[gSampleDmaNumListItems].buffer = soundAlloc(&gNotesAndBuffersPool, D_80226D68); + sSampleDmas[gSampleDmaNumListItems].buffer = soundAlloc(&gNotesAndBuffersPool, sDmaBufSize); if (sSampleDmas[gSampleDmaNumListItems].buffer == NULL) { #ifdef VERSION_EU break; @@ -355,7 +355,7 @@ out1: sSampleDmas[gSampleDmaNumListItems].sizeUnused = 0; sSampleDmas[gSampleDmaNumListItems].unused2 = 0; sSampleDmas[gSampleDmaNumListItems].ttl = 0; - sSampleDmas[gSampleDmaNumListItems].bufSize = D_80226D68; + sSampleDmas[gSampleDmaNumListItems].bufSize = sDmaBufSize; gSampleDmaNumListItems++; } #ifndef VERSION_EU @@ -894,7 +894,7 @@ void audio_init() { UNUSED s8 pad[32]; u8 buf[0x10]; #endif - s32 i, j, UNUSED k; + s32 i, UNUSED j, UNUSED k; UNUSED s32 lim1; // lim1 unused in EU #ifdef VERSION_EU u8 buf[0x10]; @@ -949,14 +949,11 @@ void audio_init() { gCurrAudioFrameDmaCount = 0; gSampleDmaNumListItems = 0; - sound_init_main_pools(D_80333EF0); + 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++) { - gAiBuffers[i][j] = 0; - } } #ifdef VERSION_EU @@ -1006,8 +1003,8 @@ void audio_init() { // Load bank sets for each sequence (assets/bank_sets.s) data = LOAD_DATA(gBankSetsData); - gAlBankSets = soundAlloc(&gAudioInitPool, 0x100); - audio_dma_copy_immediate((uintptr_t) data, gAlBankSets, 0x100); + gAlBankSets = soundAlloc(&gAudioInitPool, 0x800); + audio_dma_copy_immediate((uintptr_t)data, gAlBankSets, 0x800); init_sequence_players(); gAudioLoadLock = AUDIO_LOCK_NOT_LOADING; diff --git a/src/audio/load.h b/src/audio/load.h index 8e36b057..9003d7a7 100644 --- a/src/audio/load.h +++ b/src/audio/load.h @@ -38,7 +38,7 @@ extern struct CtlEntry *gCtlEntries; extern struct AudioBufferParametersEU gAudioBufferParameters; #endif extern s32 gAiFrequency; -extern u32 D_80226D68; +extern u32 sDmaBufSize; extern s32 gMaxAudioCmds; extern s32 gMaxSimultaneousNotes; diff --git a/src/buffers/buffers.c b/src/buffers/buffers.c index ddcd0281..d993caaa 100644 --- a/src/buffers/buffers.c +++ b/src/buffers/buffers.c @@ -4,7 +4,11 @@ #include "audio/data.h" ALIGNED8 u8 gDecompressionHeap[0xD000]; -ALIGNED16 u8 gAudioHeap[AUDIO_HEAP_SIZE]; +#if defined(VERSION_EU) || defined(VERSION_SH) +ALIGNED16 u8 gAudioHeap[DOUBLE_SIZE_ON_64_BIT(AUDIO_HEAP_SIZE) - 0x3800]; +#else +ALIGNED16 u8 gAudioHeap[DOUBLE_SIZE_ON_64_BIT(AUDIO_HEAP_SIZE)]; +#endif ALIGNED8 u8 gIdleThreadStack[0x800]; ALIGNED8 u8 gThread3Stack[0x2000]; diff --git a/src/buffers/buffers.h b/src/buffers/buffers.h index 9d1d692b..913b30f2 100644 --- a/src/buffers/buffers.h +++ b/src/buffers/buffers.h @@ -3,6 +3,7 @@ #include +#include "audio/data.h" #include "game/save_file.h" #include "game/game_init.h" diff --git a/src/pc/network/packets/packet_read_write.c b/src/pc/network/packets/packet_read_write.c index f2ef3595..18d3e9c9 100644 --- a/src/pc/network/packets/packet_read_write.c +++ b/src/pc/network/packets/packet_read_write.c @@ -97,6 +97,9 @@ void packet_duplicate(struct Packet* srcPacket, struct Packet* dstPacket) { dstPacket->levelNum = srcPacket->levelNum; dstPacket->areaIndex = srcPacket->areaIndex; +#ifdef DEBUG + assert(srcPacket->dataLength <= PACKET_LENGTH); +#endif memcpy(&dstPacket->buffer[0], &srcPacket->buffer[0], srcPacket->dataLength); if (dstPacket->reliable) { @@ -127,6 +130,10 @@ void packet_set_destination(struct Packet* packet, u8 destGlobalId) { void packet_write(struct Packet* packet, void* data, u16 length) { if (data == NULL) { packet->error = true; return; } +#ifdef DEBUG + assert(packet->dataLength + length <= PACKET_LENGTH); +#endif + if (packet->cursor + length >= PACKET_LENGTH) { SOFT_ASSERT(packet->cursor + length < PACKET_LENGTH); packet->writeError = true; @@ -177,6 +184,13 @@ u8 packet_initial_read(struct Packet* packet) { void packet_read(struct Packet* packet, void* data, u16 length) { if (data == NULL) { packet->error = true; return; } u16 cursor = packet->cursor; + +#ifdef DEBUG + // Make sure our read doesn't read past the buffer + // and that it doesn't read past our datas end. + assert(PACKET_LENGTH >= cursor + length); +#endif + memcpy(data, &packet->buffer[cursor], length); packet->cursor = cursor + length; }