CrossFader for a mixer


#1

Hi all,

I am trying to use a horizontal slider as a cross fader for 2 file players.
The end result i’m hoping for is a basic mixer.
I have pitch control and indipendent gains but wanted to cross fade between them.

The slider range is 0 - 2 at 0.1 increments.
From Right to left is no problem as when the slider passes the middle it goes from 1 to 0.
How can I make it so from left to right when the slider passes the middle (1) and gets to the end (2) it actually goes from 1 - 0???
Here is the code I have at the moment

	if(crossFader->getValue()<0.99)
	{
		
		std::cout<< "slider to the left" << "\n";
		leftPlayer->changeGain(1); // set gain at 1 (playing)
		rightPlayer->changeGain(crossFader->getValue()); // attenuate to 0
		
	}
	else if (crossFader->getValue()>1)
	{

		std::cout<< "slider to the right" << "\n";
		
		rightPlayer->changeGain(1); // set gain at 1 (playing)
	//	leftPlayer->changeGain(crossFader->getValue());
		
	}
	else
	{
		leftPlayer->changeGain(1);
		rightPlayer->changeGain(1);
	}

#2

Why don’t you just set your slider range to 0-1 ( and probably have a smaller increment size or some smoothing, preferably both to avoid clicks) then just multiply the right player by the value and the left by 1 minus the value?

Any curve shaping you want to do can then be just applied to the slider value before you set any gains.


#3

…or

source1pow(value,2)
source2
sqrt(1 - pow(value,2))
output = source1+source2

to maintain uniform power across the fade for uncorrelated sources :idea:


#4

awesome thanks guys,
I have a linear fade at the moment just to get it working. Will use your advice to refine it :slight_smile:


#5

Sorry, I made a subtle balls-up. The following line . . .

[quote=“billythekid”]
source1*pow(value,2)
:[/quote]

… should simply be: