Page 1 of 1

Need help on looping XA audio tracks

Posted: November 20th, 2013, 1:09 am
by LameGuy64
Man its been quite a while since I've last posted something here. Anyway, I'm currently working on a PlayStation game project (which I won't explain in detail yet as I want to surprise everyone once CodeBlast '14 starts 8-)) which uses XA audio tracks for music.

I got the game to play the XA tracks properly but the problem is, I don't know of a good way to loop such tracks. Sure you can make a predefined array containing the length of each XA audio channel but that method sounds extremely cumbersome to me. I think this can be done nicely by checking for the 'End of Record' bit inside the subheader structure in each XA audio sector being played but I don't know of a way to extract the subheader during playback.

Any help will be gladly appreciated!

Re: Need help on looping XA audio tracks

Posted: November 20th, 2013, 2:08 pm
by t0rxe
XA_SOUND.PDF

Re: Need help on looping XA audio tracks

Posted: November 20th, 2013, 10:44 pm
by LameGuy64
That seems to be helpful enough... Thanks t0rxe!

Re: Need help on looping XA audio tracks

Posted: November 22nd, 2013, 12:08 pm
by LameGuy64
I now got a new problem, these lines inside my callback function:

Code: Select all

XAID = *(unsigned short *)(CdBuffer+3);
		
// video sector channel number format = 1CCCCC0000000001
XAgotChannel = *((unsigned short *)(CdBuffer+3)+1);
XAgotChannel = (XAgotChannel&31744)>>10;
Gives me an Address Error (Command Fetch or Data Load) message when executed.

Re: Need help on looping XA audio tracks

Posted: November 22nd, 2013, 7:41 pm
by t0rxe
Execute each line separately (comment them out) and find the line that is causing the crash.
From there, check your pointers and bit shifts. Maybe output them to a printf to ensure you are getting the results needed. Also check the Psy-Q Library References PDF to make sure the functions do no exceed their data type.

Re: Need help on looping XA audio tracks

Posted: November 22nd, 2013, 10:37 pm
by LameGuy64
Even when

Code: Select all

XAID = *(unsigned short *)(CdBuffer+3);
is the only line being executed, I still get that error.

EDIT: Never mind, I eventually found a way to fix it... Just gotta tweak/clean it up first before I'll release it as an XA player sample with auto-stop and looping.

Re: Need help on looping XA audio tracks

Posted: January 3rd, 2015, 1:27 am
by Yuri^Cybdyn
I think this can be done nicely by checking for the 'End of Record' bit inside the subheader structure in each XA audio sector being played but I don't know of a way to extract the subheader during playback.

yeah, one of the way is chk for EOR flag in subhader. by CdgetlocL command.

another way, dunno how they make it, but at the end of exact track (file/channell ) they put data frame, so when INT1 or dataready event comes it means it reach end of current xa track.

Re: Need help on looping XA audio tracks

Posted: January 3rd, 2015, 9:42 pm
by smf
LameGuy64 wrote:Even when

Code: Select all

XAID = *(unsigned short *)(CdBuffer+3);
is the only line being executed, I still get that error.
I'm guessing that CdBuffer is a unsigned char *, and adding 3 will make it odd.

If so then the you'd get an exception because the PlayStation can only access 16 bit values on addresses divisible by 2 (mess enforces that but most emulators don't). Some compilers can be forced into creating code that will work by using a packed struct, otherwise you have to do something like CdBuffer[3] | (CdBuffer[4] << 8). I have no idea about the validity of what you're doing, but that is likely the cause of the exception.