Add sound support (VAG/XA)

This commit is contained in:
ABelliqueux 2021-08-26 19:55:00 +02:00
parent 43dea98d63
commit 04a3bbbece
20 changed files with 1453 additions and 1157 deletions

BIN
3dcam.bin Normal file

Binary file not shown.

3
3dcam.cue Normal file
View File

@ -0,0 +1,3 @@
FILE "3dcam.bin" BINARY
TRACK 01 MODE2/2352
INDEX 01 00:00:00

View File

@ -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
View 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

Binary file not shown.

View File

@ -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>

View File

@ -13,11 +13,15 @@ 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;
@ -122,6 +126,7 @@ typedef struct NODE {
CHILDREN * rigidbodies;
} NODE;
//VAG
typedef struct VAGsound {
u_char * VAGfile; // Pointer to VAG data address
u_long spu_channel; // SPU voice to playback to
@ -149,6 +154,24 @@ typedef struct XAbank {
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;
@ -163,6 +186,7 @@ typedef struct LEVEL {
CAMPATH * camPath;
CAMANGLE ** camAngles;
NODE * curNode;
LEVEL_SOUNDS * levelSounds;
VAGbank * VAG;
XAbank * XA;
XAfiles * XA;
} LEVEL;

View File

@ -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

View File

@ -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);

View File

@ -1,8 +1,8 @@
#include "level0.h"
CVECTOR level0_BGc = { 135, 232, 230, 0 };
CVECTOR level0_BGc = { 134, 231, 229, 0 };
VECTOR level0_BKc = { 174, 174, 174, 0 };
VECTOR level0_BKc = { 173, 173, 173, 0 };
CAMPOS level0_camPos_Camera = {
{ -770,459,623 },
@ -29,14 +29,14 @@ MATRIX level0_cmat = {
};
SVECTOR level0_modelCube_mesh[] = {
{ -32,32,32 },
{ 32,32,32 },
{ 32,32,-33 },
{ -33,32,-32 },
{ -32,-32,33 },
{ 33,-32,32 },
{ 32,-32,-33 },
{ -33,-32,-32 }
{ -32,32,32,0 },
{ 32,32,32,0 },
{ 32,32,-33,0 },
{ -33,32,-32,0 },
{ -32,-32,33,0 },
{ 33,-32,32,0 },
{ 32,-32,-33,0 },
{ -33,-32,-32,0 }
};
SVECTOR level0_modelCube_normal[] = {
@ -90,8 +90,8 @@ BODY level0_modelCube_body = {
{0, 0, 0, 0},
0,-236,23, 0,
0,-1024,0, 0,
5,
ONE/5,
8,
ONE/8,
-33,-32,-33, 0,
33,32,33, 0,
0,
@ -111,9 +111,9 @@ MESH level0_meshCube = {
level0_modelCube_index,
0,
0,
{0},
{0,-236,23, 0},
{0,-1024,0, 0},
{0}, // Nbr of vertices
{0,-236,23, 0}, // position
{0,-1024,0, 0}, // rotation
1, // isProp
1, // isRigidBody
0, // isStaticBody
@ -125,136 +125,136 @@ MESH level0_meshCube = {
0, // isWall
0, // isBG
0,// isSprite
0,
0,
0, // p
0, // otz
&level0_modelCube_body,
0,
0, // No animation data
&level0_nodePlane,
0,
0 // Screen space coordinates
};
SVECTOR level0_modelPlane_mesh[] = {
{ -520,0,-520 },
{ 520,0,-520 },
{ -520,0,520 },
{ 520,0,520 },
{ -520,0,312 },
{ -520,0,104 },
{ -520,0,-104 },
{ -520,0,-312 },
{ -312,0,-520 },
{ -104,0,-520 },
{ 104,0,-520 },
{ 312,0,-520 },
{ 520,0,-312 },
{ 520,0,-104 },
{ 520,0,104 },
{ 520,0,312 },
{ 312,0,520 },
{ 104,0,520 },
{ -104,0,520 },
{ -312,0,520 },
{ -312,0,-312 },
{ -312,0,-104 },
{ -312,0,104 },
{ -312,0,312 },
{ -104,0,-312 },
{ -104,0,-104 },
{ -104,0,104 },
{ -104,0,312 },
{ 104,0,-312 },
{ 104,0,-104 },
{ 104,0,104 },
{ 104,0,312 },
{ 312,0,-312 },
{ 312,0,-104 },
{ 312,0,104 },
{ 312,0,312 },
{ -520,0,-416 },
{ 416,0,-520 },
{ 520,0,416 },
{ -416,0,520 },
{ -520,0,416 },
{ -520,0,208 },
{ -520,0,0 },
{ -520,0,-208 },
{ -416,0,-520 },
{ -208,0,-520 },
{ 0,0,-520 },
{ 208,0,-520 },
{ 520,0,-416 },
{ 520,0,-208 },
{ 520,0,0 },
{ 520,0,208 },
{ 416,0,520 },
{ 208,0,520 },
{ 0,0,520 },
{ -208,0,520 },
{ -312,0,416 },
{ -312,0,-416 },
{ -312,0,-208 },
{ -312,0,0 },
{ -312,0,208 },
{ -104,0,416 },
{ -104,0,-416 },
{ -104,0,-208 },
{ -104,0,0 },
{ -104,0,208 },
{ 104,0,416 },
{ 104,0,-416 },
{ 104,0,-208 },
{ 104,0,0 },
{ 104,0,208 },
{ 312,0,416 },
{ 312,0,-416 },
{ 312,0,-208 },
{ 312,0,0 },
{ 312,0,208 },
{ -416,0,-312 },
{ -416,0,-104 },
{ -416,0,104 },
{ -416,0,312 },
{ -208,0,-312 },
{ -208,0,-104 },
{ -208,0,104 },
{ -208,0,312 },
{ 0,0,-312 },
{ 0,0,-104 },
{ 0,0,104 },
{ 0,0,312 },
{ 208,0,-312 },
{ 208,0,-104 },
{ 208,0,104 },
{ 208,0,312 },
{ 416,0,-312 },
{ 416,0,-104 },
{ 416,0,104 },
{ 416,0,312 },
{ 416,0,208 },
{ 416,0,0 },
{ 416,0,-208 },
{ 416,0,-416 },
{ 208,0,208 },
{ 208,0,0 },
{ 208,0,-208 },
{ 208,0,-416 },
{ 0,0,208 },
{ 0,0,0 },
{ 0,0,-208 },
{ 0,0,-416 },
{ -208,0,208 },
{ -208,0,0 },
{ -208,0,-208 },
{ -208,0,-416 },
{ -416,0,208 },
{ -416,0,0 },
{ -416,0,-208 },
{ -416,0,-416 },
{ 208,0,416 },
{ 0,0,416 },
{ -208,0,416 },
{ -416,0,416 },
{ 416,0,416 }
{ -520,0,-520,0 },
{ 520,0,-520,0 },
{ -520,0,520,0 },
{ 520,0,520,0 },
{ -520,0,312,0 },
{ -520,0,104,0 },
{ -520,0,-104,0 },
{ -520,0,-312,0 },
{ -312,0,-520,0 },
{ -104,0,-520,0 },
{ 104,0,-520,0 },
{ 312,0,-520,0 },
{ 520,0,-312,0 },
{ 520,0,-104,0 },
{ 520,0,104,0 },
{ 520,0,312,0 },
{ 312,0,520,0 },
{ 104,0,520,0 },
{ -104,0,520,0 },
{ -312,0,520,0 },
{ -312,0,-312,0 },
{ -312,0,-104,0 },
{ -312,0,104,0 },
{ -312,0,312,0 },
{ -104,0,-312,0 },
{ -104,0,-104,0 },
{ -104,0,104,0 },
{ -104,0,312,0 },
{ 104,0,-312,0 },
{ 104,0,-104,0 },
{ 104,0,104,0 },
{ 104,0,312,0 },
{ 312,0,-312,0 },
{ 312,0,-104,0 },
{ 312,0,104,0 },
{ 312,0,312,0 },
{ -520,0,-416,0 },
{ 416,0,-520,0 },
{ 520,0,416,0 },
{ -416,0,520,0 },
{ -520,0,416,0 },
{ -520,0,208,0 },
{ -520,0,0,0 },
{ -520,0,-208,0 },
{ -416,0,-520,0 },
{ -208,0,-520,0 },
{ 0,0,-520,0 },
{ 208,0,-520,0 },
{ 520,0,-416,0 },
{ 520,0,-208,0 },
{ 520,0,0,0 },
{ 520,0,208,0 },
{ 416,0,520,0 },
{ 208,0,520,0 },
{ 0,0,520,0 },
{ -208,0,520,0 },
{ -312,0,416,0 },
{ -312,0,-416,0 },
{ -312,0,-208,0 },
{ -312,0,0,0 },
{ -312,0,208,0 },
{ -104,0,416,0 },
{ -104,0,-416,0 },
{ -104,0,-208,0 },
{ -104,0,0,0 },
{ -104,0,208,0 },
{ 104,0,416,0 },
{ 104,0,-416,0 },
{ 104,0,-208,0 },
{ 104,0,0,0 },
{ 104,0,208,0 },
{ 312,0,416,0 },
{ 312,0,-416,0 },
{ 312,0,-208,0 },
{ 312,0,0,0 },
{ 312,0,208,0 },
{ -416,0,-312,0 },
{ -416,0,-104,0 },
{ -416,0,104,0 },
{ -416,0,312,0 },
{ -208,0,-312,0 },
{ -208,0,-104,0 },
{ -208,0,104,0 },
{ -208,0,312,0 },
{ 0,0,-312,0 },
{ 0,0,-104,0 },
{ 0,0,104,0 },
{ 0,0,312,0 },
{ 208,0,-312,0 },
{ 208,0,-104,0 },
{ 208,0,104,0 },
{ 208,0,312,0 },
{ 416,0,-312,0 },
{ 416,0,-104,0 },
{ 416,0,104,0 },
{ 416,0,312,0 },
{ 416,0,208,0 },
{ 416,0,0,0 },
{ 416,0,-208,0 },
{ 416,0,-416,0 },
{ 208,0,208,0 },
{ 208,0,0,0 },
{ 208,0,-208,0 },
{ 208,0,-416,0 },
{ 0,0,208,0 },
{ 0,0,0,0 },
{ 0,0,-208,0 },
{ 0,0,-416,0 },
{ -208,0,208,0 },
{ -208,0,0,0 },
{ -208,0,-208,0 },
{ -208,0,-416,0 },
{ -416,0,208,0 },
{ -416,0,0,0 },
{ -416,0,-208,0 },
{ -416,0,-416,0 },
{ 208,0,416,0 },
{ 0,0,416,0 },
{ -208,0,416,0 },
{ -416,0,416,0 },
{ 416,0,416,0 }
};
SVECTOR level0_modelPlane_normal[] = {
@ -891,8 +891,8 @@ BODY level0_modelPlane_body = {
{0, 0, 0, 0},
0,0,0, 0,
0,0,0, 0,
100,
ONE/100,
10,
ONE/10,
-520,0,-520, 0,
520,0,520, 0,
0,
@ -912,10 +912,9 @@ MESH level0_meshPlane = {
level0_modelPlane_index,
0,
0,
{0},
{0,0,0, 0},
{0,0,0, 0},
0, // isWall
{0}, // Nbr of vertices
{0,0,0, 0}, // position
{0,0,0, 0}, // rotation
0, // isProp
0, // isRigidBody
0, // isStaticBody
@ -924,14 +923,15 @@ MESH level0_meshPlane = {
0, // isAnim
0, // isActor
1, // isLevel
0, // isWall
0, // isBG
0,// isSprite
0,
0,
0, // p
0, // otz
&level0_modelPlane_body,
0, // No animation data
0,
0,
0,
0 // Screen space coordinates
};
MESH * level0_meshes[2] = {
@ -990,38 +990,142 @@ 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,
VAGbank level0_VAGBank = {
10,
{
{ &_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_1_cuek_vag_start, SPU_00CH, 0 },
{ &_binary_VAG_3_hehe_vag_start, SPU_01CH, 0 },
{ &_binary_VAG_7_wron_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 }
{ &_binary_VAG_1_cuek_vag_start, SPU_04CH, 0 },
{ &_binary_VAG_1_cuek_vag_start, SPU_05CH, 0 },
{ &_binary_VAG_3_hehe_vag_start, SPU_06CH, 0 },
{ &_binary_VAG_3_hehe_vag_start, SPU_07CH, 0 },
{ &_binary_VAG_1_cuek_vag_start, SPU_08CH, 0 },
{ &_binary_VAG_3_hehe_vag_start, SPU_09CH, 0 }
}
};
XAbank XABank0 = {
"\\INTER8.XA;1",
8,
XAbank level0_XABank_0 = {
"\\INTER_0.XA;1",
1,
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 }
{ 0, 366752, 0, 0, 0, 156 * XA_CHANNELS, -1 },
}
};
XAfiles level0_XAFiles = {
1,
{
&level0_XABank_0
}
};
SOUND_OBJECT level0_Speaker = {
{102,32,210},
16383, 0, 16383,
&level0_VAGBank.samples[0],
0,
&level0_meshCube
};
SOUND_OBJECT level0_Speaker_001 = {
{-82,28,210},
16383, 0, 16383,
&level0_VAGBank.samples[1],
0,
&level0_meshCube
};
SOUND_OBJECT level0_Speaker_002 = {
{-267,432,-146},
16383, 0, 16383,
&level0_VAGBank.samples[2],
0,
0
};
SOUND_OBJECT level0_Speaker_003 = {
{-101,156,253},
16383, 0, 16383,
&level0_VAGBank.samples[3],
0,
&level0_meshCube
};
SOUND_OBJECT level0_Speaker_004 = {
{83,161,253},
16383, 0, 16383,
&level0_VAGBank.samples[4],
0,
&level0_meshCube
};
SOUND_OBJECT level0_Speaker_005 = {
{76,-39,188},
16383, 0, 16383,
&level0_VAGBank.samples[5],
0,
&level0_meshCube
};
SOUND_OBJECT level0_Speaker_006 = {
{-108,-43,188},
16383, 0, 16383,
&level0_VAGBank.samples[6],
0,
&level0_meshCube
};
SOUND_OBJECT level0_Speaker_007 = {
{-352,55,234},
16383, 0, 16383,
&level0_VAGBank.samples[7],
0,
&level0_meshCube
};
SOUND_OBJECT level0_Speaker_008 = {
{-168,60,234},
16383, 0, 16383,
&level0_VAGBank.samples[8],
0,
&level0_meshCube
};
SOUND_OBJECT level0_Speaker_009 = {
{188,-156,143},
16383, 0, 16383,
0,
&level0_XABank_0.samples[0],
&level0_meshCube
};
SOUND_OBJECT level0_Speaker_010 = {
{4,-160,143},
16383, 0, 16383,
&level0_VAGBank.samples[9],
0,
&level0_meshCube
};
LEVEL_SOUNDS level0_sounds = {
11,
{
&level0_Speaker,
&level0_Speaker_001,
&level0_Speaker_002,
&level0_Speaker_003,
&level0_Speaker_004,
&level0_Speaker_005,
&level0_Speaker_006,
&level0_Speaker_007,
&level0_Speaker_008,
&level0_Speaker_009,
&level0_Speaker_010
}
};
@ -1039,6 +1143,8 @@ LEVEL level0 = {
&level0_camPath,
(CAMANGLE **)&level0_camAngles,
&level0_nodePlane,
&VAGBank0,
&XABank0
&level0_sounds,
&level0_VAGBank,
&level0_XAFiles
};

View File

@ -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;

View File

@ -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
};

View File

@ -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 :

View File

@ -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
@ -200,16 +200,20 @@ int main() {
oldTime = GetRCnt(RCntCNT1);
// Sound
SpuInit();
// Init sound settings
initSnd(&spuSettings, spu_malloc_rec);
//~ spuCDsetup(&spuSettings);
XAsetup();
for (u_short vag = 0; vag < VAG_NBR; vag++ ){
//~ VAGBank.samples[vag].spu_address = setSPUtransfer(&voiceAttributes, &VAGBank.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]);
}
}
if ( curLvl.XA != 0 ){
sample = 0;
setXAsample(&curLvl.XA->samples[sample], &filter);
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,15 +281,33 @@ int main() {
// Set level lighting
setLightEnv(draw, curLvl.BGc, curLvl.BKc);
levelWas = level;
// 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->samples[sample].cursor = -1;
setXAsample(&curLvl.XA->samples[sample], &filter);
CdIntToPos( curLvl.XA->samples[sample].start + curLvl.XA->offset , &loc);
//~ 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
timediv = 1;
@ -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 ) {

View File

@ -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()

View File

@ -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;
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;

Binary file not shown.

View File

@ -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

Binary file not shown.

Binary file not shown.