diff options
| author | Magnus Holmgren <magnushol@gmail.com> | 2007-06-16 13:00:52 +0000 |
|---|---|---|
| committer | Magnus Holmgren <magnushol@gmail.com> | 2007-06-16 13:00:52 +0000 |
| commit | c3206a455a455fadb282d09f9af482c66b6bdf8e (patch) | |
| tree | ebdddf413b84612d55291c8d64ee233f725dc316 /apps/codecs | |
| parent | 93af4feae9f7890846934f4293d1291daa2901c7 (diff) | |
| download | rockbox-c3206a455a455fadb282d09f9af482c66b6bdf8e.zip rockbox-c3206a455a455fadb282d09f9af482c66b6bdf8e.tar.gz rockbox-c3206a455a455fadb282d09f9af482c66b6bdf8e.tar.bz2 rockbox-c3206a455a455fadb282d09f9af482c66b6bdf8e.tar.xz | |
AAC: Add support for iTunes-style gapless playback.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@13636 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/codecs')
| -rw-r--r-- | apps/codecs/aac.c | 54 |
1 files changed, 52 insertions, 2 deletions
diff --git a/apps/codecs/aac.c b/apps/codecs/aac.c index 11a9d28..d4f051c 100644 --- a/apps/codecs/aac.c +++ b/apps/codecs/aac.c @@ -42,6 +42,8 @@ enum codec_status codec_main(void) uint32_t sample_duration; uint32_t sample_byte_size; int file_offset; + int framelength; + int lead_trim = 0; unsigned int i; unsigned char* buffer; static NeAACDecFrameInfo frame_info; @@ -117,6 +119,11 @@ next_track: sound_samples_done = 0; } } + + if (i == 0) + { + lead_trim = ci->id3->lead_trim; + } /* The main decoding loop */ while (i < demux_res.num_sample_byte_sizes) { @@ -133,6 +140,11 @@ next_track: &sound_samples_done, (int*) &i)) { elapsed_time = (sound_samples_done * 10) / (ci->id3->frequency / 100); ci->set_elapsed(elapsed_time); + + if (i == 0) + { + lead_trim = ci->id3->lead_trim; + } } ci->seek_complete(); } @@ -183,8 +195,46 @@ next_track: /* Output the audio */ ci->yield(); - ci->pcmbuf_insert(decoder->time_out[0], decoder->time_out[1], - frame_info.samples >> 1); + + framelength = (frame_info.samples >> 1) - lead_trim; + + if (i == demux_res.num_sample_byte_sizes - 1 && framelength > 0) + { + /* Currently limited to at most one frame of tail_trim. + * Seems to be enough. + */ + if (ci->id3->tail_trim == 0 + && sample_duration < (frame_info.samples >> 1)) + { + /* Subtract lead_trim just in case we decode a file with + * only one audio frame with actual data. + */ + framelength = sample_duration - lead_trim; + } + else + { + framelength -= ci->id3->tail_trim; + } + } + + if (framelength > 0) + { + 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) : sample_duration; + + if (lead_trim < 0 || ci->id3->lead_trim == 0) + { + lead_trim = 0; + } + } /* Update the elapsed-time indicator */ sound_samples_done += sample_duration; |