# How can I represent this mathemathically

I've written some code to implement simple cross fading between 2 channels.

It works fine but the code is ugly and riddled with if else statements so I'd like to try and express the function a more cleanly. I'm curious to discover a mathematical function to do this.

My slider goes from 0 -100. It has a "dead" range of 45 - 55 where no changes happen, so if the slider is anywhere from 45 - 55 both channels have a volume of 1.

This means that each channel has a range of 45.

Here is my code to illustrate futher.

if(value <45)

{
aChannel= 1;
bChannel =value/45;

}else if(value>55)
{
bChannel=1;
value=100-value;
aChannel=value/45;
}else
{
aChannel=1;
bChannel=1;
}


I'm not entirely sure what family of mathemathics this problem would belong to so I've added algebra as a tag. If this is innappropiate please suggest a better tag.

-
Shouldn't the statement be value>55 in the second if? –  Raskolnikov Mar 27 '12 at 10:21
yep. that was a type-o. fixed now –  dubbeat Mar 27 '12 at 10:24

assert( 0 >= value && value <=100 ) ;