1
0
Fork 0
forked from len0rd/rockbox

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
This commit is contained in:
Magnus Holmgren 2011-06-18 15:11:30 +00:00
parent 21685577c7
commit 6c8ef19dfd

View file

@ -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;
}
if (lead_trim < 0 || ci->id3->lead_trim == 0)
lead_trim -= (frame_info.samples >> 1);
if (lead_trim < 0)
{
lead_trim = 0;
}