GNOME Bugzilla – Bug 745667
volume: Unable to set the volume with gcc-4.9 on arm platform
Last modified: 2015-03-06 10:23:11 UTC
The volume can not be set with gstvolume using gstreamer-1.4.1 and gcc-4.9 on armv7 with hardfloat activated. Whith this pipeline: gst-launch-1.0 audiotestsrc ! volume volume=0.5 ! alsasink The sound level is equal to 0 instead of half of the standard volume. If i put volume=1 this is working properly. Affter investigation i understood that it is related to this line gstvolume.c:251 self->current_volume = volume; in volume_update_volume If i put any log just after this line, the behaviour is coming back to normal. If i compile with -00 it's also working fine. The bug can be reproduced on either rpi2 or imx6q.
If that line is really the problem, or the lines below it... then I would say this is a compiler bug (or undefined C behaviour I didn't know yet). What happens afterwards is that we multiple a float with signed integers, and my guess is that the compiler breaks that by first casting the float to an integer (thus giving 0 for values < 1.0)... instead of casting the integer to a float first. Does the attached patch fix it for you?
Created attachment 298625 [details] [review] volume: Explicitly cast integers to doubles and then back to integers after multiplication
Or maybe the compiler does the right thing here, and did the wrong thing before by casting the integer to a float first?
Seems like a compiler bug - ints should always promote to floats/doubles/long doubles if the other operand is one of those types. (Section 6.3 of ISO 9899:1999)
gcc 4.9.2 has been out for enough time that it is very suprising to find no other mentions of this compiler bug in the web. Is assuming the standard will happen defined behaviour? Is there any cons, besides legibility to apply Sebastian's patch of forced casting?
We don't even know yet if the patch works :)
The patch seems ok. I compiled with -O2 and i can set the volume as before.
commit 40f4daffd12b84dceb23942a992815e11b5a0839 Author: Sebastian Dröge <sebastian@centricular.com> Date: Thu Mar 5 12:31:06 2015 +0100 volume: Explicitly cast integers to doubles and then back to integers after multiplication gcc 4.9.1 on ARM seems to have a bug that causes it to cast the float to an integer first, resulting in a 0 scale factor for volume < 1.0. As a side effect this change here will also improve accuracy of the result a bit because we go via doubles instead of floats. https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65325 https://bugzilla.gnome.org/show_bug.cgi?id=745667
Thanks Sebastian :)