Improve NSW Opus header handling

This commit is contained in:
Alex Barney 2018-01-26 10:55:39 -06:00
parent 8711f5325e
commit e70c9eaf33

View File

@ -8,7 +8,8 @@ VGMSTREAM * init_vgmstream_nsw_opus(STREAMFILE *streamFile) {
off_t start_offset; off_t start_offset;
int loop_flag = 0, channel_count; int loop_flag = 0, channel_count;
int num_samples = 0, loop_start = 0, loop_end = 0; int num_samples = 0, loop_start = 0, loop_end = 0;
off_t offset = 0; off_t offset = 0, data_offset;
size_t data_size;
/* check extension, case insensitive */ /* check extension, case insensitive */
if ( !check_extensions(streamFile,"opus,lopus,nop")) /* no relation to Ogg Opus */ if ( !check_extensions(streamFile,"opus,lopus,nop")) /* no relation to Ogg Opus */
@ -46,13 +47,19 @@ VGMSTREAM * init_vgmstream_nsw_opus(STREAMFILE *streamFile) {
offset = 0x00; offset = 0x00;
} }
if (read_32bitBE(offset + 0x00,streamFile) != 0x01000080) if ((uint32_t)read_32bitLE(offset + 0x00,streamFile) != 0x80000001)
goto fail; 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);
start_offset = offset + 0x28; if ((uint32_t)read_32bitLE(data_offset, streamFile) != 0x80000004)
channel_count = read_8bit(offset + 0x09,streamFile); /* assumed */ goto fail;
/* 0x0a: packet size if CBR?, other values: no idea */
data_size = read_32bitLE(data_offset + 0x04, streamFile);
start_offset = data_offset + 0x08;
loop_flag = (loop_end > 0); /* -1 when not set */ loop_flag = (loop_end > 0); /* -1 when not set */
@ -70,10 +77,9 @@ VGMSTREAM * init_vgmstream_nsw_opus(STREAMFILE *streamFile) {
#ifdef VGM_USE_FFMPEG #ifdef VGM_USE_FFMPEG
{ {
uint8_t buf[0x100]; uint8_t buf[0x100];
size_t bytes, skip, data_size; size_t bytes, skip;
ffmpeg_custom_config cfg; ffmpeg_custom_config cfg;
data_size = get_streamfile_size(streamFile) - start_offset;
skip = 0; //todo skip = 0; //todo
bytes = ffmpeg_make_opus_header(buf,0x100, vgmstream->channels, skip, vgmstream->sample_rate); bytes = ffmpeg_make_opus_header(buf,0x100, vgmstream->channels, skip, vgmstream->sample_rate);