summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--apps/codecs/aac.c39
1 files changed, 6 insertions, 33 deletions
diff --git a/apps/codecs/aac.c b/apps/codecs/aac.c
index 309c05da38..849d87bedf 100644
--- a/apps/codecs/aac.c
+++ b/apps/codecs/aac.c
@@ -47,8 +47,6 @@ enum codec_status codec_main(void)
47 stream_t input_stream; 47 stream_t input_stream;
48 uint32_t sound_samples_done; 48 uint32_t sound_samples_done;
49 uint32_t elapsed_time; 49 uint32_t elapsed_time;
50 uint32_t sample_duration;
51 uint32_t sample_byte_size;
52 int file_offset; 50 int file_offset;
53 int framelength; 51 int framelength;
54 int lead_trim = 0; 52 int lead_trim = 0;
@@ -207,22 +205,14 @@ next_track:
207 ci->seek_complete(); 205 ci->seek_complete();
208 } 206 }
209 207
210 /* Lookup the length (in samples and bytes) of block i */
211 if (!get_sample_info(&demux_res, i, &sample_duration,
212 &sample_byte_size)) {
213 LOGF("AAC: get_sample_info error\n");
214 err = CODEC_ERROR;
215 goto done;
216 }
217
218 /* There can be gaps between chunks, so skip ahead if needed. It 208 /* There can be gaps between chunks, so skip ahead if needed. It
219 * doesn't seem to happen much, but it probably means that a 209 * doesn't seem to happen much, but it probably means that a
220 * "proper" file can have chunks out of order. Why one would want 210 * "proper" file can have chunks out of order. Why one would want
221 * that an good question (but files with gaps do exist, so who 211 * that an good question (but files with gaps do exist, so who
222 * knows?), so we don't support that - for now, at least. 212 * knows?), so we don't support that - for now, at least.
223 */ 213 */
224 file_offset = get_sample_offset(&demux_res, i); 214 file_offset = get_sample_offset(&demux_res, i);
225 215
226 if (file_offset > ci->curpos) 216 if (file_offset > ci->curpos)
227 { 217 {
228 ci->advance_buffer(file_offset - ci->curpos); 218 ci->advance_buffer(file_offset - ci->curpos);
@@ -235,7 +225,7 @@ next_track:
235 } 225 }
236 226
237 /* Request the required number of bytes from the input buffer */ 227 /* Request the required number of bytes from the input buffer */
238 buffer=ci->request_buffer(&n,sample_byte_size); 228 buffer=ci->request_buffer(&n, demux_res.sample_byte_size[i]);
239 229
240 /* Decode one block - returned samples will be host-endian */ 230 /* Decode one block - returned samples will be host-endian */
241 ret = NeAACDecDecode(decoder, &frame_info, buffer, n); 231 ret = NeAACDecDecode(decoder, &frame_info, buffer, n);
@@ -248,34 +238,17 @@ next_track:
248 } 238 }
249 239
250 /* Advance codec buffer (no need to call set_offset because of this) */ 240 /* Advance codec buffer (no need to call set_offset because of this) */
251 ci->advance_buffer(n); 241 ci->advance_buffer(frame_info.bytesconsumed);
252 242
253 /* Output the audio */ 243 /* Output the audio */
254 ci->yield(); 244 ci->yield();
255 245
256 /* Ensure correct sample_duration is used. For SBR upsampling files 246 /* Gather number of samples for the decoded frame. */
257 * sample_duration is only half the size of real output frame size. */
258 sample_duration *= sbr_fac;
259
260 framelength = (frame_info.samples >> 1) - lead_trim; 247 framelength = (frame_info.samples >> 1) - lead_trim;
261 248
262 if (i == demux_res.num_sample_byte_sizes - 1 && framelength > 0) 249 if (i == demux_res.num_sample_byte_sizes - 1 && framelength > 0)
263 { 250 {
264 /* Currently limited to at most one frame of tail_trim. 251 framelength -= ci->id3->tail_trim;
265 * Seems to be enough.
266 */
267 if (ci->id3->tail_trim == 0
268 && sample_duration < (frame_info.samples >> 1))
269 {
270 /* Subtract lead_trim just in case we decode a file with
271 * only one audio frame with actual data.
272 */
273 framelength = sample_duration - lead_trim;
274 }
275 else
276 {
277 framelength -= ci->id3->tail_trim;
278 }
279 } 252 }
280 253
281 if (framelength > 0) 254 if (framelength > 0)