Merge branch 'master' into ubi-sb

This commit is contained in:
NicknineTheEagle 2018-12-30 21:00:55 +03:00 committed by GitHub
commit 4272fcb1ed
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
20 changed files with 536 additions and 159 deletions

View File

@ -9,3 +9,7 @@ artifacts:
name: test.zip
- path: Release/foo_input_vgmstream.fb2k-component
name: foo_input_vgmstream.fb2k-component
- path: Release/test.pdb.zip
name: test.pdb.zip
- path: Release/foo_input_vgmstream.pdb.zip
name: foo_input_vgmstream.pdb.zip

View File

@ -30,6 +30,16 @@ $cliFiles = @(
"README.md"
)
$fb2kPdbFiles = @(
"Release/foo_input_vgmstream.pdb"
)
$cliPdbFiles = @(
"Release/in_vgmstream.pdb",
"Release/test.pdb",
"Release/xmp-vgmstream.pdb"
)
function Unzip
{
param([string]$zipfile, [string]$outpath)
@ -89,6 +99,8 @@ function Package
Compress-Archive $cliFiles Release/test.zip -Force
Compress-Archive $fb2kFiles Release/foo_input_vgmstream.zip -Force
Move-Item Release/foo_input_vgmstream.zip Release/foo_input_vgmstream.fb2k-component -Force
Compress-Archive $cliPdbFiles Release/test.pdb.zip -Force
Compress-Archive $fb2kPdbFiles Release/foo_input_vgmstream.pdb.zip -Force
}
function Build

View File

@ -79,6 +79,7 @@ A text file with the above commands must be saved as ".vag.txth" or ".txth", not
# - XMA2 Microsoft XMA2
# - FFMPEG Any headered FFmpeg format
# - AC3 AC3/SPDIF
# - PCFX PC-FX ADPCM
codec = (codec string)
# Codec variations [OPTIONAL, depends on codec]
@ -86,6 +87,7 @@ codec = (codec string)
# - ATRAC3: 0=autodetect joint stereo, 1=force joint stereo, 2=force normal stereo
# - XMA1|XMA2: 0=dual multichannel (2ch xN), 1=single multichannel (1ch xN)
# - XBOX: 0=standard (mono or stereo interleave), 1=force mono interleave mode
# - PCFX: 0=standard, 1='buggy encoder' mode, 2/3=same as 0/1 but with double volume
# - others: ignored
codec_mode = (number)
@ -188,11 +190,23 @@ body_file = (filename)|*.(extension)|null
# Subsongs [OPTIONAL]
# Sets the number of subsongs in the file, adjusting reads per subsong N:
# "value = @(offset) + subsong_offset*N". Mainly for bigfiles with consecutive
# headers per subsong, set subsong_offset to 0 when done as it affects any reads.
# "value = @(offset) + subsong_offset*N". (number) values aren't adjusted
# as they are seen as constants.
# Mainly for bigfiles with consecutive headers per subsong, set subsong_offset
# to 0 when done as it affects any reads.
# The current subsong number is handled externally by plugins or TXTP.
subsong_count = (number)|(offset)|(field)
subsong_offset = (number)|(offset)|(field)
# Names [OPTIONAL]
# Sets the name of the stream, most useful when used with subsongs.
# TXTH will read a string at name_offset, with name_size characters.
# name_size defaults to 0, which reads until null-terminator or a
# non-ascii character.
# name_offset can be a (number) value, but being an offset it's also
# adjusted by subsong_offset.
name_offset = (number)|(offset)|(field)
name_size = (number)|(offset)|(field)
```
## Usages

View File

@ -65,7 +65,7 @@ music_Home.ps3.scd#c3,4
### Multilayered songs
TXTP "layers" play songs with channels/parts divided into files as one
TXTP "layers" play songs with channels/parts divided into files as one.
- __Nier Automata__: _BGM_0_012_song2.txtp_
```
@ -85,6 +85,8 @@ BIK_E1_6A_DialEnd_00000000.audio.multi.bik#3
mode = layers
```
Note that the number of channels is the sum of all layers, so three 2ch layers play as a 6ch file.
### Channel swapping/mapping

View File

@ -168,6 +168,10 @@ void decode_derf(VGMSTREAMCHANNEL * stream, sample * outbuf, int channelspacing,
/* circus_decoder */
void decode_circus_adpcm(VGMSTREAMCHANNEL * stream, sample * outbuf, int channelspacing, int32_t first_sample, int32_t samples_to_do);
/* pcfx_decoder */
void decode_pcfx(VGMSTREAMCHANNEL * stream, sample * outbuf, int channelspacing, int32_t first_sample, int32_t samples_to_do, int mode);
size_t pcfx_bytes_to_samples(size_t bytes, int channels);
/* ea_mt_decoder*/
ea_mt_codec_data *init_ea_mt(int channels, int type);
ea_mt_codec_data *init_ea_mt_loops(int channels, int pcm_blocks, int loop_sample, off_t *loop_offsets);

View File

@ -503,24 +503,29 @@ void free_mpeg(mpeg_codec_data *data) {
* someone else in another thread is using it. */
}
/* seeks stream to 0 */
void reset_mpeg(VGMSTREAM *vgmstream) {
off_t input_offset;
mpeg_codec_data *data = vgmstream->codec_data;
if (!data) return;
/* reset multistream */ //todo check if stream offsets are properly reset
if (!data->custom) {
/* input_offset is ignored as we can assume it will be 0 for a seek to sample 0 */
mpg123_feedseek(data->m,0,SEEK_SET,&input_offset);
/* input_offset is ignored as we can assume it will be 0 for a seek to sample 0 */
}
else {
int i;
/* re-start from 0 */
for (i = 0; i < data->streams_size; i++) {
mpg123_feedseek(data->streams[i]->m,0,SEEK_SET,&input_offset);
data->streams[i]->bytes_in_buffer = 0;
data->streams[i]->buffer_full = 0;
data->streams[i]->buffer_used = 0;
data->streams[i]->samples_filled = 0;
data->streams[i]->samples_used = 0;
data->streams[i]->current_size_count = 0;
data->streams[i]->current_size_target = 0;
data->streams[i]->decode_to_discard = 0;
}
@ -528,16 +533,17 @@ void reset_mpeg(VGMSTREAM *vgmstream) {
}
}
/* seeks to a point */
void seek_mpeg(VGMSTREAM *vgmstream, int32_t num_sample) {
off_t input_offset;
mpeg_codec_data *data = vgmstream->codec_data;
if (!data) return;
/* seek multistream */
if (!data->custom) {
mpg123_feedseek(data->m, num_sample,SEEK_SET,&input_offset);
/* force first offset as discard-looping needs to start from the beginning */
/* adjust loop with mpg123's offset (useful?) */
if (vgmstream->loop_ch)
vgmstream->loop_ch[0].offset = vgmstream->loop_ch[0].channel_start_offset + input_offset;
}
@ -546,11 +552,14 @@ void seek_mpeg(VGMSTREAM *vgmstream, int32_t num_sample) {
/* re-start from 0 */
for (i = 0; i < data->streams_size; i++) {
mpg123_feedseek(data->streams[i]->m,0,SEEK_SET,&input_offset);
data->streams[i]->samples_filled = 0;
data->streams[i]->samples_used = 0;
data->streams[i]->decode_to_discard = 0;
data->streams[i]->bytes_in_buffer = 0;
data->streams[i]->buffer_full = 0;
data->streams[i]->buffer_used = 0;
data->streams[i]->samples_filled = 0;
data->streams[i]->samples_used = 0;
data->streams[i]->current_size_count = 0;
data->streams[i]->current_size_target = 0;
data->streams[i]->decode_to_discard = 0;
/* force first offset as discard-looping needs to start from the beginning */
if (vgmstream->loop_ch)
@ -562,33 +571,36 @@ void seek_mpeg(VGMSTREAM *vgmstream, int32_t num_sample) {
data->samples_to_discard += data->skip_samples;
}
data->bytes_in_buffer = 0;
data->buffer_full = 0;
data->buffer_used = 0;
}
/* resets mpg123 decoder and its internals (with mpg123_open_feed as mpg123_feedseek won't work) */
/* resets mpg123 decoder and its internals without seeking, useful when a new MPEG substream starts */
void flush_mpeg(mpeg_codec_data * data) {
if (!data)
return;
if (!data->custom) {
/* input_offset is ignored as we can assume it will be 0 for a seek to sample 0 */
mpg123_open_feed(data->m);
mpg123_open_feed(data->m); /* mpg123_feedseek won't work */
}
else {
int i;
/* re-start from 0 */
for (i=0; i < data->streams_size; i++) {
mpg123_open_feed(data->streams[i]->m);
data->streams[i]->samples_filled = 0;
data->streams[i]->samples_used = 0;
data->streams[i]->decode_to_discard = 0;
data->streams[i]->bytes_in_buffer = 0;
data->streams[i]->buffer_full = 0;
data->streams[i]->buffer_used = 0;
data->streams[i]->samples_filled = 0;
data->streams[i]->samples_used = 0;
data->streams[i]->current_size_count = 0;
data->streams[i]->current_size_target = 0;
data->streams[i]->decode_to_discard = 0;
}
data->samples_to_discard = data->skip_samples; /* initial delay */
data->samples_to_discard = data->skip_samples;
}
data->bytes_in_buffer = 0;

92
src/coding/pcfx_decoder.c Normal file
View File

@ -0,0 +1,92 @@
#include "coding.h"
static const int step_sizes[49] = { /* OKI table */
16, 17, 19, 21, 23, 25, 28, 31, 34, 37, 41, 45, 50,
55, 60, 66, 73, 80, 88, 97, 107, 118, 130, 143, 157,
173, 190, 209, 230, 253, 279, 307, 337, 371, 408, 449,
494, 544, 598, 658, 724, 796, 876, 963, 1060, 1166, 1282, 1411, 1552
};
static const int stex_indexes[16] = { /* IMA table */
-1, -1, -1, -1, 2, 4, 6, 8,
-1, -1, -1, -1, 2, 4, 6, 8
};
static void pcfx_expand_nibble(VGMSTREAMCHANNEL * stream, off_t byte_offset, int nibble_shift, int32_t * hist1, int32_t * step_index, int16_t *out_sample, int mode) {
int code, step, delta;
code = (read_8bit(byte_offset,stream->streamfile) >> nibble_shift) & 0xf;
step = step_sizes[*step_index];
delta = (code & 0x7);
if (mode & 1) {
if (step == 1552) /* bad last step_sizes value from OKI table */
step = 1522;
delta = step * (delta + 1) * 2;
}
else {
delta = step * (delta + 1);
}
if (code & 0x8)
delta = -delta;
*step_index += stex_indexes[code];
if (*step_index < 0) *step_index = 0;
if (*step_index > 48) *step_index = 48;
*hist1 += delta;
if (*hist1 > 16383) *hist1 = 16383;
if (*hist1 < -16384) *hist1 = -16384;
if (mode & 1) {
*out_sample = *hist1;
} else {
*out_sample = *hist1 << 1;
}
/* seems real HW does filtering here too */
/* double volume since it clips at half */
if (mode & 2) {
*out_sample = *hist1 << 1;
}
}
/* PC-FX ADPCM decoding, variation of OKI/Dialogic/VOX ADPCM. Based on mednafen/pcfx-music-dump.
* Apparently most ADPCM was made with a buggy encoder, resulting in incorrect sound in real hardware
* and sound clipped at half. Decoding can be controlled with modes:
* - 0: hardware decoding (waveforms in many games will look wrong, ex. Der Langrisser track 032)
* - 1: 'buggy encoder' decoding (waveforms will look fine)
* - 2: hardware decoding with double volume (may clip?)
* - 3: 'buggy encoder' decoding with double volume
*
* PC-FX ISOs don't have a standard filesystem nor file formats (raw data must be custom-ripped),
* so it's needs GENH/TXTH. Sample rate can only be base_value divided by 1/2/3/4, where
* base_value is approximately ~31468.5 (follows hardware clocks), mono or stereo-interleaved.
*/
void decode_pcfx(VGMSTREAMCHANNEL * stream, sample * outbuf, int channelspacing, int32_t first_sample, int32_t samples_to_do, int mode) {
int i, sample_count = 0;
int32_t hist1 = stream->adpcm_history1_32;
int step_index = stream->adpcm_step_index;
int16_t out_sample;
for (i = first_sample; i < first_sample + samples_to_do; i++) {
off_t byte_offset = stream->offset + i/2;
int nibble_shift = (i&1?4:0); /* low nibble first */
pcfx_expand_nibble(stream, byte_offset,nibble_shift, &hist1, &step_index, &out_sample, mode);
outbuf[sample_count] = out_sample;
sample_count += channelspacing;
}
stream->adpcm_history1_32 = hist1;
stream->adpcm_step_index = step_index;
}
size_t pcfx_bytes_to_samples(size_t bytes, int channels) {
/* 2 samples per byte (2 nibbles) in stereo or mono config */
return bytes * 2 / channels;
}

View File

@ -108,6 +108,7 @@ static const char* extension_list[] = {
"cks",
"cnk",
"cps",
"csa", //txth/reserved [LEGO Racers 2 (PS2)]
"csmp",
"cvs",
"cxs",
@ -203,6 +204,7 @@ static const char* extension_list[] = {
"lac3", //fake extension for .ac3, FFmpeg/not parsed
"leg",
"lflac", //fake extension for .flac, FFmpeg/not parsed
"lin",
"lm0",
"lm1",
"lm2",
@ -227,6 +229,7 @@ static const char* extension_list[] = {
"lwma", //fake extension for .wma, FFmpeg/not parsed
"mab",
"map",
"matx",
"mc3",
"mca",
@ -247,6 +250,7 @@ static const char* extension_list[] = {
//"mpc", //common
"mpdsp",
"mpds",
"mpf",
"mps", //txth/reserved [Scandal (PS2)]
"ms",
"msa",
@ -624,6 +628,7 @@ static const coding_info coding_info_list[] = {
{coding_FADPCM, "FMOD FADPCM 4-bit ADPCM"},
{coding_ASF, "Argonaut ASF 4-bit ADPCM"},
{coding_XMD, "Konami XMD 4-bit ADPCM"},
{coding_PCFX, "PC-FX 4-bit ADPCM"},
{coding_SDX2, "Squareroot-delta-exact (SDX2) 8-bit DPCM"},
{coding_SDX2_int, "Squareroot-delta-exact (SDX2) 8-bit DPCM with 1 byte interleave"},

View File

@ -33,10 +33,15 @@ void block_update_ea_schl(off_t block_offset, VGMSTREAM * vgmstream) {
case 0x5344454E: /* "SDEN" */
case 0x53444652: /* "SDFR" */
case 0x53444745: /* "SDGE" */
case 0x53444445: /* "SDDE" */
case 0x53444954: /* "SDIT" */
case 0x53445350: /* "SDSP" */
case 0x53444553: /* "SDES" */
case 0x53444D58: /* "SDMX" */
case 0x53445255: /* "SDRU" */
case 0x53444A41: /* "SDJA" */
case 0x53444A50: /* "SDJP" */
case 0x5344504C: /* "SDPL" */
/* audio chunk */
if (vgmstream->coding_type == coding_PSX)
block_samples = ps_bytes_to_samples(block_size-0x10, vgmstream->channels);

View File

@ -1889,6 +1889,10 @@
<File
RelativePath=".\coding\ogg_vorbis_decoder.c"
>
</File>
<File
RelativePath=".\coding\pcfx_decoder.c"
>
</File>
<File
RelativePath=".\coding\pcm_decoder.c"

View File

@ -527,6 +527,7 @@
<ClCompile Include="coding\ngc_dtk_decoder.c" />
<ClCompile Include="coding\nwa_decoder.c" />
<ClCompile Include="coding\ogg_vorbis_decoder.c" />
<ClCompile Include="coding\pcfx_decoder.c" />
<ClCompile Include="coding\pcm_decoder.c" />
<ClCompile Include="coding\psv_decoder.c" />
<ClCompile Include="coding\psx_decoder.c" />

View File

@ -1120,6 +1120,9 @@
<ClCompile Include="coding\ogg_vorbis_decoder.c">
<Filter>coding\Source Files</Filter>
</ClCompile>
<ClCompile Include="coding\pcfx_decoder.c">
<Filter>coding\Source Files</Filter>
</ClCompile>
<ClCompile Include="coding\pcm_decoder.c">
<Filter>coding\Source Files</Filter>
</ClCompile>

View File

@ -462,6 +462,85 @@ fail:
return NULL;
}
/* EA MPF/MUS combo - used in older 7th gen games for storing music */
VGMSTREAM * init_vgmstream_ea_mpf_mus_new(STREAMFILE *streamFile) {
uint32_t num_sounds;
uint8_t version, sub_version, block_id;
off_t table_offset, entry_offset, snr_offset, sns_offset;
size_t snr_size, sns_size;
int32_t(*read_32bit)(off_t, STREAMFILE*);
int16_t(*read_16bit)(off_t, STREAMFILE*);
STREAMFILE *musFile = NULL;
VGMSTREAM *vgmstream = NULL;
int target_stream = streamFile->stream_index;
/* check extension */
if (!check_extensions(streamFile, "mpf"))
goto fail;
/* detect endianness */
if (read_32bitBE(0x00, streamFile) == 0x50464478) { /* "PFDx" */
read_32bit = read_32bitBE;
read_16bit = read_16bitBE;
} else if (read_32bitBE(0x00, streamFile) == 0x78444650) { /* "xDFP" */
read_32bit = read_32bitLE;
read_16bit = read_16bitLE;
} else {
goto fail;
}
musFile = open_streamfile_by_ext(streamFile, "mus");
if (!musFile) goto fail;
/* MPF format is unchanged but we don't really care about its contents since
* MUS conveniently contains sound offset table */
version = read_8bit(0x04, streamFile);
sub_version = read_8bit(0x05, streamFile);
if (version != 0x05 || sub_version != 0x03) goto fail;
/* number of files is always little endian */
num_sounds = read_32bitLE(0x04, musFile);
table_offset = 0x28;
if (target_stream == 0) target_stream = 1;
if (target_stream < 0 || num_sounds == 0 || target_stream > num_sounds)
goto fail;
/*
* 0x00: hash?
* 0x04: index
* 0x06: zero
* 0x08: SNR offset
* 0x0c: SNS offset
* 0x10: SNR size
* 0x14: SNS size
* 0x18: zero
*/
entry_offset = table_offset + (target_stream - 1) * 0x1c;
snr_offset = read_32bit(entry_offset + 0x08, musFile) * 0x10;
sns_offset = read_32bit(entry_offset + 0x0c, musFile) * 0x80;
snr_size = read_32bit(entry_offset + 0x10, musFile);
sns_size = read_32bit(entry_offset + 0x14, musFile);
block_id = read_8bit(sns_offset, musFile);
if (block_id != EAAC_BLOCKID0_DATA && block_id != EAAC_BLOCKID0_END)
goto fail;
vgmstream = init_vgmstream_eaaudiocore_header(musFile, musFile, snr_offset, sns_offset, meta_EA_SNR_SNS);
if (!vgmstream)
goto fail;
vgmstream->num_streams = num_sounds;
vgmstream->stream_size = sns_size;
close_streamfile(musFile);
return vgmstream;
fail:
close_streamfile(musFile);
return NULL;
}
/* ************************************************************************* */
typedef struct {

View File

@ -62,13 +62,18 @@
#define EA_BLOCKID_LOC_DATA 0x53440000 /* "SD" */
#define EA_BLOCKID_LOC_END 0x53450000 /* "SE" */
#define EA_BLOCKID_LOC_EN 0x0000454E
#define EA_BLOCKID_LOC_FR 0x00004652
#define EA_BLOCKID_LOC_GE 0x00004745
#define EA_BLOCKID_LOC_IT 0x00004954
#define EA_BLOCKID_LOC_SP 0x00005350
#define EA_BLOCKID_LOC_RU 0x00005255
#define EA_BLOCKID_LOC_JA 0x00004A41
#define EA_BLOCKID_LOC_EN 0x0000454E /* English */
#define EA_BLOCKID_LOC_FR 0x00004652 /* French */
#define EA_BLOCKID_LOC_GE 0x00004745 /* German, older */
#define EA_BLOCKID_LOC_DE 0x00004445 /* German, newer */
#define EA_BLOCKID_LOC_IT 0x00004954 /* Italian */
#define EA_BLOCKID_LOC_SP 0x00005350 /* Castilian Spanish, older */
#define EA_BLOCKID_LOC_ES 0x00004553 /* Castilian Spanish, newer */
#define EA_BLOCKID_LOC_MX 0x00004D58 /* Mexican Spanish */
#define EA_BLOCKID_LOC_RU 0x00005255 /* Russian */
#define EA_BLOCKID_LOC_JA 0x00004A41 /* Japanese, older */
#define EA_BLOCKID_LOC_JP 0x00004A50 /* Japanese, newer */
#define EA_BLOCKID_LOC_PL 0x0000504C /* Polish */
#define EA_BNK_HEADER_LE 0x424E4B6C /* "BNKl" */
#define EA_BNK_HEADER_BE 0x424E4B62 /* "BNKb" */
@ -97,13 +102,13 @@ typedef struct {
int codec_config;
} ea_header;
static VGMSTREAM * parse_schl_block(STREAMFILE *streamFile, off_t offset, int total_streams);
static VGMSTREAM * parse_bnk_header(STREAMFILE *streamFile, off_t offset, int target_stream, int total_streams);
static VGMSTREAM * parse_schl_block(STREAMFILE *streamFile, off_t offset, int standalone);
static VGMSTREAM * parse_bnk_header(STREAMFILE *streamFile, off_t offset, int target_stream, int is_embedded);
static int parse_variable_header(STREAMFILE* streamFile, ea_header* ea, off_t begin_offset, int max_length, int bnk_version);
static uint32_t read_patch(STREAMFILE* streamFile, off_t* offset);
static int get_ea_stream_total_samples(STREAMFILE* streamFile, off_t start_offset, VGMSTREAM* vgmstream);
static off_t get_ea_stream_mpeg_start_offset(STREAMFILE* streamFile, off_t start_offset, const ea_header* ea);
static VGMSTREAM * init_vgmstream_ea_variable_header(STREAMFILE *streamFile, ea_header *ea, off_t start_offset, int is_bnk, int total_streams);
static VGMSTREAM * init_vgmstream_ea_variable_header(STREAMFILE *streamFile, ea_header *ea, off_t start_offset, int is_bnk, int standalone);
static void update_ea_stream_size_and_samples(STREAMFILE* streamFile, off_t start_offset, VGMSTREAM* vgmstream, int standalone);
/* EA SCHl with variable header - from EA games (roughly 1997~2010); generated by EA Canada's sx.exe/Sound eXchange */
VGMSTREAM * init_vgmstream_ea_schl(STREAMFILE *streamFile) {
@ -117,16 +122,21 @@ VGMSTREAM * init_vgmstream_ea_schl(STREAMFILE *streamFile) {
read_32bitBE(0x00,streamFile) != (EA_BLOCKID_LOC_HEADER | EA_BLOCKID_LOC_EN) && /* "SHEN" */
read_32bitBE(0x00,streamFile) != (EA_BLOCKID_LOC_HEADER | EA_BLOCKID_LOC_FR) && /* "SHFR" */
read_32bitBE(0x00,streamFile) != (EA_BLOCKID_LOC_HEADER | EA_BLOCKID_LOC_GE) && /* "SHGE" */
read_32bitBE(0x00,streamFile) != (EA_BLOCKID_LOC_HEADER | EA_BLOCKID_LOC_DE) && /* "SHDE" */
read_32bitBE(0x00,streamFile) != (EA_BLOCKID_LOC_HEADER | EA_BLOCKID_LOC_IT) && /* "SHIT" */
read_32bitBE(0x00,streamFile) != (EA_BLOCKID_LOC_HEADER | EA_BLOCKID_LOC_SP) && /* "SHSP" */
read_32bitBE(0x00,streamFile) != (EA_BLOCKID_LOC_HEADER | EA_BLOCKID_LOC_ES) && /* "SHES" */
read_32bitBE(0x00,streamFile) != (EA_BLOCKID_LOC_HEADER | EA_BLOCKID_LOC_MX) && /* "SHMX" */
read_32bitBE(0x00,streamFile) != (EA_BLOCKID_LOC_HEADER | EA_BLOCKID_LOC_RU) && /* "SHRU" */
read_32bitBE(0x00,streamFile) != (EA_BLOCKID_LOC_HEADER | EA_BLOCKID_LOC_JA)) /* "SHJA" */
read_32bitBE(0x00,streamFile) != (EA_BLOCKID_LOC_HEADER | EA_BLOCKID_LOC_JA) && /* "SHJA" */
read_32bitBE(0x00,streamFile) != (EA_BLOCKID_LOC_HEADER | EA_BLOCKID_LOC_JP) && /* "SHJP" */
read_32bitBE(0x00,streamFile) != (EA_BLOCKID_LOC_HEADER | EA_BLOCKID_LOC_PL)) /* "SHPL" */
goto fail;
/* Stream is divided into blocks/chunks: SCHl=audio header, SCCl=count of SCDl, SCDl=data xN, SCLl=loop end, SCEl=end.
* Video uses picture blocks (MVhd/MV0K/etc) and sometimes multiaudio blocks (SHxx/SCxx/SDxx/SExx where xx=language=EN/FR/GE/IT/SP/RU/JA).
* Video uses picture blocks (MVhd/MV0K/etc) and sometimes multiaudio blocks (SHxx/SCxx/SDxx/SExx where xx=language).
* The number/size is affected by: block rate setting, sample rate, channels, CPU location (SPU/main/DSP/others), etc */
return parse_schl_block(streamFile, 0x00, 0);
return parse_schl_block(streamFile, 0x00, 1);
fail:
return NULL;
@ -261,7 +271,7 @@ VGMSTREAM * init_vgmstream_ea_abk(STREAMFILE *streamFile) {
goto fail;
bnk_target_stream = read_32bit(target_entry_offset + 0x04, streamFile) + 1;
vgmstream = parse_bnk_header(streamFile, bnk_offset, bnk_target_stream, total_sounds);
vgmstream = parse_bnk_header(streamFile, bnk_offset, bnk_target_stream, 1);
if (!vgmstream)
goto fail;
break;
@ -280,7 +290,7 @@ VGMSTREAM * init_vgmstream_ea_abk(STREAMFILE *streamFile) {
if (read_32bitBE(schl_offset, astData) != EA_BLOCKID_HEADER)
goto fail;
vgmstream = parse_schl_block(astData, schl_offset, total_sounds);
vgmstream = parse_schl_block(astData, schl_offset, 0);
if (!vgmstream)
goto fail;
break;
@ -290,6 +300,7 @@ VGMSTREAM * init_vgmstream_ea_abk(STREAMFILE *streamFile) {
break;
}
vgmstream->num_streams = total_sounds;
close_streamfile(astData);
return vgmstream;
@ -339,10 +350,11 @@ VGMSTREAM * init_vgmstream_ea_hdr_dat(STREAMFILE *streamFile) {
if (read_32bitBE(schl_offset, datFile) != EA_BLOCKID_HEADER)
goto fail;
vgmstream = parse_schl_block(datFile, schl_offset, total_sounds);
vgmstream = parse_schl_block(datFile, schl_offset, 0);
if (!vgmstream)
goto fail;
vgmstream->num_streams = total_sounds;
close_streamfile(datFile);
return vgmstream;
@ -351,97 +363,162 @@ fail:
return NULL;
}
/* EA IDX/BIG combo - basically a set of HDR/DAT compiled into one file */
VGMSTREAM * init_vgmstream_ea_idx_big(STREAMFILE *streamFile) {
int target_stream = streamFile->stream_index, total_sounds, subsound_index;
uint32_t i, num_hdr;
uint16_t hdr_id, hdr_subid;
uint8_t userdata_size, hdr_sounds;
off_t entry_offset, hdr_offset, base_offset, schl_offset, offset_mult;
//size_t hdr_size;
char stream_name[STREAM_NAME_SIZE];
STREAMFILE *bigFile = NULL;
/* EA MAP/MUS combo - used in some old games for interactive music info */
VGMSTREAM * init_vgmstream_ea_map_mus(STREAMFILE *streamFile) {
uint8_t num_sounds, num_userdata;
off_t section_offset, schl_offset;
STREAMFILE *musFile = NULL;
VGMSTREAM *vgmstream = NULL;
int32_t (*read_32bit)(off_t,STREAMFILE*);
int16_t (*read_16bit)(off_t,STREAMFILE*);
int target_stream = streamFile->stream_index;
/* seems to always start with 0x00000001 */
if (read_32bitLE(0x00, streamFile) != 0x00000001 &&
read_32bitBE(0x00, streamFile) != 0x00000001)
/* check extension */
if (!check_extensions(streamFile, "map,lin"))
goto fail;
bigFile = open_streamfile_by_ext(streamFile, "big");
if (!bigFile)
/* always big endian */
if (read_32bitBE(0x00, streamFile) != 0x50464478) /* "PFDx" */
goto fail;
if (read_32bitBE(0x00, bigFile) != EA_BLOCKID_HEADER)
goto fail;
musFile = open_streamfile_by_ext(streamFile, "mus");
if (!musFile) goto fail;
/* use number of files for endianness check */
if (guess_endianness32bit(0x04,streamFile)) {
read_32bit = read_32bitBE;
read_16bit = read_16bitBE;
} else {
read_32bit = read_32bitLE;
read_16bit = read_16bitLE;
}
/*
* 0x04: ???
* 0x05: intro segment
* 0x06: number of segments
* 0x07: userdata entry size (incorrect?)
* 0x08: three zeroes
* 0x0b: number of userdata entries
* 0x0c: section 1 start
*/
num_sounds = read_8bit(0x06, streamFile);
num_userdata = read_8bit(0x0b, streamFile);
section_offset = 0x0c;
num_hdr = read_32bit(0x04, streamFile);
if (read_32bit(0x54,streamFile) != num_hdr)
goto fail;
/* section 1: contains information about segment playback order */
section_offset += num_sounds * 0x1c;
/* section 2: userdata, specific to game and track */
section_offset += num_userdata * 0x10;
if (target_stream == 0) target_stream = 1;
schl_offset = 0;
total_sounds = 0;
schl_offset = 0xFFFFFFFF;
for (i = 0; i < num_hdr; i++) {
entry_offset = 0x58 + 0x10 * i;
//hdr_size = read_32bit(entry_offset + 0x04, streamFile);
hdr_offset = read_32bit(entry_offset + 0x08, streamFile);
base_offset = read_32bit(entry_offset + 0x0C, streamFile);
hdr_id = read_16bit(hdr_offset + 0x00, streamFile);
hdr_subid = read_16bit(hdr_offset + 0x02, streamFile);
userdata_size = read_8bit(hdr_offset + 0x04, streamFile) & 0x0F;
hdr_sounds = read_8bit(hdr_offset + 0x05, streamFile);
offset_mult = (off_t)read_8bit(hdr_offset + 0x07, streamFile) * 0x0100 + 0x0100;
if (target_stream > total_sounds && target_stream <= total_sounds + hdr_sounds) {
schl_offset = base_offset + (off_t)read_16bitBE(hdr_offset + 0x0C + (0x02+userdata_size) * (target_stream-total_sounds-1), streamFile) * offset_mult;
subsound_index = target_stream - total_sounds;
/* There are no filenames but we can add IDs to stream name for better organization */
if (hdr_subid != 0xFFFF)
snprintf(stream_name, STREAM_NAME_SIZE, "%03d_%02d_%d", hdr_id, hdr_subid, subsound_index);
else
snprintf(stream_name, STREAM_NAME_SIZE, "%03d_%d", hdr_id, subsound_index);
}
total_sounds += hdr_sounds;
}
if (schl_offset == 0xFFFFFFFF)
if (target_stream < 0 || num_sounds == 0 || target_stream > num_sounds)
goto fail;
if (read_32bitBE(schl_offset, bigFile) != EA_BLOCKID_HEADER)
/* section 3: sound offset table */
schl_offset = read_32bitBE(section_offset + (target_stream - 1) * 0x04, streamFile);
if (read_32bitBE(schl_offset, musFile) != EA_BLOCKID_HEADER)
goto fail;
vgmstream = parse_schl_block(bigFile, schl_offset, total_sounds);
vgmstream = parse_schl_block(musFile, schl_offset, 0);
if (!vgmstream)
goto fail;
strncpy(vgmstream->stream_name, stream_name, STREAM_NAME_SIZE);
close_streamfile(bigFile);
vgmstream->num_streams = num_sounds;
close_streamfile(musFile);
return vgmstream;
fail:
close_streamfile(bigFile);
close_streamfile(musFile);
return NULL;
}
/* EA MPF/MUS combo - used in newer 6th gen games for storing music */
VGMSTREAM * init_vgmstream_ea_mpf_mus(STREAMFILE *streamFile) {
off_t section_offset, entry_offset, subentry_num, eof_offset, schl_offset;
uint16_t sec1_num;
uint8_t version, sub_version, sec2_num;
int32_t(*read_32bit)(off_t, STREAMFILE*);
int16_t(*read_16bit)(off_t, STREAMFILE*);
STREAMFILE *musFile = NULL;
VGMSTREAM *vgmstream = NULL;
int target_stream = streamFile->stream_index, total_streams;
/* check extension */
if (!check_extensions(streamFile, "mpf"))
goto fail;
/* detect endianness */
if (read_32bitBE(0x00, streamFile) == 0x50464478) { /* "PFDx" */
read_32bit = read_32bitBE;
read_16bit = read_16bitBE;
} else if (read_32bitBE(0x00, streamFile) == 0x78444650) { /* "xDFP" */
read_32bit = read_32bitLE;
read_16bit = read_16bitLE;
} else {
goto fail;
}
musFile = open_streamfile_by_ext(streamFile, "mus");
if (!musFile) goto fail;
version = read_8bit(0x04, streamFile);
sub_version = read_8bit(0x05, streamFile);
if (version < 0x04 || version > 0x05) goto fail;
if (version == 0x05 && sub_version > 0x02) goto fail; /* newer version using SNR/SNS */
if (version == 0x04) {
/* we need to go through the first two sections to find sound table */
sec1_num = read_16bit(0x12, streamFile);
sec2_num = read_8bit(0x0f, streamFile);
/* get the last entry offset */
section_offset = 0x20;
entry_offset = read_16bit(section_offset + (sec1_num - 1) * 0x02, streamFile) * 0x04;
/* HACK: there's some weird bitstream here that's stored differently in LE and BE */
/* I can't figure it out, so let's just use a workaround for now */
if (read_32bitBE(0x00, streamFile) == 0x50464478) {
subentry_num = (read_32bitBE(entry_offset + 0x04, streamFile) >> 15) & 0xFF;
} else {
subentry_num = (read_32bitBE(entry_offset + 0x04, streamFile) >> 20) & 0xFF;
}
section_offset = entry_offset + 0x10 + subentry_num * 0x04;
entry_offset = read_16bit(section_offset + (sec2_num - 1) * 0x02, streamFile) * 0x04;
/* more weird stuff */
if (read_32bitBE(0x00, streamFile) == 0x50464478) {
subentry_num = (read_32bitBE(entry_offset + 0x0c, streamFile) >> 10) & 0xFF;
} else {
subentry_num = (read_32bitBE(entry_offset + 0x0c, streamFile) >> 8) & 0xFF;
}
section_offset = entry_offset + 0x10 + subentry_num * 0x10;
entry_offset = read_32bit(section_offset, streamFile) * 0x04;
section_offset = read_32bit(entry_offset + 0x00, streamFile) * 0x04;
eof_offset = read_32bit(entry_offset + 0x04, streamFile) * 0x04;
total_streams = (eof_offset - section_offset) / 0x08;
} else if (version == 0x05) {
section_offset = read_32bit(0x34, streamFile);
eof_offset = read_32bit(0x38, streamFile);
total_streams = (eof_offset - section_offset) / 0x08;
}
if (target_stream == 0) target_stream = 1;
if (target_stream < 0 || total_streams == 0 || target_stream > total_streams)
goto fail;
schl_offset = read_32bit(section_offset + (target_stream - 1) * 0x08 + 0x00, streamFile) * 0x80;
if (read_32bitBE(schl_offset, musFile) != EA_BLOCKID_HEADER)
goto fail;
vgmstream = parse_schl_block(musFile, schl_offset, 0);
if (!vgmstream)
goto fail;
vgmstream->num_streams = total_streams;
close_streamfile(musFile);
return vgmstream;
fail:
close_streamfile(musFile);
return NULL;
}
/* EA SCHl with variable header - from EA games (roughly 1997~2010); generated by EA Canada's sx.exe/Sound eXchange */
static VGMSTREAM * parse_schl_block(STREAMFILE *streamFile, off_t offset, int total_streams) {
static VGMSTREAM * parse_schl_block(STREAMFILE *streamFile, off_t offset, int standalone) {
off_t start_offset, header_offset;
size_t header_size;
ea_header ea = { 0 };
@ -462,19 +539,20 @@ static VGMSTREAM * parse_schl_block(STREAMFILE *streamFile, off_t offset, int to
start_offset = offset + header_size; /* starts in "SCCl" (skipped in block layout) or very rarely "SCDl" and maybe movie blocks */
/* rest is common */
return init_vgmstream_ea_variable_header(streamFile, &ea, start_offset, 0, total_streams);
return init_vgmstream_ea_variable_header(streamFile, &ea, start_offset, 0, standalone);
fail:
return NULL;
}
/* EA BNK with variable header - from EA games SFXs; also created by sx.exe */
static VGMSTREAM * parse_bnk_header(STREAMFILE *streamFile, off_t offset, int target_stream, int total_streams) {
static VGMSTREAM * parse_bnk_header(STREAMFILE *streamFile, off_t offset, int target_stream, int is_embedded) {
off_t header_offset, start_offset, test_offset, table_offset;
size_t header_size;
ea_header ea = {0};
int32_t (*read_32bit)(off_t,STREAMFILE*) = NULL;
int16_t (*read_16bit)(off_t,STREAMFILE*) = NULL;
VGMSTREAM *vgmstream = NULL;
int i, bnk_version;
int total_bnk_sounds, real_bnk_sounds = 0;
@ -525,7 +603,7 @@ static VGMSTREAM * parse_bnk_header(STREAMFILE *streamFile, off_t offset, int ta
real_bnk_sounds++;
/* ABK points at absolute indexes, i.e. with dummies included */
if (total_streams != 0) {
if (is_embedded != 0) {
if (target_stream - 1 == i)
header_offset = offset + table_offset + 0x04 * i + test_offset;
}
@ -552,14 +630,20 @@ static VGMSTREAM * parse_bnk_header(STREAMFILE *streamFile, off_t offset, int ta
start_offset = ea.offsets[0]; /* first channel, presumably needed for MPEG */
/* rest is common */
return init_vgmstream_ea_variable_header(streamFile, &ea, start_offset, bnk_version, total_streams ? total_streams : real_bnk_sounds);
vgmstream = init_vgmstream_ea_variable_header(streamFile, &ea, start_offset, bnk_version, 0);
if (!vgmstream) goto fail;
if (!is_embedded) {
vgmstream->num_streams = real_bnk_sounds;
}
return vgmstream;
fail:
return NULL;
}
/* inits VGMSTREAM from a EA header */
static VGMSTREAM * init_vgmstream_ea_variable_header(STREAMFILE *streamFile, ea_header * ea, off_t start_offset, int bnk_version, int total_streams) {
static VGMSTREAM * init_vgmstream_ea_variable_header(STREAMFILE *streamFile, ea_header * ea, off_t start_offset, int bnk_version, int standalone) {
VGMSTREAM * vgmstream = NULL;
int i, ch;
int is_bnk = bnk_version;
@ -606,9 +690,6 @@ static VGMSTREAM * init_vgmstream_ea_variable_header(STREAMFILE *streamFile, ea_
vgmstream->layout_type = layout_blocked_ea_schl;
}
vgmstream->num_streams = total_streams;
//vgmstream->stream_size = ; //todo needed for kbps info
/* EA usually implements their codecs in all platforms (PS2/WII do EAXA/MT/EALAYER3) and
* favors them over platform's natives (ex. EAXA vs VAG/DSP).
* Unneeded codecs are removed over time (ex. LAYER3 when EALAYER3 was introduced). */
@ -790,15 +871,11 @@ static VGMSTREAM * init_vgmstream_ea_variable_header(STREAMFILE *streamFile, ea_
vgmstream->ch[i].offset = ea->offsets[i];
}
}
/* TODO: Figure out how to get stream size for BNK sounds */
}
else if (vgmstream->layout_type == layout_blocked_ea_schl) {
/* regular SCHls, except ATRAC3plus */
if (total_streams == 0) {
/* HACK: fix num_samples for streams with multiple SCHl. Need to eventually get rid of this */
int total_samples = get_ea_stream_total_samples(streamFile, start_offset, vgmstream);
if (total_samples > vgmstream->num_samples)
vgmstream->num_samples = total_samples;
}
else {
update_ea_stream_size_and_samples(streamFile, start_offset, vgmstream, standalone);
}
return vgmstream;
@ -1188,38 +1265,52 @@ fail:
return 0;
}
/* Get total samples by parsing block headers, needed when multiple files are stitched together.
static void update_ea_stream_size_and_samples(STREAMFILE* streamFile, off_t start_offset, VGMSTREAM *vgmstream, int standalone) {
uint32_t block_id;
int32_t num_samples;
size_t stream_size, file_size;
int multiple_schl;
stream_size = 0, num_samples = 0, multiple_schl = 0;
file_size = get_streamfile_size(streamFile);
vgmstream->next_block_offset = start_offset;
while (vgmstream->next_block_offset < file_size) {
block_update_ea_schl(vgmstream->next_block_offset, vgmstream);
block_id = read_32bitBE(vgmstream->current_block_offset + 0x00, streamFile);
if (block_id == EA_BLOCKID_END) { /* banks should never contain movie "SHxx" */
if (!standalone)
break;
}
else if (block_id == EA_BLOCKID_HEADER) { /* "SCHl" start block (movie "SHxx" shouldn't use multi files) */
multiple_schl = 1;
}
/* HACK: fix num_samples for streams with multiple SCHl. Need to eventually get rid of this.
* Get total samples by parsing block headers, needed when multiple files are stitched together.
* Some EA files (.mus/eam/sng/etc) concat many small subfiles, used for interactive/mapped
* music (.map/lin). Subfiles always share header, except num_samples. */
static int get_ea_stream_total_samples(STREAMFILE* streamFile, off_t start_offset, VGMSTREAM* vgmstream) {
int num_samples = 0;
int multiple_schl = 0;
/* calc num_samples as playable data size varies between files/blocks */
{
vgmstream->next_block_offset = start_offset;
do {
uint32_t block_id = read_32bitBE(vgmstream->next_block_offset+0x00,streamFile);
if (block_id == EA_BLOCKID_HEADER) /* "SCHl" start block (movie "SHxx" shouldn't use multi files) */
multiple_schl = 1;
block_update_ea_schl(vgmstream->next_block_offset,vgmstream);
num_samples += vgmstream->current_block_samples;
}
while (vgmstream->next_block_offset < get_streamfile_size(streamFile));
/* reset after getting samples */
block_update(start_offset,vgmstream);
/* Stream size is almost never provided in bank files so we have to calc it manually */
if (vgmstream->current_block_samples != 0) {
stream_size += vgmstream->next_block_offset - vgmstream->current_block_offset - 0x0c;
}
}
/* reset once we're done */
block_update(start_offset, vgmstream);
/* only use calculated samples with multiple subfiles (rarely header samples may be less due to padding) */
if (multiple_schl) {
;VGM_LOG("EA SCHl: multiple SCHl found\n");
return num_samples;
if (standalone && multiple_schl) {
VGM_LOG("EA SCHl: multiple SCHl found\n");
if (num_samples > vgmstream->num_samples) {
vgmstream->num_samples = num_samples;
}
else {
return 0;
}
vgmstream->stream_size = stream_size;
}
/* find data start offset inside the first SCDl; not very elegant but oh well */
@ -1243,10 +1334,15 @@ static off_t get_ea_stream_mpeg_start_offset(STREAMFILE* streamFile, off_t start
case EA_BLOCKID_LOC_DATA | EA_BLOCKID_LOC_EN: /* "SDEN" */
case EA_BLOCKID_LOC_DATA | EA_BLOCKID_LOC_FR: /* "SDFR" */
case EA_BLOCKID_LOC_DATA | EA_BLOCKID_LOC_GE: /* "SDGE" */
case EA_BLOCKID_LOC_DATA | EA_BLOCKID_LOC_DE: /* "SDDE" */
case EA_BLOCKID_LOC_DATA | EA_BLOCKID_LOC_IT: /* "SDIT" */
case EA_BLOCKID_LOC_DATA | EA_BLOCKID_LOC_SP: /* "SDSP" */
case EA_BLOCKID_LOC_DATA | EA_BLOCKID_LOC_ES: /* "SDES" */
case EA_BLOCKID_LOC_DATA | EA_BLOCKID_LOC_MX: /* "SDMX" */
case EA_BLOCKID_LOC_DATA | EA_BLOCKID_LOC_RU: /* "SDRU" */
case EA_BLOCKID_LOC_DATA | EA_BLOCKID_LOC_JA: /* "SDJA" */
case EA_BLOCKID_LOC_DATA | EA_BLOCKID_LOC_JP: /* "SDJP" */
case EA_BLOCKID_LOC_DATA | EA_BLOCKID_LOC_PL: /* "SDPL" */
offset = read_32bit(block_offset+0x0c,streamFile); /* first value seems ok, second is something else in EALayer3 */
return block_offset + 0x0c + ea->channels*0x04 + offset;
case 0x00000000:

View File

@ -4,7 +4,6 @@
#include "../util.h"
/* known GENH types */
typedef enum {
PSX = 0, /* PSX ADPCM */
@ -31,6 +30,7 @@ typedef enum {
XMA2 = 21, /* raw XMA2 */
FFMPEG = 22, /* any headered FFmpeg format */
AC3 = 23, /* AC3/SPDIF */
PCFX = 24, /* PC-FX ADPCM */
} genh_type;
typedef struct {
@ -113,6 +113,7 @@ VGMSTREAM * init_vgmstream_genh(STREAMFILE *streamFile) {
case AC3:
case FFMPEG: coding = coding_FFmpeg; break;
#endif
case PCFX: coding = coding_PCFX; break;
default:
goto fail;
}
@ -185,6 +186,14 @@ VGMSTREAM * init_vgmstream_genh(STREAMFILE *streamFile) {
}
break;
case coding_PCFX:
vgmstream->interleave_block_size = genh.interleave;
vgmstream->layout_type = layout_interleave;
if (genh.codec_mode >= 0 && genh.codec_mode <= 3)
vgmstream->codec_config = genh.codec_mode;
break;
case coding_MS_IMA:
if (!genh.interleave) goto fail; /* creates garbage */

View File

@ -22,14 +22,12 @@ VGMSTREAM * init_vgmstream_imc(STREAMFILE *streamFile) {
file_size = get_streamfile_size(streamFile);
loop_flag = 0;
start_offset = 0x10;
VGM_LOG("3\n");
/* extra checks since the header is so simple */
if (channel_count < 1 || channel_count > 8 || sample_rate < 22000 || sample_rate > 48000)
goto fail;
VGM_LOG("4\n");
if (interleave*blocks + start_offset != file_size)
goto fail;
VGM_LOG("5\n");
/* remove padding (important to play gapless subsongs, happens even for mono) */
{
@ -72,11 +70,10 @@ VGMSTREAM * init_vgmstream_imc_container(STREAMFILE *streamFile) {
VGMSTREAM *vgmstream = NULL;
STREAMFILE *temp_streamFile = NULL;
off_t header_offset, subfile_offset, next_offset, name_offset;
uint32_t flags1, flags2;
size_t subfile_size;
int total_subsongs, target_subsong = streamFile->stream_index;
/* checks */
if (!check_extensions(streamFile, "imc"))
goto fail;
@ -89,18 +86,12 @@ VGMSTREAM * init_vgmstream_imc_container(STREAMFILE *streamFile) {
header_offset = 0x04 + 0x20*(target_subsong-1);
name_offset = header_offset + 0x00;
//flags1 = (uint32_t)read_32bitLE(header_offset + 0x08, streamFile);
/* 0x08: flags? (0x702ADE77|0x002ADE77|0x20000000|etc) */
/* 0x0c: same for all songs in single .imc but varies between .imc */
subfile_offset = read_32bitLE(header_offset + 0x10,streamFile);
//flags2 = (uint32_t)read_32bitLE(header_offset + 0x14, streamFile);
/* 0x14: flags/size? (0xF0950000|0x3CFA1200|etc) */
/* 0x18: same for all songs in single .imc but varies between .imc */
/* 0x1c: flags? (0 or 2) */
//VGM_LOG("1: %x, %x\n", flags1, flags2);
// if (!(flags1 == 0x77DE2A70 || flags1 == 0x77DE2A00 || flags1 == 0x00000020 || flags1 == 0x00000000))
// goto fail;
// if (!(flags2 == 0x0000F095 || flags2 == 0x0012FA3C))
// goto fail;
//VGM_LOG("2\n");
if (target_subsong == total_subsongs) {
next_offset = get_streamfile_size(streamFile);

View File

@ -645,7 +645,8 @@ VGMSTREAM * init_vgmstream_ea_schl(STREAMFILE *streamFile);
VGMSTREAM * init_vgmstream_ea_bnk(STREAMFILE * streamFile);
VGMSTREAM * init_vgmstream_ea_abk(STREAMFILE * streamFile);
VGMSTREAM * init_vgmstream_ea_hdr_dat(STREAMFILE * streamFile);
VGMSTREAM * init_vgmstream_ea_idx_big(STREAMFILE * steeamFile);
VGMSTREAM * init_vgmstream_ea_map_mus(STREAMFILE * steeamFile);
VGMSTREAM * init_vgmstream_ea_mpf_mus(STREAMFILE * steeamFile);
VGMSTREAM * init_vgmstream_ea_schl_fixed(STREAMFILE * streamFile);
@ -683,6 +684,7 @@ VGMSTREAM * init_vgmstream_ea_snr_sns(STREAMFILE * streamFile);
VGMSTREAM * init_vgmstream_ea_sps(STREAMFILE * streamFile);
VGMSTREAM * init_vgmstream_ea_abk_new(STREAMFILE * streamFile);
VGMSTREAM * init_vgmstream_ea_hdr_sth_dat(STREAMFILE * streamFile);
VGMSTREAM * init_vgmstream_ea_mpf_mus_new(STREAMFILE * streamFile);
VGMSTREAM * init_vgmstream_ngc_vid1(STREAMFILE * streamFile);

View File

@ -30,6 +30,7 @@ typedef enum {
XMA2 = 21, /* raw XMA2 */
FFMPEG = 22, /* any headered FFmpeg format */
AC3 = 23, /* AC3/SPDIF */
PCFX = 24, /* PC-FX ADPCM */
} txth_type;
typedef struct {
@ -75,6 +76,10 @@ typedef struct {
uint32_t subsong_count;
uint32_t subsong_offset;
uint32_t name_offset_set;
uint32_t name_offset;
uint32_t name_size;
/* original STREAMFILE and its type (may be an unsupported "base" file or a .txth) */
STREAMFILE *streamFile;
int streamfile_is_txth;
@ -170,6 +175,7 @@ VGMSTREAM * init_vgmstream_txth(STREAMFILE *streamFile) {
case AC3:
case FFMPEG: coding = coding_FFmpeg; break;
#endif
case PCFX: coding = coding_PCFX; break;
default:
goto fail;
}
@ -192,6 +198,10 @@ VGMSTREAM * init_vgmstream_txth(STREAMFILE *streamFile) {
vgmstream->loop_end_sample = txth.loop_end_sample;
vgmstream->num_streams = txth.subsong_count;
vgmstream->stream_size = txth.data_size;
if (txth.name_offset_set) {
size_t name_size = txth.name_size ? txth.name_size + 1 : STREAM_NAME_SIZE;
read_string(vgmstream->stream_name,name_size, txth.name_offset,txth.streamHead);
}
/* codec specific (taken from GENH with minimal changes) */
switch (coding) {
@ -250,8 +260,15 @@ VGMSTREAM * init_vgmstream_txth(STREAMFILE *streamFile) {
vgmstream->ch[i].adpcm_step_index = 0x7f;
}
}
break;
case coding_PCFX:
vgmstream->interleave_block_size = txth.interleave;
vgmstream->layout_type = layout_interleave;
if (txth.codec_mode >= 0 && txth.codec_mode <= 3)
vgmstream->codec_config = txth.codec_mode;
break;
case coding_MS_IMA:
if (!txth.interleave) goto fail; /* creates garbage */
@ -565,6 +582,7 @@ static int parse_keyval(STREAMFILE * streamFile_, txth_header * txth, const char
else if (0==strcmp(val,"XMA2")) txth->codec = XMA2;
else if (0==strcmp(val,"FFMPEG")) txth->codec = FFMPEG;
else if (0==strcmp(val,"AC3")) txth->codec = AC3;
else if (0==strcmp(val,"PCFX")) txth->codec = PCFX;
else goto fail;
}
else if (0==strcmp(key,"codec_mode")) {
@ -710,6 +728,16 @@ static int parse_keyval(STREAMFILE * streamFile_, txth_header * txth, const char
else if (0==strcmp(key,"subsong_offset")) {
if (!parse_num(txth->streamHead,txth,val, &txth->subsong_offset)) goto fail;
}
else if (0==strcmp(key,"name_offset")) {
if (!parse_num(txth->streamHead,txth,val, &txth->name_offset)) goto fail;
txth->name_offset_set = 1;
/* special subsong adjustment */
if (txth->subsong_offset)
txth->name_offset = txth->name_offset + txth->subsong_offset * (txth->target_subsong - 1);
}
else if (0==strcmp(key,"name_size")) {
if (!parse_num(txth->streamHead,txth,val, &txth->name_size)) goto fail;
}
else if (0==strcmp(key,"header_file")) {
if (txth->streamhead_opened) {
close_streamfile(txth->streamHead);
@ -909,6 +937,8 @@ static int get_bytes_to_samples(txth_header * txth, uint32_t bytes) {
return ima_bytes_to_samples(bytes, txth->channels);
case AICA:
return aica_bytes_to_samples(bytes, txth->channels);
case PCFX:
return pcfx_bytes_to_samples(bytes, txth->channels);
/* untested */
case SDX2:

View File

@ -352,7 +352,8 @@ VGMSTREAM * (*init_vgmstream_functions[])(STREAMFILE *streamFile) = {
init_vgmstream_ea_bnk,
init_vgmstream_ea_abk,
init_vgmstream_ea_hdr_dat,
init_vgmstream_ea_idx_big,
init_vgmstream_ea_map_mus,
init_vgmstream_ea_mpf_mus,
init_vgmstream_ea_schl_fixed,
init_vgmstream_sk_aud,
init_vgmstream_stm,
@ -377,6 +378,7 @@ VGMSTREAM * (*init_vgmstream_functions[])(STREAMFILE *streamFile) = {
init_vgmstream_ea_sps,
init_vgmstream_ea_abk_new,
init_vgmstream_ea_hdr_sth_dat,
init_vgmstream_ea_mpf_mus_new,
init_vgmstream_ngc_vid1,
init_vgmstream_flx,
init_vgmstream_mogg,
@ -1148,6 +1150,7 @@ int get_vgmstream_samples_per_frame(VGMSTREAM * vgmstream) {
case coding_WV6_IMA:
case coding_ALP_IMA:
case coding_FFTA2_IMA:
case coding_PCFX:
return 2;
case coding_XBOX_IMA:
case coding_XBOX_IMA_mch:
@ -1320,6 +1323,7 @@ int get_vgmstream_frame_size(VGMSTREAM * vgmstream) {
case coding_WV6_IMA:
case coding_ALP_IMA:
case coding_FFTA2_IMA:
case coding_PCFX:
return 0x01;
case coding_MS_IMA:
case coding_RAD_IMA:
@ -2019,6 +2023,13 @@ void decode_vgmstream(VGMSTREAM * vgmstream, int samples_written, int samples_to
vgmstream->interleave_block_size);
}
break;
case coding_PCFX:
for (ch = 0; ch < vgmstream->channels; ch++) {
decode_pcfx(&vgmstream->ch[ch],buffer+samples_written*vgmstream->channels+ch,
vgmstream->channels,vgmstream->samples_into_block,samples_to_do, vgmstream->codec_config);
}
break;
case coding_EA_MT:
for (ch = 0; ch < vgmstream->channels; ch++) {
decode_ea_mt(vgmstream, buffer+samples_written*vgmstream->channels+ch,

View File

@ -149,6 +149,7 @@ typedef enum {
coding_FADPCM, /* FMOD FADPCM 4-bit ADPCM */
coding_ASF, /* Argonaut ASF 4-bit ADPCM */
coding_XMD, /* Konami XMD 4-bit ADPCM */
coding_PCFX, /* PC-FX 4-bit ADPCM */
/* others */
coding_SDX2, /* SDX2 2:1 Squareroot-Delta-Exact compression DPCM */