Experimental mutant psx codec

git-svn-id: https://vgmstream.svn.sourceforge.net/svnroot/vgmstream@257 51a99a44-fe44-0410-b1ba-c3e57ba2b86b
This commit is contained in:
halleyscometsw 2008-06-25 20:39:15 +00:00
parent 05ca1c8d29
commit c433b3046f
5 changed files with 63 additions and 2 deletions

View File

@ -25,6 +25,8 @@ void decode_pcm8(VGMSTREAMCHANNEL * stream, sample * outbuf, int channelspacing,
void decode_psx(VGMSTREAMCHANNEL * stream, sample * outbuf, int channelspacing, int32_t first_sample, int32_t samples_to_do);
void decode_invert_psx(VGMSTREAMCHANNEL * stream, sample * outbuf, int channelspacing, int32_t first_sample, int32_t samples_to_do);
void decode_xa(VGMSTREAMCHANNEL * stream, sample * outbuf, int channelspacing, int32_t first_sample, int32_t samples_to_do);
void decode_eaxa(VGMSTREAMCHANNEL * stream, sample * outbuf, int channelspacing, int32_t first_sample, int32_t samples_to_do,int channel);

View File

@ -49,3 +49,45 @@ void decode_psx(VGMSTREAMCHANNEL * stream, sample * outbuf, int channelspacing,
stream->adpcm_history1_32=hist1;
stream->adpcm_history2_32=hist2;
}
void decode_invert_psx(VGMSTREAMCHANNEL * stream, sample * outbuf, int channelspacing, int32_t first_sample, int32_t samples_to_do) {
int predict_nr, shift_factor, sample;
int32_t hist1=stream->adpcm_history1_32;
int32_t hist2=stream->adpcm_history2_32;
short scale;
int i;
int32_t sample_count;
uint8_t flag;
int framesin = first_sample/28;
predict_nr = (read_8bit(stream->offset+framesin*16,stream->streamfile) ^ 0xff) >> 4;
shift_factor = (read_8bit(stream->offset+framesin*16,stream->streamfile) ^ 0xff )& 0xf;
flag = read_8bit(stream->offset+framesin*16+1,stream->streamfile);
first_sample = first_sample % 28;
for (i=first_sample,sample_count=0; i<first_sample+samples_to_do; i++,sample_count+=channelspacing) {
sample=0;
if(flag<0x07) {
short sample_byte = (short)read_8bit(stream->offset+(framesin*16)+2+i/2,stream->streamfile);
scale = ((i&1 ?
sample_byte >> 4 :
sample_byte & 0x0f)<<12);
sample=(int)((scale >> shift_factor)+hist1*VAG_f[predict_nr][0]+hist2*VAG_f[predict_nr][1]);
}
outbuf[sample_count] = clamp16(sample);
hist2=hist1;
hist1=sample;
}
stream->adpcm_history1_32=hist1;
stream->adpcm_history2_32=hist2;
}

View File

@ -33,7 +33,10 @@ VGMSTREAM * init_vgmstream_ps2_bmdx(STREAMFILE *streamFile) {
vgmstream->sample_rate = read_32bitLE(0x18,streamFile);
/* Check for Compression Scheme */
vgmstream->coding_type = coding_PSX;
if (read_32bitLE(0x20,streamFile) == 1)
vgmstream->coding_type = coding_invert_PSX;
else
vgmstream->coding_type = coding_PSX;
vgmstream->num_samples = read_32bitLE(0x0c,streamFile)*28/16/channel_count;
/* Get loop point values */

View File

@ -295,6 +295,7 @@ int get_vgmstream_samples_per_frame(VGMSTREAM * vgmstream) {
case coding_NGC_AFC:
return 16;
case coding_PSX:
case coding_invert_PSX:
case coding_XA:
return 28;
case coding_XBOX:
@ -335,6 +336,7 @@ int get_vgmstream_frame_size(VGMSTREAM * vgmstream) {
case coding_NGC_AFC:
return 9;
case coding_PSX:
case coding_invert_PSX:
return 16;
case coding_XA:
return 14*vgmstream->channels;
@ -437,6 +439,13 @@ void decode_vgmstream(VGMSTREAM * vgmstream, int samples_written, int samples_to
vgmstream->channels,vgmstream->samples_into_block,
samples_to_do);
}
break;
case coding_invert_PSX:
for (chan=0;chan<vgmstream->channels;chan++) {
decode_invert_psx(&vgmstream->ch[chan],buffer+samples_written*vgmstream->channels+chan,
vgmstream->channels,vgmstream->samples_into_block,
samples_to_do);
}
break;
case coding_XA:
for (chan=0;chan<vgmstream->channels;chan++) {
@ -502,7 +511,8 @@ int vgmstream_do_loop(VGMSTREAM * vgmstream) {
if (vgmstream->meta_type == meta_DSP_STD ||
vgmstream->meta_type == meta_DSP_RS03 ||
vgmstream->meta_type == meta_DSP_CSTR ||
vgmstream->coding_type == coding_PSX) {
vgmstream->coding_type == coding_PSX ||
vgmstream->coding_type == coding_invert_PSX) {
int i;
for (i=0;i<vgmstream->channels;i++) {
vgmstream->loop_ch[i].adpcm_history1_16 = vgmstream->ch[i].adpcm_history1_16;
@ -627,6 +637,9 @@ void describe_vgmstream(VGMSTREAM * vgmstream, char * desc, int length) {
case coding_PSX:
snprintf(temp,TEMPSIZE,"Playstation 4-bit ADPCM");
break;
case coding_invert_PSX:
snprintf(temp,TEMPSIZE,"Inverted (?) Playstation 4-bit ADPCM");
break;
case coding_XA:
snprintf(temp,TEMPSIZE,"CD-ROM XA 4-bit ADPCM");
break;

View File

@ -28,6 +28,7 @@ typedef enum {
coding_G721, /* CCITT G.721 ADPCM */
coding_NGC_AFC, /* NGC ADPCM, called AFC */
coding_PSX, /* PSX & PS2 ADPCM */
coding_invert_PSX, /* PSX ADPCM with first byte of frame inverted */
coding_XA, /* PSX CD-XA */
coding_XBOX, /* XBOX IMA */
coding_EAXA, /* EA/XA ADPCM */