Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 682620 - media-libs/faad2 distorts audio playback when compiled with -O3
Summary: media-libs/faad2 distorts audio playback when compiled with -O3
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: Current packages (show other bugs)
Hardware: All Linux
: Normal normal with 1 vote (vote)
Assignee: Gentoo Sound Team
Depends on:
Reported: 2019-04-05 19:07 UTC by Xepher
Modified: 2019-10-09 09:55 UTC (History)
1 user (show)

See Also:
Package list:
Runtime testing required: ---

Patch to replace -O3 with -O2 (cflags.patch,616 bytes, patch)
2019-04-05 19:07 UTC, Xepher
Details | Diff
emerge --info (emerge-info.txt,7.22 KB, text/plain)
2019-04-05 19:07 UTC, Xepher

Note You need to log in before you can comment on or make changes to this bug.
Description Xepher 2019-04-05 19:07:24 UTC
Created attachment 571996 [details, diff]
Patch to replace -O3 with -O2

Listening to m4a files via rhythmbox -> gstreamer > faad sounds distorted (with a metallic sound, like old, badly encoded mp3s used to have.) I narrowed this down to faad itself, as a direct decode there shows the same issue.

faad -o test.wav input.m4a

Playing the m4a in other programs (such as mplayer or ffplay) shows no issue and the song sounds correct. Downloading/building the faad source code directly shows no problem either, and files sound correct after being decoded through a local build of the same version.

After much testing, I narrowed it down to having -O3 set in CFLAGS. Switching to -O2 completely fixes the issue. (Note, I also tried removing march=native, but that didn't help.)

Attached is a small patch using flag-o-matic to reduce -O3 to -O2.
Comment 1 Xepher 2019-04-05 19:07:48 UTC
Created attachment 571998 [details]
emerge --info
Comment 2 Xepher 2019-04-05 19:09:13 UTC
For future clarity, this is faad2-2.8.8 (the only version in portage currently)
Comment 3 Bernd 2019-10-06 06:36:00 UTC
Can confirm that switching from -O3 to -O2 solves the problem (at least for faad2-2.8.8).
I encountered that bug about half year ago when I blindly enabled all media codec flags I could find (didn't think about the possible downsides). Most videos played fine, but those with aac tracks had this metallic distorted sound. Because it only affected vlc, but not mpv, I was able o track it down to faad2 and just disabled the decoder. 
I wonder if miscompiled faad2 may affect browser video playback too? At first glance firefox seems to be using only libfdk-aac and libavcodec for aac.
Also, did you notify upstream of the bug?
Comment 4 Xepher 2019-10-09 09:55:19 UTC
> Also, did you notify upstream of the bug?

I did not. Completely unsure if it's a GCC bug, a FAAD2 bug, or some other interaction. As it IS definitely related to the build flags (and that completely solves the issue), it felt like a gentoo/ebuild patch was the most reasonable approach.