Skip to content

Commit

Permalink
Match and link snd3d.c
Browse files Browse the repository at this point in the history
  • Loading branch information
Antidote committed Oct 21, 2023
1 parent 66a930d commit 0c0fecf
Show file tree
Hide file tree
Showing 7 changed files with 151 additions and 47 deletions.
2 changes: 1 addition & 1 deletion configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -1184,7 +1184,7 @@ def Rel(lib_name, objects):
Object(Matching, "musyx/runtime/s_data.c"),
Object(NonMatching, "musyx/runtime/hw_dspctrl.c"),
Object(Matching, "musyx/runtime/hw_volconv.c"),
Object(NonMatching, "musyx/runtime/snd3d.c"),
Object(Matching, "musyx/runtime/snd3d.c"),
Object(Matching, "musyx/runtime/snd_init.c"),
Object(Matching, "musyx/runtime/snd_math.c"),
Object(NonMatching, "musyx/runtime/snd_midictrl.c"),
Expand Down
4 changes: 4 additions & 0 deletions include/musyx/hardware.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ void hwSetVirtualSampleLoopBuffer(u32 voice, void* addr, u32 len);
u16 hwGetSampleID(u32 voice);
u8 hwGetSampleType(u32 voice);
void hwChangeStudioMix(u8 studio, u32 isMaster);
#if MUSY_VERSION >= MUSY_VERSION_CHECK(2, 0, 3)
void hwSetFilter(unsigned long v, unsigned char mode, unsigned short coefA, unsigned short coefB);
void hwLowPassFrqToCoef(unsigned long frq, unsigned short* _a0, unsigned short* _b1);
#endif

#ifdef __cplusplus
}
Expand Down
78 changes: 51 additions & 27 deletions include/musyx/musyx_priv.h
Original file line number Diff line number Diff line change
Expand Up @@ -513,27 +513,34 @@ typedef struct SYNTH_VOICE {
u32 id; // offset 0xF4, size 0x4
VID_LIST* vidList; // offset 0xF8, size 0x4
VID_LIST* vidMasterList; // offset 0xFC, size 0x4
u16 allocId; // offset 0x100, size 0x2
u16 macroId; // offset 0x102, size 0x2
u8 keyGroup; // offset 0x104, size 0x1
u32 lastVID; // offset 0x108, size 0x4
u8 prio; // offset 0x10C, size 0x1
u16 ageSpeed; // offset 0x10E, size 0x2
u32 age; // offset 0x110, size 0x4
u64 cFlags; // offset 0x114, size 0x8
u8 block; // offset 0x11C, size 0x1
u8 fxFlag; // offset 0x11D, size 0x1
u8 vGroup; // offset 0x11E, size 0x1
u8 studio; // offset 0x11F, size 0x1
u8 track; // offset 0x120, size 0x1
u8 midi; // offset 0x121, size 0x1
u8 midiSet; // offset 0x122, size 0x1
u8 section; // offset 0x123, size 0x1
#if MUSY_VERSION <= MUSY_VERSION_CHECK(2, 0, 0)
u16 allocId; // offset 0x100, size 0x2
#else
u32 allocId;
#endif
u16 macroId; // offset 0x102, size 0x2
u8 keyGroup; // offset 0x104, size 0x1
u32 lastVID; // offset 0x108, size 0x4
u8 prio; // offset 0x10C, size 0x1
u16 ageSpeed; // offset 0x10E, size 0x2
u32 age; // offset 0x110, size 0x4
u64 cFlags; // offset 0x114, size 0x8
u8 block; // offset 0x11C, size 0x1
u8 fxFlag; // offset 0x11D, size 0x1
u8 vGroup; // offset 0x11E, size 0x1
u8 studio; // offset 0x11F, size 0x1
u8 track; // offset 0x120, size 0x1
u8 midi; // offset 0x121, size 0x1
u8 midiSet; // offset 0x122, size 0x1
u8 section; // offset 0x123, size 0x1
#if MUSY_VERSION <= MUSY_VERSION_CHECK(1, 5, 0)
void* sAddr;
#endif
u32 sInfo; // offset 0x124, size 0x4
u32 playFrq; // offset 0x128, size 0x4
u32 sInfo; // offset 0x124, size 0x4
u32 playFrq; // offset 0x128, size 0x4
#if MUSY_VERSION >= MUSY_VERSION_CHECK(2, 0, 3)
u16 sampleId;
#endif
u16 curNote; // offset 0x12C, size 0x2
s8 curDetune; // offset 0x12E, size 0x1
u8 orgNote; // offset 0x12F, size 0x1
Expand Down Expand Up @@ -577,9 +584,13 @@ typedef struct SYNTH_VOICE {
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
#if MUSY_VERSION >= MUSY_VERSION_CHECK(2, 0, 3)
u32 lpfLowerFrqBoundary;
u32 lpfUpperFrqBoundary;
#endif
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
Expand All @@ -606,11 +617,15 @@ typedef struct SYNTH_VOICE {
CTRL_DEST inpPreAuxB; // offset 0x380, size 0x24
CTRL_DEST inpPostAuxB; // offset 0x3A4, size 0x24
CTRL_DEST inpTremolo; // offset 0x3C8, size 0x24
u8 mesgNum; // offset 0x3EC, size 0x1
u8 mesgRead; // offset 0x3ED, size 0x1
u8 mesgWrite; // offset 0x3EE, size 0x1
s32 mesgQueue[4]; // offset 0x3F0, size 0x10
u16 curOutputVolume; // offset 0x400, size 0x2
#if MUSY_VERSION >= MUSY_VERSION_CHECK(2, 0, 3)
CTRL_DEST inpFilterSwitch; // offset 0x3F8, size 0x24
CTRL_DEST inpFilterParameter; // offset 0x41C, size 0x24
#endif
u8 mesgNum; // offset 0x3EC, size 0x1
u8 mesgRead; // offset 0x3ED, size 0x1
u8 mesgWrite; // offset 0x3EE, size 0x1
s32 mesgQueue[4]; // offset 0x3F0, size 0x10
u16 curOutputVolume; // offset 0x400, size 0x2
} SYNTH_VOICE;

typedef struct synthITDInfo {
Expand Down Expand Up @@ -855,7 +870,11 @@ typedef struct ADSR_INFO {
} ADSR_INFO;

void dataInit(u32, u32); /* extern */
void dataInitStack(); /* extern */
#if MUSY_VERSION >= MUSY_VERSION_CHECK(2, 0, 3)
void dataInitStack(unsigned long aramBase, unsigned long aramSize);
#else
void dataInitStack(); /* extern */
#endif
u32 dataInsertSDir(SDIR_DATA* sdir, void* smp_data);
u32 dataRemoveSDir(SDIR_DATA* sdir);
u32 dataInsertMacro(u16 mid, void* macroaddr);
Expand Down Expand Up @@ -1058,6 +1077,11 @@ void inpSetMidiCtrl(u8 ctrl, u8 channel, u8 set, u8 value);
void inpSetMidiCtrl14(u8 ctrl, u8 channel, u8 set, u16 value);
void inpSetExCtrl(SYNTH_VOICE* svoice, u8 ctrl, s16 v);
CHANNEL_DEFAULTS* inpGetChannelDefaults(u8 midi, u8 midiSet);
#if MUSY_VERSION >= MUSY_VERSION_CHECK(2, 0, 3)
unsigned short inpGetFilterSwitch(struct SYNTH_VOICE* svoice);
unsigned short inpGetFilterParameter(struct SYNTH_VOICE* svoice);
void inpSetLPFDefaultRange(u32 lowFrq, u32 highFrq);
#endif
extern CTRL_DEST inpAuxA[8][4];
extern CTRL_DEST inpAuxB[8][4];
void inpSetMidiLastNote(u8 midi, u8 midiSet, u8 key);
Expand Down
5 changes: 5 additions & 0 deletions include/musyx/synth.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ void hwSetAUXProcessingCallbacks(u8 studio, SND_AUX_CALLBACK auxA, void* userA,
MSTEP* dataGetMacro(u16 mid);

u32 voiceAllocate(u8 priority, u8 maxVoices, u16 allocId, u8 fxFlag);

#if MUSY_VERSION >= MUSY_VERSION_CHECK(2, 0, 3)
int voiceAllocatePeek(u8 priority, u8 maxVoices, u32 allocId, u8 fxFlag, u32 * currentAllocId);
#endif

void voiceFree(SYNTH_VOICE* svoice);
void synthActivateStudio(u8 studio, u32 isMaster, SND_STUDIO_TYPE type);
void synthDeactivateStudio(u8 studio);
Expand Down
8 changes: 4 additions & 4 deletions src/musyx/runtime/snd3d.c
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ static void CheckRoomStatus() {
room->distance = distance;
room->curMVol = has_listener ? 0x7f0000 : 0;

if (room->curMVol * 1.201479e-07f >= 0.5) {
if (room->curMVol * 1.2014794e-07f >= 0.5) {
synthActivateStudio(room->studio, TRUE, SND_STUDIO_TYPE_STD);
} else {
synthActivateStudio(room->studio, FALSE, SND_STUDIO_TYPE_STD);
Expand All @@ -142,7 +142,7 @@ static void CheckRoomStatus() {
room->flags &= ~0x80000000;
}

if (room->curMVol * 1.201479e-07f >= 0.5) {
if (room->curMVol * 1.2014794e-07f >= 0.5) {
synthActivateStudio(room->studio, TRUE, SND_STUDIO_TYPE_STD);
} else {
synthActivateStudio(room->studio, FALSE, SND_STUDIO_TYPE_STD);
Expand All @@ -155,7 +155,7 @@ static void CheckRoomStatus() {
room->curMVol = 0;
room->flags &= ~0x40000000;
}
if (room->curMVol * 1.201479e-07f >= 0.5) {
if (room->curMVol * 1.2014794e-07f >= 0.5) {
synthActivateStudio(room->studio, TRUE, SND_STUDIO_TYPE_STD);
} else {
synthActivateStudio(room->studio, FALSE, SND_STUDIO_TYPE_STD);
Expand Down Expand Up @@ -444,7 +444,7 @@ static u16 clip3FFF(u32 v) {
return v;
}

static void SetFXParameters(SND_EMITTER* em, f32 vol, f32 xPan, f32 yPan, f32 zPan, f32 doppler) {
static void SetFXParameters(SND_EMITTER* const em, f32 vol, f32 xPan, f32 yPan, f32 zPan, f32 doppler) {
SND_VOICEID vid; // r30
u8 i; // r28
SND_PARAMETER* pPtr; // r31
Expand Down
27 changes: 23 additions & 4 deletions src/musyx/runtime/snd_init.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,29 @@
*/
static s32 DoInit(u32 rate, u32 aramSize, u32 voices, u32 flags) {
#if MUSY_VERSION >= MUSY_VERSION_CHECK(2, 0, 3)
long DoInit(u32 mixFrq, u32 numVoices, u32 flags, u32 aramBase, u32 aramSize)
#else
static s32 DoInit(u32 mixFrq, u32 aramSize, u32 numVoices, u32 flags)
#endif
{
bool ret;

MUSY_DEBUG("\nMusyX software initialization...\nBuild Date: %s %s\n\n", __DATE__, __TIME__);
MUSY_DEBUG("\nMusyX software initialization...\nBuild Date: %s %s\n\n", "Dec 17 2003", "20:32:41");
ret = FALSE;

#if MUSY_VERSION >= MUSY_VERSION_CHECK(2, 0, 3)
dataInitStack(aramBase, aramGetUserBytes(aramSize));
#else
dataInitStack();

#endif
dataInit(0, aramSize);

seqInit();

synthIdleWaitActive = 0;

synthInit(rate, voices);
synthInit(mixFrq, numVoices);

streamInit();

Expand Down Expand Up @@ -72,6 +80,7 @@ s32 sndInit(u8 voices, u8 music, u8 sfx, u8 studios, u32 flags, u32 aramSize) {
u32 frq; // r1+0x14

MUSY_DEBUG("Entering sndInit()\n\n");
ret = 0;
sndActive = 0;
if (voices <= 64) {
synthInfo.voiceNum = voices;
Expand All @@ -88,7 +97,11 @@ s32 sndInit(u8 voices, u8 music, u8 sfx, u8 studios, u32 flags, u32 aramSize) {
synthInfo.maxSFX = sfx;
frq = 32000;
if ((ret = hwInit(&frq, synthInfo.voiceNum, synthInfo.studioNum, flags)) == 0) {
#if MUSY_VERSION >= MUSY_VERSION_CHECK(2, 0, 3)
ret = DoInit(32000, synthInfo.voiceNum, flags, aramGetFirstUserAddress(), aramSize);
#else
ret = DoInit(32000, aramSize, synthInfo.voiceNum, flags);
#endif
}

MUSY_DEBUG("Leaving sndInit().\n\n");
Expand Down Expand Up @@ -145,3 +158,9 @@ SND_PLAYBACKINFO* sndGetPlayBackInfo() {

return NULL;
}

#if MUSY_VERSION >= MUSY_VERSION_CHECK(2, 0, 3)
void sndSetLowPassFilterDefaultRange(unsigned long lowFrq, unsigned long highFrq) {
inpSetLPFDefaultRange(lowFrq, highFrq);
}
#endif
Loading

0 comments on commit 0c0fecf

Please sign in to comment.