C++ Efficent input control with adjustible curve using pow() or similar on clamped signal .0-1 DSP?

  audio, c++, signal-processing, vst

This is an example code of clamping an input value between 0-1 and a curve value between 0-1. The Curve input is inverted to make increasing values translate to a faster signal response.

At this point the curve is inverted, 0-1 is now 1-0 and the input and curve are clamped to 0-1

*output1_ptr++ = (pow(((std::clamp(*input_ptr++, 0.0f, 1.f) * 10.f) * 0.1f), std::clamp((-*curve_ptr++ + 1.0f), 0.005f, 1.f) * 10.f) * 10.f) * .1f;

This helps to provide a convex or concave signal curve but at some expense. The pow() function can be replaced by fast math fast and faster. Fast is accurate enough and an improvement over pow(). My question is could I refactor this code to be a little more efficient? Below is how I am getting fast math which helps but there must be a better way? Please any help speeding this process up I would really appreciate thank you.

static inline float
fastpow (float x,
         float p)
{
  return fastpow2 (p * fastlog2 (x));
}

static inline float
fasterpow (float x,
           float p)
{
  return fasterpow2 (p * fasterlog2 (x));
}

fasterlog2 (float x)
{
  union { float f; uint32_t i; } vx = { x };
  float y = vx.i;
  y *= 1.1920928955078125e-7f;
  return y - 126.94269504f;
}

static inline float
fasterlog (float x)
{
//  return 0.69314718f * fasterlog2 (x);

  union { float f; uint32_t i; } vx = { x };
  float y = vx.i;
  y *= 8.2629582881927490e-8f;
  return y - 87.989971088f;
}

Source: Windows Questions C++

LEAVE A COMMENT