Use libvorbis over FFmpeg for AKB Ogg

This commit is contained in:
bnnm 2018-03-24 15:40:01 +01:00
parent 8534006035
commit af639fc92e

View File

@ -36,72 +36,97 @@ fail:
/* AKB - found in SQEX iOS games */
VGMSTREAM * init_vgmstream_akb(STREAMFILE *streamFile) {
VGMSTREAM * vgmstream = NULL;
off_t start_offset, extra_data_offset = 0;
size_t file_size, header_size, extra_header_size = 0, extra_data_size = 0;
int loop_flag = 0, channel_count, codec;
off_t start_offset, extradata_offset = 0;
size_t stream_size, header_size, subheader_size = 0, extradata_size = 0;
int loop_flag = 0, channel_count, codec, sample_rate;
int num_samples, loop_start, loop_end;
/* check extensions */
/* checks */
/* .akb.bytes is the usual extension in later games */
if ( !check_extensions(streamFile, "akb") )
if ( !check_extensions(streamFile, "akb,bytes") )
goto fail;
/* check header */
if (read_32bitBE(0x00,streamFile) != 0x414B4220) /* "AKB " */
goto fail;
if (read_32bitLE(0x08,streamFile) != get_streamfile_size(streamFile))
goto fail;
channel_count = read_8bit(0x0d,streamFile);
/* 0x04(2): version? (iPad/IPhone?) */
header_size = read_16bitLE(0x06,streamFile);
codec = read_8bit(0x0c,streamFile);
channel_count = read_8bit(0x0d,streamFile);
sample_rate = (uint16_t)read_16bitLE(0x0e,streamFile);
num_samples = read_32bitLE(0x10,streamFile);
loop_start = read_32bitLE(0x14,streamFile);
loop_end = read_32bitLE(0x18,streamFile);
/* possibly more complex, see AKB2 */
if (header_size >= 0x44) { /* v2 */
extradata_size = read_16bitLE(0x1c,streamFile);
subheader_size = read_16bitLE(0x28,streamFile);
/* 0x20+: config? (pan, volume), 0x24: file_id? */
extradata_offset = header_size + subheader_size;
start_offset = extradata_offset + extradata_size;
}
else { /* v0 */
start_offset = header_size;
}
stream_size = get_streamfile_size(streamFile) - start_offset;
loop_flag = read_32bitLE(0x18,streamFile) > 0; /* loop end */
/* build the VGMSTREAM */
vgmstream = allocate_vgmstream(channel_count,loop_flag);
if (!vgmstream) goto fail;
/* 0x04 (2): version (iPad/IPhone?) */
header_size = read_16bitLE(0x06,streamFile);
file_size = read_32bitLE(0x08,streamFile);
codec = read_8bit(0x0c,streamFile);
vgmstream->sample_rate = (uint16_t)read_16bitLE(0x0e,streamFile);
vgmstream->num_samples = read_32bitLE(0x10,streamFile);
vgmstream->loop_start_sample = read_32bitLE(0x14,streamFile);
vgmstream->loop_end_sample = read_32bitLE(0x18,streamFile);
vgmstream->sample_rate = sample_rate;
vgmstream->meta_type = meta_AKB;
/* should be ok but not exact (probably more complex, see AKB2) */
if ( header_size >= 0x44) { /* v2 */
/* 0x10+: config? (pan, volume), 0x24: file_id? */
extra_data_size = read_16bitLE(0x1c,streamFile);
extra_header_size = read_16bitLE(0x28,streamFile);
extra_data_offset = header_size + extra_header_size;
start_offset = extra_data_offset + extra_data_size;
/* ~num_samples at extra_data_offset + 0x04/0x0c? */
}
else { /* v0 */
start_offset = header_size;
}
switch (codec) {
case 0x02: { /* MSAPDCM [various SFX] */
vgmstream->coding_type = coding_MSADPCM;
vgmstream->layout_type = layout_none;
vgmstream->interleave_block_size = read_16bitLE(extra_data_offset + 0x02,streamFile);
vgmstream->interleave_block_size = read_16bitLE(extradata_offset + 0x02,streamFile);
/* adjusted samples; bigger or smaller than base samples, but seems more accurate
* (base samples may have more than possible and read over file size otherwise, very strange)
* loop_end seems to exist even with loop disabled */
vgmstream->num_samples = read_32bitLE(extra_data_offset + 0x04, streamFile);
vgmstream->loop_start_sample = read_32bitLE(extra_data_offset + 0x08, streamFile);
vgmstream->loop_end_sample = read_32bitLE(extra_data_offset + 0x0c, streamFile);
vgmstream->num_samples = read_32bitLE(extradata_offset + 0x04, streamFile);
vgmstream->loop_start_sample = read_32bitLE(extradata_offset + 0x08, streamFile);
vgmstream->loop_end_sample = read_32bitLE(extradata_offset + 0x0c, streamFile);
break;
}
#ifdef VGM_USE_FFMPEG
#ifdef VGM_USE_VORBIS
case 0x05: { /* Ogg Vorbis [Final Fantasy VI, Dragon Quest II-VI] */
VGMSTREAM *ogg_vgmstream = NULL;
ogg_vorbis_meta_info_t ovmi = {0};
ovmi.meta_type = vgmstream->meta_type;
ovmi.stream_size = stream_size;
ogg_vgmstream = init_vgmstream_ogg_vorbis_callbacks(streamFile, NULL, start_offset, &ovmi);
if (ogg_vgmstream) {
close_vgmstream(vgmstream);
return ogg_vgmstream;
}
else {
goto fail;
}
break;
}
#elif defined(VGM_USE_FFMPEG)
/* Alt decoding without libvorbis (minor number of beginning samples difference).
* Otherwise same output with (inaudible) +-1 lower byte differences due to rounding. */
case 0x05: { /* Ogg Vorbis [Final Fantasy VI, Dragon Quest II-VI] */
/* Starting from an offset in the current libvorbis code is a bit hard so just use FFmpeg.
* Decoding seems to produce the same output with (inaudible) +-1 lower byte differences due to rounding. */
ffmpeg_codec_data *ffmpeg_data;
ffmpeg_data = init_ffmpeg_offset(streamFile, start_offset,file_size-start_offset);
ffmpeg_data = init_ffmpeg_offset(streamFile, start_offset,stream_size);
if ( !ffmpeg_data ) goto fail;
vgmstream->codec_data = ffmpeg_data;
@ -109,20 +134,30 @@ VGMSTREAM * init_vgmstream_akb(STREAMFILE *streamFile) {
vgmstream->layout_type = layout_none;
/* These oggs have loop info in the comments, too */
vgmstream->num_samples = num_samples;
vgmstream->loop_start_sample = loop_start;
vgmstream->loop_end_sample = loop_end;
break;
}
#endif
#ifdef VGM_USE_FFMPEG
case 0x06: { /* aac [The World Ends with You (iPad)] */
/* init_vgmstream_akb_mp4 above has priority, but this works fine too */
ffmpeg_codec_data *ffmpeg_data;
ffmpeg_data = init_ffmpeg_offset(streamFile, start_offset,file_size-start_offset);
ffmpeg_data = init_ffmpeg_offset(streamFile, start_offset,stream_size-start_offset);
if ( !ffmpeg_data ) goto fail;
vgmstream->codec_data = ffmpeg_data;
vgmstream->coding_type = coding_FFmpeg;
vgmstream->layout_type = layout_none;
vgmstream->num_samples = num_samples;
vgmstream->loop_start_sample = loop_start;
vgmstream->loop_end_sample = loop_end;
/* remove encoder delay from the "global" sample values */
vgmstream->num_samples -= ffmpeg_data->skipSamples;
vgmstream->loop_start_sample -= ffmpeg_data->skipSamples;
@ -235,7 +270,33 @@ VGMSTREAM * init_vgmstream_akb2(STREAMFILE *streamFile) {
break;
}
#ifdef VGM_USE_FFMPEG
#ifdef VGM_USE_VORBIS
case 0x05: { /* Ogg Vorbis [The World Ends with You (iOS / latest update)] */
VGMSTREAM *ogg_vgmstream = NULL;
ogg_vorbis_meta_info_t ovmi = {0};
ovmi.meta_type = vgmstream->meta_type;
ovmi.total_subsongs = total_subsongs;
ovmi.stream_size = stream_size;
ogg_vgmstream = init_vgmstream_ogg_vorbis_callbacks(streamFile, NULL, start_offset, &ovmi);
if (ogg_vgmstream) {
ogg_vgmstream->num_streams = vgmstream->num_streams;
ogg_vgmstream->stream_size = vgmstream->stream_size;
close_vgmstream(vgmstream);
return ogg_vgmstream;
}
else {
goto fail;
}
break;
}
#elif defined(VGM_USE_FFMPEG)
/* Alt decoding without libvorbis (minor number of beginning samples difference).
* Otherwise same output with (inaudible) +-1 lower byte differences due to rounding. */
case 0x05: { /* Ogg Vorbis [The World Ends with You (iOS / latest update)] */
ffmpeg_codec_data *ffmpeg_data;