Skip to content

Commit

Permalink
adsr, ssinit
Browse files Browse the repository at this point in the history
  • Loading branch information
sozud committed Mar 14, 2024
1 parent 566e219 commit 9f16b63
Show file tree
Hide file tree
Showing 6 changed files with 173 additions and 55 deletions.
2 changes: 2 additions & 0 deletions build.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ def build_33():

def build_35():
snd_srcs = [
'src/snd/adsr.c',
'src/snd/next.c',
'src/snd/pause.c',
'src/snd/play.c',
Expand All @@ -179,6 +180,7 @@ def build_35():
'src/snd/ssclose.c',
'src/snd/ssend.c',
'src/snd/ssinit_h.c',
'src/snd/ssinit.c',
'src/snd/ssplay.c',
'src/snd/ssquit.c',
'src/snd/ssstart.c',
Expand Down
41 changes: 41 additions & 0 deletions src/snd/adsr.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#include "libsnd_i.h"

void _SsUtResolveADSR(u16 arg0, u16 arg1, struct Unk* arg2) {
arg2->unkA = arg0 & 0x8000;
arg2->unkC = arg1 & 0x8000;
arg2->unk10 = arg1 & 0x4000;
arg2->unkE = arg1 & 0x20;
arg2->unk0 = (arg0 >> 8) & 0x7F;
arg2->unk2 = (arg0 >> 4) & 0xF;
arg2->unk4 = arg0 & 0xF;
arg2->unk6 = (arg1 >> 6) & 0x7F;
arg2->unk8 = arg1 & 0x1F;
}

void _SsUtBuildADSR(struct Unk* arg0, s16* arg1, s16* arg2) {
u16 temp_t1;
u16 var_v0;
s16 temp4;
s16 temp5;
if (arg0->unkC != 0) {
temp_t1 = 0x8000;
} else {
temp_t1 = 0;
}

if (arg0->unkA != 0) {
var_v0 = 0x8000;
} else {
var_v0 = 0;
}

if (arg0->unk10 != 0) {
temp_t1 = temp_t1 | 0x4000;
}
temp4 = var_v0 | ((arg0->unk0 << 8) & 0x7F00) | ((arg0->unk2 << 4) & 0xF0) |
(arg0->unk4 & 0xF);
temp5 = temp_t1 | ((arg0->unk6 << 6) & 0x1FC0) | (arg0->unk8 & 0x1F);
temp_t1 = temp5;
*arg1 = temp4;
*arg2 = temp_t1;
}
58 changes: 3 additions & 55 deletions src/snd/libsnd_i.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <LIBSND.H>
#include <LIBSPU.H>
#include "../types.h"
#include "snd_defs.h"

struct Unk {
u16 unk0;
Expand All @@ -12,11 +13,10 @@ struct Unk {
u16 unk6;
u16 unk8;
s16 unkA;
u16 unkC;
s16 unkC;
u16 unkE;
u16 unk10;
s16 unk10;
};

void _SsUtResolveADSR(u16 arg0, u16 arg1, struct Unk* arg2);
void _SsSeqPlay(s16, s16);

Expand Down Expand Up @@ -111,58 +111,6 @@ extern void* _svm_vg; /* number: 29 */
void SeAutoVol(s16, s16, s16, s16);
void SeAutoPan(s16, s16, s16, s16);

struct SeqStruct {
u8 unk0;
u8 pad1[3];
u8* read_pos;
u8* next_sep_pos; /* 0x8 */
u8* loop_pos; /* 0xC */
u8 unk10;
u8 unk11;
u8 channel;
u8 unk13;
u8 unk14;
u8 unk15;
u8 unk16;
u8 panpot[16];
u8 unk27;
u8 unk28;
u8 unk29;
u8 unk2a;
u8 unk2b;
u8 programs[16];
u8 unk3C;
u8 pad3D;
s16 unk3E;
s16 unk40;
s16 unk42;
s16 unk44;
s16 unk46;
s16 unk48;
s16 unk4a;
s16 unk4c;
s16 vol[16];
s16 unk6E;
s16 unk70;
s16 unk72;
u16 unk74;
s16 unk76;
s16 unk78;
s16 unk7A;
s32 unk7c;
u32 unk80;
s32 unk84;
s32 delta_value;
s32 unk8c;
s32 unk90;
s32 unk94;
s32 unk98;
s32 unk9C;
s32 unkA0;
u32 unkA4;
s16 padA6;
s16 padaa;
};
extern struct SeqStruct* _ss_score[32];

#define SPU_COMMON_MVOLL (0x01 << 0) /* master volume (left) */
Expand Down
61 changes: 61 additions & 0 deletions src/snd/snd_defs.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#ifndef SND_DEFS_H
#define SND_DEFS_H

#include "../types.h"

typedef void (*SndSsMarkCallbackProc)(short seq_no, short sep_no, short data);

struct SeqStruct {
u8 unk0;
u8 pad1[3];
u8* read_pos;
u8* next_sep_pos; /* 0x8 */
u8* loop_pos; /* 0xC */
u8 unk10;
u8 unk11;
u8 channel;
u8 unk13;
u8 unk14;
u8 unk15;
u8 unk16;
u8 panpot[16];
u8 unk27;
u8 unk28;
u8 unk29;
u8 unk2a;
u8 unk2b;
u8 programs[16];
u8 unk3C;
u8 pad3D;
s16 unk3E;
s16 unk40;
s16 unk42;
s16 unk44;
s16 unk46;
s16 unk48;
s16 unk4a;
s16 unk4c;
s16 vol[16];
s16 unk6E;
s16 unk70;
s16 unk72;
u16 unk74;
s16 unk76;
s16 unk78;
s16 unk7A;
s32 unk7c;
u32 unk80;
s32 unk84;
s32 delta_value;
s32 unk8c;
s32 unk90;
s32 unk94;
s32 unk98;
s32 unk9C;
s32 unkA0;
u32 unkA4;
s16 padA6;
s16 padaa;
};

#endif
45 changes: 45 additions & 0 deletions src/snd/ssinit.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#include "ssinit.h"

s32 _snd_openflag;
s32 VBLANK_MINUS;
SndSsMarkCallbackProc _SsMarkCallback[32][16];
struct SeqStruct* _ss_score[32];
s16 _snd_seq_s_max;
s16 _snd_seq_t_max;
s32 _snd_ev_flag;

static short D_80032EC0[] = {
0x0000, 0x0000, 0x1000, 0x3000, 0x00BF, 0x0000, 0x0000, 0x0000};

static short D_80032ED0[] = {
0x3FFF, 0x3FFF, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000};

void _SsInit(void) {
u16* var_a2;
int i, j;

var_a2 = (u16*)0x1F801C00;
for (i = 0; i < 24; i++) {
for (j = 0; j < 8; j++) {
*var_a2++ = D_80032EC0[j];
}
}

var_a2 = (u16*)0x1F801D80;
for (i = 0; i < 16; i++) {
*var_a2++ = D_80032ED0[i];
}

SpuVmInit(24);

for (j = 0; j < 32; j++) {
for (i = 0; i < 16; i++) {
_SsMarkCallback[j][i] = 0;
}
}

VBLANK_MINUS = 0x3C;
_snd_openflag = 0;
_snd_ev_flag = 0;
}
21 changes: 21 additions & 0 deletions src/snd/ssinit.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#include "../types.h"
#include "snd_defs.h"

extern s32 dummy_0;
extern s32 dummy_1;
extern s32 dummy_2;
extern s32 dummy_3;
extern s32 dummy_4;
extern s32 dummy_5;
extern s32 dummy_6;
extern s32 dummy_7;
extern s32 dummy_8;
extern s32 dummy_9;
extern s32 dummy_10;
extern SndSsMarkCallbackProc _SsMarkCallback[32][16]; /* #11 */
extern struct SeqStruct* _ss_score[32]; /* #12 */
extern s32 VBLANK_MINUS; /* #13 */
extern s32 _snd_openflag; /* #14 */
extern s16 _snd_seq_s_max; /* #15 */
extern s16 _snd_seq_t_max; /* #16 */
extern s32 _snd_ev_flag; /* #17 */

0 comments on commit 9f16b63

Please sign in to comment.