2008-06-02 19:58:08 +02:00
|
|
|
#include "coding.h"
|
|
|
|
#include "../util.h"
|
|
|
|
|
2015-08-02 09:20:57 +02:00
|
|
|
int32_t EA_XA_TABLE[28] = {0,0,240,0,460,-208,0x0188,-220,
|
2008-06-02 19:58:08 +02:00
|
|
|
0x0000,0x0000,0x00F0,0x0000,
|
|
|
|
0x01CC,0x0000,0x0188,0x0000,
|
|
|
|
0x0000,0x0000,0x0000,0x0000,
|
|
|
|
-208,-1,-220,-1,
|
|
|
|
0x0000,0x0000,0x0000,0x3F70};
|
|
|
|
|
2015-08-02 09:20:57 +02:00
|
|
|
int32_t EA_TABLE[20]= { 0x00000000, 0x000000F0, 0x000001CC, 0x00000188,
|
2008-07-14 21:21:45 +02:00
|
|
|
0x00000000, 0x00000000, 0xFFFFFF30, 0xFFFFFF24,
|
|
|
|
0x00000000, 0x00000001, 0x00000003, 0x00000004,
|
|
|
|
0x00000007, 0x00000008, 0x0000000A, 0x0000000B,
|
|
|
|
0x00000000, 0xFFFFFFFF, 0xFFFFFFFD, 0xFFFFFFFC};
|
|
|
|
|
2017-01-08 01:09:20 +01:00
|
|
|
void decode_ea_xa(VGMSTREAMCHANNEL * stream, sample * outbuf, int channelspacing, int32_t first_sample, int32_t samples_to_do,int channel) {
|
2008-06-02 19:58:08 +02:00
|
|
|
uint8_t frame_info;
|
2008-07-18 22:12:52 +02:00
|
|
|
int32_t sample_count;
|
2015-08-02 09:20:57 +02:00
|
|
|
int32_t coef1,coef2;
|
2008-06-02 19:58:08 +02:00
|
|
|
int i,shift;
|
|
|
|
off_t channel_offset=stream->channel_start_offset;
|
2008-07-18 21:33:56 +02:00
|
|
|
|
2008-06-02 19:58:08 +02:00
|
|
|
first_sample = first_sample%28;
|
|
|
|
frame_info = (uint8_t)read_8bit(stream->offset+channel_offset,stream->streamfile);
|
|
|
|
|
|
|
|
if(frame_info==0xEE) {
|
|
|
|
|
|
|
|
channel_offset++;
|
2008-07-18 21:33:56 +02:00
|
|
|
stream->adpcm_history1_32 = read_16bitBE(stream->offset+channel_offset,stream->streamfile);
|
|
|
|
stream->adpcm_history2_32 = read_16bitBE(stream->offset+channel_offset+2,stream->streamfile);
|
2008-06-02 19:58:08 +02:00
|
|
|
|
2008-07-18 21:33:56 +02:00
|
|
|
channel_offset+=4;
|
|
|
|
|
2008-06-02 19:58:08 +02:00
|
|
|
for (i=first_sample,sample_count=0; i<first_sample+samples_to_do; i++,sample_count+=channelspacing) {
|
|
|
|
outbuf[sample_count]=read_16bitBE(stream->offset+channel_offset,stream->streamfile);
|
|
|
|
channel_offset+=2;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Only increment offset on complete frame
|
|
|
|
if(channel_offset-stream->channel_start_offset==(2*28)+5)
|
|
|
|
stream->channel_start_offset+=(2*28)+5;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
|
|
|
|
coef1 = EA_XA_TABLE[((frame_info >> 4) & 0x0F) << 1];
|
|
|
|
coef2 = EA_XA_TABLE[(((frame_info >> 4) & 0x0F) << 1) + 1];
|
|
|
|
shift = (frame_info & 0x0F) + 8;
|
|
|
|
|
|
|
|
channel_offset++;
|
|
|
|
|
|
|
|
for (i=first_sample,sample_count=0; i<first_sample+samples_to_do; i++,sample_count+=channelspacing) {
|
|
|
|
uint8_t sample_byte = (uint8_t)read_8bit(stream->offset+channel_offset+i/2,stream->streamfile);
|
|
|
|
int32_t sample = ((((i&1?
|
|
|
|
sample_byte & 0x0F:
|
|
|
|
sample_byte >> 4
|
|
|
|
) << 0x1C) >> shift) +
|
|
|
|
(coef1 * stream->adpcm_history1_32) + (coef2 * stream->adpcm_history2_32)) >> 8;
|
|
|
|
|
|
|
|
outbuf[sample_count] = clamp16(sample);
|
|
|
|
stream->adpcm_history2_32 = stream->adpcm_history1_32;
|
|
|
|
stream->adpcm_history1_32 = sample;
|
|
|
|
}
|
|
|
|
|
|
|
|
channel_offset+=i/2;
|
|
|
|
|
|
|
|
// Only increment offset on complete frame
|
|
|
|
if(channel_offset-stream->channel_start_offset==0x0F)
|
|
|
|
stream->channel_start_offset+=0x0F;
|
|
|
|
}
|
|
|
|
}
|
2008-07-14 21:21:45 +02:00
|
|
|
|
|
|
|
|
2008-07-14 22:42:49 +02:00
|
|
|
void decode_ea_adpcm(VGMSTREAM * vgmstream, sample * outbuf, int channelspacing, int32_t first_sample, int32_t samples_to_do,int channel) {
|
2008-07-14 21:21:45 +02:00
|
|
|
uint8_t frame_info;
|
|
|
|
int32_t sample_count;
|
2015-08-02 09:20:57 +02:00
|
|
|
int32_t coef1,coef2;
|
2008-07-14 21:21:45 +02:00
|
|
|
int i,shift;
|
2008-07-14 22:42:49 +02:00
|
|
|
VGMSTREAMCHANNEL *stream = &(vgmstream->ch[channel]);
|
2008-07-14 21:21:45 +02:00
|
|
|
off_t channel_offset=stream->channel_start_offset;
|
|
|
|
|
2008-07-14 22:42:49 +02:00
|
|
|
vgmstream->get_high_nibble=!vgmstream->get_high_nibble;
|
2008-07-14 21:21:45 +02:00
|
|
|
|
|
|
|
first_sample = first_sample%28;
|
|
|
|
frame_info = read_8bit(stream->offset+channel_offset,stream->streamfile);
|
|
|
|
|
2008-07-14 22:42:49 +02:00
|
|
|
coef1 = EA_TABLE[(vgmstream->get_high_nibble? frame_info & 0x0F: frame_info >> 4)];
|
|
|
|
coef2 = EA_TABLE[(vgmstream->get_high_nibble? frame_info & 0x0F: frame_info >> 4) + 4];
|
2008-07-14 21:21:45 +02:00
|
|
|
|
|
|
|
channel_offset++;
|
|
|
|
|
|
|
|
frame_info = read_8bit(stream->offset+channel_offset,stream->streamfile);
|
2008-07-14 22:42:49 +02:00
|
|
|
shift = (vgmstream->get_high_nibble? frame_info & 0x0F : frame_info >> 4)+8;
|
2008-07-14 21:21:45 +02:00
|
|
|
|
|
|
|
channel_offset++;
|
|
|
|
|
|
|
|
for (i=first_sample,sample_count=0; i<first_sample+samples_to_do; i++,sample_count+=channelspacing) {
|
2009-09-01 23:28:55 +02:00
|
|
|
uint8_t sample_byte;
|
|
|
|
int32_t sample;
|
|
|
|
|
|
|
|
sample_byte = (uint8_t)read_8bit(stream->offset+channel_offset+i,stream->streamfile);
|
|
|
|
|
|
|
|
sample = ((((vgmstream->get_high_nibble?
|
2008-07-14 21:21:45 +02:00
|
|
|
sample_byte & 0x0F:
|
|
|
|
sample_byte >> 4
|
|
|
|
) << 0x1C) >> shift) +
|
|
|
|
(coef1 * stream->adpcm_history1_32) + (coef2 * stream->adpcm_history2_32) + 0x80) >> 8;
|
|
|
|
|
|
|
|
outbuf[sample_count] = clamp16(sample);
|
|
|
|
stream->adpcm_history2_32 = stream->adpcm_history1_32;
|
|
|
|
stream->adpcm_history1_32 = sample;
|
|
|
|
}
|
|
|
|
|
|
|
|
channel_offset+=i;
|
|
|
|
|
|
|
|
// Only increment offset on complete frame
|
|
|
|
if(channel_offset-stream->channel_start_offset==0x1E)
|
|
|
|
stream->channel_start_offset+=0x1E;
|
|
|
|
}
|
|
|
|
|
2009-09-01 23:28:55 +02:00
|
|
|
|
|
|
|
void decode_maxis_adpcm(VGMSTREAM * vgmstream, sample * outbuf, int channelspacing, int32_t first_sample, int32_t samples_to_do,int channel) {
|
|
|
|
uint8_t frame_info;
|
|
|
|
int32_t sample_count;
|
2015-08-02 09:20:57 +02:00
|
|
|
int32_t coef1,coef2;
|
2009-09-01 23:28:55 +02:00
|
|
|
int i,shift;
|
2009-09-02 16:25:42 +02:00
|
|
|
int frameSize = channelspacing*15;//mono samples have a frame of 15, stereo files have frames of 30
|
2009-09-01 23:28:55 +02:00
|
|
|
VGMSTREAMCHANNEL *stream = &(vgmstream->ch[channel]);
|
|
|
|
off_t channel_offset=stream->channel_start_offset;
|
|
|
|
|
|
|
|
first_sample = first_sample%28;
|
|
|
|
frame_info = read_8bit(channel_offset,stream->streamfile);
|
|
|
|
|
|
|
|
coef1 = EA_TABLE[frame_info >> 4];
|
|
|
|
coef2 = EA_TABLE[(frame_info >> 4) + 4];
|
|
|
|
shift = (frame_info & 0x0F)+8;
|
|
|
|
|
2009-09-02 16:25:42 +02:00
|
|
|
channel_offset+=channelspacing;
|
|
|
|
//stream->offset = first_sample*channelspacing/2;
|
2009-09-01 23:28:55 +02:00
|
|
|
|
|
|
|
for (i=first_sample,sample_count=0; i<first_sample+samples_to_do; i++,sample_count+=channelspacing) {
|
|
|
|
uint8_t sample_byte;
|
|
|
|
int32_t sample;
|
|
|
|
|
2009-09-02 16:25:42 +02:00
|
|
|
sample_byte = (uint8_t)read_8bit(stream->offset+channel_offset,stream->streamfile);
|
2009-09-01 23:28:55 +02:00
|
|
|
|
|
|
|
sample = (((((i&1)?
|
|
|
|
sample_byte & 0x0F:
|
|
|
|
sample_byte >> 4
|
|
|
|
) << 0x1C) >> shift) +
|
|
|
|
(coef1 * stream->adpcm_history1_32) + (coef2 * stream->adpcm_history2_32) + 0x80) >> 8;
|
|
|
|
|
|
|
|
outbuf[sample_count] = clamp16(sample);
|
|
|
|
stream->adpcm_history2_32 = stream->adpcm_history1_32;
|
|
|
|
stream->adpcm_history1_32 = sample;
|
|
|
|
|
|
|
|
if(i&1)
|
2009-09-02 16:25:42 +02:00
|
|
|
stream->offset+=channelspacing;
|
2009-09-01 23:28:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
channel_offset+=i;
|
|
|
|
|
|
|
|
// Only increment offset on complete frame
|
2009-09-02 16:25:42 +02:00
|
|
|
|
|
|
|
if(channel_offset-stream->channel_start_offset==frameSize) {
|
|
|
|
stream->channel_start_offset+=frameSize;
|
2009-09-01 23:28:55 +02:00
|
|
|
stream->offset=0;
|
|
|
|
}
|
|
|
|
}
|