From 288b37a1b39ccdea4f4c857d16776d38cf48f48c Mon Sep 17 00:00:00 2001 From: fgsfds Date: Wed, 9 Aug 2023 21:17:09 +0200 Subject: [PATCH] port: fix aEnvMixer; fix some misc warnings hopefully that was the last of the big audio issues --- include/PR/libaudio.h | 4 ++++ include/PR/os_convert.h | 6 +++++- port/include/mixer.h | 16 ++++++++-------- port/src/main.c | 1 + port/src/mixer.c | 40 +++++++++++++++++++++++----------------- port/src/pdmain.c | 14 ++------------ src/lib/audiodma.c | 13 +++++++++++++ src/lib/mp3/util_c.c | 8 ++++---- 8 files changed, 60 insertions(+), 42 deletions(-) diff --git a/include/PR/libaudio.h b/include/PR/libaudio.h index 428e9db0b..51c571ef1 100644 --- a/include/PR/libaudio.h +++ b/include/PR/libaudio.h @@ -120,7 +120,11 @@ typedef struct ALLink_s { void alUnlink(ALLink *element); void alLink(ALLink *element, ALLink *after); +#ifdef PLATFORM_N64 typedef s32 (*ALDMAproc)(s32 addr, s32 len, void *state); +#else +typedef uintptr_t (*ALDMAproc)(uintptr_t addr, s32 len, void *state); +#endif typedef ALDMAproc (*ALDMANew)(void *state); void alCopy(void *src, void *dest, s32 len); diff --git a/include/PR/os_convert.h b/include/PR/os_convert.h index 41f5880a9..c77f139c8 100644 --- a/include/PR/os_convert.h +++ b/include/PR/os_convert.h @@ -97,9 +97,13 @@ extern "C" { /* Address translation routines and macros */ +#ifdef PLATFORM_N64 extern u32 osVirtualToPhysical(void *); extern void * osPhysicalToVirtual(u32); - +#else +extern uintptr_t osVirtualToPhysical(void *); +extern void * osPhysicalToVirtual(uintptr_t); +#endif #endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ diff --git a/port/include/mixer.h b/port/include/mixer.h index 23bd3f9fe..d8cb061f2 100644 --- a/port/include/mixer.h +++ b/port/include/mixer.h @@ -38,18 +38,18 @@ void aPlayMP3Impl(const void *mp3file, u32 mp3size, void *out); #define aDisable(pkt, o, b, c) aDisableImpl(o, b, c) #define aClearBuffer(pkt, d, c) aClearBufferImpl(d, c) -#define aLoadBuffer(pkt, c, d, s) aLoadBufferImpl(s, d, c) -#define aSaveBuffer(pkt, c, s, d) aSaveBufferImpl(s, d, c) -#define aLoadADPCM(pkt, c, d) aLoadADPCMImpl(c, d) +#define aLoadBuffer(pkt, c, d, s) aLoadBufferImpl((void *)(s), d, c) +#define aSaveBuffer(pkt, c, s, d) aSaveBufferImpl(s, (int16_t *)(d), c) +#define aLoadADPCM(pkt, c, d) aLoadADPCMImpl(c, (int16_t *)(d)) #define aDMEMMove(pkt, i, o, c) aDMEMMoveImpl(i, o, c) -#define aSetLoop(pkt, a) aSetLoopImpl(a) -#define aADPCMdec(pkt, s, f, c, i, o) aADPCMdecImpl(f, s, c, i, o) -#define aResample(pkt, s, f, p, i, o) aResampleImpl(f, p, s, i, o) +#define aSetLoop(pkt, a) aSetLoopImpl((void *)(a)) +#define aADPCMdec(pkt, s, f, c, i, o) aADPCMdecImpl(f, (void *)(s), c, i, o) +#define aResample(pkt, s, f, p, i, o) aResampleImpl(f, p, (void *)(s), i, o) #define aInterleave(pkt) aInterleaveImpl() #define aMix(pkt, f, g, i, o) aMixImpl(f, g, i, o) -#define aEnvMixer(pkt, f, t, s) aEnvMixerImpl(f, s, t) +#define aEnvMixer(pkt, f, t, s) aEnvMixerImpl(f, (void *)(s), t) #define aSetVolume(pkt, f, v, t, r) aSetVolumeImpl(f, v, t, r) #define aPoleFilter(pkt, f, g, t, s) aPoleFilterImpl(f, g, t, s) -#define aPlayMP3(pkt, a, b, c) aPlayMP3Impl(a, b, c) +#define aPlayMP3(pkt, a, b, c) aPlayMP3Impl((void *)(a), b, (void *)(c)) #endif diff --git a/port/src/main.c b/port/src/main.c index f82201c70..3b56fd02d 100644 --- a/port/src/main.c +++ b/port/src/main.c @@ -8,6 +8,7 @@ #include "bss.h" #include "video.h" +#include "audio.h" #include "input.h" #include "fs.h" #include "romdata.h" diff --git a/port/src/mixer.c b/port/src/mixer.c index cd29ebdb8..653499735 100644 --- a/port/src/mixer.c +++ b/port/src/mixer.c @@ -511,6 +511,14 @@ void aEnvMixerImpl(uint8_t flags, ENVMIX_STATE state, int16_t rvol) { int16_t *wet[2] = {BUF_S16(OFS_AUX_L), BUF_S16(OFS_AUX_R)}; int nsamples = NUM_SAMPLES; + struct { + int32_t t[2]; + int32_t rate[2]; + int16_t tgt[2]; + int16_t voldry; + int16_t volwet; + } *savedstate = (void *)state; + rspa.vol[1] = rvol; // why the fuck is this here? // naudio uses a linear envelope @@ -521,21 +529,20 @@ void aEnvMixerImpl(uint8_t flags, ENVMIX_STATE state, int16_t rvol) { if (flags & A_INIT) { for (int i = 0; i < 2; ++i) { - t[i] = rspa.vol[i] << 16; - tgt[i] = rspa.target[i] << 16; + t[i] = rspa.vol[i] << 16; rate[i] = rspa.rate[i] >> 3; + tgt[i] = rspa.target[i] << 16; } voldry = rspa.vol_dry; volwet = rspa.vol_wet; } else { for (int i = 0; i < 2; ++i) { - int16_t *base = state + i * 4; - t[i] = base[0]; - tgt[i] = base[1] << 16; - rate[i] = *(int32_t *)&base[2]; + t[i] = savedstate->t[i]; + rate[i] = savedstate->rate[i]; + tgt[i] = savedstate->tgt[i] << 16; } - voldry = state[8]; - volwet = state[9]; + voldry = savedstate->voldry; + volwet = savedstate->volwet; } #ifdef PLATFORM_BIG_ENDIAN @@ -574,16 +581,15 @@ void aEnvMixerImpl(uint8_t flags, ENVMIX_STATE state, int16_t rvol) { } } - for (int i = 0; i < 2; ++i) { - int16_t *base = state + i * 4; - base[0] = t[i]; - base[1] = tgt[i] >> 16; - *(int32_t *)&base[2] = rate[i]; - } - state[8] = voldry; - state[9] = volwet; - #undef XOR + + for (int i = 0; i < 2; ++i) { + savedstate->t[i] = t[i]; + savedstate->rate[i] = rate[i]; + savedstate->tgt[i] = tgt[i] >> 16; + } + savedstate->voldry = voldry; + savedstate->volwet = volwet; } // flags is always 0 in PD diff --git a/port/src/pdmain.c b/port/src/pdmain.c index 1b95d1a80..82160ff77 100644 --- a/port/src/pdmain.c +++ b/port/src/pdmain.c @@ -1,5 +1,4 @@ #include -#include #include #include @@ -77,7 +76,6 @@ extern u8 *g_MempHeap; extern u32 g_MempHeapSize; void rngSetSeed(u32 seed); -void schedFrame(OSSched *sc); bool var8005d9b0 = false; s32 g_StageNum = STAGE_TITLE; @@ -207,14 +205,6 @@ Gfx var8005dcc8[] = { gsSPEndDisplayList(), }; -Gfx var8005dcf0[] = { - gsSPSegment(0x00, 0x00000000), - gsSPDisplayList(&var800613a0), - gsSPDisplayList(&var80061380), - gsDPFullSync(), - gsSPEndDisplayList(), -}; - s32 g_MainIsBooting = 1; void mainInit(void) @@ -522,8 +512,8 @@ void mainLoop(void) void mainTick(void) { - Gfx *gdl; - Gfx *gdlstart; + Gfx *gdl = NULL; + Gfx *gdlstart = NULL; OSScMsg msg = {OS_SC_DONE_MSG}; s32 i; diff --git a/src/lib/audiodma.c b/src/lib/audiodma.c index 53da7b133..418373279 100644 --- a/src/lib/audiodma.c +++ b/src/lib/audiodma.c @@ -10,7 +10,11 @@ struct admaitem { ALLink node; +#ifdef PLATFORM_N64 s32 startaddr; +#else + uintptr_t startaddr; +#endif s32 lastframe; u8 *ptr; }; @@ -46,14 +50,23 @@ void admaInit(void) * that this buffer was last used in this frame. This is important for the * admaBeginFrame routine. */ +#ifdef PLATFORM_N64 s32 admaExec(s32 offset, s32 len, void *state) +#else +uintptr_t admaExec(uintptr_t offset, s32 len, void *state) +#endif { void *foundbuffer; s32 delta; struct admaitem *item = g_AdmaState.firstused; struct admaitem *lastitem = NULL; +#ifdef PLATFORM_N64 s32 end = offset + len; s32 buffend; +#else + uintptr_t end = offset + len; + uintptr_t buffend; +#endif // Check to see if a buffer already contains the sample while (item) { diff --git a/src/lib/mp3/util_c.c b/src/lib/mp3/util_c.c index 08fc6d769..514ba6b68 100644 --- a/src/lib/mp3/util_c.c +++ b/src/lib/mp3/util_c.c @@ -77,9 +77,9 @@ s32 mp3util000462f8(u8 *arg0, s32 *arg1, s32 arg2, s32 arg3, s32 arg4, s32 arg5, } else { cVar1 = *(s8 *)piVar4; uVar3 = uVar5 & 7; - piVar4 = (s32 *)((u8 *)piVar4 + (uVar3 + 1 >> 3)); + piVar4 = (s32 *)((u8 *)piVar4 + ((uVar3 + 1) >> 3)); uVar5 = uVar5 + 1; - if (((u32)cVar1 >> (7 - uVar3 & 0x1f) & 1) == 0) { + if (((u32)cVar1 >> ((7 - uVar3) & 0x1f) & 1) == 0) { *puVar7 = 0; } else { *puVar7 = 1; @@ -97,9 +97,9 @@ s32 mp3util000462f8(u8 *arg0, s32 *arg1, s32 arg2, s32 arg3, s32 arg4, s32 arg5, } else { cVar1 = *(s8 *)piVar4; uVar2 = uVar5 & 7; - piVar4 = (s32 *)((u8 *)piVar4 + (uVar2 + 1 >> 3)); + piVar4 = (s32 *)((u8 *)piVar4 + ((uVar2 + 1) >> 3)); uVar5 = uVar5 + 1; - if (((u32)cVar1 >> (7 - uVar2 & 0x1f) & 1) == 0) { + if (((u32)cVar1 >> ((7 - uVar2) & 0x1f) & 1) == 0) { puVar7[1] = 0; } else { puVar7[1] = 1;