summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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)
72 unsigned char c = 0; 72 unsigned char c = 0;
73 void *ret; 73 void *ret;
74 intptr_t param; 74 intptr_t param;
75 bool empty_first_frame = false;
75 76
76 /* Clean and initialize decoder structures */ 77 /* Clean and initialize decoder structures */
77 memset(&demux_res , 0, sizeof(demux_res)); 78 memset(&demux_res , 0, sizeof(demux_res));
@@ -213,10 +214,24 @@ enum codec_status codec_run(void)
213 /* Output the audio */ 214 /* Output the audio */
214 ci->yield(); 215 ci->yield();
215 216
217 if (empty_first_frame)
218 {
219 /* Remove the first frame from lead_trim, under the assumption
220 * that it had the same size as this frame
221 */
222 empty_first_frame = false;
223 lead_trim -= (frame_info.samples >> 1);
224
225 if (lead_trim < 0)
226 {
227 lead_trim = 0;
228 }
229 }
230
216 /* Gather number of samples for the decoded frame. */ 231 /* Gather number of samples for the decoded frame. */
217 framelength = (frame_info.samples >> 1) - lead_trim; 232 framelength = (frame_info.samples >> 1) - lead_trim;
218 233
219 if (i == demux_res.num_sample_byte_sizes - 1 && framelength > 0) 234 if (i == demux_res.num_sample_byte_sizes - 1)
220 { 235 {
221 framelength -= ci->id3->tail_trim; 236 framelength -= ci->id3->tail_trim;
222 } 237 }
@@ -226,15 +241,21 @@ enum codec_status codec_run(void)
226 ci->pcmbuf_insert(&decoder->time_out[0][lead_trim], 241 ci->pcmbuf_insert(&decoder->time_out[0][lead_trim],
227 &decoder->time_out[1][lead_trim], 242 &decoder->time_out[1][lead_trim],
228 framelength); 243 framelength);
229 } 244 }
230 245
231 if (lead_trim > 0) 246 if (lead_trim > 0)
232 { 247 {
233 /* frame_info.samples can be 0 for the first frame */ 248 /* frame_info.samples can be 0 for frame 0. We still want to
234 lead_trim -= (i > 0 || frame_info.samples) 249 * remove it from lead_trim, so do that during frame 1.
235 ? (frame_info.samples >> 1) : (uint32_t)framelength; 250 */
251 if (0 == i && 0 == frame_info.samples)
252 {
253 empty_first_frame = true;
254 }
255
256 lead_trim -= (frame_info.samples >> 1);
236 257
237 if (lead_trim < 0 || ci->id3->lead_trim == 0) 258 if (lead_trim < 0)
238 { 259 {
239 lead_trim = 0; 260 lead_trim = 0;
240 } 261 }