From 6c8ef19dfd49a6410587f2dc9ab8e3731219629d Mon Sep 17 00:00:00 2001 From: Magnus Holmgren Date: Sat, 18 Jun 2011 15:11:30 +0000 Subject: FS#12161: Correct the gapless processing for AAC, so that it doesn't remove too much from the start of a track. Also simplify the logic a bit. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@30012 a1c6a512-1295-4272-9138-f99709370657 --- apps/codecs/aac.c | 35 ++++++++++++++++++++++++++++------- 1 file changed, 28 insertions(+), 7 deletions(-) (limited to 'apps') diff --git a/apps/codecs/aac.c b/apps/codecs/aac.c index cd81b5a584..3d43837c99 100644 --- a/apps/codecs/aac.c +++ b/apps/codecs/aac.c @@ -72,6 +72,7 @@ enum codec_status codec_run(void) unsigned char c = 0; void *ret; intptr_t param; + bool empty_first_frame = false; /* Clean and initialize decoder structures */ memset(&demux_res , 0, sizeof(demux_res)); @@ -213,10 +214,24 @@ enum codec_status codec_run(void) /* Output the audio */ ci->yield(); + if (empty_first_frame) + { + /* Remove the first frame from lead_trim, under the assumption + * that it had the same size as this frame + */ + empty_first_frame = false; + lead_trim -= (frame_info.samples >> 1); + + if (lead_trim < 0) + { + lead_trim = 0; + } + } + /* Gather number of samples for the decoded frame. */ framelength = (frame_info.samples >> 1) - lead_trim; - if (i == demux_res.num_sample_byte_sizes - 1 && framelength > 0) + if (i == demux_res.num_sample_byte_sizes - 1) { framelength -= ci->id3->tail_trim; } @@ -226,15 +241,21 @@ enum codec_status codec_run(void) ci->pcmbuf_insert(&decoder->time_out[0][lead_trim], &decoder->time_out[1][lead_trim], framelength); - } - + } + if (lead_trim > 0) { - /* frame_info.samples can be 0 for the first frame */ - lead_trim -= (i > 0 || frame_info.samples) - ? (frame_info.samples >> 1) : (uint32_t)framelength; + /* frame_info.samples can be 0 for frame 0. We still want to + * remove it from lead_trim, so do that during frame 1. + */ + if (0 == i && 0 == frame_info.samples) + { + empty_first_frame = true; + } + + lead_trim -= (frame_info.samples >> 1); - if (lead_trim < 0 || ci->id3->lead_trim == 0) + if (lead_trim < 0) { lead_trim = 0; } -- cgit v1.2.3