Merge pull request #271 from bxaimc/master

Add Entergram NXA Opus
This commit is contained in:
Christopher Snowhill 2018-08-01 15:31:06 -07:00 committed by GitHub
commit d1f1646533
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 75 additions and 0 deletions

View File

@ -244,6 +244,7 @@ static const char* extension_list[] = {
"npsf", //fake extension/header id for .nps (to be removed)
"nus3bank",
"nwa",
"nxa",
//"ogg", //common
"ogl",

View File

@ -679,6 +679,7 @@ VGMSTREAM * init_vgmstream_opus_nop(STREAMFILE * streamFile);
VGMSTREAM * init_vgmstream_opus_shinen(STREAMFILE * streamFile);
VGMSTREAM * init_vgmstream_opus_nus3(STREAMFILE * streamFile);
VGMSTREAM * init_vgmstream_opus_nlsd(STREAMFILE * streamFile);
VGMSTREAM * init_vgmstream_opus_nxa(STREAMFILE * streamFile);
VGMSTREAM * init_vgmstream_pc_al2(STREAMFILE * streamFile);

View File

@ -332,3 +332,75 @@ VGMSTREAM * init_vgmstream_opus_nlsd(STREAMFILE *streamFile) {
fail:
return NULL;
}
/* Entergram NXA Opus [Higurashi no Naku Koro ni Hou (Switch)] */
VGMSTREAM * init_vgmstream_opus_nxa(STREAMFILE *streamFile) {
VGMSTREAM * vgmstream = NULL;
off_t start_offset;
int loop_flag = 0, channel_count;
size_t data_size, skip = 0;
/* checks */
if (!check_extensions(streamFile, "nxa"))
goto fail;
if (read_32bitBE(0x00, streamFile) != 0x4E584131) /* "NXA1" */
goto fail;
channel_count = read_16bitLE(0x10, streamFile);
skip = read_16bitLE(0x16, streamFile);
data_size = read_32bitLE(0x08, streamFile)-0x30;
start_offset = 0x30;
/* TODO: Determine if loop points are stored externally. No visible loop points in header */
loop_flag = 0;
/* build the VGMSTREAM */
vgmstream = allocate_vgmstream(channel_count, loop_flag);
if (!vgmstream) goto fail;
vgmstream->num_samples = read_32bitLE(0x20, streamFile);
vgmstream->sample_rate = read_32bitLE(0x0C, streamFile);
vgmstream->meta_type = meta_OPUS;
#ifdef VGM_USE_FFMPEG
{
uint8_t buf[0x100];
size_t bytes;
ffmpeg_custom_config cfg = { 0 };
ffmpeg_codec_data *ffmpeg_data;
bytes = ffmpeg_make_opus_header(buf, 0x100, vgmstream->channels, skip, vgmstream->sample_rate);
if (bytes <= 0) goto fail;
cfg.type = FFMPEG_SWITCH_OPUS;
ffmpeg_data = init_ffmpeg_config(streamFile, buf, bytes, start_offset, data_size, &cfg);
if (!ffmpeg_data) goto fail;
vgmstream->codec_data = ffmpeg_data;
vgmstream->coding_type = coding_FFmpeg;
vgmstream->layout_type = layout_none;
if (ffmpeg_data->skipSamples <= 0) {
ffmpeg_set_skip_samples(ffmpeg_data, skip);
}
if (vgmstream->num_samples == 0) {
vgmstream->num_samples = switch_opus_get_samples(start_offset, data_size,
vgmstream->sample_rate, streamFile) - skip;
}
}
#else
goto fail;
#endif
/* open the file for reading */
if (!vgmstream_open_stream(vgmstream, streamFile, start_offset))
goto fail;
return vgmstream;
fail:
close_vgmstream(vgmstream);
return NULL;
}

View File

@ -373,6 +373,7 @@ VGMSTREAM * (*init_vgmstream_functions[])(STREAMFILE *streamFile) = {
init_vgmstream_opus_shinen,
init_vgmstream_opus_nus3,
init_vgmstream_opus_nlsd,
init_vgmstream_opus_nxa,
init_vgmstream_pc_al2,
init_vgmstream_pc_ast,
init_vgmstream_naac,