[haiku-development] Re: Sound of Silence...

On 2009-06-02 at 10:26:41 [+0200], Axel Dörfler <axeld@xxxxxxxxxxxxxxxx> 
wrote:
> pete.goodeve@xxxxxxxxxxxx wrote:
> > I have been digging into sources a bit, though, and I believe I've
> > found
> > the reason for my red volume slider...  And unless I'm going mad,
> > everyone
> > else should be seeing it too!
> > 
> > On line 304 of .../src/bin/desklink/VolumeControl.cpp, I see:
> > 
> >  float position = 1.0f * (max - min - max) / (max - min);
> > 
> > Hunh...?  Doesn't this result in a *negative* position for all min
> > and max?
> > As that position is then fed to the bar drawing...:
> > 
> >   be_control_look->DrawSliderBar(view, frame, frame, base,
> > leftFillColor,
> >                         rightFillColor, position, flags,
> > Orientation());
> 
> The position computation is only correct (even if it could be
> simplified) if "min" is negative - which is the whole point of the red
> vs. green color, anyway. The volume currently goes from -60 to +18 dB,
> btw.

The computation looks interesting nevertheless. Usually it holds:

        max - min - max == -min

And one can just hope that the compiler doesn't actually multiply by 1.0f. 
I'd replace the above by:

float position = (float)min / (min - max);

CU, Ingo

Other related posts: