Add .opus [Lego City Undercover]

This commit is contained in:
bnnm 2017-09-30 01:27:47 +02:00
parent c3568ffd26
commit 16786b78d4
11 changed files with 98 additions and 1 deletions

View File

@ -207,6 +207,7 @@ VGMSTREAM_DECLARE_FILE_TYPE("NWA", nwa);
VGMSTREAM_DECLARE_FILE_TYPE("OGL", ogl);
VGMSTREAM_DECLARE_FILE_TYPE("OMA", oma);
VGMSTREAM_DECLARE_FILE_TYPE("OMU", omu);
VGMSTREAM_DECLARE_FILE_TYPE("OPUS", opus);
VGMSTREAM_DECLARE_FILE_TYPE("OTM", otm);
VGMSTREAM_DECLARE_FILE_TYPE("P2BT", p2bt);

View File

@ -215,6 +215,9 @@ void ffmpeg_set_skip_samples(ffmpeg_codec_data * data, int skip_samples);
size_t ffmpeg_make_opus_header(uint8_t * buf, int buf_size, int channels, int skip, int sample_rate);
size_t ffmpeg_get_eaxma_virtual_size(int channels, off_t real_offset, size_t real_size, STREAMFILE *streamFile);
size_t switch_opus_get_samples(off_t offset, size_t data_size, int sample_rate, STREAMFILE *streamFile);
#endif
/* coding_utils */

View File

@ -159,7 +159,23 @@ int64_t ffmpeg_custom_size_switch_opus(ffmpeg_codec_data *data) {
return virtual_size;
}
size_t switch_opus_get_samples(off_t offset, size_t data_size, int sample_rate, STREAMFILE *streamFile) {
size_t num_samples = 0;
off_t end_offset = offset + data_size;
/* count by reading all frames */
while (offset < end_offset) {
uint8_t buf[4];
size_t block_size = read_32bitBE(offset, streamFile);
read_streamfile(buf, offset+4, 4, streamFile);
num_samples += get_opus_samples_per_frame(buf, sample_rate);
offset += 0x08 + block_size;
}
return num_samples;
}
/* ************************************************** */
@ -342,5 +358,4 @@ fail:
return 0;
}
#endif

View File

@ -200,6 +200,7 @@ static const char* extension_list[] = {
"ogl",
"oma", //FFmpeg, not parsed (ATRAC3/ATRAC3PLUS/MP3/LPCM/WMA)
"omu",
"opus",
"otm",
"p1d", //txth/reserved [Farming Simulator 18 (3DS)]
@ -888,6 +889,7 @@ static const meta_info meta_info_list[] = {
{meta_BINK, "RAD Game Tools Bink header"},
{meta_EA_SNU, "Electronic Arts SNU header"},
{meta_AWC, "Rockstar AWC header"},
{meta_NSW_OPUS, ".OPUS header"},
#ifdef VGM_USE_VORBIS
{meta_OGG_VORBIS, "Ogg Vorbis"},

View File

@ -622,6 +622,10 @@
RelativePath=".\meta\ngca.c"
>
</File>
<File
RelativePath=".\meta\nsw_opus.c"
>
</File>
<File
RelativePath=".\meta\nub_vag.c"
>

View File

@ -157,6 +157,7 @@
<ClCompile Include="meta\mn_str.c" />
<ClCompile Include="meta\mp4.c" />
<ClCompile Include="meta\ngca.c" />
<ClCompile Include="meta\nsw_opus.c" />
<ClCompile Include="meta\nub_vag.c" />
<ClCompile Include="meta\pc_adp.c" />
<ClCompile Include="meta\pc_snds.c" />

View File

@ -1012,6 +1012,9 @@
<ClCompile Include="meta\ngca.c">
<Filter>meta\Source Files</Filter>
</ClCompile>
<ClCompile Include="meta\nsw_opus.c">
<Filter>meta\Source Files</Filter>
</ClCompile>
<ClCompile Include="meta\ps2_mtaf.c">
<Filter>meta\Source Files</Filter>
</ClCompile>

View File

@ -682,4 +682,6 @@ VGMSTREAM * init_vgmstream_ea_snu(STREAMFILE * streamFile);
VGMSTREAM * init_vgmstream_awc(STREAMFILE * streamFile);
VGMSTREAM * init_vgmstream_nsw_opus(STREAMFILE * streamFile);
#endif /*_META_H*/

64
src/meta/nsw_opus.c Normal file
View File

@ -0,0 +1,64 @@
#include "meta.h"
#include "../util.h"
#include "../coding/coding.h"
/* .OPUS - from Lego City Undercover (Switch) */
VGMSTREAM * init_vgmstream_nsw_opus(STREAMFILE *streamFile) {
VGMSTREAM * vgmstream = NULL;
off_t start_offset;
int loop_flag = 0, channel_count;
/* check extension, case insensitive */
if ( !check_extensions(streamFile,"opus")) /* no relation to Ogg Opus */
goto fail;
if (read_32bitBE(0x00,streamFile) != 0x01000080)
goto fail;
start_offset = 0x28;
channel_count = read_8bit(0x09,streamFile); /* assumed */
/* other values in the header: no idea */
/* build the VGMSTREAM */
vgmstream = allocate_vgmstream(channel_count,loop_flag);
if (!vgmstream) goto fail;
vgmstream->sample_rate = read_32bitLE(0x0c,streamFile);
vgmstream->meta_type = meta_NSW_OPUS;
#ifdef VGM_USE_FFMPEG
{
uint8_t buf[0x100];
size_t bytes, skip, data_size;
ffmpeg_custom_config cfg;
data_size = get_streamfile_size(streamFile) - start_offset;
skip = 0; //todo
bytes = ffmpeg_make_opus_header(buf,0x100, vgmstream->channels, skip, vgmstream->sample_rate);
if (bytes <= 0) goto fail;
memset(&cfg, 0, sizeof(ffmpeg_custom_config));
cfg.type = FFMPEG_SWITCH_OPUS;
vgmstream->codec_data = init_ffmpeg_config(streamFile, buf,bytes, start_offset,data_size, &cfg);
if (!vgmstream->codec_data) goto fail;
vgmstream->coding_type = coding_FFmpeg;
vgmstream->layout_type = layout_none;
vgmstream->num_samples = switch_opus_get_samples(start_offset, data_size, vgmstream->sample_rate, streamFile);
}
#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

@ -369,6 +369,7 @@ VGMSTREAM * (*init_vgmstream_fcns[])(STREAMFILE *streamFile) = {
init_vgmstream_stm,
init_vgmstream_ea_snu,
init_vgmstream_awc,
init_vgmstream_nsw_opus,
init_vgmstream_txth, /* should go at the end (lower priority) */
#ifdef VGM_USE_FFMPEG

View File

@ -626,6 +626,7 @@ typedef enum {
meta_BINK, /* RAD Game Tools BINK audio/video */
meta_EA_SNU, /* Electronic Arts SNU (Dead Space) */
meta_AWC, /* Rockstar AWC (GTA5, RDR) */
meta_NSW_OPUS, /* Lego City Undercover (Switch) */
#ifdef VGM_USE_VORBIS
meta_OGG_VORBIS, /* Ogg Vorbis */