moved scalar processing chunks to inside switch statements to cut down on cpu cycles, revised cpow algo, changed process arguments to pointers
using namespace daisysp;
-float crossfade::process(float *in1, float *in2)
+float crossfade::process(float &in1, float &in2)
{
- // const pow scalar
- float scalar = sinf(pos_ * (M_PI * 0.5f));
+ float scalar_1, scalar_2;
switch (curve_)
{
case CROSSFADE_LIN:
- return ((*in2 * pos_) + *in1) * (1 - pos_);
+ scalar_1 = pos_;
+ return (*in1 * (1.0f - scalar_1)) + (*in2 * scalar_1);
case CROSSFADE_CPOW:
- return (*in1 * (1.0f - scalar)) + (*in2 * scalar);
+ scalar_1 = sinf(pos_ * (M_PI * 0.5f));
+ scalar_2 = sinf((1.0f - pos_) * (M_PI * 0.5f));
+ return (in1 * scalar_2) + (in2 * scalar_1);
case CROSSFADE_LOG:
- return 0;
+ scalar_1 = expf(pos_ * (logf(1.0) - logf(REALLYSMALLFLOAT)) + logf(REALLYSMALLFLOAT));
+ return (*in1 * (1.0f - scalar_1)) + (*in2 * scalar_1);
case CROSSFADE_EXP:
- return 0;
+ scalar_1 = pos_ * pos_;
+ return (*in1 * (1.0f - scalar_1)) + (*in2 * scalar_1);
default :
return 0;
