From da2eac1d480c24885b547c9fd7210987833723fb Mon Sep 17 00:00:00 2001 From: ABelliqueux Date: Mon, 16 Aug 2021 16:20:36 +0200 Subject: [PATCH] Fix XA playback delay --- custom_types.h | 4 +++- include/defines.h | 2 +- include/sound.h | 1 + levels/level0.c | 4 +--- levels/level0.h | 1 - levels/level1.c | 2 -- levels/level1.h | 1 - src/main.c | 54 +++++++++-------------------------------------- src/psx.c | 8 +++++-- src/sound.c | 8 ++++++- 10 files changed, 29 insertions(+), 56 deletions(-) diff --git a/custom_types.h b/custom_types.h index 0996c88..d6cbcc1 100644 --- a/custom_types.h +++ b/custom_types.h @@ -16,6 +16,8 @@ struct NODE; struct LEVEL; struct VAGsound; struct VAGbank; +struct XAbank; +struct XAsound; typedef struct BODY { VECTOR gForce; @@ -141,7 +143,7 @@ typedef struct XAsound { } XAsound; typedef struct XAbank { - char * name; + char name[16]; u_int index; int offset; XAsound samples[]; diff --git a/include/defines.h b/include/defines.h index dd2728b..b6a5ce0 100644 --- a/include/defines.h +++ b/include/defines.h @@ -33,7 +33,7 @@ #define FNT_VRAM_X 960 #define FNT_VRAM_Y 256 #define FNT_SCR_X 16 -#define FNT_SCR_Y 32 +#define FNT_SCR_Y 168 #define FNT_SCR_W 240 #define FNT_SCR_H 48 #define FNT_SCR_BG 0 diff --git a/include/sound.h b/include/sound.h index 23ca7c5..9e2b1f8 100644 --- a/include/sound.h +++ b/include/sound.h @@ -56,4 +56,5 @@ u_long setSPUtransfer(SpuVoiceAttr * voiceAttributes, VAGsound * sound); void playSFX(SpuVoiceAttr * voiceAttributes, VAGsound * sound); // XA playback void XAsetup(void); +void getXAoffset(LEVEL * level); void setXAsample(XAsound * sound, CdlFILTER * filter); diff --git a/levels/level0.c b/levels/level0.c index f28ca2a..921bc05 100644 --- a/levels/level0.c +++ b/levels/level0.c @@ -1021,11 +1021,9 @@ XAbank XABank0 = { { //channel 0 { 0, 698464, 1, 0, 0, ((698464/2336)-1) * XA_CHANNELS, -1 }, - { 1, 366752, 1, 1 , 0, ((366752/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, diff --git a/levels/level0.h b/levels/level0.h index dc1cbe9..5143dfa 100644 --- a/levels/level0.h +++ b/levels/level0.h @@ -39,4 +39,3 @@ extern NODE * level0_curNode; extern NODE level0_nodePlane; extern VAGbank VAGBank0; extern XAbank XABank0; -//~ extern char * loadXA0; diff --git a/levels/level1.c b/levels/level1.c index c5c40f2..be1d371 100644 --- a/levels/level1.c +++ b/levels/level1.c @@ -11073,8 +11073,6 @@ XAbank XABank1 = { { 1, 366752, 1, 1 , 0, ((366752/2336)-1) * XA_CHANNELS, -1 }, } }; -// XA file to load -//~ static char * loadXA1 = "\\INTER8.XA;1"; LEVEL level1 = { &level1_BGc, diff --git a/levels/level1.h b/levels/level1.h index d80abf2..50a9275 100644 --- a/levels/level1.h +++ b/levels/level1.h @@ -178,4 +178,3 @@ extern NODE level1_nodegnd_002; extern NODE level1_nodegnd; extern VAGbank VAGBank1; extern XAbank XABank1; -//~ extern char * loadXA1; diff --git a/src/main.c b/src/main.c index 4bb0e1c..48f39b3 100644 --- a/src/main.c +++ b/src/main.c @@ -112,44 +112,7 @@ int atime = 0; 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 -// 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 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 }, - //~ } -//~ }; -//~ // XA file to load -//~ static char * loadXA = "\\INTER8.XA;1"; -// File informations : pos, size, name -CdlFILE XAPos = {0}; +SpuVoiceAttr voiceAttributes ; // structure for changing individual voice attributes // CD filter CdlFILTER filter; // File position in m/s/f @@ -178,10 +141,6 @@ int main() { CdInit(); // Load level LoadLevelCD(overlayFile, &load_all_overlays_here); - // Load XA file - CdSearchFile( &XAPos, curLvl.XA->name); - // Set cd head to start of file - curLvl.XA->offset = CdPosToInt(&XAPos.pos); #endif // TODO : Add switch case to get the correct pointers // Get needed pointers from level file @@ -190,6 +149,13 @@ 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); @@ -256,7 +222,7 @@ int main() { // if sample's cursor is 0 if (curLvl.XA->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->samples[sample].start + curLvl.XA->offset , &loc); // Send CDROM read command CdControlF(CdlReadS, (u_char *)&loc); XATime = VSync(-1); @@ -457,7 +423,7 @@ int main() { AddPrims(otdisc[db], ot[db] + OTLEN - 1, ot[db]); FntPrint("\n#Tri : %d\n", triCount); - FntPrint("#RCnt : %d %d %d\n", VSync(-1), XA_CDSPEED, dt); + FntPrint("#RCnt : %d %d %d\n", VSync(-1), dt); FntPrint("CamAngle : %d\n", curCamAngle); FntFlush(-1); display( &disp[db], &draw[db], otdisc[db], primbuff[db], &nextpri, &db); diff --git a/src/psx.c b/src/psx.c index b516929..8eb4478 100644 --- a/src/psx.c +++ b/src/psx.c @@ -1,4 +1,5 @@ #include "../include/psx.h" +#include "../include/sound.h" void setDCLightEnv(MATRIX * curLevelCMat, MATRIX * curLevelLgtMat, SVECTOR * curLevelLgtAng){ @@ -103,8 +104,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->VAG = level->VAG; + curLevel->XA = level->XA; //~ curLevel->actorPtr->body = level->actorPtr->body; // Move these to drawPoly() @@ -121,6 +122,8 @@ int LoadLevelCD(const char*const LevelName, u_long * LoadAddress){ void SwitchLevel( LEVEL * curLevel, LEVEL * loadLevel ){ //~ ScrRst(); LvlPtrSet( curLevel, loadLevel); + // XA + getXAoffset(curLevel); // Reload textures for (int k = 0; k < *curLevel->meshes_length ; k++){ // Check data exists @@ -148,6 +151,7 @@ void SwitchLevel( LEVEL * curLevel, LEVEL * loadLevel ){ applyVector( &curLevel->propPtr->body->position, 0, 100, 0, -=); applyVector( &curLevel->propPtr->body->velocity, 0, 0, 0, =); applyVector( &curLevel->propPtr->body->gForce, 0, 0, 0, =); + }; void LoadTexture(u_long * tim, TIM_IMAGE * tparam){ // This part is from Lameguy64's tutorial series : lameguy64.net/svn/pstutorials/chapter1/3-textures.html login/pw: annoyingmous OpenTIM(tim); // Open the tim binary data, feed it the address of the data in memory diff --git a/src/sound.c b/src/sound.c index b02f1e9..be43ca4 100644 --- a/src/sound.c +++ b/src/sound.c @@ -73,7 +73,6 @@ u_long setSPUtransfer(SpuVoiceAttr * voiceAttributes, VAGsound * sound){ //~ return 1; //~ } //~ return transferred; - FntPrint("Tr: %", transferred); return spu_address; } void playSFX(SpuVoiceAttr * voiceAttributes, VAGsound * sound){ @@ -99,6 +98,13 @@ void XAsetup(void){ // Pause at current pos CdControlF(CdlPause,0); } +void getXAoffset(LEVEL * level){ + CdlFILE XAPos = {0}; + // Load XA file + CdSearchFile(&XAPos, level->XA->name); + // Set cd head to start of file + level->XA->offset = CdPosToInt(&XAPos.pos); +}; void setXAsample(XAsound * sound, CdlFILTER * filter){ filter->chan = sound->channel; filter->file = sound->file;