Move sound playback to functions
This commit is contained in:
parent
04a3bbbece
commit
d578148edf
@ -161,7 +161,7 @@ typedef struct XAfiles {
|
||||
|
||||
typedef struct SOUND_OBJECT {
|
||||
VECTOR location;
|
||||
int volume, volume_min, volume_max;
|
||||
int volumeL, volumeR, volume_min, volume_max;
|
||||
VAGsound * VAGsample;
|
||||
XAsound * XAsample;
|
||||
MESH * parent;
|
||||
|
@ -60,9 +60,9 @@
|
||||
#define FNT_VRAM_X 960
|
||||
#define FNT_VRAM_Y 256
|
||||
#define FNT_SCR_X 16
|
||||
#define FNT_SCR_Y 168
|
||||
#define FNT_SCR_Y 128
|
||||
#define FNT_SCR_W 240
|
||||
#define FNT_SCR_H 48
|
||||
#define FNT_SCR_H 88
|
||||
#define FNT_SCR_BG 0
|
||||
#define FNT_SCR_MAX_CHAR 512
|
||||
|
||||
|
@ -18,3 +18,4 @@ void ResolveCollision( BODY * one, BODY * two );
|
||||
VECTOR angularMom(BODY body);
|
||||
void applyAcceleration(BODY * actor, int dt);
|
||||
u_int jump(BODY * actor, int dt);
|
||||
void respawnMesh(LEVEL * level, MESH * mesh, VECTOR * rot, VECTOR * pos, NODE * node);
|
||||
|
@ -1,5 +1,7 @@
|
||||
#pragma once
|
||||
#include "../include/psx.h"
|
||||
#include "../include/camera.h"
|
||||
#include "../include/math.h"
|
||||
#include "../include/macros.h"
|
||||
// XA
|
||||
// Sector offset for XA data 4: simple speed, 8: double speed
|
||||
@ -26,9 +28,13 @@ 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 setVAGvolume(SpuVoiceAttr * voiceAttributes, VAGsound * sound, int volume);
|
||||
void playSFX(SpuVoiceAttr * voiceAttributes, VAGsound * sound, int volume);
|
||||
void setVAGvolume(SpuVoiceAttr * voiceAttributes, VAGsound * sound, int volumeL,int volumeR);
|
||||
void setLvlVAG(LEVEL * level, SpuCommonAttr * spuSettings, SpuVoiceAttr * voiceAttributes, char spu_malloc_rec[]);
|
||||
void playSFX(SpuVoiceAttr * voiceAttributes, VAGsound * sound, int volumeL, int volumeR );
|
||||
VECTOR setSFXdist(LEVEL * level, CAMERA * camera, int camMode);
|
||||
// XA playback
|
||||
void XAsetup(void);
|
||||
void getXAoffset(LEVEL * level);
|
||||
void setXAsample(XAsound * sound, CdlFILTER * filter);
|
||||
void setLvlXA(LEVEL * level, int sample);
|
||||
void XAplayback(LEVEL * level, int sample, long dt);
|
||||
|
@ -6,7 +6,7 @@ VECTOR level0_BKc = { 173, 173, 173, 0 };
|
||||
|
||||
CAMPOS level0_camPos_Camera = {
|
||||
{ -770,459,623 },
|
||||
{ 301,531,0 }
|
||||
{ 301,-4096,0 }
|
||||
};
|
||||
|
||||
CAMPATH level0_camPath = {
|
||||
@ -1026,7 +1026,7 @@ XAfiles level0_XAFiles = {
|
||||
};
|
||||
SOUND_OBJECT level0_Speaker = {
|
||||
{102,32,210},
|
||||
16383, 0, 16383,
|
||||
16383, 16383, 0, 16383,
|
||||
&level0_VAGBank.samples[0],
|
||||
0,
|
||||
&level0_meshCube
|
||||
@ -1034,7 +1034,7 @@ SOUND_OBJECT level0_Speaker = {
|
||||
|
||||
SOUND_OBJECT level0_Speaker_001 = {
|
||||
{-82,28,210},
|
||||
16383, 0, 16383,
|
||||
16383, 16383, 0, 16383,
|
||||
&level0_VAGBank.samples[1],
|
||||
0,
|
||||
&level0_meshCube
|
||||
@ -1042,7 +1042,7 @@ SOUND_OBJECT level0_Speaker_001 = {
|
||||
|
||||
SOUND_OBJECT level0_Speaker_002 = {
|
||||
{-267,432,-146},
|
||||
16383, 0, 16383,
|
||||
16383, 16383, 0, 16383,
|
||||
&level0_VAGBank.samples[2],
|
||||
0,
|
||||
0
|
||||
@ -1050,7 +1050,7 @@ SOUND_OBJECT level0_Speaker_002 = {
|
||||
|
||||
SOUND_OBJECT level0_Speaker_003 = {
|
||||
{-101,156,253},
|
||||
16383, 0, 16383,
|
||||
16383, 16383, 0, 16383,
|
||||
&level0_VAGBank.samples[3],
|
||||
0,
|
||||
&level0_meshCube
|
||||
@ -1058,7 +1058,7 @@ SOUND_OBJECT level0_Speaker_003 = {
|
||||
|
||||
SOUND_OBJECT level0_Speaker_004 = {
|
||||
{83,161,253},
|
||||
16383, 0, 16383,
|
||||
16383, 16383, 0, 16383,
|
||||
&level0_VAGBank.samples[4],
|
||||
0,
|
||||
&level0_meshCube
|
||||
@ -1066,7 +1066,7 @@ SOUND_OBJECT level0_Speaker_004 = {
|
||||
|
||||
SOUND_OBJECT level0_Speaker_005 = {
|
||||
{76,-39,188},
|
||||
16383, 0, 16383,
|
||||
16383, 16383, 0, 16383,
|
||||
&level0_VAGBank.samples[5],
|
||||
0,
|
||||
&level0_meshCube
|
||||
@ -1074,7 +1074,7 @@ SOUND_OBJECT level0_Speaker_005 = {
|
||||
|
||||
SOUND_OBJECT level0_Speaker_006 = {
|
||||
{-108,-43,188},
|
||||
16383, 0, 16383,
|
||||
16383, 16383, 0, 16383,
|
||||
&level0_VAGBank.samples[6],
|
||||
0,
|
||||
&level0_meshCube
|
||||
@ -1082,7 +1082,7 @@ SOUND_OBJECT level0_Speaker_006 = {
|
||||
|
||||
SOUND_OBJECT level0_Speaker_007 = {
|
||||
{-352,55,234},
|
||||
16383, 0, 16383,
|
||||
16383, 16383, 0, 16383,
|
||||
&level0_VAGBank.samples[7],
|
||||
0,
|
||||
&level0_meshCube
|
||||
@ -1090,7 +1090,7 @@ SOUND_OBJECT level0_Speaker_007 = {
|
||||
|
||||
SOUND_OBJECT level0_Speaker_008 = {
|
||||
{-168,60,234},
|
||||
16383, 0, 16383,
|
||||
16383, 16383, 0, 16383,
|
||||
&level0_VAGBank.samples[8],
|
||||
0,
|
||||
&level0_meshCube
|
||||
@ -1098,7 +1098,7 @@ SOUND_OBJECT level0_Speaker_008 = {
|
||||
|
||||
SOUND_OBJECT level0_Speaker_009 = {
|
||||
{188,-156,143},
|
||||
16383, 0, 16383,
|
||||
16383, 16383, 0, 16383,
|
||||
0,
|
||||
&level0_XABank_0.samples[0],
|
||||
&level0_meshCube
|
||||
@ -1106,7 +1106,7 @@ SOUND_OBJECT level0_Speaker_009 = {
|
||||
|
||||
SOUND_OBJECT level0_Speaker_010 = {
|
||||
{4,-160,143},
|
||||
16383, 0, 16383,
|
||||
16383, 16383, 0, 16383,
|
||||
&level0_VAGBank.samples[9],
|
||||
0,
|
||||
&level0_meshCube
|
||||
|
@ -11083,7 +11083,7 @@ XAfiles level1_XAFiles = {
|
||||
|
||||
SOUND_OBJECT level1_Speaker = {
|
||||
{102,32,210},
|
||||
16383, 0, 16383,
|
||||
16383, 16383, 0, 16383,
|
||||
&level1_VAGBank.samples[0],
|
||||
0,
|
||||
&level1_meshCube
|
||||
@ -11091,7 +11091,7 @@ SOUND_OBJECT level1_Speaker = {
|
||||
|
||||
SOUND_OBJECT level1_Speaker_001 = {
|
||||
{-82,28,210},
|
||||
16383, 0, 16383,
|
||||
16383, 16383, 0, 16383,
|
||||
&level1_VAGBank.samples[1],
|
||||
0,
|
||||
&level1_meshCube
|
||||
@ -11099,7 +11099,7 @@ SOUND_OBJECT level1_Speaker_001 = {
|
||||
|
||||
SOUND_OBJECT level1_Speaker_002 = {
|
||||
{-267,432,-146},
|
||||
16383, 0, 16383,
|
||||
16383, 16383, 0, 16383,
|
||||
&level1_VAGBank.samples[2],
|
||||
0,
|
||||
0
|
||||
@ -11107,7 +11107,7 @@ SOUND_OBJECT level1_Speaker_002 = {
|
||||
|
||||
SOUND_OBJECT level1_Speaker_003 = {
|
||||
{-101,156,253},
|
||||
16383, 0, 16383,
|
||||
16383, 16383, 0, 16383,
|
||||
&level1_VAGBank.samples[3],
|
||||
0,
|
||||
&level1_meshCube
|
||||
@ -11115,7 +11115,7 @@ SOUND_OBJECT level1_Speaker_003 = {
|
||||
|
||||
SOUND_OBJECT level1_Speaker_004 = {
|
||||
{83,161,253},
|
||||
16383, 0, 16383,
|
||||
16383, 16383, 0, 16383,
|
||||
&level1_VAGBank.samples[4],
|
||||
0,
|
||||
&level1_meshCube
|
||||
@ -11123,7 +11123,7 @@ SOUND_OBJECT level1_Speaker_004 = {
|
||||
|
||||
SOUND_OBJECT level1_Speaker_005 = {
|
||||
{76,-39,188},
|
||||
16383, 0, 16383,
|
||||
16383, 16383, 0, 16383,
|
||||
&level1_VAGBank.samples[5],
|
||||
0,
|
||||
&level1_meshCube
|
||||
@ -11131,7 +11131,7 @@ SOUND_OBJECT level1_Speaker_005 = {
|
||||
|
||||
SOUND_OBJECT level1_Speaker_006 = {
|
||||
{-108,-43,188},
|
||||
16383, 0, 16383,
|
||||
16383, 16383, 0, 16383,
|
||||
&level1_VAGBank.samples[6],
|
||||
0,
|
||||
&level1_meshCube
|
||||
@ -11139,7 +11139,7 @@ SOUND_OBJECT level1_Speaker_006 = {
|
||||
|
||||
SOUND_OBJECT level1_Speaker_007 = {
|
||||
{-352,55,234},
|
||||
16383, 0, 16383,
|
||||
16383, 16383, 0, 16383,
|
||||
&level1_VAGBank.samples[7],
|
||||
0,
|
||||
&level1_meshCube
|
||||
@ -11147,7 +11147,7 @@ SOUND_OBJECT level1_Speaker_007 = {
|
||||
|
||||
SOUND_OBJECT level1_Speaker_008 = {
|
||||
{-168,60,234},
|
||||
16383, 0, 16383,
|
||||
16383, 16383, 0, 16383,
|
||||
&level1_VAGBank.samples[8],
|
||||
0,
|
||||
&level1_meshCube
|
||||
@ -11155,7 +11155,7 @@ SOUND_OBJECT level1_Speaker_008 = {
|
||||
|
||||
SOUND_OBJECT level1_Speaker_009 = {
|
||||
{188,-156,143},
|
||||
16383, 0, 16383,
|
||||
16383, 16383, 0, 16383,
|
||||
0,
|
||||
&level1_XABank_0.samples[0],
|
||||
&level1_meshCube
|
||||
|
142
src/main.c
142
src/main.c
@ -79,9 +79,9 @@ int dist = 150;
|
||||
int lerping = 0;
|
||||
short curCamAngle = 0;
|
||||
// Actor's forward vector (used for dualshock)
|
||||
VECTOR fVecActor = {0,0,0,0};
|
||||
VECTOR fVecActor;
|
||||
u_long triCount = 0;
|
||||
LEVEL curLvl = {0};
|
||||
LEVEL curLvl;
|
||||
LEVEL * loadLvl;
|
||||
// Actor start position
|
||||
VECTOR actorStartPos = {0};
|
||||
@ -95,7 +95,6 @@ NODE * propStartNode;
|
||||
void callback();
|
||||
// variable FPS
|
||||
long oldTime = 0;
|
||||
long XATime = 0;
|
||||
long dt = 0;
|
||||
// Physics/collisions
|
||||
short physics = 1;
|
||||
@ -113,10 +112,6 @@ char spu_malloc_rec[SPU_MALLOC_RECSIZ * (2 + MALLOC_MAX + 1)];
|
||||
// SPU settings
|
||||
SpuCommonAttr spuSettings; // structure for changing common voice attributes
|
||||
SpuVoiceAttr voiceAttributes ; // structure for changing individual voice attributes
|
||||
// CD filter
|
||||
CdlFILTER filter;
|
||||
// File position in m/s/f
|
||||
CdlLOC loc;
|
||||
// Keep track of XA Sample currently playing
|
||||
int sample = -1;
|
||||
|
||||
@ -149,13 +144,6 @@ int main() {
|
||||
} else if ( level == 1) {
|
||||
LvlPtrSet( &curLvl, &level1);
|
||||
}
|
||||
#ifdef USECD
|
||||
getXAoffset(&curLvl);
|
||||
//~ // Load XA file
|
||||
//~ CdSearchFile(&XAPos, curLvl.XA->name);
|
||||
//~ // Set cd head to start of file
|
||||
//~ curLvl.XA->offset = CdPosToInt(&XAPos.pos);
|
||||
#endif
|
||||
levelWas = level;
|
||||
// Copy light matrices / vector to scratchpad
|
||||
setDCLightEnv(curLvl.cmat, curLvl.lgtmat, &lgtang);
|
||||
@ -200,49 +188,18 @@ int main() {
|
||||
oldTime = GetRCnt(RCntCNT1);
|
||||
// Sound
|
||||
SpuInit();
|
||||
//~ spuCDsetup(&spuSettings);
|
||||
XAsetup();
|
||||
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 ){
|
||||
// Load level's VAGs to SPU
|
||||
setLvlVAG(&curLvl, &spuSettings, &voiceAttributes, spu_malloc_rec);
|
||||
// Set XA sample
|
||||
sample = 0;
|
||||
setXAsample(&curLvl.XA->banks[1]->samples[sample], &filter);
|
||||
}
|
||||
|
||||
setLvlXA(&curLvl, sample);
|
||||
// Main loop
|
||||
//~ while ( VSync(VSYNC) ) {
|
||||
while ( 1 ) {
|
||||
dt = GetRCnt(RCntCNT1) - oldTime;
|
||||
oldTime = GetRCnt(RCntCNT1);
|
||||
// XA playback
|
||||
// if sample is set
|
||||
if (sample != -1 ){
|
||||
// Begin XA file playback...
|
||||
// if sample's cursor is 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->banks[0]->samples[sample].start + curLvl.XA->banks[0]->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 ((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->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->banks[0]->samples[sample].cursor = -1;
|
||||
//~ sample = !sample;
|
||||
setXAsample(&curLvl.XA->banks[0]->samples[sample], &filter);
|
||||
}
|
||||
}
|
||||
// XA playback (keep track of playback and loop XA)
|
||||
XAplayback(&curLvl, sample, dt);
|
||||
// Check if level has changed
|
||||
// TODO : Proper level system / loader
|
||||
if ( levelWas != level ){
|
||||
@ -281,32 +238,10 @@ 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->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);
|
||||
}
|
||||
// Load level's VAGs to SPU
|
||||
setLvlVAG(&curLvl, &spuSettings, &voiceAttributes, spu_malloc_rec);
|
||||
// Set
|
||||
setLvlXA(&curLvl, sample);
|
||||
}
|
||||
//~ FntPrint("Ovl:%s\nLvl : %x\nLvl: %d %d \n%x", overlayFile, &level, level, levelWas, loadLvl);
|
||||
// atime is used for animations timing
|
||||
@ -318,41 +253,17 @@ int main() {
|
||||
// TODO : put in a function
|
||||
// Reset player/prop pos
|
||||
if(curLvl.actorPtr->pos.vy >= 200){
|
||||
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;
|
||||
playSFX(&voiceAttributes, curLvl.levelSounds->sounds[6]->VAGsample, curLvl.levelSounds->sounds[6]->volumeL, curLvl.levelSounds->sounds[6]->volumeR);
|
||||
respawnMesh(&curLvl, curLvl.actorPtr, &actorStartRot, &actorStartPos, actorStartNode );
|
||||
}
|
||||
if(curLvl.propPtr->pos.vy >= 200){
|
||||
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);
|
||||
}
|
||||
playSFX(&voiceAttributes, curLvl.levelSounds->sounds[3]->VAGsample, curLvl.levelSounds->sounds[3]->volumeL, curLvl.levelSounds->sounds[3]->volumeR);
|
||||
respawnMesh(&curLvl, curLvl.propPtr, &propStartRot, &propStartPos, propStartNode );
|
||||
}
|
||||
// Spatialize Sound
|
||||
// TODO : Use L/R to spatialize further
|
||||
VECTOR screenPos;
|
||||
screenPos = setSFXdist(&curLvl, &camera, camMode);
|
||||
// Spatial partitioning
|
||||
if (curLvl.curNode){
|
||||
for ( int msh = 0; msh < curLvl.curNode->siblings->index; msh ++ ) {
|
||||
@ -476,7 +387,10 @@ 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);
|
||||
FntPrint("XA: %x\n", curLvl.XA);
|
||||
FntPrint("Ofst: %d\n", curLvl.XA->banks[0]->offset);
|
||||
FntPrint("Vol: %d %d", curLvl.levelSounds->sounds[0]->volumeL, curLvl.levelSounds->sounds[0]->volumeR );
|
||||
FntPrint("Screenpos: %d %d", screenPos.vx, screenPos.vy );
|
||||
FntFlush(-1);
|
||||
display( &disp[db], &draw[db], otdisc[db], primbuff[db], &nextpri, &db);
|
||||
|
||||
@ -554,7 +468,7 @@ void callback() {
|
||||
} else {
|
||||
curLvl.actorPtr->isPrism = 1;
|
||||
}
|
||||
playSFX(&voiceAttributes, curLvl.levelSounds->sounds[0]->VAGsample, curLvl.levelSounds->sounds[0]->volume );
|
||||
playSFX(&voiceAttributes, curLvl.levelSounds->sounds[0]->VAGsample, curLvl.levelSounds->sounds[0]->volumeL, curLvl.levelSounds->sounds[0]->volumeR );
|
||||
//~ timer = 10;
|
||||
lastPad = PAD;
|
||||
}
|
||||
@ -562,7 +476,7 @@ void callback() {
|
||||
lastPad = PAD;
|
||||
}
|
||||
if ( PAD & Square && !( lastPad & Square ) ){
|
||||
playSFX(&voiceAttributes, curLvl.levelSounds->sounds[7]->VAGsample, curLvl.levelSounds->sounds[7]->volume);
|
||||
playSFX(&voiceAttributes, curLvl.levelSounds->sounds[7]->VAGsample, curLvl.levelSounds->sounds[7]->volumeL, curLvl.levelSounds->sounds[7]->volumeR);
|
||||
//~ sample = 0;
|
||||
//~ setXAsample(&XABank.samples[sample], &filter);
|
||||
lastPad = PAD;
|
||||
@ -576,14 +490,14 @@ void callback() {
|
||||
curLvl.actorPtr->body->gForce.vy = -200;
|
||||
}
|
||||
timer = 10;
|
||||
playSFX(&voiceAttributes, curLvl.levelSounds->sounds[4]->VAGsample, curLvl.levelSounds->sounds[4]->volume);
|
||||
playSFX(&voiceAttributes, curLvl.levelSounds->sounds[4]->VAGsample, curLvl.levelSounds->sounds[4]->volumeL, curLvl.levelSounds->sounds[4]->volumeR );
|
||||
lastPad = PAD;
|
||||
}
|
||||
if ( !(PAD & Cross) && lastPad & Cross ) {
|
||||
lastPad = PAD;
|
||||
}
|
||||
if ( PAD & Circle && !(PAD & lastPad) ){
|
||||
playSFX(&voiceAttributes, curLvl.levelSounds->sounds[5]->VAGsample, curLvl.levelSounds->sounds[5]->volume);
|
||||
playSFX(&voiceAttributes, curLvl.levelSounds->sounds[5]->VAGsample, curLvl.levelSounds->sounds[5]->volumeL, curLvl.levelSounds->sounds[5]->volumeR );
|
||||
lastPad = PAD;
|
||||
}
|
||||
if ( !(PAD & Circle) && lastPad & Circle ) {
|
||||
|
@ -231,3 +231,14 @@ u_int jump(BODY * actor, int dt){
|
||||
);
|
||||
return vt;
|
||||
};
|
||||
void respawnMesh(LEVEL * level, MESH * mesh, VECTOR * rot, VECTOR * pos, NODE * node){
|
||||
// Actor
|
||||
if( mesh->isActor ){
|
||||
level->curNode = node;
|
||||
level->levelPtr = level->curNode->plane;
|
||||
} else {
|
||||
level->propPtr->node = node;
|
||||
}
|
||||
copyVector(&mesh->body->position, pos );
|
||||
copyVector(&mesh->rot, rot );
|
||||
};
|
||||
|
118
src/sound.c
118
src/sound.c
@ -18,14 +18,14 @@ void initSnd(SpuCommonAttr * spuSettings, char * spu_malloc_rec, u_int mallocMax
|
||||
SpuSetIRQ(SPU_OFF);
|
||||
// Mute all voices
|
||||
SpuSetKey(SpuOff, SPU_ALLCH);
|
||||
}
|
||||
};
|
||||
u_long sendVAGtoSPU(unsigned int VAG_data_size, u_char *VAG_data){
|
||||
u_long transferred;
|
||||
SpuSetTransferMode(SpuTransByDMA); // DMA transfer; can do other processing during transfer
|
||||
transferred = SpuWrite (VAG_data + sizeof(VAGhdr), VAG_data_size); // transfer VAG_data_size bytes from VAG_data address to sound buffer
|
||||
SpuIsTransferCompleted (SPU_TRANSFER_WAIT); // Checks whether transfer is completed and waits for completion
|
||||
return transferred;
|
||||
}
|
||||
};
|
||||
void setVoiceAttr(SpuVoiceAttr * voiceAttributes, u_int pitch, long channel, u_long soundAddr ){
|
||||
voiceAttributes->mask= //~ Attributes (bit string, 1 bit per attribute)
|
||||
(
|
||||
@ -56,7 +56,7 @@ void setVoiceAttr(SpuVoiceAttr * voiceAttributes, u_int pitch, long channel, u_l
|
||||
voiceAttributes->sr = 0x0; //~ Sustain rate
|
||||
voiceAttributes->sl = 0xf; //~ Sustain level
|
||||
SpuSetVoiceAttr(voiceAttributes); // set attributes
|
||||
}
|
||||
};
|
||||
u_long setSPUtransfer(SpuVoiceAttr * voiceAttributes, VAGsound * sound){
|
||||
// Return spu_address
|
||||
u_long transferred, spu_address;
|
||||
@ -68,21 +68,68 @@ u_long setSPUtransfer(SpuVoiceAttr * voiceAttributes, VAGsound * sound){
|
||||
transferred = sendVAGtoSPU(SWAP_ENDIAN32(VAGheader->dataSize), sound->VAGfile);
|
||||
setVoiceAttr(voiceAttributes, pitch, sound->spu_channel, spu_address);
|
||||
return spu_address;
|
||||
}
|
||||
void setVAGvolume(SpuVoiceAttr * voiceAttributes, VAGsound * sound, int volume){
|
||||
};
|
||||
void setVAGvolume(SpuVoiceAttr * voiceAttributes, VAGsound * sound, int volumeL,int volumeR ){
|
||||
voiceAttributes->mask= ( SPU_VOICE_VOLL | SPU_VOICE_VOLR );
|
||||
voiceAttributes->voice = sound->spu_channel;
|
||||
// Range 0 - 3fff
|
||||
voiceAttributes->volume.left = volume;
|
||||
voiceAttributes->volume.right = volume;
|
||||
voiceAttributes->volume.left = volumeL;
|
||||
voiceAttributes->volume.right = volumeR;
|
||||
SpuSetVoiceAttr(voiceAttributes);
|
||||
}
|
||||
void playSFX(SpuVoiceAttr * voiceAttributes, VAGsound * sound, int volume){
|
||||
};
|
||||
void setLvlVAG(LEVEL * level, SpuCommonAttr * spuSettings, SpuVoiceAttr * voiceAttributes, char spu_malloc_rec[]){
|
||||
if (level->VAG != 0){
|
||||
// Free SPU mem
|
||||
for (u_short vag = 0; vag < level->VAG->index; vag++ ){
|
||||
if(level->VAG->samples[vag].spu_address != 0){
|
||||
SpuFree(level->VAG->samples[vag].spu_address);
|
||||
}
|
||||
}
|
||||
// Init sound settings
|
||||
initSnd(spuSettings, spu_malloc_rec, level->VAG->index );
|
||||
for (u_short vag = 0; vag < level->VAG->index; vag++ ){
|
||||
level->VAG->samples[vag].spu_address = setSPUtransfer(voiceAttributes, &level->VAG->samples[vag]);
|
||||
}
|
||||
}
|
||||
};
|
||||
void playSFX(SpuVoiceAttr * voiceAttributes, VAGsound * sound, int volumeL, int volumeR ){
|
||||
// Set voice volume to sample volume
|
||||
setVAGvolume(voiceAttributes, sound, volume);
|
||||
setVAGvolume(voiceAttributes, sound, volumeL, volumeR);
|
||||
// Play voice
|
||||
SpuSetKey(SpuOn, sound->spu_channel);
|
||||
}
|
||||
};
|
||||
VECTOR setSFXdist(LEVEL * level, CAMERA * camera, int camMode ){
|
||||
VECTOR output;
|
||||
//long long phi = 0;
|
||||
if (level->levelSounds != 0){
|
||||
//~ for(int snd = 0; snd < level0_sounds.index; snd++){
|
||||
for(int snd = 0; snd < level->levelSounds->index; snd++){
|
||||
// TODO : move in playSFX()
|
||||
// update sound location if sound has a parent
|
||||
u_int r;
|
||||
|
||||
// If parent is actor,
|
||||
if (level->levelSounds->sounds[snd]->parent == level->actorPtr && camMode <= 1){
|
||||
r = CAM_DIST_TO_ACT;
|
||||
} else if ( level->levelSounds->sounds[snd]->parent != 0){
|
||||
VECTOR dist;
|
||||
copyVector(&level->levelSounds->sounds[snd]->location, &level->levelSounds->sounds[snd]->parent->pos);
|
||||
// Get distance between sound source and camera
|
||||
addVector2(camera->pos, &level->levelSounds->sounds[snd]->location, &dist);
|
||||
r = psqrt((dist.vx * dist.vx) + (dist.vz * dist.vz));
|
||||
// Get angle between sound source and camera
|
||||
//phi = patan( level->levelSounds->sounds[snd]->location.vx, level->levelSounds->sounds[snd]->location.vz );
|
||||
//phi = ( phi >> 4 );
|
||||
}
|
||||
level->levelSounds->sounds[snd]->volumeL = level->levelSounds->sounds[snd]->volumeR = (level->levelSounds->sounds[snd]->volume_max/r) * SND_NMALIZED > SND_MAX_VOL ? SND_MAX_VOL :
|
||||
(level->levelSounds->sounds[snd]->volume_max/r) * SND_NMALIZED < 0 ? 0 :
|
||||
(level->levelSounds->sounds[snd]->volume_max/r) * SND_NMALIZED;
|
||||
//TODO : use screen coordinates
|
||||
worldToScreen(&level->levelSounds->sounds[snd]->location, &output);
|
||||
}
|
||||
}
|
||||
return output;
|
||||
};
|
||||
void XAsetup(void){
|
||||
u_char param[4];
|
||||
// ORing the parameters we need to set ; drive speed, ADPCM play, Subheader filter, sector size
|
||||
@ -94,8 +141,9 @@ void XAsetup(void){
|
||||
CdControlB(CdlSetmode, param, 0);
|
||||
// Pause at current pos
|
||||
CdControlF(CdlPause,0);
|
||||
}
|
||||
};
|
||||
void getXAoffset(LEVEL * level){
|
||||
// TODO : Only works for first XA file
|
||||
CdlFILE XAPos = {0};
|
||||
// Load XA file
|
||||
//~ CdSearchFile(&XAPos, level->XA->name);
|
||||
@ -111,4 +159,48 @@ void setXAsample(XAsound * sound, CdlFILTER * filter){
|
||||
CdControlF(CdlSetfilter, (u_char *)filter);
|
||||
// Reset sample's cursor
|
||||
sound->cursor = 0;
|
||||
}
|
||||
};
|
||||
void setLvlXA(LEVEL * level, int sample){
|
||||
if(sample >= 0){
|
||||
// CD filter
|
||||
CdlFILTER filter;
|
||||
// File position in m/s/f
|
||||
CdlLOC loc;
|
||||
if (level->XA != 0){
|
||||
// Change XA track
|
||||
XAsetup();
|
||||
//~ sample = !sample;
|
||||
level->XA->banks[0]->samples[sample].cursor = -1;
|
||||
getXAoffset(level);
|
||||
setXAsample(&level->XA->banks[0]->samples[sample], &filter);
|
||||
CdIntToPos(level->XA->banks[0]->samples[sample].start + level->XA->banks[0]->offset , &loc);
|
||||
// Send CDROM read command
|
||||
CdControlF(CdlReadS, (u_char *)&loc);
|
||||
}
|
||||
}
|
||||
};
|
||||
void XAplayback(LEVEL * level, int sample, long dt){
|
||||
if (sample != -1 ){
|
||||
// CD filter
|
||||
CdlFILTER filter;
|
||||
// File position in m/s/f
|
||||
CdlLOC loc;
|
||||
// Begin XA file playback...
|
||||
// if sample's cursor is 0
|
||||
if (level->XA->banks[0]->samples[sample].cursor == 0){
|
||||
// Convert sector number to CD position in min/second/frame and set CdlLOC accordingly.
|
||||
CdIntToPos(level->XA->banks[0]->samples[sample].start + level->XA->banks[0]->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
|
||||
// XA playback has fixed rate
|
||||
if ((level->XA->banks[0]->samples[sample].cursor += XA_CDSPEED / ((XA_RATE/(dt+1)+1)) ) >= (level->XA->banks[0]->samples[sample].end - level->XA->banks[0]->samples[sample].start) * ONE ){
|
||||
//~ CdControlF(CdlStop,0);
|
||||
level->XA->banks[0]->samples[sample].cursor = -1;
|
||||
setXAsample(&level->XA->banks[0]->samples[sample], &filter);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user