faad2 icon indicating copy to clipboard operation
faad2 copied to clipboard

Distorted sound in AAC stream

Open jpalus opened this issue 3 years ago • 14 comments

48kbps AAC stream is decoded fine with ffmpeg while faad2 decodes it distorted. However I think for a small fraction of second at the very beginning it plays fine (volume level is significantly different between "good" and "bad"). Sample can be downloaded here:

http://jpalus.fastmail.com/out.aac

jpalus avatar Nov 01 '20 22:11 jpalus

i have same issue but its way more noticeable like the sound is almost muted, just occasionally few fraction of seconds

Kazzaky avatar Jan 07 '22 03:01 Kazzaky

Hello, @jpalus @Kazzaky.

Unfortunately old link is not working. Please consider re-sharing (I believe you can attach file to message by simply drag-n-dropping).

I would be glad to investigate the problem. Also, please mention an alternative decoder you use, so I will have a baseline for comparison.

eustas avatar Apr 18 '23 21:04 eustas

Link still works fine for me but here it is compressed with zip (due to file type restrictions in GH). out-aac.zip

jpalus avatar Apr 18 '23 21:04 jpalus

Regarding decoders:

Those that work well: ffmpeg, fdk-aac, ie using gstreamer:

# ffmpeg
$ gst-launch-1.0  filesrc location=out.aac ! aacparse ! avdec_aac ! audioresample ! audioconvert ! audio/x-raw,format=S16LE,rate=41000 ! wavenc ! filesink location=out-av.wav
# fdk-aac
$ gst-launch-1.0  filesrc location=out.aac ! aacparse ! fdkaacdec ! audioresample ! audioconvert ! audio/x-raw,format=S16LE,rate=41000 ! wavenc ! filesink location=out-fdk-aac.wav

And for faad:

$ gst-launch-1.0  filesrc location=out.aac ! aacparse ! faad ! audioresample ! audioconvert ! audio/x-raw,format=S16LE,rate=41000 ! wavenc ! filesink location=out-faad.wav

jpalus avatar Apr 18 '23 22:04 jpalus

Thanks. This will help a lot.

eustas avatar Apr 20 '23 07:04 eustas

Even with faad executable distortion is reproducible. Trying to compare with other aac decoding library. Unfortunately, there is no open libraries that just build and work...

eustas avatar May 15 '23 09:05 eustas

Likely found one problem: faad2 drops the first frame output. (that is because object type is LC, not LD?)

But distortion is still there...

eustas avatar May 16 '23 16:05 eustas

It seems that sound is not distorted at the beginning... It is just goes very quiet after first few frames.

Top: current faad2 Middle: modified faad2 that does not swallow first frame Bottom: Fraunhofer decoder Screenshot 2023-05-16 at 18 36 10

eustas avatar May 16 '23 16:05 eustas

One more clue - decoding in "fixed_point" mode produces loud noise... Still do not have enough time to pinpoint the problem...

eustas avatar Jun 06 '23 14:06 eustas

#149 should fix dropping of the first frame. Not adding primer as FDK does, because it seems to be too much.

eustas avatar Jun 08 '23 09:06 eustas

This is still marked as one of the release blockers in #115. How are the chances to fix this? @eustas

fabiangreffrath avatar Aug 22 '23 08:08 fabiangreffrath

At last debugging session I've got some insights and understood that I need to dive deeper. Going to remove it from blocker list, as have no resources to fix it timely.

eustas avatar Aug 22 '23 08:08 eustas

Noticed this for some iTunes M4A files as well. Using minimp4 as demuxer, though. Problem vanishes with libfdk-aac.

ghost avatar Sep 22 '23 21:09 ghost

Unfortunately, there is no open libraries that just build and work...

Found simple example with fdk-aac here. I prepared sample project based on it for debugging decoding with fdk-aac with supplied file. See https://github.com/bahusoid/aac-example

Debugging dec_test.cpp I noticed that second frame is decoded differently with libfaad and fdk-aac. In fdk-aac second frame is decoded to all zeroes (same as first frame) but it has some values in libfaad. Looks suspicious.

In fdk-aac second frame has some values initially and data are zeroed in sbr processing (inside sbrDecoder_DecodeElement):

qmfSynPrototypeFirSlot qmf.cpp:184
qmfSynthesisFilteringSlot qmf.cpp:881
qmfSynthesisFiltering qmf.cpp:951
sbr_dec sbr_dec.cpp:571
sbrDecoder_DecodeElement sbrdecoder.cpp:1473
sbrDecoder_Apply sbrdecoder.cpp:1624
aacDecoder_DecodeFrame aacdecoder_lib.cpp:951
AacDecoder::aacdec_decode_frame fdkaac_dec.cpp:79
main dec_test.cpp:100
  • And then left non-zero values are zeroed here

So seems libfaad makes something differently in sbr processing (if I properly found similar place something wrong might be here)

bahusoid avatar Mar 23 '24 11:03 bahusoid