some modifications on xbox decoder to handle multi channels streams

git-svn-id: https://vgmstream.svn.sourceforge.net/svnroot/vgmstream@445 51a99a44-fe44-0410-b1ba-c3e57ba2b86b
This commit is contained in:
fastelbja 2008-09-29 21:06:12 +00:00
parent 0aef7053db
commit 591c60c6c9
2 changed files with 51 additions and 15 deletions

View File

@ -75,7 +75,10 @@ void decode_xbox_ima(VGMSTREAM * vgmstream,VGMSTREAMCHANNEL * stream, sample * o
int step_index = stream->adpcm_step_index;
off_t offset=stream->offset;
first_sample = first_sample % (32*vgmstream->channels);
if(vgmstream->channels==1)
first_sample = first_sample % 32;
else
first_sample = first_sample % (32*(vgmstream->channels&2));
if (first_sample == 0) {
@ -83,8 +86,8 @@ void decode_xbox_ima(VGMSTREAM * vgmstream,VGMSTREAMCHANNEL * stream, sample * o
hist1 = read_16bitLE(offset,stream->streamfile);
step_index = read_16bitLE(offset+2,stream->streamfile);
} else {
hist1 = read_16bitLE(offset+channel*4,stream->streamfile);
step_index = read_16bitLE(offset+channel*4+2,stream->streamfile);
hist1 = read_16bitLE(offset+(channel%2)*4,stream->streamfile);
step_index = read_16bitLE(offset+(channel%2)*4+2,stream->streamfile);
}
if (step_index < 0) step_index=0;
if (step_index > 88) step_index=88;
@ -95,8 +98,12 @@ void decode_xbox_ima(VGMSTREAM * vgmstream,VGMSTREAMCHANNEL * stream, sample * o
if(vgmstream->layout_type==layout_ea_blocked)
offset = stream->offset + (i/8*4+(i%8)/2+4);
else
offset = stream->offset + 4*channelspacing + (i/8*4*channelspacing+(i%8)/2+4*channel);
else {
if(channelspacing==1)
offset = stream->offset + 4 + (i/8*4+(i%8)/2+4*(channel%2));
else
offset = stream->offset + 4*2 + (i/8*4*2+(i%8)/2+4*(channel%2));
}
sample_nibble = (read_8bit(offset,stream->streamfile) >> (i&1?4:0))&0xf;
@ -125,8 +132,13 @@ void decode_xbox_ima(VGMSTREAM * vgmstream,VGMSTREAMCHANNEL * stream, sample * o
if(offset-stream->offset==32+3) // ??
stream->offset+=36;
} else {
if(offset-stream->offset==(32*channelspacing)+(4*channel)+3) // ??
stream->offset+=36*channelspacing;
if(channelspacing==1) {
if(offset-stream->offset==32+3) // ??
stream->offset+=36;
} else {
if(offset-stream->offset==64+(4*(channel%2))+3) // ??
stream->offset+=36*channelspacing;
}
}
stream->adpcm_history1_32=hist1;
stream->adpcm_step_index=step_index;

View File

@ -17,7 +17,7 @@ VGMSTREAM * init_vgmstream_xbox_xwav(STREAMFILE *streamFile) {
int loop_flag=0;
int channel_count;
off_t start_offset;
int i;
int i,j=0;
/* check extension, case insensitive */
streamFile->get_name(streamFile,filename,sizeof(filename));
@ -31,7 +31,10 @@ VGMSTREAM * init_vgmstream_xbox_xwav(STREAMFILE *streamFile) {
goto fail;
/* No loop on wavm */
loop_flag = 0;
if(read_32bitBE(0x28,streamFile)==0x77736D70)
loop_flag = 1;
else
loop_flag = 0;
/* Always stereo files */
channel_count=read_16bitLE(0x16,streamFile);
@ -40,6 +43,12 @@ VGMSTREAM * init_vgmstream_xbox_xwav(STREAMFILE *streamFile) {
vgmstream = allocate_vgmstream(channel_count,loop_flag);
if (!vgmstream) goto fail;
/* hack for loop wave found on Dynasty warriors */
if(loop_flag) {
vgmstream->loop_start_sample = read_32bitLE(0x4C,streamFile);
vgmstream->loop_end_sample = vgmstream->loop_start_sample + read_32bitLE(0x50,streamFile);
}
/* fill in the vital statistics */
vgmstream->channels = channel_count;
vgmstream->sample_rate = read_32bitLE(0x18,streamFile);
@ -65,13 +74,28 @@ VGMSTREAM * init_vgmstream_xbox_xwav(STREAMFILE *streamFile) {
vgmstream->meta_type = meta_XBOX_RIFF;
/* open the file for reading by each channel */
{
for (i=0;i<channel_count;i++) {
vgmstream->ch[i].streamfile = streamFile->open(streamFile,filename,36);
vgmstream->ch[i].offset = start_offset+4;
if (!vgmstream->ch[i].streamfile) goto fail;
}
{
if(channel_count>2) {
for (i=0;i<channel_count;i++,j++) {
if((j&2) && (i!=0)) {
j=0;
start_offset+=36*2;
}
vgmstream->ch[i].streamfile = streamFile->open(streamFile,filename,36);
vgmstream->ch[i].offset = start_offset+4;
if (!vgmstream->ch[i].streamfile) goto fail;
}
} else {
for (i=0;i<channel_count;i++) {
vgmstream->ch[i].streamfile = streamFile->open(streamFile,filename,36);
vgmstream->ch[i].offset = start_offset+4;
if (!vgmstream->ch[i].streamfile) goto fail;
}
}
}
return vgmstream;