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) { // fading out b aChannel= 1; bChannel =value/45; }else if(value>55) { // fading out a bChannel=1; value=100-value; aChannel=value/45; }else { // fading nothing 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.