2008-05-06 05:35:37 +02:00
|
|
|
#include "coding.h"
|
2008-05-06 00:45:21 +02:00
|
|
|
#include "../util.h"
|
|
|
|
|
|
|
|
double VAG_f[5][2] = { { 0.0 , 0.0 },
|
|
|
|
{ 60.0 / 64.0 , 0.0 },
|
|
|
|
{ 115.0 / 64.0 , -52.0 / 64.0 },
|
|
|
|
{ 98.0 / 64.0 , -55.0 / 64.0 } ,
|
|
|
|
{ 122.0 / 64.0 , -60.0 / 64.0 } } ;
|
|
|
|
|
|
|
|
void decode_psx(VGMSTREAMCHANNEL * stream, sample * outbuf, int channelspacing, int32_t first_sample, int32_t samples_to_do) {
|
|
|
|
|
|
|
|
int predict_nr, shift_factor, sample;
|
2008-05-10 21:58:03 +02:00
|
|
|
int32_t hist1=stream->adpcm_history1_32;
|
|
|
|
int32_t hist2=stream->adpcm_history2_32;
|
2008-05-06 00:45:21 +02:00
|
|
|
|
2008-05-09 19:59:05 +02:00
|
|
|
short scale;
|
2008-05-06 00:45:21 +02:00
|
|
|
int i;
|
|
|
|
int32_t sample_count;
|
2008-05-13 21:53:31 +02:00
|
|
|
uint8_t flag;
|
2008-05-06 00:45:21 +02:00
|
|
|
|
|
|
|
int framesin = first_sample/28;
|
|
|
|
|
|
|
|
predict_nr = read_8bit(stream->offset+framesin*16,stream->streamfile) >> 4;
|
|
|
|
shift_factor = read_8bit(stream->offset+framesin*16,stream->streamfile) & 0xf;
|
2008-05-13 21:53:31 +02:00
|
|
|
flag = read_8bit(stream->offset+framesin*16+1,stream->streamfile);
|
2008-05-06 00:45:21 +02:00
|
|
|
|
2008-05-13 21:53:31 +02:00
|
|
|
first_sample = first_sample % 28;
|
|
|
|
|
2008-05-06 00:45:21 +02:00
|
|
|
for (i=first_sample,sample_count=0; i<first_sample+samples_to_do; i++,sample_count+=channelspacing) {
|
|
|
|
|
2008-05-13 21:53:31 +02:00
|
|
|
sample=0;
|
|
|
|
|
2008-05-17 23:52:40 +02:00
|
|
|
if(flag<0x07) {
|
2008-05-13 21:53:31 +02:00
|
|
|
|
|
|
|
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);
|
2008-05-06 00:45:21 +02:00
|
|
|
|
2008-05-13 21:53:31 +02:00
|
|
|
sample=(int)((scale >> shift_factor)+hist1*VAG_f[predict_nr][0]+hist2*VAG_f[predict_nr][1]);
|
|
|
|
}
|
2008-05-06 00:45:21 +02:00
|
|
|
|
2008-05-13 21:53:31 +02:00
|
|
|
outbuf[sample_count] = clamp16(sample);
|
2008-05-06 00:45:21 +02:00
|
|
|
hist2=hist1;
|
2008-05-10 21:58:03 +02:00
|
|
|
hist1=sample;
|
2008-05-06 00:45:21 +02:00
|
|
|
}
|
2008-05-10 21:58:03 +02:00
|
|
|
stream->adpcm_history1_32=hist1;
|
|
|
|
stream->adpcm_history2_32=hist2;
|
2008-05-06 05:35:37 +02:00
|
|
|
}
|