Add sound support (VAG/XA)
This commit is contained in:
parent
43dea98d63
commit
04a3bbbece
3
3dcam.cue
Normal file
3
3dcam.cue
Normal file
@ -0,0 +1,3 @@
|
||||
FILE "3dcam.bin" BINARY
|
||||
TRACK 01 MODE2/2352
|
||||
INDEX 01 00:00:00
|
@ -26,6 +26,7 @@ Real-time 3D / 8bpp background / 4bpp background
|
||||
* Up to 3 light sources
|
||||
* Use pre-rendered backgrounds (8bpp and 4bpp)
|
||||
* Basic collisions
|
||||
* Sound effects (VAG/XA)
|
||||
|
||||
### Demo Controls
|
||||
|
||||
@ -39,7 +40,6 @@ Real-time 3D / 8bpp background / 4bpp background
|
||||
## Planned
|
||||
|
||||
* Fix and improve all the things !
|
||||
* Wall collisions
|
||||
|
||||
# Compiling
|
||||
|
||||
|
8
XA/inter_0.txt
Normal file
8
XA/inter_0.txt
Normal file
@ -0,0 +1,8 @@
|
||||
1 xa /home/arthus/build/psxdev/blender_io_export_psx_mesh/XA/3_hehe.xa 0 0
|
||||
1 xa /home/arthus/build/psxdev/blender_io_export_psx_mesh/XA/3_hehe.xa 0 1
|
||||
1 xa /home/arthus/build/psxdev/blender_io_export_psx_mesh/XA/1_cuek.xa 0 2
|
||||
1 xa /home/arthus/build/psxdev/blender_io_export_psx_mesh/XA/1_cuek.xa 0 3
|
||||
1 xa /home/arthus/build/psxdev/blender_io_export_psx_mesh/XA/1_cuek.xa 0 4
|
||||
1 xa /home/arthus/build/psxdev/blender_io_export_psx_mesh/XA/3_hehe.xa 0 5
|
||||
1 null
|
||||
1 null
|
BIN
XA/inter_0.xa
Normal file
BIN
XA/inter_0.xa
Normal file
Binary file not shown.
@ -16,7 +16,8 @@
|
||||
<file name="SCES_313.37" type="data" source="main.ps-exe"/>
|
||||
<file name="LEVEL0.bin" type="data" source="Overlay.lvl0" />
|
||||
<file name="LEVEL1.bin" type="data" source="Overlay.lvl1" />
|
||||
<file name="INTER8.XA" type="xa" source="xa/inter8.xa"/>
|
||||
<file name="INTER8.XA" type="xa" source="XA/inter8.xa"/>
|
||||
<file name="INTER_0.XA" type="xa" source="/home/arthus/build/psxdev/3dcam-bak/XA/inter_0.xa"/>
|
||||
|
||||
<dummy sectors="1024"/>
|
||||
</directory_tree>
|
||||
|
242
custom_types.h
242
custom_types.h
@ -13,76 +13,80 @@ struct CAMANGLE;
|
||||
struct SIBLINGS;
|
||||
struct CHILDREN;
|
||||
struct NODE;
|
||||
struct QUAD;
|
||||
struct LEVEL;
|
||||
struct VAGsound;
|
||||
struct VAGbank;
|
||||
struct XAbank;
|
||||
struct XAsound;
|
||||
struct XAbank;
|
||||
struct XAfiles;
|
||||
struct SOUND_OBJECT;
|
||||
struct LEVEL_SOUNDS;
|
||||
|
||||
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 :
|
||||
@ -92,77 +96,97 @@ 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;
|
||||
|
||||
//VAG
|
||||
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;
|
||||
|
||||
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;
|
||||
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;
|
||||
u_int id;
|
||||
u_int size;
|
||||
u_char file, channel;
|
||||
u_int start, end;
|
||||
int cursor;
|
||||
} XAsound;
|
||||
|
||||
typedef struct XAbank {
|
||||
char name[16];
|
||||
u_int index;
|
||||
int offset;
|
||||
XAsound samples[];
|
||||
} XAbank;
|
||||
char name[16];
|
||||
u_int index;
|
||||
int offset;
|
||||
XAsound samples[];
|
||||
} XAbank;
|
||||
|
||||
typedef struct XAfiles {
|
||||
u_int index;
|
||||
XAbank * banks[];
|
||||
} XAfiles;
|
||||
|
||||
typedef struct SOUND_OBJECT {
|
||||
VECTOR location;
|
||||
int volume, volume_min, volume_max;
|
||||
VAGsound * VAGsample;
|
||||
XAsound * XAsample;
|
||||
MESH * parent;
|
||||
} SOUND_OBJECT;
|
||||
|
||||
typedef struct LEVEL_SOUNDS {
|
||||
int index;
|
||||
SOUND_OBJECT * sounds[];
|
||||
} LEVEL_SOUNDS;
|
||||
|
||||
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;
|
||||
VAGbank * VAG;
|
||||
XAbank * XA;
|
||||
} 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_SOUNDS * levelSounds;
|
||||
VAGbank * VAG;
|
||||
XAfiles * XA;
|
||||
} LEVEL;
|
||||
|
@ -10,7 +10,18 @@
|
||||
#define CLEAR_COLOR_G 0
|
||||
#define CLEAR_COLOR_B 0
|
||||
|
||||
#define CAM_DIST_TO_ACT 200
|
||||
#define CAM_DIST_TO_GND 100
|
||||
|
||||
// Sound
|
||||
// Sound engine
|
||||
#define SND_DIST_MIN 200
|
||||
#define SND_DIST_MAX 1200
|
||||
#define SND_ATTENUATION 6144
|
||||
#define SND_MAX_VOL 16383
|
||||
#define SND_RANGE (SND_DIST_MAX-SND_DIST_MIN)
|
||||
#define SND_NMALIZED (SND_RANGE*SND_ATTENUATION/SND_MAX_VOL)
|
||||
// SPU channels
|
||||
#define SPU_00CH (0x1L<< 0)
|
||||
#define SPU_01CH (0x1L<< 1)
|
||||
#define SPU_02CH (0x1L<< 2)
|
||||
@ -19,7 +30,23 @@
|
||||
#define SPU_05CH (0x1L<< 5)
|
||||
#define SPU_06CH (0x1L<< 6)
|
||||
#define SPU_07CH (0x1L<< 7)
|
||||
#define SPU_08CH (0x1L<< 8)
|
||||
#define SPU_09CH (0x1L<< 9)
|
||||
#define SPU_10CH (0x1L<<10)
|
||||
#define SPU_11CH (0x1L<<11)
|
||||
#define SPU_12CH (0x1L<<12)
|
||||
#define SPU_13CH (0x1L<<13)
|
||||
#define SPU_14CH (0x1L<<14)
|
||||
#define SPU_15CH (0x1L<<15)
|
||||
#define SPU_16CH (0x1L<<16)
|
||||
#define SPU_17CH (0x1L<<17)
|
||||
#define SPU_18CH (0x1L<<18)
|
||||
#define SPU_19CH (0x1L<<19)
|
||||
|
||||
#define SPU_20CH (0x1L<<20)
|
||||
#define SPU_21CH (0x1L<<21)
|
||||
#define SPU_22CH (0x1L<<22)
|
||||
#define SPU_23CH (0x1L<<23)
|
||||
// CDDA / XA volume
|
||||
#define XA_CHANNELS 8
|
||||
#define MVOL_L 0x3fff
|
||||
|
@ -8,20 +8,8 @@
|
||||
#define XA_RATE 380
|
||||
// Number of XA samples ( != # of XA files )
|
||||
#define XA_TRACKS 2
|
||||
// VAG
|
||||
// Number of VAG files to load
|
||||
#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;
|
||||
// SPU
|
||||
#define MALLOC_MAX 48 // Max number of time we can call SpuMalloc
|
||||
// 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
|
||||
@ -33,28 +21,13 @@ 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;
|
||||
|
||||
//~ typedef struct XAbank {
|
||||
//~ char * name;
|
||||
//~ u_int index;
|
||||
//~ int offset;
|
||||
//~ XAsound samples[];
|
||||
//~ } XAbank;
|
||||
|
||||
// VAG playback
|
||||
void initSnd(SpuCommonAttr * spuSettings, char * spu_malloc_rec);
|
||||
void initSnd(SpuCommonAttr * spuSettings, char * spu_malloc_rec, u_int mallocMax);
|
||||
u_long sendVAGtoSPU(unsigned int VAG_data_size, u_char *VAG_data);
|
||||
void setVoiceAttr(SpuVoiceAttr * voiceAttributes, u_int pitch, long channel, u_long soundAddr );
|
||||
u_long setSPUtransfer(SpuVoiceAttr * voiceAttributes, VAGsound * sound);
|
||||
void playSFX(SpuVoiceAttr * voiceAttributes, VAGsound * sound);
|
||||
void setVAGvolume(SpuVoiceAttr * voiceAttributes, VAGsound * sound, int volume);
|
||||
void playSFX(SpuVoiceAttr * voiceAttributes, VAGsound * sound, int volume);
|
||||
// XA playback
|
||||
void XAsetup(void);
|
||||
void getXAoffset(LEVEL * level);
|
||||
|
2004
levels/level0.c
2004
levels/level0.c
File diff suppressed because it is too large
Load Diff
@ -36,6 +36,19 @@ extern MESH * level0_levelPtr;
|
||||
extern MESH * level0_propPtr;
|
||||
extern CAMANGLE * level0_camPtr;
|
||||
extern NODE * level0_curNode;
|
||||
extern VAGbank level0_VAGBank;
|
||||
extern XAbank level0_XABank_0;
|
||||
extern XAfiles level0_XAFiles;
|
||||
extern SOUND_OBJECT level0_Speaker;
|
||||
extern SOUND_OBJECT level0_Speaker_001;
|
||||
extern SOUND_OBJECT level0_Speaker_002;
|
||||
extern SOUND_OBJECT level0_Speaker_003;
|
||||
extern SOUND_OBJECT level0_Speaker_004;
|
||||
extern SOUND_OBJECT level0_Speaker_005;
|
||||
extern SOUND_OBJECT level0_Speaker_006;
|
||||
extern SOUND_OBJECT level0_Speaker_007;
|
||||
extern SOUND_OBJECT level0_Speaker_008;
|
||||
extern SOUND_OBJECT level0_Speaker_009;
|
||||
extern SOUND_OBJECT level0_Speaker_010;
|
||||
extern LEVEL_SOUNDS level0_sounds;
|
||||
extern NODE level0_nodePlane;
|
||||
extern VAGbank VAGBank0;
|
||||
extern XAbank XABank0;
|
||||
|
116
levels/level1.c
116
levels/level1.c
@ -11049,7 +11049,7 @@ 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 VAGBank1 = {
|
||||
VAGbank level1_VAGBank = {
|
||||
8,
|
||||
{
|
||||
{ &_binary_VAG_0_come_vag_start, SPU_00CH, 0 },
|
||||
@ -11059,13 +11059,13 @@ VAGbank VAGBank1 = {
|
||||
{ &_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 }
|
||||
{ &_binary_VAG_8_yooo_vag_start, SPU_07CH, 0 },
|
||||
}
|
||||
};
|
||||
|
||||
XAbank XABank1 = {
|
||||
XAbank level1_XABank_0 = {
|
||||
"\\INTER8.XA;1",
|
||||
8,
|
||||
2,
|
||||
0,
|
||||
{
|
||||
//channel 0
|
||||
@ -11074,6 +11074,109 @@ XAbank XABank1 = {
|
||||
}
|
||||
};
|
||||
|
||||
XAfiles level1_XAFiles = {
|
||||
1,
|
||||
{
|
||||
&level1_XABank_0
|
||||
}
|
||||
};
|
||||
|
||||
SOUND_OBJECT level1_Speaker = {
|
||||
{102,32,210},
|
||||
16383, 0, 16383,
|
||||
&level1_VAGBank.samples[0],
|
||||
0,
|
||||
&level1_meshCube
|
||||
};
|
||||
|
||||
SOUND_OBJECT level1_Speaker_001 = {
|
||||
{-82,28,210},
|
||||
16383, 0, 16383,
|
||||
&level1_VAGBank.samples[1],
|
||||
0,
|
||||
&level1_meshCube
|
||||
};
|
||||
|
||||
SOUND_OBJECT level1_Speaker_002 = {
|
||||
{-267,432,-146},
|
||||
16383, 0, 16383,
|
||||
&level1_VAGBank.samples[2],
|
||||
0,
|
||||
0
|
||||
};
|
||||
|
||||
SOUND_OBJECT level1_Speaker_003 = {
|
||||
{-101,156,253},
|
||||
16383, 0, 16383,
|
||||
&level1_VAGBank.samples[3],
|
||||
0,
|
||||
&level1_meshCube
|
||||
};
|
||||
|
||||
SOUND_OBJECT level1_Speaker_004 = {
|
||||
{83,161,253},
|
||||
16383, 0, 16383,
|
||||
&level1_VAGBank.samples[4],
|
||||
0,
|
||||
&level1_meshCube
|
||||
};
|
||||
|
||||
SOUND_OBJECT level1_Speaker_005 = {
|
||||
{76,-39,188},
|
||||
16383, 0, 16383,
|
||||
&level1_VAGBank.samples[5],
|
||||
0,
|
||||
&level1_meshCube
|
||||
};
|
||||
|
||||
SOUND_OBJECT level1_Speaker_006 = {
|
||||
{-108,-43,188},
|
||||
16383, 0, 16383,
|
||||
&level1_VAGBank.samples[6],
|
||||
0,
|
||||
&level1_meshCube
|
||||
};
|
||||
|
||||
SOUND_OBJECT level1_Speaker_007 = {
|
||||
{-352,55,234},
|
||||
16383, 0, 16383,
|
||||
&level1_VAGBank.samples[7],
|
||||
0,
|
||||
&level1_meshCube
|
||||
};
|
||||
|
||||
SOUND_OBJECT level1_Speaker_008 = {
|
||||
{-168,60,234},
|
||||
16383, 0, 16383,
|
||||
&level1_VAGBank.samples[8],
|
||||
0,
|
||||
&level1_meshCube
|
||||
};
|
||||
|
||||
SOUND_OBJECT level1_Speaker_009 = {
|
||||
{188,-156,143},
|
||||
16383, 0, 16383,
|
||||
0,
|
||||
&level1_XABank_0.samples[0],
|
||||
&level1_meshCube
|
||||
};
|
||||
|
||||
LEVEL_SOUNDS level1_sounds = {
|
||||
10,
|
||||
{
|
||||
&level1_Speaker,
|
||||
&level1_Speaker_001,
|
||||
&level1_Speaker_002,
|
||||
&level1_Speaker_003,
|
||||
&level1_Speaker_004,
|
||||
&level1_Speaker_005,
|
||||
&level1_Speaker_006,
|
||||
&level1_Speaker_007,
|
||||
&level1_Speaker_008,
|
||||
&level1_Speaker_009
|
||||
}
|
||||
};
|
||||
|
||||
LEVEL level1 = {
|
||||
&level1_BGc,
|
||||
&level1_BKc,
|
||||
@ -11088,6 +11191,7 @@ LEVEL level1 = {
|
||||
&level1_camPath,
|
||||
(CAMANGLE **)&level1_camAngles,
|
||||
&level1_nodegnd,
|
||||
&VAGBank1,
|
||||
&XABank1
|
||||
&level1_sounds,
|
||||
&level1_VAGBank,
|
||||
&level1_XAFiles
|
||||
};
|
||||
|
@ -44,7 +44,7 @@ void setCameraMode(LEVEL * curLvl, CAMERA * camera, VECTOR * posToActor, VECTOR
|
||||
switch (camMode){
|
||||
// Camera follows actor
|
||||
case 0 :
|
||||
dist = 200;
|
||||
dist = CAM_DIST_TO_ACT;
|
||||
setVector(dc_camPos, -(camera->x/ONE), -(camera->y/ONE), -(camera->z/ONE));
|
||||
angle->vy = -(curLvl->actorPtr->rot.vy / 2) + angleCam->vy;
|
||||
// Camera horizontal and vertical position
|
||||
@ -55,9 +55,9 @@ void setCameraMode(LEVEL * curLvl, CAMERA * camera, VECTOR * posToActor, VECTOR
|
||||
// Camera rotates continuously around actor
|
||||
case 1 :
|
||||
// Set distance between cam and actor
|
||||
dist = 150;
|
||||
dist = CAM_DIST_TO_ACT;
|
||||
// Set camera position
|
||||
setVector(dc_camPos, -(camera->x/ONE), 100, -(camera->z/ONE));
|
||||
setVector(dc_camPos, -(camera->x/ONE), CAM_DIST_TO_GND, -(camera->z/ONE));
|
||||
// Find new camera position
|
||||
getCameraXZ(&camera->x, &camera->z, curLvl->actorPtr->pos.vx, curLvl->actorPtr->pos.vz, angle->vy, dist);
|
||||
// Set rotation amount
|
||||
@ -105,7 +105,7 @@ void setCameraMode(LEVEL * curLvl, CAMERA * camera, VECTOR * posToActor, VECTOR
|
||||
// Using precalc sqrt
|
||||
dist = psqrt( (posToActor->vx * posToActor->vx ) + (posToActor->vz * posToActor->vz) );
|
||||
// Set camera position
|
||||
setVector(dc_camPos, 190, 100, 180);
|
||||
setVector(dc_camPos, 190, CAM_DIST_TO_GND, 180);
|
||||
break;
|
||||
// Flyby mode with LERP from camStart to camEnd
|
||||
case 4 :
|
||||
|
103
src/main.c
103
src/main.c
@ -37,7 +37,7 @@ u_long overlaySize = 0;
|
||||
#include "../levels/level1.h"
|
||||
|
||||
// Levels
|
||||
u_char level = 1;
|
||||
u_char level = 0;
|
||||
u_short levelWas = 0;
|
||||
u_short levelHasChanged = 0;
|
||||
// Overlay
|
||||
@ -199,17 +199,21 @@ int main() {
|
||||
// Time counter
|
||||
oldTime = GetRCnt(RCntCNT1);
|
||||
// Sound
|
||||
SpuInit();
|
||||
// Init sound settings
|
||||
initSnd(&spuSettings, spu_malloc_rec);
|
||||
SpuInit();
|
||||
//~ spuCDsetup(&spuSettings);
|
||||
XAsetup();
|
||||
for (u_short vag = 0; vag < VAG_NBR; vag++ ){
|
||||
//~ VAGBank.samples[vag].spu_address = setSPUtransfer(&voiceAttributes, &VAGBank.samples[vag]);
|
||||
curLvl.VAG->samples[vag].spu_address = setSPUtransfer(&voiceAttributes, &curLvl.VAG->samples[vag]);
|
||||
if (curLvl.VAG != 0){
|
||||
// Init sound settings
|
||||
initSnd(&spuSettings, spu_malloc_rec, curLvl.VAG->index );
|
||||
for (u_short vag = 0; vag < curLvl.VAG->index; vag++ ){
|
||||
curLvl.VAG->samples[vag].spu_address = setSPUtransfer(&voiceAttributes, &curLvl.VAG->samples[vag]);
|
||||
}
|
||||
}
|
||||
sample = 0;
|
||||
setXAsample(&curLvl.XA->samples[sample], &filter);
|
||||
if ( curLvl.XA != 0 ){
|
||||
sample = 0;
|
||||
setXAsample(&curLvl.XA->banks[1]->samples[sample], &filter);
|
||||
}
|
||||
|
||||
// Main loop
|
||||
//~ while ( VSync(VSYNC) ) {
|
||||
while ( 1 ) {
|
||||
@ -220,9 +224,9 @@ int main() {
|
||||
if (sample != -1 ){
|
||||
// Begin XA file playback...
|
||||
// if sample's cursor is 0
|
||||
if (curLvl.XA->samples[sample].cursor == 0){
|
||||
if (curLvl.XA->banks[0]->samples[sample].cursor == 0){
|
||||
// Convert sector number to CD position in min/second/frame and set CdlLOC accordingly.
|
||||
CdIntToPos(curLvl.XA->samples[sample].start + curLvl.XA->offset , &loc);
|
||||
CdIntToPos(curLvl.XA->banks[0]->samples[sample].start + curLvl.XA->banks[0]->offset , &loc);
|
||||
// Send CDROM read command
|
||||
CdControlF(CdlReadS, (u_char *)&loc);
|
||||
XATime = VSync(-1);
|
||||
@ -232,11 +236,11 @@ int main() {
|
||||
//~ if ((curLvl.XA->samples[sample].cursor += XA_CDSPEED) >= curLvl.XA->samples[sample].end - curLvl.XA->samples[sample].start ){
|
||||
//~ if ((curLvl.XA->samples[sample].cursor += (XA_CDSPEED*4096)/((400/(dt+1)+1)) ) >= (curLvl.XA->samples[sample].end - curLvl.XA->samples[sample].start)*4096 ){
|
||||
// XA playback has fixed rate
|
||||
if ((curLvl.XA->samples[sample].cursor += XA_CDSPEED / ((XA_RATE/(dt+1)+1)) ) >= (curLvl.XA->samples[sample].end - curLvl.XA->samples[sample].start) * ONE ){
|
||||
if ((curLvl.XA->banks[0]->samples[sample].cursor += XA_CDSPEED / ((XA_RATE/(dt+1)+1)) ) >= (curLvl.XA->banks[0]->samples[sample].end - curLvl.XA->banks[0]->samples[sample].start) * ONE ){
|
||||
//~ CdControlF(CdlStop,0);
|
||||
curLvl.XA->samples[sample].cursor = -1;
|
||||
curLvl.XA->banks[0]->samples[sample].cursor = -1;
|
||||
//~ sample = !sample;
|
||||
setXAsample(&curLvl.XA->samples[sample], &filter);
|
||||
setXAsample(&curLvl.XA->banks[0]->samples[sample], &filter);
|
||||
}
|
||||
}
|
||||
// Check if level has changed
|
||||
@ -277,14 +281,32 @@ int main() {
|
||||
// Set level lighting
|
||||
setLightEnv(draw, curLvl.BGc, curLvl.BKc);
|
||||
levelWas = level;
|
||||
// Change XA track
|
||||
XAsetup();
|
||||
sample = !sample;
|
||||
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);
|
||||
// TODO : move to functions
|
||||
if (curLvl.VAG != 0) {
|
||||
// Free SPU mem
|
||||
for (u_short vag = 0; vag < curLvl.VAG->index; vag++ ){
|
||||
//~ VAGBank.samples[vag].spu_address = setSPUtransfer(&voiceAttributes, &VAGBank.samples[vag]);
|
||||
SpuFree(curLvl.VAG->samples[vag].spu_address);
|
||||
}
|
||||
// Reinit SPU
|
||||
initSnd(&spuSettings, spu_malloc_rec, curLvl.VAG->index );
|
||||
// Load level VAGs
|
||||
for (u_short vag = 0; vag < curLvl.VAG->index; vag++ ){
|
||||
//~ //VAGBank.samples[vag].spu_address = setSPUtransfer(&voiceAttributes, &VAGBank.samples[vag]);
|
||||
curLvl.VAG->samples[vag].spu_address = setSPUtransfer(&voiceAttributes, &curLvl.VAG->samples[vag]);
|
||||
}
|
||||
}
|
||||
if (curLvl.XA != 0){
|
||||
// Change XA track
|
||||
XAsetup();
|
||||
//~ sample = !sample;
|
||||
curLvl.XA->banks[0]->samples[sample].cursor = -1;
|
||||
getXAoffset(&curLvl);
|
||||
setXAsample(&curLvl.XA->banks[0]->samples[sample], &filter);
|
||||
CdIntToPos( curLvl.XA->banks[0]->samples[sample].start + curLvl.XA->banks[0]->offset , &loc);
|
||||
// Send CDROM read command
|
||||
CdControlF(CdlReadS, (u_char *)&loc);
|
||||
}
|
||||
}
|
||||
//~ FntPrint("Ovl:%s\nLvl : %x\nLvl: %d %d \n%x", overlayFile, &level, level, levelWas, loadLvl);
|
||||
// atime is used for animations timing
|
||||
@ -296,18 +318,41 @@ int main() {
|
||||
// TODO : put in a function
|
||||
// Reset player/prop pos
|
||||
if(curLvl.actorPtr->pos.vy >= 200){
|
||||
playSFX(&voiceAttributes, &curLvl.VAG->samples[6]);
|
||||
playSFX(&voiceAttributes, curLvl.levelSounds->sounds[6]->VAGsample, curLvl.levelSounds->sounds[6]->volume);
|
||||
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, &curLvl.VAG->samples[3]);
|
||||
playSFX(&voiceAttributes, curLvl.levelSounds->sounds[3]->VAGsample, curLvl.levelSounds->sounds[3]->volume);
|
||||
copyVector(&curLvl.propPtr->body->position, &propStartPos );
|
||||
copyVector(&curLvl.propPtr->rot, &propStartRot );
|
||||
curLvl.propPtr->node = propStartNode;
|
||||
}
|
||||
// Sound
|
||||
if (curLvl.levelSounds != 0){
|
||||
//~ for(int snd = 0; snd < level0_sounds.index; snd++){
|
||||
for(int snd = 0; snd < curLvl.levelSounds->index; snd++){
|
||||
// TODO : move in playSFX()
|
||||
// update sound location if sound has a parent
|
||||
u_int r;
|
||||
// If parent is actor,
|
||||
if (curLvl.levelSounds->sounds[snd]->parent == curLvl.actorPtr && camMode <= 1){
|
||||
r = CAM_DIST_TO_ACT;
|
||||
} else if ( curLvl.levelSounds->sounds[snd]->parent != 0){
|
||||
VECTOR dist;
|
||||
copyVector(&curLvl.levelSounds->sounds[snd]->location, &curLvl.levelSounds->sounds[snd]->parent->pos);
|
||||
// Get distance between sound source and camera
|
||||
addVector2(camera.pos, &curLvl.levelSounds->sounds[snd]->location, &dist);
|
||||
r = psqrt((dist.vx * dist.vx) + (dist.vz * dist.vz));
|
||||
}
|
||||
curLvl.levelSounds->sounds[snd]->volume = (curLvl.levelSounds->sounds[snd]->volume_max/r) * SND_NMALIZED > SND_MAX_VOL ? SND_MAX_VOL :
|
||||
(curLvl.levelSounds->sounds[snd]->volume_max/r) * SND_NMALIZED < 0 ? 0 :
|
||||
(curLvl.levelSounds->sounds[snd]->volume_max/r) * SND_NMALIZED;
|
||||
//~ FntPrint("Vol %d\n", curLvl.levelSounds->sounds[snd]->volume);
|
||||
}
|
||||
}
|
||||
// Spatial partitioning
|
||||
if (curLvl.curNode){
|
||||
for ( int msh = 0; msh < curLvl.curNode->siblings->index; msh ++ ) {
|
||||
@ -431,6 +476,7 @@ int main() {
|
||||
//~ FntPrint("XA : %d\n", (XA_CDSPEED)/((400/(dt+1))+1) );
|
||||
//~ FntPrint("XA : %d\n", curLvl.XA->samples[sample].cursor );
|
||||
FntPrint("CamAngle : %d\n", curCamAngle);
|
||||
FntPrint("XA: %x", curLvl.XA);
|
||||
FntFlush(-1);
|
||||
display( &disp[db], &draw[db], otdisc[db], primbuff[db], &nextpri, &db);
|
||||
|
||||
@ -508,7 +554,7 @@ void callback() {
|
||||
} else {
|
||||
curLvl.actorPtr->isPrism = 1;
|
||||
}
|
||||
playSFX(&voiceAttributes, &curLvl.VAG->samples[0]);
|
||||
playSFX(&voiceAttributes, curLvl.levelSounds->sounds[0]->VAGsample, curLvl.levelSounds->sounds[0]->volume );
|
||||
//~ timer = 10;
|
||||
lastPad = PAD;
|
||||
}
|
||||
@ -516,7 +562,7 @@ void callback() {
|
||||
lastPad = PAD;
|
||||
}
|
||||
if ( PAD & Square && !( lastPad & Square ) ){
|
||||
playSFX(&voiceAttributes, &curLvl.VAG->samples[7]);
|
||||
playSFX(&voiceAttributes, curLvl.levelSounds->sounds[7]->VAGsample, curLvl.levelSounds->sounds[7]->volume);
|
||||
//~ sample = 0;
|
||||
//~ setXAsample(&XABank.samples[sample], &filter);
|
||||
lastPad = PAD;
|
||||
@ -527,18 +573,17 @@ void callback() {
|
||||
if ( PAD & Cross && !(lastPad & Cross) ){
|
||||
if (curLvl.actorPtr->body->gForce.vy == 0 && (curLvl.actorPtr->body->position.vy - curLvl.actorPtr->body->min.vy) == curLvl.levelPtr->body->min.vy ){
|
||||
// Use delta to find jump force
|
||||
//~ curLvl.actorPtr->body->gForce.vy = - ((200/((ONE/(dt<1?1:dt))<1?1:(ONE/(dt<1?1:dt))))*14);
|
||||
curLvl.actorPtr->body->gForce.vy = -200;
|
||||
}
|
||||
timer = 10;
|
||||
playSFX(&voiceAttributes, &curLvl.VAG->samples[4]);
|
||||
playSFX(&voiceAttributes, curLvl.levelSounds->sounds[4]->VAGsample, curLvl.levelSounds->sounds[4]->volume);
|
||||
lastPad = PAD;
|
||||
}
|
||||
if ( !(PAD & Cross) && lastPad & Cross ) {
|
||||
lastPad = PAD;
|
||||
}
|
||||
if ( PAD & Circle && !(PAD & lastPad) ){
|
||||
playSFX(&voiceAttributes, &curLvl.VAG->samples[5]);
|
||||
playSFX(&voiceAttributes, curLvl.levelSounds->sounds[5]->VAGsample, curLvl.levelSounds->sounds[5]->volume);
|
||||
lastPad = PAD;
|
||||
}
|
||||
if ( !(PAD & Circle) && lastPad & Circle ) {
|
||||
|
@ -106,6 +106,7 @@ void LvlPtrSet(LEVEL * curLevel, LEVEL * level){
|
||||
curLevel->curNode = level->curNode; // Blank
|
||||
curLevel->VAG = level->VAG;
|
||||
curLevel->XA = level->XA;
|
||||
curLevel->levelSounds = level->levelSounds;
|
||||
|
||||
//~ curLevel->actorPtr->body = level->actorPtr->body;
|
||||
// Move these to drawPoly()
|
||||
|
31
src/sound.c
31
src/sound.c
@ -2,9 +2,8 @@
|
||||
#include "../include/space.h"
|
||||
|
||||
// VAG playback
|
||||
void initSnd(SpuCommonAttr * spuSettings, char * spu_malloc_rec){
|
||||
|
||||
SpuInitMalloc(MALLOC_MAX, spu_malloc_rec); // Maximum number of blocks, mem. management table address.
|
||||
void initSnd(SpuCommonAttr * spuSettings, char * spu_malloc_rec, u_int mallocMax){
|
||||
SpuInitMalloc(mallocMax, spu_malloc_rec); // Maximum number of blocks, mem. management table address.
|
||||
spuSettings->mask = (SPU_COMMON_MVOLL | SPU_COMMON_MVOLR | SPU_COMMON_CDVOLL | SPU_COMMON_CDVOLR | SPU_COMMON_CDMIX ); // Mask which attributes to set
|
||||
spuSettings->mvol.left = MVOL_L; // Master volume left
|
||||
spuSettings->mvol.right = MVOL_R; // see libref47.pdf, p.1058
|
||||
@ -12,7 +11,7 @@ void initSnd(SpuCommonAttr * spuSettings, char * spu_malloc_rec){
|
||||
spuSettings->cd.volume.right = CDVOL_R;
|
||||
// Enable CD input ON
|
||||
spuSettings->cd.mix = SPU_ON;
|
||||
|
||||
// Apply settings
|
||||
SpuSetCommonAttr(spuSettings);
|
||||
// Set transfer mode
|
||||
SpuSetTransferMode(SPU_TRANSFER_BY_DMA);
|
||||
@ -68,21 +67,19 @@ u_long setSPUtransfer(SpuVoiceAttr * voiceAttributes, VAGsound * sound){
|
||||
SpuSetTransferStartAddr(spu_address); // Sets a starting address in the sound buffer
|
||||
transferred = sendVAGtoSPU(SWAP_ENDIAN32(VAGheader->dataSize), sound->VAGfile);
|
||||
setVoiceAttr(voiceAttributes, pitch, sound->spu_channel, spu_address);
|
||||
// Return 1 if ok, size transferred else.
|
||||
//~ if (transferred == SWAP_ENDIAN32(VAGheader->dataSize)){
|
||||
//~ return 1;
|
||||
//~ }
|
||||
//~ return transferred;
|
||||
return spu_address;
|
||||
}
|
||||
void playSFX(SpuVoiceAttr * voiceAttributes, VAGsound * sound){
|
||||
// Set voice volume to max
|
||||
void setVAGvolume(SpuVoiceAttr * voiceAttributes, VAGsound * sound, int volume){
|
||||
voiceAttributes->mask= ( SPU_VOICE_VOLL | SPU_VOICE_VOLR );
|
||||
voiceAttributes->voice = sound->spu_channel;
|
||||
// Range 0 - 3fff
|
||||
voiceAttributes->volume.left = VOICEVOL_L;
|
||||
voiceAttributes->volume.right = VOICEVOL_R;
|
||||
SpuSetVoiceAttr(voiceAttributes);
|
||||
voiceAttributes->volume.left = volume;
|
||||
voiceAttributes->volume.right = volume;
|
||||
SpuSetVoiceAttr(voiceAttributes);
|
||||
}
|
||||
void playSFX(SpuVoiceAttr * voiceAttributes, VAGsound * sound, int volume){
|
||||
// Set voice volume to sample volume
|
||||
setVAGvolume(voiceAttributes, sound, volume);
|
||||
// Play voice
|
||||
SpuSetKey(SpuOn, sound->spu_channel);
|
||||
}
|
||||
@ -101,9 +98,11 @@ void XAsetup(void){
|
||||
void getXAoffset(LEVEL * level){
|
||||
CdlFILE XAPos = {0};
|
||||
// Load XA file
|
||||
CdSearchFile(&XAPos, level->XA->name);
|
||||
//~ CdSearchFile(&XAPos, level->XA->name);
|
||||
CdSearchFile(&XAPos, level->XA->banks[0]->name);
|
||||
// Set cd head to start of file
|
||||
level->XA->offset = CdPosToInt(&XAPos.pos);
|
||||
//~ level->XA->offset = CdPosToInt(&XAPos.pos);
|
||||
level->XA->banks[0]->offset = CdPosToInt(&XAPos.pos);
|
||||
};
|
||||
void setXAsample(XAsound * sound, CdlFILTER * filter){
|
||||
filter->chan = sound->channel;
|
||||
|
BIN
xa/inter8.xa
BIN
xa/inter8.xa
Binary file not shown.
@ -1,8 +0,0 @@
|
||||
1 xa lobby.xa 1 0
|
||||
1 xa pixel.xa 1 1
|
||||
1 null
|
||||
1 null
|
||||
1 null
|
||||
1 null
|
||||
1 null
|
||||
1 null
|
BIN
xa/lobby.xa
BIN
xa/lobby.xa
Binary file not shown.
BIN
xa/pixel.xa
BIN
xa/pixel.xa
Binary file not shown.
Loading…
Reference in New Issue
Block a user