Move sounds to level file

This commit is contained in:
ABelliqueux 2021-08-16 14:42:07 +02:00
parent 95eb0ff24e
commit d662d0b465
10 changed files with 10866 additions and 10749 deletions

View File

@ -13,72 +13,74 @@ struct CAMANGLE;
struct SIBLINGS;
struct CHILDREN;
struct NODE;
struct QUAD;
struct LEVEL;
struct VAGsound;
struct VAGbank;
typedef struct BODY {
VECTOR gForce;
VECTOR position;
SVECTOR velocity;
int mass;
int invMass;
VECTOR min;
VECTOR max;
int restitution;
} BODY;
VECTOR gForce;
VECTOR position;
SVECTOR velocity;
int mass;
int invMass;
VECTOR min;
VECTOR max;
int restitution;
} BODY;
typedef struct VANIM {
int nframes; // number of frames e.g 20
int nvert; // number of vertices e.g 21
int cursor; // anim cursor
int lerpCursor; // anim cursor
int dir; // playback direction (1 or -1)
int interpolate; // use lerp to interpolate keyframes
SVECTOR data[]; // vertex pos as SVECTORs e.g 20 * 21 SVECTORS
} VANIM;
int nframes; // number of frames e.g 20
int nvert; // number of vertices e.g 21
int cursor; // anim cursor
int lerpCursor; // anim cursor
int dir; // playback direction (1 or -1)
int interpolate; // use lerp to interpolate keyframes
SVECTOR data[]; // vertex pos as SVECTORs e.g 20 * 21 SVECTORS
} VANIM;
typedef struct PRIM {
VECTOR order;
int code; // Same as POL3/POL4 codes : Code (F3 = 1, FT3 = 2, G3 = 3,
VECTOR order;
int code; // Same as POL3/POL4 codes : Code (F3 = 1, FT3 = 2, G3 = 3,
// GT3 = 4) Code (F4 = 5, FT4 = 6, G4 = 7, GT4 = 8)
} PRIM;
} PRIM;
typedef struct MESH {
int totalVerts;
TMESH * tmesh;
PRIM * index;
TIM_IMAGE * tim;
unsigned long * tim_data;
MATRIX mat;
VECTOR pos;
SVECTOR rot;
short isProp;
short isRigidBody;
short isStaticBody;
short isRound;
short isPrism;
short isAnim;
short isActor;
short isLevel;
short isWall;
short isBG;
short isSprite;
long p;
long OTz;
BODY * body;
VANIM * anim;
struct NODE * node;
VECTOR pos2D;
} MESH;
int totalVerts;
TMESH * tmesh;
PRIM * index;
TIM_IMAGE * tim;
unsigned long * tim_data;
MATRIX mat;
VECTOR pos;
SVECTOR rot;
short isProp;
short isRigidBody;
short isStaticBody;
short isRound;
short isPrism;
short isAnim;
short isActor;
short isLevel;
short isWall;
short isBG;
short isSprite;
long p;
long OTz;
BODY * body;
VANIM * anim;
struct NODE * node;
VECTOR pos2D;
} MESH;
typedef struct QUAD {
VECTOR v0, v1;
VECTOR v2, v3;
} QUAD;
VECTOR v0, v1;
VECTOR v2, v3;
} QUAD;
typedef struct CAMPOS {
SVECTOR pos;
SVECTOR rot;
} CAMPOS;
SVECTOR pos;
SVECTOR rot;
} CAMPOS;
// Blender cam ~= PSX cam with these settings :
@ -88,48 +90,77 @@ typedef struct CAMPOS {
// Lower values mean wider angle
typedef struct CAMANGLE {
CAMPOS * campos;
TIM_IMAGE * BGtim;
unsigned long * tim_data;
QUAD bw, fw;
int index;
MESH * objects[];
} CAMANGLE;
CAMPOS * campos;
TIM_IMAGE * BGtim;
unsigned long * tim_data;
QUAD bw, fw;
int index;
MESH * objects[];
} CAMANGLE;
typedef struct CAMPATH {
short len, cursor, pos;
VECTOR points[];
} CAMPATH;
short len, cursor, pos;
VECTOR points[];
} CAMPATH;
typedef struct SIBLINGS {
int index;
struct NODE * list[];
} SIBLINGS ;
int index;
struct NODE * list[];
} SIBLINGS ;
typedef struct CHILDREN {
int index;
MESH * list[];
} CHILDREN ;
int index;
MESH * list[];
} CHILDREN ;
typedef struct NODE {
MESH * plane;
SIBLINGS * siblings;
CHILDREN * objects;
CHILDREN * rigidbodies;
} NODE;
MESH * plane;
SIBLINGS * siblings;
CHILDREN * objects;
CHILDREN * rigidbodies;
} NODE;
typedef struct VAGsound {
u_char * VAGfile; // Pointer to VAG data address
u_long spu_channel; // SPU voice to playback to
u_long spu_address; // SPU address for memory freeing spu mem
} VAGsound;
typedef struct VAGbank {
u_int index;
VAGsound samples[];
} VAGbank;
// XA
typedef struct XAsound {
u_int id;
u_int size;
u_char file, channel;
u_int start, end;
int cursor;
} XAsound;
typedef struct XAbank {
char * name;
u_int index;
int offset;
XAsound samples[];
} XAbank;
typedef struct LEVEL {
CVECTOR * BGc;
VECTOR * BKc;
MATRIX * cmat;
MATRIX * lgtmat;
MESH ** meshes;
int * meshes_length;
MESH * actorPtr;
MESH * levelPtr;
MESH * propPtr;
CAMANGLE * camPtr;
CAMPATH * camPath;
CAMANGLE ** camAngles;
NODE * curNode;
} LEVEL;
CVECTOR * BGc;
VECTOR * BKc;
MATRIX * cmat;
MATRIX * lgtmat;
MESH ** meshes;
int * meshes_length;
MESH * actorPtr;
MESH * levelPtr;
MESH * propPtr;
CAMANGLE * camPtr;
CAMPATH * camPath;
CAMANGLE ** camAngles;
NODE * curNode;
VAGbank * VAG;
XAbank * XA;
} LEVEL;

View File

@ -11,7 +11,17 @@
#define CLEAR_COLOR_B 0
// Sound
#define SPU_00CH (0x1L<< 0)
#define SPU_01CH (0x1L<< 1)
#define SPU_02CH (0x1L<< 2)
#define SPU_03CH (0x1L<< 3)
#define SPU_04CH (0x1L<< 4)
#define SPU_05CH (0x1L<< 5)
#define SPU_06CH (0x1L<< 6)
#define SPU_07CH (0x1L<< 7)
// CDDA / XA volume
#define XA_CHANNELS 8
#define MVOL_L 0x3fff
#define MVOL_R 0x3fff
#define CDVOL_L 0x7fff
@ -23,11 +33,11 @@
#define FNT_VRAM_X 960
#define FNT_VRAM_Y 256
#define FNT_SCR_X 16
#define FNT_SCR_Y 192
#define FNT_SCR_Y 32
#define FNT_SCR_W 240
#define FNT_SCR_H 48
#define FNT_SCR_BG 0
#define FNT_SCR_MAX_CHAR 256
#define FNT_SCR_MAX_CHAR 512
// Ordering table
#define OT2LEN 8

View File

@ -12,15 +12,15 @@
#define VAG_NBR 8
#define MALLOC_MAX VAG_NBR // Max number of time we can call SpuMalloc
// Custom struct to handle VAG files
typedef struct VAGsound {
u_char * VAGfile; // Pointer to VAG data address
u_long spu_channel; // SPU voice to playback to
u_long spu_address; // SPU address for memory freeing spu mem
} VAGsound;
typedef struct VAGbank {
u_int index;
VAGsound samples[];
} VAGbank;
//~ typedef struct VAGsound {
//~ u_char * VAGfile; // Pointer to VAG data address
//~ u_long spu_channel; // SPU voice to playback to
//~ u_long spu_address; // SPU address for memory freeing spu mem
//~ } VAGsound;
//~ typedef struct VAGbank {
//~ u_int index;
//~ VAGsound samples[];
//~ } VAGbank;
// VAG header struct (see fileformat47.pdf, p.209)
typedef struct VAGhdr { // All the values in this header must be big endian
char id[4]; // VAGp 4 bytes -> 1 char * 4
@ -32,20 +32,21 @@ typedef struct VAGhdr { // All the values in this header must be
char name[16]; // 16 bytes -> 1 char * 16
// Waveform data after that
} VAGhdr;
// XA
typedef struct XAsound {
u_int id;
u_int size;
u_char file, channel;
u_int start, end;
int cursor;
} XAsound;
//~ // XA
//~ typedef struct XAsound {
//~ u_int id;
//~ u_int size;
//~ u_char file, channel;
//~ u_int start, end;
//~ int cursor;
//~ } XAsound;
typedef struct XAbank {
u_int index;
int offset;
XAsound samples[];
} XAbank;
//~ typedef struct XAbank {
//~ char * name;
//~ u_int index;
//~ int offset;
//~ XAsound samples[];
//~ } XAbank;
// VAG playback
void initSnd(SpuCommonAttr * spuSettings, char * spu_malloc_rec);

View File

@ -990,6 +990,43 @@ CAMANGLE * level0_camPtr = &level0_camAngle_Camera;
NODE * level0_curNode = &level0_nodePlane;
// extern VAG files
extern u_char _binary_VAG_0_come_vag_start;
extern u_char _binary_VAG_1_cuek_vag_start;
extern u_char _binary_VAG_2_erro_vag_start;
extern u_char _binary_VAG_3_hehe_vag_start;
extern u_char _binary_VAG_4_m4a1_vag_start;
extern u_char _binary_VAG_5_punc_vag_start;
extern u_char _binary_VAG_7_wron_vag_start;
extern u_char _binary_VAG_8_yooo_vag_start;
// soundBank
VAGbank VAGBank0 = {
8,
{
{ &_binary_VAG_0_come_vag_start, SPU_00CH, 0 },
{ &_binary_VAG_1_cuek_vag_start, SPU_01CH, 0 },
{ &_binary_VAG_2_erro_vag_start, SPU_02CH, 0 },
{ &_binary_VAG_3_hehe_vag_start, SPU_03CH, 0 },
{ &_binary_VAG_4_m4a1_vag_start, SPU_04CH, 0 },
{ &_binary_VAG_5_punc_vag_start, SPU_05CH, 0 },
{ &_binary_VAG_7_wron_vag_start, SPU_06CH, 0 },
{ &_binary_VAG_8_yooo_vag_start, SPU_07CH, 0 }
}
};
XAbank XABank0 = {
"\\INTER8.XA;1",
8,
0,
{
//channel 0
{ 0, 698464, 1, 0, 0, ((698464/2336)-1) * XA_CHANNELS, -1 },
{ 1, 366752, 1, 1 , 0, ((366752/2336)-1) * XA_CHANNELS, -1 },
}
};
// XA file to load
//~ static char * loadXA0 = "\\INTER8.XA;1";
LEVEL level0 = {
&level0_BGc,
&level0_BKc,
@ -1004,4 +1041,6 @@ LEVEL level0 = {
&level0_camPath,
(CAMANGLE **)&level0_camAngles,
&level0_nodePlane,
&VAGBank0,
&XABank0
};

View File

@ -1,5 +1,7 @@
#pragma once
#include "../custom_types.h"
#include "../include/defines.h"
extern LEVEL level0;
extern CVECTOR level0_BGc;
extern VECTOR level0_BKc;
@ -35,3 +37,6 @@ extern MESH * level0_propPtr;
extern CAMANGLE * level0_camPtr;
extern NODE * level0_curNode;
extern NODE level0_nodePlane;
extern VAGbank VAGBank0;
extern XAbank XABank0;
//~ extern char * loadXA0;

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,6 @@
#pragma once
#include "../custom_types.h"
#include "../include/defines.h"
extern LEVEL level1;
extern CVECTOR level1_BGc;
@ -176,3 +176,6 @@ extern NODE level1_nodegnd_001;
extern NODE level1_nodegnd_003;
extern NODE level1_nodegnd_002;
extern NODE level1_nodegnd;
extern VAGbank VAGBank1;
extern XAbank XABank1;
//~ extern char * loadXA1;

View File

@ -114,53 +114,40 @@ char spu_malloc_rec[SPU_MALLOC_RECSIZ * (2 + MALLOC_MAX + 1)];
SpuCommonAttr spuSettings; // structure for changing common voice attributes
SpuVoiceAttr voiceAttributes ; // structure for changing individual voice attributes
// extern VAG files
extern u_char _binary_VAG_0_come_vag_start;
extern u_char _binary_VAG_1_cuek_vag_start;
extern u_char _binary_VAG_2_erro_vag_start;
extern u_char _binary_VAG_3_hehe_vag_start;
extern u_char _binary_VAG_4_m4a1_vag_start;
extern u_char _binary_VAG_5_punc_vag_start;
extern u_char _binary_VAG_7_wron_vag_start;
extern u_char _binary_VAG_8_yooo_vag_start;
//~ extern u_char _binary_VAG_0_come_vag_start;
//~ extern u_char _binary_VAG_1_cuek_vag_start;
//~ extern u_char _binary_VAG_2_erro_vag_start;
//~ extern u_char _binary_VAG_3_hehe_vag_start;
//~ extern u_char _binary_VAG_4_m4a1_vag_start;
//~ extern u_char _binary_VAG_5_punc_vag_start;
//~ extern u_char _binary_VAG_7_wron_vag_start;
//~ extern u_char _binary_VAG_8_yooo_vag_start;
// soundBank
VAGbank VAGBank = {
8,
{
{ &_binary_VAG_0_come_vag_start, SPU_00CH, 0 },
{ &_binary_VAG_1_cuek_vag_start, SPU_01CH, 0 },
{ &_binary_VAG_2_erro_vag_start, SPU_02CH, 0 },
{ &_binary_VAG_3_hehe_vag_start, SPU_03CH, 0 },
{ &_binary_VAG_4_m4a1_vag_start, SPU_04CH, 0 },
{ &_binary_VAG_5_punc_vag_start, SPU_05CH, 0 },
{ &_binary_VAG_7_wron_vag_start, SPU_06CH, 0 },
{ &_binary_VAG_8_yooo_vag_start, SPU_07CH, 0 }
}
};
//~ VAGbank VAGBank = {
//~ 8,
//~ {
//~ { &_binary_VAG_0_come_vag_start, SPU_00CH, 0 },
//~ { &_binary_VAG_1_cuek_vag_start, SPU_01CH, 0 },
//~ { &_binary_VAG_2_erro_vag_start, SPU_02CH, 0 },
//~ { &_binary_VAG_3_hehe_vag_start, SPU_03CH, 0 },
//~ { &_binary_VAG_4_m4a1_vag_start, SPU_04CH, 0 },
//~ { &_binary_VAG_5_punc_vag_start, SPU_05CH, 0 },
//~ { &_binary_VAG_7_wron_vag_start, SPU_06CH, 0 },
//~ { &_binary_VAG_8_yooo_vag_start, SPU_07CH, 0 }
//~ }
//~ };
// XA playback
XAbank XABank = {
8,
0,
{
//channel 0
{ 0, 698464, 1, 0, 0, ((698464/2336)-1) * XA_CHANNELS, -1 },
{ 1, 366752, 1, 1 , 0, ((366752/2336)-1) * XA_CHANNELS, -1 },
//~ // channel 5
//~ // id size file channel start end cursor
//~ { 0, 18688, 0, 5, 0, 56, -1 },
//~ { 1, 44384, 0, 5 , 144, 288, -1 },
//~ // channel 6
//~ { 2, 32704, 0, 6 , 0, 104, -1 },
//~ { 3, 56064, 0, 6 , 196, 380, -1 },
//~ { 4, 53728, 0, 6 , 468, 644, -1 },
//~ // channel 7
//~ { 5, 84096, 0, 7 , 0, 260, -1 },
//~ { 6, 16352, 0, 7 , 368, 440, -1 },
//~ // channel 8
//~ { 7, 114464, 0, 8 , 0, 384, -1 }
}
};
// XA file to load
static char * loadXA = "\\INTER8.XA;1";
//~ XAbank XABank = {
//~ 8,
//~ 0,
//~ {
//~ //channel 0
//~ { 0, 698464, 1, 0, 0, ((698464/2336)-1) * XA_CHANNELS, -1 },
//~ { 1, 366752, 1, 1 , 0, ((366752/2336)-1) * XA_CHANNELS, -1 },
//~ }
//~ };
//~ // XA file to load
//~ static char * loadXA = "\\INTER8.XA;1";
// File informations : pos, size, name
CdlFILE XAPos = {0};
// CD filter
@ -192,9 +179,9 @@ int main() {
// Load level
LoadLevelCD(overlayFile, &load_all_overlays_here);
// Load XA file
CdSearchFile( &XAPos, loadXA);
CdSearchFile( &XAPos, curLvl.XA->name);
// Set cd head to start of file
XABank.offset = CdPosToInt(&XAPos.pos);
curLvl.XA->offset = CdPosToInt(&XAPos.pos);
#endif
// TODO : Add switch case to get the correct pointers
// Get needed pointers from level file
@ -252,10 +239,11 @@ int main() {
//~ spuCDsetup(&spuSettings);
XAsetup();
for (u_short vag = 0; vag < VAG_NBR; vag++ ){
VAGBank.samples[vag].spu_address = setSPUtransfer(&voiceAttributes, &VAGBank.samples[vag]);
//~ VAGBank.samples[vag].spu_address = setSPUtransfer(&voiceAttributes, &VAGBank.samples[vag]);
curLvl.VAG->samples[vag].spu_address = setSPUtransfer(&voiceAttributes, &curLvl.VAG->samples[vag]);
}
sample = 0;
setXAsample(&XABank.samples[sample], &filter);
setXAsample(&curLvl.XA->samples[sample], &filter);
// Main loop
while ( VSync(VSYNC) ) {
dt = GetRCnt(RCntCNT1) - oldTime;
@ -266,20 +254,20 @@ int main() {
// TODO : Fix XA playback with VSYNC = 1
// Begin XA file playback...
// if sample's cursor is 0
if (XABank.samples[sample].cursor == 0){
if (curLvl.XA->samples[sample].cursor == 0){
// Convert sector number to CD position in min/second/frame and set CdlLOC accordingly.
CdIntToPos( XABank.samples[sample].start + XABank.offset , &loc);
CdIntToPos( curLvl.XA->samples[sample].start + curLvl.XA->offset , &loc);
// Send CDROM read command
CdControlF(CdlReadS, (u_char *)&loc);
XATime = VSync(-1);
// Set playing flag
}
// if sample's cursor is close to sample's end position, stop playback
if ((XABank.samples[sample].cursor += XA_CDSPEED) >= XABank.samples[sample].end - XABank.samples[sample].start ){
if ((curLvl.XA->samples[sample].cursor += XA_CDSPEED) >= curLvl.XA->samples[sample].end - curLvl.XA->samples[sample].start ){
//~ CdControlF(CdlStop,0);
XABank.samples[sample].cursor = -1;
curLvl.XA->samples[sample].cursor = -1;
//~ sample = !sample;
setXAsample(&XABank.samples[sample], &filter);
setXAsample(&curLvl.XA->samples[sample], &filter);
}
}
// Check if level has changed
@ -323,9 +311,9 @@ int main() {
// Change XA track
XAsetup();
sample = !sample;
XABank.samples[sample].cursor = -1;
setXAsample(&XABank.samples[sample], &filter);
CdIntToPos( XABank.samples[sample].start + XABank.offset , &loc);
curLvl.XA->samples[sample].cursor = -1;
setXAsample(&curLvl.XA->samples[sample], &filter);
CdIntToPos( curLvl.XA->samples[sample].start + curLvl.XA->offset , &loc);
// Send CDROM read command
CdControlF(CdlReadS, (u_char *)&loc);
}
@ -339,14 +327,14 @@ int main() {
// TODO : put in a function
// Reset player/prop pos
if(curLvl.actorPtr->pos.vy >= 200){
playSFX(&voiceAttributes, &VAGBank.samples[6]);
playSFX(&voiceAttributes, &curLvl.VAG->samples[6]);
copyVector(&curLvl.actorPtr->body->position, &actorStartPos );
copyVector(&curLvl.actorPtr->rot, &actorStartRot );
curLvl.curNode = actorStartNode;
curLvl.levelPtr = curLvl.curNode->plane;
}
if(curLvl.propPtr->pos.vy >= 200){
playSFX(&voiceAttributes, &VAGBank.samples[3]);
playSFX(&voiceAttributes, &curLvl.VAG->samples[3]);
copyVector(&curLvl.propPtr->body->position, &propStartPos );
copyVector(&curLvl.propPtr->rot, &propStartRot );
curLvl.propPtr->node = propStartNode;
@ -468,7 +456,6 @@ int main() {
// Add secondary OT to main OT
AddPrims(otdisc[db], ot[db] + OTLEN - 1, ot[db]);
//~ FntPrint("\nTime : %d\n", time);
FntPrint("\n#Tri : %d\n", triCount);
FntPrint("#RCnt : %d %d %d\n", VSync(-1), XA_CDSPEED, dt);
FntPrint("CamAngle : %d\n", curCamAngle);
@ -548,7 +535,7 @@ void callback() {
} else {
curLvl.actorPtr->isPrism = 1;
}
playSFX(&voiceAttributes, &VAGBank.samples[0]);
playSFX(&voiceAttributes, &curLvl.VAG->samples[0]);
//~ timer = 10;
lastPad = PAD;
}
@ -556,7 +543,7 @@ void callback() {
lastPad = PAD;
}
if ( PAD & Square && !( lastPad & Square ) ){
playSFX(&voiceAttributes, &VAGBank.samples[7]);
playSFX(&voiceAttributes, &curLvl.VAG->samples[7]);
//~ sample = 0;
//~ setXAsample(&XABank.samples[sample], &filter);
lastPad = PAD;
@ -571,14 +558,14 @@ void callback() {
curLvl.actorPtr->body->gForce.vy = -200;
}
timer = 10;
playSFX(&voiceAttributes, &VAGBank.samples[4]);
playSFX(&voiceAttributes, &curLvl.VAG->samples[4]);
lastPad = PAD;
}
if ( !(PAD & Cross) && lastPad & Cross ) {
lastPad = PAD;
}
if ( PAD & Circle && !(PAD & lastPad) ){
playSFX(&voiceAttributes, &VAGBank.samples[5]);
playSFX(&voiceAttributes, &curLvl.VAG->samples[5]);
lastPad = PAD;
}
if ( !(PAD & Circle) && lastPad & Circle ) {

View File

@ -103,6 +103,8 @@ void LvlPtrSet(LEVEL * curLevel, LEVEL * level){
curLevel->camPath = level->camPath;
curLevel->camAngles = level->camAngles;
curLevel->curNode = level->curNode; // Blank
curLevel->VAG = level->VAG; // Blank
curLevel->XA = level->XA; // Blank
//~ curLevel->actorPtr->body = level->actorPtr->body;
// Move these to drawPoly()

View File

@ -73,6 +73,7 @@ u_long setSPUtransfer(SpuVoiceAttr * voiceAttributes, VAGsound * sound){
//~ return 1;
//~ }
//~ return transferred;
FntPrint("Tr: %", transferred);
return spu_address;
}
void playSFX(SpuVoiceAttr * voiceAttributes, VAGsound * sound){