ffmpeg: AAC cleanup and doc

This commit is contained in:
bnnm 2021-07-23 15:52:31 +02:00
parent 4927761e52
commit 4a178e4e44
7 changed files with 19 additions and 19 deletions

View File

@ -572,7 +572,7 @@ STREAMFILE* ffmpeg_get_streamfile(ffmpeg_codec_data* data);
/* ffmpeg_decoder_utils.c (helper-things) */ /* ffmpeg_decoder_utils.c (helper-things) */
ffmpeg_codec_data* init_ffmpeg_atrac3_raw(STREAMFILE* sf, off_t offset, size_t data_size, int sample_count, int channels, int sample_rate, int block_align, int encoder_delay); ffmpeg_codec_data* init_ffmpeg_atrac3_raw(STREAMFILE* sf, off_t offset, size_t data_size, int sample_count, int channels, int sample_rate, int block_align, int encoder_delay);
ffmpeg_codec_data* init_ffmpeg_atrac3_riff(STREAMFILE* sf, off_t offset, int* out_samples); ffmpeg_codec_data* init_ffmpeg_atrac3_riff(STREAMFILE* sf, off_t offset, int* out_samples);
ffmpeg_codec_data* init_ffmpeg_aac(STREAMFILE* sf, off_t offset, size_t size); ffmpeg_codec_data* init_ffmpeg_aac(STREAMFILE* sf, off_t offset, size_t size, int skip_samples);
/* ffmpeg_decoder_custom_opus.c (helper-things) */ /* ffmpeg_decoder_custom_opus.c (helper-things) */

View File

@ -764,10 +764,8 @@ static ffmpeg_codec_data* init_ffmpeg_custom_opus_config(STREAMFILE* sf, off_t s
/* FFmpeg + libopus: skips samples, notifies skip in codecCtx->delay (not in stream->skip_samples) /* FFmpeg + libopus: skips samples, notifies skip in codecCtx->delay (not in stream->skip_samples)
* FFmpeg + opus: *doesn't* skip, also notifies skip in codecCtx->delay, hurray (possibly fixed in recent versions) * FFmpeg + opus: *doesn't* skip, also notifies skip in codecCtx->delay, hurray (possibly fixed in recent versions)
* FFmpeg + opus is audibly buggy with some low bitrate SSB Ultimate files too */ * FFmpeg + opus is audibly buggy with some low bitrate SSB Ultimate files */
//if (ffmpeg_data->skipSamples <= 0) { //ffmpeg_set_skip_samples(ffmpeg_data, skip);
// ffmpeg_set_skip_samples(ffmpeg_data, skip);
//}
close_streamfile(temp_sf); close_streamfile(temp_sf);
return ffmpeg_data; return ffmpeg_data;

View File

@ -187,7 +187,7 @@ fail:
return NULL; return NULL;
} }
ffmpeg_codec_data* init_ffmpeg_aac(STREAMFILE* sf, off_t offset, size_t size) { ffmpeg_codec_data* init_ffmpeg_aac(STREAMFILE* sf, off_t offset, size_t size, int skip_samples) {
ffmpeg_codec_data* data = NULL; ffmpeg_codec_data* data = NULL;
data = init_ffmpeg_offset(sf, offset, size); data = init_ffmpeg_offset(sf, offset, size);
@ -199,7 +199,7 @@ ffmpeg_codec_data* init_ffmpeg_aac(STREAMFILE* sf, off_t offset, size_t size) {
/* raw AAC doesn't set this, while some decoders like FAAD remove 1024, /* raw AAC doesn't set this, while some decoders like FAAD remove 1024,
* but should be handled in container as each encoder uses its own value * but should be handled in container as each encoder uses its own value
* (Apple: 2112, FAAD: probably 1024, etc) */ * (Apple: 2112, FAAD: probably 1024, etc) */
//ffmpeg_set_skip_samples(data, 1024); ffmpeg_set_skip_samples(data, skip_samples);
return data; return data;
fail: fail:

View File

@ -82,6 +82,9 @@ VGMSTREAM* init_vgmstream_ffmpeg(STREAMFILE* sf) {
* .mus: Marc Ecko's Getting Up (PC) */ * .mus: Marc Ecko's Getting Up (PC) */
if (!num_samples && check_extensions(sf, "mp3,lmp3,mus")) { if (!num_samples && check_extensions(sf, "mp3,lmp3,mus")) {
num_samples = mpeg_get_samples(sf, 0x00, get_streamfile_size(sf)); num_samples = mpeg_get_samples(sf, 0x00, get_streamfile_size(sf));
/* this seems correct thankfully */
//ffmpeg_set_skip_samples(data, encoder_delay);
} }
#endif #endif

View File

@ -6,7 +6,7 @@
VGMSTREAM* init_vgmstream_naac(STREAMFILE* sf) { VGMSTREAM* init_vgmstream_naac(STREAMFILE* sf) {
VGMSTREAM* vgmstream = NULL; VGMSTREAM* vgmstream = NULL;
off_t start_offset; off_t start_offset;
int loop_flag, channels; int loop_flag, channels, skip_samples;
size_t data_size; size_t data_size;
@ -22,6 +22,7 @@ VGMSTREAM* init_vgmstream_naac(STREAMFILE* sf) {
start_offset = 0x1000; start_offset = 0x1000;
loop_flag = (read_s32le(0x18,sf) != 0); loop_flag = (read_s32le(0x18,sf) != 0);
channels = read_s32le(0x08,sf); channels = read_s32le(0x08,sf);
skip_samples = 1024; /* raw AAC doesn't set this */
/* build the VGMSTREAM */ /* build the VGMSTREAM */
vgmstream = allocate_vgmstream(channels, loop_flag); vgmstream = allocate_vgmstream(channels, loop_flag);
@ -42,15 +43,14 @@ VGMSTREAM* init_vgmstream_naac(STREAMFILE* sf) {
#ifdef VGM_USE_FFMPEG #ifdef VGM_USE_FFMPEG
{ {
vgmstream->codec_data = init_ffmpeg_aac(sf, start_offset, data_size); vgmstream->codec_data = init_ffmpeg_aac(sf, start_offset, data_size, skip_samples);
if (!vgmstream->codec_data) goto fail; if (!vgmstream->codec_data) goto fail;
vgmstream->coding_type = coding_FFmpeg; vgmstream->coding_type = coding_FFmpeg;
vgmstream->layout_type = layout_none; vgmstream->layout_type = layout_none;
/* observed default, some files start without silence though seems correct when loop_start=0 */ /* observed default, some files start without silence though seems correct when loop_start=0 */
ffmpeg_set_skip_samples(vgmstream->codec_data, 1024); /* raw AAC doesn't set this */ vgmstream->num_samples -= skip_samples;
vgmstream->num_samples -= 1024; vgmstream->loop_end_sample -= skip_samples;
vgmstream->loop_end_sample -= 1024;
/* for some reason last frame is ignored/bugged in various decoders (gives EOF errors) */ /* for some reason last frame is ignored/bugged in various decoders (gives EOF errors) */
} }
#else #else

View File

@ -4,9 +4,9 @@
/* .STRM - from Abylight 3DS games [Cursed Castilla (3DS)] */ /* .STRM - from Abylight 3DS games [Cursed Castilla (3DS)] */
VGMSTREAM* init_vgmstream_strm_abylight(STREAMFILE* sf) { VGMSTREAM* init_vgmstream_strm_abylight(STREAMFILE* sf) {
VGMSTREAM * vgmstream = NULL; VGMSTREAM* vgmstream = NULL;
off_t start_offset; off_t start_offset;
int loop_flag, channel_count, sample_rate; int loop_flag, channel_count, sample_rate, skip_samples;
size_t data_size; size_t data_size;
@ -22,6 +22,7 @@ VGMSTREAM* init_vgmstream_strm_abylight(STREAMFILE* sf) {
loop_flag = 0; loop_flag = 0;
channel_count = 2; /* there are various possible fields but all files are stereo */ channel_count = 2; /* there are various possible fields but all files are stereo */
sample_rate = read_32bitLE(0x08,sf); sample_rate = read_32bitLE(0x08,sf);
skip_samples = 1024; /* assumed, maybe a bit more */
start_offset = 0x1e; start_offset = 0x1e;
data_size = read_32bitLE(0x10,sf); data_size = read_32bitLE(0x10,sf);
@ -42,14 +43,12 @@ VGMSTREAM* init_vgmstream_strm_abylight(STREAMFILE* sf) {
#ifdef VGM_USE_FFMPEG #ifdef VGM_USE_FFMPEG
{ {
vgmstream->codec_data = init_ffmpeg_aac(sf, start_offset, data_size); vgmstream->codec_data = init_ffmpeg_aac(sf, start_offset, data_size, skip_samples);
if (!vgmstream->codec_data) goto fail; if (!vgmstream->codec_data) goto fail;
vgmstream->coding_type = coding_FFmpeg; vgmstream->coding_type = coding_FFmpeg;
vgmstream->layout_type = layout_none; vgmstream->layout_type = layout_none;
/* assumed, maybe a bit more */ vgmstream->num_samples -= skip_samples;
ffmpeg_set_skip_samples(vgmstream->codec_data, 1024);
vgmstream->num_samples -= 1024;
} }
#else #else
goto fail; goto fail;

View File

@ -486,7 +486,7 @@ VGMSTREAM* init_vgmstream_txth(STREAMFILE* sf) {
vgmstream->num_samples = ffmpeg_data->totalSamples; /* sometimes works */ vgmstream->num_samples = ffmpeg_data->totalSamples; /* sometimes works */
} }
else if (txth.codec == AAC) { else if (txth.codec == AAC) {
ffmpeg_data = init_ffmpeg_aac(txth.sf_body, txth.start_offset, txth.data_size); ffmpeg_data = init_ffmpeg_aac(txth.sf_body, txth.start_offset, txth.data_size, 0);
if (!ffmpeg_data) goto fail; if (!ffmpeg_data) goto fail;
} }
else { else {