From 54971c1dcb50f04875b07e49e832e2671761a5be Mon Sep 17 00:00:00 2001 From: Phillip Stephens Date: Fri, 13 Oct 2023 10:26:03 -0700 Subject: [PATCH] Link snd_synthapi Former-commit-id: 20cb8ee9ecdd41d276fdb41d2473659b08dd8fcf --- config/GM8E01_00/symbols.txt | 51 +++++---- configure.py | 16 +-- src/musyx/runtime/synthdata.c | 177 ++++++++++++++++++++++---------- src/musyx/runtime/synthmacros.c | 10 ++ 4 files changed, 168 insertions(+), 86 deletions(-) diff --git a/config/GM8E01_00/symbols.txt b/config/GM8E01_00/symbols.txt index dca7ffd2..b0a1a7a8 100644 --- a/config/GM8E01_00/symbols.txt +++ b/config/GM8E01_00/symbols.txt @@ -19325,16 +19325,16 @@ synthGlobalVariable = .bss:0x80550AB4; // type:object size:0x40 scope:global dat inpAuxB = .bss:0x80550AF4; // type:object size:0x480 scope:global inpAuxA = .bss:0x80550F74; // type:object size:0x480 scope:global streamInfo = .bss:0x805513F8; // type:object size:0x1900 scope:global -dataKeymapTab = .bss:0x80552CF8; // type:object size:0x800 scope:global -dataLayerTab = .bss:0x805534F8; // type:object size:0xC00 scope:global -dataCurveTab = .bss:0x805540F8; // type:object size:0x4000 scope:global -dataSmpSDirs = .bss:0x805580F8; // type:object size:0x600 scope:global data:4byte -dataFXGroups = .bss:0x805586F8; // type:object size:0x400 scope:global data:2byte -dataMacMaintab = .bss:0x80558AF8; // type:object size:0x800 scope:global data:2byte -dataMacSubTabmem = .bss:0x805592F8; // type:object size:0x4000 scope:global -key$731 = .bss:0x8055D2F8; // type:object size:0x20 scope:global data:2byte -key$493 = .bss:0x8055D318; // type:object size:0xC scope:global -key$487 = .bss:0x8055D324; // type:object size:0xC scope:global data:2byte +dataKeymapTab = .bss:0x80552CF8; // type:object size:0x800 scope:local +dataLayerTab = .bss:0x805534F8; // type:object size:0xC00 scope:local +dataCurveTab = .bss:0x805540F8; // type:object size:0x4000 scope:local +dataSmpSDirs = .bss:0x805580F8; // type:object size:0x600 scope:local data:4byte +dataFXGroups = .bss:0x805586F8; // type:object size:0x400 scope:local data:2byte +dataMacMainTab = .bss:0x80558AF8; // type:object size:0x800 scope:local data:2byte +dataMacSubTabmem = .bss:0x805592F8; // type:object size:0x4000 scope:local +key$284 = .bss:0x8055D2F8; // type:object size:0x20 scope:local data:2byte +key$329 = .bss:0x8055D318; // type:object size:0xC scope:local +key$341 = .bss:0x8055D324; // type:object size:0xA scope:local data:2byte newsmp$473 = .bss:0x8055D330; // type:object size:0x20 scope:global data:4byte vidList = .bss:0x8055D350; // type:object size:0x800 scope:local data:4byte voicePrioSortVoices = .bss:0x8055DB50; // type:object size:0x100 scope:global @@ -19362,7 +19362,7 @@ 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 __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 @@ -22282,27 +22282,26 @@ synthRealTime = .sbss:0x805A9A48; // type:object size:0x8 scope:global data:4byt 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 -result$494 = .sbss:0x805A9A58; // type:object size:0x4 scope:local data:4byte -result$768 = .sbss:0x805A9A5C; // type:object size:0x4 scope:local data:4byte -key$767 = .sbss:0x805A9A60; // type:object size:0x8 scope:local -result$760 = .sbss:0x805A9A68; // type:object size:0x4 scope:local data:4byte -key$759 = .sbss:0x805A9A6C; // type:object size:0x8 scope:local -sheader$733 = .sbss:0x805A9A74; // type:object size:0x4 scope:local data:4byte -result$732 = .sbss:0x805A9A78; // type:object size:0x4 scope:local data:4byte -result$714 = .sbss:0x805A9A7C; // type:object size:0x4 scope:local data:4byte -key$713 = .sbss:0x805A9A80; // type:object size:0x8 scope:local -main$712 = .sbss:0x805A9A88; // type:object size:0x4 scope:local data:4byte -base$711 = .sbss:0x805A9A8C; // type:object size:0x4 scope:local data:4byte +result$330 = .sbss:0x805A9A58; // type:object size:0x4 scope:local data:4byte +result$318 = .sbss:0x805A9A5C; // type:object size:0x4 scope:local data:4byte +key$317 = .sbss:0x805A9A60; // type:object size:0x8 scope:local +result$310 = .sbss:0x805A9A68; // type:object size:0x4 scope:local data:4byte +key$309 = .sbss:0x805A9A6C; // type:object size:0x8 scope:local +sheader$286 = .sbss:0x805A9A74; // type:object size:0x4 scope:local data:4byte +result$285 = .sbss:0x805A9A78; // type:object size:0x4 scope:local data:4byte +result$269 = .sbss:0x805A9A7C; // type:object size:0x4 scope:local data:4byte +key$268 = .sbss:0x805A9A80; // type:object size:0x8 scope:local +main$267 = .sbss:0x805A9A88; // type:object size:0x4 scope:local data:4byte +base$266 = .sbss:0x805A9A8C; // type:object size:0x4 scope:local data:4byte dataFXGroupNum = .sbss:0x805A9A90; // type:object size:0x2 scope:local data:2byte dataMacTotal = .sbss:0x805A9A92; // type:object size:0x2 scope:local data:2byte dataLayerNum = .sbss:0x805A9A94; // type:object size:0x2 scope:local data:2byte dataKeymapNum = .sbss:0x805A9A96; // type:object size:0x2 scope:local data:2byte dataCurveNum = .sbss:0x805A9A98; // type:object size:0x2 scope:local data:2byte -dataSmpSDirNum = .sbss:0x805A9A9A; // type:object size:0x6 scope:local data:2byte +dataSmpSDirNum = .sbss:0x805A9A9A; // type:object size:0x2 scope:local data:2byte cstep$1643 = .sbss:0x805A9AA0; // type:object size:0x8 scope:local data:4byte -macRealTime = .sbss:0x805A9AA8; // type:object size:0x4 scope:local data:4byte -lbl_805A9AAC = .sbss:0x805A9AAC; // type:object size:0x4 data:4byte -macTimeQueueRoot = .sbss:0x805A9AB0; // type:object size:0x4 scope:local data:4byte +macRealTime = .sbss:0x805A9AA8; // type:object size:0x8 scope:local data:8byte +macTimeQueueRoot = .sbss:0x805A9AB0; // type:object size:0x4 scope:local macActiveMacroRoot = .sbss:0x805A9AB4; // type:object size:0x4 scope:local data:4byte DebugMacroSteps = .sbss:0x805A9AB8; // type:object size:0x8 scope:local data:byte vidFree = .sbss:0x805A9AC0; // type:object size:0x4 scope:local data:4byte diff --git a/configure.py b/configure.py index 70f8919d..66b0744d 100755 --- a/configure.py +++ b/configure.py @@ -200,7 +200,9 @@ cflags_musyx_debug = [ "-nosyspath", "-i include", "-i libc", - "-g -sym on -D_DEBUG=1", + "-g", + "-sym on", + "-D_DEBUG=1", "-enum int", "-D_MATH_INLINE=static", ] @@ -1156,16 +1158,16 @@ 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=1, + #minor=5, + #patch=3, objects=[ Object(Matching, "musyx/runtime/seq.c"), Object(Matching, "musyx/runtime/synth.c"), Object(Matching, "musyx/runtime/seq_api.c"), - Object(NonMatching, "musyx/runtime/snd_synthapi.c"), + Object(Matching, "musyx/runtime/snd_synthapi.c"), Object(NonMatching, "musyx/runtime/stream.c"), Object(NonMatching, "musyx/runtime/synthdata.c"), Object(NonMatching, "musyx/runtime/synthmacros.c"), diff --git a/src/musyx/runtime/synthdata.c b/src/musyx/runtime/synthdata.c index d5a894a7..f5e267d6 100644 --- a/src/musyx/runtime/synthdata.c +++ b/src/musyx/runtime/synthdata.c @@ -1,21 +1,20 @@ - #include "musyx/musyx_priv.h" -static u16 dataSmpSDirNum = 0; static SDIR_TAB dataSmpSDirs[128]; -static u16 dataCurveNum = 0; +static u16 dataSmpSDirNum; static DATA_TAB dataCurveTab[2048]; -static u16 dataKeymapNum = 0; +static u16 dataCurveNum; static DATA_TAB dataKeymapTab[256]; -static u16 dataLayerNum = 0; +static u16 dataKeymapNum; static LAYER_TAB dataLayerTab[256]; -static u16 dataMacTotal = 0; +static u16 dataLayerNum; static MAC_MAINTAB dataMacMainTab[512]; static MAC_SUBTAB dataMacSubTabmem[2048]; -static u16 dataFXGroupNum = 0; +static u16 dataMacTotal; static FX_GROUP dataFXGroups[128]; +static u16 dataFXGroupNum; -u32 dataInsertKeymap(u16 cid, void* keymapdata) { +bool dataInsertKeymap(u16 cid, void* keymapdata) { long i; // r31 long j; // r29 hwDisableIrq(); @@ -32,19 +31,15 @@ u32 dataInsertKeymap(u16 cid, void* keymapdata) { for (j = dataKeymapNum - 1; j >= i; --j) dataKeymapTab[j + 1] = dataKeymapTab[j]; ++dataKeymapNum; - } else { - hwEnableIrq(); return 0; } } else { - dataKeymapTab[i].refCount++; hwEnableIrq(); return 0; } - } else if (dataKeymapNum < 256) { ++dataKeymapNum; } else { @@ -62,7 +57,7 @@ u32 dataInsertKeymap(u16 cid, void* keymapdata) { return 1; } -unsigned long dataRemoveKeymap(unsigned short sid) { +bool dataRemoveKeymap(u16 sid) { long i; // r31 long j; // r30 @@ -70,17 +65,21 @@ unsigned long dataRemoveKeymap(unsigned short sid) { for (i = 0; i < dataKeymapNum && dataKeymapTab[i].id != sid; ++i) ; - if (i != dataKeymapNum) { - for (j = i + 1; j < dataKeymapNum; j++, i++) { - dataKeymapTab[i] = dataKeymapTab[j]; + if (i != dataKeymapNum && --dataKeymapTab[i].refCount == 0) { + for (j = i + 1; j < dataKeymapNum; j++) { + dataKeymapTab[j - 1] = dataKeymapTab[j]; } + + --dataKeymapNum; + hwEnableIrq(); + return 1; } hwEnableIrq(); - return 1; + return 0; } -unsigned long dataInsertLayer(unsigned short cid, void* layerdata, unsigned short size) { +bool dataInsertLayer(u16 cid, void* layerdata, u16 size) { long i; // r31 long j; // r29 @@ -129,12 +128,29 @@ unsigned long dataInsertLayer(unsigned short cid, void* layerdata, unsigned shor return 1; } -unsigned long dataRemoveLayer(unsigned short sid) { +bool dataRemoveLayer(u16 sid) { long i; // r31 long j; // r30 + + hwDisableIrq(); + for (i = 0; i < dataLayerNum && dataLayerTab[i].id != sid; ++i) + ; + + if (i != dataLayerNum && --dataLayerTab[i].refCount == 0) { + for (j = i + 1; j < dataLayerNum; j++) { + dataLayerTab[j - 1] = dataLayerTab[j]; + } + + --dataLayerNum; + hwEnableIrq(); + return 1; + } + + hwEnableIrq(); + return 0; } -unsigned long dataInsertCurve(unsigned short cid, void* curvedata) { +bool dataInsertCurve(u16 cid, void* curvedata) { long i; // r31 long j; // r29 @@ -180,64 +196,121 @@ unsigned long dataInsertCurve(unsigned short cid, void* curvedata) { return 1; } -unsigned long dataRemoveCurve(unsigned short sid) { +bool dataRemoveCurve(u16 sid) { long i; // r31 long j; // r30 + + hwDisableIrq(); + for (i = 0; i < dataCurveNum && dataCurveTab[i].id != sid; ++i) + ; + + if (i != dataCurveNum && --dataCurveTab[i].refCount == 0) { + for (j = i + 1; j < dataCurveNum; j++) { + dataCurveTab[j - 1] = dataCurveTab[j]; + } + + --dataCurveNum; + hwEnableIrq(); + return 1; + } + + hwEnableIrq(); + return 0; } -unsigned long dataInsertSDir(struct SDIR_DATA* sdir, void* smp_data) { - long i; // r31 - struct SDIR_DATA* s; // r25 - unsigned short n; // r27 - unsigned short j; // r29 - unsigned short k; // r26 +bool dataInsertSDir(SDIR_DATA* sdir, void* smp_data) { + s32 i; // r31 + SDIR_DATA* s; // r25 + u16 n; // r27 + u16 j; // r29 + u16 k; // r26 + for (i = 0; i < dataSmpSDirNum && dataSmpSDirs[i].data != sdir; ++i) + ; + + if (i == dataSmpSDirNum) { + if (dataSmpSDirNum < 128) { + n = 0; + for (s = sdir; s->id != 0xffff; ++s) { + ++n; + } + + hwDisableIrq(); + + for (j = 0; j < n; ++j) { + for (i = 0; i < dataSmpSDirNum; ++i) { + for (k = 0; k < dataSmpSDirs[i].numSmp; ++k) { + if (sdir[j].id == dataSmpSDirs[i].data[k].id) + goto done_loop; + } + } + } + done_loop: + if (i == dataSmpSDirNum) { + sdir[j].ref_cnt = 0; + } else { + sdir[j].ref_cnt = 0xffff; + } + + dataSmpSDirs[dataSmpSDirNum].data = sdir; + dataSmpSDirs[dataSmpSDirNum].numSmp = n; + dataSmpSDirs[dataSmpSDirNum].base = smp_data; + ++dataSmpSDirNum; + hwEnableIrq(); + return 1; + } else { + return 0; + } + } + + return 1; } -unsigned long dataRemoveSDir(struct SDIR_DATA* sdir) { +bool dataRemoveSDir(struct SDIR_DATA* sdir) { long i; // r28 long j; // r30 long index; // r27 struct SDIR_DATA* data; // r31 } -unsigned long dataAddSampleReference(unsigned short sid) { - unsigned long i; // r29 - struct SAMPLE_HEADER* header; // r1+0xC - struct SDIR_DATA* data; // r30 - struct SDIR_DATA* sdir; // r31 +bool dataAddSampleReference(u16 sid) { + u32 i; // r29 + SAMPLE_HEADER* header; // r1+0xC + SDIR_DATA* data; // r30 + SDIR_DATA* sdir; // r31 } -unsigned long dataRemoveSampleReference(unsigned short sid) { +bool dataRemoveSampleReference(u16 sid) { unsigned long i; // r30 struct SDIR_DATA* sdir; // r31 } -unsigned long dataInsertFX(unsigned short gid, struct FX_TAB* fx, unsigned short fxNum) { +bool dataInsertFX(u16 gid, struct FX_TAB* fx, u16 fxNum) { long i; // r31 + return dataFXGroups[0].gid; } -unsigned long dataRemoveFX(unsigned short gid) { +bool dataRemoveFX(u16 gid) { long i; // r31 long j; // r30 return 1; } -unsigned long dataInsertMacro(unsigned short mid, void* macroaddr) { +bool dataInsertMacro(u16 mid, void* macroaddr) { long main; // r28 long pos; // r29 long base; // r27 long i; // r31 } -unsigned long dataRemoveMacro(unsigned short mid) { +bool dataRemoveMacro(u16 mid) { long main; // r29 long base; // r28 long i; // r31 } -long maccmp(void* p1, void* p2) { return ((MAC_SUBTAB*)p1)->id - ((MAC_SUBTAB*)p2)->id; } +static s32 maccmp(void* p1, void* p2) { return ((MAC_SUBTAB*)p1)->id - ((MAC_SUBTAB*)p2)->id; } -struct MSTEP* dataGetMacro(unsigned short mid) { +MSTEP* dataGetMacro(u16 mid) { static s32 base; static s32 main; static MAC_SUBTAB key; @@ -257,11 +330,9 @@ struct MSTEP* dataGetMacro(unsigned short mid) { return NULL; } -long smpcmp(void* p1, void* p2) { return ((SDIR_DATA*)p1)->id - ((SDIR_DATA*)p2)->id; } +static s32 smpcmp(void* p1, void* p2) { return ((SDIR_DATA*)p1)->id - ((SDIR_DATA*)p2)->id; } -long dataGetSample(unsigned short sid, SAMPLE_INFO* newsmp) { - static s32 base; - static s32 main; +long dataGetSample(u16 sid, SAMPLE_INFO* newsmp) { static SDIR_DATA key; static SDIR_DATA* result; static SAMPLE_HEADER* sheader; @@ -293,33 +364,33 @@ long dataGetSample(unsigned short sid, SAMPLE_INFO* newsmp) { return -1; } -long curvecmp(void* p1, void* p2) { return ((DATA_TAB*)p1)->id - ((DATA_TAB*)p2)->id; } +static s32 curvecmp(void* p1, void* p2) { return ((DATA_TAB*)p1)->id - ((DATA_TAB*)p2)->id; } -void* dataGetCurve(unsigned short cid) { +void* dataGetCurve(u16 cid) { static DATA_TAB key; static DATA_TAB* result; key.id = cid; if (result = - (DATA_TAB*)sndBSearcH(&key, dataCurveTab, dataCurveNum, sizeof(DATA_TAB), curvecmp)) { + (DATA_TAB*)sndBSearch(&key, dataCurveTab, dataCurveNum, sizeof(DATA_TAB), curvecmp)) { return result->data; } return NULL; } -void* dataGetKeymap(unsigned short cid) { +void* dataGetKeymap(u16 cid) { static DATA_TAB key; static DATA_TAB* result; key.id = cid; if (result = - (DATA_TAB*)sndBSearcH(&key, dataCurveTab, dataCurveNum, sizeof(DATA_TAB), curvecmp)) { + (DATA_TAB*)sndBSearch(&key, dataKeymapTab, dataKeymapNum, sizeof(DATA_TAB), curvecmp)) { return result->data; } return NULL; } -long layercmp(void* p1, void* p2) { return ((LAYER_TAB*)p1)->id - ((LAYER_TAB*)p2)->id; } +static s32 layercmp(void* p1, void* p2) { return ((LAYER_TAB*)p1)->id - ((LAYER_TAB*)p2)->id; } void* dataGetLayer(u16 cid, u16* n) { static LAYER_TAB key; @@ -327,16 +398,16 @@ void* dataGetLayer(u16 cid, u16* n) { key.id = cid; if (result = - (LAYER_TAB*)sndBSearcH(&key, dataLayerTab, dataLayerNum, sizeof(LAYER_TAB), layercmp)) { + (LAYER_TAB*)sndBSearch(&key, dataLayerTab, dataLayerNum, sizeof(LAYER_TAB), layercmp)) { *n = result->num; return result->data; } return NULL; } -long fxcmp(void* p1, void* p2) { return ((FX_TAB*)p1)->id - ((FX_TAB*)p2)->id; } +static s32 fxcmp(void* p1, void* p2) { return ((FX_TAB*)p1)->id - ((FX_TAB*)p2)->id; } -struct FX_TAB* dataGetFX(unsigned short fid) { +struct FX_TAB* dataGetFX(u16 fid) { static FX_TAB key; FX_TAB* ret; // r29 long i; // r31 diff --git a/src/musyx/runtime/synthmacros.c b/src/musyx/runtime/synthmacros.c index 29418a40..1f5c237b 100644 --- a/src/musyx/runtime/synthmacros.c +++ b/src/musyx/runtime/synthmacros.c @@ -292,7 +292,9 @@ static void mcmdUntrapEvent(SYNTH_VOICE* svoice, MSTEP* cstep) { svoice->trapEventAny = 0; } +#pragma dont_inline on static void mcmdLoop(SYNTH_VOICE* svoice, MSTEP* cstep) {} +#pragma dont_inline reset static void mcmdPlayMacro(SYNTH_VOICE* svoice, MSTEP* cstep) { s32 key; // r29 @@ -570,6 +572,7 @@ static void mcmdSetupLFO(SYNTH_VOICE* svoice, MSTEP* cstep) { svoice->lfo[n].period = time; } +#pragma dont_inline on static void DoSetPitch(SYNTH_VOICE* svoice) { u32 f; // r28 u32 of; // r25 @@ -583,6 +586,7 @@ static void DoSetPitch(SYNTH_VOICE* svoice) { 4096, 4339, 4597, 4871, 5160, 5467, 5792, 6137, 6502, 6888, 7298, 7732, 8192, }; } +#pragma dont_inline reset static void mcmdSetPitch(SYNTH_VOICE* svoice, MSTEP* cstep) { svoice->playFrq = (u32)(cstep->para[0] >> 8); @@ -592,6 +596,7 @@ static void mcmdSetPitch(SYNTH_VOICE* svoice, MSTEP* cstep) { } } +#pragma dont_inline on static void mcmdSetADSR(SYNTH_VOICE* svoice, MSTEP* cstep) { ADSR_INFO adsr; // r1+0x10 ADSR_INFO* adsr_ptr; // r31 @@ -599,6 +604,7 @@ static void mcmdSetADSR(SYNTH_VOICE* svoice, MSTEP* cstep) { s32 dscale; // r28 float sScale; // r63 } +#pragma dont_inline reset static s32 midi2TimeTab[128] = { 0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, @@ -614,6 +620,7 @@ static s32 midi2TimeTab[128] = { 150000, 155000, 160000, 165000, 170000, 175000, 180000, 0, }; +#pragma dont_inline on static void mcmdSetADSRFromCtrl(SYNTH_VOICE* svoice, MSTEP* cstep) { float sScale; // r63 ADSR_INFO adsr; // r1+0x10 @@ -626,6 +633,7 @@ static void mcmdSetPitchADSR(SYNTH_VOICE* svoice, MSTEP* cstep) { s32 ascale; // r27 s32 dscale; // r26 } +#pragma dont_inline reset static u32 mcmdPitchSweep(SYNTH_VOICE* svoice, MSTEP* cstep, int num) { s32 delta; // r31 @@ -787,6 +795,7 @@ static void mcmdFadeIn(SYNTH_VOICE* svoice, MSTEP* cstep) { DoEnvelopeCalculation(svoice, cstep, 0); } +#pragma dont_inline on static void mcmdRandomKey(SYNTH_VOICE* svoice, MSTEP* cstep) { u8 k1; // r30 u8 k2; // r29 @@ -795,6 +804,7 @@ static void mcmdRandomKey(SYNTH_VOICE* svoice, MSTEP* cstep) { s32 i2; // r27 u8 detune; // r26 } +#pragma dont_inline reset static void mcmdSetPitchbendAfterKeyOff(SYNTH_VOICE* svoice) { svoice->cFlags |= 0x10000; } static void mcmdScaleReverb(SYNTH_VOICE* svoice, MSTEP* cstep) {