From a4431c3d5d850e4e71c309cf513ca6ee2ae7b46e Mon Sep 17 00:00:00 2001 From: Alex Barney Date: Mon, 29 Jan 2018 18:07:08 -0600 Subject: [PATCH 1/2] Fix getting samples per frame for Switch Opus Switch Opus uses the same output format that opus_demo writes. Each frame has an 8-byte header. The first 4 bytes contain the length of the frame. The second 4 bytes contain the final state of the range coder. https://github.com/xiph/opus/blob/8299edfc0c34aaf91ef07bf2410ad15423bcaf96/src/opus_demo.c#L658-L681 --- src/coding/ffmpeg_decoder_utils_switch_opus.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/coding/ffmpeg_decoder_utils_switch_opus.c b/src/coding/ffmpeg_decoder_utils_switch_opus.c index 5bc1835e..c44fd0af 100644 --- a/src/coding/ffmpeg_decoder_utils_switch_opus.c +++ b/src/coding/ffmpeg_decoder_utils_switch_opus.c @@ -169,7 +169,7 @@ size_t switch_opus_get_samples(off_t offset, size_t data_size, int sample_rate, uint8_t buf[4]; size_t block_size = read_32bitBE(offset, streamFile); - read_streamfile(buf, offset+4, 4, streamFile); + read_streamfile(buf, offset+8, 4, streamFile); num_samples += get_opus_samples_per_frame(buf, sample_rate); offset += 0x08 + block_size; From 90f09ac562bf05e793e6bf637ad9f59cd13b5740 Mon Sep 17 00:00:00 2001 From: Alex Barney Date: Sat, 10 Feb 2018 17:39:00 -0600 Subject: [PATCH 2/2] Skip initial padding in Switch Opus streams --- src/meta/nsw_opus.c | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/src/meta/nsw_opus.c b/src/meta/nsw_opus.c index 9b6bd83f..7794f77b 100644 --- a/src/meta/nsw_opus.c +++ b/src/meta/nsw_opus.c @@ -9,7 +9,7 @@ VGMSTREAM * init_vgmstream_nsw_opus(STREAMFILE *streamFile) { int loop_flag = 0, channel_count; int num_samples = 0, loop_start = 0, loop_end = 0; off_t offset = 0, data_offset; - size_t data_size; + size_t data_size, skip = 0; /* check extension, case insensitive */ if ( !check_extensions(streamFile,"opus,lopus,nop")) /* no relation to Ogg Opus */ @@ -53,6 +53,7 @@ VGMSTREAM * init_vgmstream_nsw_opus(STREAMFILE *streamFile) { 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_32bitLE(offset + 0x1c, streamFile); if ((uint32_t)read_32bitLE(data_offset, streamFile) != 0x80000004) goto fail; @@ -77,10 +78,9 @@ VGMSTREAM * init_vgmstream_nsw_opus(STREAMFILE *streamFile) { #ifdef VGM_USE_FFMPEG { uint8_t buf[0x100]; - size_t bytes, skip; + size_t bytes; ffmpeg_custom_config cfg; - - skip = 0; //todo + ffmpeg_codec_data *ffmpeg_data; bytes = ffmpeg_make_opus_header(buf,0x100, vgmstream->channels, skip, vgmstream->sample_rate); if (bytes <= 0) goto fail; @@ -88,14 +88,21 @@ VGMSTREAM * init_vgmstream_nsw_opus(STREAMFILE *streamFile) { 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; + 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); + if (vgmstream->num_samples == 0) { + vgmstream->num_samples = switch_opus_get_samples(start_offset, data_size, + vgmstream->sample_rate, streamFile) - skip; + } } #else goto fail;