take the first channel found

git-svn-id: https://vgmstream.svn.sourceforge.net/svnroot/vgmstream@860 51a99a44-fe44-0410-b1ba-c3e57ba2b86b
This commit is contained in:
fastelbja 2010-10-02 13:49:23 +00:00
parent f2cbf2116d
commit 08c67aa7ae

View File

@ -20,6 +20,8 @@ VGMSTREAM * init_vgmstream_cdxa(STREAMFILE *streamFile) {
char filename[260];
int channel_count;
int headerless=0;
int* xa_channel=0;
uint8_t bCoding;
off_t start_offset;
@ -33,10 +35,11 @@ VGMSTREAM * init_vgmstream_cdxa(STREAMFILE *streamFile) {
if (!((read_32bitBE(0x00,streamFile) == 0x52494646) &&
(read_32bitBE(0x08,streamFile) == 0x43445841) &&
(read_32bitBE(0x0C,streamFile) == 0x666D7420)))
goto fail;
headerless=1;
/* First init to have the correct info of the channel */
start_offset=init_xa_channel(0,streamFile);
if (!headerless) {
start_offset=init_xa_channel(&xa_channel,streamFile);
/* No sound ? */
if(start_offset==0)
@ -56,7 +59,7 @@ VGMSTREAM * init_vgmstream_cdxa(STREAMFILE *streamFile) {
/* fill in the vital statistics */
vgmstream->channels = channel_count;
vgmstream->xa_channel = 0;
vgmstream->xa_channel = xa_channel;
switch (AUDIO_CODING_GET_FREQ(bCoding)) {
case 0: vgmstream->sample_rate = 37800; break;
@ -65,9 +68,21 @@ VGMSTREAM * init_vgmstream_cdxa(STREAMFILE *streamFile) {
}
/* Check for Compression Scheme */
vgmstream->coding_type = coding_XA;
vgmstream->num_samples = (int32_t)((((get_streamfile_size(streamFile) - 0x3C)/2352)*0x1F80)/(2*channel_count));
} else
{
channel_count=2;
vgmstream = allocate_vgmstream(2,0);
if (!vgmstream) goto fail;
vgmstream->xa_headerless=1;
vgmstream->sample_rate=44100;
vgmstream->channels=2;
vgmstream->num_samples = (int32_t)(((get_streamfile_size(streamFile)/ 0x80)*0xE0)/2);
start_offset=0;
}
vgmstream->coding_type = coding_XA;
vgmstream->layout_type = layout_xa_blocked;
vgmstream->meta_type = meta_PSX_XA;
@ -93,7 +108,7 @@ fail:
return NULL;
}
off_t init_xa_channel(int channel,STREAMFILE* streamFile) {
off_t init_xa_channel(int* channel,STREAMFILE* streamFile) {
off_t block_offset=0x44;
size_t filelength=get_streamfile_size(streamFile);
@ -109,9 +124,10 @@ begin:
currentChannel=read_8bit(block_offset-7,streamFile);
subAudio=read_8bit(block_offset-6,streamFile);
if (!((currentChannel==channel) && (subAudio==0x64))) {
block_offset+=2352;
goto begin;
}
*channel=currentChannel;
//if (!((currentChannel==channel) && (subAudio==0x64))) {
// block_offset+=2352;
// goto begin;
//}
return block_offset;
}