Skip to content

Commit

Permalink
Fix XA playback delay
Browse files Browse the repository at this point in the history
  • Loading branch information
ABelliqueux committed Aug 16, 2021
1 parent d662d0b commit da2eac1
Show file tree
Hide file tree
Showing 10 changed files with 29 additions and 56 deletions.
4 changes: 3 additions & 1 deletion custom_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ struct NODE;
struct LEVEL;
struct VAGsound;
struct VAGbank;
struct XAbank;
struct XAsound;

typedef struct BODY {
VECTOR gForce;
Expand Down Expand Up @@ -141,7 +143,7 @@ typedef struct XAsound {
} XAsound;

typedef struct XAbank {
char * name;
char name[16];
u_int index;
int offset;
XAsound samples[];
Expand Down
2 changes: 1 addition & 1 deletion include/defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions include/sound.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
4 changes: 1 addition & 3 deletions levels/level0.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 0 additions & 1 deletion levels/level0.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,3 @@ extern NODE * level0_curNode;
extern NODE level0_nodePlane;
extern VAGbank VAGBank0;
extern XAbank XABank0;
//~ extern char * loadXA0;
2 changes: 0 additions & 2 deletions levels/level1.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 0 additions & 1 deletion levels/level1.h
Original file line number Diff line number Diff line change
Expand Up @@ -178,4 +178,3 @@ extern NODE level1_nodegnd_002;
extern NODE level1_nodegnd;
extern VAGbank VAGBank1;
extern XAbank XABank1;
//~ extern char * loadXA1;
54 changes: 10 additions & 44 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
8 changes: 6 additions & 2 deletions src/psx.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "../include/psx.h"
#include "../include/sound.h"


void setDCLightEnv(MATRIX * curLevelCMat, MATRIX * curLevelLgtMat, SVECTOR * curLevelLgtAng){
Expand Down Expand Up @@ -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()
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
8 changes: 7 additions & 1 deletion src/sound.c
Original file line number Diff line number Diff line change
Expand Up @@ -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){
Expand All @@ -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;
Expand Down

0 comments on commit da2eac1

Please sign in to comment.