Using variable in lambda not working

Hi! Newbie question: I’m trying to use a variable in my lambda setting a pulsewidth duty like this:

void Osc::setPulseWidth (const float duty)
{
    initialise ([] (float x, float duty) { return x < 0.0f ? -1.0 + duty : 1.0 - duty; });
}

However this gives me this error:

No viable conversion from '(lambda at [My path])' to 'const std::function<NumericType (NumericType)>' (aka 'const function<float (float)>')

What am I doing wrong?

You need to pass duty in as a capture, not as a parameter.

initialise ([duty] (float x) { return x < 0.0f ? -1.0 + duty : 1.0 - duty; });

Thanks! That worked.