Skip to main content

Topic: HE-AAC gapless playback (Read 12574 times) previous topic - next topic

0 Members and 1 Guest are viewing this topic.
  • nu774
  • [*][*][*][*][*]
  • Developer
HE-AAC gapless playback
I knew that Apple and other software (at least fb2k and winamp FhG encoder) treats delay of HE-AAC differently.
In short, fb2k can play FhG's HE-AAC gaplessly, and iTunes can play Apple's HE-AAC gaplessly, but fb2k cannot play Apple's HE-AAC gaplessly, etc.

Personally I'm not using HE-AAC for music so I didn't care much about it so far.
However, just out of curiosity, I looked into it further today.

In ISO 14496-24:2008 (which you can read from the link at http://wiki.multimedia.cx/index.php?title=AAC), it is written that additional decoder delay introduced by SBR tool is 481 (which becomes 962 in upsampled scale).

Then I tried trimming the first 962 samples of the decoded wav file (encoded by Apple then decoded by fb2k), and I noticed that offset matches with the original.
Next, I made hacked version of qaac, which basically do the following:
  • Append silence of 2048 samples to the end of input before sending to encoder
  • Add 481 to encoder delay of iTunSMPB, and also edit other values

Using this hacked version of qaac, now I could get gapless HE-AAC playback on fb2k.
So, my guess is the following:
  • fb2k doesn't trim additional decoder delay introduced by SBR tool
  • Winamp FhG encoder count this additional decoder delay into encoder delay of iTuneSMPB

Why all of this is happening? Is this correct?

This hacked qaac and used test files are in the attached file:
Files under CAF and M4A_2112 are unmodified HE-AAC files (You can play this CAF file gaplessly using my foo_input_caf).
Files under M4A_2112+481 was encoded using hacked qaac.
[ Specified attachment is not available ]
  • Last Edit: 22 December, 2012, 12:25:21 PM by nu774

  • nu774
  • [*][*][*][*][*]
  • Developer
HE-AAC gapless playback
Reply #1
As I did it, trimming required by gapless playback can be achieved by counting this as the encoder delay (Although it is some kind of a hack or cheating).
However, I think it is quite problematic if it actually is a decoder delay produced by SBR decoding, since HE-AAC can be decoded as LC-AAC (ignoring SBR part), in which case this additional delay will not appear.

  • benski
  • [*][*][*][*][*]
  • Developer
HE-AAC gapless playback
Reply #2
The Winamp code for adding the iTunSMPB writes the total encoder+decoder delay, yes.  And the playback code also assumes that iTunSMPB includes total delay.  That's what was done for iTunes AAC LC, but I have not updated this code since iTunes added support for HE-AAC.

I will investigate the iTunes implementation and see what delay is written and whether it includes SBR delay or not.  It does raise the question of what to do about old files with the wrong delay value, but since the delays are fairly standard it can be easily detected and corrected for. 

Thanks for passing along the information; wouldn't have known about it otherwise.

  • kode54
  • [*][*][*][*][*]
  • Administrator
HE-AAC gapless playback
Reply #3
Extra add for this, the XLD encoder plug-in based on fdk-aac has the same problem with SBR. I found that subtracting 481 from the delay written to SBR files worked perfectly, but not so for SBR+PS. It seems SBR+PS need to subtract 391 from the combined delay given by the encoder instead.

EDIT: Scratch that, I was using Jack rerouted output instead of actually converting the files. Seems like 481 is correct for PS as well.
  • Last Edit: 14 August, 2013, 03:18:19 AM by kode54

  • nu774
  • [*][*][*][*][*]
  • Developer
HE-AAC gapless playback
Reply #4
And my extra add about this:
https://sites.google.com/site/qaacpage/news...se225refalac125

As a workaround, I just appended one frame length silence, but it might be better to try smart padder of opus (using LPC).

  • nu774
  • [*][*][*][*][*]
  • Developer
HE-AAC gapless playback
Reply #5
Since iTunSMPB includes decoder delay of LC-AAC (1024), I guess Apple doesn't includes additional decoder delay of SBR (481) purely for compatibility reason with LC only decoder.

  • kode54
  • [*][*][*][*][*]
  • Administrator
HE-AAC gapless playback
Reply #6
foobar2000 v1.3, which is now in beta, handles iTunes encoded files correctly now, at least as long as they don't exhibit the bug you just described.

  • nu774
  • [*][*][*][*][*]
  • Developer
HE-AAC gapless playback
Reply #7
foobar2000 v1.3, which is now in beta, handles iTunes encoded files correctly now, at least as long as they don't exhibit the bug you just described.

Oh, nice to hear that. Then it might better to fix fdkaac. It still uses the value returned from FDK encoder.

  • sluggy
  • [*][*]
HE-AAC gapless playback
Reply #8
Does that mean that fhgaac now needs to be updated for HE-AAC to be played correctly in fb2k and itunes?

  • nu774
  • [*][*][*][*][*]
  • Developer
HE-AAC gapless playback
Reply #9
Does that mean that fhgaac now needs to be updated for HE-AAC to be played correctly in fb2k and itunes?

Unless fb2k implements some conditional trick specific on encoder, yes.

  • kode54
  • [*][*][*][*][*]
  • Administrator
HE-AAC gapless playback
Reply #10
Or unless the fhg encoder already uses Nero chapters, which will be preferred over the iTunSMPB tag.

  • nu774
  • [*][*][*][*][*]
  • Developer
HE-AAC gapless playback
Reply #11
Added --include-sbr-delay option to fdkaac, for controlling SBR decoder delay treatment.

Also found some oddity in iTunes AAC decoder.
I had to finally upgrade iTunes only to confirm if these issues are still there... and as I was afraid, nothing seems to have changed from 10.5.3.

  • sluggy
  • [*][*]
HE-AAC gapless playback
Reply #12
[fdkaac] 0.4.2
posted 8 hours ago by nu 774
I found gapless playback issue on this sample when encoded with SBR (not annoying, but tiny pop is audible), so implemented improved gapless playback by the method used by Vorbis and Opus (extrapolation by linear prediction). Extrapolation is done both at beginning and ending, since ending only extrapolation didn't fix the issue on this sample.

Also, this version adds one extra zero sample at beginning in case of SBR+PS, since FDK-AAC has odd enc_delay for SBR+PS, which cannot be exactly expressed in downsampled time scale (which is mandatory for iTunes compatibility).

In order not to increase amount of enc_delay and padding, one AAC frame is discarded from each of beginning and ending, to compensate the padding added on our side.

To tell the truth, qaac has the same gapless issue when encoded with --he. However, I'm wondering if I should implement the same padder on qaac, since it will make the result no more identical with iTunes (or other Apple softwares).


  • eahm
  • [*][*][*][*][*]
HE-AAC gapless playback
Reply #13
To tell the truth, qaac has the same gapless issue when encoded with --he. However, I'm wondering if I should implement the same padder on qaac, since it will make the result no more identical with iTunes (or other Apple softwares).

Thanks for the update and crazy about iTunes, is Apple every reading here? Are they going to fix this as well?

  • nu774
  • [*][*][*][*][*]
  • Developer
HE-AAC gapless playback
Reply #14
To tell the truth, qaac has the same gapless issue when encoded with --he. However, I'm wondering if I should implement the same padder on qaac, since it will make the result no more identical with iTunes (or other Apple softwares).

Thanks for the update and crazy about iTunes, is Apple every reading here? Are they going to fix this as well?

It may not be nice, but I don't think it is a BUG.
It seems that SBR is weaker against cliffs at beginning/ending than LC, but I'm no specialist and don't have any technical clues.

  • Maurits
  • [*][*][*][*]
HE-AAC gapless playback
Reply #15
To tell the truth, qaac has the same gapless issue when encoded with --he. However, I'm wondering if I should implement the same padder on qaac, since it will make the result no more identical with iTunes (or other Apple softwares).

Thanks for the update and crazy about iTunes, is Apple every reading here? Are they going to fix this as well?

I know of at least two senior Apple developers who occasionally used to pop up in relevant topics on HA. I doubt they'll read every topic that might have some relevance to Apple though...
There is a hidden message in the song at approximately 4:32. If played at half speed, Waters can be heard to say, "That was pretty avant-garde, wasn't it?"

  • poiko
  • [*]
HE-AAC gapless playback
Reply #16
I have been contact with Apple regarding this issue and also wrote to their support forum. (https://discussions.apple.com/thread/6397997)

The Apple implementation for HE AAC gapless is bad.

Winamp, Foobar, and EZ CD Audio Converter use the same kind of gapless information which is the actual number of samples for encoder delay and total samples not just the AAC LC part as Apple does.