music players

This commit is contained in:
Henny022p 2021-03-24 08:40:16 +01:00
parent 5af4805e59
commit 6e7674e865
5 changed files with 760 additions and 683 deletions

View File

@ -1611,6 +1611,3 @@ gUnk_08A11C0C:: @ 08A11C0C
gUnk_08A11C1C:: @ 08A11C1C gUnk_08A11C1C:: @ 08A11C1C
.incbin "baserom.gba", 0xA11C1C, 0x0000020 .incbin "baserom.gba", 0xA11C1C, 0x0000020
gMPlayTable:: @ 08A11C3C
.incbin "baserom.gba", 0xA11C3C, 0x0000180

View File

@ -46,18 +46,131 @@ typedef struct SongHeader {
typedef struct Song { typedef struct Song {
const SongHeader* header; const SongHeader* header;
u16 ms; u16 musicPlayerIndex;
u16 me; u16 me;
} Song; } Song;
typedef struct SoundChannel {
u8 statusFlags;
u8 type;
u8 rightVolume;
u8 leftVolume;
u8 attack;
u8 decay;
u8 sustain;
u8 release;
u8 key;
u8 envelopeVolume;
u8 envelopeVolumeRight;
u8 envelopeVolumeLeft;
u8 echoVolume;
u8 echoLength;
u8 unk0;
u8 unk1;
u8 gateTime;
u8 midiKey;
u8 velocity;
u8 priority;
u8 rhythmPan;
u8 unk2[3];
u32 count;
u32 fw;
u32 frequency;
WaveData* wav;
u32 currentPointer;
MusicPlayerTrack* track;
u32 prev;
u32 next;
u32 unk3;
u16 xpi;
u16 xpc;
} SoundChannel;
typedef void (*MPlayMainFunc)(MusicPlayerInfo*);
// typedef above
struct MusicPlayerInfo {
const SongHeader* songHeader;
u32 status;
u8 trackCount;
u8 priority;
u8 cmd;
u8 unk_B;
u32 clock;
u8 gap[8];
u8* memAccArea;
u16 tempoD;
u16 tempoU;
u16 tempoI;
u16 tempoC;
u16 fadeOI;
u16 fadeOC;
u16 fadeOV;
MusicPlayerTrack* tracks;
ToneData* tone;
u32 ident;
MPlayMainFunc func;
u32* intp;
};
#define MPT_FLG_VOLSET 0x01
#define MPT_FLG_VOLCHG 0x03
#define MPT_FLG_PITSET 0x04
#define MPT_FLG_PITCHG 0x0C
#define MPT_FLG_START 0x40
#define MPT_FLG_EXIST 0x80
// typedef above
struct MusicPlayerTrack {
u8 flags;
u8 wait;
u8 patternLevel;
u8 repN;
u8 gateTime;
u8 key;
u8 velocity;
u8 runningStatus;
u8 keyM;
u8 pitM;
s8 keyShift;
s8 keyShiftX;
s8 tune;
u8 pitX;
s8 bend;
u8 bendRange;
u8 volMR;
u8 volML;
u8 vol;
u8 volX;
s8 pan;
s8 panX;
s8 modM;
u8 mod;
u8 modT;
u8 lfoSpeed;
u8 lfoSpeedC;
u8 lfoDelay;
u8 lfoDelayC;
u8 priority;
u8 echoVolume;
u8 echoLength;
SoundChannel* chan;
ToneData tone;
u8 gap[10];
u16 unk_3A;
u32 unk_3C;
u8* cmdPtr;
u8* patternStack[3];
};
typedef struct MusicPlayer { typedef struct MusicPlayer {
MusicPlayerInfo* info; MusicPlayerInfo* info;
MusicPlayerTrack* track; MusicPlayerTrack* tracks;
u8 unk_8; u8 nTracks;
u16 unk_A; u16 unk_A;
} MusicPlayer; } MusicPlayer;
extern const MusicPlayer gMPlayTable[]; extern const MusicPlayer gMusicPlayers[];
extern const Song gSongTable[]; extern const Song gSongTable[];
void m4aSoundInit(void); void m4aSoundInit(void);

View File

@ -155,6 +155,7 @@ SECTIONS {
. = 0x00036A58; gUnk_02036A58 = .; . = 0x00036A58; gUnk_02036A58 = .;
. = 0x00036AD8; gUnk_02036AD8 = .; . = 0x00036AD8; gUnk_02036AD8 = .;
. = 0x00036BB8; gUnk_02036BB8 = .; . = 0x00036BB8; gUnk_02036BB8 = .;
. = 0x00036BC0; gMPlayTracks = .;
. = 0x00038560; gUnk_02038560 = .; . = 0x00038560; gUnk_02038560 = .;
. = 0x00040000; . = 0x00040000;
} >ewram } >ewram
@ -223,7 +224,9 @@ SECTIONS {
. = 0x00004DD8; gUnk_03004DD8 = .; . = 0x00004DD8; gUnk_03004DD8 = .;
. = 0x00004DDC; gUnk_03004DDC = .; . = 0x00004DDC; gUnk_03004DDC = .;
. = 0x00004DE0; gCgbChans = .; . = 0x00004DE0; gCgbChans = .;
. = 0x00004EE0; gMPlayInfos = .;
. = 0x000055E0; gMPlayMemAccArea = .; . = 0x000055E0; gMPlayMemAccArea = .;
. = 0x000055F0; gMPlayInfos2 = .;
. = 0x000056F0; gUnk_030056F0 = .; . = 0x000056F0; gUnk_030056F0 = .;
. = 0x000056F1; gUnk_030056F1 = .; . = 0x000056F1; gUnk_030056F1 = .;
. = 0x00005740; gUnk_03005740 = .; . = 0x00005740; gUnk_03005740 = .;

File diff suppressed because it is too large Load Diff

View File

@ -42,7 +42,6 @@ typedef void (*CgbSoundFunc)(void);
typedef void (*CgbOscOffFunc)(u8); typedef void (*CgbOscOffFunc)(u8);
typedef u32 (*MidiKeyToCgbFreqFunc)(u8, u8, u8); typedef u32 (*MidiKeyToCgbFreqFunc)(u8, u8, u8);
typedef void (*ExtVolPitFunc)(void); typedef void (*ExtVolPitFunc)(void);
typedef void (*MPlayMainFunc)(MusicPlayerInfo*);
typedef void (*XcmdFunc)(MusicPlayerInfo*, MusicPlayerTrack*); typedef void (*XcmdFunc)(MusicPlayerInfo*, MusicPlayerTrack*);
typedef struct CgbChannel { typedef struct CgbChannel {
@ -85,42 +84,6 @@ typedef struct CgbChannel {
u8 unk4[8]; u8 unk4[8];
} CgbChannel; } CgbChannel;
typedef struct SoundChannel {
u8 statusFlags;
u8 type;
u8 rightVolume;
u8 leftVolume;
u8 attack;
u8 decay;
u8 sustain;
u8 release;
u8 key;
u8 envelopeVolume;
u8 envelopeVolumeRight;
u8 envelopeVolumeLeft;
u8 echoVolume;
u8 echoLength;
u8 unk0;
u8 unk1;
u8 gateTime;
u8 midiKey;
u8 velocity;
u8 priority;
u8 rhythmPan;
u8 unk2[3];
u32 count;
u32 fw;
u32 frequency;
WaveData* wav;
u32 currentPointer;
MusicPlayerTrack* track;
u32 prev;
u32 next;
u32 unk3;
u16 xpi;
u16 xpc;
} SoundChannel;
#define MAX_DIRECTSOUND_CHANNELS 12 #define MAX_DIRECTSOUND_CHANNELS 12
#define PCM_DMA_BUF_SIZE 1584 // size of Direct Sound buffer #define PCM_DMA_BUF_SIZE 1584 // size of Direct Sound buffer
@ -162,56 +125,6 @@ typedef struct SoundInfo {
s8 pcmBuffer[PCM_DMA_BUF_SIZE]; s8 pcmBuffer[PCM_DMA_BUF_SIZE];
} SoundInfo; } SoundInfo;
#define MPT_FLG_VOLSET 0x01
#define MPT_FLG_VOLCHG 0x03
#define MPT_FLG_PITSET 0x04
#define MPT_FLG_PITCHG 0x0C
#define MPT_FLG_START 0x40
#define MPT_FLG_EXIST 0x80
// typedef above
struct MusicPlayerTrack {
u8 flags;
u8 wait;
u8 patternLevel;
u8 repN;
u8 gateTime;
u8 key;
u8 velocity;
u8 runningStatus;
u8 keyM;
u8 pitM;
s8 keyShift;
s8 keyShiftX;
s8 tune;
u8 pitX;
s8 bend;
u8 bendRange;
u8 volMR;
u8 volML;
u8 vol;
u8 volX;
s8 pan;
s8 panX;
s8 modM;
u8 mod;
u8 modT;
u8 lfoSpeed;
u8 lfoSpeedC;
u8 lfoDelay;
u8 lfoDelayC;
u8 priority;
u8 echoVolume;
u8 echoLength;
SoundChannel* chan;
ToneData tone;
u8 gap[10];
u16 unk_3A;
u32 unk_3C;
u8* cmdPtr;
u8* patternStack[3];
};
#define MUSICPLAYER_STATUS_TRACK 0x0000ffff #define MUSICPLAYER_STATUS_TRACK 0x0000ffff
#define MUSICPLAYER_STATUS_PAUSE 0x80000000 #define MUSICPLAYER_STATUS_PAUSE 0x80000000
@ -222,31 +135,6 @@ struct MusicPlayerTrack {
#define FADE_VOL_MAX 64 #define FADE_VOL_MAX 64
#define FADE_VOL_SHIFT 2 #define FADE_VOL_SHIFT 2
// typedef above
struct MusicPlayerInfo {
const SongHeader* songHeader;
u32 status;
u8 trackCount;
u8 priority;
u8 cmd;
u8 unk_B;
u32 clock;
u8 gap[8];
u8* memAccArea;
u16 tempoD;
u16 tempoU;
u16 tempoI;
u16 tempoC;
u16 fadeOI;
u16 fadeOC;
u16 fadeOV;
MusicPlayerTrack* tracks;
ToneData* tone;
u32 ident;
MPlayMainFunc func;
u32* intp;
};
extern u8 gMPlayMemAccArea[]; extern u8 gMPlayMemAccArea[];
extern char SoundMainRAM[]; extern char SoundMainRAM[];
@ -471,9 +359,9 @@ void m4aSoundInit(void) {
(8 << SOUND_MODE_MAXCHN_SHIFT)); (8 << SOUND_MODE_MAXCHN_SHIFT));
for (i = 0; i < NUM_MUSIC_PLAYERS; i++) { for (i = 0; i < NUM_MUSIC_PLAYERS; i++) {
MusicPlayerInfo* mplayInfo = gMPlayTable[i].info; MusicPlayerInfo* mplayInfo = gMusicPlayers[i].info;
MPlayOpen(mplayInfo, gMPlayTable[i].track, gMPlayTable[i].unk_8); MPlayOpen(mplayInfo, gMusicPlayers[i].tracks, gMusicPlayers[i].nTracks);
mplayInfo->unk_B = gMPlayTable[i].unk_A; mplayInfo->unk_B = gMusicPlayers[i].unk_A;
mplayInfo->memAccArea = gMPlayMemAccArea; mplayInfo->memAccArea = gMPlayMemAccArea;
} }
} }
@ -483,19 +371,19 @@ void m4aSoundMain(void) {
} }
void m4aSongNumStart(u16 n) { void m4aSongNumStart(u16 n) {
const MusicPlayer* mplayTable = gMPlayTable; const MusicPlayer* mplayTable = gMusicPlayers;
const Song* songTable = gSongTable; const Song* songTable = gSongTable;
const Song* song = &songTable[n]; const Song* song = &songTable[n];
const MusicPlayer* mplay = &mplayTable[song->ms]; const MusicPlayer* mplay = &mplayTable[song->musicPlayerIndex];
MPlayStart(mplay->info, song->header); MPlayStart(mplay->info, song->header);
} }
void m4aSongNumStartOrChange(u16 n) { void m4aSongNumStartOrChange(u16 n) {
const MusicPlayer* mplayTable = gMPlayTable; const MusicPlayer* mplayTable = gMusicPlayers;
const Song* songTable = gSongTable; const Song* songTable = gSongTable;
const Song* song = &songTable[n]; const Song* song = &songTable[n];
const MusicPlayer* mplay = &mplayTable[song->ms]; const MusicPlayer* mplay = &mplayTable[song->musicPlayerIndex];
if (mplay->info->songHeader != song->header) { if (mplay->info->songHeader != song->header) {
MPlayStart(mplay->info, song->header); MPlayStart(mplay->info, song->header);
@ -507,10 +395,10 @@ void m4aSongNumStartOrChange(u16 n) {
} }
void m4aSongNumStartOrContinue(u16 n) { void m4aSongNumStartOrContinue(u16 n) {
const MusicPlayer* mplayTable = gMPlayTable; const MusicPlayer* mplayTable = gMusicPlayers;
const Song* songTable = gSongTable; const Song* songTable = gSongTable;
const Song* song = &songTable[n]; const Song* song = &songTable[n];
const MusicPlayer* mplay = &mplayTable[song->ms]; const MusicPlayer* mplay = &mplayTable[song->musicPlayerIndex];
if (mplay->info->songHeader != song->header) if (mplay->info->songHeader != song->header)
MPlayStart(mplay->info, song->header); MPlayStart(mplay->info, song->header);
@ -521,20 +409,20 @@ void m4aSongNumStartOrContinue(u16 n) {
} }
void m4aSongNumStop(u16 n) { void m4aSongNumStop(u16 n) {
const MusicPlayer* mplayTable = gMPlayTable; const MusicPlayer* mplayTable = gMusicPlayers;
const Song* songTable = gSongTable; const Song* songTable = gSongTable;
const Song* song = &songTable[n]; const Song* song = &songTable[n];
const MusicPlayer* mplay = &mplayTable[song->ms]; const MusicPlayer* mplay = &mplayTable[song->musicPlayerIndex];
if (mplay->info->songHeader == song->header) if (mplay->info->songHeader == song->header)
MPlayStop(mplay->info); MPlayStop(mplay->info);
} }
void m4aSongNumContinue(u16 n) { void m4aSongNumContinue(u16 n) {
const MusicPlayer* mplayTable = gMPlayTable; const MusicPlayer* mplayTable = gMusicPlayers;
const Song* songTable = gSongTable; const Song* songTable = gSongTable;
const Song* song = &songTable[n]; const Song* song = &songTable[n];
const MusicPlayer* mplay = &mplayTable[song->ms]; const MusicPlayer* mplay = &mplayTable[song->musicPlayerIndex];
if (mplay->info->songHeader == song->header) if (mplay->info->songHeader == song->header)
MPlayContinue(mplay->info); MPlayContinue(mplay->info);
@ -544,7 +432,7 @@ void m4aMPlayAllStop(void) {
s32 i; s32 i;
for (i = 0; i < NUM_MUSIC_PLAYERS; i++) for (i = 0; i < NUM_MUSIC_PLAYERS; i++)
MPlayStop(gMPlayTable[i].info); MPlayStop(gMusicPlayers[i].info);
} }
void m4aMPlayContinue(MusicPlayerInfo* mplayInfo) { void m4aMPlayContinue(MusicPlayerInfo* mplayInfo) {
@ -555,7 +443,7 @@ void m4aMPlayAllContinue(void) {
s32 i; s32 i;
for (i = 0; i < NUM_MUSIC_PLAYERS; i++) for (i = 0; i < NUM_MUSIC_PLAYERS; i++)
MPlayContinue(gMPlayTable[i].info); MPlayContinue(gMusicPlayers[i].info);
} }
void m4aMPlayFadeOut(MusicPlayerInfo* mplayInfo, u16 speed) { void m4aMPlayFadeOut(MusicPlayerInfo* mplayInfo, u16 speed) {