summaryrefslogtreecommitdiffstats
path: root/apps
diff options
context:
space:
mode:
authorMagnus Holmgren <magnushol@gmail.com>2011-06-18 15:11:30 +0000
committerMagnus Holmgren <magnushol@gmail.com>2011-06-18 15:11:30 +0000
commit6c8ef19dfd49a6410587f2dc9ab8e3731219629d (patch)
tree1c437dd009e9f2d6e873b105e6a6622a745323ca /apps
parent21685577c7628c22af80d1b5185d3b070a1d2a28 (diff)
downloadrockbox-6c8ef19dfd49a6410587f2dc9ab8e3731219629d.tar.gz
rockbox-6c8ef19dfd49a6410587f2dc9ab8e3731219629d.tar.bz2
rockbox-6c8ef19dfd49a6410587f2dc9ab8e3731219629d.zip
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
Diffstat (limited to 'apps')
-rw-r--r--apps/codecs/aac.c35
1 files changed, 28 insertions, 7 deletions
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;
}