2017-08-20 02:18:48 +02:00
|
|
|
#include "layout.h"
|
|
|
|
#include "../coding/coding.h"
|
|
|
|
#include "../vgmstream.h"
|
|
|
|
|
2017-12-17 17:38:54 +01:00
|
|
|
/* EA SNS/SPS blocks */
|
2017-11-25 01:18:27 +01:00
|
|
|
void block_update_ea_sns(off_t block_offset, VGMSTREAM * vgmstream) {
|
2017-08-20 02:18:48 +02:00
|
|
|
STREAMFILE* streamFile = vgmstream->ch[0].streamfile;
|
2019-01-23 04:40:42 +01:00
|
|
|
uint32_t block_id, block_size, block_samples;
|
2018-02-03 17:19:38 +01:00
|
|
|
off_t channel_start;
|
|
|
|
size_t channel_interleave;
|
2017-08-20 02:18:48 +02:00
|
|
|
int i;
|
|
|
|
|
2019-01-23 04:40:42 +01:00
|
|
|
/* EOF reads: signal we have nothing and let the layout fail */
|
|
|
|
if (block_offset >= get_streamfile_size(streamFile)) {
|
|
|
|
vgmstream->current_block_offset = block_offset;
|
|
|
|
vgmstream->next_block_offset = block_offset;
|
|
|
|
vgmstream->current_block_samples = -1;
|
2017-08-20 02:18:48 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-01-23 04:40:42 +01:00
|
|
|
/* always BE */
|
|
|
|
block_size = read_32bitBE(block_offset + 0x00,streamFile);
|
|
|
|
|
2017-12-17 17:38:54 +01:00
|
|
|
/* At 0x00(1): block flag
|
|
|
|
* - in SNS: 0x00=normal block, 0x80=last block (not mandatory)
|
|
|
|
* - in SPS: 0x48=header, 0x44=normal block, 0x45=last block (empty) */
|
2019-01-23 04:40:42 +01:00
|
|
|
block_id = (block_size & 0x00FFFFFF) >> 24;
|
2017-12-17 17:38:54 +01:00
|
|
|
block_size &= 0x00FFFFFF;
|
2017-08-20 02:18:48 +02:00
|
|
|
|
2019-01-23 04:40:42 +01:00
|
|
|
if (block_id == 0x00 || block_id == 0x80 || block_id == 0x44) {
|
|
|
|
block_samples = read_32bitBE(block_offset + 0x04, streamFile);
|
|
|
|
} else {
|
|
|
|
block_samples = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
vgmstream->current_block_offset = block_offset;
|
|
|
|
vgmstream->next_block_offset = block_offset + block_size;
|
|
|
|
vgmstream->current_block_samples = block_samples;
|
|
|
|
|
|
|
|
/* no need to setup offsets (plus could read over filesize near EOF) */
|
|
|
|
if (block_samples == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
switch (vgmstream->coding_type) {
|
2018-02-03 17:19:38 +01:00
|
|
|
case coding_NGC_DSP:
|
|
|
|
/* 0x04: unknown (0x00/02), 0x08: some size?, 0x34: null? */
|
2019-01-23 04:40:42 +01:00
|
|
|
channel_start = read_32bitBE(block_offset + 0x08 + 0x00, streamFile);
|
|
|
|
channel_interleave = read_32bitBE(block_offset + 0x08 + 0x0c, streamFile);
|
2018-02-03 17:19:38 +01:00
|
|
|
/* guessed as all known EA DSP only have one block with subheader (maybe changes coefs every block?) */
|
|
|
|
if (channel_start >= 0x40) {
|
2019-01-23 04:40:42 +01:00
|
|
|
dsp_read_coefs_be(vgmstream, streamFile, block_offset + 0x08 + 0x10, 0x28);
|
|
|
|
dsp_read_hist_be(vgmstream, streamFile, block_offset + 0x08 + 0x30, 0x28);//todo guessed and doesn't fix clicks in full loops
|
2018-02-03 17:19:38 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
channel_start = 0x00;
|
|
|
|
channel_interleave = 0x00;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2017-08-20 02:18:48 +02:00
|
|
|
for (i = 0; i < vgmstream->channels; i++) {
|
2019-01-23 04:40:42 +01:00
|
|
|
vgmstream->ch[i].offset = block_offset + 0x08 + channel_start + i * channel_interleave;
|
2017-12-01 20:04:33 +01:00
|
|
|
|
|
|
|
/* also fix first offset (for EALayer3) */
|
|
|
|
if (block_offset == vgmstream->ch[i].channel_start_offset) {
|
|
|
|
vgmstream->ch[i].channel_start_offset = vgmstream->ch[i].offset;
|
|
|
|
}
|
2017-08-20 02:18:48 +02:00
|
|
|
}
|
|
|
|
}
|