Skip to content

Commit

Permalink
Match adsrHandle
Browse files Browse the repository at this point in the history
  • Loading branch information
Antidote committed Oct 27, 2023
1 parent 78bbe70 commit 3cd23e9
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 6 deletions.
10 changes: 5 additions & 5 deletions configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -1172,11 +1172,11 @@ def Rel(lib_name, objects):
],
},
MusyX(
# debug=True,
# mw_version="GC/1.2.5",
# major=2,
# minor=0,
# patch=0,
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"),
Expand Down
2 changes: 1 addition & 1 deletion include/musyx/musyx_priv.h
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,7 @@ typedef struct SYNTH_VOICE {
u32 id; // offset 0xF4, size 0x4
VID_LIST* vidList; // offset 0xF8, size 0x4
VID_LIST* vidMasterList; // offset 0xFC, size 0x4
#if MUSY_VERSION > MUSY_VERSION_CHECK(1, 5, 3) && MUSY_VERSION <= MUSY_VERSION_CHECK(2, 0, 0)
#if MUSY_VERSION >= MUSY_VERSION_CHECK(1, 5, 0) && MUSY_VERSION <= MUSY_VERSION_CHECK(2, 0, 0)
u16 allocId; // offset 0x100, size 0x2
#else
u32 allocId;
Expand Down
56 changes: 56 additions & 0 deletions src/musyx/runtime/synth_adsr.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,14 @@ static u32 adsrGetIndex(ADSR_VARS* adsr) {

u32 adsrConvertTimeCents(long tc) { return 1000.f * powf(2.f, 1.2715658e-08f * tc); }

#pragma dont_inline on
u32 salChangeADSRState(ADSR_VARS* adsr) {
u32 VoiceDone; // r30
VoiceDone = FALSE;

return VoiceDone;
}
#pragma dont_inline reset

u32 adsrSetup(ADSR_VARS* adsr) {
adsr->state = 0;
Expand Down Expand Up @@ -68,6 +73,57 @@ u32 adsrHandle(ADSR_VARS* adsr, u16* adsr_start, u16* adsr_delta) {
s32 old_volume; // r29
bool VoiceDone; // r28
s32 vDelta; // r27

VoiceDone = FALSE;

switch (adsr->mode) {
case 0:
if (adsr->state != 3) {
old_volume = adsr->currentVolume;
adsr->currentVolume += adsr->currentDelta;
*adsr_start = old_volume >> 16;
if (adsr->currentDelta >= 0) {
*adsr_delta = adsr->currentDelta >> 21;
} else {
*adsr_delta = -(-adsr->currentDelta >> 21);
}

if (--adsr->cnt == 0) {
VoiceDone = salChangeADSRState(adsr);
}
} else {
*adsr_start = adsr->currentVolume >> 16;
*adsr_delta = 0;
}
break;
case 1:
if (adsr->state != 3) {
old_volume = adsr->currentVolume;
if (adsr->data.dls.aMode == 0 && adsr->state == 1) {
adsr->currentVolume += adsr->currentDelta;
} else {
adsr->currentIndex += adsr->currentDelta;
adsr->currentVolume = dspAttenuationTab[adsrGetIndex(adsr)] << 16;
}
*adsr_start = old_volume >> 16;
vDelta = adsr->currentVolume - old_volume;
if (vDelta >= 0) {
*adsr_delta = vDelta >> 21;
} else {
*adsr_delta = -(-vDelta >> 21);
}

if (--adsr->cnt == 0) {
VoiceDone = salChangeADSRState(adsr);
}
} else {
*adsr_start = adsr->currentVolume >> 16;
*adsr_delta = 0;
}
break;
}

return VoiceDone;
}
u32 adsrHandleLowPrecision(ADSR_VARS* adsr, u16* adsr_start, u16* adsr_delta) {
u8 i; // r31
Expand Down

0 comments on commit 3cd23e9

Please sign in to comment.