From 476175e46013778d79792865700b651b0dea770c Mon Sep 17 00:00:00 2001 From: Phillip Stephens Date: Sat, 21 Oct 2023 00:40:09 -0700 Subject: [PATCH] Alignment fixes, found exact MusyX version used Former-commit-id: 66a930d6ee1bb21ae695ece190221a4540ab99b6 --- config/GM8E01_00/splits.txt | 5 +- config/GM8E01_00/symbols.txt | 23 +- configure.py | 24 +- include/musyx/assert.h | 2 +- include/musyx/hardware.h | 1 + include/musyx/musyx_priv.h | 107 +++---- include/musyx/seq.h | 2 +- include/musyx/synth.h | 9 +- include/musyx/version.h | 6 +- src/Dolphin/dummy.c | 2 + src/musyx/runtime/hw_dolphin.c | 4 +- src/musyx/runtime/s_data.c | 1 + src/musyx/runtime/seq.c | 6 +- src/musyx/runtime/snd3d.c | 442 ++++++++++++++++++++++++----- src/musyx/runtime/synth.c | 6 +- src/musyx/runtime/synth_vsamples.c | 2 +- 16 files changed, 481 insertions(+), 161 deletions(-) create mode 100644 src/Dolphin/dummy.c diff --git a/config/GM8E01_00/splits.txt b/config/GM8E01_00/splits.txt index 4f42dc62..0ad8c574 100644 --- a/config/GM8E01_00/splits.txt +++ b/config/GM8E01_00/splits.txt @@ -4302,9 +4302,12 @@ musyx/runtime/hw_aramdma.c: musyx/runtime/hw_dolphin.c: .text start:0x803B4C3C end:0x803B5134 - .bss start:0x805678A0 end:0x80569908 + .bss start:0x805678A0 end:0x80569900 .sbss start:0x805A9B70 end:0x805A9B98 +Dolphin/dummy.c: + .bss start:0x80569900 end:0x80569908 + musyx/runtime/hw_memory.c: .text start:0x803B5134 end:0x803B5188 diff --git a/config/GM8E01_00/symbols.txt b/config/GM8E01_00/symbols.txt index 35d2516d..35238c68 100644 --- a/config/GM8E01_00/symbols.txt +++ b/config/GM8E01_00/symbols.txt @@ -19067,7 +19067,7 @@ jumptable_803F4208 = .data:0x803F4208; // type:object size:0x24 scope:local jumptable_803F422C = .data:0x803F422C; // type:object size:0x24 scope:local jumptable_803F4250 = .data:0x803F4250; // type:object size:0x24 scope:local sndSintab = .data:0x803F4278; // type:object size:0x800 scope:global -dspSlave = .data:0x803F4A80; // type:object size:0x19E0 scope:global +dspSlave = .data:0x803F4A80; // type:object size:0x19E0 scope:global align:32 lens$115 = .data:0x803F6460; // type:object size:0x10 scope:local lens$115 = .data:0x803F6470; // type:object size:0x20 scope:local rsmpTab12khz = .data:0x803F6490; // type:object size:0x800 scope:local @@ -19114,7 +19114,7 @@ D54 = .data:0x803F7170; // type:object size:0x2D scope:local data:byte D35 = .data:0x803F71A0; // type:object size:0x380 scope:local @12 = .data:0x803F7520; // type:object size:0x9 scope:local data:string @13 = .data:0x803F752C; // type:object size:0x1A scope:local data:string -sGraphicsFifo = .bss:0x803F7560; // type:object size:0x60000 scope:local +sGraphicsFifo = .bss:0x803F7560; // type:object size:0x60000 scope:local align:32 sMainSpace = .bss:0x80457560; // type:object size:0x168 scope:local lbl_804576C8 = .bss:0x804576C8; // type:object size:0xD0 lbl_80457798 = .bss:0x80457798; // type:object size:0x160 @@ -19227,7 +19227,7 @@ stringize_Buffer$11 = .bss:0x804795A0; // type:object size:0x200 scope:local rs_debugger_buffer = .bss:0x804797A0; // type:object size:0x400 scope:local lbl_80479BA0 = .bss:0x80479BA0; // type:object size:0x30 sVtxDescList = .bss:0x80479BD0; // type:object size:0xF0 scope:local data:4byte -sSpareFrameBuffer = .bss:0x80479CC0; // type:object size:0x46000 scope:local +sSpareFrameBuffer = .bss:0x80479CC0; // type:object size:0x46000 scope:local align:32 kEnvBlendCTandCConCF = .bss:0x804BFCC0; // type:object size:0x50 scope:local sLoadedTextures = .bss:0x804BFD10; // type:object size:0x20 scope:local XAxis = .bss:0x804BFD30; // type:object size:0xC scope:local data:float @@ -19249,11 +19249,11 @@ sTextureProjectionTransform = .bss:0x804BFF5C; // type:object size:0x34 scope:lo lbl_804BFF90 = .bss:0x804BFF90; // type:object size:0x10 lbl_804BFFA0 = .bss:0x804BFFA0; // type:object size:0xC lbl_804BFFAC = .bss:0x804BFFAC; // type:object size:0x14 -sStaticSkinningData__8Skinning = .bss:0x804BFFC0; // type:object size:0x8000C scope:local +sStaticSkinningData__8Skinning = .bss:0x804BFFC0; // type:object size:0x8000C scope:local align:32 sSkinningBuffer__8Skinning = .bss:0x8053FFCC; // type:object size:0x28 scope:local data:byte sAllocations__8Skinning = .bss:0x8053FFF4; // type:object size:0x1C scope:local lbl_80540010 = .bss:0x80540010; // type:object size:0x10 -lbl_80540020 = .bss:0x80540020; // type:object size:0x500 +lbl_80540020 = .bss:0x80540020; // type:object size:0x500 align:32 lbl_80540520 = .bss:0x80540520; // type:object size:0x30 lbl_80540550 = .bss:0x80540550; // type:object size:0x30 lbl_80540580 = .bss:0x80540580; // type:object size:0x64 @@ -19265,9 +19265,9 @@ lbl_80540A40 = .bss:0x80540A40; // type:object size:0xC lbl_80540A4C = .bss:0x80540A4C; // type:object size:0x34 CommandList = .bss:0x80540A80; // type:object size:0x3C scope:local data:4byte ...bss.0 = .bss:0x80540A80; // type:label scope:local -AlarmForWA = .bss:0x80540AC0; // type:object size:0x28 scope:local -AlarmForTimeout = .bss:0x80540AE8; // type:object size:0x28 scope:local -AlarmForBreak = .bss:0x80540B10; // type:object size:0x28 scope:local +AlarmForWA = .bss:0x80540AC0; // type:object size:0x28 scope:local align:8 +AlarmForTimeout = .bss:0x80540AE8; // type:object size:0x28 scope:local align:8 +AlarmForBreak = .bss:0x80540B10; // type:object size:0x28 scope:local align:8 Prev = .bss:0x80540B38; // type:object size:0xC scope:local Curr = .bss:0x80540B44; // type:object size:0xC scope:local BB2 = .bss:0x80540B60; // type:object size:0x20 scope:local align:32 @@ -19287,7 +19287,7 @@ DriveBlock = .bss:0x80541220; // type:object size:0x30 scope:local __OSErrorTable = .bss:0x80541250; // type:object size:0x44 scope:global data:4byte ...bss.0 = .bss:0x80541250; // type:label scope:local lbl_80541298 = .bss:0x80541298; // type:object size:0x2E8 data:4byte -Header = .bss:0x80541580; // type:object size:0x20 scope:global +Header = .bss:0x80541580; // type:object size:0x20 scope:local align:32 Scb = .bss:0x805415A0; // type:object size:0x54 scope:local align:32 data:4byte ...bss.0 = .bss:0x805415A0; // type:label scope:local RunQueue = .bss:0x805415F8; // type:object size:0x100 scope:local data:4byte @@ -19362,7 +19362,8 @@ aramQueueLo = .bss:0x80566F90; // type:object size:0x284 scope:local aramQueueHi = .bss:0x80567214; // type:object size:0x284 scope:local aramStreamBuffers = .bss:0x80567498; // type:object size:0x400 scope:local data:4byte dsp_task = .bss:0x805678A0; // type:object size:0x50 scope:local align:8 -dram_image = .bss:0x80567900; // type:object size:0x2008 scope:local align:32 +dram_image = .bss:0x80567900; // type:object size:0x2000 scope:local align:32 +dummy = .bss:0x80569900; // type:object size:0x8 scope:global __block_for_run_callback = .bss:0x80569908; // type:object size:0x30 scope:local __block_for_prep_callback = .bss:0x80569938; // type:object size:0x30 scope:local __block_for_stream_status = .bss:0x80569968; // type:object size:0x30 scope:local @@ -22279,7 +22280,7 @@ synthFlags = .sbss:0x805A9A34; // type:object size:0x4 scope:global data:4byte synthVoice = .sbss:0x805A9A38; // type:object size:0x4 scope:global data:4byte synthMessageCallback = .sbss:0x805A9A3C; // type:object size:0x4 scope:global data:4byte synthIdleWaitActive = .sbss:0x805A9A40; // type:object size:0x1 scope:global data:byte -synthRealTime = .sbss:0x805A9A48; // type:object size:0x8 scope:global data:4byte +synthRealTime = .sbss:0x805A9A48; // type:object size:0x8 scope:global align:8 data:4byte nextPublicID = .sbss:0x805A9A50; // type:object size:0x4 scope:local data:4byte streamCallDelay = .sbss:0x805A9A54; // type:object size:0x1 scope:local data:byte streamCallCnt = .sbss:0x805A9A55; // type:object size:0x1 scope:local data:byte diff --git a/configure.py b/configure.py index fb312fec..35e1e073 100755 --- a/configure.py +++ b/configure.py @@ -239,10 +239,10 @@ def RetroLib(lib_name, objects): } -def MusyX(objects, mw_version="GC/1.3.2", debug=False, major=1, minor=5, patch=4): +def MusyX(objects, mw_version="GC/1.3.2", debug=False, major=2, minor=0, patch=0): cflags = cflags_musyx if not debug else cflags_musyx_debug return { - "lib": "MusyX", + "lib": "musyx" + "D" if config.debug else "", "mw_version": mw_version, "host": False, "cflags": [ @@ -1040,7 +1040,9 @@ config.libs = [ DolphinLib( "mtx", [ - Object(Matching, "Dolphin/mtx/mtx.c", cflags = [*cflags_base, "-fp_contract off"]), + Object( + Matching, "Dolphin/mtx/mtx.c", cflags=[*cflags_base, "-fp_contract off"] + ), Object(NonMatching, "Dolphin/mtx/mtx44vec.c"), Object(NonMatching, "Dolphin/mtx/mtx44.c"), Object(NonMatching, "Dolphin/mtx/vec.c"), @@ -1161,11 +1163,11 @@ config.libs = [ ], }, MusyX( - #debug=True, - #mw_version="GC/1.2.5", - #major=1, - #minor=5, - #patch=3, + # debug=True, + # mw_version="GC/1.2.5", + # major=2, + # minor=0, + # patch=0, objects=[ Object(Matching, "musyx/runtime/seq.c"), Object(Matching, "musyx/runtime/synth.c"), @@ -1222,6 +1224,12 @@ config.libs = [ Object(NonMatching, "musyx/txwin/txwin.c"), ], }, + DolphinLib( + "Dummy", + [ + Object(Matching, "Dolphin/dummy.c"), + ], + ), DolphinLib( "dtk", [ diff --git a/include/musyx/assert.h b/include/musyx/assert.h index 7ce9a86d..69753f5a 100644 --- a/include/musyx/assert.h +++ b/include/musyx/assert.h @@ -27,7 +27,7 @@ static inline void __SOME_ASSERT_DERP() { __SOME_ASSERT_DERP2() != 0; } #ifndef MUSY_ASSERT_MSG #ifdef _DEBUG -#if MUSY_VERSION >= MUSY_VERSION_CHECK(2, 0, 0) +#if MUSY_VERSION >= MUSY_VERSION_CHECK(2, 0, 1) #define MUSY_ASSERT_MSG(cond, msg) \ do { \ s32 tmp = 1; \ diff --git a/include/musyx/hardware.h b/include/musyx/hardware.h index e3162c1e..2700a665 100644 --- a/include/musyx/hardware.h +++ b/include/musyx/hardware.h @@ -29,6 +29,7 @@ void hwExitSampleMem(); void hwSetVirtualSampleLoopBuffer(u32 voice, void* addr, u32 len); u16 hwGetSampleID(u32 voice); u8 hwGetSampleType(u32 voice); +void hwChangeStudioMix(u8 studio, u32 isMaster); #ifdef __cplusplus } diff --git a/include/musyx/musyx_priv.h b/include/musyx/musyx_priv.h index 0f683332..ebd02a6c 100644 --- a/include/musyx/musyx_priv.h +++ b/include/musyx/musyx_priv.h @@ -532,54 +532,54 @@ typedef struct SYNTH_VOICE { #if MUSY_VERSION <= MUSY_VERSION_CHECK(1, 5, 0) void* sAddr; #endif - u32 sInfo; // offset 0x124, size 0x4 - u32 playFrq; // offset 0x128, size 0x4 - u16 curNote; // offset 0x12C, size 0x2 - s8 curDetune; // offset 0x12E, size 0x1 - u8 orgNote; // offset 0x12F, size 0x1 - u8 lastNote; // offset 0x130, size 0x1 - u8 portType; // offset 0x131, size 0x1 - u16 portLastCtrlState; // offset 0x132, size 0x2 - u32 portDuration; // offset 0x134, size 0x4 - u32 portCurPitch; // offset 0x138, size 0x4 - u32 portTime; // offset 0x13C, size 0x4 - u8 vibKeyRange; // offset 0x140, size 0x1 - u8 vibCentRange; // offset 0x141, size 0x1 - u32 vibPeriod; // offset 0x144, size 0x4 - u32 vibCurTime; // offset 0x148, size 0x4 - s32 vibCurOffset; // offset 0x14C, size 0x4 - s16 vibModAddScale; // offset 0x150, size 0x2 - u32 volume; // offset 0x154, size 0x4 - u32 orgVolume; // offset 0x158, size 0x4 - float lastVolFaderScale; // offset 0x15C, size 0x4 - u32 lastPan; // offset 0x160, size 0x4 - u32 lastSPan; // offset 0x164, size 0x4 - float treCurScale; // offset 0x168, size 0x4 - u16 treScale; // offset 0x16C, size 0x2 - u16 treModAddScale; // offset 0x16E, size 0x2 - u32 panning[2]; // offset 0x170, size 0x8 - s32 panDelta[2]; // offset 0x178, size 0x8 - u32 panTarget[2]; // offset 0x180, size 0x8 - u32 panTime[2]; // offset 0x188, size 0x8 - u8 revVolScale; // offset 0x190, size 0x1 - u8 revVolOffset; // offset 0x191, size 0x1 - u8 volTable; // offset 0x192, size 0x1 - u8 itdMode; // offset 0x193, size 0x1 - s32 envDelta; // offset 0x194, size 0x4 - u32 envTarget; // offset 0x198, size 0x4 - u32 envCurrent; // offset 0x19C, size 0x4 - u32 sweepOff[2]; // offset 0x1A0, size 0x8 - s32 sweepAdd[2]; // offset 0x1A8, size 0x8 - s32 sweepCnt[2]; // offset 0x1B0, size 0x8 - u8 sweepNum[2]; // offset 0x1B8, size 0x2 - SYNTH_LFO lfo[2]; // offset 0x1BC, size 0x18 - u8 lfoUsedByInput[2]; // offset 0x1D4, size 0x2 - u8 pbLowerKeyRange; // offset 0x1D6, size 0x1 - u8 pbUpperKeyRange; // offset 0x1D7, size 0x1 - u16 pbLast; // offset 0x1D8, size 0x2 - ADSR_VARS pitchADSR; // offset 0x1DC, size 0x28 - s16 pitchADSRRange; // offset 0x204, size 0x2 - u16 curPitch; // offset 0x206, size 0x2 + u32 sInfo; // offset 0x124, size 0x4 + u32 playFrq; // offset 0x128, size 0x4 + u16 curNote; // offset 0x12C, size 0x2 + s8 curDetune; // offset 0x12E, size 0x1 + u8 orgNote; // offset 0x12F, size 0x1 + u8 lastNote; // offset 0x130, size 0x1 + u8 portType; // offset 0x131, size 0x1 + u16 portLastCtrlState; // offset 0x132, size 0x2 + u32 portDuration; // offset 0x134, size 0x4 + u32 portCurPitch; // offset 0x138, size 0x4 + u32 portTime; // offset 0x13C, size 0x4 + u8 vibKeyRange; // offset 0x140, size 0x1 + u8 vibCentRange; // offset 0x141, size 0x1 + u32 vibPeriod; // offset 0x144, size 0x4 + u32 vibCurTime; // offset 0x148, size 0x4 + s32 vibCurOffset; // offset 0x14C, size 0x4 + s16 vibModAddScale; // offset 0x150, size 0x2 + u32 volume; // offset 0x154, size 0x4 + u32 orgVolume; // offset 0x158, size 0x4 + float lastVolFaderScale; // offset 0x15C, size 0x4 + u32 lastPan; // offset 0x160, size 0x4 + u32 lastSPan; // offset 0x164, size 0x4 + float treCurScale; // offset 0x168, size 0x4 + u16 treScale; // offset 0x16C, size 0x2 + u16 treModAddScale; // offset 0x16E, size 0x2 + u32 panning[2]; // offset 0x170, size 0x8 + s32 panDelta[2]; // offset 0x178, size 0x8 + u32 panTarget[2]; // offset 0x180, size 0x8 + u32 panTime[2]; // offset 0x188, size 0x8 + u8 revVolScale; // offset 0x190, size 0x1 + u8 revVolOffset; // offset 0x191, size 0x1 + u8 volTable; // offset 0x192, size 0x1 + u8 itdMode; // offset 0x193, size 0x1 + s32 envDelta; // offset 0x194, size 0x4 + u32 envTarget; // offset 0x198, size 0x4 + u32 envCurrent; // offset 0x19C, size 0x4 + u32 sweepOff[2]; // offset 0x1A0, size 0x8 + s32 sweepAdd[2]; // offset 0x1A8, size 0x8 + s32 sweepCnt[2]; // offset 0x1B0, size 0x8 + u8 sweepNum[2]; // offset 0x1B8, size 0x2 + SYNTH_LFO lfo[2]; // offset 0x1BC, size 0x18 + u8 lfoUsedByInput[2]; // offset 0x1D4, size 0x2 + u8 pbLowerKeyRange; // offset 0x1D6, size 0x1 + u8 pbUpperKeyRange; // offset 0x1D7, size 0x1 + u16 pbLast; // offset 0x1D8, size 0x2 + ADSR_VARS pitchADSR; // offset 0x1DC, size 0x28 + s16 pitchADSRRange; // offset 0x204, size 0x2 + u16 curPitch; // offset 0x206, size 0x2 struct setup { // total size: 0x9 u8 vol; // offset 0x0, size 0x1 @@ -903,7 +903,6 @@ void synthInit(u32 mixFrq, u32 numVoices); void synthSetBpm(u32 pbm, u8 set, u8 section); void synthFXCloneMidiSetup(SYNTH_VOICE* dest, SYNTH_VOICE* src); void synthSetMusicVolumeType(u8 vGroup, u8 type); -void synthAddJob(SYNTH_VOICE* svoice, SYNTH_JOBTYPE jobType, u32 deltaTime); extern s32 synthGlobalVariable[16]; extern u16 voicePrioSortRootListRoot; @@ -962,6 +961,14 @@ extern SYNTH_MESSAGE_CALLBACK synthMessageCallback; void salApplyMatrix(const SND_FMATRIX* a, const SND_FVECTOR* b, SND_FVECTOR* out); f32 salNormalizeVector(SND_FVECTOR* vec); void salCrossProduct(SND_FVECTOR* out, const SND_FVECTOR* a, const SND_FVECTOR* b); + +#define SAL_CROSS_PRODUCT(out, a, b) \ + do { \ + out.x = (a.y * b.z) - (a.z * b.y); \ + out.y = (a.z * b.x) - (a.x * b.z); \ + out.z = (a.x * b.y) - (a.y * b.x); \ + } while (0) + void salInvertMatrix(SND_FMATRIX* out, const SND_FMATRIX* in); /* hardware */ @@ -1059,7 +1066,7 @@ u16 inpGetExCtrl(SYNTH_VOICE* svoice, u8 ctrl); u16 inpGetMidiCtrl(u8 ctrl, u8 channel, u8 set); void inpSetMidiLastNote(u8 midi, u8 midiSet, u8 key); u16 inpGetModulation(SYNTH_VOICE* svoice); -void inpResetMidiCtrl(u8 ch, u8 set, u32 coldReset) ; +void inpResetMidiCtrl(u8 ch, u8 set, u32 coldReset); void inpResetChannelDefaults(u8 midi, u8 midiSet); u16 inpGetPitchBend(SYNTH_VOICE* svoice); u16 inpGetDoppler(SYNTH_VOICE* svoice); diff --git a/include/musyx/seq.h b/include/musyx/seq.h index 67a1308f..bed259c3 100644 --- a/include/musyx/seq.h +++ b/include/musyx/seq.h @@ -62,7 +62,7 @@ typedef struct PRG_STATE { u16 macId; // offset 0x0, size 0x2 u8 priority; // offset 0x2, size 0x1 u8 maxVoices; // offset 0x3, size 0x1 -#if MUSY_VERSION >= MUSY_VERSION_CHECK(2, 0, 0) +#if MUSY_VERSION >= MUSY_VERSION_CHECK(2, 0, 1) u8 program; // offset 0x4, size 0x1 #endif } PRG_STATE; diff --git a/include/musyx/synth.h b/include/musyx/synth.h index 88d99e37..0d93690a 100644 --- a/include/musyx/synth.h +++ b/include/musyx/synth.h @@ -26,7 +26,7 @@ bool synthSendKeyOff(SND_VOICEID vid); SND_VOICEID synthFXStart(u16 fid, u8 vol, u8 pan, u8 studio, u32 itd); void synthVolume(u8 volume, u16 time, u8 vGroup, u8 seqMode, u32 seqId); u32 synthStartSound(u16 id, u8 prio, u8 max, -#if MUSY_VERSION >= MUSY_VERSION_CHECK(2, 0, 0) +#if MUSY_VERSION >= MUSY_VERSION_CHECK(2, 0, 1) u32 sourceID, #endif u8 key, u8 vol, u8 panning, u8 midi, u8 midiSet, u8 section, u16 step, @@ -41,6 +41,13 @@ MSTEP* dataGetMacro(u16 mid); u32 voiceAllocate(u8 priority, u8 maxVoices, u16 allocId, u8 fxFlag); void voiceFree(SYNTH_VOICE* svoice); +void synthActivateStudio(u8 studio, u32 isMaster, SND_STUDIO_TYPE type); +void synthDeactivateStudio(u8 studio); +u8 synthFXGetMaxVoices(u16 fid); +void synthPauseVolume(u8 volume, u16 time, u8 vGroup); + +bool dataRemoveFX(u16 gid); + #ifdef __cplusplus } #endif diff --git a/include/musyx/version.h b/include/musyx/version.h index 69d59cfd..cc6dd4dc 100644 --- a/include/musyx/version.h +++ b/include/musyx/version.h @@ -7,15 +7,15 @@ #endif #ifndef MUSY_VERSION_MAJOR -#define MUSY_VERSION_MAJOR 1 +#define MUSY_VERSION_MAJOR 2 #endif #ifndef MUSY_VERSION_MINOR -#define MUSY_VERSION_MINOR 5 +#define MUSY_VERSION_MINOR 0 #endif #ifndef MUSY_VERSION_PATCH -#define MUSY_VERSION_PATCH 3 +#define MUSY_VERSION_PATCH 0 #endif diff --git a/src/Dolphin/dummy.c b/src/Dolphin/dummy.c new file mode 100644 index 00000000..71b7c1a0 --- /dev/null +++ b/src/Dolphin/dummy.c @@ -0,0 +1,2 @@ +#pragma force_active on +__declspec(section ".data") char dummy[4]; diff --git a/src/musyx/runtime/hw_dolphin.c b/src/musyx/runtime/hw_dolphin.c index e1759955..ba5e71d1 100644 --- a/src/musyx/runtime/hw_dolphin.c +++ b/src/musyx/runtime/hw_dolphin.c @@ -3,10 +3,8 @@ #include "dolphin/dsp.h" #include "musyx/dsp_import.h" -/* Is this actually what factor 5 did? They specify 0x2000 for the dram size, but the next TU winds - * up incorrectly aligned */ static DSPTaskInfo dsp_task ATTRIBUTE_ALIGN(8); -static u16 dram_image[4096 + 4] ATTRIBUTE_ALIGN(32); +static u16 dram_image[4096] ATTRIBUTE_ALIGN(32); static volatile u32 oldState = 0; static volatile u16 hwIrqLevel = 0; diff --git a/src/musyx/runtime/s_data.c b/src/musyx/runtime/s_data.c index edf2a275..9310a2be 100644 --- a/src/musyx/runtime/s_data.c +++ b/src/musyx/runtime/s_data.c @@ -1,5 +1,6 @@ #include "musyx/musyx_priv.h" +#include "musyx/synth.h" static GSTACK gs[128]; static s16 sp; diff --git a/src/musyx/runtime/seq.c b/src/musyx/runtime/seq.c index 156fddaf..052891b3 100644 --- a/src/musyx/runtime/seq.c +++ b/src/musyx/runtime/seq.c @@ -288,7 +288,7 @@ static void DoPrgChange(SEQ_INSTANCE* seq, u8 prg, u8 midi) { seq->prgState[midi].macId = seq->normtab[prg].macro; seq->prgState[midi].priority = seq->normtab[prg].prio; seq->prgState[midi].maxVoices = seq->normtab[prg].maxVoices; -#if MUSY_VERSION >= MUSY_VERSION_CHECK(2, 0, 0) +#if MUSY_VERSION >= MUSY_VERSION_CHECK(2, 0, 1) seq->prgState[midi].program = prg; #endif return; @@ -302,7 +302,7 @@ static void DoPrgChange(SEQ_INSTANCE* seq, u8 prg, u8 midi) { seq->prgState[midi].macId = seq->drumtab[prg].macro; seq->prgState[midi].priority = seq->drumtab[prg].prio; seq->prgState[midi].maxVoices = seq->drumtab[prg].maxVoices; -#if MUSY_VERSION >= MUSY_VERSION_CHECK(2, 0, 0) +#if MUSY_VERSION >= MUSY_VERSION_CHECK(2, 0, 1) seq->prgState[midi].program = prg; #endif } @@ -1175,7 +1175,7 @@ static SEQ_EVENT* HandleEvent(SEQ_EVENT* event, u8 secIndex, u32* loopFlag) { if ((note = AllocateNote(event->time + pe->length, secIndex)) != NULL) { if ((note->id = synthStartSound( macId, cseq->prgState[midi].priority, cseq->prgState[midi].maxVoices, -#if MUSY_VERSION >= MUSY_VERSION_CHECK(2, 0, 0) +#if MUSY_VERSION >= MUSY_VERSION_CHECK(2, 0, 1) cseq->groupID | (cseq->prgState[midi].program << 16) | ((midi == 9 ? 1 : 0) << 24), #endif diff --git a/src/musyx/runtime/snd3d.c b/src/musyx/runtime/snd3d.c index 81e88bf6..8ed4685f 100644 --- a/src/musyx/runtime/snd3d.c +++ b/src/musyx/runtime/snd3d.c @@ -15,7 +15,7 @@ static u8 s3dUseMaxVoices; static void UpdateRoomDistances() { SND_ROOM* r; // r30 SND_LISTENER* li; // r31 - float distance; // r63 + f32 distance; // r63 u32 n; // r29 SND_FVECTOR d; // r1+0x8 @@ -39,15 +39,15 @@ static void UpdateRoomDistances() { } } -static CheckRoomStatus() { +static void CheckRoomStatus() { SND_LISTENER* li; // r30 SND_EMITTER* em; // r28 SND_ROOM* r; // r27 SND_ROOM* max_room; // r29 SND_ROOM* room; // r31 SND_FVECTOR d; // r1+0x8 - float distance; // r63 - float maxDis; // r62 + f32 distance; // r63 + f32 maxDis; // r62 u32 li_num; // r25 u32 i; // r26 u32 mask; // r23 @@ -78,7 +78,89 @@ static CheckRoomStatus() { break; } } - // TODO: Finish + + mask = ~(-1 << snd_max_studios); + + if (mask != (snd_used_studios & mask)) { + for (i = 0; i < snd_max_studios; ++i) { + if (!(snd_used_studios & (1 << i))) { + break; + } + } + + snd_used_studios |= (1 << i); + room->studio = i + snd_base_studio; + } else { + maxDis = -1.f; + + for (r = s3dRoomRoot; r != NULL; r = r->next) { + if (r->studio != 0xFF && maxDis < r->distance) { + maxDis = r->distance; + max_room = r; + } + } + + if (has_listener || maxDis > distance) { + + for (em = s3dEmitterRoot; em != NULL; em = em->next) { + if (em->room == max_room) { + synthSendKeyOff(em->vid); + em->flags |= 0x80000; + em->vid = -1; + } + } + + if (max_room->deActivateReverb != NULL) { + max_room->deActivateReverb(max_room->studio); + } + + synthDeactivateStudio(max_room->studio); + room->studio = max_room->studio; + max_room->studio = 0xff; + max_room->flags = 0; + } else { + continue; + } + } + room->distance = distance; + room->curMVol = has_listener ? 0x7f0000 : 0; + + if (room->curMVol * 1.201479e-07f >= 0.5) { + synthActivateStudio(room->studio, TRUE, SND_STUDIO_TYPE_STD); + } else { + synthActivateStudio(room->studio, FALSE, SND_STUDIO_TYPE_STD); + } + + if (room->activateReverb != NULL) { + room->activateReverb(room->studio, room->user); + } + } else { + if (room->flags & 0x80000000) { + room->curMVol += 0x40000; + if (room->curMVol >= 0x7F0000) { + room->curMVol = 0x7F0000; + room->flags &= ~0x80000000; + } + + if (room->curMVol * 1.201479e-07f >= 0.5) { + synthActivateStudio(room->studio, TRUE, SND_STUDIO_TYPE_STD); + } else { + synthActivateStudio(room->studio, FALSE, SND_STUDIO_TYPE_STD); + } + } + + if ((room->flags & 0x40000000) != 0) { + room->curMVol = room->curMVol - 0x40000; + if ((int)room->curMVol >= 0) { + room->curMVol = 0; + room->flags &= ~0x40000000; + } + if (room->curMVol * 1.201479e-07f >= 0.5) { + synthActivateStudio(room->studio, TRUE, SND_STUDIO_TYPE_STD); + } else { + synthActivateStudio(room->studio, FALSE, SND_STUDIO_TYPE_STD); + } + } } } } @@ -181,8 +263,8 @@ static void RemoveListenerFromRoom(SND_ROOM* room) { } static void CalcDoorParameters(SND_DOOR* door) { - float f; // r1+0xC - float v; // r63 + f32 f; // r1+0xC + f32 v; // r63 v = door->open; f = (1.f - door->open) * door->dampen; door->input.volA = door->fxVol * v; @@ -222,8 +304,8 @@ static void CheckDoorStatus() { } } -bool sndAddDoor(SND_DOOR* door, SND_ROOM* a, SND_ROOM* b, SND_FVECTOR* pos, float dampen, - float open, unsigned char fxVol, s16 filterCoef[4], u32 flags) { +bool sndAddDoor(SND_DOOR* door, SND_ROOM* a, SND_ROOM* b, SND_FVECTOR* pos, f32 dampen, f32 open, + unsigned char fxVol, s16 filterCoef[4], u32 flags) { hwDisableIrq(); @@ -258,19 +340,94 @@ bool sndRemoveDoor(SND_DOOR* door) { return 1; } -static void CalcEmitter(struct SND_EMITTER* em, float* vol, float* doppler, float* xPan, - float* yPan, float* zPan) { - SND_LISTENER* li; // r31 - SND_FVECTOR d; // r1+0x44 - SND_FVECTOR v; // r1+0x38 - SND_FVECTOR p; // r1+0x2C - float relspeed; // r60 - float distance; // r61 - float new_distance; // r59 - float ft; // r63 - float vd; // r62 - SND_FVECTOR pan; // r1+0x20 - unsigned long n; // r29 +static void CalcEmitter(struct SND_EMITTER* em, f32* vol, f32* doppler, f32* xPan, f32* yPan, + f32* zPan) { + SND_LISTENER* li; // r31 + SND_FVECTOR d; // r1+0x44 + SND_FVECTOR v; // r1+0x38 + SND_FVECTOR p; // r1+0x2C + f32 relspeed; // r60 + f32 distance; // r61 + f32 new_distance; // r59 + f32 ft; // r63 + f32 vd; // r62 + SND_FVECTOR pan; // r1+0x20 + u32 n; // r29 + ft = 1.f / 60.f; + *vol = 0.f; + *doppler = 1.f; + + pan.x = pan.y = pan.z = 0.f; + + for (n = 0, li = s3dListenerRoot; li != NULL; li = li->next, ++n) { + d.x = em->pos.x - (li->pos.x + li->heading.x * li->volPosOff); + d.y = em->pos.y - (li->pos.y + li->heading.y * li->volPosOff); + d.z = em->pos.z - (li->pos.z + li->heading.z * li->volPosOff); + + distance = sqrtf(d.x * d.x + d.y * d.y + d.z * d.z); + + if (em->maxDis >= distance) { + vd = distance / em->maxDis; + + if (em->volPush >= 0.f) { + *vol += + li->vol * (em->minVol + (em->maxVol - em->minVol) * + (1.f - ((1.f - em->volPush) * vd + em->volPush * vd * vd))); + } else { + *vol += + li->vol * (em->minVol + (em->maxVol - em->minVol) * + (1.f - ((em->volPush + 1.f) * vd - + em->volPush * (1.f - (1.f - vd) * (1.f - vd))))); + } + + if (!(em->flags & 0x80000)) { + if ((em->flags & 0x8) || (li->flags & 1)) { + v.x = li->dir.x - em->dir.x; + v.y = li->dir.y - em->dir.y; + v.z = li->dir.z - em->dir.z; + relspeed = sqrtf(v.x * v.x + v.y * v.y + v.z * v.z); + + if (relspeed > 0.f) { + + d.x = (em->pos.x + em->dir.x * ft) - (li->pos.x + li->dir.x * ft); + d.y = (em->pos.y + em->dir.y * ft) - (li->pos.y + li->dir.y * ft); + d.z = (em->pos.z + em->dir.z * ft) - (li->pos.z + li->dir.z * ft); + + new_distance = sqrtf(d.x * d.x + d.y * d.y + d.z * d.z); + + if (new_distance < distance) { + *doppler = li->soundSpeed / (li->soundSpeed - relspeed); + } else { + *doppler = li->soundSpeed / (li->soundSpeed + relspeed); + } + } + } + + if (distance != 0.f) { + salApplyMatrix(&li->mat, &em->pos, &p); + + if (p.z <= 0.f) { + pan.z += -li->surroundDisFront < p.z ? -p.z / li->surroundDisFront : 1.f; + } else { + pan.z += li->surroundDisBack > p.z ? -p.z / li->surroundDisBack : -1.f; + } + + if (p.x != 0.f || p.y != 0.f || p.z != 0.f) { + salNormalizeVector(&p); + } + + pan.x += p.x; + pan.y -= p.y; + } + } + } + } + + if (n != 0) { + *xPan = pan.x / n; + *yPan = pan.y / n; + *zPan = pan.z / n; + } } static u8 clip127(u8 v) { @@ -287,8 +444,7 @@ static u16 clip3FFF(u32 v) { return v; } -static void SetFXParameters(SND_EMITTER* em, float vol, float xPan, float yPan, float zPan, - float doppler) { +static void SetFXParameters(SND_EMITTER* em, f32 vol, f32 xPan, f32 yPan, f32 zPan, f32 doppler) { SND_VOICEID vid; // r30 u8 i; // r28 SND_PARAMETER* pPtr; // r31 @@ -377,15 +533,15 @@ bool sndCheckEmitter(SND_EMITTER* em) { } static SND_VOICEID AddEmitter(SND_EMITTER* em_buffer, SND_FVECTOR* pos, SND_FVECTOR* dir, - float maxDis, float comp, u32 flags, u16 fxid, u32 groupid, u8 maxVol, + f32 maxDis, f32 comp, u32 flags, u16 fxid, u32 groupid, u8 maxVol, u8 minVol, SND_ROOM* room, SND_PARAMETER_INFO* para, u8 studio) { - SND_EMITTER* em; // r31 - float xPan; // r1+0x3C - float yPan; // r1+0x38 - float zPan; // r1+0x34 - float cvol; // r1+0x30 - float pitch; // r1+0x2C static SND_EMITTER tmp_em; + SND_EMITTER* em; // r31 + f32 xPan; // r1+0x3C + f32 yPan; // r1+0x38 + f32 zPan; // r1+0x34 + f32 cvol; // r1+0x30 + f32 pitch; // r1+0x2C hwDisableIrq(); em = em_buffer == NULL ? &tmp_em : em_buffer; @@ -419,11 +575,10 @@ static SND_VOICEID AddEmitter(SND_EMITTER* em_buffer, SND_FVECTOR* pos, SND_FVEC if (em->vid == -1) { hwEnableIrq(); return -1; - } else { - SetFXParameters(em, cvol, xPan, yPan, zPan, pitch); - hwEnableIrq(); - return em->vid; } + SetFXParameters(em, cvol, xPan, yPan, zPan, pitch); + hwEnableIrq(); + return em->vid; } } else { if ((em->next = s3dEmitterRoot) != NULL) { @@ -437,13 +592,14 @@ static SND_VOICEID AddEmitter(SND_EMITTER* em_buffer, SND_FVECTOR* pos, SND_FVEC em->VolLevelCnt = 0; em->flags |= 0x30000; em->maxVoices = synthFXGetMaxVoices(em->fxid); - hwEnableIrq(); - return -1; } + + hwEnableIrq(); + return -1; } -unsigned long sndAddEmitter(SND_EMITTER* em_buffer, SND_FVECTOR* pos, SND_FVECTOR* dir, - float maxDis, float comp, unsigned long flags, unsigned short fxid, +unsigned long sndAddEmitter(SND_EMITTER* em_buffer, SND_FVECTOR* pos, SND_FVECTOR* dir, f32 maxDis, + f32 comp, unsigned long flags, unsigned short fxid, unsigned char maxVol, unsigned char minVol, SND_ROOM* room) { if (sndActive) { return AddEmitter(em_buffer, pos, dir, maxDis, comp, flags, fxid, fxid | 0x80000000, maxVol, @@ -454,9 +610,9 @@ unsigned long sndAddEmitter(SND_EMITTER* em_buffer, SND_FVECTOR* pos, SND_FVECTO } unsigned long sndAddEmitterEx(struct SND_EMITTER* em_buffer, struct SND_FVECTOR* pos, - struct SND_FVECTOR* dir, float maxDis, float comp, - unsigned long flags, unsigned short fxid, unsigned short groupid, - unsigned char maxVol, unsigned char minVol, struct SND_ROOM* room) { + struct SND_FVECTOR* dir, f32 maxDis, f32 comp, unsigned long flags, + unsigned short fxid, unsigned short groupid, unsigned char maxVol, + unsigned char minVol, struct SND_ROOM* room) { if (sndActive) { return AddEmitter(em_buffer, pos, dir, maxDis, comp, flags, fxid, groupid, maxVol, minVol, room, NULL, 0); @@ -466,10 +622,9 @@ unsigned long sndAddEmitterEx(struct SND_EMITTER* em_buffer, struct SND_FVECTOR* } unsigned long sndAddEmitterPara(struct SND_EMITTER* em_buffer, struct SND_FVECTOR* pos, - struct SND_FVECTOR* dir, float maxDis, float comp, - unsigned long flags, unsigned short fxid, unsigned char maxVol, - unsigned char minVol, struct SND_ROOM* room, - struct SND_PARAMETER_INFO* para) { + struct SND_FVECTOR* dir, f32 maxDis, f32 comp, unsigned long flags, + unsigned short fxid, unsigned char maxVol, unsigned char minVol, + struct SND_ROOM* room, struct SND_PARAMETER_INFO* para) { if (sndActive) { return AddEmitter(em_buffer, pos, dir, maxDis, comp, flags, fxid, fxid | 0x80000000, maxVol, minVol, room, para, 0); @@ -478,7 +633,7 @@ unsigned long sndAddEmitterPara(struct SND_EMITTER* em_buffer, struct SND_FVECTO } unsigned long sndAddEmitterParaEx(struct SND_EMITTER* em_buffer, struct SND_FVECTOR* pos, - struct SND_FVECTOR* dir, float maxDis, float comp, + struct SND_FVECTOR* dir, f32 maxDis, f32 comp, unsigned long flags, unsigned short fxid, unsigned short groupid, unsigned char maxVol, unsigned char minVol, struct SND_ROOM* room, struct SND_PARAMETER_INFO* para) { @@ -491,7 +646,7 @@ unsigned long sndAddEmitterParaEx(struct SND_EMITTER* em_buffer, struct SND_FVEC } unsigned long sndAddEmitter2Studio(struct SND_EMITTER* em_buffer, struct SND_FVECTOR* pos, - struct SND_FVECTOR* dir, float maxDis, float comp, + struct SND_FVECTOR* dir, f32 maxDis, f32 comp, unsigned long flags, unsigned short fxid, unsigned char maxVol, unsigned char minVol, unsigned char studio) { if (sndActive) { @@ -502,7 +657,7 @@ unsigned long sndAddEmitter2Studio(struct SND_EMITTER* em_buffer, struct SND_FVE } unsigned long sndAddEmitter2StudioEx(struct SND_EMITTER* em_buffer, struct SND_FVECTOR* pos, - struct SND_FVECTOR* dir, float maxDis, float comp, + struct SND_FVECTOR* dir, f32 maxDis, f32 comp, unsigned long flags, unsigned short fxid, unsigned short groupid, unsigned char maxVol, unsigned char minVol, unsigned char studio) { @@ -514,7 +669,7 @@ unsigned long sndAddEmitter2StudioEx(struct SND_EMITTER* em_buffer, struct SND_F } unsigned long sndAddEmitter2StudioPara(struct SND_EMITTER* em_buffer, struct SND_FVECTOR* pos, - struct SND_FVECTOR* dir, float maxDis, float comp, + struct SND_FVECTOR* dir, f32 maxDis, f32 comp, unsigned long flags, unsigned short fxid, unsigned char maxVol, unsigned char minVol, unsigned char studio, struct SND_PARAMETER_INFO* para) { @@ -526,7 +681,7 @@ unsigned long sndAddEmitter2StudioPara(struct SND_EMITTER* em_buffer, struct SND } unsigned long sndAddEmitter2StudioParaEx(struct SND_EMITTER* em_buffer, struct SND_FVECTOR* pos, - struct SND_FVECTOR* dir, float maxDis, float comp, + struct SND_FVECTOR* dir, f32 maxDis, f32 comp, unsigned long flags, unsigned short fxid, unsigned short groupid, unsigned char maxVol, unsigned char minVol, unsigned char studio, @@ -643,9 +798,9 @@ unsigned long sndUpdateListener(SND_LISTENER* li, SND_FVECTOR* pos, SND_FVECTOR* } unsigned long sndAddListenerEx(SND_LISTENER* li, SND_FVECTOR* pos, SND_FVECTOR* dir, - SND_FVECTOR* heading, SND_FVECTOR* up, float front_sur, - float back_sur, float soundSpeed, float volPosOffset, - unsigned long flags, unsigned char vol, SND_ROOM* room) { + SND_FVECTOR* heading, SND_FVECTOR* up, f32 front_sur, f32 back_sur, + f32 soundSpeed, f32 volPosOffset, unsigned long flags, + unsigned char vol, SND_ROOM* room) { if (sndActive) { hwDisableIrq(); @@ -678,8 +833,8 @@ unsigned long sndAddListenerEx(SND_LISTENER* li, SND_FVECTOR* pos, SND_FVECTOR* } unsigned long sndAddListener(SND_LISTENER* li, SND_FVECTOR* pos, SND_FVECTOR* dir, - SND_FVECTOR* heading, SND_FVECTOR* up, float front_sur, float back_sur, - float soundSpeed, unsigned long flags, unsigned char vol, + SND_FVECTOR* heading, SND_FVECTOR* up, f32 front_sur, f32 back_sur, + f32 soundSpeed, unsigned long flags, unsigned char vol, SND_ROOM* room) { return sndAddListenerEx(li, pos, dir, heading, up, front_sur, back_sur, soundSpeed, 0.f, flags, vol, room); @@ -713,18 +868,18 @@ unsigned long sndRemoveListener(SND_LISTENER* li) { typedef struct START_LIST { // total size: 0x1C struct START_LIST* next; // offset 0x0, size 0x4 - float vol; // offset 0x4, size 0x4 - float xPan; // offset 0x8, size 0x4 - float yPan; // offset 0xC, size 0x4 - float zPan; // offset 0x10, size 0x4 - float pitch; // offset 0x14, size 0x4 + f32 vol; // offset 0x4, size 0x4 + f32 xPan; // offset 0x8, size 0x4 + f32 yPan; // offset 0xC, size 0x4 + f32 zPan; // offset 0x10, size 0x4 + f32 pitch; // offset 0x14, size 0x4 SND_EMITTER* em; // offset 0x18, size 0x4 } START_LIST; typedef struct RUN_LIST { // total size: 0xC struct RUN_LIST* next; // offset 0x0, size 0x4 - float vol; // offset 0x4, size 0x4 + f32 vol; // offset 0x4, size 0x4 SND_EMITTER* em; // offset 0x8, size 0x4 } RUN_LIST; @@ -749,7 +904,7 @@ void ClearStartList() { runListNum = 0; } -void AddRunningEmitter(SND_EMITTER* em, float vol) { +void AddRunningEmitter(SND_EMITTER* em, f32 vol) { long i; // r30 RUN_LIST* rl; // r29 RUN_LIST* lrl; // r28 @@ -789,8 +944,7 @@ void AddRunningEmitter(SND_EMITTER* em, float vol) { runList[runListNum++].vol = vol; } -bool AddStartingEmitter(SND_EMITTER* em, float vol, float xPan, float yPan, float zPan, - float pitch) { +bool AddStartingEmitter(SND_EMITTER* em, f32 vol, f32 xPan, f32 yPan, f32 zPan, f32 pitch) { long i; // r30 START_LIST* sl; // r29 @@ -845,17 +999,153 @@ void StartContinousEmitters() { long i; // r30 START_LIST* sl; // r29 SND_EMITTER* em; // r31 - float dv; // r63 + f32 dv; // r63 + + for (i = 0; i < startGroupNum; ++i) { + + for (sl = startGroup[i].list; sl != NULL; sl = sl->next) { + if ((startGroup[i].running != NULL) && + !(((s3dUseMaxVoices != '\0' && ((startGroup[i].id & 0x80000000) != 0)) && + (startGroup[i].numRunning < startGroup[i].list->em->maxVoices)))) { + + dv = sl->vol - (startGroup[i].running)->vol; + if (dv <= 0.08f) { + continue; + } else if (dv <= 0.15f) { + if (++sl->em->VolLevelCnt < 20) { + continue; + } + } else { + sl->em->VolLevelCnt = 0; + } + } + em = sl->em; + + if (em->room != NULL && em->room->studio == 0xFF) { + goto set_flags; + } + if ((em->vid = + synthFXStart(em->fxid, 127, 64, em->room != NULL ? em->room->studio : em->studio, + (em->flags & 0x10) != 0)) == -1) { + set_flags: + if (!(em->flags & 0x2)) { + em->flags |= 0x40000; + em->flags &= ~0x20000; + } + } else { + if (!(em->flags & 0x20)) { + em->flags |= 0x100000; + em->fade = 0.f; + } else { + em->fade = 1.f; + } + SetFXParameters(em, sl->vol, sl->xPan, sl->yPan, sl->zPan, sl->pitch); + em->flags &= ~0x20000; + ++startGroup[i].numRunning; + if (startGroup[i].running != NULL) { + startGroup[i].running = startGroup[i].running->next; + } + } + } + } } void s3dHandle() { SND_EMITTER* em; // r31 SND_EMITTER* nem; // r30 - float vol; // r1+0x18 - float xPan; // r1+0x14 - float yPan; // r1+0x10 - float zPan; // r1+0xC - float pitch; // r1+0x8 + f32 vol; // r1+0x18 + f32 xPan; // r1+0x14 + f32 yPan; // r1+0x10 + f32 zPan; // r1+0xC + f32 pitch; // r1+0x8 + + if (s3dCallCnt != 0) { + --s3dCallCnt; + return; + } + s3dCallCnt = 3; + ClearStartList(); + em = s3dEmitterRoot; + for (; em != NULL; em = nem) { + nem = em->next; + if ((em->flags & 0x40000) != 0) { + EmitterShutdown(em); + continue; + } + if ((em->flags & 0x20001) != 0) { + CalcEmitter(em, &vol, &pitch, &xPan, &yPan, &zPan); + } + + if (!(em->flags & 0x80000)) { + if (em->flags & 0x20000) { + if (vol == 0.f && em->flags & 0x4) { + em->flags |= 0x80000; + em->flags &= ~0x20000; + goto found_emitter; + } else if (vol == 0.f && em->flags & 0x40) { + EmitterShutdown(em); + continue; + } + + if (em->flags & 1) { + if (AddStartingEmitter(em, vol, xPan, yPan, zPan, pitch)) { + continue; + } + } else if (em->room == NULL || em->room->studio != 0xFF) { + if ((em->vid = + synthFXStart(em->fxid, 127, 64, em->room != NULL ? em->room->studio : em->studio, + (em->flags & 0x10) != 0)) == -1) { + + derp: + if (!(em->flags & 2)) { + em->flags |= 0x40000; + em->flags &= ~0x20000; + } else { + continue; + } + } + } else { + goto derp; + } + } else if ((em->vid = sndFXCheck(em->vid)) == -1) { + if ((em->flags & 2)) { + em->flags |= 0x20000; + } else { + em->flags |= 0x40000; + } + } + + found_emitter: + if (em->vid != -1) { + if ((em->flags & 1) != 0) { + AddRunningEmitter(em, vol); + } + if ((vol == 0.f) && ((em->flags & 4) != 0)) { + synthSendKeyOff(em->vid); + em->vid = 0xffffffff; + if ((em->flags & 2)) { + em->flags |= 0x80000; + } else { + em->flags |= 0x40000; + } + } else { + SetFXParameters(em, vol, xPan, yPan, zPan, pitch); + } + } + if ((em->flags & 0x100000) != 0) { + em->fade += .3f; + if (em->fade >= 1.f) { + em->flags &= ~0x100000; + } + } + } else if ((em->room == NULL || (em->room != NULL && em->room->studio != 0xff)) && vol != 0.f) { + em->flags &= ~0x80000; + em->flags |= 0x20000; + } + } + StartContinousEmitters(); + CheckRoomStatus(); + CheckDoorStatus(); } void sndSetup3DStudios(unsigned char first, unsigned char num) { @@ -865,11 +1155,11 @@ void sndSetup3DStudios(unsigned char first, unsigned char num) { void sndGet3DParameters(SND_3DINFO* info, SND_FVECTOR* pos, SND_FVECTOR* dir, f32 maxDis, f32 comp, u8 maxVol, u8 minVol, SND_ROOM* room) { - float xPan; // r1+0x34 - float yPan; // r1+0x30 - float zPan; // r1+0x2C - float cvol; // r1+0x28 - float pitch; // r1+0x24 + f32 xPan; // r1+0x34 + f32 yPan; // r1+0x30 + f32 zPan; // r1+0x2C + f32 cvol; // r1+0x28 + f32 pitch; // r1+0x24 static SND_EMITTER em; hwDisableIrq(); diff --git a/src/musyx/runtime/synth.c b/src/musyx/runtime/synth.c index ceed0e9c..75413c0d 100644 --- a/src/musyx/runtime/synth.c +++ b/src/musyx/runtime/synth.c @@ -31,6 +31,8 @@ u8 synthAuxBMIDI[8]; u8 synthAuxBMIDISet[8]; u8 synthTrackVolume[64]; // size: 0x40 +static void synthAddJob(SYNTH_VOICE* svoice, SYNTH_JOBTYPE jobType, u32 deltaTime); + void synthSetBpm(u32 bpm, u8 set, u8 section) { if (set == 0xFF) { set = 8; @@ -323,7 +325,7 @@ static void unblockAllAllocatedVoices(u32 vid) { #endif u32 synthStartSound(u16 id, u8 prio, u8 max, -#if MUSY_VERSION >= MUSY_VERSION_CHECK(2, 0, 0) +#if MUSY_VERSION >= MUSY_VERSION_CHECK(2, 0, 1) u32 sourceID, #endif u8 key, u8 vol, u8 panning, u8 midi, u8 midiSet, u8 section, u16 step, @@ -931,7 +933,7 @@ u32 synthFXStart(u16 fid, u8 vol, u8 pan, u8 studio, u32 itd) { } v = synthStartSound(fx->macro, fx->priority, fx->maxVoices, -#if MUSY_VERSION >= MUSY_VERSION_CHECK(2, 0, 0) +#if MUSY_VERSION >= MUSY_VERSION_CHECK(2, 0, 1) 0, // TODO #endif fx->key | 0x80, vol, pan, 0xFF, 0xFF, 0, 0, 0xFF, fx->vGroup, 0, studio, diff --git a/src/musyx/runtime/synth_vsamples.c b/src/musyx/runtime/synth_vsamples.c index 60a8836b..cfa6ffcb 100644 --- a/src/musyx/runtime/synth_vsamples.c +++ b/src/musyx/runtime/synth_vsamples.c @@ -251,7 +251,7 @@ unsigned long sndVirtualSampleAllocateBuffers(unsigned char numInstances, return 0; } -void sndVirtualSampleFreeBuffers() { +s32 sndVirtualSampleFreeBuffers() { u8 i; // r31 #line 481 MUSY_ASSERT_MSG(sndActive, "Sound system is not initialized.");