Fully match seq_api.c

Former-commit-id: c03eb111e7
This commit is contained in:
Phillip Stephens 2023-06-25 21:50:23 -07:00
parent cf8cb69b61
commit 82d0e68236
5 changed files with 345 additions and 16 deletions

View File

@ -383,7 +383,7 @@ LIBS = [
"WorldFormat/CAreaOctTree",
["WorldFormat/CMetroidAreaCollider", False],
["WorldFormat/CWorldLight", False],
"WorldFormat/COBBTree",
["WorldFormat/COBBTree", False],
"WorldFormat/CCollidableOBBTree",
"WorldFormat/CCollidableOBBTreeGroup",
"WorldFormat/CPVSAreaSet",

View File

@ -1,8 +1,9 @@
#ifndef _MUSYX_MUSYX_PRIV
#define _MUSYX_MUSYX_PRIV
#include "musyx/assert.h"
#include "musyx/musyx.h"
#include "musyx/assert.h"
#include "musyx/hardware.h"
#ifdef __cplusplus
extern "C" {
@ -1015,6 +1016,8 @@ void streamOutputModeChanged();
u8 inpTranslateExCtrl(u8 ctrl);
void inpSetGlobalMIDIDirtyFlag(u8 chan, u8 midiSet, s32 flag);
void inpAddCtrl(struct CTRL_DEST* dest, u8 ctrl, long scale, u8 comb, u32 isVar);
void inpSetMidiCtrl(unsigned char ctrl, unsigned char channel, unsigned char set, unsigned char value);
void inpSetMidiCtrl14(unsigned char ctrl, unsigned char channel, unsigned char set, u16 value);
void inpSetExCtrl(SYNTH_VOICE* svoice, u8 ctrl, s16 v);
CHANNEL_DEFAULTS* inpGetChannelDefaults(u8 midi, u8 midiSet);
extern CTRL_DEST inpAuxA[8][4];

View File

@ -163,13 +163,15 @@ extern u8 synthTrackVolume[64];
extern SEQ_INSTANCE seqInstance[8];
extern u16 seqMIDIPriority[8][16];
void seqSpeed(unsigned long seqId, unsigned short speed);
void seqVolume(unsigned char volume, unsigned short time, unsigned long seqId, unsigned char mode);
void sndSeqStop(s32 unk);
void sndSeqSpeed(s32 unk1, s32 unk2);
void sndSeqSpeed(u32 seqId, u16 speed);
void sndSeqContinue(s32 unk);
void sndSeqMute(s32 unk1, s32 unk2, s32 unk3);
void sndSeqVolume(s32 unk1, s32 unk2, s32 unk3, s32 unk4);
void sndSeqVolume(unsigned char volume, unsigned short time, unsigned long seqId, unsigned char mode);
void seqStop(unsigned long seqId);
u16 seqGetMIDIPriority(s32 unk1, s32 unk2);
u16 seqGetMIDIPriority(u8 set, u8 channel);
#ifdef __cplusplus
}

View File

@ -1,33 +1,357 @@
#include "musyx/seq.h"
/*
*/
#include "musyx/hardware.h"
#include "musyx/seq.h"
/*
*/
void sndSeqCrossFade(struct SND_CROSSFADE* ci, unsigned long* new_seqId) {
MUSY_ASSERT_MSG(sndActive, "Sound system is not initialized.");
MUSY_ASSERT_MSG(ci != NULL, "Crossfade information pointer is NULL.");
MUSY_ASSERT_MSG(ci->studio2 < 8, "Studio index is illegal.");
MUSY_ASSERT_MSG(hwIsStudioActive(ci->studio2), "Selected studio is inactive.");
hwDisableIrq();
seqCrossFade(ci, new_seqId, 0);
hwEnableIrq();
}
/*
*/
u32 sndSeqCrossFadeDone(u32* new_seqId) {
if (*new_seqId != -1) {
return (*new_seqId & 0x80000000) == 0;
}
return TRUE;
}
u16 sndSeqGetLoopCnt(u32 seqId) {
MUSY_ASSERT_MSG(sndActive, "Sound system is not initialized.");
seqId = seqGetPrivateId(seqId);
if (seqId != -1 && (seqId & 0x80000000) == 0) {
return seqInstance[seqId].section[0].loopCnt;
}
return 0;
}
/*
*/
u16 sndSeqGetLoopCntEx(u32 seqId, u8 track) {
MUSY_ASSERT_MSG(sndActive, "Sound system is not initialized.");
seqId = seqGetPrivateId(seqId);
if (seqId != -1 && (seqId & 0x80000000) == 0) {
if (seqInstance[seqId].trackSectionTab == NULL) {
return seqInstance[seqId].section[0].loopCnt;
} else {
return seqInstance[seqId].section[seqInstance[seqId].trackSectionTab[track]].loopCnt;
}
}
return 0;
}
/*
*/
unsigned long sndSeqGetValid(unsigned long seqId) {
MUSY_ASSERT_MSG(sndActive, "Sound system is not initialized.");
return seqGetPrivateId(seqId) != -1;
}
/*
*/
void sndSeqPause(s32 unk) {
MUSY_ASSERT_MSG(sndActive, "Sound system is not initialized.");
hwDisableIrq();
seqPause(unk);
hwEnableIrq();
}
/*
*/
void sndSeqStop(s32 unk) {
MUSY_ASSERT_MSG(sndActive, "Sound system is not initialized.");
hwDisableIrq();
seqStop(unk);
hwEnableIrq();
}
void sndSeqSpeed(s32 unk1, s32 unk2) {
/*
*/
unsigned long sndSeqLoop(unsigned long seqId, bool on) {
unsigned long i; // r30
MUSY_ASSERT_MSG(sndActive, "Sound system is not initialized.");
if ((seqId = seqGetPrivateId(seqId)) != -1) {
if ((seqId & 0x80000000) == 0) {
for (i = 0; i < 16; ++i) {
seqInstance[seqId].section[i].loopDisable = !on;
}
return TRUE;
}
MUSY_DEBUG("Sequencer ID is temporary.\n");
} else {
MUSY_DEBUG("Sequencer ID is not valid.\n");
}
return FALSE;
}
/*
*/
unsigned long sndSeqLoopEx(unsigned long seqId, unsigned char track, bool on) {
unsigned long i; // r29
MUSY_ASSERT_MSG(sndActive, "Sound system is not initialized.");
if ((seqId = seqGetPrivateId(seqId)) != -1) {
if ((seqId & 0x80000000) == 0) {
if (seqInstance[seqId].trackSectionTab == NULL) {
for (i = 0; i < 16; ++i) {
seqInstance[seqId].section[i].loopDisable = !on;
}
return TRUE;
}
seqInstance[seqId].section[seqInstance[seqId].trackSectionTab[track]].loopDisable = !on;
return TRUE;
}
MUSY_DEBUG("Sequencer ID is temporary.\n");
} else {
MUSY_DEBUG("Sequencer ID is not valid.\n");
}
return FALSE;
}
/*
*/
void sndSeqSpeed(u32 seqId, u16 speed) {
MUSY_ASSERT_MSG(sndActive, "Sound system is not initialized.");
hwDisableIrq();
seqSpeed(unk1, unk2);
seqSpeed(seqId, speed);
hwEnableIrq();
}
/*
*/
void sndSeqContinue(s32 unk) {
MUSY_ASSERT_MSG(sndActive, "Sound system is not initialized.");
hwDisableIrq();
seqContinue(unk);
hwEnableIrq();
}
/*
*/
void sndSeqMute(s32 unk1, s32 unk2, s32 unk3) {
MUSY_ASSERT_MSG(sndActive, "Sound system is not initialized.");
hwDisableIrq();
seqMute(unk1, unk2, unk3);
hwEnableIrq();
}
void sndSeqVolume(s32 unk1, s32 unk2, s32 unk3, s32 unk4) {
/*
*/
void sndSeqVolume(unsigned char volume, unsigned short time, unsigned long seqId,
unsigned char mode) {
MUSY_ASSERT_MSG(sndActive, "Sound system is not initialized.");
hwDisableIrq();
seqVolume(unk1, unk2, unk3, unk4);
seqVolume(volume, time, seqId, mode);
hwEnableIrq();
}
u16 seqGetMIDIPriority(s32 arg0, s32 arg1) { return seqMIDIPriority[(u8)arg0][(u8)arg1]; }
/*
*/
unsigned char sndSeqGetVolGroup(unsigned long seqId) {
MUSY_ASSERT_MSG(sndActive, "Sound system is not initialized.");
if ((seqId = seqGetPrivateId(seqId)) != -1) {
return seqInstance[seqId].defVGroup;
}
MUSY_DEBUG("Volume group could not be received from sequencer.\n");
return 0;
}
/*
*/
unsigned long sndSeqAssignVolGroup2Track(unsigned long seqId, unsigned char track,
unsigned char vGroup) {
MUSY_ASSERT_MSG(sndActive, "Sound system is not initialized.");
if ((seqId = seqGetPrivateId(seqId)) != -1) {
seqInstance[seqId].trackVolGroup[track] = vGroup;
synthSetMusicVolumeType(vGroup, 2);
return TRUE;
}
MUSY_DEBUG("Volume group could not be assigned to track.\n");
return FALSE;
}
/*
*/
unsigned char sndSeqGetMidiCtrl(unsigned long seqId, unsigned char channel, unsigned char ctrl) {
unsigned char value; // r31
MUSY_ASSERT_MSG(sndActive, "Sound system is not initialized.");
value = 0;
hwDisableIrq();
if ((seqId = seqGetPrivateId(seqId)) != -1) {
value = inpGetMidiCtrl(ctrl, channel, seqId) >> 7;
}
hwEnableIrq();
return value;
}
/*
*/
unsigned short sndSeqGetMidiCtrl14(unsigned long seqId, unsigned char channel, unsigned char ctrl) {
unsigned short value; // r31
MUSY_ASSERT_MSG(sndActive, "Sound system is not initialized.");
value = 0;
hwDisableIrq();
if ((seqId = seqGetPrivateId(seqId)) != -1) {
value = inpGetMidiCtrl(ctrl, channel, seqId);
}
hwEnableIrq();
return value;
}
/*
*/
unsigned long sndSeqSetMidiCtrl(unsigned long seqId, unsigned char channel, unsigned char ctrl,
unsigned char value) {
unsigned long ret = FALSE; // r30
MUSY_ASSERT_MSG(sndActive, "Sound system is not initialized.");
hwDisableIrq();
if ((seqId = seqGetPrivateId(seqId)) != -1) {
inpSetMidiCtrl(ctrl, channel, seqId, value);
ret = TRUE;
} else {
MUSY_DEBUG("Sequenzer ID is not valid.\n\n");
}
hwEnableIrq();
return ret;
}
/*
*/
unsigned long sndSeqSetMidiCtrl14(unsigned long seqId, unsigned char channel, unsigned char ctrl,
unsigned short value) {
unsigned long ret = FALSE; // r30
MUSY_ASSERT_MSG(sndActive, "Sound system is not initialized.");
hwDisableIrq();
if ((seqId = seqGetPrivateId(seqId)) != -1) {
inpSetMidiCtrl14(ctrl, channel, seqId, value);
ret = TRUE;
} else {
MUSY_DEBUG("Sequenzer ID is not valid.\n\n");
}
hwEnableIrq();
return ret;
}
u16 seqGetMIDIPriority(u8 set, u8 channel) { return seqMIDIPriority[set][channel]; }

View File

@ -34,7 +34,7 @@ void vidInit() {
lvl->next = NULL;
}
VID_LIST* get_vidlist(u32 vid) {
static VID_LIST* get_vidlist(u32 vid) {
VID_LIST* vl = vidRoot;
while (vl != NULL) {
if (vl->vid == vid) {
@ -49,7 +49,7 @@ VID_LIST* get_vidlist(u32 vid) {
return NULL;
}
u32 get_newvid() {
static u32 get_newvid() {
u32 vid; // r31
do {
vid = vidCurrentId++;
@ -58,7 +58,7 @@ u32 get_newvid() {
return vid;
}
void vidRemove(VID_LIST** vidList) {
static void vidRemove(VID_LIST** vidList) {
if ((*vidList)->prev != NULL) {
(*vidList)->prev->next = (*vidList)->next;
} else {
@ -184,7 +184,7 @@ u32 vidGetInternalId(u32 vid) {
return 0xffffffff;
}
void voiceInitPrioSort() {
static void voiceInitPrioSort() {
u32 i;
for (i = 0; i < synthInfo.voiceNum; ++i) {
@ -328,7 +328,7 @@ void voiceFree(SYNTH_VOICE* svoice) {
svoice->id = 0xFFFFFFFF;
}
void voiceInitFreeList() {
static void voiceInitFreeList() {
u32 i; // r31
for (i = 0; i < synthInfo.voiceNum; ++i) {