mirror of
https://github.com/vgmstream/vgmstream.git
synced 2025-01-17 23:36:41 +01:00
CRLF to LF
This commit is contained in:
parent
eea1c3b489
commit
cf7ef5067a
1682
doc/TXTH.md
1682
doc/TXTH.md
File diff suppressed because it is too large
Load Diff
@ -1,174 +1,174 @@
|
||||
#include "meta.h"
|
||||
#include "../coding/coding.h"
|
||||
|
||||
|
||||
static int get_ogg_page_size(STREAMFILE *streamFile, off_t page_offset, off_t *out_data_offset, size_t *out_page_size);
|
||||
static int ogg_get_num_samples(STREAMFILE *streamFile, off_t start_offset);
|
||||
|
||||
/* Ogg Opus - standard Opus with optional looping comments [The Pillars of Earth (PC), Monster Boy and the Cursed Kingdom (Switch)] */
|
||||
VGMSTREAM * init_vgmstream_ogg_opus(STREAMFILE *streamFile) {
|
||||
VGMSTREAM * vgmstream = NULL;
|
||||
off_t start_offset, data_offset = 0;
|
||||
size_t page_size = 0;
|
||||
int loop_flag, channel_count, original_rate;
|
||||
int loop_start = 0, loop_end = 0;
|
||||
|
||||
|
||||
/* checks */
|
||||
/* .opus: standard, .lopus: fake extension for plugins
|
||||
* .ogg: less common, .logg: same */
|
||||
if (!check_extensions(streamFile, "opus,lopus,ogg,logg"))
|
||||
goto fail;
|
||||
if (read_32bitBE(0x00,streamFile) != 0x4F676753) /* "OggS" */
|
||||
goto fail;
|
||||
/* see: https://tools.ietf.org/html/rfc7845.html */
|
||||
|
||||
start_offset = 0x00;
|
||||
|
||||
/* parse 1st page: opus head */
|
||||
if (!get_ogg_page_size(streamFile, start_offset, &data_offset, &page_size))
|
||||
goto fail;
|
||||
if (read_32bitBE(data_offset+0x00,streamFile) != 0x4F707573 && /* "Opus" */
|
||||
read_32bitBE(data_offset+0x04,streamFile) != 0x48656164) /* "Head" */
|
||||
goto fail;
|
||||
/* 0x01: version 1, fixed */
|
||||
channel_count = read_8bit(data_offset+0x09,streamFile);
|
||||
/* 0x0A: skip samples */
|
||||
original_rate = read_32bitLE(data_offset+0x0c,streamFile);
|
||||
/* 0x10: gain */
|
||||
/* 0x12: mapping family */
|
||||
|
||||
/* parse 2nd page: opus tags (also mandatory) */
|
||||
if (!get_ogg_page_size(streamFile, start_offset+page_size, &data_offset, &page_size))
|
||||
goto fail;
|
||||
if (read_32bitBE(data_offset+0x00,streamFile) != 0x4F707573 && /* "Opus" */
|
||||
read_32bitBE(data_offset+0x04,streamFile) != 0x54616773) /* "Tags" */
|
||||
goto fail;
|
||||
|
||||
loop_flag = 0;
|
||||
{
|
||||
char user_comment[1024+1];
|
||||
off_t offset;
|
||||
int vendor_size, comment_count, user_comment_size, user_comment_max;
|
||||
int i;
|
||||
int has_encoder_options = 0, has_title = 0;
|
||||
|
||||
vendor_size = read_32bitLE(data_offset+0x08,streamFile);
|
||||
comment_count = read_32bitLE(data_offset+0x0c+vendor_size,streamFile);
|
||||
|
||||
/* parse comments */
|
||||
offset = data_offset + 0x0c + vendor_size + 0x04;
|
||||
for (i = 0; i < comment_count; i++) {
|
||||
user_comment_size = read_32bitLE(offset+0x00,streamFile);
|
||||
user_comment_max = user_comment_size > 1024 ? 1024 : user_comment_size;
|
||||
read_string(user_comment,user_comment_max+1, offset+0x04,streamFile);
|
||||
|
||||
|
||||
/* parse loop strings */
|
||||
if (strstr(user_comment,"LOOP_START=")==user_comment) { /* Monster Boy and the Cursed Kingdom (Switch) */
|
||||
loop_start = atol(strrchr(user_comment,'=')+1);
|
||||
loop_flag = (loop_start >= 0);
|
||||
}
|
||||
else if (strstr(user_comment,"LOOP_END=")==user_comment) { /* LOOP_START pair */
|
||||
loop_end = atol(strrchr(user_comment,'=')+1);
|
||||
}
|
||||
else if (strstr(user_comment,"ENCODER_OPTIONS=")==user_comment) { /* for detection */
|
||||
has_encoder_options = 1;
|
||||
}
|
||||
else if (strstr(user_comment,"TITLE=")==user_comment) { /* for detection */
|
||||
has_title = 1;
|
||||
}
|
||||
|
||||
|
||||
//;VGM_LOG("OggOpus: user_comment=%s\n", user_comment);
|
||||
offset += 0x04 + user_comment_size;
|
||||
}
|
||||
|
||||
|
||||
/* Monster Boy has loop points for 44100hz (what), but Opus is resampled so
|
||||
* they must be adjusted (with extra checks just in case). */
|
||||
if (loop_flag && original_rate < 48000 && has_encoder_options && has_title) {
|
||||
float modifier = 48000.0f / (float)original_rate;
|
||||
loop_start = loop_start * modifier;
|
||||
loop_end = loop_end * modifier;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* build the VGMSTREAM */
|
||||
vgmstream = allocate_vgmstream(channel_count, loop_flag);
|
||||
if (!vgmstream) goto fail;
|
||||
|
||||
vgmstream->meta_type = meta_OGG_OPUS;
|
||||
vgmstream->sample_rate = 48000; /* Opus always resamples to this */
|
||||
vgmstream->num_samples = ogg_get_num_samples(streamFile, 0x00);
|
||||
vgmstream->loop_start_sample = loop_start;
|
||||
vgmstream->loop_end_sample = loop_end;
|
||||
|
||||
#ifdef VGM_USE_FFMPEG
|
||||
{
|
||||
vgmstream->codec_data = init_ffmpeg_offset(streamFile, start_offset, get_streamfile_size(streamFile));
|
||||
if (!vgmstream->codec_data) goto fail;
|
||||
vgmstream->coding_type = coding_FFmpeg;
|
||||
vgmstream->layout_type = layout_none;
|
||||
vgmstream->channel_layout = ffmpeg_get_channel_layout(vgmstream->codec_data);
|
||||
/* FFmpeg+libopus handles skip samples ok, FFmpeg+opus doesn't */
|
||||
}
|
||||
#else
|
||||
goto fail;
|
||||
#endif
|
||||
|
||||
if (!vgmstream_open_stream(vgmstream,streamFile,start_offset))
|
||||
goto fail;
|
||||
return vgmstream;
|
||||
|
||||
fail:
|
||||
close_vgmstream(vgmstream);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
/* parse OggS's bizarre segment table */
|
||||
static int get_ogg_page_size(STREAMFILE *streamFile, off_t page_offset, off_t *out_data_offset, size_t *out_page_size) {
|
||||
uint8_t segments;
|
||||
size_t page_size = 0;
|
||||
int i;
|
||||
|
||||
if (read_32bitBE(page_offset+0x00,streamFile) != 0x4F676753) /* "OggS" */
|
||||
goto fail;
|
||||
|
||||
/* read all segment sizes */
|
||||
segments = (uint8_t)read_8bit(page_offset+0x1a, streamFile);
|
||||
for (i = 0; i < segments; i++) {
|
||||
page_size += (uint8_t)read_8bit(page_offset + 0x1b + i, streamFile);
|
||||
}
|
||||
page_size += 0x1b + segments;
|
||||
|
||||
if (out_data_offset) *out_data_offset = page_offset + 0x1b + segments;
|
||||
if (out_page_size) *out_page_size = page_size;
|
||||
return 1;
|
||||
fail:
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Ogg doesn't have num_samples info, must manually seek+read last granule
|
||||
* (Xiph is insistent this is the One True Way). */
|
||||
static int ogg_get_num_samples(STREAMFILE *streamFile, off_t start_offset) {
|
||||
uint32_t expected_id = 0x4F676753;
|
||||
off_t offset = get_streamfile_size(streamFile) - 0x04-0x01-0x01-0x08-0x04-0x04-0x04;
|
||||
|
||||
//todo better buffer reads (Ogg page max is 0xFFFF)
|
||||
//lame way to force buffer, assuming it's around that
|
||||
read_32bitBE(offset - 0x4000, streamFile);
|
||||
|
||||
while (offset >= start_offset) {
|
||||
uint32_t current_id = read_32bitBE(offset, streamFile);
|
||||
if (current_id == expected_id) { /* if more checks are needed last page starts with 0x0004 */
|
||||
return read_32bitLE(offset+0x04+0x01+0x01, streamFile); /* get last granule = total samples (64b but whatevs) */
|
||||
}
|
||||
|
||||
offset--;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
#include "meta.h"
|
||||
#include "../coding/coding.h"
|
||||
|
||||
|
||||
static int get_ogg_page_size(STREAMFILE *streamFile, off_t page_offset, off_t *out_data_offset, size_t *out_page_size);
|
||||
static int ogg_get_num_samples(STREAMFILE *streamFile, off_t start_offset);
|
||||
|
||||
/* Ogg Opus - standard Opus with optional looping comments [The Pillars of Earth (PC), Monster Boy and the Cursed Kingdom (Switch)] */
|
||||
VGMSTREAM * init_vgmstream_ogg_opus(STREAMFILE *streamFile) {
|
||||
VGMSTREAM * vgmstream = NULL;
|
||||
off_t start_offset, data_offset = 0;
|
||||
size_t page_size = 0;
|
||||
int loop_flag, channel_count, original_rate;
|
||||
int loop_start = 0, loop_end = 0;
|
||||
|
||||
|
||||
/* checks */
|
||||
/* .opus: standard, .lopus: fake extension for plugins
|
||||
* .ogg: less common, .logg: same */
|
||||
if (!check_extensions(streamFile, "opus,lopus,ogg,logg"))
|
||||
goto fail;
|
||||
if (read_32bitBE(0x00,streamFile) != 0x4F676753) /* "OggS" */
|
||||
goto fail;
|
||||
/* see: https://tools.ietf.org/html/rfc7845.html */
|
||||
|
||||
start_offset = 0x00;
|
||||
|
||||
/* parse 1st page: opus head */
|
||||
if (!get_ogg_page_size(streamFile, start_offset, &data_offset, &page_size))
|
||||
goto fail;
|
||||
if (read_32bitBE(data_offset+0x00,streamFile) != 0x4F707573 && /* "Opus" */
|
||||
read_32bitBE(data_offset+0x04,streamFile) != 0x48656164) /* "Head" */
|
||||
goto fail;
|
||||
/* 0x01: version 1, fixed */
|
||||
channel_count = read_8bit(data_offset+0x09,streamFile);
|
||||
/* 0x0A: skip samples */
|
||||
original_rate = read_32bitLE(data_offset+0x0c,streamFile);
|
||||
/* 0x10: gain */
|
||||
/* 0x12: mapping family */
|
||||
|
||||
/* parse 2nd page: opus tags (also mandatory) */
|
||||
if (!get_ogg_page_size(streamFile, start_offset+page_size, &data_offset, &page_size))
|
||||
goto fail;
|
||||
if (read_32bitBE(data_offset+0x00,streamFile) != 0x4F707573 && /* "Opus" */
|
||||
read_32bitBE(data_offset+0x04,streamFile) != 0x54616773) /* "Tags" */
|
||||
goto fail;
|
||||
|
||||
loop_flag = 0;
|
||||
{
|
||||
char user_comment[1024+1];
|
||||
off_t offset;
|
||||
int vendor_size, comment_count, user_comment_size, user_comment_max;
|
||||
int i;
|
||||
int has_encoder_options = 0, has_title = 0;
|
||||
|
||||
vendor_size = read_32bitLE(data_offset+0x08,streamFile);
|
||||
comment_count = read_32bitLE(data_offset+0x0c+vendor_size,streamFile);
|
||||
|
||||
/* parse comments */
|
||||
offset = data_offset + 0x0c + vendor_size + 0x04;
|
||||
for (i = 0; i < comment_count; i++) {
|
||||
user_comment_size = read_32bitLE(offset+0x00,streamFile);
|
||||
user_comment_max = user_comment_size > 1024 ? 1024 : user_comment_size;
|
||||
read_string(user_comment,user_comment_max+1, offset+0x04,streamFile);
|
||||
|
||||
|
||||
/* parse loop strings */
|
||||
if (strstr(user_comment,"LOOP_START=")==user_comment) { /* Monster Boy and the Cursed Kingdom (Switch) */
|
||||
loop_start = atol(strrchr(user_comment,'=')+1);
|
||||
loop_flag = (loop_start >= 0);
|
||||
}
|
||||
else if (strstr(user_comment,"LOOP_END=")==user_comment) { /* LOOP_START pair */
|
||||
loop_end = atol(strrchr(user_comment,'=')+1);
|
||||
}
|
||||
else if (strstr(user_comment,"ENCODER_OPTIONS=")==user_comment) { /* for detection */
|
||||
has_encoder_options = 1;
|
||||
}
|
||||
else if (strstr(user_comment,"TITLE=")==user_comment) { /* for detection */
|
||||
has_title = 1;
|
||||
}
|
||||
|
||||
|
||||
//;VGM_LOG("OggOpus: user_comment=%s\n", user_comment);
|
||||
offset += 0x04 + user_comment_size;
|
||||
}
|
||||
|
||||
|
||||
/* Monster Boy has loop points for 44100hz (what), but Opus is resampled so
|
||||
* they must be adjusted (with extra checks just in case). */
|
||||
if (loop_flag && original_rate < 48000 && has_encoder_options && has_title) {
|
||||
float modifier = 48000.0f / (float)original_rate;
|
||||
loop_start = loop_start * modifier;
|
||||
loop_end = loop_end * modifier;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* build the VGMSTREAM */
|
||||
vgmstream = allocate_vgmstream(channel_count, loop_flag);
|
||||
if (!vgmstream) goto fail;
|
||||
|
||||
vgmstream->meta_type = meta_OGG_OPUS;
|
||||
vgmstream->sample_rate = 48000; /* Opus always resamples to this */
|
||||
vgmstream->num_samples = ogg_get_num_samples(streamFile, 0x00);
|
||||
vgmstream->loop_start_sample = loop_start;
|
||||
vgmstream->loop_end_sample = loop_end;
|
||||
|
||||
#ifdef VGM_USE_FFMPEG
|
||||
{
|
||||
vgmstream->codec_data = init_ffmpeg_offset(streamFile, start_offset, get_streamfile_size(streamFile));
|
||||
if (!vgmstream->codec_data) goto fail;
|
||||
vgmstream->coding_type = coding_FFmpeg;
|
||||
vgmstream->layout_type = layout_none;
|
||||
vgmstream->channel_layout = ffmpeg_get_channel_layout(vgmstream->codec_data);
|
||||
/* FFmpeg+libopus handles skip samples ok, FFmpeg+opus doesn't */
|
||||
}
|
||||
#else
|
||||
goto fail;
|
||||
#endif
|
||||
|
||||
if (!vgmstream_open_stream(vgmstream,streamFile,start_offset))
|
||||
goto fail;
|
||||
return vgmstream;
|
||||
|
||||
fail:
|
||||
close_vgmstream(vgmstream);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
/* parse OggS's bizarre segment table */
|
||||
static int get_ogg_page_size(STREAMFILE *streamFile, off_t page_offset, off_t *out_data_offset, size_t *out_page_size) {
|
||||
uint8_t segments;
|
||||
size_t page_size = 0;
|
||||
int i;
|
||||
|
||||
if (read_32bitBE(page_offset+0x00,streamFile) != 0x4F676753) /* "OggS" */
|
||||
goto fail;
|
||||
|
||||
/* read all segment sizes */
|
||||
segments = (uint8_t)read_8bit(page_offset+0x1a, streamFile);
|
||||
for (i = 0; i < segments; i++) {
|
||||
page_size += (uint8_t)read_8bit(page_offset + 0x1b + i, streamFile);
|
||||
}
|
||||
page_size += 0x1b + segments;
|
||||
|
||||
if (out_data_offset) *out_data_offset = page_offset + 0x1b + segments;
|
||||
if (out_page_size) *out_page_size = page_size;
|
||||
return 1;
|
||||
fail:
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Ogg doesn't have num_samples info, must manually seek+read last granule
|
||||
* (Xiph is insistent this is the One True Way). */
|
||||
static int ogg_get_num_samples(STREAMFILE *streamFile, off_t start_offset) {
|
||||
uint32_t expected_id = 0x4F676753;
|
||||
off_t offset = get_streamfile_size(streamFile) - 0x04-0x01-0x01-0x08-0x04-0x04-0x04;
|
||||
|
||||
//todo better buffer reads (Ogg page max is 0xFFFF)
|
||||
//lame way to force buffer, assuming it's around that
|
||||
read_32bitBE(offset - 0x4000, streamFile);
|
||||
|
||||
while (offset >= start_offset) {
|
||||
uint32_t current_id = read_32bitBE(offset, streamFile);
|
||||
if (current_id == expected_id) { /* if more checks are needed last page starts with 0x0004 */
|
||||
return read_32bitLE(offset+0x04+0x01+0x01, streamFile); /* get last granule = total samples (64b but whatevs) */
|
||||
}
|
||||
|
||||
offset--;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
878
src/meta/opus.c
878
src/meta/opus.c
@ -1,439 +1,439 @@
|
||||
#include "meta.h"
|
||||
#include "../coding/coding.h"
|
||||
#include "../layout/layout.h"
|
||||
#include "opus_interleave_streamfile.h"
|
||||
|
||||
/* Nintendo OPUS - from Switch games, including header variations (not the same as Ogg Opus) */
|
||||
|
||||
static VGMSTREAM * init_vgmstream_opus(STREAMFILE *streamFile, meta_t meta_type, off_t offset, int32_t num_samples, int32_t loop_start, int32_t loop_end) {
|
||||
VGMSTREAM * vgmstream = NULL;
|
||||
off_t start_offset;
|
||||
int loop_flag = 0, channel_count;
|
||||
off_t data_offset, multichannel_offset = 0;
|
||||
size_t data_size, skip = 0;
|
||||
|
||||
|
||||
if ((uint32_t)read_32bitLE(offset + 0x00,streamFile) != 0x80000001)
|
||||
goto fail;
|
||||
|
||||
channel_count = read_8bit(offset + 0x09, streamFile);
|
||||
/* 0x0a: packet size if CBR, 0 if VBR */
|
||||
data_offset = offset + read_32bitLE(offset + 0x10, streamFile);
|
||||
skip = read_16bitLE(offset + 0x1c, streamFile);
|
||||
/* 0x1e: ? (seen in Lego Movie 2 (Switch)) */
|
||||
|
||||
/* recent >2ch info [Clannad (Switch)] */
|
||||
if ((uint32_t)read_32bitLE(offset + 0x20, streamFile) == 0x80000005) {
|
||||
multichannel_offset = offset + 0x20;
|
||||
}
|
||||
|
||||
if ((uint32_t)read_32bitLE(data_offset, streamFile) != 0x80000004)
|
||||
goto fail;
|
||||
|
||||
data_size = read_32bitLE(data_offset + 0x04, streamFile);
|
||||
|
||||
start_offset = data_offset + 0x08;
|
||||
loop_flag = (loop_end > 0); /* -1 when not set */
|
||||
|
||||
|
||||
/* build the VGMSTREAM */
|
||||
vgmstream = allocate_vgmstream(channel_count,loop_flag);
|
||||
if (!vgmstream) goto fail;
|
||||
|
||||
vgmstream->meta_type = meta_type;
|
||||
vgmstream->sample_rate = read_32bitLE(offset + 0x0c,streamFile);
|
||||
if (vgmstream->sample_rate == 16000)
|
||||
vgmstream->sample_rate = 48000; // Grandia HD Collection contains a false sample_rate in header
|
||||
vgmstream->num_samples = num_samples;
|
||||
vgmstream->loop_start_sample = loop_start;
|
||||
vgmstream->loop_end_sample = loop_end;
|
||||
vgmstream->stream_size = data_size; /* to avoid inflated sizes from fake OggS IO */
|
||||
|
||||
#ifdef VGM_USE_FFMPEG
|
||||
{
|
||||
opus_config cfg = {0};
|
||||
|
||||
cfg.channels = vgmstream->channels;
|
||||
cfg.skip = skip;
|
||||
cfg.sample_rate = vgmstream->sample_rate;
|
||||
|
||||
if (multichannel_offset && vgmstream->channels <= 8) {
|
||||
int i;
|
||||
cfg.stream_count = read_8bit(multichannel_offset + 0x08,streamFile);
|
||||
cfg.coupled_count = read_8bit(multichannel_offset + 0x09,streamFile);
|
||||
for (i = 0; i < vgmstream->channels; i++) {
|
||||
cfg.channel_mapping[i] = read_8bit(multichannel_offset + 0x0a + i,streamFile);
|
||||
}
|
||||
}
|
||||
|
||||
vgmstream->codec_data = init_ffmpeg_switch_opus_config(streamFile, start_offset,data_size, &cfg);
|
||||
if (!vgmstream->codec_data) goto fail;
|
||||
vgmstream->coding_type = coding_FFmpeg;
|
||||
vgmstream->layout_type = layout_none;
|
||||
vgmstream->channel_layout = ffmpeg_get_channel_layout(vgmstream->codec_data);
|
||||
|
||||
if (vgmstream->num_samples == 0) {
|
||||
vgmstream->num_samples = switch_opus_get_samples(start_offset, data_size, streamFile) - skip;
|
||||
}
|
||||
}
|
||||
#else
|
||||
goto fail;
|
||||
#endif
|
||||
|
||||
if ( !vgmstream_open_stream(vgmstream, streamFile, start_offset) )
|
||||
goto fail;
|
||||
return vgmstream;
|
||||
|
||||
fail:
|
||||
close_vgmstream(vgmstream);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
/* standard Switch Opus, Nintendo header + raw data (generated by opus_test.c?) [Lego City Undercover (Switch)] */
|
||||
VGMSTREAM * init_vgmstream_opus_std(STREAMFILE *streamFile) {
|
||||
STREAMFILE * PSIFile = NULL;
|
||||
off_t offset;
|
||||
int num_samples, loop_start, loop_end;
|
||||
|
||||
/* checks */
|
||||
if (!check_extensions(streamFile,"opus,lopus"))
|
||||
goto fail;
|
||||
|
||||
offset = 0x00;
|
||||
|
||||
/* BlazBlue: Cross Tag Battle (Switch) PSI Metadata for corresponding Opus */
|
||||
/* Maybe future Arc System Works games will use this too? */
|
||||
PSIFile = open_streamfile_by_ext(streamFile, "psi");
|
||||
if (PSIFile) {
|
||||
num_samples = read_32bitLE(0x8C, PSIFile);
|
||||
loop_start = read_32bitLE(0x84, PSIFile);
|
||||
loop_end = read_32bitLE(0x88, PSIFile);
|
||||
close_streamfile(PSIFile);
|
||||
}
|
||||
else {
|
||||
num_samples = 0;
|
||||
loop_start = 0;
|
||||
loop_end = 0;
|
||||
}
|
||||
|
||||
return init_vgmstream_opus(streamFile, meta_OPUS, offset, num_samples,loop_start,loop_end);
|
||||
fail:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Nippon1 variation [Disgaea 5 (Switch)] */
|
||||
VGMSTREAM * init_vgmstream_opus_n1(STREAMFILE *streamFile) {
|
||||
off_t offset;
|
||||
int num_samples, loop_start, loop_end;
|
||||
|
||||
/* checks */
|
||||
if ( !check_extensions(streamFile,"opus,lopus"))
|
||||
goto fail;
|
||||
if (!((read_32bitBE(0x04,streamFile) == 0x00000000 && read_32bitBE(0x0c,streamFile) == 0x00000000) ||
|
||||
(read_32bitBE(0x04,streamFile) == 0xFFFFFFFF && read_32bitBE(0x0c,streamFile) == 0xFFFFFFFF)))
|
||||
goto fail;
|
||||
|
||||
offset = 0x10;
|
||||
num_samples = 0;
|
||||
loop_start = read_32bitLE(0x00,streamFile);
|
||||
loop_end = read_32bitLE(0x08,streamFile);
|
||||
|
||||
return init_vgmstream_opus(streamFile, meta_OPUS, offset, num_samples,loop_start,loop_end);
|
||||
fail:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Capcom variation [Ultra Street Fighter II (Switch), Resident Evil: Revelations (Switch)] */
|
||||
VGMSTREAM * init_vgmstream_opus_capcom(STREAMFILE *streamFile) {
|
||||
VGMSTREAM *vgmstream = NULL;
|
||||
off_t offset;
|
||||
int num_samples, loop_start, loop_end;
|
||||
int channel_count;
|
||||
|
||||
/* checks */
|
||||
if ( !check_extensions(streamFile,"opus,lopus"))
|
||||
goto fail;
|
||||
|
||||
channel_count = read_32bitLE(0x04,streamFile);
|
||||
if (channel_count != 1 && channel_count != 2 && channel_count != 6)
|
||||
goto fail; /* unknown stream layout */
|
||||
|
||||
num_samples = read_32bitLE(0x00,streamFile);
|
||||
/* 0x04: channels, >2 uses interleaved streams (2ch+2ch+2ch) */
|
||||
loop_start = read_32bitLE(0x08,streamFile);
|
||||
loop_end = read_32bitLE(0x0c,streamFile);
|
||||
/* 0x10: frame size (with extra data) */
|
||||
/* 0x14: extra chunk count */
|
||||
/* 0x18: null */
|
||||
offset = read_32bitLE(0x1c,streamFile);
|
||||
/* 0x20-8: config? (0x0077C102 04000000 E107070C) */
|
||||
/* 0x2c: some size? */
|
||||
/* 0x30+: extra chunks (0x00: 0x7f, 0x04: num_sample), alt loop starts/regions? */
|
||||
|
||||
if (channel_count == 6) {
|
||||
/* 2ch multistream hacky-hacks, don't try this at home. We'll end up with:
|
||||
* main vgmstream > N vgmstream layers > substream IO deinterleaver > opus meta > Opus IO transmogrifier (phew) */
|
||||
layered_layout_data* data = NULL;
|
||||
int layers = channel_count / 2;
|
||||
int i;
|
||||
int loop_flag = (loop_end > 0);
|
||||
|
||||
|
||||
/* build the VGMSTREAM */
|
||||
vgmstream = allocate_vgmstream(channel_count,loop_flag);
|
||||
if (!vgmstream) goto fail;
|
||||
|
||||
vgmstream->layout_type = layout_layered;
|
||||
|
||||
/* init layout */
|
||||
data = init_layout_layered(layers);
|
||||
if (!data) goto fail;
|
||||
vgmstream->layout_data = data;
|
||||
|
||||
/* open each layer subfile */
|
||||
for (i = 0; i < layers; i++) {
|
||||
STREAMFILE* temp_streamFile = setup_opus_interleave_streamfile(streamFile, offset+0x28*i, layers);
|
||||
if (!temp_streamFile) goto fail;
|
||||
|
||||
data->layers[i] = init_vgmstream_opus(temp_streamFile, meta_OPUS, 0x00, num_samples,loop_start,loop_end);
|
||||
close_streamfile(temp_streamFile);
|
||||
if (!data->layers[i]) goto fail;
|
||||
}
|
||||
|
||||
/* setup layered VGMSTREAMs */
|
||||
if (!setup_layout_layered(data))
|
||||
goto fail;
|
||||
|
||||
vgmstream->sample_rate = data->layers[0]->sample_rate;
|
||||
vgmstream->num_samples = data->layers[0]->num_samples;
|
||||
vgmstream->loop_start_sample = data->layers[0]->loop_start_sample;
|
||||
vgmstream->loop_end_sample = data->layers[0]->loop_end_sample;
|
||||
vgmstream->meta_type = meta_OPUS;
|
||||
vgmstream->coding_type = data->layers[0]->coding_type;
|
||||
|
||||
return vgmstream;
|
||||
}
|
||||
else {
|
||||
return init_vgmstream_opus(streamFile, meta_OPUS, offset, num_samples,loop_start,loop_end);
|
||||
}
|
||||
|
||||
|
||||
fail:
|
||||
close_vgmstream(vgmstream);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Procyon Studio variation [Xenoblade Chronicles 2 (Switch)] */
|
||||
VGMSTREAM * init_vgmstream_opus_nop(STREAMFILE *streamFile) {
|
||||
off_t offset;
|
||||
int num_samples, loop_start = 0, loop_end = 0, loop_flag;
|
||||
|
||||
/* checks */
|
||||
if (!check_extensions(streamFile,"nop"))
|
||||
goto fail;
|
||||
if (read_32bitBE(0x00, streamFile) != 0x73616466 || /* "sadf" */
|
||||
read_32bitBE(0x08, streamFile) != 0x6f707573) /* "opus" */
|
||||
goto fail;
|
||||
|
||||
offset = read_32bitLE(0x1c, streamFile);
|
||||
num_samples = read_32bitLE(0x28, streamFile);
|
||||
loop_flag = read_8bit(0x19, streamFile);
|
||||
if (loop_flag) {
|
||||
loop_start = read_32bitLE(0x2c, streamFile);
|
||||
loop_end = read_32bitLE(0x30, streamFile);
|
||||
}
|
||||
|
||||
return init_vgmstream_opus(streamFile, meta_OPUS, offset, num_samples,loop_start,loop_end);
|
||||
fail:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Shin'en variation [Fast RMX (Switch)] */
|
||||
VGMSTREAM * init_vgmstream_opus_shinen(STREAMFILE *streamFile) {
|
||||
off_t offset = 0;
|
||||
int num_samples, loop_start, loop_end;
|
||||
|
||||
/* checks */
|
||||
if ( !check_extensions(streamFile,"opus,lopus"))
|
||||
goto fail;
|
||||
if (read_32bitBE(0x08,streamFile) != 0x01000080)
|
||||
goto fail;
|
||||
|
||||
offset = 0x08;
|
||||
num_samples = 0;
|
||||
loop_start = read_32bitLE(0x00,streamFile);
|
||||
loop_end = read_32bitLE(0x04,streamFile); /* 0 if no loop */
|
||||
|
||||
if (loop_start > loop_end)
|
||||
goto fail; /* just in case */
|
||||
|
||||
return init_vgmstream_opus(streamFile, meta_OPUS, offset, num_samples,loop_start,loop_end);
|
||||
fail:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Bandai Namco Opus (found in NUS3Banks) [Taiko no Tatsujin: Nintendo Switch Version!] */
|
||||
VGMSTREAM * init_vgmstream_opus_nus3(STREAMFILE *streamFile) {
|
||||
off_t offset = 0;
|
||||
int num_samples = 0, loop_start = 0, loop_end = 0, loop_flag;
|
||||
|
||||
/* checks */
|
||||
/* .opus: header ID (they only exist inside .nus3bank) */
|
||||
if (!check_extensions(streamFile, "opus,lopus"))
|
||||
goto fail;
|
||||
if (read_32bitBE(0x00, streamFile) != 0x4F505553) /* "OPUS" */
|
||||
goto fail;
|
||||
|
||||
/* Here's an interesting quirk, OPUS header contains big endian values
|
||||
while the Nintendo Opus header and data that follows remain little endian as usual */
|
||||
offset = read_32bitBE(0x20, streamFile);
|
||||
num_samples = read_32bitBE(0x08, streamFile);
|
||||
|
||||
/* Check if there's a loop end value to determine loop_flag*/
|
||||
loop_flag = read_32bitBE(0x18, streamFile);
|
||||
if (loop_flag) {
|
||||
loop_start = read_32bitBE(0x14, streamFile);
|
||||
loop_end = read_32bitBE(0x18, streamFile);
|
||||
}
|
||||
|
||||
return init_vgmstream_opus(streamFile, meta_OPUS, offset, num_samples, loop_start, loop_end);
|
||||
fail:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Nippon Ichi SPS wrapper (non-segmented) [Ys VIII: Lacrimosa of Dana (Switch)] */
|
||||
VGMSTREAM * init_vgmstream_opus_sps_n1(STREAMFILE *streamFile) {
|
||||
off_t offset;
|
||||
int num_samples, loop_start = 0, loop_end = 0, loop_flag;
|
||||
|
||||
/* checks */
|
||||
/* .sps: Labyrinth of Refrain - Coven of Dusk (Switch)
|
||||
* .nlsd: Disgaea Refine (Switch), Ys VIII (Switch) */
|
||||
if (!check_extensions(streamFile, "sps,nlsd"))
|
||||
goto fail;
|
||||
if (read_32bitBE(0x00, streamFile) != 0x09000000) /* file type (see other N1 SPS) */
|
||||
goto fail;
|
||||
|
||||
offset = 0x1C;
|
||||
num_samples = read_32bitLE(0x0C, streamFile);
|
||||
|
||||
/* sections num_samples (remnant of segmented opus_sps_n1):
|
||||
* 0x10: intro, 0x14: loop, 0x18: end (all must add up to num_samples) */
|
||||
loop_flag = read_32bitLE(0x18, streamFile); /* with loop disabled only loop section has samples */
|
||||
if (loop_flag) {
|
||||
loop_start = read_32bitLE(0x10, streamFile);
|
||||
loop_end = loop_start + read_32bitLE(0x14, streamFile);
|
||||
}
|
||||
|
||||
return init_vgmstream_opus(streamFile, meta_OPUS, offset, num_samples, loop_start, loop_end);
|
||||
fail:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* AQUASTYLE wrapper [Touhou Genso Wanderer -Reloaded- (Switch)] */
|
||||
VGMSTREAM * init_vgmstream_opus_opusx(STREAMFILE *streamFile) {
|
||||
off_t offset;
|
||||
int num_samples, loop_start = 0, loop_end = 0;
|
||||
float modifier;
|
||||
|
||||
/* checks */
|
||||
if (!check_extensions(streamFile, "opusx"))
|
||||
goto fail;
|
||||
if (read_32bitBE(0x00, streamFile) != 0x4F505553) /* "OPUS" */
|
||||
goto fail;
|
||||
|
||||
offset = 0x10;
|
||||
/* values are for the original 44100 files, but Opus resamples to 48000 */
|
||||
modifier = 48000.0f / 44100.0f;
|
||||
num_samples = 0;//read_32bitLE(0x04, streamFile) * modifier; /* better use calc'd num_samples */
|
||||
loop_start = read_32bitLE(0x08, streamFile) * modifier;
|
||||
loop_end = read_32bitLE(0x0c, streamFile) * modifier;
|
||||
|
||||
/* resampling calcs are slighly off and may to over num_samples, but by removing delay seems ok */
|
||||
if (loop_start >= 120) {
|
||||
loop_start -= 128;
|
||||
loop_end -= 128;
|
||||
}
|
||||
else {
|
||||
loop_end = 0;
|
||||
}
|
||||
|
||||
return init_vgmstream_opus(streamFile, meta_OPUS, offset, num_samples, loop_start, loop_end);
|
||||
fail:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Prototype variation [Clannad (Switch)] */
|
||||
VGMSTREAM * init_vgmstream_opus_prototype(STREAMFILE *streamFile) {
|
||||
off_t offset = 0;
|
||||
int num_samples = 0, loop_start = 0, loop_end = 0, loop_flag;
|
||||
|
||||
/* checks */
|
||||
if (!check_extensions(streamFile, "opus,lopus"))
|
||||
goto fail;
|
||||
if (read_32bitBE(0x00, streamFile) != 0x4F505553 || /* "OPUS" */
|
||||
read_32bitBE(0x18, streamFile) != 0x01000080)
|
||||
goto fail;
|
||||
|
||||
offset = 0x18;
|
||||
num_samples = read_32bitLE(0x08, streamFile);
|
||||
|
||||
/* Check if there's a loop end value to determine loop_flag*/
|
||||
loop_flag = read_32bitLE(0x10, streamFile);
|
||||
if (loop_flag) {
|
||||
loop_start = read_32bitLE(0x0C, streamFile);
|
||||
loop_end = read_32bitLE(0x10, streamFile);
|
||||
}
|
||||
|
||||
return init_vgmstream_opus(streamFile, meta_OPUS, offset, num_samples, loop_start, loop_end);
|
||||
fail:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Edelweiss variation [Astebreed (Switch)] */
|
||||
VGMSTREAM * init_vgmstream_opus_opusnx(STREAMFILE *streamFile) {
|
||||
off_t offset = 0;
|
||||
int num_samples = 0, loop_start = 0, loop_end = 0;
|
||||
|
||||
/* checks */
|
||||
if (!check_extensions(streamFile, "opus,lopus"))
|
||||
goto fail;
|
||||
if (read_64bitBE(0x00, streamFile) != 0x4F5055534E580000) /* "OPUSNX\0\0" */
|
||||
goto fail;
|
||||
|
||||
offset = 0x10;
|
||||
num_samples = 0; //read_32bitLE(0x08, streamFile); /* samples with encoder delay */
|
||||
if (read_32bitLE(0x0c, streamFile) != 0)
|
||||
goto fail;
|
||||
|
||||
return init_vgmstream_opus(streamFile, meta_OPUS, offset, num_samples, loop_start, loop_end);
|
||||
fail:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Square Enix variation [Dragon Quest I-III (Switch)] */
|
||||
VGMSTREAM * init_vgmstream_opus_sqex(STREAMFILE *streamFile) {
|
||||
off_t offset = 0;
|
||||
int num_samples = 0, loop_start = 0, loop_end = 0, loop_flag;
|
||||
|
||||
/* checks */
|
||||
if (!check_extensions(streamFile, "opus,lopus"))
|
||||
goto fail;
|
||||
if (read_64bitBE(0x00, streamFile) != 0x0100000002000000)
|
||||
goto fail;
|
||||
|
||||
offset = read_32bitLE(0x0C, streamFile);
|
||||
num_samples = read_32bitLE(0x1C, streamFile);
|
||||
|
||||
/* Check if there's a loop end value to determine loop_flag*/
|
||||
loop_flag = read_32bitLE(0x18, streamFile);
|
||||
if (loop_flag) {
|
||||
loop_start = read_32bitLE(0x14, streamFile);
|
||||
loop_end = read_32bitLE(0x18, streamFile);
|
||||
}
|
||||
|
||||
return init_vgmstream_opus(streamFile, meta_OPUS, offset, num_samples, loop_start, loop_end);
|
||||
fail:
|
||||
return NULL;
|
||||
}
|
||||
#include "meta.h"
|
||||
#include "../coding/coding.h"
|
||||
#include "../layout/layout.h"
|
||||
#include "opus_interleave_streamfile.h"
|
||||
|
||||
/* Nintendo OPUS - from Switch games, including header variations (not the same as Ogg Opus) */
|
||||
|
||||
static VGMSTREAM * init_vgmstream_opus(STREAMFILE *streamFile, meta_t meta_type, off_t offset, int32_t num_samples, int32_t loop_start, int32_t loop_end) {
|
||||
VGMSTREAM * vgmstream = NULL;
|
||||
off_t start_offset;
|
||||
int loop_flag = 0, channel_count;
|
||||
off_t data_offset, multichannel_offset = 0;
|
||||
size_t data_size, skip = 0;
|
||||
|
||||
|
||||
if ((uint32_t)read_32bitLE(offset + 0x00,streamFile) != 0x80000001)
|
||||
goto fail;
|
||||
|
||||
channel_count = read_8bit(offset + 0x09, streamFile);
|
||||
/* 0x0a: packet size if CBR, 0 if VBR */
|
||||
data_offset = offset + read_32bitLE(offset + 0x10, streamFile);
|
||||
skip = read_16bitLE(offset + 0x1c, streamFile);
|
||||
/* 0x1e: ? (seen in Lego Movie 2 (Switch)) */
|
||||
|
||||
/* recent >2ch info [Clannad (Switch)] */
|
||||
if ((uint32_t)read_32bitLE(offset + 0x20, streamFile) == 0x80000005) {
|
||||
multichannel_offset = offset + 0x20;
|
||||
}
|
||||
|
||||
if ((uint32_t)read_32bitLE(data_offset, streamFile) != 0x80000004)
|
||||
goto fail;
|
||||
|
||||
data_size = read_32bitLE(data_offset + 0x04, streamFile);
|
||||
|
||||
start_offset = data_offset + 0x08;
|
||||
loop_flag = (loop_end > 0); /* -1 when not set */
|
||||
|
||||
|
||||
/* build the VGMSTREAM */
|
||||
vgmstream = allocate_vgmstream(channel_count,loop_flag);
|
||||
if (!vgmstream) goto fail;
|
||||
|
||||
vgmstream->meta_type = meta_type;
|
||||
vgmstream->sample_rate = read_32bitLE(offset + 0x0c,streamFile);
|
||||
if (vgmstream->sample_rate == 16000)
|
||||
vgmstream->sample_rate = 48000; // Grandia HD Collection contains a false sample_rate in header
|
||||
vgmstream->num_samples = num_samples;
|
||||
vgmstream->loop_start_sample = loop_start;
|
||||
vgmstream->loop_end_sample = loop_end;
|
||||
vgmstream->stream_size = data_size; /* to avoid inflated sizes from fake OggS IO */
|
||||
|
||||
#ifdef VGM_USE_FFMPEG
|
||||
{
|
||||
opus_config cfg = {0};
|
||||
|
||||
cfg.channels = vgmstream->channels;
|
||||
cfg.skip = skip;
|
||||
cfg.sample_rate = vgmstream->sample_rate;
|
||||
|
||||
if (multichannel_offset && vgmstream->channels <= 8) {
|
||||
int i;
|
||||
cfg.stream_count = read_8bit(multichannel_offset + 0x08,streamFile);
|
||||
cfg.coupled_count = read_8bit(multichannel_offset + 0x09,streamFile);
|
||||
for (i = 0; i < vgmstream->channels; i++) {
|
||||
cfg.channel_mapping[i] = read_8bit(multichannel_offset + 0x0a + i,streamFile);
|
||||
}
|
||||
}
|
||||
|
||||
vgmstream->codec_data = init_ffmpeg_switch_opus_config(streamFile, start_offset,data_size, &cfg);
|
||||
if (!vgmstream->codec_data) goto fail;
|
||||
vgmstream->coding_type = coding_FFmpeg;
|
||||
vgmstream->layout_type = layout_none;
|
||||
vgmstream->channel_layout = ffmpeg_get_channel_layout(vgmstream->codec_data);
|
||||
|
||||
if (vgmstream->num_samples == 0) {
|
||||
vgmstream->num_samples = switch_opus_get_samples(start_offset, data_size, streamFile) - skip;
|
||||
}
|
||||
}
|
||||
#else
|
||||
goto fail;
|
||||
#endif
|
||||
|
||||
if ( !vgmstream_open_stream(vgmstream, streamFile, start_offset) )
|
||||
goto fail;
|
||||
return vgmstream;
|
||||
|
||||
fail:
|
||||
close_vgmstream(vgmstream);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
/* standard Switch Opus, Nintendo header + raw data (generated by opus_test.c?) [Lego City Undercover (Switch)] */
|
||||
VGMSTREAM * init_vgmstream_opus_std(STREAMFILE *streamFile) {
|
||||
STREAMFILE * PSIFile = NULL;
|
||||
off_t offset;
|
||||
int num_samples, loop_start, loop_end;
|
||||
|
||||
/* checks */
|
||||
if (!check_extensions(streamFile,"opus,lopus"))
|
||||
goto fail;
|
||||
|
||||
offset = 0x00;
|
||||
|
||||
/* BlazBlue: Cross Tag Battle (Switch) PSI Metadata for corresponding Opus */
|
||||
/* Maybe future Arc System Works games will use this too? */
|
||||
PSIFile = open_streamfile_by_ext(streamFile, "psi");
|
||||
if (PSIFile) {
|
||||
num_samples = read_32bitLE(0x8C, PSIFile);
|
||||
loop_start = read_32bitLE(0x84, PSIFile);
|
||||
loop_end = read_32bitLE(0x88, PSIFile);
|
||||
close_streamfile(PSIFile);
|
||||
}
|
||||
else {
|
||||
num_samples = 0;
|
||||
loop_start = 0;
|
||||
loop_end = 0;
|
||||
}
|
||||
|
||||
return init_vgmstream_opus(streamFile, meta_OPUS, offset, num_samples,loop_start,loop_end);
|
||||
fail:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Nippon1 variation [Disgaea 5 (Switch)] */
|
||||
VGMSTREAM * init_vgmstream_opus_n1(STREAMFILE *streamFile) {
|
||||
off_t offset;
|
||||
int num_samples, loop_start, loop_end;
|
||||
|
||||
/* checks */
|
||||
if ( !check_extensions(streamFile,"opus,lopus"))
|
||||
goto fail;
|
||||
if (!((read_32bitBE(0x04,streamFile) == 0x00000000 && read_32bitBE(0x0c,streamFile) == 0x00000000) ||
|
||||
(read_32bitBE(0x04,streamFile) == 0xFFFFFFFF && read_32bitBE(0x0c,streamFile) == 0xFFFFFFFF)))
|
||||
goto fail;
|
||||
|
||||
offset = 0x10;
|
||||
num_samples = 0;
|
||||
loop_start = read_32bitLE(0x00,streamFile);
|
||||
loop_end = read_32bitLE(0x08,streamFile);
|
||||
|
||||
return init_vgmstream_opus(streamFile, meta_OPUS, offset, num_samples,loop_start,loop_end);
|
||||
fail:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Capcom variation [Ultra Street Fighter II (Switch), Resident Evil: Revelations (Switch)] */
|
||||
VGMSTREAM * init_vgmstream_opus_capcom(STREAMFILE *streamFile) {
|
||||
VGMSTREAM *vgmstream = NULL;
|
||||
off_t offset;
|
||||
int num_samples, loop_start, loop_end;
|
||||
int channel_count;
|
||||
|
||||
/* checks */
|
||||
if ( !check_extensions(streamFile,"opus,lopus"))
|
||||
goto fail;
|
||||
|
||||
channel_count = read_32bitLE(0x04,streamFile);
|
||||
if (channel_count != 1 && channel_count != 2 && channel_count != 6)
|
||||
goto fail; /* unknown stream layout */
|
||||
|
||||
num_samples = read_32bitLE(0x00,streamFile);
|
||||
/* 0x04: channels, >2 uses interleaved streams (2ch+2ch+2ch) */
|
||||
loop_start = read_32bitLE(0x08,streamFile);
|
||||
loop_end = read_32bitLE(0x0c,streamFile);
|
||||
/* 0x10: frame size (with extra data) */
|
||||
/* 0x14: extra chunk count */
|
||||
/* 0x18: null */
|
||||
offset = read_32bitLE(0x1c,streamFile);
|
||||
/* 0x20-8: config? (0x0077C102 04000000 E107070C) */
|
||||
/* 0x2c: some size? */
|
||||
/* 0x30+: extra chunks (0x00: 0x7f, 0x04: num_sample), alt loop starts/regions? */
|
||||
|
||||
if (channel_count == 6) {
|
||||
/* 2ch multistream hacky-hacks, don't try this at home. We'll end up with:
|
||||
* main vgmstream > N vgmstream layers > substream IO deinterleaver > opus meta > Opus IO transmogrifier (phew) */
|
||||
layered_layout_data* data = NULL;
|
||||
int layers = channel_count / 2;
|
||||
int i;
|
||||
int loop_flag = (loop_end > 0);
|
||||
|
||||
|
||||
/* build the VGMSTREAM */
|
||||
vgmstream = allocate_vgmstream(channel_count,loop_flag);
|
||||
if (!vgmstream) goto fail;
|
||||
|
||||
vgmstream->layout_type = layout_layered;
|
||||
|
||||
/* init layout */
|
||||
data = init_layout_layered(layers);
|
||||
if (!data) goto fail;
|
||||
vgmstream->layout_data = data;
|
||||
|
||||
/* open each layer subfile */
|
||||
for (i = 0; i < layers; i++) {
|
||||
STREAMFILE* temp_streamFile = setup_opus_interleave_streamfile(streamFile, offset+0x28*i, layers);
|
||||
if (!temp_streamFile) goto fail;
|
||||
|
||||
data->layers[i] = init_vgmstream_opus(temp_streamFile, meta_OPUS, 0x00, num_samples,loop_start,loop_end);
|
||||
close_streamfile(temp_streamFile);
|
||||
if (!data->layers[i]) goto fail;
|
||||
}
|
||||
|
||||
/* setup layered VGMSTREAMs */
|
||||
if (!setup_layout_layered(data))
|
||||
goto fail;
|
||||
|
||||
vgmstream->sample_rate = data->layers[0]->sample_rate;
|
||||
vgmstream->num_samples = data->layers[0]->num_samples;
|
||||
vgmstream->loop_start_sample = data->layers[0]->loop_start_sample;
|
||||
vgmstream->loop_end_sample = data->layers[0]->loop_end_sample;
|
||||
vgmstream->meta_type = meta_OPUS;
|
||||
vgmstream->coding_type = data->layers[0]->coding_type;
|
||||
|
||||
return vgmstream;
|
||||
}
|
||||
else {
|
||||
return init_vgmstream_opus(streamFile, meta_OPUS, offset, num_samples,loop_start,loop_end);
|
||||
}
|
||||
|
||||
|
||||
fail:
|
||||
close_vgmstream(vgmstream);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Procyon Studio variation [Xenoblade Chronicles 2 (Switch)] */
|
||||
VGMSTREAM * init_vgmstream_opus_nop(STREAMFILE *streamFile) {
|
||||
off_t offset;
|
||||
int num_samples, loop_start = 0, loop_end = 0, loop_flag;
|
||||
|
||||
/* checks */
|
||||
if (!check_extensions(streamFile,"nop"))
|
||||
goto fail;
|
||||
if (read_32bitBE(0x00, streamFile) != 0x73616466 || /* "sadf" */
|
||||
read_32bitBE(0x08, streamFile) != 0x6f707573) /* "opus" */
|
||||
goto fail;
|
||||
|
||||
offset = read_32bitLE(0x1c, streamFile);
|
||||
num_samples = read_32bitLE(0x28, streamFile);
|
||||
loop_flag = read_8bit(0x19, streamFile);
|
||||
if (loop_flag) {
|
||||
loop_start = read_32bitLE(0x2c, streamFile);
|
||||
loop_end = read_32bitLE(0x30, streamFile);
|
||||
}
|
||||
|
||||
return init_vgmstream_opus(streamFile, meta_OPUS, offset, num_samples,loop_start,loop_end);
|
||||
fail:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Shin'en variation [Fast RMX (Switch)] */
|
||||
VGMSTREAM * init_vgmstream_opus_shinen(STREAMFILE *streamFile) {
|
||||
off_t offset = 0;
|
||||
int num_samples, loop_start, loop_end;
|
||||
|
||||
/* checks */
|
||||
if ( !check_extensions(streamFile,"opus,lopus"))
|
||||
goto fail;
|
||||
if (read_32bitBE(0x08,streamFile) != 0x01000080)
|
||||
goto fail;
|
||||
|
||||
offset = 0x08;
|
||||
num_samples = 0;
|
||||
loop_start = read_32bitLE(0x00,streamFile);
|
||||
loop_end = read_32bitLE(0x04,streamFile); /* 0 if no loop */
|
||||
|
||||
if (loop_start > loop_end)
|
||||
goto fail; /* just in case */
|
||||
|
||||
return init_vgmstream_opus(streamFile, meta_OPUS, offset, num_samples,loop_start,loop_end);
|
||||
fail:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Bandai Namco Opus (found in NUS3Banks) [Taiko no Tatsujin: Nintendo Switch Version!] */
|
||||
VGMSTREAM * init_vgmstream_opus_nus3(STREAMFILE *streamFile) {
|
||||
off_t offset = 0;
|
||||
int num_samples = 0, loop_start = 0, loop_end = 0, loop_flag;
|
||||
|
||||
/* checks */
|
||||
/* .opus: header ID (they only exist inside .nus3bank) */
|
||||
if (!check_extensions(streamFile, "opus,lopus"))
|
||||
goto fail;
|
||||
if (read_32bitBE(0x00, streamFile) != 0x4F505553) /* "OPUS" */
|
||||
goto fail;
|
||||
|
||||
/* Here's an interesting quirk, OPUS header contains big endian values
|
||||
while the Nintendo Opus header and data that follows remain little endian as usual */
|
||||
offset = read_32bitBE(0x20, streamFile);
|
||||
num_samples = read_32bitBE(0x08, streamFile);
|
||||
|
||||
/* Check if there's a loop end value to determine loop_flag*/
|
||||
loop_flag = read_32bitBE(0x18, streamFile);
|
||||
if (loop_flag) {
|
||||
loop_start = read_32bitBE(0x14, streamFile);
|
||||
loop_end = read_32bitBE(0x18, streamFile);
|
||||
}
|
||||
|
||||
return init_vgmstream_opus(streamFile, meta_OPUS, offset, num_samples, loop_start, loop_end);
|
||||
fail:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Nippon Ichi SPS wrapper (non-segmented) [Ys VIII: Lacrimosa of Dana (Switch)] */
|
||||
VGMSTREAM * init_vgmstream_opus_sps_n1(STREAMFILE *streamFile) {
|
||||
off_t offset;
|
||||
int num_samples, loop_start = 0, loop_end = 0, loop_flag;
|
||||
|
||||
/* checks */
|
||||
/* .sps: Labyrinth of Refrain - Coven of Dusk (Switch)
|
||||
* .nlsd: Disgaea Refine (Switch), Ys VIII (Switch) */
|
||||
if (!check_extensions(streamFile, "sps,nlsd"))
|
||||
goto fail;
|
||||
if (read_32bitBE(0x00, streamFile) != 0x09000000) /* file type (see other N1 SPS) */
|
||||
goto fail;
|
||||
|
||||
offset = 0x1C;
|
||||
num_samples = read_32bitLE(0x0C, streamFile);
|
||||
|
||||
/* sections num_samples (remnant of segmented opus_sps_n1):
|
||||
* 0x10: intro, 0x14: loop, 0x18: end (all must add up to num_samples) */
|
||||
loop_flag = read_32bitLE(0x18, streamFile); /* with loop disabled only loop section has samples */
|
||||
if (loop_flag) {
|
||||
loop_start = read_32bitLE(0x10, streamFile);
|
||||
loop_end = loop_start + read_32bitLE(0x14, streamFile);
|
||||
}
|
||||
|
||||
return init_vgmstream_opus(streamFile, meta_OPUS, offset, num_samples, loop_start, loop_end);
|
||||
fail:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* AQUASTYLE wrapper [Touhou Genso Wanderer -Reloaded- (Switch)] */
|
||||
VGMSTREAM * init_vgmstream_opus_opusx(STREAMFILE *streamFile) {
|
||||
off_t offset;
|
||||
int num_samples, loop_start = 0, loop_end = 0;
|
||||
float modifier;
|
||||
|
||||
/* checks */
|
||||
if (!check_extensions(streamFile, "opusx"))
|
||||
goto fail;
|
||||
if (read_32bitBE(0x00, streamFile) != 0x4F505553) /* "OPUS" */
|
||||
goto fail;
|
||||
|
||||
offset = 0x10;
|
||||
/* values are for the original 44100 files, but Opus resamples to 48000 */
|
||||
modifier = 48000.0f / 44100.0f;
|
||||
num_samples = 0;//read_32bitLE(0x04, streamFile) * modifier; /* better use calc'd num_samples */
|
||||
loop_start = read_32bitLE(0x08, streamFile) * modifier;
|
||||
loop_end = read_32bitLE(0x0c, streamFile) * modifier;
|
||||
|
||||
/* resampling calcs are slighly off and may to over num_samples, but by removing delay seems ok */
|
||||
if (loop_start >= 120) {
|
||||
loop_start -= 128;
|
||||
loop_end -= 128;
|
||||
}
|
||||
else {
|
||||
loop_end = 0;
|
||||
}
|
||||
|
||||
return init_vgmstream_opus(streamFile, meta_OPUS, offset, num_samples, loop_start, loop_end);
|
||||
fail:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Prototype variation [Clannad (Switch)] */
|
||||
VGMSTREAM * init_vgmstream_opus_prototype(STREAMFILE *streamFile) {
|
||||
off_t offset = 0;
|
||||
int num_samples = 0, loop_start = 0, loop_end = 0, loop_flag;
|
||||
|
||||
/* checks */
|
||||
if (!check_extensions(streamFile, "opus,lopus"))
|
||||
goto fail;
|
||||
if (read_32bitBE(0x00, streamFile) != 0x4F505553 || /* "OPUS" */
|
||||
read_32bitBE(0x18, streamFile) != 0x01000080)
|
||||
goto fail;
|
||||
|
||||
offset = 0x18;
|
||||
num_samples = read_32bitLE(0x08, streamFile);
|
||||
|
||||
/* Check if there's a loop end value to determine loop_flag*/
|
||||
loop_flag = read_32bitLE(0x10, streamFile);
|
||||
if (loop_flag) {
|
||||
loop_start = read_32bitLE(0x0C, streamFile);
|
||||
loop_end = read_32bitLE(0x10, streamFile);
|
||||
}
|
||||
|
||||
return init_vgmstream_opus(streamFile, meta_OPUS, offset, num_samples, loop_start, loop_end);
|
||||
fail:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Edelweiss variation [Astebreed (Switch)] */
|
||||
VGMSTREAM * init_vgmstream_opus_opusnx(STREAMFILE *streamFile) {
|
||||
off_t offset = 0;
|
||||
int num_samples = 0, loop_start = 0, loop_end = 0;
|
||||
|
||||
/* checks */
|
||||
if (!check_extensions(streamFile, "opus,lopus"))
|
||||
goto fail;
|
||||
if (read_64bitBE(0x00, streamFile) != 0x4F5055534E580000) /* "OPUSNX\0\0" */
|
||||
goto fail;
|
||||
|
||||
offset = 0x10;
|
||||
num_samples = 0; //read_32bitLE(0x08, streamFile); /* samples with encoder delay */
|
||||
if (read_32bitLE(0x0c, streamFile) != 0)
|
||||
goto fail;
|
||||
|
||||
return init_vgmstream_opus(streamFile, meta_OPUS, offset, num_samples, loop_start, loop_end);
|
||||
fail:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Square Enix variation [Dragon Quest I-III (Switch)] */
|
||||
VGMSTREAM * init_vgmstream_opus_sqex(STREAMFILE *streamFile) {
|
||||
off_t offset = 0;
|
||||
int num_samples = 0, loop_start = 0, loop_end = 0, loop_flag;
|
||||
|
||||
/* checks */
|
||||
if (!check_extensions(streamFile, "opus,lopus"))
|
||||
goto fail;
|
||||
if (read_64bitBE(0x00, streamFile) != 0x0100000002000000)
|
||||
goto fail;
|
||||
|
||||
offset = read_32bitLE(0x0C, streamFile);
|
||||
num_samples = read_32bitLE(0x1C, streamFile);
|
||||
|
||||
/* Check if there's a loop end value to determine loop_flag*/
|
||||
loop_flag = read_32bitLE(0x18, streamFile);
|
||||
if (loop_flag) {
|
||||
loop_start = read_32bitLE(0x14, streamFile);
|
||||
loop_end = read_32bitLE(0x18, streamFile);
|
||||
}
|
||||
|
||||
return init_vgmstream_opus(streamFile, meta_OPUS, offset, num_samples, loop_start, loop_end);
|
||||
fail:
|
||||
return NULL;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user