Fix some .nlsd [Disgaea 4 (PC)]

This commit is contained in:
bnnm 2020-10-01 21:22:34 +02:00
parent d2dd3abf45
commit 96727a5192
9 changed files with 181 additions and 160 deletions

View File

@ -1228,7 +1228,7 @@ static const meta_info meta_info_list[] = {
{meta_TXTP, "TXTP generic header"},
{meta_SMC_SMH, "Genki SMC+SMH header"},
{meta_PPST, "Parappa PPST header"},
{meta_OPUS_PPP, "AT9 OPUS header"},
{meta_SPS_N1, "Nippon Ichi .SPS header"},
{meta_UBI_BAO, "Ubisoft BAO header"},
{meta_DSP_SWITCH_AUDIO, "UE4 Switch Audio header"},
{meta_TA_AAC_VITA, "tri-Ace AAC (Vita) header"},

View File

@ -1125,10 +1125,6 @@
<File
RelativePath=".\meta\omu.c"
>
</File>
<File
RelativePath=".\meta\opus_ppp.c"
>
</File>
<File
RelativePath=".\meta\otm.c"

View File

@ -408,7 +408,6 @@
<ClCompile Include="meta\ogg_vorbis.c" />
<ClCompile Include="meta\ogl.c" />
<ClCompile Include="meta\omu.c" />
<ClCompile Include="meta\opus_ppp.c" />
<ClCompile Include="meta\otm.c" />
<ClCompile Include="meta\p3d.c" />
<ClCompile Include="meta\raw_al.c" />

View File

@ -730,9 +730,6 @@
<ClCompile Include="meta\omu.c">
<Filter>meta\Source Files</Filter>
</ClCompile>
<ClCompile Include="meta\opus_ppp.c">
<Filter>meta\Source Files</Filter>
</ClCompile>
<ClCompile Include="meta\otm.c">
<Filter>meta\Source Files</Filter>
</ClCompile>

View File

@ -691,6 +691,7 @@ VGMSTREAM * init_vgmstream_xwc(STREAMFILE *streamFile);
VGMSTREAM * init_vgmstream_atsl(STREAMFILE *streamFile);
VGMSTREAM * init_vgmstream_sps_n1(STREAMFILE *streamFile);
VGMSTREAM * init_vgmstream_sps_n1_segmented(STREAMFILE *streamFile);
VGMSTREAM * init_vgmstream_atx(STREAMFILE *streamFile);
@ -727,8 +728,6 @@ VGMSTREAM * init_vgmstream_smc_smh(STREAMFILE * streamFile);
VGMSTREAM * init_vgmstream_ppst(STREAMFILE *streamFile);
VGMSTREAM * init_vgmstream_opus_sps_n1_segmented(STREAMFILE *streamFile);
VGMSTREAM * init_vgmstream_ubi_bao_pk(STREAMFILE *streamFile);
VGMSTREAM * init_vgmstream_ubi_bao_atomic(STREAMFILE *streamFile);

View File

@ -1,93 +0,0 @@
#include "meta.h"
#include "../coding/coding.h"
#include "../layout/layout.h"
/* Nippon Ichi SPS wrapper (segmented) [Penny-Punching Princess (Switch)] */
VGMSTREAM * init_vgmstream_opus_sps_n1_segmented(STREAMFILE *streamFile) {
VGMSTREAM * vgmstream = NULL;
off_t segment_offset;
int loop_flag, channel_count;
int i;
segmented_layout_data *data = NULL;
int segment_count, loop_start_segment = 0, loop_end_segment = 0;
int num_samples = 0, loop_start_sample = 0, loop_end_sample = 0;
/* checks */
if (!check_extensions(streamFile, "at9"))
goto fail;
if (read_32bitBE(0x00,streamFile) != 0x09000000) /* file type (see other N1 SPS) */
goto fail;
if (read_32bitLE(0x04,streamFile) + 0x1c != get_streamfile_size(streamFile))
goto fail;
/* 0x08(2): sample rate, 0x0a(2): flag?, 0x0c: num_samples (slightly smaller than added samples) */
segment_count = 3; /* intro/loop/end */
loop_start_segment = 1;
loop_end_segment = 1;
loop_flag = (segment_count > 0);
/* init layout */
data = init_layout_segmented(segment_count);
if (!data) goto fail;
/* open each segment subfile */
segment_offset = 0x1c;
for (i = 0; i < segment_count; i++) {
STREAMFILE* temp_streamFile;
size_t segment_size = read_32bitLE(0x10+0x04*i,streamFile);
if (!segment_size)
goto fail;
temp_streamFile = setup_subfile_streamfile(streamFile, segment_offset,segment_size, "opus");
if (!temp_streamFile) goto fail;
data->segments[i] = init_vgmstream_opus_std(temp_streamFile);
close_streamfile(temp_streamFile);
if (!data->segments[i]) goto fail;
segment_offset += segment_size;
//todo there are some trailing samples that must be removed for smooth loops, start skip seems ok
data->segments[i]->num_samples -= 374; //not correct for all files, no idea how to calculate
/* get looping and samples */
if (loop_flag && loop_start_segment == i)
loop_start_sample = num_samples;
num_samples += data->segments[i]->num_samples;
if (loop_flag && loop_end_segment == i)
loop_end_sample = num_samples;
}
/* setup segmented VGMSTREAMs */
if (!setup_layout_segmented(data))
goto fail;
channel_count = data->segments[0]->channels;
/* build the VGMSTREAM */
vgmstream = allocate_vgmstream(channel_count,loop_flag);
if (!vgmstream) goto fail;
vgmstream->sample_rate = (uint16_t)read_16bitLE(0x08,streamFile);
vgmstream->num_samples = num_samples;
vgmstream->loop_start_sample = loop_start_sample;
vgmstream->loop_end_sample = loop_end_sample;
vgmstream->meta_type = meta_OPUS_PPP;
vgmstream->coding_type = data->segments[0]->coding_type;
vgmstream->layout_type = layout_segmented;
vgmstream->layout_data = data;
return vgmstream;
fail:
close_vgmstream(vgmstream);
free_layout_segmented(data);
return NULL;
}

View File

@ -1,54 +1,177 @@
#include "meta.h"
#include "../coding/coding.h"
/* .SPS - Nippon Ichi wrapper [ClaDun (PSP)] */
VGMSTREAM * init_vgmstream_sps_n1(STREAMFILE *streamFile) {
VGMSTREAM *vgmstream = NULL;
STREAMFILE *temp_streamFile = NULL;
int type, sample_rate;
off_t subfile_offset;
size_t subfile_size;
/* check extensions */
if ( !check_extensions(streamFile,"sps"))
goto fail;
/* mini header */
type = read_32bitLE(0x00,streamFile);
subfile_size = read_32bitLE(0x04,streamFile);
sample_rate = (uint16_t)read_16bitLE(0x08,streamFile);
/* 0x0a: flag? */
//num_samples = read_32bitLE(0x0c,streamFile);
subfile_offset = 0x10;
/* init the VGMSTREAM */
switch(type) {
case 1: /* .vag */
temp_streamFile = setup_subfile_streamfile(streamFile, subfile_offset, subfile_size, "vag");
if (!temp_streamFile) goto fail;
vgmstream = init_vgmstream_vag(temp_streamFile);
if (!vgmstream) goto fail;
break;
case 2: /* .at3 */
temp_streamFile = setup_subfile_streamfile(streamFile, subfile_offset, subfile_size, "at3");
if (!temp_streamFile) goto fail;
vgmstream = init_vgmstream_riff(temp_streamFile);
if (!vgmstream) goto fail;
break;
default:
goto fail;
}
vgmstream->sample_rate = sample_rate; /* .vag header doesn't match */
close_streamfile(temp_streamFile);
return vgmstream;
fail:
close_streamfile(temp_streamFile);
close_vgmstream(vgmstream);
return NULL;
}
#include "meta.h"
#include "../layout/layout.h"
#include "../coding/coding.h"
/* also see init_vgmstream_dsp_sps_n1 and init_vgmstream_opus_sps_n1 */
/* Nippon Ichi SPS wrapper [ClaDun (PSP)] */
VGMSTREAM* init_vgmstream_sps_n1(STREAMFILE* sf) {
VGMSTREAM* vgmstream = NULL;
STREAMFILE* temp_sf = NULL;
int type, sample_rate;
off_t subfile_offset;
size_t subfile_size;
VGMSTREAM* (*init_vgmstream_subfile)(STREAMFILE*) = NULL;
const char* extension;
/* checks */
if (!check_extensions(sf,"sps"))
goto fail;
type = read_u32le(0x00,sf);
subfile_size = read_u32le(0x04,sf);
sample_rate = read_u16le(0x08,sf);
/* 0x0a: flag? (stereo?) */
/* 0x0b: flag? */
/* 0x0c: num_samples */
switch(type) {
case 1:
init_vgmstream_subfile = init_vgmstream_vag;
extension = "vag";
break;
case 2:
init_vgmstream_subfile = init_vgmstream_riff;
extension = "at3";
break;
default:
goto fail;
}
subfile_offset = 0x10;
if (subfile_size + subfile_offset != get_streamfile_size(sf))
goto fail;
/* init the VGMSTREAM */
temp_sf = setup_subfile_streamfile(sf, subfile_offset, subfile_size, extension);
if (!temp_sf) goto fail;
vgmstream = init_vgmstream_subfile(temp_sf);
if (!vgmstream) goto fail;
vgmstream->sample_rate = sample_rate; /* .vag header doesn't match */
close_streamfile(temp_sf);
return vgmstream;
fail:
close_streamfile(temp_sf);
close_vgmstream(vgmstream);
return NULL;
}
/* Nippon Ichi SPS wrapper (segmented) [Penny-Punching Princess (Switch), Disgaea 4 Complete (PC)] */
VGMSTREAM* init_vgmstream_sps_n1_segmented(STREAMFILE* sf) {
VGMSTREAM* vgmstream = NULL;
off_t segment_offset;
size_t data_size, max_size;
int loop_flag, type, sample_rate;
int i, segment;
VGMSTREAM* (*init_vgmstream_subfile)(STREAMFILE*) = NULL;
const char* extension;
segmented_layout_data* data = NULL;
int segment_count, loop_start_segment, loop_end_segment;
/* checks */
/* .at9: Penny-Punching Princess (Switch)
* .nlsd: Disgaea 4 Complete (PC) */
if (!check_extensions(sf, "at9,nlsd"))
goto fail;
type = read_u32le(0x00,sf);
data_size = read_u32le(0x04,sf);
sample_rate = read_u16le(0x08,sf);
/* 0x0a: flag? (stereo?) */
/* 0x0b: flag? */
/* 0x0c: num_samples (slightly smaller than added samples?) */
switch(type) {
case 7:
init_vgmstream_subfile = init_vgmstream_ogg_vorbis;
extension = "ogg";
break;
case 9:
init_vgmstream_subfile = init_vgmstream_opus_std;
extension = "opus";
break;
default:
goto fail;
}
segment_offset = 0x1c;
if (data_size + segment_offset != get_streamfile_size(sf))
goto fail;
/* segmented using 3 files (intro/loop/outro). non-segmented wrapper is the same
* but with loop samples instead of sub-sizes */
max_size = 0;
segment_count = 0;
for (i = 0; i < 3; i++) {
size_t segment_size = read_u32le(0x10 + 0x04*i,sf);
max_size += segment_size;
/* may only set 1 segment (Disgaea4's bgm_185) */
if (segment_size)
segment_count++;
}
if (data_size != max_size)
goto fail;
loop_flag = segment_count > 1; /* intro+loop section must exit */
loop_start_segment = 1;
loop_end_segment = 1;
/* init layout */
data = init_layout_segmented(segment_count);
if (!data) goto fail;
/* open each segment subfile */
segment = 0;
for (i = 0; i < 3; i++) {
STREAMFILE* temp_sf;
size_t segment_size = read_u32le(0x10 + 0x04*i,sf);
if (!segment_size)
continue;
temp_sf = setup_subfile_streamfile(sf, segment_offset,segment_size, extension);
if (!temp_sf) goto fail;
data->segments[segment] = init_vgmstream_subfile(temp_sf);
close_streamfile(temp_sf);
if (!data->segments[segment]) goto fail;
segment_offset += segment_size;
segment++;
if (type == 9) {
//todo there are some trailing samples that must be removed for smooth loops, start skip seems ok
//not correct for all files, no idea how to calculate
data->segments[segment]->num_samples -= 374;
}
}
/* setup segmented VGMSTREAMs */
if (!setup_layout_segmented(data))
goto fail;
vgmstream = allocate_segmented_vgmstream(data, loop_flag, loop_start_segment, loop_end_segment);
if (!vgmstream) goto fail;
vgmstream->sample_rate = sample_rate;
vgmstream->meta_type = meta_SPS_N1;
return vgmstream;
fail:
close_vgmstream(vgmstream);
free_layout_segmented(data);
return NULL;
}

View File

@ -393,7 +393,7 @@ VGMSTREAM* (*init_vgmstream_functions[])(STREAMFILE* sf) = {
init_vgmstream_txtp,
init_vgmstream_smc_smh,
init_vgmstream_ppst,
init_vgmstream_opus_sps_n1_segmented,
init_vgmstream_sps_n1_segmented,
init_vgmstream_ubi_bao_pk,
init_vgmstream_ubi_bao_atomic,
init_vgmstream_dsp_switch_audio,

View File

@ -656,7 +656,7 @@ typedef enum {
meta_TXTP, /* generic text playlist */
meta_SMC_SMH, /* Wangan Midnight (System 246) */
meta_PPST, /* PPST [Parappa the Rapper (PSP)] */
meta_OPUS_PPP, /* .at9 Opus [Penny-Punching Princess (Switch)] */
meta_SPS_N1,
meta_UBI_BAO, /* Ubisoft BAO */
meta_DSP_SWITCH_AUDIO, /* Gal Gun 2 (Switch) */
meta_TA_AAC_VITA, /* tri-Ace AAC (Judas Code) */